#pragma once #include #include #include #include "utils.h" #include "physicaldevice.h" #include "surface.h" #include "program/pipeline.h" #include "program/program.h" namespace Engine { class SwapChain; class LogicalDevice { public: LogicalDevice( PhysicalDevice* physicalDevice, Surface* surface, const std::vector& extensions, const std::vector layers ); ~LogicalDevice(); void createSwapChain(); void clearSwapChain(); void recreateSwapChain(); void setResized(); void addProgram(const Program& program); void drawFrame(); VkResult waitIdle(); VkResult waitForFence(const VkFence& fence); VkResult resetFence(const VkFence& fence); VkExtent2D chooseSwapExtent() const; VkResult createVkSwapChain(const VkExtent2D& extent, VkSwapchainKHR& out); void destroyVkSwapChain(VkSwapchainKHR& swapChain); VkResult getVkSwapChainImages(VkSwapchainKHR& swapChain, std::vector& out); VkResult createVkImageView(const VkImage& image, VkImageView& out); void destroyVkImageView(VkImageView& view); VkResult createVkFrameBuffer(const VkImageView& imageView, const VkExtent2D& extent, VkFramebuffer& out); void destroyVkFrameBuffer(VkFramebuffer& buffer); VkResult createPipeline(VkGraphicsPipelineCreateInfo& info, VkPipeline& out); VkResult createPipelineLayout(const VkPipelineLayoutCreateInfo& info, VkPipelineLayout& out); void destroyPipelineLayout(VkPipelineLayout& layout); void destroyPipeline(VkPipeline& pipline); VkResult createShaderModule(const VkShaderModuleCreateInfo& info, VkShaderModule& out); void destroyShaderModule(VkShaderModule& shaderModule); private: void createDevice( VkPhysicalDevice physicalDevice, const QueueFamilyIndices& indices, const std::vector& extensions, const std::vector layers ); void createQueues(uint32_t graphicsFamilyIndex, uint32_t presenFamilyIndex); void createCommandPool(uint32_t queueFamilyIndex); void createCommandBuffers(); void createSyncObjects(); void createRenderPass(VkFormat format); VkResult queueSubmitGraphics( const VkSemaphore& wait, const VkCommandBuffer& buffer, const VkSemaphore& signal, const VkFence& fence ); VkResult queuePresent(const VkSemaphore& signal, uint32_t index); void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); private: PhysicalDevice* phys; VkDevice vk; VkQueue graphicsQueue; VkQueue presentQueue; VkRenderPass renderPass; std::vector pipelines; VkCommandPool commandPool; std::vector commandBuffers; std::vector imageAvailableSemaphores; std::vector renderFinishedSemaphores; std::vector inFlightFences; uint32_t currentFrame; bool framebufferResized; Surface* surface; VkSurfaceFormatKHR surfaceFormat; SwapChain* swapChain; }; }