yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
93f5d13fc
master
1// func-resource-result-simple.slang 2 3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 5// Not supported in WGSL: Arrays of textures or buffers 6//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu 7 8// Test that a function that returns a resource type can be 9// compiled for targets that don't natively support resource 10// return values. 11 12//TEST_INPUT:set textures=[Texture2D(size=4, content = zero), Texture2D(size=4, content = one)] 13Texture2D textures[2]; 14 15//TEST_INPUT:set sampler=Sampler 16SamplerState sampler; 17 18Texture2D getTex(int index) 19{ 20 Texture2D result; 21 // Note: `index` here will need to be a compile time constant in order to generate 22 // valid GLSL. If constant folding and function inlining are all done correctly 23 // we should be able to compile this. 24 if (index == 0) 25 result = textures[1]; 26 else 27 result = textures[0]; 28 return result; 29} 30 31int test(int val) 32{ 33 // Make sure index is a compile-time constant. 34 return getTex(int(0.0) + 1*2 < 5 ? 0 : 1).SampleLevel(sampler, float2(0,0), 0).x == 0.0 ? 0 : 1; 35} 36 37//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 38RWStructuredBuffer<int> outputBuffer; 39 40[numthreads(4, 1, 1)] 41void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 42{ 43 int tid = dispatchThreadID.x; 44 int inVal = tid; 45 int outVal = test(inVal); 46 outputBuffer[tid] = outVal; 47}