yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Gangzheng TongDiagnose error when the function args can't satisfy constexpr parameter requirements (#7269)afb8146e1

master
1.4 KiB56 linesraw
1//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
2//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK1):
3//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK2):
4
5// Failure to pass compile-time-constant argument
6// where it is expected.
7//
8// Test both callee and nested callee that require constexpr parameters.
9// Test both function defined in the same module and external function.
10
11Texture2D<int> input;
12RWTexture2D<int> output;
13
14int func_with_constexpr_params(constexpr int const_a)
15{
16    return const_a + const_a;
17}
18
19int func_internal(int a)
20{
21    // Error: arg passed through isn't compile-time constant
22    // CHECK: ([[# @LINE+1]]): error 40013:
23    return func_with_constexpr_params(a);
24}
25
26int func_external(int a)
27{
28    // CHECK1: ([[# @LINE+1]]): error 40012:
29    int2 offset = int2(a, a);
30    int3 location = int3(0, 0, 0);
31    // Load requires constexpr offset
32    return input.Load(location, offset);
33}
34
35[shader("compute")]
36void Test(uint3 thread_index : SV_DispatchThreadID)
37{
38    int result = 0;
39
40    // Okay, immediate constant
41    result += func_with_constexpr_params(1);
42
43
44    int ii = 0;
45    if (thread_index.x > 0)
46    {
47        ii = 1;
48    }
49    // Pass non-compile-time-constant argument to function that requires constexpr parameter
50    // CHECK2: ([[# @LINE+1]]): error 40013:
51    result += func_with_constexpr_params(ii);
52
53    // The nested function calls should issue compile errors
54    result += func_internal(ii);
55    result += func_external(ii);
56}