From 203d1d79dc6c9e555a23ff4d65b8d1ce72691c0d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 19 Apr 2021 21:41:34 +0200 Subject: [PATCH 1/6] Add drawCount to GPU indirect draw cmds. --- Source/Engine/Graphics/GPUContext.h | 6 ++++-- .../Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp | 4 ++-- .../Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h | 4 ++-- .../Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp | 8 ++++---- .../Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h | 4 ++-- Source/Engine/GraphicsDevice/Null/GPUContextNull.h | 4 ++-- Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp | 4 ++-- Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h | 4 ++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Source/Engine/Graphics/GPUContext.h b/Source/Engine/Graphics/GPUContext.h index ed2417c96..9eb607a5c 100644 --- a/Source/Engine/Graphics/GPUContext.h +++ b/Source/Engine/Graphics/GPUContext.h @@ -508,14 +508,16 @@ public: /// /// The buffer with drawing arguments. /// The aligned byte offset for arguments. - API_FUNCTION() virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; + /// The number of draw command to execute. + API_FUNCTION() virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) = 0; /// /// Draws the instanced GPU-generated indexed primitives. Buffer must contain GPUDrawIndexedIndirectArgs. /// /// The buffer with drawing arguments. /// The aligned byte offset for arguments. - API_FUNCTION() virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; + /// The number of draw command to execute. + API_FUNCTION() virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) = 0; public: diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp index 9c9af3145..a737b9ea5 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp @@ -465,7 +465,7 @@ void GPUContextDX11::DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCo RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -476,7 +476,7 @@ void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offs RENDER_STAT_DRAW_CALL(0, 0); } -void GPUContextDX11::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextDX11::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h index dffeae00c..23205a010 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h @@ -128,8 +128,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp index 4d1bd3e17..efd6773e1 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp @@ -912,7 +912,7 @@ void GPUContextDX12::DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCo RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -921,11 +921,11 @@ void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offs SetResourceState(bufferForArgsDX12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); onDrawCall(); - _commandList->ExecuteIndirect(signature, 1, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); + _commandList->ExecuteIndirect(signature, drawCount, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); RENDER_STAT_DRAW_CALL(0, 0); } -void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -934,7 +934,7 @@ void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint SetResourceState(bufferForArgsDX12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); onDrawCall(); - _commandList->ExecuteIndirect(signature, 1, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); + _commandList->ExecuteIndirect(signature, drawCount, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); RENDER_STAT_DRAW_CALL(0, 0); } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h index 6fb670e7b..ac693a991 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h @@ -182,8 +182,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; diff --git a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h index f45417976..c15b26599 100644 --- a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h +++ b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h @@ -132,11 +132,11 @@ public: { } - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override { } - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override { } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index e8f770831..7da429830 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -1090,13 +1090,13 @@ void GPUContextVulkan::DrawIndexedInstanced(uint32 indicesCount, uint32 instance RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextVulkan::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextVulkan::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { // TODO: implement it MISSING_CODE("GPUContextVulkan::DrawInstancedIndirect"); } -void GPUContextVulkan::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) +void GPUContextVulkan::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { // TODO: implement it MISSING_CODE("GPUContextVulkan::DrawIndexedInstancedIndirect"); diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h index a3d26f017..df41b53c7 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h @@ -199,8 +199,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; From 52815a4ab0fd6a55b163ff0edbe6df0335531050 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 19 Apr 2021 22:02:59 +0200 Subject: [PATCH 2/6] Refactor using GPUDrawIndirectArgs. --- Source/Engine/Renderer/DepthOfFieldPass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Renderer/DepthOfFieldPass.cpp b/Source/Engine/Renderer/DepthOfFieldPass.cpp index 4e4ee7ed1..87394e5d9 100644 --- a/Source/Engine/Renderer/DepthOfFieldPass.cpp +++ b/Source/Engine/Renderer/DepthOfFieldPass.cpp @@ -143,8 +143,8 @@ bool DepthOfFieldPass::setupResources() _bokehBuffer = GPUDevice::Instance->CreateBuffer(TEXT("Bokeh Buffer")); if (_bokehIndirectArgsBuffer == nullptr) _bokehIndirectArgsBuffer = GPUDevice::Instance->CreateBuffer(TEXT("Bokeh Indirect Args Buffer")); - uint32 indirectArgsBufferInitData[4] = { 0, 1, 0, 0 }; - if (_bokehIndirectArgsBuffer->Init(GPUBufferDescription::Argument(indirectArgsBufferInitData, sizeof(indirectArgsBufferInitData)))) + GPUDrawIndirectArgs indirectArgsBufferInitData{0, 1, 0, 0}; + if (_bokehIndirectArgsBuffer->Init(GPUBufferDescription::Argument(&indirectArgsBufferInitData, sizeof(indirectArgsBufferInitData)))) return true; } From 3fc7073046f8d04435d83eaa30e249d2d5e2b592 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 24 Apr 2021 14:29:38 +0200 Subject: [PATCH 3/6] DrawInstancedIndirect & DrawIndexedInstanceIndirect impl. --- .../GraphicsDevice/Vulkan/GPUContextVulkan.cpp | 18 ++++++++++++++---- .../GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index 7da429830..bf1e2ba5b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -1092,14 +1092,24 @@ void GPUContextVulkan::DrawIndexedInstanced(uint32 indicesCount, uint32 instance void GPUContextVulkan::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { - // TODO: implement it - MISSING_CODE("GPUContextVulkan::DrawInstancedIndirect"); + ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); + + auto bufferForArgsVK = (GPUBufferVulkan*)bufferForArgs; + const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer(); + OnDrawCall(); + vkCmdDrawIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, drawCount, sizeof(VkDrawIndirectCommand)); + RENDER_STAT_DRAW_CALL(0, 0); } void GPUContextVulkan::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) { - // TODO: implement it - MISSING_CODE("GPUContextVulkan::DrawIndexedInstancedIndirect"); + ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); + + auto bufferForArgsVK = (GPUBufferVulkan*)bufferForArgs; + const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer(); + OnDrawCall(); + vkCmdDrawIndexedIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, drawCount, sizeof(VkDrawIndexedIndirectCommand)); + RENDER_STAT_DRAW_CALL(0, 0); } void GPUContextVulkan::SetViewport(const Viewport& viewport) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 498fd3491..249289c7a 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -1704,7 +1704,7 @@ bool GPUDeviceVulkan::Init() limits.HasGeometryShaders = false; // TODO: add geometry shaders support for Vulkan limits.HasInstancing = true; limits.HasVolumeTextureRendering = true; - limits.HasDrawIndirect = false; // TODO: add Draw Indirect support for Vulkan + limits.HasDrawIndirect = true; limits.HasAppendConsumeBuffers = false; // TODO: add Append Consume buffers support for Vulkan limits.HasSeparateRenderTargetBlendState = true; limits.HasDepthAsSRV = true; From b4a870933ad2a5df4190ee4784115cf344ad38ea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 16 May 2021 17:23:52 +0200 Subject: [PATCH 4/6] Revert IndirectDrawCount. --- Source/Engine/Graphics/GPUContext.h | 4 ++-- .../Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp | 4 ++-- .../Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h | 4 ++-- .../Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp | 8 ++++---- .../Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h | 4 ++-- Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp | 8 ++++---- Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/Engine/Graphics/GPUContext.h b/Source/Engine/Graphics/GPUContext.h index 9eb607a5c..6bcfde28d 100644 --- a/Source/Engine/Graphics/GPUContext.h +++ b/Source/Engine/Graphics/GPUContext.h @@ -509,7 +509,7 @@ public: /// The buffer with drawing arguments. /// The aligned byte offset for arguments. /// The number of draw command to execute. - API_FUNCTION() virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) = 0; + API_FUNCTION() virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; /// /// Draws the instanced GPU-generated indexed primitives. Buffer must contain GPUDrawIndexedIndirectArgs. @@ -517,7 +517,7 @@ public: /// The buffer with drawing arguments. /// The aligned byte offset for arguments. /// The number of draw command to execute. - API_FUNCTION() virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) = 0; + API_FUNCTION() virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; public: diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp index a737b9ea5..9c9af3145 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp @@ -465,7 +465,7 @@ void GPUContextDX11::DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCo RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -476,7 +476,7 @@ void GPUContextDX11::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offs RENDER_STAT_DRAW_CALL(0, 0); } -void GPUContextDX11::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextDX11::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h index 23205a010..dffeae00c 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h @@ -128,8 +128,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp index efd6773e1..4d1bd3e17 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp @@ -912,7 +912,7 @@ void GPUContextDX12::DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCo RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -921,11 +921,11 @@ void GPUContextDX12::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offs SetResourceState(bufferForArgsDX12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); onDrawCall(); - _commandList->ExecuteIndirect(signature, drawCount, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); + _commandList->ExecuteIndirect(signature, 1, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); RENDER_STAT_DRAW_CALL(0, 0); } -void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); @@ -934,7 +934,7 @@ void GPUContextDX12::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint SetResourceState(bufferForArgsDX12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); onDrawCall(); - _commandList->ExecuteIndirect(signature, drawCount, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); + _commandList->ExecuteIndirect(signature, 1, bufferForArgsDX12->GetResource(), (UINT64)offsetForArgs, nullptr, 0); RENDER_STAT_DRAW_CALL(0, 0); } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h index ac693a991..6fb670e7b 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h @@ -182,8 +182,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index bf1e2ba5b..aafa7b6a6 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -1090,25 +1090,25 @@ void GPUContextVulkan::DrawIndexedInstanced(uint32 indicesCount, uint32 instance RENDER_STAT_DRAW_CALL(0, indicesCount / 3 * instanceCount); } -void GPUContextVulkan::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextVulkan::DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); auto bufferForArgsVK = (GPUBufferVulkan*)bufferForArgs; const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer(); OnDrawCall(); - vkCmdDrawIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, drawCount, sizeof(VkDrawIndirectCommand)); + vkCmdDrawIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, 1, sizeof(VkDrawIndirectCommand)); RENDER_STAT_DRAW_CALL(0, 0); } -void GPUContextVulkan::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount) +void GPUContextVulkan::DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) { ASSERT(bufferForArgs && bufferForArgs->GetFlags() & GPUBufferFlags::Argument); auto bufferForArgsVK = (GPUBufferVulkan*)bufferForArgs; const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer(); OnDrawCall(); - vkCmdDrawIndexedIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, drawCount, sizeof(VkDrawIndexedIndirectCommand)); + vkCmdDrawIndexedIndirect(cmdBuffer->GetHandle(), bufferForArgsVK->GetHandle(), (VkDeviceSize)offsetForArgs, 1, sizeof(VkDrawIndexedIndirectCommand)); RENDER_STAT_DRAW_CALL(0, 0); } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h index df41b53c7..a3d26f017 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h @@ -199,8 +199,8 @@ public: void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource, int32 destSubResource, PixelFormat format) override; void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance, int32 startVertex) override; void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance, int32 startVertex, int32 startIndex) override; - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override; + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override; void SetViewport(const Viewport& viewport) override; void SetScissor(const Rectangle& scissorRect) override; GPUPipelineState* GetState() const override; From 3599de7eb8ad73b6a8a56179983739743fe22757 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 16 May 2021 17:30:15 +0200 Subject: [PATCH 5/6] Fix revert indirect draw count. --- Source/Engine/GraphicsDevice/Null/GPUContextNull.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h index c15b26599..f45417976 100644 --- a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h +++ b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h @@ -132,11 +132,11 @@ public: { } - void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override + void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override { } - void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs, uint32 drawCount = 1) override + void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) override { } From fd3d6abd61f544cfb82b2b8f5f8f593b96aa9285 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 16 May 2021 21:39:30 +0200 Subject: [PATCH 6/6] Fix docs. --- Source/Engine/Graphics/GPUContext.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Engine/Graphics/GPUContext.h b/Source/Engine/Graphics/GPUContext.h index 6bcfde28d..ed2417c96 100644 --- a/Source/Engine/Graphics/GPUContext.h +++ b/Source/Engine/Graphics/GPUContext.h @@ -508,7 +508,6 @@ public: /// /// The buffer with drawing arguments. /// The aligned byte offset for arguments. - /// The number of draw command to execute. API_FUNCTION() virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; /// @@ -516,7 +515,6 @@ public: /// /// The buffer with drawing arguments. /// The aligned byte offset for arguments. - /// The number of draw command to execute. API_FUNCTION() virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0; public: