From 3072cfea95aad2a9ddab0f517c8f18f634442a27 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 22 May 2025 21:29:06 -0500 Subject: 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. --- tests/initializer-list/generic-array-init.slang | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'tests/initializer-list/generic-array-init.slang') 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 outputBuffer; void test() @@ -18,6 +18,28 @@ void test() outputBuffer[2] = array[2]; // BUFFER-NEXT: 3 outputBuffer[3] = array.getCount(); + + vector 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 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() void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { test<3>(); -} +} -- cgit v1.2.3