diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2025-02-05 12:37:03 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-05 10:37:03 -0800 |
| commit | 9ec6b91686b651d959fd9ffbec283845bd725dd6 (patch) | |
| tree | 2c48202cb04b76e5ddcb274be35529378ddf8f31 /tests/initializer-list/struct-visibility-1.slang | |
| parent | 4b350645042b8e8fbdad19784ee745d11c7bc616 (diff) | |
Feature/initialize list side branch (#6058)
* SP004: implement initialize list translation to ctor
- We synthesize a member-wise constructor for each struct follow
the rules described in SP004.
- Add logic to translate the initialize list to constructor invoke
- Add cuda-host decoration for the synthesized constructor
- Remove the default constructor when we have a valid member init constructor
- Disable -zero-initialize option, will re-implement it in followup (#6109).
- Fix the overload lookup issue
When creating invoke expression for ctor, we need to call
ResolveInvoke() to find us the best candidates, however
the existing lookup logic could find us the base constructor
for child struct, we should eliminate this case by providing
the LookupOptions::IgnoreInheritance to lookup, this requires
us to create a subcontext on SemanticsVisitor to indicate that
we only want to use this option on looking the constructor.
- Do not implicit initialize a struct that doesn't have explicit default
constructor.
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests/initializer-list/struct-visibility-1.slang')
| -rw-r--r-- | tests/initializer-list/struct-visibility-1.slang | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/initializer-list/struct-visibility-1.slang b/tests/initializer-list/struct-visibility-1.slang new file mode 100644 index 000000000..691e8c991 --- /dev/null +++ b/tests/initializer-list/struct-visibility-1.slang @@ -0,0 +1,105 @@ + +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj + +public struct Visibility +{ + internal int x = 1; + public int y = 5; + + int getX() { return x; } +} + + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; +void test(inout uint index) +{ + Visibility t1 = {}; // OK, initialized to {1,5} via ctor call. + // BUFFER: 1 + outputBuffer[index++] = t1.getX(); + // BUFFER-NEXT: 5 + outputBuffer[index++] = t1.y; + + Visibility t2 = {1}; // OK, initialized to {1,1} via ctor call. + // BUFFER-NEXT: 1 + outputBuffer[index++] = t2.getX(); + // BUFFER-NEXT: 1 + outputBuffer[index++] = t2.y; +} + +internal struct Visibility2 +{ + // Visibility3 type is considered as C-style struct. + // Because all members have the same visibility as the type. + // Therefore we will attempt the legacy fallback logic for + // initializer-list syntax. + // Note that c-style structs can still have init exprs on members. + internal int x; + internal int y = 2; + // compiler synthesizes: + // internal __init(int x, int y = 2); +} + +internal void test2(inout uint index) +{ + Visibility2 t = {3, 4}; // OK, initialized to {3,4} via ctor call. + // BUFFER-NEXT: 3 + outputBuffer[index++] = t.x; + // BUFFER-NEXT: 4 + outputBuffer[index++] = t.y; + + Visibility2 t1 = {1}; // OK, initialized to {1,2} via ctor call. + // BUFFER-NEXT: 1 + outputBuffer[index++] = t1.x; + // BUFFER-NEXT: 2 + outputBuffer[index++] = t1.y; + + Visibility2 t2 = {}; // OK, initialized to {0, 2} via legacy logic. + // BUFFER-NEXT: 0 + outputBuffer[index++] = t2.x; + // BUFFER-NEXT: 2 + outputBuffer[index++] = t2.y; +} + +internal struct Visibility3 +{ + // Visibility4 type is considered as C-style struct. + // And we still synthesize a ctor for member initialization. + // Because Visibility4 has no public members, the synthesized + // ctor will take 0 arguments. + internal int x = 1; + internal int y = 2; + // compiler synthesizes: + // internal __init(int x = 1, int y = 2); +} + +internal void test3(inout uint index) +{ + Visibility3 t = {0, 0}; // OK, initialized to {0,0} via ctor call. + // BUFFER-NEXT: 0 + outputBuffer[index++] = t.x; + // BUFFER-NEXT: 0 + outputBuffer[index++] = t.y; + + Visibility3 t1 = {3}; // OK, initialized to {3,2} via ctor call. + // BUFFER-NEXT: 3 + outputBuffer[index++] = t1.x; + // BUFFER-NEXT: 2 + outputBuffer[index++] = t1.y; + + Visibility3 t2 = {}; // OK, initialized to {1,2} via ctor call. + // BUFFER-NEXT: 1 + outputBuffer[index++] = t2.x; + // BUFFER-NEXT: 2 + outputBuffer[index++] = t2.y; +} + +[shader("compute")] +void computeMain() +{ + uint index = 0; + test(index); + test2(index); + test3(index); +} |
