yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeMake interface types non c-style in Slang2026. (#7260)812e47898

master
1.0 KiB47 linesraw
1// Test that the size of an optional interface type is the same as the existential box.
2
3//TEST:SIMPLE(filecheck=CHECK): -target hlsl -conformance "Impl1:IFoo=1" -entry computeMain -profile cs_6_0
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -output-using-type
5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -vk -shaderobj -output-using-type
6
7//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
8RWStructuredBuffer<int> outputBuffer;
9
10interface IFoo
11{
12    int method();
13}
14
15//TEST_INPUT: type_conformance Impl1:IFoo = 0
16struct Impl1 : IFoo
17{
18    int data;
19    int method() { return data + 1; }
20}
21
22struct MyType
23{
24    Optional<IFoo> foo;
25}
26
27Optional<T> process<T>(Optional<T> opt)
28{
29    return opt;
30}
31
32[numthreads(1, 1, 1)]
33void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
34{
35    MyType t = {};
36    t.foo = process(t.foo);
37
38    // BUFFER: 100
39    if (let f = t.foo)
40        outputBuffer[0] = f.method();
41    else
42        outputBuffer[0] = 100;
43}
44
45// CHECK: struct MyType
46// CHECK-NEXT: {
47// CHECK-NEXT: Tuple{{.*}} foo{{.*}};