diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/interface-local.slang | 48 | ||||
| -rw-r--r-- | tests/compute/interface-local.slang.expected.txt | 4 | ||||
| -rw-r--r-- | tests/compute/interface-param.slang | 48 | ||||
| -rw-r--r-- | tests/compute/interface-param.slang.expected.txt | 4 |
4 files changed, 104 insertions, 0 deletions
diff --git a/tests/compute/interface-local.slang b/tests/compute/interface-local.slang new file mode 100644 index 000000000..d3ee88062 --- /dev/null +++ b/tests/compute/interface-local.slang @@ -0,0 +1,48 @@ +// interface-local.slang + +// Test basic use of an interface as an existential type +// for a local variable, instead of just as a constraint +// on a generic type parameter. +// +// Because the existential is created and then used inside +// the same function, we can eliminate it via simple +// local optimizations. + +// on a generic type parameter. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + +interface IHelper +{ + int getVal(); +} + +struct HelperImpl : IHelper +{ + int storedVal; + + int getVal() { return storedVal; } +} + +int test(int val) +{ + HelperImpl helperImpl = { val }; + + IHelper existentialHelper = helperImpl; + + return existentialHelper.getVal(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer<int> gOutputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inputVal = tid; + int outputVal = test(inputVal); + gOutputBuffer[tid] = outputVal; +}
\ No newline at end of file diff --git a/tests/compute/interface-local.slang.expected.txt b/tests/compute/interface-local.slang.expected.txt new file mode 100644 index 000000000..bc856dafa --- /dev/null +++ b/tests/compute/interface-local.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +3 diff --git a/tests/compute/interface-param.slang b/tests/compute/interface-param.slang new file mode 100644 index 000000000..2e97a7fe2 --- /dev/null +++ b/tests/compute/interface-param.slang @@ -0,0 +1,48 @@ +// interface-param.slang + +//TEST_DISABLED: + +// Test basic use of an interface as an existential type +// for a value parameter, instead of just as a constraint +// on a generic type parameter. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + +//TEST:SIMPLE:-target hlsl -entry computeMain -stage compute -profile sm_5_1 -dump-ir + +interface IHelper +{ + int getVal(); +} + +int doTheThing(IHelper helper) +{ + return helper.getVal(); +} + +struct HelperImpl : IHelper +{ + int storedVal; + + int getVal() { return storedVal; } +} + +int test(int val) +{ + HelperImpl helperImpl = { val }; + return doTheThing(helperImpl); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer<int> gOutputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inputVal = tid; + int outputVal = test(inputVal); + gOutputBuffer[tid] = outputVal; +}
\ No newline at end of file diff --git a/tests/compute/interface-param.slang.expected.txt b/tests/compute/interface-param.slang.expected.txt new file mode 100644 index 000000000..bc856dafa --- /dev/null +++ b/tests/compute/interface-param.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +3 |
