diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp index 53234330e..f558152f1 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp @@ -188,6 +188,13 @@ void GPUContextDX11::ClearUA(GPUTexture* texture, const uint32 value[4]) _context->ClearUnorderedAccessViewUint(uav, value); } +void GPUContextDX11::ClearUA(GPUTexture* texture, const Vector4& value) +{ + ASSERT(texture != nullptr && texture->IsUnorderedAccess()); + auto uav = ((GPUTextureViewDX11*)(texture->IsVolume() ? texture->ViewVolume() : texture->View()))->UAV(); + _context->ClearUnorderedAccessViewFloat(uav, value.Raw); +} + void GPUContextDX11::ResetRenderTarget() { if (_rtCount != 0 || _rtDepth) diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h index 65aa31a5f..766aefe45 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.h @@ -110,6 +110,7 @@ public: void ClearUA(GPUBuffer* buf, const Vector4& value) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override; + void ClearUA(GPUTexture* texture, const Vector4& value) override; void ResetRenderTarget() override; void SetRenderTarget(GPUTextureView* rt) override; void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override; diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp index 966ce6dc8..2e2f57b06 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp @@ -755,6 +755,20 @@ void GPUContextDX12::ClearUA(GPUTexture* texture, const uint32 value[4]) _commandList->ClearUnorderedAccessViewUint(desc.GPU, uav, texDX12->GetResource(), value, 0, nullptr); } +void GPUContextDX12::ClearUA(GPUTexture* texture, const Vector4& value) +{ + ASSERT(texture != nullptr && texture->IsUnorderedAccess()); + auto texDX12 = reinterpret_cast(texture); + + SetResourceState(texDX12, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + flushRBs(); + + auto uav = ((GPUTextureViewDX12*)(texDX12->IsVolume() ? texDX12->ViewVolume() : texDX12->View(0)))->UAV(); + Descriptor desc; + GetActiveHeapDescriptor(uav, desc); + _commandList->ClearUnorderedAccessViewFloat(desc.GPU, uav, texDX12->GetResource(), value.Raw, 0, nullptr); +} + void GPUContextDX12::ResetRenderTarget() { if (_rtDepth || _rtCount != 0) diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h index 029745f37..b2285bd84 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.h @@ -160,6 +160,7 @@ public: void ClearUA(GPUBuffer* buf, const Vector4& value) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override; + void ClearUA(GPUTexture* texture, const Vector4& value) override; void ResetRenderTarget() override; void SetRenderTarget(GPUTextureView* rt) override; void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override; diff --git a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h index 3731ef204..64c4b1aca 100644 --- a/Source/Engine/GraphicsDevice/Null/GPUContextNull.h +++ b/Source/Engine/GraphicsDevice/Null/GPUContextNull.h @@ -64,6 +64,10 @@ public: { } + void ClearUA(GPUTexture* texture, const Vector4& value) override + { + } + void ResetRenderTarget() override { } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index f4c4f9330..f392a256a 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -874,6 +874,23 @@ void GPUContextVulkan::ClearUA(GPUTexture* texture, const uint32 value[4]) } } +void GPUContextVulkan::ClearUA(GPUTexture* texture, const Vector4& value) +{ + const auto texVulkan = static_cast(texture); + if (texVulkan) + { + auto rtVulkan = ((GPUTextureViewVulkan*)(texVulkan->IsVolume() ? texVulkan->ViewVolume() : texVulkan->View(0))); + const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer(); + if (cmdBuffer->IsInsideRenderPass()) + EndRenderPass(); + + AddImageBarrier(rtVulkan, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + FlushBarriers(); + + vkCmdClearColorImage(cmdBuffer->GetHandle(), rtVulkan->Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (const VkClearColorValue*)value.Raw, 1, &rtVulkan->Info.subresourceRange); + } +} + void GPUContextVulkan::ResetRenderTarget() { if (_rtDepth || _rtCount != 0) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h index 5665ef29b..a559d0e87 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h @@ -176,6 +176,7 @@ public: void ClearUA(GPUBuffer* buf, const Vector4& value) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override; + void ClearUA(GPUTexture* texture, const Vector4& value) override; void ResetRenderTarget() override; void SetRenderTarget(GPUTextureView* rt) override; void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;