diff options
| author | Yong He <yonghe@outlook.com> | 2022-02-25 20:49:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-25 20:49:31 -0800 |
| commit | c31577953d5041c82375c22d847c2eba06106c58 (patch) | |
| tree | bc685a8b63fc13cb85d160ae13df950056ca6e91 /tests/optimization/func-resource-result | |
| parent | 8990d270e3a0c01b1f7abbf4f79556c5ef82a096 (diff) | |
Improved SCCP, inlining and resource specialization passes, legalize `ImageSubscript` for GLSL (#2146)
Diffstat (limited to 'tests/optimization/func-resource-result')
| -rw-r--r-- | tests/optimization/func-resource-result/func-resource-result-complex.slang | 45 | ||||
| -rw-r--r-- | tests/optimization/func-resource-result/func-resource-result-complex.slang.expected.txt | 4 |
2 files changed, 49 insertions, 0 deletions
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<int> 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 |
