[llvm] [DXIL] Consume Metadata Analysis information in passes (PR #108034)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 11:49:58 PDT 2024


================
@@ -58,25 +89,257 @@ static void emitResourceMetadata(Module &M, const DXILResourceMap &DRM,
   }
 
   if (!HasResources)
-    return;
+    return nullptr;
 
   NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata("dx.resources");
   ResourceMD->addOperand(
       MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
+
+  return ResourceMD;
+}
+
+static StringRef getShortShaderStage(Triple::EnvironmentType Env) {
+  switch (Env) {
+  case Triple::Pixel:
+    return "ps";
+  case Triple::Vertex:
+    return "vs";
+  case Triple::Geometry:
+    return "gs";
+  case Triple::Hull:
+    return "hs";
+  case Triple::Domain:
+    return "ds";
+  case Triple::Compute:
+    return "cs";
+  case Triple::Library:
+    return "lib";
+  case Triple::Mesh:
+    return "ms";
+  case Triple::Amplification:
+    return "as";
+  default:
+    break;
+  }
+  llvm_unreachable("Unsupported environment for DXIL generation.");
+}
+
+static uint32_t getShaderStage(Triple::EnvironmentType Env) {
+  return (uint32_t)Env - (uint32_t)llvm::Triple::Pixel;
+}
+
+namespace {
+enum EntryPropsTag {
+  ShaderFlagsTag = 0,
+  GSStateTag,
+  DSStateTag,
+  HSStateTag,
+  NumThreadsTag,
+  AutoBindingSpaceTag,
+  RayPayloadSizeTag,
+  RayAttribSizeTag,
+  ShaderKindTag,
+  MSStateTag,
+  ASStateTag,
+  WaveSizeTag,
+  EntryRootSigTag,
+};
----------------
bogner wrote:

I think it'd be better to use `enum class` here. This would also mean the "Tag" suffix on each value isn't necessary since it doesn't pollute the local namespace that way.

https://github.com/llvm/llvm-project/pull/108034


More information about the llvm-commits mailing list