From b325474c4aba52cca7e0bcd4eae02d23ca4ab9a3 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 15 May 2025 11:59:15 -0500 Subject: Implement spec const for generic parameter (#7121) Close #6840. This PR add supports to use specialize constant in generic parameter, and that parameter can also be used as array size, e.g. following code should work: ``` struct MyStruct { float buffer[N]; } MyStruct s; ``` - Loose the restriction from Link-Time to SpecializationConstant when extract generic argument - Tweak the logic of how we decide whether a inst is hoistable. Besides checking existing hoistable flag of each IRInst, when we detect a IRInst's type is SpecConstRateType, we will treat that inst hoistable. Because IRInst in global scope can be deduplicated, and every SpecConstRateType inst should be in the global scope or IRGeneric scope (which will be at global scope after specialization). - Remove the SpecConstIntVal to IRInst map in IR lowering logic, because we already have way to deduplicate the global scope IR. --- source/slang/slang-ir-specialize.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-specialize.cpp') diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp index 2f51b28a2..266c1aa99 100644 --- a/source/slang/slang-ir-specialize.cpp +++ b/source/slang/slang-ir-specialize.cpp @@ -101,7 +101,13 @@ struct SpecializationContext case kIROp_IntCast: case kIROp_FloatCast: case kIROp_Select: - return true; + { + if (isSpecConstRateType(inst->getFullType())) + { + return false; + } + return true; + } default: return false; } -- cgit v1.2.3