diff options
Diffstat (limited to 'tests/language-feature/interfaces')
4 files changed, 96 insertions, 0 deletions
diff --git a/tests/language-feature/interfaces/is-as-dynamic.slang b/tests/language-feature/interfaces/is-as-dynamic.slang new file mode 100644 index 000000000..4499db53a --- /dev/null +++ b/tests/language-feature/interfaces/is-as-dynamic.slang @@ -0,0 +1,48 @@ +// is-as-dynamic.slang + +// Test that `is` and `as` operators works as intended in dynamic dispatch. + +//TEST(compute):COMPARE_COMPUTE: -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[anyValueSize(8)] +interface IFoo +{ + int method(); +} + +//TEST_INPUT: type_conformance Impl1:IFoo = 0 +struct Impl1 : IFoo +{ + int data; + int method() { return data; } +} + +//TEST_INPUT: type_conformance Impl2:IFoo = 1 +struct Impl2 : IFoo +{ + int data1; + int data2; + int method() { return data1 + data2; } +} + +int getData(IFoo foo) +{ + let castResult = foo as Impl2; + if (castResult.hasValue && foo is Impl2 && !(foo is Impl1)) + { + return castResult.value.method(); + } + return 0; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + int2 data = int2(1, 2); + IFoo dynamicObject = createDynamicObject<IFoo, int2>(1, data); + int outVal = getData(dynamicObject); + outputBuffer[0] = outVal; +} diff --git a/tests/language-feature/interfaces/is-as-dynamic.slang.expected.txt b/tests/language-feature/interfaces/is-as-dynamic.slang.expected.txt new file mode 100644 index 000000000..00750edc0 --- /dev/null +++ b/tests/language-feature/interfaces/is-as-dynamic.slang.expected.txt @@ -0,0 +1 @@ +3 diff --git a/tests/language-feature/interfaces/is-as.slang b/tests/language-feature/interfaces/is-as.slang new file mode 100644 index 000000000..2712d9810 --- /dev/null +++ b/tests/language-feature/interfaces/is-as.slang @@ -0,0 +1,46 @@ +// is-as.slang + +// Test that `is` and `as` operators works as intended. + +//TEST(compute):COMPARE_COMPUTE: -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +interface IFoo +{ + int method(); +} + +struct Impl1 : IFoo +{ + int data; + int method() { return data; } +} + +struct Impl2 : IFoo +{ + int data1; + int data2; + int method() { return data1 + data2; } +} + +int getData(IFoo foo) +{ + let castResult = foo as Impl2; + if (castResult.hasValue) + { + return castResult.value.method(); + } + return 0; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + Impl2 obj; + obj.data1 = 1; + obj.data2 = 2; + int outVal = getData(obj); + outputBuffer[0] = outVal; +} diff --git a/tests/language-feature/interfaces/is-as.slang.expected.txt b/tests/language-feature/interfaces/is-as.slang.expected.txt new file mode 100644 index 000000000..00750edc0 --- /dev/null +++ b/tests/language-feature/interfaces/is-as.slang.expected.txt @@ -0,0 +1 @@ +3 |
