diff --git a/renderdoc/data/hlsl/depth_copy.hlsl b/renderdoc/data/hlsl/depth_copy.hlsl index dbf1f750d..b6d3d926d 100644 --- a/renderdoc/data/hlsl/depth_copy.hlsl +++ b/renderdoc/data/hlsl/depth_copy.hlsl @@ -23,6 +23,10 @@ ******************************************************************************/ Texture2D 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 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 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 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; +} diff --git a/renderdoc/driver/d3d11/d3d11_debug.cpp b/renderdoc/driver/d3d11/d3d11_debug.cpp index b0bf81709..aaa122709 100644 --- a/renderdoc/driver/d3d11/d3d11_debug.cpp +++ b/renderdoc/driver/d3d11/d3d11_debug.cpp @@ -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); diff --git a/renderdoc/driver/d3d11/d3d11_overlay.cpp b/renderdoc/driver/d3d11/d3d11_overlay.cpp index 393c9ce92..73c8c671b 100644 --- a/renderdoc/driver/d3d11/d3d11_overlay.cpp +++ b/renderdoc/driver/d3d11/d3d11_overlay.cpp @@ -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(©Desc, &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); diff --git a/renderdoc/driver/d3d11/d3d11_replay.h b/renderdoc/driver/d3d11/d3d11_replay.h index 5e57498c7..f32d05027 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.h +++ b/renderdoc/driver/d3d11/d3d11_replay.h @@ -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;