diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-04 13:05:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-04 13:05:58 -0700 |
| commit | 812e478989e27983b8dea7ab11964de751654ba2 (patch) | |
| tree | e6db6def9c7896ee48c5fe42926856644e81c0e6 /tests | |
| parent | b9dc21d362f65f22bc707bede733a9537b80460a (diff) | |
Make interface types non c-style in Slang2026. (#7260)
* Make interface types non c-style.
* Make Optional<T> work with autodiff and existential types.
* Fix.
* patch behind slang 2026.
* Fix warnings.
* cleanup.
* Fix tests.
* Fix.
* Fix com interface lowering.
* Add comment to test.
* regenerate command line reference
* Add test for passing `none` to autodiff function.
* Fix recording of `getDynamicObjectRTTIBytes`.
* Fix nested Optional types.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/optional.slang | 59 | ||||
| -rw-r--r-- | tests/initializer-list/existential-is-not-c-like.slang | 21 | ||||
| -rw-r--r-- | tests/language-feature/interfaces/optional-none.slang | 47 | ||||
| -rw-r--r-- | tests/language-feature/interfaces/zero-init-interface.slang | 33 | ||||
| -rw-r--r-- | tests/language-feature/nested-optional.slang | 35 |
5 files changed, 162 insertions, 33 deletions
diff --git a/tests/autodiff/optional.slang b/tests/autodiff/optional.slang new file mode 100644 index 000000000..a86440413 --- /dev/null +++ b/tests/autodiff/optional.slang @@ -0,0 +1,59 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -output-using-type +//TEST(compute,vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -slang -compute -output-using-type + +[Differentiable] +Optional<float> sumSquare(Optional<float> a, Optional<float> b) +{ + if (let x = a) + { + if (let y = b) + { + return x * x + y * y; + } + else + { + return x * x; + } + } + else if (let y = b) + { + return y * y; + } + return none; +} + +//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + var dpa = diffPair<Optional<float>>(3.0f, none); + var dpb = diffPair<Optional<float>>(4.0f, none); + + bwd_diff(sumSquare)(dpa, dpb, 1.0f); + + outputBuffer[0] = -1; + + // CHECK: 14.0 + if (dpa.d.hasValue && dpb.d.hasValue) + outputBuffer[0] = dpa.d.value + dpb.d.value; + + // CHECK: 1.0 + dpa = diffPair<Optional<float>>(3.0f, none); + dpb = diffPair<Optional<float>>(4.0f, none); + bwd_diff(sumSquare)(dpa, dpb, none); + if (dpa.d.value == 0.0 && dpb.d.value == 0.0) + { + outputBuffer[1] = 1.0f; + } + + // CHECK: 100.0 + dpa = diffPair<Optional<float>>(none, none); + dpb = diffPair<Optional<float>>(4.0f, none); + bwd_diff(sumSquare)(dpa, dpb, 1.0); + if (dpa.d == none) + { + outputBuffer[2] = 100.0f; + } +}
\ No newline at end of file diff --git a/tests/initializer-list/existential-is-not-c-like.slang b/tests/initializer-list/existential-is-not-c-like.slang new file mode 100644 index 000000000..1058033c9 --- /dev/null +++ b/tests/initializer-list/existential-is-not-c-like.slang @@ -0,0 +1,21 @@ +// Test that in Slang 2026, it is no longer valid to default initialize an existential value. +#lang 2026 + +//TEST:SIMPLE(filecheck=CHECK): -target spirv +interface IBSDF +{ + float3 eval(float3 wi, float3 wo); +} + +struct ShaderGraph +{ + IBSDF bsdf_stack[8]; // Intentionally uninitialized. + int next_bsdf = 0; // must be zero. +} + +[numthreads(1,1,1)] +void main() +{ + // CHECK: ([[# @LINE+1]]): error + ShaderGraph sg = {}; +}
\ No newline at end of file diff --git a/tests/language-feature/interfaces/optional-none.slang b/tests/language-feature/interfaces/optional-none.slang new file mode 100644 index 000000000..04bb8f83e --- /dev/null +++ b/tests/language-feature/interfaces/optional-none.slang @@ -0,0 +1,47 @@ +// Test that the size of an optional interface type is the same as the existential box. + +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -conformance "Impl1:IFoo=1" -entry computeMain -profile cs_6_0 +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -vk -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +interface IFoo +{ + int method(); +} + +//TEST_INPUT: type_conformance Impl1:IFoo = 0 +struct Impl1 : IFoo +{ + int data; + int method() { return data + 1; } +} + +struct MyType +{ + Optional<IFoo> foo; +} + +Optional<T> process<T>(Optional<T> opt) +{ + return opt; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyType t = {}; + t.foo = process(t.foo); + + // BUFFER: 100 + if (let f = t.foo) + outputBuffer[0] = f.method(); + else + outputBuffer[0] = 100; +} + +// CHECK: struct MyType +// CHECK-NEXT: { +// CHECK-NEXT: Tuple{{.*}} foo{{.*}};
\ No newline at end of file diff --git a/tests/language-feature/interfaces/zero-init-interface.slang b/tests/language-feature/interfaces/zero-init-interface.slang deleted file mode 100644 index ed3b1eaa4..000000000 --- a/tests/language-feature/interfaces/zero-init-interface.slang +++ /dev/null @@ -1,33 +0,0 @@ -// Test that we can zero-init a struct with interface typed member. - -//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -shaderobj -//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -vk -shaderobj - -//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer -RWStructuredBuffer<int> outputBuffer; - -interface IFoo -{ - int method(); -} - -//TEST_INPUT: type_conformance Impl1:IFoo = 0 -struct Impl1 : IFoo -{ - int data; - int method() { return data + 1; } -} - -struct MyType -{ - IFoo foo; -} - - -[numthreads(1, 1, 1)] -void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) -{ - MyType t = {}; - // BUFFER: 1 - outputBuffer[0] = t.foo.method(); -} diff --git a/tests/language-feature/nested-optional.slang b/tests/language-feature/nested-optional.slang new file mode 100644 index 000000000..8fdeac33b --- /dev/null +++ b/tests/language-feature/nested-optional.slang @@ -0,0 +1,35 @@ +//TEST:INTERPRET(filecheck=CHECK): + +Optional<Optional<int>> getNone() { return none; } + +void main() +{ + Optional<Optional<Optional<int>>> val = Optional<Optional<int>>(5); + Optional<Optional<Optional<int>>> defaultVal1 = none; + Optional<Optional<Optional<int>>> defaultVal2 = getNone(); + + // CHECK: 8 + printf("%d\n", sizeof(val)); + + // CHECK: success + if (defaultVal1.hasValue == defaultVal2.hasValue) + { + printf("success\n"); + } + else + { + printf("failure\n"); + } + + // CHECK: value: 5 + if (let x = val) + { + if (let y = x) + { + if (let z = y) + { + printf("value: %d\n", z); + } + } + } +}
\ No newline at end of file |
