diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a63b78601..f30bce8470 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -744,7 +744,7 @@ set (VULKAN_SOURCES common/rendering/vulkan/vk_postprocess.cpp common/rendering/vulkan/vk_pprenderstate.cpp common/rendering/vulkan/commands/vk_commandbuffer.cpp - common/rendering/vulkan/buffers/vk_streambuffer.cpp + common/rendering/vulkan/buffers/vk_rsbuffers.cpp common/rendering/vulkan/buffers/vk_hwbuffer.cpp common/rendering/vulkan/buffers/vk_buffer.cpp common/rendering/vulkan/samplers/vk_samplers.cpp diff --git a/src/common/rendering/vulkan/buffers/vk_buffer.cpp b/src/common/rendering/vulkan/buffers/vk_buffer.cpp index bb8a4d5d5a..483fc39aa2 100644 --- a/src/common/rendering/vulkan/buffers/vk_buffer.cpp +++ b/src/common/rendering/vulkan/buffers/vk_buffer.cpp @@ -22,12 +22,11 @@ #include "vk_buffer.h" #include "vk_hwbuffer.h" -#include "vk_streambuffer.h" +#include "vk_rsbuffers.h" #include "vulkan/vk_renderdevice.h" #include "vulkan/pipelines/vk_renderpass.h" #include "vulkan/commands/vk_commandbuffer.h" #include -#include "flatvertices.h" #include "cmdlib.h" VkBufferManager::VkBufferManager(VulkanRenderDevice* fb) : fb(fb) @@ -99,126 +98,3 @@ void VkBufferManager::CreateFanToTrisIndexBuffer() FanToTrisIndexBuffer.reset(CreateIndexBuffer()); FanToTrisIndexBuffer->SetData(sizeof(uint32_t) * data.Size(), data.Data(), BufferUsageType::Static); } - -///////////////////////////////////////////////////////////////////////////// - -VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb) -{ - 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) - .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(mBlockSize * count) - .DebugName("VkStreamBuffer") - .Create(fb->GetDevice()); - - Data = UBO->Map(0, UBO->size); -} - -VkStreamBuffer::~VkStreamBuffer() -{ - UBO->Unmap(); -} - -uint32_t VkStreamBuffer::NextStreamDataBlock() -{ - mStreamDataOffset += mBlockSize; - if (mStreamDataOffset + (size_t)mBlockSize >= UBO->size) - { - mStreamDataOffset = 0; - return 0xffffffff; - } - return mStreamDataOffset; -} diff --git a/src/common/rendering/vulkan/buffers/vk_buffer.h b/src/common/rendering/vulkan/buffers/vk_buffer.h index 17dc6785d1..e4de97f3dc 100644 --- a/src/common/rendering/vulkan/buffers/vk_buffer.h +++ b/src/common/rendering/vulkan/buffers/vk_buffer.h @@ -7,58 +7,9 @@ class VulkanRenderDevice; class VkHardwareBuffer; class VkHardwareDataBuffer; -class VkStreamBuffer; class IBuffer; +class VkRSBuffers; struct FVertexBufferAttribute; -struct HWViewpointUniforms; -struct FFlatVertex; - -class VkRSBuffers -{ -public: - VkRSBuffers(VulkanRenderDevice* fb); - ~VkRSBuffers(); - - struct - { - std::unique_ptr VertexBuffer; - int VertexFormat = 0; - FFlatVertex* Vertices = nullptr; - unsigned int ShadowDataSize = 0; - unsigned int CurIndex = 0; - static const unsigned int BUFFER_SIZE = 2000000; - static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE - 500; - std::unique_ptr IndexBuffer; - } Flatbuffer; - - struct - { - int UploadIndex = 0; - int BlockAlign = 0; - int Count = 1000; - std::unique_ptr UBO; - void* Data = nullptr; - } Viewpoint; - - struct - { - int UploadIndex = 0; - int Count = 80000; - std::unique_ptr UBO; - void* Data = nullptr; - } Lightbuffer; - - struct - { - int UploadIndex = 0; - int Count = 80000; - std::unique_ptr SSO; - void* Data = nullptr; - } Bonebuffer; - - std::unique_ptr MatrixBuffer; - std::unique_ptr StreamBuffer; -}; class VkBufferManager { @@ -94,20 +45,3 @@ private: std::list Buffers; std::vector> RSBuffers; }; - -class VkStreamBuffer -{ -public: - VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count); - ~VkStreamBuffer(); - - uint32_t NextStreamDataBlock(); - void Reset() { mStreamDataOffset = 0; } - - std::unique_ptr UBO; - void* Data = nullptr; - -private: - uint32_t mBlockSize = 0; - uint32_t mStreamDataOffset = 0; -}; diff --git a/src/common/rendering/vulkan/buffers/vk_rsbuffers.cpp b/src/common/rendering/vulkan/buffers/vk_rsbuffers.cpp new file mode 100644 index 0000000000..0d13983a23 --- /dev/null +++ b/src/common/rendering/vulkan/buffers/vk_rsbuffers.cpp @@ -0,0 +1,201 @@ +/* +** Vulkan backend +** Copyright (c) 2016-2020 Magnus Norddahl +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any damages +** arising from the use of this software. +** +** Permission is granted to anyone to use this software for any purpose, +** including commercial applications, and to alter it and redistribute it +** freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you must not +** claim that you wrote the original software. If you use this software +** in a product, an acknowledgment in the product documentation would be +** appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and must not be +** misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source distribution. +** +*/ + +#include "vk_rsbuffers.h" +#include "vulkan/vk_renderstate.h" +#include "vulkan/vk_renderdevice.h" +#include "vulkan/buffers/vk_buffer.h" +#include +#include "flatvertices.h" +#include "cmdlib.h" + +VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb) +{ + 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) + .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(mBlockSize * count) + .DebugName("VkStreamBuffer") + .Create(fb->GetDevice()); + + Data = UBO->Map(0, UBO->size); +} + +VkStreamBuffer::~VkStreamBuffer() +{ + UBO->Unmap(); +} + +uint32_t VkStreamBuffer::NextStreamDataBlock() +{ + mStreamDataOffset += mBlockSize; + if (mStreamDataOffset + (size_t)mBlockSize >= UBO->size) + { + mStreamDataOffset = 0; + return 0xffffffff; + } + return mStreamDataOffset; +} + +VkStreamBufferWriter::VkStreamBufferWriter(VkRSBuffers* rsbuffers) +{ + mBuffer = rsbuffers->StreamBuffer.get(); +} + +bool VkStreamBufferWriter::Write(const StreamData& data) +{ + mDataIndex++; + if (mDataIndex == MAX_STREAM_DATA) + { + mDataIndex = 0; + mStreamDataOffset = mBuffer->NextStreamDataBlock(); + if (mStreamDataOffset == 0xffffffff) + return false; + } + uint8_t* ptr = (uint8_t*)mBuffer->Data; + memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData)); + return true; +} + +void VkStreamBufferWriter::Reset() +{ + mDataIndex = MAX_STREAM_DATA - 1; + mStreamDataOffset = 0; + mBuffer->Reset(); +} + +///////////////////////////////////////////////////////////////////////////// + +VkMatrixBufferWriter::VkMatrixBufferWriter(VkRSBuffers* rsbuffers) +{ + mBuffer = rsbuffers->MatrixBuffer.get(); +} + +bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices) +{ + mOffset = mBuffer->NextStreamDataBlock(); + if (mOffset == 0xffffffff) + return false; + + uint8_t* ptr = (uint8_t*)mBuffer->Data; + memcpy(ptr + mOffset, &matrices, sizeof(MatricesUBO)); + return true; +} + +void VkMatrixBufferWriter::Reset() +{ + mOffset = 0; + mBuffer->Reset(); +} diff --git a/src/common/rendering/vulkan/buffers/vk_rsbuffers.h b/src/common/rendering/vulkan/buffers/vk_rsbuffers.h new file mode 100644 index 0000000000..d08802d24e --- /dev/null +++ b/src/common/rendering/vulkan/buffers/vk_rsbuffers.h @@ -0,0 +1,104 @@ + +#pragma once + +#include "vulkan/buffers/vk_hwbuffer.h" +#include "vulkan/shaders/vk_shader.h" + +class VkStreamBuffer; +struct FFlatVertex; + +class VkRSBuffers +{ +public: + VkRSBuffers(VulkanRenderDevice* fb); + ~VkRSBuffers(); + + struct + { + std::unique_ptr VertexBuffer; + int VertexFormat = 0; + FFlatVertex* Vertices = nullptr; + unsigned int ShadowDataSize = 0; + unsigned int CurIndex = 0; + static const unsigned int BUFFER_SIZE = 2000000; + static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE - 500; + std::unique_ptr IndexBuffer; + } Flatbuffer; + + struct + { + int UploadIndex = 0; + int BlockAlign = 0; + int Count = 1000; + std::unique_ptr UBO; + void* Data = nullptr; + } Viewpoint; + + struct + { + int UploadIndex = 0; + int Count = 80000; + std::unique_ptr UBO; + void* Data = nullptr; + } Lightbuffer; + + struct + { + int UploadIndex = 0; + int Count = 80000; + std::unique_ptr SSO; + void* Data = nullptr; + } Bonebuffer; + + std::unique_ptr MatrixBuffer; + std::unique_ptr StreamBuffer; +}; + +class VkStreamBuffer +{ +public: + VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count); + ~VkStreamBuffer(); + + uint32_t NextStreamDataBlock(); + void Reset() { mStreamDataOffset = 0; } + + std::unique_ptr UBO; + void* Data = nullptr; + +private: + uint32_t mBlockSize = 0; + uint32_t mStreamDataOffset = 0; +}; + +class VkStreamBufferWriter +{ +public: + VkStreamBufferWriter(VkRSBuffers* rsbuffers); + + bool Write(const StreamData& data); + void Reset(); + + uint32_t DataIndex() const { return mDataIndex; } + uint32_t StreamDataOffset() const { return mStreamDataOffset; } + +private: + VkStreamBuffer* mBuffer; + uint32_t mDataIndex = MAX_STREAM_DATA - 1; + uint32_t mStreamDataOffset = 0; +}; + +class VkMatrixBufferWriter +{ +public: + VkMatrixBufferWriter(VkRSBuffers* rsbuffers); + + bool Write(const MatricesUBO& matrices); + void Reset(); + + uint32_t Offset() const { return mOffset; } + +private: + VkStreamBuffer* mBuffer; + uint32_t mOffset = 0; +}; diff --git a/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp b/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp deleted file mode 100644 index ecea350376..0000000000 --- a/src/common/rendering/vulkan/buffers/vk_streambuffer.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -** Vulkan backend -** Copyright (c) 2016-2020 Magnus Norddahl -** -** This software is provided 'as-is', without any express or implied -** warranty. In no event will the authors be held liable for any damages -** arising from the use of this software. -** -** Permission is granted to anyone to use this software for any purpose, -** including commercial applications, and to alter it and redistribute it -** freely, subject to the following restrictions: -** -** 1. The origin of this software must not be misrepresented; you must not -** claim that you wrote the original software. If you use this software -** in a product, an acknowledgment in the product documentation would be -** appreciated but is not required. -** 2. Altered source versions must be plainly marked as such, and must not be -** misrepresented as being the original software. -** 3. This notice may not be removed or altered from any source distribution. -** -*/ - -#include "vk_streambuffer.h" -#include "vulkan/vk_renderstate.h" -#include "vulkan/vk_renderdevice.h" -#include "vulkan/buffers/vk_buffer.h" -#include - -VkStreamBufferWriter::VkStreamBufferWriter(VkRSBuffers* rsbuffers) -{ - mBuffer = rsbuffers->StreamBuffer.get(); -} - -bool VkStreamBufferWriter::Write(const StreamData& data) -{ - mDataIndex++; - if (mDataIndex == MAX_STREAM_DATA) - { - mDataIndex = 0; - mStreamDataOffset = mBuffer->NextStreamDataBlock(); - if (mStreamDataOffset == 0xffffffff) - return false; - } - uint8_t* ptr = (uint8_t*)mBuffer->Data; - memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData)); - return true; -} - -void VkStreamBufferWriter::Reset() -{ - mDataIndex = MAX_STREAM_DATA - 1; - mStreamDataOffset = 0; - mBuffer->Reset(); -} - -///////////////////////////////////////////////////////////////////////////// - -VkMatrixBufferWriter::VkMatrixBufferWriter(VkRSBuffers* rsbuffers) -{ - mBuffer = rsbuffers->MatrixBuffer.get(); -} - -bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices) -{ - mOffset = mBuffer->NextStreamDataBlock(); - if (mOffset == 0xffffffff) - return false; - - uint8_t* ptr = (uint8_t*)mBuffer->Data; - memcpy(ptr + mOffset, &matrices, sizeof(MatricesUBO)); - return true; -} - -void VkMatrixBufferWriter::Reset() -{ - mOffset = 0; - mBuffer->Reset(); -} diff --git a/src/common/rendering/vulkan/buffers/vk_streambuffer.h b/src/common/rendering/vulkan/buffers/vk_streambuffer.h deleted file mode 100644 index b70bdbe87a..0000000000 --- a/src/common/rendering/vulkan/buffers/vk_streambuffer.h +++ /dev/null @@ -1,40 +0,0 @@ - -#pragma once - -#include "vulkan/buffers/vk_hwbuffer.h" -#include "vulkan/shaders/vk_shader.h" - -class VkStreamBuffer; -class VkRSBuffers; - -class VkStreamBufferWriter -{ -public: - VkStreamBufferWriter(VkRSBuffers* rsbuffers); - - bool Write(const StreamData& data); - void Reset(); - - uint32_t DataIndex() const { return mDataIndex; } - uint32_t StreamDataOffset() const { return mStreamDataOffset; } - -private: - VkStreamBuffer* mBuffer; - uint32_t mDataIndex = MAX_STREAM_DATA - 1; - uint32_t mStreamDataOffset = 0; -}; - -class VkMatrixBufferWriter -{ -public: - VkMatrixBufferWriter(VkRSBuffers* rsbuffers); - - bool Write(const MatricesUBO& matrices); - void Reset(); - - uint32_t Offset() const { return mOffset; } - -private: - VkStreamBuffer* mBuffer; - uint32_t mOffset = 0; -}; diff --git a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp index adbbc8ad0f..f38559075c 100644 --- a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp +++ b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp @@ -30,7 +30,7 @@ #include "vulkan/textures/vk_texture.h" #include "vulkan/buffers/vk_hwbuffer.h" #include "vulkan/buffers/vk_buffer.h" -#include "vulkan/buffers/vk_streambuffer.h" +#include "vulkan/buffers/vk_rsbuffers.h" #include "vulkan/commands/vk_commandbuffer.h" #include "vulkan/pipelines/vk_pprenderpass.h" #include diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index 42de119c24..d1fe909bb2 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -54,7 +54,7 @@ #include "vulkan/commands/vk_commandbuffer.h" #include "vulkan/buffers/vk_hwbuffer.h" #include "vulkan/buffers/vk_buffer.h" -#include "vulkan/buffers/vk_streambuffer.h" +#include "vulkan/buffers/vk_rsbuffers.h" #include #include #include diff --git a/src/common/rendering/vulkan/vk_renderstate.h b/src/common/rendering/vulkan/vk_renderstate.h index c5f7afccc8..e89cc436c7 100644 --- a/src/common/rendering/vulkan/vk_renderstate.h +++ b/src/common/rendering/vulkan/vk_renderstate.h @@ -2,7 +2,7 @@ #pragma once #include "vulkan/buffers/vk_hwbuffer.h" -#include "vulkan/buffers/vk_streambuffer.h" +#include "vulkan/buffers/vk_rsbuffers.h" #include "vulkan/shaders/vk_shader.h" #include "vulkan/pipelines/vk_renderpass.h"