summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/const-to-nodiff-function-diagnostic-improvement.slang
blob: 961ac75d5af2b4fb5a6ea0f1866e92744ea35118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):

float someNoDiffFunc(float x, no_diff float y)
{
    return x * x + y * y;
}

// Previously, when we call a no-diff function side a differntiable function, we will have to use no_diff to tell compiler that this is intended.
// However, if the parameter is just a constant, there is no need to use no_diff, because constant won't carry any derivative information.
// Therefore, this test is to check we won't report any error when the parameter is a constant in this case.
[Differentiable]
float eval(float x)
{
    // CHECK-NOT: ([[# @LINE+1]]): error 41020
    return exp(x) - someNoDiffFunc(1.0f, x);
}

[Differentiable]
float eval1(float x)
{
    // CHECK: ([[# @LINE+1]]): error 41020
    return exp(x) - someNoDiffFunc(x, 1.0);
}

RWStructuredBuffer<float> output;

[shader("compute")]
[numthreads(1,1,1)]
void computeMain(uint id : SV_DispatchThreadID)
{
    var x = diffPair(2.0f);
    bwd_diff(eval)(x, 1.0f);

    output[0] = x.d;

    var x1 = diffPair(2.0f);
    bwd_diff(eval1)(x1, 1.0f);
    output[1] = x1.d;
}