d3d11 Mipmaps and Compute Shader

Started by
6 comments, last by Hornsj3 12 years, 1 month ago
I am pumping the top mip level of a texture through a compute shader, but I want the result to propagate down to the lower mip levels. Is there a way for the hardware to generate the lower mips from the top level?

I know there is D3D11_RESOURCE_MISC_GENERATE_MIPS, but the docs say this only works for a SRV with "bind flags that specify that the resource is a render target and a shader resource," and my resource just has bind flags D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS.
-----Quat
Advertisement
Can you put BIND_RENDER_TARGET on the texture and try generating the mips? I'm not sure if it would work, but it's worth a shot. If not, then you can generate mips very easily with a simple pixel shader that samples the higher mip level and renders to the lower mip level. You could also do it with a compute shader, but I'm pretty sure it would be faster with a pixel shader.
I know this topic has been around for a while but I was wondering if you found a solution.

Also, how do you invoke a pixel shader without a fragment (pixel candiate) ? Do you invoke a shader on a piece of geometry in order to generate the mips? Also, if I wanted to fill all mip levels in the pyramid this way would I have to run multiple passes?


Thanks.
You can generate mipmaps for resources with bind flag D3D11_BIND_UNORDERED_ACCESS in dx11.

You have to set the following bind flags:
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET | D3D11_BIND_UNORDERED_ACCESS

Use your compute shader to write to the highest quality mip.
Unbind the UAV and call Context->GenerateMips(); on the SRV for the resource.
This works just fine.

I'm currently using it to generate mips for a cubemap generated with a compute shader.
Thank you for the reply.

I would like to fill the mip levels with values I compute (max value of the 4 texels on the next lowest layer) rather than the standard (average of 4 texels on the next lowest layer).

Sampling a texture at level N for the 4 texels of the mipmap and writing the max value in the appropriate texel at layer N+1 would be exactly what I need to do.

Example Mip Pyramid:
Level N: 512x512 (texture / miplevel to sample)
Level N+1: 256x256 (texture / miplevel to write)
Level N+2: 128x128
Level N+3: 64x64
Level N+4: 32x32
Level N+5: 16x16
Level N+6: 8x8
Level N+7: 4x4
Level N+8: 2x2
Level N+9: 1

It is not to be used for LOD in the traditional way, which is why I need to do this.
I think I've decided to do this in the compute shader. It seems possible to bind an unordered access view for each mip level and write the data to those views for each level.
I wasn't aware that it was possible to bind individual mip slices as UAV's.
That seems to be the correct way to do this then.
Don't take my word as gospel, as I'm feeling my way through this.

However, the D3D11_UNORDERED_ACCESS_VIEW_DESC has a member of type D3D11_TEX2D_UAV, which contains a member called mipslice.

I believe this will allow me to bind individual slices to unordered access views and write to them in the compute shader.

[font="Consolas, Courier, monospace"]I have yet to verify this but I am about to hack it out.[/font]

This topic is closed to new replies.

Advertisement