summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-06 16:16:52 -0800
committerGitHub <noreply@github.com>2018-11-06 16:16:52 -0800
commit02e18b55faff56c037a76645c793b24b712fa375 (patch)
tree3f1ad284f7d9b0b30671dbe4aec95d106e9373e1
parent1185bd464092f372430cbfaa15a7be4dcaa90752 (diff)
Translate NonUniformResourceIndex() calls to Vulkan GLSL (#713)
These calls translate to uses of the `nonuniformEXT` qualifier introduced by the `GL_EXT_nonuniform_qualifier` extension. The standard library changes in this case are straightforward uses of existing compiler mechanisms. The test case is one of the less pleasant ones where we compare SPIR-V output against SPIR-V generated from a hand-coded GLSL baseline. This is a case where a simpler test type that just checks for specific textual matches in the output (and not whole files) would be better, but that is out of scope for this change.
-rw-r--r--source/slang/hlsl.meta.slang5
-rw-r--r--source/slang/hlsl.meta.slang.h5
-rw-r--r--tests/cross-compile/non-uniform-indexing.slang13
-rw-r--r--tests/cross-compile/non-uniform-indexing.slang.glsl28
4 files changed, 51 insertions, 0 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index fb03dfcfc..c666dadd3 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -871,7 +871,12 @@ __generic<let N : int> float noise(vector<float, N> x);
/// to this function as necessary in output code, rather than make this
/// the user's responsibility, so that the default behavior of the language
/// is more semantically "correct."
+__target_intrinsic(glsl, nonuniformEXT)
+__glsl_extension(GL_EXT_nonuniform_qualifier)
uint NonUniformResourceIndex(uint index);
+
+__target_intrinsic(glsl, nonuniformEXT)
+__glsl_extension(GL_EXT_nonuniform_qualifier)
int NonUniformResourceIndex(int index);
// Normalize a vector
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h
index e1e080d25..2db710ccb 100644
--- a/source/slang/hlsl.meta.slang.h
+++ b/source/slang/hlsl.meta.slang.h
@@ -916,7 +916,12 @@ SLANG_RAW("/// Note: a future version of Slang may take responsibility for inser
SLANG_RAW("/// to this function as necessary in output code, rather than make this\n")
SLANG_RAW("/// the user's responsibility, so that the default behavior of the language\n")
SLANG_RAW("/// is more semantically \"correct.\"\n")
+SLANG_RAW("__target_intrinsic(glsl, nonuniformEXT)\n")
+SLANG_RAW("__glsl_extension(GL_EXT_nonuniform_qualifier)\n")
SLANG_RAW("uint NonUniformResourceIndex(uint index);\n")
+SLANG_RAW("\n")
+SLANG_RAW("__target_intrinsic(glsl, nonuniformEXT)\n")
+SLANG_RAW("__glsl_extension(GL_EXT_nonuniform_qualifier)\n")
SLANG_RAW("int NonUniformResourceIndex(int index);\n")
SLANG_RAW("\n")
SLANG_RAW("// Normalize a vector\n")
diff --git a/tests/cross-compile/non-uniform-indexing.slang b/tests/cross-compile/non-uniform-indexing.slang
new file mode 100644
index 000000000..647742df8
--- /dev/null
+++ b/tests/cross-compile/non-uniform-indexing.slang
@@ -0,0 +1,13 @@
+//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment
+
+// Confirm that `NonUniformResourceIndex` translates to SPIR-V as expeted
+
+Texture2D t[10];
+SamplerState s;
+
+float4 main(
+ float3 uv : UV)
+ : SV_Target
+{
+ return t[NonUniformResourceIndex(int(uv.z))].Sample(s, uv.xy);
+}
diff --git a/tests/cross-compile/non-uniform-indexing.slang.glsl b/tests/cross-compile/non-uniform-indexing.slang.glsl
new file mode 100644
index 000000000..83f63c70d
--- /dev/null
+++ b/tests/cross-compile/non-uniform-indexing.slang.glsl
@@ -0,0 +1,28 @@
+//TEST_IGNORE_FILE
+#version 450
+
+#extension GL_EXT_nonuniform_qualifier : require
+
+layout(binding = 0)
+uniform texture2D t_0[10];
+
+layout(binding = 1)
+uniform sampler s_0;
+
+layout(location = 0)
+out vec4 _S1;
+
+layout(location = 0)
+in vec3 _S2;
+
+void main()
+{
+ vec3 _S3 = _S2;
+
+ int _S4 = nonuniformEXT(int(_S3.z));
+
+ vec4 _S5 = texture(sampler2D(t_0[_S4],s_0), _S3.xy);
+
+ _S1 = _S5;
+ return;
+}