From 375ecfe2903b09f07abeba2eafb88d9a564c1458 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 14 May 2025 12:11:53 -0500 Subject: support specialization constant sized array (#6871) Close #6859 Goal of this PR We want to support an array whose size can be specialization constant for shared/global variable e.g. layout (constant_id = 0) const uint BLOCK_SIZE = 64; shared float buf_a[(BLOCK_SIZE + 5) * 4]; Overview of the solution: During IndexExpr check, we will loose the restriction to allow SpecConst passing, but the size parameter will not be a constant value because it cannot be folded into a constant, so we will make it follow the same logic as generic parameter value, and the size will be represented by FuncCallIntVal/PolynomialIntVal/DeclRefIntVal. During IR lowering, we will detect whether there is spec constant in the IntVal, and wrap the IRInst with a SpecConstRateType, and propagate the type though the lowering logic, such that the IntVal representing the array size will have SpecConstRateType. During spirv emit stage, if we detect that a IRInst has SpecConstRateType, we will emit it as SpecConstantOp. We have to implement new logic to emit OpSpecConstantOp, the existing emit logic doesn't support emitting OpSpecConstantOp, especially this op can embed arithmetic operation at global scope, where we can only emit arithmetic instruct at local. But there are only few instructs we need to support. Overview of the solution: This PR doesn't support generic, and we will create a separate PR to extend that, tracked in #6840. --- source/slang/slang-ir-lower-buffer-element-type.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-ir-lower-buffer-element-type.cpp') diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp index 6f0e22a57..1294b400d 100644 --- a/source/slang/slang-ir-lower-buffer-element-type.cpp +++ b/source/slang/slang-ir-lower-buffer-element-type.cpp @@ -309,7 +309,7 @@ struct LoweredElementTypeContext builder.emitBlock(); auto packedParam = builder.emitParam(refStructType); auto packedArray = builder.emitFieldAddress(packedParam, dataKey); - auto count = getIntVal(arrayType->getElementCount()); + auto count = getArraySizeVal(arrayType->getElementCount()); IRInst* result = nullptr; if (count <= kMaxArraySizeToUnroll) { @@ -374,7 +374,7 @@ struct LoweredElementTypeContext builder.emitBlock(); auto outParam = builder.emitParam(outLoweredType); auto originalParam = builder.emitParam(arrayType); - auto count = getIntVal(arrayType->getElementCount()); + auto count = getArraySizeVal(arrayType->getElementCount()); auto destArray = builder.emitFieldAddress(outParam, arrayStructKey); if (count <= kMaxArraySizeToUnroll) { @@ -602,7 +602,8 @@ struct LoweredElementTypeContext StringBuilder nameSB; nameSB << "_Array_" << getLayoutName(config.layoutRule->ruleName) << "_"; getTypeNameHint(nameSB, arrayType->getElementType()); - nameSB << getIntVal(arrayType->getElementCount()); + nameSB << getArraySizeVal(arrayType->getElementCount()); + builder.addNameHintDecoration( loweredType, nameSB.produceString().getUnownedSlice()); -- cgit v1.2.3