summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-02-19 08:56:46 -0800
committerGitHub <noreply@github.com>2020-02-19 08:56:46 -0800
commit1d9152bd2d0b1234680ce6a9f7ef940d7f179e9a (patch)
treea4672a712ddc9217ac44fc98fcefcaccc04244e8 /source/slang/slang-emit-hlsl.cpp
parent45d1a680634c59d1081ed09dddaa444695296492 (diff)
Fixes for DXR 1.1 RayQuery type (#1227)
The previous change that added `RayQuery` to the standard library didn't mark it as any kind of intrinsic, so the first fix here was to add the appopriate attribtue to the stdlib declaration of `RayQuery`. Next I found that the legalization pass was obliterating the `RayQuery` type because it had no members, and thus looked like an empty `struct` (which we eliminate for a variety of reasons). I fixed that by adding a check for a target-intrinsic decoration in type legalization. Next I found that the type wasn't emitted correctly because our generic specialization was turning `RayQuery<0>` into a new type `RayQuery_0` (which is what our specialization is designed to do, after all). I then disabled generic specialization for types that are marked as target intrinsics (which probably renders the preceding fix moot). Finally, I found that the emit logic for types in HLSL wasn't handling the case of a generic intrinsic type that didn't also use its own dedicated opcode. I fixes that up by adding a specific case for `IRSpecialize` as a late catch-all. After all these changes, a declaration of a `RayQuery` variable seems to Just Work (even without any new/improved behavior for handling default constructors). One potential gotcha looking forward is that my checks for `IRTargetIntrinsicDecoration` aren't checking what target the decoration is for. This is fine for now because there are only two types using the decoration right now (`RayDesc` and `RayQuery`), and the special cases above are reasonable for both of them. If/when we have more target-intrinsic types with this decoration, and some of them are only intrinsic for specific targets, then we will need to revisit this choice and either: * make these checks perform filtering based on the "current" target (similar to what the emit logic has today), or * (more likely) make the linking and target-specialization step strip out any target-intrinsic decorations that aren't the right one(s) for the current target Note that this change doesn't include a test case yet because I don't have a DXR 1.1 ready version of dxc to test against. I have manually confirmed that appropriate Slang input seems to be producing reasonable HLSL output when using these functions, but I cannot yet try to check that in (using an HLSL file for the expected output would be quite fragile).
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 4225b1bf3..1d4b6a317 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -659,6 +659,22 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
return;
}
+ else if(auto specializedType = as<IRSpecialize>(type))
+ {
+ // If a `specialize` instruction made it this far, then
+ // it represents an intrinsic generic type.
+ //
+ emitSimpleType((IRType*) getSpecializedValue(specializedType));
+ m_writer->emit("<");
+ UInt argCount = specializedType->getArgCount();
+ for (UInt ii = 0; ii < argCount; ++ii)
+ {
+ if (ii != 0) m_writer->emit(", ");
+ emitVal(specializedType->getArg(ii), getInfo(EmitOp::General));
+ }
+ m_writer->emit(" >");
+ return;
+ }
// HACK: As a fallback for HLSL targets, assume that the name of the
// instruction being used is the same as the name of the HLSL type.