From c31577953d5041c82375c22d847c2eba06106c58 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 25 Feb 2022 20:49:31 -0800 Subject: Improved SCCP, inlining and resource specialization passes, legalize `ImageSubscript` for GLSL (#2146) --- .../func-resource-result-complex.slang | 45 ++++++++++++++++++++++ ...func-resource-result-complex.slang.expected.txt | 4 ++ 2 files changed, 49 insertions(+) create mode 100644 tests/optimization/func-resource-result/func-resource-result-complex.slang create mode 100644 tests/optimization/func-resource-result/func-resource-result-complex.slang.expected.txt (limited to 'tests/optimization') diff --git a/tests/optimization/func-resource-result/func-resource-result-complex.slang b/tests/optimization/func-resource-result/func-resource-result-complex.slang new file mode 100644 index 000000000..a5585ff4c --- /dev/null +++ b/tests/optimization/func-resource-result/func-resource-result-complex.slang @@ -0,0 +1,45 @@ +// func-resource-result-simple.slang + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj + +// Test that a function that returns a resource type can be +// compiled for targets that don't natively support resource +// return values. + +//TEST_INPUT:set textures=[Texture2D(size=4, content = zero), Texture2D(size=4, content = one)] +Texture2D textures[2]; + +//TEST_INPUT:set sampler=Sampler +SamplerState sampler; + +Texture2D getTex(int index) +{ + Texture2D result; + // Note: `index` here will need to be a compile time constant in order to generate + // valid GLSL. If constant folding and function inlining are all done correctly + // we should be able to compile this. + if (index == 0) + result = textures[1]; + else + result = textures[0]; + return result; +} + +int test(int val) +{ + // Make sure index is a compile-time constant. + return getTex(int(0.0) + 1*2 < 5 ? 0 : 1).SampleLevel(sampler, float2(0,0), 0).x == 0.0 ? 0 : 1; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +} diff --git a/tests/optimization/func-resource-result/func-resource-result-complex.slang.expected.txt b/tests/optimization/func-resource-result/func-resource-result-complex.slang.expected.txt new file mode 100644 index 000000000..ef529012e --- /dev/null +++ b/tests/optimization/func-resource-result/func-resource-result-complex.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +1 +1 \ No newline at end of file -- cgit v1.2.3