Advertisement

Depth buffer resource, mipmaps

Started by December 03, 2018 02:15 PM
6 comments, last by GMCommand 6 years, 2 months ago

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

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. 

Advertisement

OK, thank you :)

:)

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.

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.

Advertisement
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 :)

This topic is closed to new replies.

Advertisement