D3D11 Depth Overlay improvements

Handle depth copying with a texture array source
Clear stencil to zero during the depth copy to match the other implementations
Specify the bind flags when creating the new depth-stencil texture
This commit is contained in:
Jake Turner
2023-11-30 15:05:25 +00:00
parent d52f97c225
commit defe79d82c
4 changed files with 66 additions and 3 deletions
+23
View File
@@ -23,6 +23,10 @@
******************************************************************************/
Texture2D<float2> srcDepth : register(t0);
cbuffer ViewInput : register(b0)
{
uint4 viewData; // viewIndex, ???, ???, ???
};
void RENDERDOC_DepthCopyPS(float4 pos : SV_Position, out float depth : SV_Depth)
{
@@ -30,6 +34,14 @@ void RENDERDOC_DepthCopyPS(float4 pos : SV_Position, out float depth : SV_Depth)
depth = srcDepth.Load(int3(srcCoord, 0)).r;
}
Texture2DArray<float2> srcDepthArray : register(t0);
void RENDERDOC_DepthCopyArrayPS(float4 pos : SV_Position, out float depth : SV_Depth)
{
int2 srcCoord = int2(pos.xy);
depth = srcDepthArray.Load(int4(srcCoord, viewData.x, 0)).r;
}
Texture2DMS<float2> srcDepthMS : register(t0);
void RENDERDOC_DepthCopyMSPS(float4 pos
@@ -40,3 +52,14 @@ void RENDERDOC_DepthCopyMSPS(float4 pos
int2 srcCoord = int2(pos.xy);
depth = srcDepthMS.Load(srcCoord, sample).r;
}
Texture2DMSArray<float2> srcDepthMSArray : register(t0);
void RENDERDOC_DepthCopyMSArrayPS(float4 pos
: SV_Position, uint sample
: SV_SampleIndex, out float depth
: SV_Depth)
{
int2 srcCoord = int2(pos.xy);
depth = srcDepthMSArray.Load(int3(srcCoord, viewData.x), sample).r;
}
+6
View File
@@ -1139,7 +1139,11 @@ void D3D11Replay::OverlayRendering::Init(WrappedID3D11Device *device)
rdcstr hlsl = GetEmbeddedResource(depth_copy_hlsl);
DepthCopyPS = shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyPS", "ps_5_0");
DepthCopyArrayPS =
shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyArrayPS", "ps_5_0");
DepthCopyMSPS = shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyMSPS", "ps_5_0");
DepthCopyMSArrayPS =
shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyMSArrayPS", "ps_5_0");
}
{
D3D11_BLEND_DESC blendDesc = {};
@@ -1179,7 +1183,9 @@ void D3D11Replay::OverlayRendering::Release()
SAFE_RELEASE(TriangleSizeGS);
SAFE_RELEASE(TriangleSizePS);
SAFE_RELEASE(DepthCopyPS);
SAFE_RELEASE(DepthCopyArrayPS);
SAFE_RELEASE(DepthCopyMSPS);
SAFE_RELEASE(DepthCopyMSArrayPS);
SAFE_RELEASE(DepthResolveDS);
SAFE_RELEASE(DepthBlendRTMaskZero);
+35 -3
View File
@@ -1406,6 +1406,9 @@ ResourceId D3D11Replay::RenderOverlay(ResourceId texid, FloatVector clearCol, De
D3D11_TEXTURE2D_DESC dsTexDesc;
renderDepth->GetDesc(&dsTexDesc);
dsTexDesc.Format = dsNewFmt;
// only need depth stencil, other bind flags may be invalid with the typed format
dsTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
dsTexDesc.MiscFlags = 0;
hr = m_pDevice->CreateTexture2D(&dsTexDesc, NULL, &renderDepthStencil);
if(FAILED(hr))
{
@@ -1446,7 +1449,16 @@ ResourceId D3D11Replay::RenderOverlay(ResourceId texid, FloatVector clearCol, De
copyDesc.DepthEnable = TRUE;
copyDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
copyDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
copyDesc.StencilEnable = FALSE;
// Clear the stencil to zero during the copy
copyDesc.StencilEnable = TRUE;
copyDesc.StencilReadMask = 0x0;
copyDesc.StencilWriteMask = 0xff;
copyDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
copyDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
copyDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
copyDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
copyDesc.BackFace = copyDesc.FrontFace;
SAFE_RELEASE(os);
hr = m_pDevice->CreateDepthStencilState(&copyDesc, &os);
if(FAILED(hr))
@@ -1471,10 +1483,30 @@ ResourceId D3D11Replay::RenderOverlay(ResourceId texid, FloatVector clearCol, De
m_pImmediateContext->GSSetShader(NULL, NULL, 0);
m_pImmediateContext->PSSetShaderResources(0, 1, &depthSRV);
if(srvDesc.ArraySize > 1)
{
uint32_t viewIndex[4] = {};
if(srvDesc.SampleDesc.Count > 1)
viewIndex[0] = dsViewDesc.Texture2DMSArray.FirstArraySlice;
else
viewIndex[0] = dsViewDesc.Texture2DArray.FirstArraySlice;
ID3D11Buffer *buf = GetDebugManager()->MakeCBuffer(viewIndex, sizeof(viewIndex));
m_pImmediateContext->PSSetConstantBuffers(0, 1, &buf);
}
if(srvDesc.SampleDesc.Count > 1)
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyMSPS, NULL, 0);
{
if(srvDesc.ArraySize > 1)
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyMSArrayPS, NULL, 0);
else
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyMSPS, NULL, 0);
}
else
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyPS, NULL, 0);
{
if(srvDesc.ArraySize > 1)
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyArrayPS, NULL, 0);
else
m_pImmediateContext->PSSetShader(m_Overlay.DepthCopyPS, NULL, 0);
}
m_pImmediateContext->RSSetState(m_General.RasterState);
+2
View File
@@ -426,7 +426,9 @@ private:
ID3D11PixelShader *QOResolvePS = NULL;
ID3D11PixelShader *TriangleSizePS = NULL;
ID3D11PixelShader *DepthCopyPS = NULL;
ID3D11PixelShader *DepthCopyArrayPS = NULL;
ID3D11PixelShader *DepthCopyMSPS = NULL;
ID3D11PixelShader *DepthCopyMSArrayPS = NULL;
ID3D11GeometryShader *TriangleSizeGS = NULL;
ID3D11BlendState *DepthBlendRTMaskZero = NULL;
ID3D11DepthStencilState *DepthResolveDS = NULL;