yum-mirror/slang

Making it easier to work with shaders

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

Sai Praveen Bangaru[AD] Add support for resolving custom derivatives where generic parameters can't be automatically inferred (#5630)9913cfbf6

master
1.2 KiB51 linesraw
1//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
2
3//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
4RWStructuredBuffer<float> outputBuffer;
5
6typedef DifferentialPair<float> dpfloat;
7
8interface IFoo
9{
10    static float bar1(float x);
11
12    // CHECK-DAG: {{.*}}(13): error 31152
13    [PrimalSubstitute(bar1)]
14    static float bar(float x);
15
16    static DifferentialPair<float> dd(DifferentialPair<float> x);
17}
18
19__generic<let N:int>
20float f(float x)
21{
22    return N*x*x;
23}
24
25// CHECK-DAG: {{.*}}(26): error 31153
26[ForwardDerivative(IFoo.dd)]
27float bbb(float x);
28
29// CHECK-DAG: {{.*}}(30): error 31152
30[ForwardDerivativeOf(IFoo.bar)]
31DifferentialPair<float> dd1(DifferentialPair<float> x)
32{
33    return x;
34}
35
36// CHECK-DAG: {{.*}}(37): error 31151
37[BackwardDerivativeOf(f)]
38DifferentialPair<float> df<let N:int>(inout DifferentialPair<float> x, float dOut)
39{
40    var primal = x.p * x.p;
41    var diff = 2 * x.p * x.d * N;
42    return DifferentialPair<float>(primal, diff);
43}
44[numthreads(1, 1, 1)]
45void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
46{
47    {
48        dpfloat dpa = dpfloat(3.0, 1.0);
49        outputBuffer[1] = __fwd_diff(f<3>)(dpa).d; // Expect: 6.0
50    }
51}