Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend D3D11 Depth Test Overlay #3118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions renderdoc/data/hlsl/depth_copy.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2023 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

Texture2D<float2> srcDepth : register(t0);

void RENDERDOC_DepthCopyPS(float4 pos : SV_Position, out float depth : SV_Depth)
{
int2 srcCoord = int2(int(pos.x), int(pos.y));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: I believe this could just be int2 srcCoord = int2(pos.xy);.

depth = srcDepth.Load(int3(srcCoord, 0)).r;
}

Texture2DMS<float2> srcDepthMS : register(t0);

void RENDERDOC_DepthCopyMSPS(float4 pos
: SV_Position, uint sample
: SV_SampleIndex, out float depth
: SV_Depth)
{
int2 srcCoord = int2(int(pos.x), int(pos.y));
depth = srcDepthMS.Load(srcCoord, sample).r;
}
1 change: 1 addition & 0 deletions renderdoc/data/renderdoc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ RESOURCE_texremap_hlsl TYPE_EMBED "hlsl/texremap.hlsl"
RESOURCE_fixedcol_hlsl TYPE_EMBED "hlsl/fixedcol.hlsl"
RESOURCE_shaderdebug_hlsl TYPE_EMBED "hlsl/shaderdebug.hlsl"
RESOURCE_d3d12_pixelhistory_hlsl TYPE_EMBED "hlsl/d3d12_pixelhistory.hlsl"
RESOURCE_depth_copy_hlsl TYPE_EMBED "hlsl/depth_copy.hlsl"

#ifdef RENDERDOC_BAKED_DXC_SHADERS

Expand Down
1 change: 1 addition & 0 deletions renderdoc/data/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define RESOURCE_fixedcol_hlsl 112
#define RESOURCE_shaderdebug_hlsl 118
#define RESOURCE_d3d12_pixelhistory_hlsl 119
#define RESOURCE_depth_copy_hlsl 120

#define RESOURCE_fixedcol_0_dxbc 113
#define RESOURCE_fixedcol_1_dxbc 114
Expand Down
39 changes: 39 additions & 0 deletions renderdoc/driver/d3d11/d3d11_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,40 @@ void D3D11Replay::OverlayRendering::Init(WrappedID3D11Device *device)
TriangleSizePS =
shaderCache->MakePShader(meshhlsl.c_str(), "RENDERDOC_TriangleSizePS", "ps_4_0");
}
{
rdcstr hlsl = GetEmbeddedResource(depth_copy_hlsl);

DepthCopyPS = shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyPS", "ps_5_0");
DepthCopyMSPS = shaderCache->MakePShader(hlsl.c_str(), "RENDERDOC_DepthCopyMSPS", "ps_5_0");
}
{
D3D11_BLEND_DESC blendDesc = {};
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
HRESULT hr = device->CreateBlendState(&blendDesc, &DepthBlendRTMaskZero);
if(FAILED(hr))
{
RDCERR("Failed to create depth overlay blend state HRESULT: %s", ToStr(hr).c_str());
}
}
{
D3D11_DEPTH_STENCIL_DESC dsDesc = {};
dsDesc.DepthEnable = FALSE;
dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
dsDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
dsDesc.StencilEnable = TRUE;
dsDesc.StencilReadMask = 0xff;
dsDesc.StencilWriteMask = 0x0;
dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_EQUAL;
dsDesc.BackFace = dsDesc.FrontFace;
HRESULT hr = device->CreateDepthStencilState(&dsDesc, &DepthResolveDS);
if(FAILED(hr))
{
RDCERR("Failed to create depth resolve depth stencil state HRESULT: %s", ToStr(hr).c_str());
}
}
}

void D3D11Replay::OverlayRendering::Release()
Expand All @@ -1144,6 +1178,11 @@ void D3D11Replay::OverlayRendering::Release()
SAFE_RELEASE(QOResolvePS);
SAFE_RELEASE(TriangleSizeGS);
SAFE_RELEASE(TriangleSizePS);
SAFE_RELEASE(DepthCopyPS);
SAFE_RELEASE(DepthCopyMSPS);

SAFE_RELEASE(DepthResolveDS);
SAFE_RELEASE(DepthBlendRTMaskZero);

SAFE_RELEASE(Texture);
}
Expand Down
Loading