nvpro-samples / vk_compute_mipmaps

Customizable compute shader for fast cache-aware mipmap generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question, why is rgba8ui used as the output format and not rgba8?

mbechard opened this issue · comments

First of all, thanks so much for making this library available. Very nice and easy to integrate!

My question:
Why is rgba8ui used as the output format and not rgba8? Is there a performance reason for this? I ask since support for other pixel formats is easier to handle if the code is just writing out vec4 instead of uvec4. Also, handling of BGRA8 vs RGBA8 formats is done automatically when using rgba8.

This is just because I prefer to perform the encode from linear color space to 8-bit encoded sRGB color space manually (i.e. "gamma correction"). In a compute shader using imageStore, there is currently no way to rely on the hardware sRGB encoder, so you can either manually convert to sRGB-encoded vec4 (relying on the hardware to quantize from float to uint8) or manually convert to 8-bit sRGB-encoded uvec4. I arbitrarily chose the latter approach (personal opinion, it's less likely to make "mixing color spaces" mistakes if separate types are used for different color spaces, in this case vec4 for linear, uvec4 for sRGB-encoded).

As far as I know, imageStore also doesn't handle any RGB-to-BGR swizzles automatically. Both hardware sRGB output and image swizzling are features exclusive to framebuffers (only relevant for graphics pipelines).

If adapting the example shader, the minimal change in the shader to switch to using vec4 output should just be to change the output image declaration and remove the srgbFromLinearVec call from the NVPRO_PYRAMID_STORE macro:

layout(set=1, binding=0, rgba8) uniform writeonly uimage2D imageMipLevels[16];

#define NVPRO_PYRAMID_STORE(coord, level, in_) imageStore(imageMipLevels[level], coord, in_)

Alternatively, if srgb correction is still needed, the srgbFromLinearVec function can just be modified to output a vec4 instead of uvec4.

Ok, thanks for the answer. As far as I can tell imageStore does handle RGB-to-BGR swizzles automatically, but certainly not the sRGB conversions. I've already adapted the code to work closer to my workflow, it was a clean to do so.
Thanks again for this library!