Graphics/SpriteChainRenderer: Improve copy

This commit is contained in:
Jérôme Leclercq 2021-09-13 23:35:31 +02:00
parent db85372778
commit 7f6b61df53
2 changed files with 18 additions and 5 deletions

View File

@ -35,6 +35,13 @@ namespace Nz
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
private:
struct BufferCopy
{
AbstractBuffer* targetBuffer;
UploadPool::Allocation* allocation;
std::size_t size;
};
struct VertexBufferPool
{
std::vector<std::shared_ptr<AbstractBuffer>> vertexBuffers;
@ -44,7 +51,7 @@ namespace Nz
std::shared_ptr<VertexBufferPool> m_vertexBufferPool;
std::size_t m_maxVertexBufferSize;
std::size_t m_maxVertexCount;
std::vector<std::pair<UploadPool::Allocation*, AbstractBuffer*>> m_pendingCopies;
std::vector<BufferCopy> m_pendingCopies;
RenderDevice& m_device;
};

View File

@ -87,7 +87,13 @@ namespace Nz
if (currentAllocation)
{
m_pendingCopies.emplace_back(currentAllocation, currentVertexBuffer);
std::size_t size = currentAllocationMemPtr - static_cast<UInt8*>(currentAllocation->mappedPtr);
m_pendingCopies.emplace_back(BufferCopy{
currentVertexBuffer,
currentAllocation,
size
});
firstQuadIndex = 0;
currentAllocation = nullptr;
@ -237,8 +243,8 @@ namespace Nz
{
currentFrame.Execute([&](CommandBufferBuilder& builder)
{
for (auto&& [allocation, buffer] : m_pendingCopies)
builder.CopyBuffer(*allocation, buffer);
for (auto& copy : m_pendingCopies)
builder.CopyBuffer(*copy.allocation, copy.targetBuffer, copy.size);
builder.PostTransferBarrier();
}, Nz::QueueType::Transfer);
@ -247,7 +253,7 @@ namespace Nz
}
}
void SpriteChainRenderer::Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount)
void SpriteChainRenderer::Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t /*elementCount*/)
{
auto& data = static_cast<SpriteChainRendererData&>(rendererData);