summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/emit.cpp19
-rw-r--r--tests/bugs/gh-941.slang17
-rw-r--r--tests/bugs/gh-941.slang.glsl38
3 files changed, 74 insertions, 0 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index c17bb3266..e69ee2a93 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -6542,6 +6542,25 @@ struct EmitVisitor
return;
}
}
+
+ // When emitting unbounded-size resource arrays with GLSL we need
+ // to use the `GL_EXT_nonuniform_qualifier` extension to ensure
+ // that they are not treated as "implicitly-sized arrays" which
+ // are arrays that have a fixed size that just isn't specified
+ // at the declaration site (instead being inferred from use sites).
+ //
+ // While the extension primarily introduces the `nonuniformEXT`
+ // qualifier that we use to implement `NonUniformResourceIndex`,
+ // it also changes the GLSL language semantics around (resource) array
+ // declarations that don't specify a size.
+ //
+ if( as<IRUnsizedArrayType>(varType) )
+ {
+ if(isResourceType(unwrapArray(varType)))
+ {
+ requireGLSLExtension("GL_EXT_nonuniform_qualifier");
+ }
+ }
}
// Need to emit appropriate modifiers here.
diff --git a/tests/bugs/gh-941.slang b/tests/bugs/gh-941.slang
new file mode 100644
index 000000000..f66c25e97
--- /dev/null
+++ b/tests/bugs/gh-941.slang
@@ -0,0 +1,17 @@
+//TEST:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
+
+// Ensure that we add the `GL_EXT_nonuniform_qualifier` extension for any code that uses unbounded-size arrays of resources.
+
+Texture2D t[];
+SamplerState s;
+
+cbuffer C
+{
+ float2 uv;
+ uint index;
+}
+
+float4 main() : SV_Target
+{
+ return t[index].Sample(s, uv);
+}
diff --git a/tests/bugs/gh-941.slang.glsl b/tests/bugs/gh-941.slang.glsl
new file mode 100644
index 000000000..d3c29820d
--- /dev/null
+++ b/tests/bugs/gh-941.slang.glsl
@@ -0,0 +1,38 @@
+//TEST_IGNORE_FILE:
+
+#version 450
+
+#extension GL_EXT_nonuniform_qualifier : require
+
+struct SLANG_ParameterGroup_C_0
+{
+ vec2 uv_0;
+ uint index_0;
+};
+
+layout(binding = 2)
+layout(std140)
+uniform _S1
+{
+ SLANG_ParameterGroup_C_0 _data;
+} C_0;
+
+layout(binding = 0)
+uniform texture2D t_0[];
+
+layout(binding = 1)
+uniform sampler s_0;
+
+layout(location = 0)
+out vec4 _S2;
+
+void main()
+{
+ vec4 _S3 = texture(
+ sampler2D(
+ t_0[C_0._data.index_0],
+ s_0),
+ C_0._data.uv_0);
+ _S2 = _S3;
+ return;
+} \ No newline at end of file