yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d3fd7470e
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -compute -shaderobj 2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -compute -shaderobj 3//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<int> outputBuffer; 7 8 9interface IFoo 10{ 11 int foo(int a); 12} 13 14struct MyImpl1 : IFoo 15{ 16 int foo(int a) { return a; } 17} 18 19struct MyImpl2 : IFoo 20{ 21 int foo(int a) { return a + 5; } 22} 23 24int test(IFoo foo, int idx) 25{ 26 int val = 0; 27 if (let a = foo as MyImpl1) 28 { 29 val = a.foo(idx); 30 } 31 else if (let a = foo as MyImpl2) 32 { 33 val = a.foo(idx); 34 } 35 return (val); 36} 37 38int test1<T>(T t) 39{ 40 if (let a = t as uint) 41 { 42 return 1; 43 } 44 else if(let a = t as float) 45 { 46 return 2; 47 } 48 else if (let a = t as double) 49 { 50 return 3; 51 } 52 else if (let a = t as int) 53 { 54 return 4; 55 } 56 else if (let a = t as uint64_t) 57 { 58 return 5; 59 } 60 else 61 { 62 return 6; 63 } 64} 65 66 67[numthreads(1, 1, 1)] 68void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 69{ 70 MyImpl1 impl1; 71 MyImpl2 impl2; 72 // CHECK: 1 73 // CHECK: 7 74 outputBuffer[0] = test(impl1, 1); 75 outputBuffer[1] = test(impl2, 2); 76 77 // CHECK: 1 78 outputBuffer[2] = test1(2U); 79 // CHECK: 2 80 outputBuffer[3] = test1(2.0f); 81 // CHECK: 3 82 outputBuffer[4] = test1(2.0lf); 83 // CHECK: 4 84 outputBuffer[5] = test1(2); 85 // CHECK: 5 86 outputBuffer[6] = test1(2LLU); 87 // CHECK: 6 88 outputBuffer[7] = test1(impl1); 89}