Add GPUContext.ClearUA for buffer and texture with uint format
This commit is contained in:
@@ -198,12 +198,26 @@ public:
|
||||
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 1.0f) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Clears an unordered access resource with a float value.
|
||||
/// Clears an unordered access buffer with a float value.
|
||||
/// </summary>
|
||||
/// <param name="buf">The buffer to clear.</param>
|
||||
/// <param name="value">The clear value.</param>
|
||||
API_FUNCTION() virtual void ClearUA(GPUBuffer* buf, const Vector4& value) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Clears an unordered access buffer with a unsigned value.
|
||||
/// </summary>
|
||||
/// <param name="buf">The buffer to clear.</param>
|
||||
/// <param name="value">The clear value.</param>
|
||||
virtual void ClearUA(GPUBuffer* buf, const uint32 value[4]) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Clears an unordered access texture with a unsigned value.
|
||||
/// </summary>
|
||||
/// <param name="texture">The texture to clear.</param>
|
||||
/// <param name="value">The clear value.</param>
|
||||
virtual void ClearUA(GPUTexture* texture, const uint32 value[4]) = 0;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -170,12 +170,24 @@ void GPUContextDX11::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
|
||||
void GPUContextDX11::ClearUA(GPUBuffer* buf, const Vector4& value)
|
||||
{
|
||||
ASSERT(buf != nullptr && buf->IsUnorderedAccess());
|
||||
|
||||
auto uav = ((GPUBufferViewDX11*)buf->View())->UAV();
|
||||
|
||||
_context->ClearUnorderedAccessViewFloat(uav, value.Raw);
|
||||
}
|
||||
|
||||
void GPUContextDX11::ClearUA(GPUBuffer* buf, const uint32 value[4])
|
||||
{
|
||||
ASSERT(buf != nullptr && buf->IsUnorderedAccess());
|
||||
auto uav = ((GPUBufferViewDX11*)buf->View())->UAV();
|
||||
_context->ClearUnorderedAccessViewUint(uav, value);
|
||||
}
|
||||
|
||||
void GPUContextDX11::ClearUA(GPUTexture* texture, const uint32 value[4])
|
||||
{
|
||||
ASSERT(texture != nullptr && texture->IsUnorderedAccess());
|
||||
auto uav = ((GPUTextureViewDX11*)texture->View())->UAV();
|
||||
_context->ClearUnorderedAccessViewUint(uav, value);
|
||||
}
|
||||
|
||||
void GPUContextDX11::ResetRenderTarget()
|
||||
{
|
||||
if (_rtCount != 0 || _rtDepth)
|
||||
|
||||
@@ -108,6 +108,8 @@ public:
|
||||
void Clear(GPUTextureView* rt, const Color& color) override;
|
||||
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override;
|
||||
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 ResetRenderTarget() override;
|
||||
void SetRenderTarget(GPUTextureView* rt) override;
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||
|
||||
@@ -727,6 +727,34 @@ void GPUContextDX12::ClearUA(GPUBuffer* buf, const Vector4& value)
|
||||
_commandList->ClearUnorderedAccessViewFloat(desc.GPU, uav, bufDX12->GetResource(), value.Raw, 0, nullptr);
|
||||
}
|
||||
|
||||
void GPUContextDX12::ClearUA(GPUBuffer* buf, const uint32 value[4])
|
||||
{
|
||||
ASSERT(buf != nullptr && buf->IsUnorderedAccess());
|
||||
auto bufDX12 = reinterpret_cast<GPUBufferDX12*>(buf);
|
||||
|
||||
SetResourceState(bufDX12, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
flushRBs();
|
||||
|
||||
auto uav = ((GPUBufferViewDX12*)bufDX12->View())->UAV();
|
||||
Descriptor desc;
|
||||
GetActiveHeapDescriptor(uav, desc);
|
||||
_commandList->ClearUnorderedAccessViewUint(desc.GPU, uav, bufDX12->GetResource(), value, 0, nullptr);
|
||||
}
|
||||
|
||||
void GPUContextDX12::ClearUA(GPUTexture* texture, const uint32 value[4])
|
||||
{
|
||||
ASSERT(texture != nullptr && texture->IsUnorderedAccess());
|
||||
auto texDX12 = reinterpret_cast<GPUTextureDX12*>(texture);
|
||||
|
||||
SetResourceState(texDX12, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
flushRBs();
|
||||
|
||||
auto uav = ((GPUTextureViewDX12*)texDX12->View(0))->UAV();
|
||||
Descriptor desc;
|
||||
GetActiveHeapDescriptor(uav, desc);
|
||||
_commandList->ClearUnorderedAccessViewUint(desc.GPU, uav, texDX12->GetResource(), value, 0, nullptr);
|
||||
}
|
||||
|
||||
void GPUContextDX12::ResetRenderTarget()
|
||||
{
|
||||
if (_rtDepth || _rtCount != 0)
|
||||
|
||||
@@ -56,6 +56,14 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override
|
||||
{
|
||||
}
|
||||
|
||||
void ClearUA(GPUTexture* texture, const uint32 value[4]) override
|
||||
{
|
||||
}
|
||||
|
||||
void ResetRenderTarget() override
|
||||
{
|
||||
}
|
||||
|
||||
@@ -831,18 +831,49 @@ void GPUContextVulkan::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
|
||||
void GPUContextVulkan::ClearUA(GPUBuffer* buf, const Vector4& value)
|
||||
{
|
||||
const auto bufVulkan = static_cast<GPUBufferVulkan*>(buf);
|
||||
|
||||
if (bufVulkan)
|
||||
{
|
||||
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||
if (cmdBuffer->IsInsideRenderPass())
|
||||
EndRenderPass();
|
||||
|
||||
// TODO: add support for other components if buffer has them
|
||||
uint32_t* data = (uint32_t*)&value;
|
||||
vkCmdFillBuffer(cmdBuffer->GetHandle(), bufVulkan->GetHandle(), 0, bufVulkan->GetSize(), *data);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUContextVulkan::ClearUA(GPUBuffer* buf, const uint32 value[4])
|
||||
{
|
||||
const auto bufVulkan = static_cast<GPUBufferVulkan*>(buf);
|
||||
if (bufVulkan)
|
||||
{
|
||||
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||
if (cmdBuffer->IsInsideRenderPass())
|
||||
EndRenderPass();
|
||||
|
||||
// TODO: add support for other components if buffer has them
|
||||
vkCmdFillBuffer(cmdBuffer->GetHandle(), bufVulkan->GetHandle(), 0, bufVulkan->GetSize(), value[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUContextVulkan::ClearUA(GPUTexture* texture, const uint32 value[4])
|
||||
{
|
||||
const auto texVulkan = static_cast<GPUTextureVulkan*>(texture);
|
||||
if (texVulkan)
|
||||
{
|
||||
auto rtVulkan = static_cast<GPUTextureViewVulkan*>(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, 1, &rtVulkan->Info.subresourceRange);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUContextVulkan::ResetRenderTarget()
|
||||
{
|
||||
if (_rtDepth || _rtCount != 0)
|
||||
|
||||
@@ -174,6 +174,8 @@ public:
|
||||
void Clear(GPUTextureView* rt, const Color& color) override;
|
||||
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override;
|
||||
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 ResetRenderTarget() override;
|
||||
void SetRenderTarget(GPUTextureView* rt) override;
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||
|
||||
Reference in New Issue
Block a user