#pragma once #include #include #include #include #include #include #include #include #ifdef VALIDATION_LAYER_ON #define VALIDATION_LAYER "VK_LAYER_KHRONOS_validation" #else #define VALIDATION_LAYER #endif // GPU properties priority for selection #define GPU_DISCRETE_PRIORITY 1000 struct RenderCommand { enum Type { NONE, //STORE screenHeight and screenWidth BEFORE request RESIZE_WINDOW, SHUTDOWN } type = NONE; }; struct QueueFamiliesBundle { std::optional graphics; std::optional presence; }; class Renderer { private: std::stop_token *stoken; std::jthread renderThread; SDL_Window *window; VkInstance vulkan; VkPhysicalDevice gpu; VkDevice device; QueueFamiliesBundle queueFamilies; const float defaultQueuePriority = 1.0f; Rml::Context *uiContext; boost::lockfree::spsc_queue> commands; void InitVulkan(); void SetupDevice(); void Threading(); void Loop(); void ProcessCommand(const RenderCommand &command); void Release(); public: std::atomic isRunning; std::atomic screenWidth, screenHeight; Renderer(SDL_Window *window); ~Renderer(); void Start(); void Shutdown(); void Request(const RenderCommand &command); void Request(RenderCommand::Type type); };