From 09790c4cbdf5df597c70dd23150b335556d4fb27 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 26 Jan 2024 16:26:22 +0100 Subject: [PATCH] Adding some barriers --- src/Engine/Graphics/RenderPass/DebugPass.cpp | 1 - src/Engine/Graphics/RenderPass/RenderPass.cpp | 5 ++++ src/Engine/Graphics/VertexData.cpp | 12 +++++++++ src/Engine/Graphics/Vulkan/Graphics.cpp | 25 ++++++++++--------- src/Engine/Graphics/Vulkan/Graphics.h | 10 +++++--- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index 034e55a..b01b602 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -124,7 +124,6 @@ void DebugPass::createRenderPass() gfxInfo.vertexShader = vertexShader; gfxInfo.fragmentShader = fragmentShader; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE; - gfxInfo.rasterizationState.lineWidth = 5.f; gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST; gfxInfo.pipelineLayout = std::move(pipelineLayout); gfxInfo.renderPass = renderPass; diff --git a/src/Engine/Graphics/RenderPass/RenderPass.cpp b/src/Engine/Graphics/RenderPass/RenderPass.cpp index abe5c9c..d6c4c12 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/RenderPass.cpp @@ -36,6 +36,11 @@ void RenderPass::beginFrame(const Component::Camera& cam) .data = (uint8*)&viewParams, }; viewParamsBuffer->updateContents(uniformUpdate); + viewParamsBuffer->pipelineBarrier( + Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, + Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, + Gfx::SE_ACCESS_MEMORY_READ_BIT, + Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT); viewParamsLayout->reset(); viewParamsSet = viewParamsLayout->allocateDescriptorSet(); viewParamsSet->updateBuffer(0, viewParamsBuffer); diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 9b17646..42b4082 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -72,6 +72,12 @@ void VertexData::createDescriptors() .numElements = instanceData.size(), .dynamic = false, }); + matInst.instanceBuffer->pipelineBarrier( + Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, + Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, + Gfx::SE_ACCESS_MEMORY_READ_BIT, + Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT + ); matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet(); matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ @@ -82,6 +88,12 @@ void VertexData::createDescriptors() .numElements = meshes.size(), .dynamic = false, }); + matInst.meshDataBuffer->pipelineBarrier( + Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, + Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, + Gfx::SE_ACCESS_MEMORY_READ_BIT, + Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT + ); matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer); matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer); matInst.descriptorSet->updateBuffer(2, meshletBuffer); diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 62e1bbc..5b32831 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -19,10 +19,10 @@ using namespace Seele; using namespace Seele::Vulkan; -thread_local OCommandPool Seele::Vulkan::Graphics::graphicsCommands = nullptr; -thread_local OCommandPool Seele::Vulkan::Graphics::computeCommands = nullptr; -thread_local OCommandPool Seele::Vulkan::Graphics::transferCommands = nullptr; -thread_local OCommandPool Seele::Vulkan::Graphics::dedicatedTransferCommands = nullptr; +thread_local PCommandPool Seele::Vulkan::Graphics::graphicsCommands = nullptr; +thread_local PCommandPool Seele::Vulkan::Graphics::computeCommands = nullptr; +thread_local PCommandPool Seele::Vulkan::Graphics::transferCommands = nullptr; +thread_local PCommandPool Seele::Vulkan::Graphics::dedicatedTransferCommands = nullptr; Graphics::Graphics() : instance(VK_NULL_HANDLE) @@ -35,15 +35,12 @@ Graphics::Graphics() Graphics::~Graphics() { vkDeviceWaitIdle(handle); - graphicsCommands = nullptr; - computeCommands = nullptr; - transferCommands = nullptr; - dedicatedTransferCommands = nullptr; pipelineCache = nullptr; allocator = nullptr; destructionManager = nullptr; allocatedFramebuffers.clear(); shaderCompiler = nullptr; + pools.clear(); vkDestroyDevice(handle, nullptr); DestroyDebugReportCallbackEXT(instance, nullptr, callback); vkDestroyInstance(instance, nullptr); @@ -315,7 +312,8 @@ PCommandPool Graphics::getGraphicsCommands() { if(graphicsCommands == nullptr) { - graphicsCommands = new CommandPool(this, graphicsQueue); + std::unique_lock l(poolLock); + graphicsCommands = pools.add(new CommandPool(this, graphicsQueue)); } return graphicsCommands; } @@ -323,7 +321,8 @@ PCommandPool Graphics::getComputeCommands() { if(computeCommands == nullptr) { - computeCommands = new CommandPool(this, computeQueue); + std::unique_lock l(poolLock); + computeCommands = pools.add(new CommandPool(this, computeQueue)); } return computeCommands; } @@ -331,7 +330,8 @@ PCommandPool Graphics::getTransferCommands() { if(transferCommands == nullptr) { - transferCommands = new CommandPool(this, transferQueue); + std::unique_lock l(poolLock); + transferCommands = pools.add(new CommandPool(this, transferQueue)); } return transferCommands; } @@ -339,7 +339,8 @@ PCommandPool Graphics::getDedicatedTransferCommands() { if(dedicatedTransferCommands == nullptr) { - dedicatedTransferCommands = new CommandPool(this, dedicatedTransferQueue != nullptr ? dedicatedTransferQueue : transferQueue); + std::unique_lock l(poolLock); + dedicatedTransferCommands = pools.add(new CommandPool(this, dedicatedTransferQueue != nullptr ? dedicatedTransferQueue : transferQueue)); } return dedicatedTransferCommands; } diff --git a/src/Engine/Graphics/Vulkan/Graphics.h b/src/Engine/Graphics/Vulkan/Graphics.h index 6980123..43feea7 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.h +++ b/src/Engine/Graphics/Vulkan/Graphics.h @@ -88,10 +88,12 @@ protected: OQueue computeQueue; OQueue transferQueue; OQueue dedicatedTransferQueue; - thread_local static OCommandPool graphicsCommands; - thread_local static OCommandPool computeCommands; - thread_local static OCommandPool transferCommands; - thread_local static OCommandPool dedicatedTransferCommands; + thread_local static PCommandPool graphicsCommands; + thread_local static PCommandPool computeCommands; + thread_local static PCommandPool transferCommands; + thread_local static PCommandPool dedicatedTransferCommands; + std::mutex poolLock; + Array pools; VkPhysicalDeviceProperties props; VkPhysicalDeviceFeatures2 features; VkPhysicalDeviceVulkan11Features features11;