From 6c262bc5c9a364cd8c6a4026dbb9f8034c500f11 Mon Sep 17 00:00:00 2001 From: Sruthik P Date: Tue, 13 May 2025 11:09:23 +0530 Subject: Support Array Sizes using Generic arguments to be initialized via {} (#6720) * Add support for Array Sizes using Generic arguments to be initialized via {} Fixes one subissue of #6138 This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. The change checks for an array whose size parameter is a GenericParamIntVal and since the size of such an array will be known at link time, is not considered as a case of the size not being known statically. * Add support for Array Sizes using Generic arguments to be initialized via {} Fixes one subissue of #6138. Fixes the issue #6958. This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. Support is added by means of adding a new AST Expr node that lowers down to the IR MakeArrayFromElement and the emission of a diagnostic is replaced with the creation of this new AST Expr node. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska --- tests/initializer-list/generic-array-init.slang | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/initializer-list/generic-array-init.slang (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 new file mode 100644 index 000000000..4257e2972 --- /dev/null +++ b/tests/initializer-list/generic-array-init.slang @@ -0,0 +1,28 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -vk +//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 +RWStructuredBuffer outputBuffer; + +void test() +{ + // Test array initialization with generic size + int array[TSize] = {}; + + // BUFFER: 0 + outputBuffer[0] = array[0]; + // BUFFER-NEXT: 0 + outputBuffer[1] = array[1]; + // BUFFER-NEXT: 0 + outputBuffer[2] = array[2]; + // BUFFER-NEXT: 3 + outputBuffer[3] = array.getCount(); +} + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + test<3>(); +} -- cgit v1.2.3