[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)
Finn Plummer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 14 10:16:58 PDT 2025
================
@@ -52,6 +59,45 @@ static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
return false;
}
+static bool extractMdValue(uint32_t &Value, MDNode *Node, unsigned int OpId) {
+
+ auto *CI = mdconst::extract<ConstantInt>(Node->getOperand(OpId));
+ if (CI == nullptr)
+ return true;
+
+ Value = CI->getZExtValue();
+ return false;
+}
+
+static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
+ MDNode *RootFlagNode) {
+
+ if (RootFlagNode->getNumOperands() != 5)
+ return reportError(Ctx, "Invalid format for RootConstants Element");
+
+ mcdxbc::RootParameter NewParameter;
+ NewParameter.Header.ParameterType = dxbc::RootParameterType::Constants32Bit;
+
+ uint32_t SV;
+ if (extractMdValue(SV, RootFlagNode, 1))
+ return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ NewParameter.Header.ShaderVisibility = (dxbc::ShaderVisibility)SV;
+
+ if (extractMdValue(NewParameter.Constants.ShaderRegister, RootFlagNode, 2))
+ return reportError(Ctx, "Invalid value for ShaderRegister");
+
+ if (extractMdValue(NewParameter.Constants.RegisterSpace, RootFlagNode, 3))
+ return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (extractMdValue(NewParameter.Constants.Num32BitValues, RootFlagNode, 4))
+ return reportError(Ctx, "Invalid value for Num32BitValues");
----------------
inbelic wrote:
Only the "Invalid value for ShaderVisibility" has a test demonstrating its functionality. Maybe it is too verbose to include a test case for each diag type, or, they are all reporting the same error (expected an i32) and we could move that logic into `extractMdValue`?
https://github.com/llvm/llvm-project/pull/135085
More information about the llvm-branch-commits
mailing list