From d5f3f477918769338dd5baa73ff560d10a5ca7e9 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Mon, 29 Sep 2025 09:33:45 +0300 Subject: Update function type after inserting KernelContext parameter (#8551) Without this, there are functions with missing parameters in their type in the IR after running the `introduceExplicitGlobalContext` pass: ``` [layout(%15)] [export("_SV4test12outputBuffer")] [nameHint("outputBuffer")] let %outputBuffer : _ = key [noSideEffect] [export("_S4test7dostuffp1pi_ff")] [nameHint("dostuff")] func %dostuff : Func(Float, Float) { block %34( [nameHint("f")] param %f : Float, [nameHint("kernelContext")] param %kernelContext : Ptr(%KernelContext, 0 : UInt64, 1 : UInt64)): let %35 : Float = mul(%f, %f) let %36 : Ptr(ConstantBuffer(%GlobalParams, DefaultLayout), 0 : UInt64, 1 : UInt64) = get_field_addr(%kernelContext, %globalParams) let %37 : ConstantBuffer(%GlobalParams, DefaultLayout) = load(%36) let %38 : Ptr(RWStructuredBuffer(Float, DefaultLayout, %20)) = get_field_addr(%37, %outputBuffer) let %39 : RWStructuredBuffer(Float, DefaultLayout, %20) = load(%38) let %40 : Ptr(Float) = rwstructuredBufferGetElementPtr(%39, 1 : Int) let %41 : Float = load(%40) let %42 : Float = mul(%35, %41) return_val(%42) } ``` Not sure why this doesn't seem to negatively affect existing targets, but it sure is an issue for the LLVM target I'm working on. I could've left this fix for that PR, but I want to check now if this causes any issues with the existing targets using the CI. This also happens with the entry point functions, where the function type is not updated after adding `ComputeThreadVaryingInput`. This had no effect in the C++ target because `convertEntryPointPtrParamsToRawPtrs(irModule);` is called right after and fixes it. --- source/slang/slang-ir-explicit-global-context.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source') diff --git a/source/slang/slang-ir-explicit-global-context.cpp b/source/slang/slang-ir-explicit-global-context.cpp index dd07db883..515992cee 100644 --- a/source/slang/slang-ir-explicit-global-context.cpp +++ b/source/slang/slang-ir-explicit-global-context.cpp @@ -564,6 +564,9 @@ struct IntroduceExplicitGlobalContextPass builder.emitStore(fieldPtr, var); } } + + // Update entry point function type after potentially adding parameters. + fixUpFuncType(entryPointFunc); } void replaceUsesOfGlobalParam(IRGlobalParam* globalParam) @@ -723,6 +726,9 @@ struct IntroduceExplicitGlobalContextPass addKernelContextNameHint(contextParam); contextParam->insertBefore(firstBlock->getFirstOrdinaryInst()); + // Update the type of the function to reflect this new parameter. + fixUpFuncType(func); + // The new parameter can be registered as the context value // to be used for `func` right away. // -- cgit v1.2.3