2022-06-15 00:09:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-24 23:33:46 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif
|
2023-02-06 20:51:05 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
|
|
#undef WINVER
|
|
|
|
#define WINVER 0x599
|
|
|
|
#endif
|
2023-05-01 16:38:54 +00:00
|
|
|
#include <cstdint>
|
2024-04-13 16:06:14 +00:00
|
|
|
#include "vulkan/vulkan_hpp_wrapper.hpp"
|
2023-03-23 21:53:43 +00:00
|
|
|
#include "../external/VulkanMemoryAllocator-Hpp/include/vk_mem_alloc.hpp"
|
2022-06-15 00:09:51 +00:00
|
|
|
#include "vulkan_swapchain.hpp"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Context();
|
|
|
|
~Context();
|
2023-01-24 23:33:46 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
2023-03-23 21:53:43 +00:00
|
|
|
bool init_Xlib(Display *dpy, Window xid, int preferred_device = -1);
|
2023-01-24 23:33:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
2023-03-23 21:53:43 +00:00
|
|
|
bool init_wayland(wl_display *dpy, wl_surface *parent, int width, int height, int preferred_device = -1);
|
2023-01-30 23:54:23 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
2023-03-23 21:53:43 +00:00
|
|
|
bool init_win32(HINSTANCE hinstance, HWND hwnd, int preferred_device = -1);
|
2023-01-24 23:33:46 +00:00
|
|
|
#endif
|
2024-04-19 21:24:54 +00:00
|
|
|
bool init(int preferred_device = -1, int initial_width = -1, int initial_height = -1);
|
2023-01-24 23:33:46 +00:00
|
|
|
bool create_swapchain(int width = -1, int height = -1);
|
|
|
|
bool recreate_swapchain(int width = -1, int height = -1);
|
2022-06-15 00:09:51 +00:00
|
|
|
void wait_idle();
|
|
|
|
vk::CommandBuffer begin_cmd_buffer();
|
|
|
|
void end_cmd_buffer();
|
2023-02-02 20:14:49 +00:00
|
|
|
void hard_barrier(vk::CommandBuffer cmd);
|
2023-03-23 21:53:43 +00:00
|
|
|
static std::vector<std::string> get_device_list();
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
vma::Allocator allocator;
|
|
|
|
vk::Device device;
|
2023-04-14 20:37:38 +00:00
|
|
|
uint32_t graphics_queue_family_index;
|
2022-06-15 00:09:51 +00:00
|
|
|
vk::Queue queue;
|
|
|
|
vk::UniqueCommandPool command_pool;
|
|
|
|
vk::UniqueDescriptorPool descriptor_pool;
|
|
|
|
std::unique_ptr<Swapchain> swapchain;
|
2023-04-14 20:37:38 +00:00
|
|
|
vk::UniqueInstance instance;
|
|
|
|
vk::PhysicalDevice physical_device;
|
|
|
|
vk::PhysicalDeviceProperties physical_device_props;
|
|
|
|
vk::UniqueSurfaceKHR surface;
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool init_vma();
|
|
|
|
bool init_device(int preferred_device = 0);
|
|
|
|
bool init_command_pool();
|
|
|
|
bool init_descriptor_pool();
|
|
|
|
|
2023-01-24 23:33:46 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
2022-06-15 00:09:51 +00:00
|
|
|
Display *xlib_display;
|
|
|
|
Window xlib_window;
|
2023-01-24 23:33:46 +00:00
|
|
|
#endif
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
vk::CommandBuffer one_time_use_cmd;
|
|
|
|
};
|
|
|
|
|
2023-05-01 16:38:54 +00:00
|
|
|
} // namespace Vulkan
|