Skip to content

Commit 196f07f

Browse files
authored
On GLSL targets emit 3 component texture layouts as 4 component (shader-slang#904)
* * On GLSL targets, output texture layouts that are 3 component as 4 component, because 4 component style is not supported by glslang currently * * Improve comment around SPIR-V and 3 component layouts.
1 parent 8fd57e2 commit 196f07f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

source/slang/emit.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -5612,9 +5612,29 @@ struct EmitVisitor
56125612
{
56135613
default: Emit("rgba"); break;
56145614

5615-
// TODO: GLSL doesn't actually seem to support 3-component formats
5616-
// universally, so this might cause problems.
5617-
case 3: Emit("rgb"); break;
5615+
case 3:
5616+
{
5617+
// TODO: GLSL doesn't support 3-component formats so for now we are going to
5618+
// default to rgba
5619+
//
5620+
// The SPIR-V spec (https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.pdf)
5621+
// section 3.11 on Image Formats it does not list rgbf32.
5622+
//
5623+
// It seems SPIR-V can support having an image with an unknown-at-compile-time
5624+
// format, so long as the underlying API supports it. Ideally this would mean that we can
5625+
// just drop all these qualifiers when emitting GLSL for Vulkan targets.
5626+
//
5627+
// This raises the question of what to do more long term. For Vulkan hopefully we can just
5628+
// drop the layout. For OpenGL targets it would seem reasonable to have well-defined rules
5629+
// for inferring the format (and just document that 3-component formats map to 4-component formats,
5630+
// but that shouldn't matter because the API wouldn't let the user allocate those 3-component formats anyway),
5631+
// and add an attribute for specifying the format manually if you really want to override our
5632+
// inference (e.g., to specify r11fg11fb10f).
5633+
5634+
Emit("rgba");
5635+
//Emit("rgb");
5636+
break;
5637+
}
56185638

56195639
case 2: Emit("rg"); break;
56205640
case 1: Emit("r"); break;

0 commit comments

Comments
 (0)