🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

D3D12 Enabling depth causes nothing to draw.

Started by
4 comments, last by Notallthatevil 1 year, 4 months ago

As the title suggests, I am enabling the depth checking on my PSO, which for some reason that I cannot figure out, nothing draws to the screen. If depth is false, I am able to see everything drawn to the screen, albeit, with behind data showing through.

Depth Disabled
Depth Enabled

Here is my code related to my depth buffer.

D3D12_RESOURCE_DESC desc{ .Dimension        = D3D12_RESOURCE_DIMENSION::D3D12_RESOURCE_DIMENSION_TEXTURE2D,
                          .Alignment        = 0,
                          .Width            = m_width,
                          .Height           = m_height,
                          .DepthOrArraySize = 1,
                          .MipLevels        = 1,
                          .Format           = DXGI_FORMAT::DXGI_FORMAT_D24_UNORM_S8_UINT,
                          .SampleDesc       = { .Count = 1, .Quality = 0 },
                          .Layout           = D3D12_TEXTURE_LAYOUT::D3D12_TEXTURE_LAYOUT_UNKNOWN,
                          .Flags            = D3D12_RESOURCE_FLAGS::D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL };

D3D12_CLEAR_VALUE clearValue{ .Format = DXGI_FORMAT::DXGI_FORMAT_D24_UNORM_S8_UINT, .DepthStencil = { .Depth = 1.f, .Stencil = 0 } };
dxAssertResult(m_device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
                                                 D3D12_HEAP_FLAG_NONE,
                                                 &desc,
                                                 D3D12_RESOURCE_STATE_DEPTH_WRITE,
                                                 &clearValue,
                                                 TNT_IID_PPV_ARGS(m_depthBuffer.GetAddressOf())));

m_depthBuffer->SetName(L"MainDepthBuffer");


// Returns a handle that contains one descriptor.
m_dsvHandleManager = CPUDXDescriptorHeap::allocateDescriptors(m_device.Get(), D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1); 

// m_dsvHandleManager.getHandle().CPUHandle returns the same handle every time it is called

m_device->CreateDepthStencilView(m_depthBuffer.Get(), nullptr, m_dsvHandleManager.getHandle().CPUHandle);
m_commandList->ClearDepthStencilView(m_dsvHandleManager.getHandle().CPUHandle, D3D12_CLEAR_FLAG_DEPTH, 1.f, 0, 0, nullptr);
m_commandList->OMSetRenderTargets(1, &renderTargetView, false, &depthStencilView);
Advertisement

What function have you setup in your PSO for in the DepthStencilDescriptor to determine which depth sample to keep?

D3D12_DEPTH_STENCIL_DESC& depthStencilStateDesc = m_pipeLineStateDescriptor.DepthStencilState;
depthStencilStateDesc.DepthEnable = true;
depthStencilStateDesc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
depthStencilStateDesc.DepthFunc = D3D12_COMPARISON_FUNC_GREATER_EQUAL;
depthStencilStateDesc.StencilEnable = 0;
depthStencilStateDesc.StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
depthStencilStateDesc.StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
depthStencilStateDesc.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
depthStencilStateDesc.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
depthStencilStateDesc.FrontFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP;
depthStencilStateDesc.FrontFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;
depthStencilStateDesc.BackFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
depthStencilStateDesc.BackFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
depthStencilStateDesc.BackFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP;
depthStencilStateDesc.BackFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;

This descriptor decides for each pixel that it renders what it should do with the values in the stencil and depth buffers

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

@NightCreature83
Currently it is set to LESS and the DepthWriteMask is ALL

I just tested it again, setting it to what you have suggested above (GREATER_EQUAL). It does draw; however, it now renders the same as depth disabled. What I mean is that it is still rendering the stuff behind. Actually, it will render as long as the Func is ≥ or ≤ like the screenshot below. Strictly greater also fails.

Yeah I clear with 0, and less equals should work for you in that case assuming that you are writing values less than 1 into the depth buffer when they are further away from the front plane.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

I appreciate the help. I figured out the issue though and it had nothing to do with the depth buffer at all, at least not directly.
What the problem actually was me making the mistake of setting the viewports max depth to some really high value. Doing so caused the depth buffer to not behave correctly. Setting the min and max depth to 0 and 1 of the viewports resolved all my issues.

This topic is closed to new replies.

Advertisement