yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b7d318f48
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//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cpu -compute -shaderobj -output-using-type 5 6//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 7RWStructuredBuffer<float> outputBuffer; 8 9struct NonDiff 10{ 11 float a; 12} 13 14[Differentiable] 15float myFunc(__constref NonDiff fIn, float x, __constref no_diff float y) 16{ 17 return x * fIn.a + y; 18} 19 20// test that the ordering of no_diff and __constref doesn't matter. 21[Differentiable] 22float myFunc2(__constref NonDiff fIn, float x, no_diff __constref float y) 23{ 24 return x * fIn.a + y; 25} 26 27[numthreads(1, 1, 1)] 28void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 29{ 30 float a = 10.0; 31 NonDiff fIn = { a }; 32 DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f); 33 float rs = __fwd_diff(myFunc)(fIn, dpx, 1.0).d; 34 float rs2 = __fwd_diff(myFunc2)(fIn, dpx, 1.0).d; 35 36 // CHECK: 10.0 37 // CHECK: 10.0 38 39 outputBuffer[0] = rs; 40 outputBuffer[1] = rs2; 41}