yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
712ce653d
master
1// interface-param.slang 2 3// Test basic use of an interface as an existential type 4// for a value parameter, instead of just as a constraint 5// on a generic type parameter. 6 7//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 8//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 9//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 10//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 11 12interface IHelper 13{ 14 int getVal(); 15} 16 17int doTheThing(IHelper helper) 18{ 19 return helper.getVal(); 20} 21 22struct HelperImpl : IHelper 23{ 24 int storedVal; 25 26 int getVal() { return storedVal; } 27} 28 29int test(int val) 30{ 31 HelperImpl helperImpl = { val }; 32 return doTheThing(helperImpl); 33} 34 35//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer 36RWStructuredBuffer<int> gOutputBuffer; 37 38[numthreads(4, 1, 1)] 39void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 40{ 41 int tid = dispatchThreadID.x; 42 int inputVal = tid; 43 int outputVal = test(inputVal); 44 gOutputBuffer[tid] = outputVal; 45}