From c68c6fa02690012f54928202811050cee649d81e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 19 Apr 2018 09:34:54 -0700 Subject: Fix up DXR type emission from IR type system (#498) * There was a simple typo where we were emitting `RaytracingAccelerationStructureType` instead of `RaytracingAccelerationStructure` * The IR lowering logic was failing to handle types with an `__intrinsic_type` modifier (which maps them to a single IR opcode) that weren't in one of the various special cases. I added a catch-all case to the handling of `DeclRefType`. This notably affected the `RayDesc` type. * Even if we lower `RayDesc` to an intrinsic type, we still need to lower its *fields* too, and these were getting emitted with mangled names (as would happen for any user-defined fields). The solution I implemented was to allow for fields to have `__target_intrinsic` modifiers in the stdlib, to specify the un-mangled name they should use on each target. I'm not 100% happy with this solution, because it seems odd to have `RayDesc` be an intrinsic type, but then to also have field keys used in `getField` instructions as if it were an ordinary `struct`. It seems like a better solution would be to have it lower to an IR `struct`, just with an appropriate modifier. --- source/slang/emit.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index e93dfbbb5..71d323c9e 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1095,9 +1095,9 @@ struct EmitVisitor { switch (type->op) { - case kIROp_HLSLByteAddressBufferType: Emit("ByteAddressBuffer"); break; - case kIROp_HLSLRWByteAddressBufferType: Emit("RWByteAddressBuffer"); break; - case kIROp_RaytracingAccelerationStructureType: Emit("RaytracingAccelerationStructureType"); break; + case kIROp_HLSLByteAddressBufferType: Emit("ByteAddressBuffer"); break; + case kIROp_HLSLRWByteAddressBufferType: Emit("RWByteAddressBuffer"); break; + case kIROp_RaytracingAccelerationStructureType: Emit("RaytracingAccelerationStructure"); break; default: SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled buffer type"); @@ -1110,9 +1110,9 @@ struct EmitVisitor { switch (type->op) { - case kIROp_HLSLByteAddressBufferType: Emit("ByteAddressBuffer"); break; - case kIROp_HLSLRWByteAddressBufferType: Emit("RWByteAddressBuffer"); break; - case kIROp_RaytracingAccelerationStructureType: Emit("RaytracingAccelerationStructureType"); break; + case kIROp_HLSLByteAddressBufferType: Emit("ByteAddressBuffer"); break; + case kIROp_HLSLRWByteAddressBufferType: Emit("RWByteAddressBuffer"); break; + case kIROp_RaytracingAccelerationStructureType: Emit("RaytracingAccelerationStructure"); break; default: SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled buffer type"); @@ -1898,6 +1898,14 @@ struct EmitVisitor String getIRName( IRInst* inst) { + // If the instruction names something + // that should be emitted as a target intrinsic, + // then use that name instead. + if(auto intrinsicDecoration = findTargetIntrinsicDecoration(context, inst)) + { + return intrinsicDecoration->definition; + } + // If the instruction has a mangled name, then emit using that. if (auto globalValue = as(inst)) { @@ -2498,9 +2506,9 @@ struct EmitVisitor IRTargetIntrinsicDecoration* findTargetIntrinsicDecoration( EmitContext* /* ctx */, - IRFunc* func) + IRInst* inst) { - for (auto dd = func->firstDecoration; dd; dd = dd->next) + for (auto dd = inst->firstDecoration; dd; dd = dd->next) { if (dd->op != kIRDecorationOp_TargetIntrinsic) continue; -- cgit v1.2.3