From 8be5d3059fb01c8c5bc7703bfd03ac4aa3a560c9 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Thu, 3 Oct 2024 19:47:09 +0200 Subject: [PATCH] refactor --- include/application.hpp | 73 +++++-- include/simulation.hpp | 54 ----- include/vulkan/command_pool.hpp | 2 +- include/vulkan/image.hpp | 4 +- include/vulkan/instance.hpp | 13 +- shaders/shader.frag | 2 +- src/{simulation.cpp => application.cpp} | 259 ++++++++++++++++++++---- src/main.cpp | 12 +- src/vulkan/application.cpp | 205 ------------------- src/vulkan/buffer.cpp | 10 +- src/vulkan/command_pool.cpp | 16 +- src/vulkan/descriptor_pool.cpp | 12 +- src/vulkan/image.cpp | 8 +- src/vulkan/instance.cpp | 18 +- src/vulkan/pipeline.cpp | 18 +- src/vulkan/swapchain.cpp | 28 +-- src/vulkan/synchronization.cpp | 8 +- 17 files changed, 365 insertions(+), 377 deletions(-) delete mode 100644 include/simulation.hpp rename src/{simulation.cpp => application.cpp} (63%) delete mode 100644 src/vulkan/application.cpp diff --git a/include/application.hpp b/include/application.hpp index 4697ce6..86a5d6e 100644 --- a/include/application.hpp +++ b/include/application.hpp @@ -15,10 +15,13 @@ #include #include #include +#include "constraints.hpp" +#include using std::unique_ptr, std::make_unique; using std::vector; +class SoftBody; class Instance; class Swapchain; class GraphicsPipeline; @@ -36,27 +39,63 @@ public: explicit Application(); void mainLoop(); ~Application(); -protected: - Swapchain* swapchain = nullptr; - DescriptorPool* descriptorPool = nullptr; - GraphicsPipeline* graphicsPipeline = nullptr; - Buffer* uniformBuffer = nullptr; +private: - void updateUniformBuffer(); + void createSyncObjects(); + unique_ptr imageAvailable; + unique_ptr renderFinished; + unique_ptr computeFinished; + unique_ptr renderInFlight; + unique_ptr computeInFlight; - void recordGraphicsCommandBuffer(uint32_t imageIndex); + unique_ptr swapchain; + unique_ptr descriptorPool; + unique_ptr graphicsPipeline; + unique_ptr uniformBuffer; + + unique_ptr camera; + + void createMeshBuffers(); + unique_ptr vertexBuffer; + unique_ptr faceBuffer; + unique_ptr edgeBuffer; + unique_ptr triangleBuffer; + unique_ptr tetrahedronBuffer; + ConstraintData constraintData {}; + vector> softBodies; + + struct SizeInformation { + uint32_t vertexCount; + uint32_t faceCount; + uint32_t edgeCount; + uint32_t triangleCount; + uint32_t tetrahedronCount; + }; + unique_ptr sizeInformationBuffer; + + struct Properties { + glm::vec3 gravity; + float dt; + uint32_t k; + }; + unique_ptr propertiesBuffer; + Properties properties {}; - Semaphore* imageAvailable = nullptr; - Semaphore* renderFinished = nullptr; - Semaphore* computeFinished = nullptr; - Fence* renderInFlight = nullptr; - Fence* computeInFlight = nullptr; + void createComputePipelines(); + unique_ptr pbdPipeline; + unique_ptr normalPipeline; + void updateUniformBuffer(); + void recordGraphicsCommandBuffer(uint32_t imageIndex); + void recordDrawCommands(); void drawFrame(); - virtual void recordDrawCommands() {}; - virtual void recordComputeCommands(VkCommandBuffer cmdBuffer) {} - void update(); - void createSyncObjects(); - Camera* camera = nullptr; + void recordComputeCommands(VkCommandBuffer cmdBuffer); + struct PBDPushData { + uint32_t state; + ConstraintData::Partition edgePartition; + ConstraintData::Partition tetrahedronPartition; + }; + + void update(); }; diff --git a/include/simulation.hpp b/include/simulation.hpp deleted file mode 100644 index b5fac55..0000000 --- a/include/simulation.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "application.hpp" -#include "constraints.hpp" -#include - -class SoftBody; -class Buffer; - -class Simulation : public Application { -public: - Simulation(); - ~Simulation(); -private: - unique_ptr vertexBuffer; - unique_ptr faceBuffer; - unique_ptr edgeBuffer; - unique_ptr triangleBuffer; - unique_ptr tetrahedronBuffer; - void createMeshBuffers(); - - struct SizeInformation { - uint32_t vertexCount; - uint32_t faceCount; - uint32_t edgeCount; - uint32_t triangleCount; - uint32_t tetrahedronCount; - }; - unique_ptr sizeInformationBuffer; - - struct Properties { - glm::vec3 gravity; - float dt; - uint32_t k; - }; - unique_ptr propertiesBuffer; - Properties properties {}; - - struct PBDPushData { - uint32_t state; - ConstraintData::Partition edgePartition; - ConstraintData::Partition tetrahedronPartition; - }; - - ConstraintData constraintData {}; - - unique_ptr pbdPipeline; - unique_ptr normalPipeline; - void createComputePipelines(); - - vector> softBodies; - void recordDrawCommands() override; - void recordComputeCommands(VkCommandBuffer cmdBuffer) override; -}; \ No newline at end of file diff --git a/include/vulkan/command_pool.hpp b/include/vulkan/command_pool.hpp index d80ffa7..49d6139 100644 --- a/include/vulkan/command_pool.hpp +++ b/include/vulkan/command_pool.hpp @@ -7,7 +7,7 @@ class Instance; class CommandPool { public: - explicit CommandPool(); + explicit CommandPool(VkSurfaceKHR surface); ~CommandPool(); VkCommandBuffer graphicsBuffer = VK_NULL_HANDLE; VkCommandBuffer computeBuffer = VK_NULL_HANDLE; diff --git a/include/vulkan/image.hpp b/include/vulkan/image.hpp index 25d6db4..3a112fc 100644 --- a/include/vulkan/image.hpp +++ b/include/vulkan/image.hpp @@ -7,7 +7,7 @@ class Instance; class Image { public: - explicit Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, + Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage); ~Image(); @@ -16,6 +16,6 @@ public: VkImage handle = VK_NULL_HANDLE; VkImageView view = VK_NULL_HANDLE; private: - VmaAllocation allocation = VK_NULL_HANDLE; + VmaAllocation allocation = nullptr; VmaAllocationInfo allocationInfo {}; }; \ No newline at end of file diff --git a/include/vulkan/instance.hpp b/include/vulkan/instance.hpp index 2965fbe..fc5f81e 100644 --- a/include/vulkan/instance.hpp +++ b/include/vulkan/instance.hpp @@ -14,10 +14,6 @@ public: ~Instance(); GLFWwindow *window = nullptr; - VkSurfaceKHR surface = VK_NULL_HANDLE; - VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; - VkDevice device = VK_NULL_HANDLE; - VmaAllocator allocator = VK_NULL_HANDLE; VkQueue graphicsQueue = VK_NULL_HANDLE; VkQueue presentQueue = VK_NULL_HANDLE; VkQueue computeQueue = VK_NULL_HANDLE; @@ -49,7 +45,16 @@ public: static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface); static Instance* instance; + static VkDevice GetDevice(); + static VkPhysicalDevice GetPhysicalDevice(); + static VmaAllocator GetAllocator(); + static VkSurfaceKHR GetSurface(); private: + VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; + VkDevice device = VK_NULL_HANDLE; + VkSurfaceKHR surface = VK_NULL_HANDLE; + VmaAllocator allocator = VK_NULL_HANDLE; + VkInstance handle = VK_NULL_HANDLE; void initWindow(); diff --git a/shaders/shader.frag b/shaders/shader.frag index e6776be..0cfb143 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -8,5 +8,5 @@ layout (location = 2) in vec3 normal; void main() { outColor = vec4((normal + vec3(1, 1, 1)) / 2, 1.0); - outColor = vec4(uv.x, uv.y, 0.0, 1.0); + // outColor = vec4(uv.x, uv.y, 0.0, 1.0); } \ No newline at end of file diff --git a/src/simulation.cpp b/src/application.cpp similarity index 63% rename from src/simulation.cpp rename to src/application.cpp index 2d144bb..abfed1c 100644 --- a/src/simulation.cpp +++ b/src/application.cpp @@ -1,15 +1,36 @@ -#include "simulation.hpp" +#include "application.hpp" +#include "vulkan/swapchain.hpp" +#include "vulkan/pipeline.hpp" #include "vulkan/instance.hpp" -#include "vulkan/command_pool.hpp" #include "vulkan/buffer.hpp" -#include "vulkan/pipeline.hpp" +#include "vulkan/command_pool.hpp" +#include "vulkan/image.hpp" +#include "vulkan/synchronization.hpp" +#include "vulkan/descriptor_pool.hpp" +#include "camera.hpp" +#include "input.hpp" #include "soft_body.hpp" #include "mesh.hpp" #include "constraints.hpp" -#include "vulkan/descriptor_pool.hpp" -#include "timer.hpp" -Simulation::Simulation() { +Application::Application() { + createSyncObjects(); + swapchain = make_unique(); + descriptorPool = make_unique(); + graphicsPipeline = unique_ptr(new GraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", + swapchain->renderPass, + {descriptorPool->layouts[DescriptorSet::WORLD]})); + + VkDeviceSize bufferSize = sizeof(UniformBufferObject); + + uniformBuffer = make_unique(bufferSize, + VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, + VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); + + descriptorPool->bindBuffer(*uniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorSet::WORLD, 0); + camera = make_unique(swapchain->extent); + createMeshBuffers(); SizeInformation sizeInformation {}; @@ -42,12 +63,33 @@ Simulation::Simulation() { createComputePipelines(); char* stats; - vmaBuildStatsString(Instance::instance->allocator, &stats, VK_TRUE); + vmaBuildStatsString(Instance::GetAllocator(), &stats, VK_TRUE); // printf("%s", stats); - vmaFreeStatsString(Instance::instance->allocator, stats); + vmaFreeStatsString(Instance::GetAllocator(), stats); +} + +void Application::mainLoop() { + while (!glfwWindowShouldClose(Instance::instance->window)){ + glfwPollEvents(); + update(); + drawFrame(); + } + vkDeviceWaitIdle(Instance::GetDevice()); } -void Simulation::createMeshBuffers() { +Application::~Application() { + +} + +void Application::createSyncObjects() { + imageAvailable = make_unique(); + renderFinished = make_unique(); + computeFinished = make_unique(); + renderInFlight = make_unique(true); + computeInFlight = make_unique(true); +} + +void Application::createMeshBuffers() { Mesh sphere("models/icosphere.ply"); Mesh bunny("models/bunny_medium.ply"); @@ -161,9 +203,178 @@ void Simulation::createMeshBuffers() { tetrahedronBuffer = make_unique(constraintData.tetrahedra.data(), constraintData.tetrahedra.size() * sizeof(Tetrahedron)); } -void Simulation::recordDrawCommands() { +void Application::createComputePipelines() { + vector layouts; + vector pushRanges; + + { + layouts.push_back(descriptorPool->layouts[DescriptorSet::MESH]); + layouts.push_back(descriptorPool->layouts[DescriptorSet::SIMULATION]); + pushRanges.push_back({ + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + .offset = 0, + .size = sizeof(PBDPushData) + }); + pbdPipeline = unique_ptr(new ComputePipeline("shaders/pbd.spv", layouts, pushRanges)); + } + + layouts.clear(); + pushRanges.clear(); + + { + layouts.push_back(descriptorPool->layouts[DescriptorSet::MESH]); + pushRanges.push_back({ + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + .offset = 0, + .size = sizeof(uint32_t) + }); + normalPipeline = unique_ptr(new ComputePipeline("shaders/normal.spv", layouts, pushRanges)); + } + +} + + +void Application::updateUniformBuffer() { + static float elapsed = 0; + + elapsed += 0.007; + + UniformBufferObject ubo {}; + ubo.model = glm::mat4(1); + ubo.view = camera->view(); + ubo.projection = camera->projection(); + ubo.projection[1][1] *= -1; + + memcpy(uniformBuffer->allocationInfo.pMappedData, &ubo, sizeof(UniformBufferObject)); +} + +void Application::recordGraphicsCommandBuffer(uint32_t imageIndex) { + VkCommandBuffer cmdBuffer = Instance::instance->commandPool->graphicsBuffer; + + VkCommandBufferBeginInfo beginInfo {}; + beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + + vkBeginCommandBuffer(cmdBuffer, &beginInfo); + + VkRenderPassBeginInfo renderPassInfo {}; + renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + renderPassInfo.renderPass = swapchain->renderPass; + renderPassInfo.framebuffer = swapchain->frameBuffers[imageIndex]; + renderPassInfo.renderArea.offset = {0, 0}; + renderPassInfo.renderArea.extent = swapchain->extent; + + VkClearValue clearValues[2] {}; + clearValues[0].color = {{0, 0, 0, 1}}; + clearValues[1].depthStencil = {1.0f, 0}; + + renderPassInfo.clearValueCount = 2; + renderPassInfo.pClearValues = clearValues; + + vkCmdBeginRenderPass(cmdBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + + VkViewport viewport {}; + viewport.x = 0; + viewport.y = 0; + viewport.width = static_cast(swapchain->extent.width); + viewport.height = static_cast(swapchain->extent.height); + viewport.minDepth = 0; + viewport.maxDepth = 1; + vkCmdSetViewport(cmdBuffer, 0, 1, &viewport); + + VkRect2D scissor {}; + scissor.offset = {0, 0}; + scissor.extent = swapchain->extent; + vkCmdSetScissor(cmdBuffer, 0, 1, &scissor); + + recordDrawCommands(); + + vkCmdEndRenderPass(cmdBuffer); + vkEndCommandBuffer(cmdBuffer); +} + +void Application::drawFrame() { + vkWaitForFences(Instance::GetDevice(), 1, &renderInFlight->handle, VK_TRUE, UINT64_MAX); + + uint32_t imageIndex; + VkResult result = vkAcquireNextImageKHR(Instance::GetDevice(), swapchain->handle, UINT64_MAX, imageAvailable->handle, VK_NULL_HANDLE, &imageIndex); + if (result == VK_ERROR_OUT_OF_DATE_KHR){ + swapchain->recreateSwapchain(); + return; + } + + vkResetFences(Instance::GetDevice(), 1, &renderInFlight->handle); + + vkResetCommandBuffer(Instance::instance->commandPool->graphicsBuffer, 0); + recordGraphicsCommandBuffer(imageIndex); + + camera->update(0.017); + updateUniformBuffer(); + + VkSubmitInfo submitInfo {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + + VkSemaphore waitSemaphores[] = {imageAvailable->handle, computeFinished->handle}; + VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT}; + submitInfo.waitSemaphoreCount = 2; + submitInfo.pWaitSemaphores = waitSemaphores; + submitInfo.pWaitDstStageMask = waitStages; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &Instance::instance->commandPool->graphicsBuffer; + + VkSemaphore signalSemaphores[] = {renderFinished->handle}; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = signalSemaphores; + + vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, renderInFlight->handle); + + VkPresentInfoKHR presentInfo {}; + presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + presentInfo.waitSemaphoreCount = 1; + presentInfo.pWaitSemaphores = signalSemaphores; + + VkSwapchainKHR swapchains[] = {swapchain->handle}; + presentInfo.swapchainCount = 1; + presentInfo.pSwapchains = swapchains; + presentInfo.pImageIndices = &imageIndex; + + result = vkQueuePresentKHR(Instance::instance->presentQueue, &presentInfo); + if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || Instance::instance->windowResized){ + Instance::instance->windowResized = false; + swapchain->recreateSwapchain(); + } +} + +void Application::update() { + vkWaitForFences(Instance::GetDevice(), 1, &computeInFlight->handle, VK_TRUE, UINT64_MAX); + vkResetFences(Instance::GetDevice(), 1, &computeInFlight->handle); + + + VkCommandBuffer cmdBuffer = Instance::instance->commandPool->computeBuffer; + vkResetCommandBuffer(cmdBuffer, 0); + + VkCommandBufferBeginInfo beginInfo {}; + beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + beginInfo.flags = 0; + + vkBeginCommandBuffer(cmdBuffer, &beginInfo); + recordComputeCommands(cmdBuffer); + vkEndCommandBuffer(cmdBuffer); + + VkSubmitInfo submit {}; + submit.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit.commandBufferCount = 1; + submit.pCommandBuffers = &Instance::instance->commandPool->computeBuffer; + submit.signalSemaphoreCount = 1; + submit.pSignalSemaphores = &computeFinished->handle; + + vkQueueSubmit(Instance::instance->computeQueue, 1, &submit, computeInFlight->handle); +} + +void Application::recordDrawCommands() { VkCommandBuffer cmdBuffer = Instance::instance->commandPool->graphicsBuffer; + vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline->handle); + VkBuffer buffers[] = {vertexBuffer->handle}; VkDeviceSize offsets[] = {0}; vkCmdBindVertexBuffers(cmdBuffer, 0, 1, buffers, offsets); @@ -175,7 +386,7 @@ void Simulation::recordDrawCommands() { } } -void Simulation::recordComputeCommands(VkCommandBuffer cmdBuffer) { +void Application::recordComputeCommands(VkCommandBuffer cmdBuffer) { #define BlOCK_SIZE 32 auto getGroupCount = [](uint32_t threads, uint32_t blockSize){ @@ -250,35 +461,9 @@ void Simulation::recordComputeCommands(VkCommandBuffer cmdBuffer) { vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr); } -void Simulation::createComputePipelines() { - vector layouts; - vector pushRanges; - { - layouts.push_back(descriptorPool->layouts[DescriptorSet::MESH]); - layouts.push_back(descriptorPool->layouts[DescriptorSet::SIMULATION]); - pushRanges.push_back({ - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - .offset = 0, - .size = sizeof(PBDPushData) - }); - pbdPipeline = unique_ptr(new ComputePipeline("shaders/pbd.spv", layouts, pushRanges)); - } - layouts.clear(); - pushRanges.clear(); - { - layouts.push_back(descriptorPool->layouts[DescriptorSet::MESH]); - pushRanges.push_back({ - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - .offset = 0, - .size = sizeof(uint32_t) - }); - normalPipeline = unique_ptr(new ComputePipeline("shaders/normal.spv", layouts, pushRanges)); - } -} -Simulation::~Simulation() = default; diff --git a/src/main.cpp b/src/main.cpp index 3900f57..ef61dcf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ -#include "simulation.hpp" - -#include +#include "application.hpp" +#include "vulkan/instance.hpp" +#include "input.hpp" int main() { - Simulation simulation; - simulation.mainLoop(); + Instance instance; + Input input(Instance::instance->window); + Application application; + application.mainLoop(); } diff --git a/src/vulkan/application.cpp b/src/vulkan/application.cpp deleted file mode 100644 index 48d7973..0000000 --- a/src/vulkan/application.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "application.hpp" -#include "vulkan/swapchain.hpp" -#include "vulkan/pipeline.hpp" -#include "vulkan/instance.hpp" -#include "vulkan/buffer.hpp" -#include "vulkan/command_pool.hpp" -#include "vulkan/image.hpp" -#include "vulkan/synchronization.hpp" -#include "camera.hpp" -#include "input.hpp" -#include "vulkan/descriptor_pool.hpp" - -Application::Application() { - new Instance; - new Input(Instance::instance->window); - - createSyncObjects(); - swapchain = new Swapchain(); - descriptorPool = new DescriptorPool(); - graphicsPipeline = new GraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", - swapchain->renderPass, - {descriptorPool->layouts[DescriptorSet::WORLD]}); - - VkDeviceSize bufferSize = sizeof(UniformBufferObject); - - uniformBuffer = new Buffer(bufferSize, - VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, - VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, - VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); - - descriptorPool->bindBuffer(*uniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorSet::WORLD, 0); - camera = new Camera(swapchain->extent); -} - -void Application::updateUniformBuffer() { - static float elapsed = 0; - - elapsed += 0.007; - - UniformBufferObject ubo {}; - ubo.model = glm::mat4(1); - ubo.view = camera->view(); - ubo.projection = camera->projection(); - ubo.projection[1][1] *= -1; - - memcpy(uniformBuffer->allocationInfo.pMappedData, &ubo, sizeof(UniformBufferObject)); -} - -void Application::recordGraphicsCommandBuffer(uint32_t imageIndex) { - VkCommandBuffer cmdBuffer = Instance::instance->commandPool->graphicsBuffer; - - VkCommandBufferBeginInfo beginInfo {}; - beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - - vkBeginCommandBuffer(cmdBuffer, &beginInfo); - - VkRenderPassBeginInfo renderPassInfo {}; - renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - renderPassInfo.renderPass = swapchain->renderPass; - renderPassInfo.framebuffer = swapchain->frameBuffers[imageIndex]; - renderPassInfo.renderArea.offset = {0, 0}; - renderPassInfo.renderArea.extent = swapchain->extent; - - VkClearValue clearValues[2] {}; - clearValues[0].color = {{0, 0, 0, 1}}; - clearValues[1].depthStencil = {1.0f, 0}; - - renderPassInfo.clearValueCount = 2; - renderPassInfo.pClearValues = clearValues; - - vkCmdBeginRenderPass(cmdBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); - vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline->handle); - - VkViewport viewport {}; - viewport.x = 0; - viewport.y = 0; - viewport.width = static_cast(swapchain->extent.width); - viewport.height = static_cast(swapchain->extent.height); - viewport.minDepth = 0; - viewport.maxDepth = 1; - vkCmdSetViewport(cmdBuffer, 0, 1, &viewport); - - VkRect2D scissor {}; - scissor.offset = {0, 0}; - scissor.extent = swapchain->extent; - vkCmdSetScissor(cmdBuffer, 0, 1, &scissor); - - recordDrawCommands(); - - vkCmdEndRenderPass(cmdBuffer); - vkEndCommandBuffer(cmdBuffer); -} - -void Application::createSyncObjects() { - imageAvailable = new Semaphore; - renderFinished = new Semaphore; - computeFinished = new Semaphore; - renderInFlight = new Fence(true); - computeInFlight = new Fence(true); -} - -void Application::mainLoop() { - while (!glfwWindowShouldClose(Instance::instance->window)){ - glfwPollEvents(); - update(); - drawFrame(); - } - vkDeviceWaitIdle(Instance::instance->device); -} - -void Application::drawFrame() { - vkWaitForFences(Instance::instance->device, 1, &renderInFlight->handle, VK_TRUE, UINT64_MAX); - - uint32_t imageIndex; - VkResult result = vkAcquireNextImageKHR(Instance::instance->device, swapchain->handle, UINT64_MAX, imageAvailable->handle, VK_NULL_HANDLE, &imageIndex); - if (result == VK_ERROR_OUT_OF_DATE_KHR){ - swapchain->recreateSwapchain(); - return; - } - - vkResetFences(Instance::instance->device, 1, &renderInFlight->handle); - - vkResetCommandBuffer(Instance::instance->commandPool->graphicsBuffer, 0); - recordGraphicsCommandBuffer(imageIndex); - - camera->update(0.017); - updateUniformBuffer(); - - VkSubmitInfo submitInfo {}; - submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - - VkSemaphore waitSemaphores[] = {imageAvailable->handle, computeFinished->handle}; - VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT}; - submitInfo.waitSemaphoreCount = 2; - submitInfo.pWaitSemaphores = waitSemaphores; - submitInfo.pWaitDstStageMask = waitStages; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &Instance::instance->commandPool->graphicsBuffer; - - VkSemaphore signalSemaphores[] = {renderFinished->handle}; - submitInfo.signalSemaphoreCount = 1; - submitInfo.pSignalSemaphores = signalSemaphores; - - vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, renderInFlight->handle); - - VkPresentInfoKHR presentInfo {}; - presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - presentInfo.waitSemaphoreCount = 1; - presentInfo.pWaitSemaphores = signalSemaphores; - - VkSwapchainKHR swapchains[] = {swapchain->handle}; - presentInfo.swapchainCount = 1; - presentInfo.pSwapchains = swapchains; - presentInfo.pImageIndices = &imageIndex; - - result = vkQueuePresentKHR(Instance::instance->presentQueue, &presentInfo); - if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || Instance::instance->windowResized){ - Instance::instance->windowResized = false; - swapchain->recreateSwapchain(); - } -} - -void Application::update() { - vkWaitForFences(Instance::instance->device, 1, &computeInFlight->handle, VK_TRUE, UINT64_MAX); - vkResetFences(Instance::instance->device, 1, &computeInFlight->handle); - - - VkCommandBuffer cmdBuffer = Instance::instance->commandPool->computeBuffer; - vkResetCommandBuffer(cmdBuffer, 0); - - VkCommandBufferBeginInfo beginInfo {}; - beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - beginInfo.flags = 0; - - vkBeginCommandBuffer(cmdBuffer, &beginInfo); - recordComputeCommands(cmdBuffer); - vkEndCommandBuffer(cmdBuffer); - - VkSubmitInfo submit {}; - submit.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit.commandBufferCount = 1; - submit.pCommandBuffers = &Instance::instance->commandPool->computeBuffer; - submit.signalSemaphoreCount = 1; - submit.pSignalSemaphores = &computeFinished->handle; - - vkQueueSubmit(Instance::instance->computeQueue, 1, &submit, computeInFlight->handle); -} - -Application::~Application() { - delete swapchain; - delete descriptorPool; - delete imageAvailable; - delete renderFinished; - delete computeFinished; - delete renderInFlight; - delete computeInFlight; - delete uniformBuffer; - delete graphicsPipeline; - delete camera; - delete Instance::instance; -} - - - - diff --git a/src/vulkan/buffer.cpp b/src/vulkan/buffer.cpp index 2a08d26..4a7fe29 100644 --- a/src/vulkan/buffer.cpp +++ b/src/vulkan/buffer.cpp @@ -17,7 +17,7 @@ Buffer::Buffer(VkDeviceSize size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage allocationCreateInfo.usage = memoryUsage; allocationCreateInfo.flags = flags; - vmaCreateBuffer(Instance::instance->allocator, &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); + vmaCreateBuffer(Instance::GetAllocator(), &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); } Buffer::Buffer(VkDeviceSize size, void *data, VkDeviceSize dataSize, VkBufferUsageFlags bufferUsage, @@ -36,7 +36,7 @@ Buffer::Buffer(VkDeviceSize size, void *data, VkDeviceSize dataSize, VkBufferUsa } Buffer::~Buffer() { - vmaDestroyBuffer(Instance::instance->allocator, handle, allocation); + vmaDestroyBuffer(Instance::GetAllocator(), handle, allocation); } void Buffer::copyTo(Buffer *dst) { @@ -47,7 +47,7 @@ void Buffer::copyTo(Buffer *dst) { allocateInfo.commandBufferCount = 1; VkCommandBuffer commandBuffer; - vkAllocateCommandBuffers(Instance::instance->device, &allocateInfo, &commandBuffer); + vkAllocateCommandBuffers(Instance::GetDevice(), &allocateInfo, &commandBuffer); VkCommandBufferBeginInfo beginInfo {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -65,7 +65,7 @@ void Buffer::copyTo(Buffer *dst) { submitInfo.pCommandBuffers = &commandBuffer; vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); - vkDeviceWaitIdle(Instance::instance->device); + vkDeviceWaitIdle(Instance::GetDevice()); - vkFreeCommandBuffers(Instance::instance->device, Instance::instance->commandPool->handle, 1, &commandBuffer); + vkFreeCommandBuffers(Instance::GetDevice(), Instance::instance->commandPool->handle, 1, &commandBuffer); } diff --git a/src/vulkan/command_pool.cpp b/src/vulkan/command_pool.cpp index 0c4ad7f..b41f103 100644 --- a/src/vulkan/command_pool.cpp +++ b/src/vulkan/command_pool.cpp @@ -2,15 +2,15 @@ #include "application.hpp" #include "vulkan/instance.hpp" -CommandPool::CommandPool() { - Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(Instance::instance->physicalDevice, Instance::instance->surface); +CommandPool::CommandPool(VkSurfaceKHR surface) { + Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(Instance::GetPhysicalDevice(), surface); VkCommandPoolCreateInfo poolInfo {}; poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; poolInfo.queueFamilyIndex = indices.graphicsAndComputeFamily.value(); - vkCreateCommandPool(Instance::instance->device, &poolInfo, nullptr, &handle); + vkCreateCommandPool(Instance::GetDevice(), &poolInfo, nullptr, &handle); createBuffers(); } @@ -22,12 +22,12 @@ void CommandPool::createBuffers() { allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.commandBufferCount = 1; - vkAllocateCommandBuffers(Instance::instance->device, &allocateInfo, &graphicsBuffer); - vkAllocateCommandBuffers(Instance::instance->device, &allocateInfo, &computeBuffer); + vkAllocateCommandBuffers(Instance::GetDevice(), &allocateInfo, &graphicsBuffer); + vkAllocateCommandBuffers(Instance::GetDevice(), &allocateInfo, &computeBuffer); } CommandPool::~CommandPool() { - vkFreeCommandBuffers(Instance::instance->device, handle, 1, &graphicsBuffer); - vkFreeCommandBuffers(Instance::instance->device, handle, 1, &computeBuffer); - vkDestroyCommandPool(Instance::instance->device, handle, nullptr); + vkFreeCommandBuffers(Instance::GetDevice(), handle, 1, &graphicsBuffer); + vkFreeCommandBuffers(Instance::GetDevice(), handle, 1, &computeBuffer); + vkDestroyCommandPool(Instance::GetDevice(), handle, nullptr); } diff --git a/src/vulkan/descriptor_pool.cpp b/src/vulkan/descriptor_pool.cpp index 12178fa..0fa7b74 100644 --- a/src/vulkan/descriptor_pool.cpp +++ b/src/vulkan/descriptor_pool.cpp @@ -15,7 +15,7 @@ DescriptorPool::DescriptorPool() { poolInfo.poolSizeCount = sizeof(poolSizes) / sizeof(VkDescriptorPoolSize); poolInfo.maxSets = 10; - vkCreateDescriptorPool(Instance::instance->device, &poolInfo, nullptr, &handle); + vkCreateDescriptorPool(Instance::GetDevice(), &poolInfo, nullptr, &handle); std::map> setBindings; auto addBinding = [&setBindings](DescriptorSet set, VkDescriptorType type, VkShaderStageFlags stageFlags){ @@ -62,14 +62,14 @@ DescriptorPool::DescriptorPool() { allocateInfo.descriptorSetCount = 1; allocateInfo.pSetLayouts = &layout; - vkAllocateDescriptorSets(Instance::instance->device, &allocateInfo, &sets[set]); + vkAllocateDescriptorSets(Instance::GetDevice(), &allocateInfo, &sets[set]); } } DescriptorPool::~DescriptorPool() { - vkDestroyDescriptorPool(Instance::instance->device, handle, nullptr); + vkDestroyDescriptorPool(Instance::GetDevice(), handle, nullptr); for (const auto &[type, layout] : layouts) - vkDestroyDescriptorSetLayout(Instance::instance->device, layout, nullptr); + vkDestroyDescriptorSetLayout(Instance::GetDevice(), layout, nullptr); } void DescriptorPool::bindBuffer(const Buffer& buffer, VkDescriptorType type, DescriptorSet set, uint32_t binding) { @@ -87,7 +87,7 @@ void DescriptorPool::bindBuffer(const Buffer& buffer, VkDescriptorType type, Des descriptorWrite.descriptorCount = 1; descriptorWrite.pBufferInfo = &bufferInfo; - vkUpdateDescriptorSets(Instance::instance->device, 1, &descriptorWrite, 0, nullptr); + vkUpdateDescriptorSets(Instance::GetDevice(), 1, &descriptorWrite, 0, nullptr); } void DescriptorPool::createLayout(DescriptorSet set, const std::vector &bindings) { @@ -96,5 +96,5 @@ void DescriptorPool::createLayout(DescriptorSet set, const std::vectordevice, &layoutCreateInfo, nullptr, &layouts[set]); + vkCreateDescriptorSetLayout(Instance::GetDevice(), &layoutCreateInfo, nullptr, &layouts[set]); } diff --git a/src/vulkan/image.cpp b/src/vulkan/image.cpp index f3c83e1..179f8a2 100644 --- a/src/vulkan/image.cpp +++ b/src/vulkan/image.cpp @@ -24,13 +24,13 @@ Image::Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling til allocationCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; allocationCreateInfo.flags = 0; - vmaCreateImage(Instance::instance->allocator, &imageCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); + vmaCreateImage(Instance::GetAllocator(), &imageCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); } Image::~Image() { if (view) - vkDestroyImageView(Instance::instance->device, view, nullptr); - vmaDestroyImage(Instance::instance->allocator, handle, allocation); + vkDestroyImageView(Instance::GetDevice(), view, nullptr); + vmaDestroyImage(Instance::GetAllocator(), handle, allocation); } VkImageView Image::createView(VkFormat format, VkImageAspectFlags aspectFlags) { @@ -48,7 +48,7 @@ VkImageView Image::createView(VkFormat format, VkImageAspectFlags aspectFlags) { createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; createInfo.subresourceRange = subresourceRange; - vkCreateImageView(Instance::instance->device, &createInfo, nullptr, &view); + vkCreateImageView(Instance::GetDevice(), &createInfo, nullptr, &view); return view; } diff --git a/src/vulkan/instance.cpp b/src/vulkan/instance.cpp index f798682..1379caf 100644 --- a/src/vulkan/instance.cpp +++ b/src/vulkan/instance.cpp @@ -59,7 +59,7 @@ Instance::Instance() { pickPhysicalDevice(); createLogicalDevice(); createAllocator(); - commandPool = new CommandPool; + commandPool = new CommandPool(surface); } void Instance::initWindow() { @@ -254,6 +254,22 @@ bool Instance::checkDeviceExtensionSupport(VkPhysicalDevice device) { return required.empty(); } +VkDevice Instance::GetDevice() { + return instance->device; +} + +VkPhysicalDevice Instance::GetPhysicalDevice() { + return instance->physicalDevice; +} + +VmaAllocator Instance::GetAllocator() { + return instance->allocator; +} + +VkSurfaceKHR Instance::GetSurface() { + return instance->surface; +} + Instance::~Instance() { delete commandPool; vmaDestroyAllocator(allocator); diff --git a/src/vulkan/pipeline.cpp b/src/vulkan/pipeline.cpp index d071aed..60b06ff 100644 --- a/src/vulkan/pipeline.cpp +++ b/src/vulkan/pipeline.cpp @@ -28,7 +28,7 @@ VkShaderModule Pipeline::createShaderModule(const std::vector &code) { createInfo.pCode = reinterpret_cast(code.data()); VkShaderModule shaderModule; - vkCreateShaderModule(Instance::instance->device, &createInfo, nullptr, &shaderModule); + vkCreateShaderModule(Instance::GetDevice(), &createInfo, nullptr, &shaderModule); return shaderModule; } @@ -42,12 +42,12 @@ Pipeline::Pipeline(const std::vector &descriptorSetLayout pipelineLayoutInfo.pushConstantRangeCount = pushConstantRanges.size(); pipelineLayoutInfo.pPushConstantRanges = pushConstantRanges.data(); - vkCreatePipelineLayout(Instance::instance->device, &pipelineLayoutInfo, nullptr, &layout); + vkCreatePipelineLayout(Instance::GetDevice(), &pipelineLayoutInfo, nullptr, &layout); } Pipeline::~Pipeline() { - vkDestroyPipelineLayout(Instance::instance->device, layout, nullptr); - vkDestroyPipeline(Instance::instance->device, handle, nullptr); + vkDestroyPipelineLayout(Instance::GetDevice(), layout, nullptr); + vkDestroyPipeline(Instance::GetDevice(), handle, nullptr); } @@ -160,10 +160,10 @@ GraphicsPipeline::GraphicsPipeline(const std::string& vertexShaderPath, const st pipelineInfo.subpass = 0; } - vkCreateGraphicsPipelines(Instance::instance->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &handle); + vkCreateGraphicsPipelines(Instance::GetDevice(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &handle); - vkDestroyShaderModule(Instance::instance->device, vertShaderModule, nullptr); - vkDestroyShaderModule(Instance::instance->device, fragShaderModule, nullptr); + vkDestroyShaderModule(Instance::GetDevice(), vertShaderModule, nullptr); + vkDestroyShaderModule(Instance::GetDevice(), fragShaderModule, nullptr); } ComputePipeline::ComputePipeline(const std::string& shaderFile, @@ -182,9 +182,9 @@ ComputePipeline::ComputePipeline(const std::string& shaderFile, pipelineInfo.layout = layout; pipelineInfo.stage = stageInfo; - vkCreateComputePipelines(Instance::instance->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &handle); + vkCreateComputePipelines(Instance::GetDevice(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &handle); - vkDestroyShaderModule(Instance::instance->device, module, nullptr); + vkDestroyShaderModule(Instance::GetDevice(), module, nullptr); } diff --git a/src/vulkan/swapchain.cpp b/src/vulkan/swapchain.cpp index 2fcb0fe..8956981 100644 --- a/src/vulkan/swapchain.cpp +++ b/src/vulkan/swapchain.cpp @@ -36,7 +36,7 @@ Swapchain::Swapchain() { Swapchain::~Swapchain() { cleanupSwapchain(); - vkDestroyRenderPass(Instance::instance->device, renderPass, nullptr); + vkDestroyRenderPass(Instance::GetDevice(), renderPass, nullptr); } VkExtent2D Swapchain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities) { @@ -59,7 +59,7 @@ VkExtent2D Swapchain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilit } void Swapchain::createSwapchain() { - SwapchainSupportDetails swapchainSupport = querySwapchainSupport(Instance::instance->physicalDevice, Instance::instance->surface); + SwapchainSupportDetails swapchainSupport = querySwapchainSupport(Instance::GetPhysicalDevice(), Instance::GetSurface()); VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapchainSupport.formats); VkPresentModeKHR presentMode = chooseSwapPresentMode(swapchainSupport.presentModes); @@ -72,7 +72,7 @@ void Swapchain::createSwapchain() { VkSwapchainCreateInfoKHR createInfo {}; createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - createInfo.surface = Instance::instance->surface; + createInfo.surface = Instance::GetSurface(); createInfo.minImageCount = imageCount; createInfo.imageFormat = surfaceFormat.format; createInfo.imageColorSpace = surfaceFormat.colorSpace; @@ -80,7 +80,7 @@ void Swapchain::createSwapchain() { createInfo.imageArrayLayers = 1; createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(Instance::instance->physicalDevice, Instance::instance->surface); + Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(Instance::GetPhysicalDevice(), Instance::GetSurface()); uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()}; if (indices.graphicsFamily != indices.presentFamily){ @@ -97,28 +97,28 @@ void Swapchain::createSwapchain() { createInfo.clipped = VK_TRUE; createInfo.oldSwapchain = VK_NULL_HANDLE; - vkCreateSwapchainKHR(Instance::instance->device, &createInfo, nullptr, &handle); + vkCreateSwapchainKHR(Instance::GetDevice(), &createInfo, nullptr, &handle); - vkGetSwapchainImagesKHR(Instance::instance->device, handle, &imageCount, nullptr); + vkGetSwapchainImagesKHR(Instance::GetDevice(), handle, &imageCount, nullptr); images.resize(imageCount); - vkGetSwapchainImagesKHR(Instance::instance->device, handle, &imageCount, images.data()); + vkGetSwapchainImagesKHR(Instance::GetDevice(), handle, &imageCount, images.data()); imageFormat = surfaceFormat.format; } void Swapchain::cleanupSwapchain() { for (auto framebuffer : frameBuffers){ - vkDestroyFramebuffer(Instance::instance->device, framebuffer, nullptr); + vkDestroyFramebuffer(Instance::GetDevice(), framebuffer, nullptr); } for (auto imageView : imageViews){ - vkDestroyImageView(Instance::instance->device, imageView, nullptr); + vkDestroyImageView(Instance::GetDevice(), imageView, nullptr); } delete depthImage; - vkDestroySwapchainKHR(Instance::instance->device, handle, nullptr); + vkDestroySwapchainKHR(Instance::GetDevice(), handle, nullptr); } void Swapchain::recreateSwapchain() { - vkDeviceWaitIdle(Instance::instance->device); + vkDeviceWaitIdle(Instance::GetDevice()); cleanupSwapchain(); @@ -143,7 +143,7 @@ void Swapchain::createImageViews() { VK_COMPONENT_SWIZZLE_IDENTITY, }; createInfo.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; - vkCreateImageView(Instance::instance->device, &createInfo, nullptr, &imageViews[i]); + vkCreateImageView(Instance::GetDevice(), &createInfo, nullptr, &imageViews[i]); } } @@ -201,7 +201,7 @@ void Swapchain::createRenderpass() { renderPassInfo.dependencyCount = 1; renderPassInfo.pDependencies = &dependency; - vkCreateRenderPass(Instance::instance->device, &renderPassInfo, nullptr, &renderPass); + vkCreateRenderPass(Instance::GetDevice(), &renderPassInfo, nullptr, &renderPass); } void Swapchain::createDepthResources() { @@ -232,7 +232,7 @@ void Swapchain::createFramebuffers() { framebufferInfo.height = extent.height; framebufferInfo.layers = 1; - vkCreateFramebuffer(Instance::instance->device, &framebufferInfo, nullptr, &frameBuffers[i]); + vkCreateFramebuffer(Instance::GetDevice(), &framebufferInfo, nullptr, &frameBuffers[i]); } } diff --git a/src/vulkan/synchronization.cpp b/src/vulkan/synchronization.cpp index 6bf4fee..876e7fd 100644 --- a/src/vulkan/synchronization.cpp +++ b/src/vulkan/synchronization.cpp @@ -5,11 +5,11 @@ Semaphore::Semaphore() { VkSemaphoreCreateInfo semaphoreInfo {}; semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &handle); + vkCreateSemaphore(Instance::GetDevice(), &semaphoreInfo, nullptr, &handle); } Semaphore::~Semaphore() { - vkDestroySemaphore(Instance::instance->device, handle, nullptr); + vkDestroySemaphore(Instance::GetDevice(), handle, nullptr); } Fence::Fence(bool signaled) { @@ -17,9 +17,9 @@ Fence::Fence(bool signaled) { fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceInfo.flags = signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0; - vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &handle); + vkCreateFence(Instance::GetDevice(), &fenceInfo, nullptr, &handle); } Fence::~Fence() { - vkDestroyFence(Instance::instance->device, handle, nullptr); + vkDestroyFence(Instance::GetDevice(), handle, nullptr); }