Add stencilValue for stencil buffer clearing

This commit is contained in:
Wojtek Figat
2024-04-02 14:56:26 +02:00
parent bc9cdf5cdb
commit 13a04c2941
8 changed files with 12 additions and 16 deletions

View File

@@ -186,7 +186,8 @@ public:
/// </summary>
/// <param name="depthBuffer">The depth buffer to clear.</param>
/// <param name="depthValue">The clear depth value.</param>
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 1.0f) = 0;
/// <param name="stencilValue">The clear stencil value.</param>
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 1.0f, uint8 stencilValue = 0) = 0;
/// <summary>
/// Clears an unordered access buffer with a float value.

View File

@@ -151,21 +151,19 @@ bool GPUContextDX11::IsDepthBufferBinded()
void GPUContextDX11::Clear(GPUTextureView* rt, const Color& color)
{
auto rtDX11 = static_cast<GPUTextureViewDX11*>(rt);
if (rtDX11)
{
_context->ClearRenderTargetView(rtDX11->RTV(), color.Raw);
}
}
void GPUContextDX11::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
void GPUContextDX11::ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue)
{
auto depthBufferDX11 = static_cast<GPUTextureViewDX11*>(depthBuffer);
if (depthBufferDX11)
{
ASSERT(depthBufferDX11->DSV());
_context->ClearDepthStencilView(depthBufferDX11->DSV(), D3D11_CLEAR_DEPTH, depthValue, 0xff);
_context->ClearDepthStencilView(depthBufferDX11->DSV(), D3D11_CLEAR_DEPTH, depthValue, stencilValue);
}
}

View File

@@ -108,7 +108,7 @@ public:
void* GetNativePtr() const override;
bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override;

View File

@@ -703,7 +703,6 @@ bool GPUContextDX12::IsDepthBufferBinded()
void GPUContextDX12::Clear(GPUTextureView* rt, const Color& color)
{
auto rtDX12 = static_cast<GPUTextureViewDX12*>(rt);
if (rtDX12)
{
SetResourceState(rtDX12->GetResourceOwner(), D3D12_RESOURCE_STATE_RENDER_TARGET, rtDX12->SubresourceIndex);
@@ -713,16 +712,15 @@ void GPUContextDX12::Clear(GPUTextureView* rt, const Color& color)
}
}
void GPUContextDX12::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
void GPUContextDX12::ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue)
{
auto depthBufferDX12 = static_cast<GPUTextureViewDX12*>(depthBuffer);
if (depthBufferDX12)
{
SetResourceState(depthBufferDX12->GetResourceOwner(), D3D12_RESOURCE_STATE_DEPTH_WRITE, depthBufferDX12->SubresourceIndex);
flushRBs();
_commandList->ClearDepthStencilView(depthBufferDX12->DSV(), D3D12_CLEAR_FLAG_DEPTH, depthValue, 0xff, 0, nullptr);
_commandList->ClearDepthStencilView(depthBufferDX12->DSV(), D3D12_CLEAR_FLAG_DEPTH, depthValue, stencilValue, 0, nullptr);
}
}

View File

@@ -159,7 +159,7 @@ public:
void* GetNativePtr() const override;
bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override;

View File

@@ -48,7 +48,7 @@ public:
{
}
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override
void ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue) override
{
}

View File

@@ -797,10 +797,9 @@ void GPUContextVulkan::Clear(GPUTextureView* rt, const Color& color)
}
}
void GPUContextVulkan::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
void GPUContextVulkan::ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue)
{
const auto rtVulkan = static_cast<GPUTextureViewVulkan*>(depthBuffer);
if (rtVulkan)
{
// TODO: detect if inside render pass and use ClearAttachments
@@ -815,7 +814,7 @@ void GPUContextVulkan::ClearDepth(GPUTextureView* depthBuffer, float depthValue)
VkClearDepthStencilValue clear;
clear.depth = depthValue;
clear.stencil = 0;
clear.stencil = stencilValue;
vkCmdClearDepthStencilImage(cmdBuffer->GetHandle(), rtVulkan->Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear, 1, &rtVulkan->Info.subresourceRange);
}
}

View File

@@ -151,7 +151,7 @@ public:
void* GetNativePtr() const override;
bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue, uint8 stencilValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override;