From e4d7def727f75cee3f8fdfe6f286da2b8114b329 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 10 Jul 2023 12:23:07 -0700 Subject: Fix hit object emit for HLSL + FuncType specialization bug fix. (#2976) * Fix hit object emit for HLSL. * Fix a bug involving specialization of functon type. * Add a test case. --------- Co-authored-by: Yong He --- source/slang/slang-emit-hlsl.cpp | 2 +- source/slang/slang-ir-link.cpp | 3 ++- source/slang/slang-ir-lower-witness-lookup.cpp | 2 +- source/slang/slang-ir.cpp | 4 ++++ source/slang/slang-lower-to-ir.cpp | 12 ++++++------ 5 files changed, 14 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 76300c18b..bc6b7a159 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -926,7 +926,7 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) } case kIROp_HitObjectType: { - m_writer->emit("HitObject"); + m_writer->emit("NvHitObject"); return; } default: break; diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 14e79560e..f57919e44 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -1198,10 +1198,11 @@ IRInst* cloneInst( IRInst* clonedArg = cloneValue(context, originalArg); newArgs[aa] = clonedArg; } + auto funcType = cloneType(context, originalInst->getFullType()); context->builder = oldBuilder; IRInst* clonedInst = builder->createIntrinsicInst( - cloneType(context, originalInst->getFullType()), + funcType, originalInst->getOp(), argCount, newArgs.getArrayView().getBuffer()); builder->addInst(clonedInst); diff --git a/source/slang/slang-ir-lower-witness-lookup.cpp b/source/slang/slang-ir-lower-witness-lookup.cpp index 841617ac8..b94059238 100644 --- a/source/slang/slang-ir-lower-witness-lookup.cpp +++ b/source/slang/slang-ir-lower-witness-lookup.cpp @@ -106,7 +106,7 @@ struct WitnessLookupLoweringContext translatedOperands.add(translateType(builder, type->getOperand(i))); } auto translated = builder.emitIntrinsicInst( - builder.getTypeKind(), + type->getFullType(), type->getOp(), (UInt)translatedOperands.getCount(), translatedOperands.getBuffer()); diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 74679de96..84730c913 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -1570,6 +1570,10 @@ namespace Slang parent = mergeCandidateParentsForHoistableInst(parent, operandParent); } + if (inst->getFullType()) + { + parent = mergeCandidateParentsForHoistableInst(parent, inst->getFullType()->getParent()); + } // We better have ended up with a parent to insert into, // or else the invariants of our IR have been violated. diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index cf564605c..7b649ff0d 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -8577,6 +8577,12 @@ struct DeclLoweringVisitor : DeclVisitor else outerGeneric = emitOuterGenerics(subContext, decl, decl); + FuncDeclBaseTypeInfo info; + _lowerFuncDeclBaseTypeInfo( + subContext, + createDefaultSpecializedDeclRef(context, nullptr, decl), + info); + // need to create an IR function here IRFunc* irFunc = subBuilder->createFunc(); @@ -8598,12 +8604,6 @@ struct DeclLoweringVisitor : DeclVisitor } } - FuncDeclBaseTypeInfo info; - _lowerFuncDeclBaseTypeInfo( - subContext, - createDefaultSpecializedDeclRef(context, nullptr, decl), - info); - auto irFuncType = info.type; auto& irResultType = info.resultType; auto& parameterLists = info.parameterLists; -- cgit v1.2.3