KhronosGroup / KTX-Specification

KTX file format source
Other
69 stars 12 forks source link

Generated format switches not including many Vulkan formats in 2glFormat and 2glType #209

Closed MarkCallow closed 4 months ago

MarkCallow commented 4 months ago

Here are the line counts for each file:

      79     308    5081 out/vkFormat2dxgiFormat.inl
      96     376    4883 out/vkFormat2glFormat.inl
     202     800   13649 out/vkFormat2glInternalFormat.inl
      96     376    5371 out/vkFormat2glType.inl
     137     540    9365 out/vkFormat2mtlFormat.inl
     610    2400   38349 total

Note that 2glFormat and 2glType have only 96 lines which 2glInternalFormat has 202. mtl and dxgi` look suspiciously short as well.

I ran into this while trying to get the glFormat for VK_FORMAT_BC3_UNORM_BLOCK and not finding it. Its not the generator. The data is missing in formats.json.

I am aware that most block compressed formats have a glFormat of GL_RGBA and glType of GL_UNSIGNED_BYTE. Most, but not all. Even if these values are true for the equivalents of all VkFormats used in ktx v2, when all you have is the token value it is not easy to special case for the compressed formats. It would be better if all formats can be handled uniformly. Therefore type and format info should be included in the database entry for all formats having a GL equivalent.

lexaknyazev commented 4 months ago

Compressed formats use only internalformat in OpenGL. See https://registry.khronos.org/OpenGL-Refpages/gl4/html/glCompressedTexImage2D.xhtml.

MarkCallow commented 4 months ago

Compressed formats use only internalformat in OpenGL

If you use glCompressedTexImage2D, but you can also use glTexImage2D. See https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml and https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt.

In the context of libktx, it is already identifying compressed textures and using glCompressedTexImage* to load them so it isn't much of a problem provided the format lookup, which happens earlier, is guarded. In the general context of a KTX file one can use the DFD's colorModel to quickly determine if a texture is compressed so I suppose it is okay to force everyone to have to choose the upload command according to the internalformat.

Please add a note at the top of Appendix B and to switch_test/vk2gl.c to the effect that for compressed formats only the mapping to the GL internalformat is provided. In vk2gl.c add something like "therefore only vkFormat2glInternalFormat provides a valid result."

lexaknyazev commented 4 months ago

but you can also use glTexImage2D

That workflow has different semantics and is unrelated to KTX operations. Specifically, the following command uploads uncompressed RGBA8 data and expects the OpenGL driver to compress it on the fly.

glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
             4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
MarkCallow commented 4 months ago

That workflow has different semantics

Oh! Silly me. Apologies. A comment in vk2gl.c is still a good idea, maybe not so important in Appendix B.