summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-10 12:23:07 -0700
committerGitHub <noreply@github.com>2023-07-10 12:23:07 -0700
commite4d7def727f75cee3f8fdfe6f286da2b8114b329 (patch)
tree197686d1c1736e3fd141b4b62bff5dc193a897c0
parent5569b4850dabbb7dbcb72278bb2918c281e0d475 (diff)
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 <yhe@nvidia.com>
-rw-r--r--source/slang/slang-emit-hlsl.cpp2
-rw-r--r--source/slang/slang-ir-link.cpp3
-rw-r--r--source/slang/slang-ir-lower-witness-lookup.cpp2
-rw-r--r--source/slang/slang-ir.cpp4
-rw-r--r--source/slang/slang-lower-to-ir.cpp12
-rw-r--r--tests/bugs/func-type-specialize.slang36
6 files changed, 50 insertions, 9 deletions
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<DeclLoweringVisitor, LoweredValInfo>
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<DeclLoweringVisitor, LoweredValInfo>
}
}
- FuncDeclBaseTypeInfo info;
- _lowerFuncDeclBaseTypeInfo(
- subContext,
- createDefaultSpecializedDeclRef(context, nullptr, decl),
- info);
-
auto irFuncType = info.type;
auto& irResultType = info.resultType;
auto& parameterLists = info.parameterLists;
diff --git a/tests/bugs/func-type-specialize.slang b/tests/bugs/func-type-specialize.slang
new file mode 100644
index 000000000..7e17c5c3d
--- /dev/null
+++ b/tests/bugs/func-type-specialize.slang
@@ -0,0 +1,36 @@
+//TEST:SIMPLE(filecheck=CHECK):-target hlsl -entry computeMain -profile cs_6_5 -validate-ir
+//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+// CHECK: void computeMain
+// CHECK: RayQuery<0
+interface IFoo
+{
+ int doThing<let f : int>(RayQuery<f> arr);
+}
+
+
+struct HitInfo
+{
+ static int makeHitInfo<let f : int>(RayQuery<f> q)
+ {
+ return 0;
+ }
+}
+
+struct Impl : IFoo
+{
+ int doThing<let f : int>(RayQuery<f> arr)
+ {
+ return HitInfo.makeHitInfo(arr);
+ }
+}
+
+RWStructuredBuffer<int> outVal;
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ Impl impl;
+ RayQuery<0> q;
+ outVal[dispatchThreadID.x] = impl.doThing(q);
+} \ No newline at end of file