yum-mirror/slang

Making it easier to work with shaders

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

Yong HeImprove diagnostic on differentiablitiy check. (#2687)6c26aa1f7

master
583 B39 linesraw
1//DIAGNOSTIC_TEST:SIMPLE:
2
3struct DiffT : IDifferentiable
4{
5    float f;
6}
7struct NoDiffField
8{
9    DiffT fp;
10}
11
12[BackwardDifferentiable]
13float g(float x)
14{
15    NoDiffField obj;
16    obj.fp.f = x * x; // Error, this location cannot hold derivative.
17    return obj.fp.f;
18}
19
20[BackwardDifferentiable]
21void diffOut(inout float x)
22{
23    x = 2;
24}
25
26float noDiffFunc(float x)
27{
28    return 0.0;
29}
30
31[BackwardDifferentiable]
32float h(float x)
33{
34    NoDiffField obj;
35    obj.fp.f = detach(x * x); // OK.
36    obj.fp.f = noDiffFunc(x); // OK.
37    diffOut(obj.fp.f); // Error.
38    return obj.fp.f;
39}