Skip to main content
Game Development

Return to Question

Don't repeat tags in title
Source Link
DMGregory
  • 140.5k
  • 23
  • 256
  • 395

DIRECTX12 - Can't write DepthBuffer — result is completely white

I am new to DX12 and I am currently trying to get the depthbufferdepth buffer to work. I have done pretty much everything identical to blogpostsblog posts I've seen online. I can also see that the depthbuffer-texturedepthbuffer-texture is there in renderdocRenderDoc, itsit's just completely white (see here):

enter image description hereWhite image in RenderDoc

Also, the depth target is in D3D12_RESOURCE_STATE_DEPTH_WRITED3D12_RESOURCE_STATE_DEPTH_WRITE state. I've set all the settings in my pipeline so it supports depthtestingdepth testing, matched the formats and everything.

PipelinesetupPipeline setup:

I don't understand why itsit's not working - help would be verymuchvery much appreciated. I dontdon't want to spam this complete thread with code (since itsit's quite a lot of boilerplate) so if you want to look at the complete code you can check it out here: https://github.com/eliasfuericht/artisDX/blob/main/src/Application.cpp

DIRECTX12 - Can't write DepthBuffer

I am new to DX12 and I am currently trying to get the depthbuffer to work. I have done pretty much everything identical to blogposts I've seen online. I can also see that the depthbuffer-texture is there in renderdoc, its just completely white (see here)enter image description here Also the depth target is in D3D12_RESOURCE_STATE_DEPTH_WRITE state. I've set all the settings in my pipeline so it supports depthtesting, matched the formats and everything.

Pipelinesetup:

I don't understand why its not working - help would be verymuch appreciated. I dont want to spam this complete thread with code (since its quite a lot of boilerplate) so if you want to look at the code you can check it out here: https://github.com/eliasfuericht/artisDX/blob/main/src/Application.cpp

Can't write DepthBuffer — result is completely white

I am new to DX12 and I am currently trying to get the depth buffer to work. I have done pretty much everything identical to blog posts I've seen online. I can also see that the depthbuffer-texture is there in RenderDoc, it's just completely white:

White image in RenderDoc

Also, the depth target is in D3D12_RESOURCE_STATE_DEPTH_WRITE state. I've set all the settings in my pipeline so it supports depth testing, matched the formats and everything.

Pipeline setup:

I don't understand why it's not working help would be very much appreciated. I don't want to spam this thread with code (since it's quite a lot of boilerplate) so if you want to look at the complete code you can check it out here: https://github.com/eliasfuericht/artisDX/blob/main/src/Application.cpp

Source Link
eli3D
  • 11
  • 3

DIRECTX12 - Can't write DepthBuffer

I am new to DX12 and I am currently trying to get the depthbuffer to work. I have done pretty much everything identical to blogposts I've seen online. I can also see that the depthbuffer-texture is there in renderdoc, its just completely white (see here)enter image description here Also the depth target is in D3D12_RESOURCE_STATE_DEPTH_WRITE state. I've set all the settings in my pipeline so it supports depthtesting, matched the formats and everything.

Pipelinesetup:

psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
psoDesc.SampleMask = UINT_MAX;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoDesc.SampleDesc.Count = 1;
ThrowIfFailed(_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&_pipelineState)));

DepthBuffer-Resource:

// Create the DSV Heap
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 1;
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ThrowIfFailed(_device->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(&_dsvHeap)));
// Heap properties for creating the texture (GPU read/write)
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
heapProps.CreationNodeMask = 1;
heapProps.VisibleNodeMask = 1;
// Create Depth-Stencil Resource (Texture2D)
D3D12_RESOURCE_DESC depthResourceDesc = {};
depthResourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
depthResourceDesc.Alignment = 0;
depthResourceDesc.Width = _width; // Width of the texture
depthResourceDesc.Height = _height; // Height of the texture
depthResourceDesc.DepthOrArraySize = 1;
depthResourceDesc.MipLevels = 1;
depthResourceDesc.Format = DXGI_FORMAT_D32_FLOAT; // Depth format (could also be D24_UNORM_S8_UINT)
depthResourceDesc.SampleDesc.Count = 1;
depthResourceDesc.SampleDesc.Quality = 0;
depthResourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
depthResourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
D3D12_CLEAR_VALUE depthOptimizedClearValue = {};
depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;
depthOptimizedClearValue.DepthStencil.Depth = 1.0f; // Default clear depth
depthOptimizedClearValue.DepthStencil.Stencil = 0; // Default clear stencil
ThrowIfFailed(_device->CreateCommittedResource(
 &heapProps,
 D3D12_HEAP_FLAG_NONE,
 &depthResourceDesc,
 D3D12_RESOURCE_STATE_DEPTH_WRITE,
 &depthOptimizedClearValue,
 IID_PPV_ARGS(&_depthStencilBuffer)
));
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
dsvDesc.Flags = D3D12_DSV_FLAG_NONE;
// Create the DSV for the depth-stencil buffer
_device->CreateDepthStencilView(_depthStencilBuffer.Get(), &dsvDesc, _dsvHeap->GetCPUDescriptorHandleForHeapStart());

And lastly binding:

D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = _rtvHeap->GetCPUDescriptorHandleForHeapStart();
rtvHandle.ptr += (_frameIndex * _rtvDescriptorSize);
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = _dsvHeap->GetCPUDescriptorHandleForHeapStart();
_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);
_commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0.0f, 0, nullptr);

I don't understand why its not working - help would be verymuch appreciated. I dont want to spam this complete thread with code (since its quite a lot of boilerplate) so if you want to look at the code you can check it out here: https://github.com/eliasfuericht/artisDX/blob/main/src/Application.cpp

default

AltStyle によって変換されたページ (->オリジナル) /