yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// Test packing/unpacking different types of fields into `AnyValue`s. 2 3//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu -output-using-type 4//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -output-using-type 5//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -output-using-type 6//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type 7//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 8 9[anyValueSize(16)] 10interface IInterface 11{ 12 float run(); 13} 14 15//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer 16RWStructuredBuffer<float> gOutputBuffer; 17 18//TEST_INPUT: set gObj = new StructuredBuffer<IInterface>[new FloatVal{1.0}, new Float4Val{{[2.0, 3.0, 4.0, 5.0]}}, new IntVal{6}, new Int4Val{[7,8,9,10]}]; 19RWStructuredBuffer<IInterface> gObj; 20 21[numthreads(1, 1, 1)] 22void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 23{ 24 // Test unpacking. 25 float result = 0.0; 26 for (int i = 0; i < 4; i++) 27 { 28 IInterface v0 = gObj.Load(i); 29 result += v0.run(); 30 } 31 32 // Test packing. 33 IInterface v[2]; 34 Float4Val cval; 35 cval.val.val = float4(1,2,3,4); 36 v[0] = cval; 37 38 Int4Val ival; 39 ival.val = int4(2,3,4,5); 40 v[1] = ival; 41 42 for (int i = 0; i < 2; i++) 43 { 44 result += v[i].run(); 45 } 46 gOutputBuffer[0] = result; 47} 48 49// Type must be marked `public` to ensure it is visible in the generated DLL. 50export struct FloatVal : IInterface 51{ 52 float val; 53 float run() 54 { 55 return val; 56 } 57}; 58interface ISomething{void g();} 59struct Float4Struct : ISomething { float4 val; void g() {} } 60export struct Float4Val : IInterface 61{ 62 Float4Struct val; 63 float run() 64 { 65 return val.val.x; 66 } 67}; 68export struct IntVal : IInterface 69{ 70 int val; 71 float run() 72 { 73 return val; 74 } 75}; 76export struct Int4Val : IInterface 77{ 78 int4 val; 79 float run() 80 { 81 return val.x; 82 } 83};