yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
c3df36043
master
1//TEST:SIMPLE(filecheck=CHECK): -target hlsl -line-directive-mode none -entry computeMain -stage compute 2//TEST:SIMPLE(filecheck=CHECK): -target cuda -line-directive-mode none -entry computeMain -stage compute 3//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 4RWStructuredBuffer<float> outputBuffer; 5 6struct Foo2 : IDifferentiable 7{ 8 float dx[3]; 9} 10 11struct Foo : IDifferentiable 12{ 13 typealias Differential = Foo2; 14 15 float x[3]; 16 // CHECK: tests/autodiff/struct-without-diff-associations.slang([[# @LINE-1]]): error 30102: differentiable member 'x' should have a corresponding field in 'Foo2'. Use [DerivativeMember(Foo2.<field-name>)] or mark as no_diff 17 // CHECK-NEXT: float x[3]; 18 // CHECK-NEXT: ^ 19}; 20 21[Differentiable] 22Foo getFoo(float x) 23{ 24 return { { x, x, x } }; 25} 26 27[Differentiable] 28float foobar(float x) 29{ 30 int i = 3 * int(floor(x)); 31 Foo foo = getFoo(x); 32 return foo.x[i] * foo.x[i]; 33} 34 35[numthreads(1, 1, 1)] 36void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 37{ 38 { 39 float a = 0.5; 40 var d = fwd_diff(foobar)(diffPair(a, 1.0)).d; 41 outputBuffer[0] = d; 42 } 43}