[llvm] [DirectX] Add `llvm.dx.resource.getdimensions` intrinsic and lowering to DXIL (PR #161753)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 11:26:08 PDT 2025
================
@@ -627,6 +627,30 @@ class OpLowerer {
});
}
+ [[nodiscard]] bool lowerGetDimensions(Function &F) {
+ IRBuilder<> &IRB = OpBuilder.getIRB();
+ Type *Int32Ty = IRB.getInt32Ty();
+
+ return replaceFunction(F, [&](CallInst *CI) -> Error {
+ IRB.SetInsertPoint(CI);
+ Value *Handle =
+ createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
+ Value *Op1 = CI->getArgOperand(1);
+ if (isa<llvm::PoisonValue>(Op1))
+ Op1 = UndefValue::get(Int32Ty);
+
+ Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
+ OpCode::GetDimensions, {Handle, Op1}, CI->getName(), Int32Ty);
----------------
bogner wrote:
There isn't really a great place to do it, but we should validate here that the results are being used correctly (That is, none of the `undef`s in the table in https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#getdimensions are being accessed) based on the type of the resource. This will prevent us from generating DXIL that wouldn't pass the validator if we're given bogus IR.
https://github.com/llvm/llvm-project/pull/161753
More information about the llvm-commits
mailing list