diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2025-05-14 12:11:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-14 10:11:53 -0700 |
| commit | 375ecfe2903b09f07abeba2eafb88d9a564c1458 (patch) | |
| tree | a507ffcdbe118f5d69ffb3e6c341d8f954e0bfef /source/slang/slang-ir.cpp | |
| parent | 39c9e25f6d728e970b68a9452330e754991b4ac5 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index fb7d752d5..9c4cb98c0 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -314,6 +314,23 @@ IRIntegerValue getIntVal(IRInst* inst) } } +IRIntegerValue getArraySizeVal(IRInst* inst) +{ + switch (inst->getOp()) + { + case kIROp_IntLit: + return static_cast<IRConstant*>(inst)->value.intVal; + break; + default: + // Treat specialization constant array as the unsized array here. + if (isSpecConstRateType(inst->getFullType())) + return kUnsizedArrayMagicLength; + + SLANG_UNEXPECTED("needed a known integer value"); + UNREACHABLE_RETURN(0); + } +} + // IRCapabilitySet CapabilitySet IRCapabilitySet::getCaps() @@ -3194,6 +3211,10 @@ IRActualGlobalRate* IRBuilder::getActualGlobalRate() { return (IRActualGlobalRate*)getType(kIROp_ActualGlobalRate); } +IRSpecConstRate* IRBuilder::getSpecConstRate() +{ + return (IRSpecConstRate*)getType(kIROp_SpecConstRate); +} IRRateQualifiedType* IRBuilder::getRateQualifiedType(IRRate* rate, IRType* dataType) { |
