yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type 2//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9 10struct Foo : IDifferentiable 11{ 12 float a; 13 int b; 14} 15 16[PreferCheckpoint] 17float k() 18{ 19 return outputBuffer[3] + 1; 20} 21 22[Differentiable] 23void h(float x, float y, out Foo result) 24{ 25 float p = no_diff k(); 26 float m = x + y + p; 27 float n = x - y; 28 float r = m * n + 2 * x * y; 29 30 result = {r, 2}; 31} 32 33[numthreads(1, 1, 1)] 34void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 35{ 36 float x = 2.0; 37 float y = 3.5; 38 float dx = 1.0; 39 float dy = 0.5; 40 41 dpfloat dresult; 42 dpfloat dpx = diffPair(x); 43 dpfloat dpy = diffPair(y); 44 Foo.Differential dFoo; 45 dFoo.a = 1.0; 46 bwd_diff(h)(dpx, dpy, dFoo); 47 48 outputBuffer[0] = dpx.d; // CHECK: 12.0 49 outputBuffer[1] = dpy.d; // CHECK: -4.0 50}