summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/constexpr-error.slang45
-rw-r--r--tests/diagnostics/constexpr-error.slang.expected8
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/diagnostics/constexpr-error.slang b/tests/diagnostics/constexpr-error.slang
new file mode 100644
index 000000000..6006450a1
--- /dev/null
+++ b/tests/diagnostics/constexpr-error.slang
@@ -0,0 +1,45 @@
+//TEST:SIMPLE:
+
+// Failure to pass compile-time-constant data
+// where it is expected.
+//
+// In this case, the place where compile-time-constant
+// data is expected is the texel offset parameter to
+// the `Texture2D.Sample` operation.
+
+Texture2D t;
+SamplerState s;
+
+cbuffer U
+{
+ float2 uv;
+ uint2 offset;
+};
+
+float4 main() : SV_Target
+{
+ float4 result = 0.0f;
+
+ // Okay, immediate constant
+ result += t.Sample(s, uv, uint2(0,0));
+
+ // Error: data passed through cbuffer isn't compile-time constant
+ result += t.Sample(s, uv, offset);
+
+ // Error: data computed via conditional isn't compile-time cosntant
+ uint ii = 0;
+ if(uv.x > 0.0f)
+ {
+ ii = 1;
+ }
+ result += t.Sample(s, uv, uint2(ii));
+
+ // Error: data computed in loop isn't compile-time constant
+ // (and loop isn't unroll-able)
+ for(uint jj = 0; jj < uv.y; jj++)
+ {
+ result += t.Sample(s, uv, uint2(jj));
+ }
+
+ return result;
+} \ No newline at end of file
diff --git a/tests/diagnostics/constexpr-error.slang.expected b/tests/diagnostics/constexpr-error.slang.expected
new file mode 100644
index 000000000..c0b5e94d3
--- /dev/null
+++ b/tests/diagnostics/constexpr-error.slang.expected
@@ -0,0 +1,8 @@
+result code = -1
+standard error = {
+tests/diagnostics/constexpr-error.slang(27): error 40006: expected a compile-time constant
+tests/diagnostics/constexpr-error.slang(35): error 40006: expected a compile-time constant
+tests/diagnostics/constexpr-error.slang(41): error 40006: expected a compile-time constant
+}
+standard output = {
+}