summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/diagnostics/constexpr-error.slang9
-rw-r--r--tests/diagnostics/constexpr-param.slang56
2 files changed, 62 insertions, 3 deletions
diff --git a/tests/diagnostics/constexpr-error.slang b/tests/diagnostics/constexpr-error.slang
index 0a4744b71..a79c71847 100644
--- a/tests/diagnostics/constexpr-error.slang
+++ b/tests/diagnostics/constexpr-error.slang
@@ -24,7 +24,7 @@ float4 main() : SV_Target
result += t.Sample(s, uv, int2(0,0));
// Error: data passed through cbuffer isn't compile-time constant
- // CHECK: ([[# @LINE+1]]): error 40006:
+ // CHECK: ([[# @LINE+1]]): error 40012:
result += t.Sample(s, uv, offset);
// Error: data computed via conditional isn't compile-time cosntant
@@ -33,16 +33,19 @@ float4 main() : SV_Target
{
ii = 1;
}
- // CHECK: ([[# @LINE+1]]): error 40006:
+ // CHECK: ([[# @LINE+1]]): error 40012:
result += t.Sample(s, uv, int2(ii));
// Error: data computed in loop isn't compile-time constant
// (and loop isn't unroll-able)
- // CHECK: ([[# @LINE+1]]): error 40006:
+ // CHECK: ([[# @LINE+1]]): error 40012:
for(uint jj = 0; jj < uv.y; jj++)
{
result += t.Sample(s, uv, int2(jj));
}
+
+
+
return result;
} \ No newline at end of file
diff --git a/tests/diagnostics/constexpr-param.slang b/tests/diagnostics/constexpr-param.slang
new file mode 100644
index 000000000..d41410b16
--- /dev/null
+++ b/tests/diagnostics/constexpr-param.slang
@@ -0,0 +1,56 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK1):
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK2):
+
+// Failure to pass compile-time-constant argument
+// where it is expected.
+//
+// Test both callee and nested callee that require constexpr parameters.
+// Test both function defined in the same module and external function.
+
+Texture2D<int> input;
+RWTexture2D<int> output;
+
+int func_with_constexpr_params(constexpr int const_a)
+{
+ return const_a + const_a;
+}
+
+int func_internal(int a)
+{
+ // Error: arg passed through isn't compile-time constant
+ // CHECK: ([[# @LINE+1]]): error 40013:
+ return func_with_constexpr_params(a);
+}
+
+int func_external(int a)
+{
+ // CHECK1: ([[# @LINE+1]]): error 40012:
+ int2 offset = int2(a, a);
+ int3 location = int3(0, 0, 0);
+ // Load requires constexpr offset
+ return input.Load(location, offset);
+}
+
+[shader("compute")]
+void Test(uint3 thread_index : SV_DispatchThreadID)
+{
+ int result = 0;
+
+ // Okay, immediate constant
+ result += func_with_constexpr_params(1);
+
+
+ int ii = 0;
+ if (thread_index.x > 0)
+ {
+ ii = 1;
+ }
+ // Pass non-compile-time-constant argument to function that requires constexpr parameter
+ // CHECK2: ([[# @LINE+1]]): error 40013:
+ result += func_with_constexpr_params(ii);
+
+ // The nested function calls should issue compile errors
+ result += func_internal(ii);
+ result += func_external(ii);
+}