Jump to content
  • Advertisement
Sign in to follow this  
kretash

OpenGL [D3D12] Enabling the depth test in d3d12

This topic is 1127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, first post in gamedev.net! ph34r.png

 

I have been building on top of the HelloTriangle demo and got a working obj loader. And its working fine, but i can't figure out how to enable the depth test in d3d12. My previous experience comes from opengl, so I'm just expecting to call glEnable(GL_DEPTH_TEST). Is it that simple in DirectX12?

 

I have looked in the multi-threading example and the instance example and couldn't find anything similar. What I did see is that both examples have a depth map. The multi-threading has shadows so it might just be rendering the depth to calculate that, but I'm not sure.

 

Cheers

 

Here's what it looks like: http://i.imgur.com/AQsEkeE.png

Share this post


Link to post
Share on other sites
Advertisement

Cool, I'm guessing you'll need to set this up.

psoDesc.DepthStencilState.DepthEnable = FALSE;

Thanks, i'll look into it in the morning.

Share this post


Link to post
Share on other sites

I have added this depth stencil description to the PSO and is doing the same thing.

  CD3DX12_DEPTH_STENCIL_DESC depthStencilDesc(D3D12_DEFAULT);
  depthStencilDesc.DepthEnable = true;
  depthStencilDesc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
  depthStencilDesc.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;
  depthStencilDesc.StencilEnable = FALSE;

Is the anything else i have to set up?

Share this post


Link to post
Share on other sites

I have added a depth buffer but I is not rendering to it.

    D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
    dsvHeapDesc.NumDescriptors = 1 + FrameCount * 1;
    dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
    dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
    result = m_device->CreateDescriptorHeap( &dsvHeapDesc, IID_PPV_ARGS( &m_dsvHeap ) );
    assert( result == S_OK && "ERROR CREATING THE DSV HEAP" );
{//Creating the depth texture
    CD3DX12_RESOURCE_DESC depth_texture( D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0,
      static_cast< UINT >( m_viewport.Width ), static_cast< UINT >( m_viewport.Height ), 1, 1,
      DXGI_FORMAT_D32_FLOAT, 1, 0, D3D12_TEXTURE_LAYOUT_UNKNOWN,
      D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE );

    D3D12_CLEAR_VALUE clear_value;
    clear_value.Format = DXGI_FORMAT_D32_FLOAT;
    clear_value.DepthStencil.Depth = 1.0f;
    clear_value.DepthStencil.Stencil = 0;

    result = m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES( D3D12_HEAP_TYPE_DEFAULT ),
      D3D12_HEAP_FLAG_NONE, &depth_texture, D3D12_RESOURCE_STATE_DEPTH_WRITE, &clear_value,
      IID_PPV_ARGS( &m_depthStencil ) );
    assert( result == S_OK && "CREATING THE DEPTH STENCIL FAILED" );

    m_device->CreateDepthStencilView( m_depthStencil.Get(), nullptr, m_dsvHeap->GetCPUDescriptorHandleForHeapStart() );
  }
m_commandList->ClearDepthStencilView( m_dsvHeap->GetCPUDescriptorHandleForHeapStart(),
    D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

BZ8C7le.png

 

The only thing that i think its missing is that the resource is not bound, but i dont know how to bind it.

Share this post


Link to post
Share on other sites

Create a texture with D3D12_RESOURCE_DIMENSION_TEXTURE2D and D3D12_TEXTURE_LAYOUT_UNKNOWN. after that, create a view on a DSV heap. while recording, get the D3D12_CPU_DESCRIPTOR_HANDLE of the dsv and set it at the last parameter of OMSetRenderTargets. Before that, ofc clear the view.

 

Looking at your code above, you have forgotten to set it in the OMSetRenderTargets function? like this: OMSetRenderTargets(1, &rtvHandle, false, &dsvHandle);

Edited by Anthom

Share this post


Link to post
Share on other sites

I was missing this

CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle( m_rtvHeap->GetCPUDescriptorHandleForHeapStart(),
    m_frameIndex, m_rtvDescriptorSize );
  CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle( m_dsvHeap->GetCPUDescriptorHandleForHeapStart() );
  m_commandList->OMSetRenderTargets( 1, &rtvHandle, FALSE, &dsvHandle );

Now it works!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!