yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVno_diff diagnostics improvement (#7655)a670bafc1

master
766 B42 linesraw
1//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
2
3struct MyStruct<T> where T: __BuiltinFloatingPointType
4{
5    float a;
6    __init(float a) { this.a = a;}
7
8    [Differentiable]
9    T eval(T x)
10    {
11        //CHECK: ([[# @LINE+1]]): warning 31159
12        return exp(x * T(a) * T(a));
13    }
14
15    [Differentiable]
16    [NoDiffThis]
17    T eval1(T x)
18    {
19        //CHECK-NOT: ([[# @LINE+1]]): warning 31159
20        return exp(x * T(a) * T(a));
21    }
22};
23
24[Differentiable]
25float evalFunc(float x)
26{
27    MyStruct<float> s = {x};
28    return s.eval(x) + s.eval1(x);
29}
30
31RWStructuredBuffer<float> output;
32
33[shader("compute")]
34[numthreads(1,1,1)]
35void computeMain(uint id : SV_DispatchThreadID)
36{
37    var x = diffPair(2.0f);
38    bwd_diff(evalFunc)(x, 1.0f);
39
40    output[0] = x.d;
41}
42