Jump to content
  • Advertisement
GMCommand

DX12 Depth buffer resource, mipmaps

Recommended Posts

Hello everyone,

I have a little question about depth resource and D3D12.
I need to have mip levels of the depth buffer(as described in some SSR techniques). What I thought I could do was run the geometry pass to get the depth, then use a compute shader to generate the mip levels of the depth buffer, in the same resource as the depth buffer.
So I created a resource, with D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, but as I needed it in the compute shader, I also had to set the ALLOW_UNORDERED_ACCES flag... which is not compatible with the first one :|.
My question is do I need to create another resource, copy the depth buffer to it and generate the mip levels on that copied resource ? or am I missing something and there's a way to do it directly in the depth buffer resource ?

Thanks

Share this post


Link to post
Share on other sites
Advertisement

You're correct. From memory, mip maps aren't compatible depth-stencil resources either, so you'd have to copy it to a mippable resource anyway. 

Share this post


Link to post
Share on other sites

Rather than the 2 stage process of buffer copying to your target resource, then later generating the mips on that target with a compute shader,

you could do it in a single step by using the depth texture as a srv input for the compute shader and have that compute shader be responsible for both copying of the input srv's pixels to the highest level of the target texture and also creating the mips and write those to the target texture.

Edited by CortexDragon

Share this post


Link to post
Share on other sites
On 12/3/2018 at 3:12 PM, Hodgman said:

From memory, mip maps aren't compatible depth-stencil resources either, so you'd have to copy it to a mippable resource anyway. 

Documentation disagrees. D3D12_TEX2D_DSV contains a field for a MipSlice. Depth resource can in fact be mipped, but there's no way to write to the individual mips other than to explicitly bind them as a DSV. I have no idea why you'd do such a thing, but it is in fact legal.

Share this post


Link to post
Share on other sites
7 hours ago, SoldierOfLight said:

Documentation disagrees. D3D12_TEX2D_DSV contains a field for a MipSlice. Depth resource can in fact be mipped, but there's no way to write to the individual mips other than to explicitly bind them as a DSV. I have no idea why you'd do such a thing, but it is in fact legal.

Ah yes, it reads it in the subresource page too : "Depth-Stencil is the only format that fully supports mipmaps, arrays, and multiple planes (often plane 0 for Depth and plane 1 for Stencil)".

10 hours ago, CortexDragon said:

Rather than the 2 stage process of buffer copying to your target resource, then later generating the mips on that target with a compute shader,

you could do it in a single step by using the depth texture as a srv input for the compute shader and have that compute shader be responsible for both copying of the input srv's pixels to the highest level of the target texture and also creating the mips and write those to the target texture.

Yes indeed, thank you for pointing this out :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!