PDA

View Full Version : imageStore on RGB formats



lebeta
07-14-2017, 07:43 AM
What is the rationale for GLSL's imageStore being unable to store in RGB formats? (e.g RGB8, RGB16, etc)
is there any workaround to this which doesn't require changing texture format?
cheers.

Dark Photon
07-15-2017, 11:17 AM
What is the rationale for GLSL's imageStore being unable to store in RGB formats? (e.g RGB8, RGB16, etc)

From ARB_shader_image_load_store (https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_image_load_store.txt)...


(3) Should we general support image loads and stores for three-component
"RGB" formats?

RESOLVED: Not in this extension. If an application needs to perform
image loads and stores on a three-component texture, it could use an
equivalent RGBA format and ignore the alpha component. The
EXT_texture_swizzle extension could be used to make the values returned
by texture appear identical to an RGB texture, if required.


This doesn't really answer your question though.

I suspect the reason is that some desktop GPUs do not support 24-bit RGB8 textures (or so I've read). They are internally converted to 32-bit by the driver, at the cost of app performance uploading content to them. This is probably due to the fact that the memory alignment of 3-byte texels isn't as nice as 4-byte. 3-component formats in general just don't fit as nicely into power-of-2-sized cache pages.

Also, on some drivers, if you query (via glGetInternalFormat() (https://www.khronos.org/opengl/wiki/GLAPI/glGetInternalformat)) the recommended internal formats to use (GL_INTERNAL_FORMAT_PREFERRED) for the non-packed non-compressed 2- and 3-component internal formats (e.g. GL_RGB8), the driver will suggest that you use the 4-component formats instead (e.g. GL_RGBA8).

Try asking your GL driver what it prefers for different internal formats (see this section (https://www.khronos.org/opengl/wiki/Common_Mistakes#Slow_pixel_transfer_performance) for a glGetInternalFormat() (https://www.khronos.org/opengl/wiki/GLAPI/glGetInternalformat) usage example). Try querying for the values of these parameters:



GL_INTERNALFORMAT_SUPPORTED
GL_INTERNALFORMAT_PREFERRED
GL_SHADER_IMAGE_STORE