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:-slang -compute -shaderobj -output-using-type 2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9typedef float.Differential dfloat; 10 11[BackwardDifferentiable] 12float test_simple_switch(float y, int i) 13{ 14 float o; 15 switch (i) 16 { 17 case 0: 18 case 1: 19 o = y * 2.0; 20 break; 21 22 case 2: 23 o = y * 3.0; 24 break; 25 26 default: 27 o = y; 28 } 29 30 return o; 31} 32 33[numthreads(1, 1, 1)] 34void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 35{ 36 { 37 dpfloat dpa = dpfloat(1.0, 0.0); 38 39 __bwd_diff(test_simple_switch)(dpa, 1, 1.0f); 40 outputBuffer[0] = dpa.d; // Expect: 2.0 41 } 42 43 { 44 dpfloat dpa = dpfloat(0.4, 0.0); 45 46 __bwd_diff(test_simple_switch)(dpa, 2, 1.0f); 47 outputBuffer[1] = dpa.d; // Expect: 3.0 48 } 49 50 { 51 dpfloat dpa = dpfloat(1.0, 0.0); 52 53 __bwd_diff(test_simple_switch)(dpa, 3, 1.0f); 54 outputBuffer[2] = dpa.d; // Expect: 1.0 55 } 56}