diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2025-05-22 21:29:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-22 19:29:06 -0700 |
| commit | 3072cfea95aad2a9ddab0f517c8f18f634442a27 (patch) | |
| tree | 966c019c35604b0f457caec02c9619feddbf2665 /tests/initializer-list/generic-array-init.slang | |
| parent | 2d34409f2e72673ac9fd766eaeaa75f60882e7ca (diff) | |
Implement default initializer list for C-Style type member (#7079)
* Implement default initializer list for C-Style type member
Close #6189.
Previsouly, for the C-Style member in a struct, if it doesn't have any initialize
expression, when we synthesize the ctor, we will not associate the
default value for the parameter corresponding to that member.
This bring some trouble that existing slang users has to add '= {}' to
every struct fields in order to make all the parameters in the synthesized ctor having
a default value, so people can still use `Struct a = {}` to create a
struct.
To make this use case convenience, we will automatically associated a
'= {}' as the default value for this case.
This PR also add support for empty initializing link-time sized vector/matrix by "= {}".
In addition, this PR also fix a bug in auto diff where we should not report error when proccessing
transpose on an empty struct.
Diffstat (limited to 'tests/initializer-list/generic-array-init.slang')
| -rw-r--r-- | tests/initializer-list/generic-array-init.slang | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/initializer-list/generic-array-init.slang b/tests/initializer-list/generic-array-init.slang index 4257e2972..83c14ebd2 100644 --- a/tests/initializer-list/generic-array-init.slang +++ b/tests/initializer-list/generic-array-init.slang @@ -2,7 +2,7 @@ //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -mtl //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-cpu -compute -entry computeMain -//TEST_INPUT:ubuffer(data=[9 9 9 9], stride=4):out,name=outputBuffer +//TEST_INPUT:ubuffer(data=[9 9 9 9 9 9 9 9 9 9 9 9], stride=4):out,name=outputBuffer RWStructuredBuffer<int> outputBuffer; void test<let TSize : uint>() @@ -18,6 +18,28 @@ void test<let TSize : uint>() outputBuffer[2] = array[2]; // BUFFER-NEXT: 3 outputBuffer[3] = array.getCount(); + + vector<int, TSize> vec = {}; + + // BUFFER-NEXT: 0 + outputBuffer[4] = vec[0]; + // BUFFER-NEXT: 0 + outputBuffer[5] = vec[1]; + // BUFFER-NEXT: 0 + outputBuffer[6] = vec[2]; + // BUFFER-NEXT: 3 + outputBuffer[7] = vec.getCount(); + + matrix<float, TSize, TSize-1> mat = {}; + + // BUFFER-NEXT: 0 + outputBuffer[8] = (int)mat[0][0]; + // BUFFER-NEXT: 0 + outputBuffer[9] = (int)mat[1][1]; + // BUFFER-NEXT: 0 + outputBuffer[10] = (int)mat[2][1]; + // BUFFER-NEXT: 3 + outputBuffer[11] = mat.getCount(); // this is a bad name, getCount() is actually get the number of row. } [shader("compute")] @@ -25,4 +47,4 @@ void test<let TSize : uint>() void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { test<3>(); -} +} |
