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 D3D12 Depth Test Overlay #3126

Conversation

Zorro666
Copy link
Collaborator

Description

D3D12 Replay support for Issue #2858

This is a PR in a sequence of PRs which all together complete the implementation of the feature.
Future PRs will cover replay support for Vulkan and extending the automated overlay tests GL_Overlay_Test, D3D11_Overlay_Test, D3D12_Overlay_Test, VK_Overlay_Test.

The feature enables supporting shader exported depth for the Depth Test overlay by replaying the draw using the pixel shader from the capture instead of a replacement shader. Depth test passing pixels are identified by using the stencil buffer to generate a stencil mask.

If the depth buffer used for the draw does not have a stencil buffer then a new depth buffer is created with a depth+stencil format and a fullscreen pass is used to copy depth from the original depth buffer to the newly created depth+stencil buffer.

Tested on Windows using changes to D3D12_Overlay_Test

The change makes the pixel shader write out depth 0.0 for a small rectangle just bottom-left of the centre

Before (using v1.29) : the rectangle of output depth 0.0 is shown as failing the depth test

Depth Buffer format D24_S8
image
Depth Buffer format D32F_S8
image
Depth Buffer format D16 MSAA
imageDepth
Depth Buffer format D32F MSAA
image

After : the rectangle of output depth 0.0 is shown as passing the depth test

Depth Buffer format D24_S8
image
Depth Buffer format D32F_S8
image
Depth Buffer format D16 MSAA
image
Buffer format D32F MSAA
image

ID3D12RootSignature *DepthResolveRootSig = NULL;
std::unordered_map<DXGI_FORMAT, ID3D12PipelineState *[8]> DepthResolvePipe;
ID3D12RootSignature *DepthCopyRootSig = NULL;
std::unordered_map<DXGI_FORMAT, ID3D12PipelineState *[8]> DepthCopyPipe;
Copy link
Owner

Choose a reason for hiding this comment

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

A map here is overkill when we know this will only ever be used with two keys - I'd prefer just making this a simple array with [0] being D24S8 and [1] being D32S8, as that's what is done in other situations. If you want you can have a helper function to get the index for a given format, or you can do it with an if inline where needed.

RDCASSERT(root);
hr = device->CreateRootSignature(0, root->GetBufferPointer(), root->GetBufferSize(),
__uuidof(ID3D12RootSignature), (void **)&DepthCopyRootSig);
SAFE_RELEASE(root);
Copy link
Owner

Choose a reason for hiding this comment

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

There's no need for a root signature to be strictly limited to only the used elements, so you could use this same root signature for both passes. The only thing I'm not sure about is if D3D12 allows you to leave unused root signature parameters unset - it might be legal, but for safety you could bind the same parameter in both cases even if it's only used in one.

for(DXGI_FORMAT fmt : {DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_D32_FLOAT_S8X24_UINT})
{
ID3D12PipelineState **psos = DepthResolvePipe[fmt];
for(size_t i = 0; i < 8; i++)
Copy link
Owner

Choose a reason for hiding this comment

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

You can reduce this loop down to 5 instead of 8 - 16x MSAA is as high as any hardware supports currently or is likely to support.

if(overlayTexDesc.SampleDesc.Count == 1)
{
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = (UINT)-1;
Copy link
Owner

Choose a reason for hiding this comment

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

This kind of cast looks 'wrong' to me, I'd rather use ~0U or a #define if there is one.

Support shader exported depth by replaying using the capture pixel shader to determine passing pixels
@Zorro666 Zorro666 force-pushed the support-shader-exported-depth-in-depth-test-overlay-d3d12 branch from fb06951 to cc52b2e Compare November 13, 2023 09:44
@Zorro666 Zorro666 merged commit e9b7dfc into baldurk:v1.x Nov 13, 2023
16 checks passed
@Zorro666 Zorro666 deleted the support-shader-exported-depth-in-depth-test-overlay-d3d12 branch November 13, 2023 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants