yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
adaea0e99
master
1// interface-local.slang 2 3// Test basic use of an interface as an existential type 4// for a local variable, instead of just as a constraint 5// on a generic type parameter. 6// 7// Because the existential is created and then used inside 8// the same function, we can eliminate it via simple 9// local optimizations. 10 11// on a generic type parameter. 12 13//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 14//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 15//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 16//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 17 18 19interface IHelper 20{ 21 int getVal(); 22} 23 24struct HelperImpl : IHelper 25{ 26 int storedVal; 27 28 int getVal() { return storedVal; } 29} 30 31int test(int val) 32{ 33 HelperImpl helperImpl = { val }; 34 35 IHelper existentialHelper = helperImpl; 36 37 return existentialHelper.getVal(); 38} 39 40//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer 41RWStructuredBuffer<int> gOutputBuffer; 42 43[numthreads(4, 1, 1)] 44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 45{ 46 uint tid = dispatchThreadID.x; 47 int inputVal = int(tid); 48 int outputVal = test(inputVal); 49 gOutputBuffer[tid] = outputVal; 50}