From 17f8027cc97337b6e533067b72e5d82fc975f9f9 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 12 May 2023 03:30:40 +0200 Subject: [PATCH] Create RenderState buffers for each thread --- .../rendering/vulkan/buffers/vk_buffer.cpp | 177 ++++++++++-------- .../rendering/vulkan/buffers/vk_buffer.h | 44 +++-- .../rendering/vulkan/buffers/vk_hwbuffer.cpp | 33 ---- .../vulkan/buffers/vk_streambuffer.cpp | 8 +- .../vulkan/buffers/vk_streambuffer.h | 5 +- .../vulkan/commands/vk_commandbuffer.cpp | 2 +- .../vulkan/commands/vk_commandbuffer.h | 2 +- .../descriptorsets/vk_descriptorset.cpp | 60 +++--- .../vulkan/descriptorsets/vk_descriptorset.h | 17 +- .../vulkan/pipelines/vk_renderpass.cpp | 2 +- .../rendering/vulkan/vk_renderdevice.cpp | 2 +- src/common/rendering/vulkan/vk_renderdevice.h | 2 + .../rendering/vulkan/vk_renderstate.cpp | 86 ++++----- src/common/rendering/vulkan/vk_renderstate.h | 7 +- 14 files changed, 213 insertions(+), 234 deletions(-) diff --git a/src/common/rendering/vulkan/buffers/vk_buffer.cpp b/src/common/rendering/vulkan/buffers/vk_buffer.cpp index 738b83e29c..bb8a4d5d5a 100644 --- a/src/common/rendering/vulkan/buffers/vk_buffer.cpp +++ b/src/common/rendering/vulkan/buffers/vk_buffer.cpp @@ -40,69 +40,10 @@ VkBufferManager::~VkBufferManager() void VkBufferManager::Init() { - static const FVertexBufferAttribute format[] = + for (int threadIndex = 0; threadIndex < fb->MaxThreads; threadIndex++) { - { 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) }, - { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) }, - { 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) }, - }; - - Flatbuffer.VertexFormat = fb->GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format); - - Flatbuffer.VertexBuffer = BufferBuilder() - .Usage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) - .MemoryType( - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .Size(Flatbuffer.BUFFER_SIZE * sizeof(FFlatVertex)) - .DebugName("Flatbuffer.VertexBuffer") - .Create(fb->GetDevice()); - - Flatbuffer.Vertices = (FFlatVertex*)Flatbuffer.VertexBuffer->Map(0, Flatbuffer.VertexBuffer->size); - - Flatbuffer.IndexBuffer = BufferBuilder() - .Usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY) - .Size(16) - .DebugName("Flatbuffer.IndexBuffer") - .Create(fb->GetDevice()); - - MatrixBuffer.reset(new VkStreamBuffer(this, sizeof(MatricesUBO), 50000)); - StreamBuffer.reset(new VkStreamBuffer(this, sizeof(StreamUBO), 300)); - - Viewpoint.BlockAlign = (sizeof(HWViewpointUniforms) + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment; - - Viewpoint.UBO = BufferBuilder() - .Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) - .MemoryType( - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .Size(Viewpoint.Count * Viewpoint.BlockAlign) - .DebugName("Viewpoint.UBO") - .Create(fb->GetDevice()); - - Viewpoint.Data = Viewpoint.UBO->Map(0, Viewpoint.UBO->size); - - Lightbuffer.UBO = BufferBuilder() - .Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) - .MemoryType( - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .Size(Lightbuffer.Count * 4 * sizeof(FVector4)) - .DebugName("Lightbuffer.UBO") - .Create(fb->GetDevice()); - - Lightbuffer.Data = Lightbuffer.UBO->Map(0, Lightbuffer.UBO->size); - - Bonebuffer.SSO = BufferBuilder() - .Usage(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) - .MemoryType( - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .Size(Bonebuffer.Count * sizeof(VSMatrix)) - .DebugName("Bonebuffer.SSO") - .Create(fb->GetDevice()); - - Bonebuffer.Data = Bonebuffer.SSO->Map(0, Bonebuffer.SSO->size); + RSBuffers.push_back(std::make_unique(fb)); + } Shadowmap.Nodes.reset(new VkHardwareDataBuffer(fb, true, false)); Shadowmap.Lines.reset(new VkHardwareDataBuffer(fb, true, false)); @@ -113,22 +54,7 @@ void VkBufferManager::Init() void VkBufferManager::Deinit() { - if (Flatbuffer.VertexBuffer) - Flatbuffer.VertexBuffer->Unmap(); - Flatbuffer.VertexBuffer.reset(); - Flatbuffer.IndexBuffer.reset(); - - if (Viewpoint.UBO) - Viewpoint.UBO->Unmap(); - Viewpoint.UBO.reset(); - - if (Lightbuffer.UBO) - Lightbuffer.UBO->Unmap(); - Lightbuffer.UBO.reset(); - - if (Bonebuffer.SSO) - Bonebuffer.SSO->Unmap(); - Bonebuffer.SSO.reset(); + RSBuffers.clear(); Shadowmap.Nodes.reset(); Shadowmap.Lines.reset(); @@ -176,9 +102,98 @@ void VkBufferManager::CreateFanToTrisIndexBuffer() ///////////////////////////////////////////////////////////////////////////// -VkStreamBuffer::VkStreamBuffer(VkBufferManager* buffers, size_t structSize, size_t count) +VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb) { - mBlockSize = static_cast((structSize + buffers->fb->uniformblockalignment - 1) / buffers->fb->uniformblockalignment * buffers->fb->uniformblockalignment); + static const FVertexBufferAttribute format[] = + { + { 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) }, + { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) }, + { 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) }, + }; + + Flatbuffer.VertexFormat = fb->GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format); + + Flatbuffer.VertexBuffer = BufferBuilder() + .Usage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) + .MemoryType( + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + .Size(Flatbuffer.BUFFER_SIZE * sizeof(FFlatVertex)) + .DebugName("Flatbuffer.VertexBuffer") + .Create(fb->GetDevice()); + + Flatbuffer.Vertices = (FFlatVertex*)Flatbuffer.VertexBuffer->Map(0, Flatbuffer.VertexBuffer->size); + + Flatbuffer.IndexBuffer = BufferBuilder() + .Usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY) + .Size(16) + .DebugName("Flatbuffer.IndexBuffer") + .Create(fb->GetDevice()); + + MatrixBuffer = std::make_unique(fb, sizeof(MatricesUBO), 50000); + StreamBuffer = std::make_unique(fb, sizeof(StreamUBO), 300); + + Viewpoint.BlockAlign = (sizeof(HWViewpointUniforms) + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment; + + Viewpoint.UBO = BufferBuilder() + .Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) + .MemoryType( + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + .Size(Viewpoint.Count * Viewpoint.BlockAlign) + .DebugName("Viewpoint.UBO") + .Create(fb->GetDevice()); + + Viewpoint.Data = Viewpoint.UBO->Map(0, Viewpoint.UBO->size); + + Lightbuffer.UBO = BufferBuilder() + .Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) + .MemoryType( + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + .Size(Lightbuffer.Count * 4 * sizeof(FVector4)) + .DebugName("Lightbuffer.UBO") + .Create(fb->GetDevice()); + + Lightbuffer.Data = Lightbuffer.UBO->Map(0, Lightbuffer.UBO->size); + + Bonebuffer.SSO = BufferBuilder() + .Usage(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) + .MemoryType( + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + .Size(Bonebuffer.Count * sizeof(VSMatrix)) + .DebugName("Bonebuffer.SSO") + .Create(fb->GetDevice()); + + Bonebuffer.Data = Bonebuffer.SSO->Map(0, Bonebuffer.SSO->size); +} + +VkRSBuffers::~VkRSBuffers() +{ + if (Flatbuffer.VertexBuffer) + Flatbuffer.VertexBuffer->Unmap(); + Flatbuffer.VertexBuffer.reset(); + Flatbuffer.IndexBuffer.reset(); + + if (Viewpoint.UBO) + Viewpoint.UBO->Unmap(); + Viewpoint.UBO.reset(); + + if (Lightbuffer.UBO) + Lightbuffer.UBO->Unmap(); + Lightbuffer.UBO.reset(); + + if (Bonebuffer.SSO) + Bonebuffer.SSO->Unmap(); + Bonebuffer.SSO.reset(); +} + +///////////////////////////////////////////////////////////////////////////// + +VkStreamBuffer::VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count) +{ + mBlockSize = static_cast((structSize + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment); UBO = BufferBuilder() .Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) @@ -187,7 +202,7 @@ VkStreamBuffer::VkStreamBuffer(VkBufferManager* buffers, size_t structSize, size VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) .Size(mBlockSize * count) .DebugName("VkStreamBuffer") - .Create(buffers->fb->GetDevice()); + .Create(fb->GetDevice()); Data = UBO->Map(0, UBO->size); } diff --git a/src/common/rendering/vulkan/buffers/vk_buffer.h b/src/common/rendering/vulkan/buffers/vk_buffer.h index 5465a33b94..17dc6785d1 100644 --- a/src/common/rendering/vulkan/buffers/vk_buffer.h +++ b/src/common/rendering/vulkan/buffers/vk_buffer.h @@ -13,20 +13,11 @@ struct FVertexBufferAttribute; struct HWViewpointUniforms; struct FFlatVertex; -class VkBufferManager +class VkRSBuffers { public: - VkBufferManager(VulkanRenderDevice* fb); - ~VkBufferManager(); - - void Init(); - void Deinit(); - - IBuffer* CreateVertexBuffer(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute* attrs); - IBuffer* CreateIndexBuffer(); - - void AddBuffer(VkHardwareBuffer* buffer); - void RemoveBuffer(VkHardwareBuffer* buffer); + VkRSBuffers(VulkanRenderDevice* fb); + ~VkRSBuffers(); struct { @@ -65,6 +56,27 @@ public: void* Data = nullptr; } Bonebuffer; + std::unique_ptr MatrixBuffer; + std::unique_ptr StreamBuffer; +}; + +class VkBufferManager +{ +public: + VkBufferManager(VulkanRenderDevice* fb); + ~VkBufferManager(); + + void Init(); + void Deinit(); + + IBuffer* CreateVertexBuffer(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute* attrs); + IBuffer* CreateIndexBuffer(); + + void AddBuffer(VkHardwareBuffer* buffer); + void RemoveBuffer(VkHardwareBuffer* buffer); + + VkRSBuffers* GetRSBuffers(int threadIndex) { return RSBuffers[threadIndex].get(); } + struct { std::unique_ptr Nodes; @@ -72,9 +84,6 @@ public: std::unique_ptr Lights; } Shadowmap; - std::unique_ptr MatrixBuffer; - std::unique_ptr StreamBuffer; - std::unique_ptr FanToTrisIndexBuffer; private: @@ -83,14 +92,13 @@ private: VulkanRenderDevice* fb = nullptr; std::list Buffers; - - friend class VkStreamBuffer; + std::vector> RSBuffers; }; class VkStreamBuffer { public: - VkStreamBuffer(VkBufferManager* buffers, size_t structSize, size_t count); + VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count); ~VkStreamBuffer(); uint32_t NextStreamDataBlock(); diff --git a/src/common/rendering/vulkan/buffers/vk_hwbuffer.cpp b/src/common/rendering/vulkan/buffers/vk_hwbuffer.cpp index 879f48f80a..065a35d7ec 100644 --- a/src/common/rendering/vulkan/buffers/vk_hwbuffer.cpp +++ b/src/common/rendering/vulkan/buffers/vk_hwbuffer.cpp @@ -158,39 +158,6 @@ void VkHardwareBuffer::SetSubData(size_t offset, size_t size, const void *data) } } -/* -void VkHardwareBuffer::Resize(size_t newsize) -{ - newsize = max(newsize, (size_t)16); // For supporting zero byte buffers - - // Grab old buffer - size_t oldsize = buffersize; - std::unique_ptr oldBuffer = std::move(mBuffer); - oldBuffer->Unmap(); - map = nullptr; - - // Create new buffer - mBuffer = BufferBuilder() - .Usage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) - .MemoryType( - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .Size(newsize) - .DebugName("VkHardwareBuffer.Resized") - .Create(fb->GetDevice()); - buffersize = newsize; - - // Transfer data from old to new - fb->GetCommands()->GetTransferCommands()->copyBuffer(oldBuffer.get(), mBuffer.get(), 0, 0, oldsize); - fb->GetCommands()->TransferDeleteList->Add(std::move(oldBuffer)); - fb->GetCommands()->WaitForCommands(false); - fb->GetDescriptorSetManager()->UpdateHWBufferSet(); // Old buffer may be part of the bound descriptor set - - // Fetch pointer to new buffer - map = mBuffer->Map(0, newsize); -} -*/ - void VkHardwareBuffer::Map() { if (!mPersistent) diff --git a/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp b/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp index eae01b7535..ecea350376 100644 --- a/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp +++ b/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp @@ -26,9 +26,9 @@ #include "vulkan/buffers/vk_buffer.h" #include -VkStreamBufferWriter::VkStreamBufferWriter(VulkanRenderDevice* fb) +VkStreamBufferWriter::VkStreamBufferWriter(VkRSBuffers* rsbuffers) { - mBuffer = fb->GetBufferManager()->StreamBuffer.get(); + mBuffer = rsbuffers->StreamBuffer.get(); } bool VkStreamBufferWriter::Write(const StreamData& data) @@ -55,9 +55,9 @@ void VkStreamBufferWriter::Reset() ///////////////////////////////////////////////////////////////////////////// -VkMatrixBufferWriter::VkMatrixBufferWriter(VulkanRenderDevice* fb) +VkMatrixBufferWriter::VkMatrixBufferWriter(VkRSBuffers* rsbuffers) { - mBuffer = fb->GetBufferManager()->MatrixBuffer.get(); + mBuffer = rsbuffers->MatrixBuffer.get(); } bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices) diff --git a/src/common/rendering/vulkan/buffers/vk_streambuffer.h b/src/common/rendering/vulkan/buffers/vk_streambuffer.h index 7829ef6091..b70bdbe87a 100644 --- a/src/common/rendering/vulkan/buffers/vk_streambuffer.h +++ b/src/common/rendering/vulkan/buffers/vk_streambuffer.h @@ -5,11 +5,12 @@ #include "vulkan/shaders/vk_shader.h" class VkStreamBuffer; +class VkRSBuffers; class VkStreamBufferWriter { public: - VkStreamBufferWriter(VulkanRenderDevice* fb); + VkStreamBufferWriter(VkRSBuffers* rsbuffers); bool Write(const StreamData& data); void Reset(); @@ -26,7 +27,7 @@ private: class VkMatrixBufferWriter { public: - VkMatrixBufferWriter(VulkanRenderDevice* fb); + VkMatrixBufferWriter(VkRSBuffers* rsbuffers); bool Write(const MatricesUBO& matrices); void Reset(); diff --git a/src/common/rendering/vulkan/commands/vk_commandbuffer.cpp b/src/common/rendering/vulkan/commands/vk_commandbuffer.cpp index 7ced1440ba..4b1c7b5e57 100644 --- a/src/common/rendering/vulkan/commands/vk_commandbuffer.cpp +++ b/src/common/rendering/vulkan/commands/vk_commandbuffer.cpp @@ -78,7 +78,7 @@ VulkanCommandBuffer* VkCommandBufferManager::GetTransferCommands() return mTransferCommands.get(); } -VulkanCommandBuffer* VkCommandBufferManager::GetDrawCommands() +VulkanCommandBuffer* VkCommandBufferManager::GetDrawCommands(int threadIndex) { if (!mDrawCommands) { diff --git a/src/common/rendering/vulkan/commands/vk_commandbuffer.h b/src/common/rendering/vulkan/commands/vk_commandbuffer.h index 1ce16b021f..3386b1e45b 100644 --- a/src/common/rendering/vulkan/commands/vk_commandbuffer.h +++ b/src/common/rendering/vulkan/commands/vk_commandbuffer.h @@ -15,7 +15,7 @@ public: void BeginFrame(); VulkanCommandBuffer* GetTransferCommands(); - VulkanCommandBuffer* GetDrawCommands(); + VulkanCommandBuffer* GetDrawCommands(int threadIndex = 0); void FlushCommands(bool finish, bool lastsubmit = false, bool uploadOnly = false); diff --git a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp index d04a53b101..1d49a799fd 100644 --- a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp +++ b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp @@ -39,9 +39,9 @@ VkDescriptorSetManager::VkDescriptorSetManager(VulkanRenderDevice* fb) : fb(fb) { - CreateHWBufferSetLayout(); + CreateRSBufferSetLayout(); CreateFixedSetLayout(); - CreateHWBufferPool(); + CreateRSBufferPool(); CreateFixedSetPool(); } @@ -54,7 +54,22 @@ VkDescriptorSetManager::~VkDescriptorSetManager() void VkDescriptorSetManager::Init() { UpdateFixedSet(); - UpdateHWBufferSet(); + + for (int threadIndex = 0; threadIndex < fb->MaxThreads; threadIndex++) + { + auto rsbuffers = fb->GetBufferManager()->GetRSBuffers(threadIndex); + auto rsbufferset = RSBufferDescriptorPool->allocate(RSBufferSetLayout.get()); + + WriteDescriptors() + .AddBuffer(rsbufferset.get(), 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Viewpoint.UBO.get(), 0, sizeof(HWViewpointUniforms)) + .AddBuffer(rsbufferset.get(), 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->MatrixBuffer->UBO.get(), 0, sizeof(MatricesUBO)) + .AddBuffer(rsbufferset.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->StreamBuffer->UBO.get(), 0, sizeof(StreamUBO)) + .AddBuffer(rsbufferset.get(), 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Lightbuffer.UBO.get(), 0, sizeof(LightBufferUBO)) + .AddBuffer(rsbufferset.get(), 4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, rsbuffers->Bonebuffer.SSO.get()) + .Execute(fb->GetDevice()); + + RSBufferSets.push_back(std::move(rsbufferset)); + } } void VkDescriptorSetManager::Deinit() @@ -66,27 +81,6 @@ void VkDescriptorSetManager::Deinit() void VkDescriptorSetManager::BeginFrame() { UpdateFixedSet(); - UpdateHWBufferSet(); -} - -void VkDescriptorSetManager::UpdateHWBufferSet() -{ - fb->GetCommands()->DrawDeleteList->Add(std::move(HWBufferSet)); - - HWBufferSet = HWBufferDescriptorPool->tryAllocate(HWBufferSetLayout.get()); - if (!HWBufferSet) - { - fb->GetCommands()->WaitForCommands(false); - HWBufferSet = HWBufferDescriptorPool->allocate(HWBufferSetLayout.get()); - } - - WriteDescriptors() - .AddBuffer(HWBufferSet.get(), 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->GetBufferManager()->Viewpoint.UBO.get(), 0, sizeof(HWViewpointUniforms)) - .AddBuffer(HWBufferSet.get(), 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->GetBufferManager()->MatrixBuffer->UBO.get(), 0, sizeof(MatricesUBO)) - .AddBuffer(HWBufferSet.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->GetBufferManager()->StreamBuffer->UBO.get(), 0, sizeof(StreamUBO)) - .AddBuffer(HWBufferSet.get(), 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->GetBufferManager()->Lightbuffer.UBO.get(), 0, sizeof(LightBufferUBO)) - .AddBuffer(HWBufferSet.get(), 4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetBufferManager()->Bonebuffer.SSO.get()) - .Execute(fb->GetDevice()); } void VkDescriptorSetManager::UpdateFixedSet() @@ -254,15 +248,15 @@ std::unique_ptr VkDescriptorSetManager::AllocatePPDescripto return PPDescriptorPool->allocate(layout); } -void VkDescriptorSetManager::CreateHWBufferSetLayout() +void VkDescriptorSetManager::CreateRSBufferSetLayout() { - HWBufferSetLayout = DescriptorSetLayoutBuilder() + RSBufferSetLayout = DescriptorSetLayoutBuilder() .AddBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) .AddBinding(1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) .AddBinding(2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) .AddBinding(3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT) .AddBinding(4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT) - .DebugName("VkDescriptorSetManager.HWBufferSetLayout") + .DebugName("VkDescriptorSetManager.RSBufferSetLayout") .Create(fb->GetDevice()); } @@ -285,13 +279,13 @@ void VkDescriptorSetManager::CreateFixedSetLayout() FixedSetLayout = builder.Create(fb->GetDevice()); } -void VkDescriptorSetManager::CreateHWBufferPool() +void VkDescriptorSetManager::CreateRSBufferPool() { - HWBufferDescriptorPool = DescriptorPoolBuilder() - .AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 4 * maxSets) - .AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1 * maxSets) - .MaxSets(maxSets) - .DebugName("VkDescriptorSetManager.HWBufferDescriptorPool") + RSBufferDescriptorPool = DescriptorPoolBuilder() + .AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 4 * fb->MaxThreads) + .AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1 * fb->MaxThreads) + .MaxSets(fb->MaxThreads) + .DebugName("VkDescriptorSetManager.RSBufferDescriptorPool") .Create(fb->GetDevice()); } diff --git a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.h b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.h index f9be16ca41..04babd639c 100644 --- a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.h +++ b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.h @@ -19,15 +19,13 @@ public: void Init(); void Deinit(); void BeginFrame(); - void UpdateFixedSet(); - void UpdateHWBufferSet(); void ResetHWTextureSets(); - VulkanDescriptorSetLayout* GetHWBufferSetLayout() { return HWBufferSetLayout.get(); } + VulkanDescriptorSetLayout* GetRSBufferSetLayout() { return RSBufferSetLayout.get(); } VulkanDescriptorSetLayout* GetFixedSetLayout() { return FixedSetLayout.get(); } VulkanDescriptorSetLayout* GetTextureSetLayout(int numLayers); - VulkanDescriptorSet* GetHWBufferDescriptorSet() { return HWBufferSet.get(); } + VulkanDescriptorSet* GetRSBufferDescriptorSet(int threadIndex) { return RSBufferSets[threadIndex].get(); } VulkanDescriptorSet* GetFixedDescriptorSet() { return FixedSet.get(); } VulkanDescriptorSet* GetNullTextureDescriptorSet(); @@ -39,20 +37,21 @@ public: void RemoveMaterial(VkMaterial* texture); private: - void CreateHWBufferSetLayout(); + void CreateRSBufferSetLayout(); void CreateFixedSetLayout(); - void CreateHWBufferPool(); + void CreateRSBufferPool(); void CreateFixedSetPool(); + void UpdateFixedSet(); std::unique_ptr AllocatePPDescriptorSet(VulkanDescriptorSetLayout* layout); VulkanRenderDevice* fb = nullptr; - std::unique_ptr HWBufferSetLayout; + std::unique_ptr RSBufferSetLayout; std::unique_ptr FixedSetLayout; std::vector> TextureSetLayouts; - std::unique_ptr HWBufferDescriptorPool; + std::unique_ptr RSBufferDescriptorPool; std::unique_ptr FixedDescriptorPool; std::unique_ptr PPDescriptorPool; @@ -61,7 +60,7 @@ private: int TextureDescriptorsLeft = 0; std::vector> TextureDescriptorPools; - std::unique_ptr HWBufferSet; + std::vector> RSBufferSets; std::unique_ptr FixedSet; std::unique_ptr NullTextureDescriptorSet; diff --git a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp index 3bc4af996e..9fa8c2b467 100644 --- a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp +++ b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp @@ -150,7 +150,7 @@ VulkanPipelineLayout* VkRenderPassManager::GetPipelineLayout(int numLayers) PipelineLayoutBuilder builder; builder.AddSetLayout(descriptors->GetFixedSetLayout()); - builder.AddSetLayout(descriptors->GetHWBufferSetLayout()); + builder.AddSetLayout(descriptors->GetRSBufferSetLayout()); if (numLayers != 0) builder.AddSetLayout(descriptors->GetTextureSetLayout(numLayers)); builder.AddPushConstantRange(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(PushConstants)); diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index 5e545f1b3b..42de119c24 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -193,7 +193,7 @@ void VulkanRenderDevice::InitializeState() #ifdef __APPLE__ mRenderState.reset(new VkRenderStateMolten(this)); #else - mRenderState.reset(new VkRenderState(this)); + mRenderState.reset(new VkRenderState(this, 0)); #endif } diff --git a/src/common/rendering/vulkan/vk_renderdevice.h b/src/common/rendering/vulkan/vk_renderdevice.h index 4dc73e1b10..d49ca9092e 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.h +++ b/src/common/rendering/vulkan/vk_renderdevice.h @@ -86,6 +86,8 @@ public: void WaitForCommands(bool finish) override; + int MaxThreads = 8; // To do: this may need to be limited by how much memory is available for dedicated buffer mapping (i.e. is resizeable bar available or not) + private: void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void PrintStartupLog(); diff --git a/src/common/rendering/vulkan/vk_renderstate.cpp b/src/common/rendering/vulkan/vk_renderstate.cpp index 84586605bb..efdfb7c4a8 100644 --- a/src/common/rendering/vulkan/vk_renderstate.cpp +++ b/src/common/rendering/vulkan/vk_renderstate.cpp @@ -40,7 +40,7 @@ CVAR(Int, vk_submit_size, 1000, 0); EXTERN_CVAR(Bool, r_skipmats) -VkRenderState::VkRenderState(VulkanRenderDevice* fb) : fb(fb), mStreamBufferWriter(fb), mMatrixBufferWriter(fb) +VkRenderState::VkRenderState(VulkanRenderDevice* fb, int threadIndex) : fb(fb), threadIndex(threadIndex), mRSBuffers(fb->GetBufferManager()->GetRSBuffers(threadIndex)), mStreamBufferWriter(mRSBuffers), mMatrixBufferWriter(mRSBuffers) { mMatrices.ModelMatrix.loadIdentity(); mMatrices.NormalModelMatrix.loadIdentity(); @@ -203,7 +203,7 @@ void VkRenderState::Apply(int dt) ApplyDepthBias(); ApplyPushConstants(); ApplyVertexBuffers(); - ApplyHWBufferSet(); + ApplyBufferSets(); ApplyMaterial(); mNeedApply = false; @@ -224,7 +224,7 @@ void VkRenderState::ApplyRenderPass(int dt) // Find a pipeline that matches our state VkPipelineKey pipelineKey; pipelineKey.DrawType = dt; - pipelineKey.VertexFormat = mVertexBuffer ? static_cast(mVertexBuffer)->VertexFormat : fb->GetBufferManager()->Flatbuffer.VertexFormat; + pipelineKey.VertexFormat = mVertexBuffer ? static_cast(mVertexBuffer)->VertexFormat : mRSBuffers->Flatbuffer.VertexFormat; pipelineKey.RenderStyle = mRenderStyle; pipelineKey.DepthTest = mDepthTest; pipelineKey.DepthWrite = mDepthTest && mDepthWrite; @@ -310,7 +310,7 @@ void VkRenderState::ApplyRenderPass(int dt) if (!inRenderPass) { - mCommandBuffer = fb->GetCommands()->GetDrawCommands(); + mCommandBuffer = fb->GetCommands()->GetDrawCommands(threadIndex); mScissorChanged = true; mViewportChanged = true; mStencilRefChanged = true; @@ -451,9 +451,8 @@ void VkRenderState::ApplyVertexBuffers() } else { - auto buffers = fb->GetBufferManager(); - const VkVertexFormat* format = fb->GetRenderPassManager()->GetVertexFormat(buffers->Flatbuffer.VertexFormat); - VkBuffer vertexBuffers[2] = { buffers->Flatbuffer.VertexBuffer->buffer, buffers->Flatbuffer.VertexBuffer->buffer }; + const VkVertexFormat* format = fb->GetRenderPassManager()->GetVertexFormat(mRSBuffers->Flatbuffer.VertexFormat); + VkBuffer vertexBuffers[2] = { mRSBuffers->Flatbuffer.VertexBuffer->buffer, mRSBuffers->Flatbuffer.VertexBuffer->buffer }; VkDeviceSize offsets[] = { mVertexOffsets[0] * format->Stride, mVertexOffsets[1] * format->Stride }; mCommandBuffer->bindVertexBuffers(0, 2, vertexBuffers, offsets); } @@ -471,7 +470,7 @@ void VkRenderState::ApplyVertexBuffers() } else { - mCommandBuffer->bindIndexBuffer(fb->GetBufferManager()->Flatbuffer.IndexBuffer->buffer, 0, VK_INDEX_TYPE_UINT32); + mCommandBuffer->bindIndexBuffer(mRSBuffers->Flatbuffer.IndexBuffer->buffer, 0, VK_INDEX_TYPE_UINT32); } mLastIndexBuffer = mIndexBuffer; mIndexBufferNeedsBind = false; @@ -495,7 +494,7 @@ void VkRenderState::ApplyMaterial() } } -void VkRenderState::ApplyHWBufferSet() +void VkRenderState::ApplyBufferSets() { uint32_t matrixOffset = mMatrixBufferWriter.Offset(); uint32_t streamDataOffset = mStreamBufferWriter.StreamDataOffset(); @@ -507,7 +506,7 @@ void VkRenderState::ApplyHWBufferSet() uint32_t offsets[4] = { mViewpointOffset, matrixOffset, streamDataOffset, lightsOffset }; mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 0, fb->GetDescriptorSetManager()->GetFixedDescriptorSet()); - mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 1, descriptors->GetHWBufferDescriptorSet(), 4, offsets); + mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 1, descriptors->GetRSBufferDescriptorSet(threadIndex), 4, offsets); mLastViewpointOffset = mViewpointOffset; mLastMatricesOffset = matrixOffset; @@ -526,21 +525,20 @@ void VkRenderState::WaitForStreamBuffers() int VkRenderState::SetViewpoint(const HWViewpointUniforms& vp) { - auto buffers = fb->GetBufferManager(); - if (buffers->Viewpoint.Count == buffers->Viewpoint.UploadIndex) + if (mRSBuffers->Viewpoint.Count == mRSBuffers->Viewpoint.UploadIndex) { - return buffers->Viewpoint.Count - 1; + return mRSBuffers->Viewpoint.Count - 1; } - memcpy(((char*)buffers->Viewpoint.Data) + buffers->Viewpoint.UploadIndex * buffers->Viewpoint.BlockAlign, &vp, sizeof(HWViewpointUniforms)); - int index = buffers->Viewpoint.UploadIndex++; - mViewpointOffset = index * buffers->Viewpoint.BlockAlign; + memcpy(((char*)mRSBuffers->Viewpoint.Data) + mRSBuffers->Viewpoint.UploadIndex * mRSBuffers->Viewpoint.BlockAlign, &vp, sizeof(HWViewpointUniforms)); + int index = mRSBuffers->Viewpoint.UploadIndex++; + mViewpointOffset = index * mRSBuffers->Viewpoint.BlockAlign; mNeedApply = true; return index; } void VkRenderState::SetViewpoint(int index) { - mViewpointOffset = index * fb->GetBufferManager()->Viewpoint.BlockAlign; + mViewpointOffset = index * mRSBuffers->Viewpoint.BlockAlign; mNeedApply = true; } @@ -561,8 +559,6 @@ void VkRenderState::SetTextureMatrix(const VSMatrix& matrix) int VkRenderState::UploadLights(const FDynLightData& data) { - auto buffers = fb->GetBufferManager(); - // All meaasurements here are in vec4's. int size0 = data.arrays[0].Size() / 4; int size1 = data.arrays[1].Size() / 4; @@ -593,17 +589,17 @@ int VkRenderState::UploadLights(const FDynLightData& data) return -1; // Make sure the light list doesn't cross a page boundary - if (buffers->Lightbuffer.UploadIndex % MAX_LIGHT_DATA + totalsize > MAX_LIGHT_DATA) - buffers->Lightbuffer.UploadIndex = (buffers->Lightbuffer.UploadIndex / MAX_LIGHT_DATA + 1) * MAX_LIGHT_DATA; + if (mRSBuffers->Lightbuffer.UploadIndex % MAX_LIGHT_DATA + totalsize > MAX_LIGHT_DATA) + mRSBuffers->Lightbuffer.UploadIndex = (mRSBuffers->Lightbuffer.UploadIndex / MAX_LIGHT_DATA + 1) * MAX_LIGHT_DATA; - int thisindex = buffers->Lightbuffer.UploadIndex; - if (thisindex + totalsize <= buffers->Lightbuffer.Count) + int thisindex = mRSBuffers->Lightbuffer.UploadIndex; + if (thisindex + totalsize <= mRSBuffers->Lightbuffer.Count) { - buffers->Lightbuffer.UploadIndex += totalsize; + mRSBuffers->Lightbuffer.UploadIndex += totalsize; float parmcnt[] = { 0, float(size0), float(size0 + size1), float(size0 + size1 + size2) }; - float* copyptr = (float*)buffers->Lightbuffer.Data + thisindex * 4; + float* copyptr = (float*)mRSBuffers->Lightbuffer.Data + thisindex * 4; memcpy(©ptr[0], parmcnt, sizeof(FVector4)); memcpy(©ptr[4], &data.arrays[0][0], size0 * sizeof(FVector4)); memcpy(©ptr[4 + 4 * size0], &data.arrays[1][0], size1 * sizeof(FVector4)); @@ -618,20 +614,18 @@ int VkRenderState::UploadLights(const FDynLightData& data) int VkRenderState::UploadBones(const TArray& bones) { - auto buffers = fb->GetBufferManager(); - int totalsize = bones.Size(); if (bones.Size() == 0) { return -1; } - int thisindex = buffers->Bonebuffer.UploadIndex; - buffers->Bonebuffer.UploadIndex += totalsize; + int thisindex = mRSBuffers->Bonebuffer.UploadIndex; + mRSBuffers->Bonebuffer.UploadIndex += totalsize; - if (thisindex + totalsize <= buffers->Bonebuffer.Count) + if (thisindex + totalsize <= mRSBuffers->Bonebuffer.Count) { - memcpy((VSMatrix*)buffers->Bonebuffer.Data + thisindex, bones.Data(), bones.Size() * sizeof(VSMatrix)); + memcpy((VSMatrix*)mRSBuffers->Bonebuffer.Data + thisindex, bones.Data(), bones.Size() * sizeof(VSMatrix)); return thisindex; } else @@ -642,25 +636,23 @@ int VkRenderState::UploadBones(const TArray& bones) std::pair VkRenderState::AllocVertices(unsigned int count) { - auto buffers = fb->GetBufferManager(); - unsigned int index = buffers->Flatbuffer.CurIndex; - if (index + count >= buffers->Flatbuffer.BUFFER_SIZE_TO_USE) + unsigned int index = mRSBuffers->Flatbuffer.CurIndex; + if (index + count >= mRSBuffers->Flatbuffer.BUFFER_SIZE_TO_USE) { // If a single scene needs 2'000'000 vertices there must be something very wrong. I_FatalError("Out of vertex memory. Tried to allocate more than %u vertices for a single frame", index + count); } - buffers->Flatbuffer.CurIndex += count; - return std::make_pair(buffers->Flatbuffer.Vertices + index, index); + mRSBuffers->Flatbuffer.CurIndex += count; + return std::make_pair(mRSBuffers->Flatbuffer.Vertices + index, index); } void VkRenderState::SetShadowData(const TArray& vertices, const TArray& indexes) { - auto buffers = fb->GetBufferManager(); auto commands = fb->GetCommands(); UpdateShadowData(0, vertices.Data(), vertices.Size()); - buffers->Flatbuffer.ShadowDataSize = vertices.Size(); - buffers->Flatbuffer.CurIndex = buffers->Flatbuffer.ShadowDataSize; + mRSBuffers->Flatbuffer.ShadowDataSize = vertices.Size(); + mRSBuffers->Flatbuffer.CurIndex = mRSBuffers->Flatbuffer.ShadowDataSize; if (indexes.Size() > 0) { @@ -685,8 +677,8 @@ void VkRenderState::SetShadowData(const TArray& vertices, const TAr commands->GetTransferCommands()->copyBuffer(staging.get(), buffer.get()); commands->TransferDeleteList->Add(std::move(staging)); - commands->DrawDeleteList->Add(std::move(buffers->Flatbuffer.IndexBuffer)); - buffers->Flatbuffer.IndexBuffer = std::move(buffer); + commands->DrawDeleteList->Add(std::move(mRSBuffers->Flatbuffer.IndexBuffer)); + mRSBuffers->Flatbuffer.IndexBuffer = std::move(buffer); mIndexBufferNeedsBind = true; mNeedApply = true; @@ -695,13 +687,12 @@ void VkRenderState::SetShadowData(const TArray& vertices, const TAr void VkRenderState::UpdateShadowData(unsigned int index, const FFlatVertex* vertices, unsigned int count) { - memcpy(fb->GetBufferManager()->Flatbuffer.Vertices + index, vertices, count * sizeof(FFlatVertex)); + memcpy(mRSBuffers->Flatbuffer.Vertices + index, vertices, count * sizeof(FFlatVertex)); } void VkRenderState::ResetVertices() { - auto buffers = fb->GetBufferManager(); - buffers->Flatbuffer.CurIndex = buffers->Flatbuffer.ShadowDataSize; + mRSBuffers->Flatbuffer.CurIndex = mRSBuffers->Flatbuffer.ShadowDataSize; } void VkRenderState::BeginFrame() @@ -709,10 +700,9 @@ void VkRenderState::BeginFrame() mMaterial.Reset(); mApplyCount = 0; - auto buffers = fb->GetBufferManager(); - buffers->Viewpoint.UploadIndex = 0; - buffers->Lightbuffer.UploadIndex = 0; - buffers->Bonebuffer.UploadIndex = 0; + mRSBuffers->Viewpoint.UploadIndex = 0; + mRSBuffers->Lightbuffer.UploadIndex = 0; + mRSBuffers->Bonebuffer.UploadIndex = 0; } void VkRenderState::EndRenderPass() diff --git a/src/common/rendering/vulkan/vk_renderstate.h b/src/common/rendering/vulkan/vk_renderstate.h index deb06d8f5c..c5f7afccc8 100644 --- a/src/common/rendering/vulkan/vk_renderstate.h +++ b/src/common/rendering/vulkan/vk_renderstate.h @@ -18,7 +18,7 @@ class VkTextureImage; class VkRenderState : public FRenderState { public: - VkRenderState(VulkanRenderDevice* fb); + VkRenderState(VulkanRenderDevice* fb, int threadIndex); virtual ~VkRenderState() = default; // Draw commands @@ -71,7 +71,7 @@ protected: void ApplyStreamData(); void ApplyMatrices(); void ApplyPushConstants(); - void ApplyHWBufferSet(); + void ApplyBufferSets(); void ApplyVertexBuffers(); void ApplyMaterial(); @@ -79,6 +79,9 @@ protected: void WaitForStreamBuffers(); VulkanRenderDevice* fb = nullptr; + int threadIndex = 0; + + VkRSBuffers* mRSBuffers = nullptr; bool mDepthClamp = true; VulkanCommandBuffer *mCommandBuffer = nullptr;