Vulkan and mipmap generation

Started by
1 comment, last by C0lumbo 7 years, 11 months ago

I'm implementing the Scalable Ambient Obscurance algorithm on Vulkan ; at some point the algorithm is generating a mipchain on a linearized depth texture. I use a render pass to generate a linear depth texture and do the actual SAO computation. Then I use 2 compute shaders for the bilateral filtering since I can use shared memory to lessen memory bandwidth pressure.

I wonder what is the best way to do it in Vulkan ; the mipmap generation step would occur between the depth linear step and the SAO computation one. I can use a compute shader for every mipmap level ; introducing CS between graphic shaders is however not recommended since on some gpu (geforce ?) it triggers a unit reconfiguration and a cache flush. Since there is no advantage in using shared memory here the penalty can't be counterbalanced as for the bilateral passes. I could use a CS for the sao computation algorithm too but I rely on the dFdX function which is only available in fragment shader.

I can use a render pass too however I'm not sure how it will map to hardware. Since mipmap levels have different size it means using as many render passes as there are mipmap level. I fear this scenario may be suboptimal for renderpass and that switching renderpasses may increase an overhead of some sort.

Advertisement

On some of my back-ends, I implement mip-map generation using compute - which turned out to be faster than my PS based approach. The CS optimization that I used was to calculate and generate 3 mip levels per dispatch, which greatly reduces the number of passes required to compute the full chain.

i.e. I read 8x8 pixels, output 4x4 to the 1st RWTexture, 2x2 to the 2nd, and 1px to the 3rd.

You're right though that this graphics->compute->graphics transition could be quite bad on some GPU's... so maybe I should have two code-paths -- this CS mipping for some GPU's, and a PS fallback for others...

I think vkCmdBlitImage is likely to be a superior option for mipmap generation than using a render pass per mipmap level. Not sure how vkCmdBlitImage stacks up against a compute shader though.

This topic is closed to new replies.

Advertisement