[llvm] [DirectX] Implement Shader Flag Analysis for `UAVsAtEveryStage` (PR #137085)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 10:44:12 PDT 2025


================
@@ -32,6 +32,35 @@
 using namespace llvm;
 using namespace llvm::dxil;
 
+static bool hasUAVsAtEveryStage(DXILResourceMap &DRM,
+                                const ModuleMetadataInfo &MMDI) {
+  if (DRM.uavs().empty())
+    return false;
+
+  switch (MMDI.ShaderProfile) {
+  default:
+    return false;
+  case Triple::EnvironmentType::Compute:
+  case Triple::EnvironmentType::Pixel:
+    return false;
+  case Triple::EnvironmentType::Vertex:
+  case Triple::EnvironmentType::Geometry:
+  case Triple::EnvironmentType::Hull:
+  case Triple::EnvironmentType::Domain:
+    return true;
----------------
bogner wrote:

This is one of the places where the fact that we're using the triple environment rather than a dedicated enum is kind of annoying. If we had a dedicated enum then we would get a `-Wcovered-switch` warning if that came up and my answer to this question would unambiguously be no.

However, I still don't think that this would be an improvement. Consider:
- If we get another shader stage then by definition the validator version is greater than 1.8, since a new shader stage couldn't be added without bumping the DXIL version.
- Whether or not UAVsAtEveryStage should be set for the new shader stage probably depends on what that stage is, so we'd probably want to modify this anyway.
- If we have a triple that doesn't have a shader stage as its environment (ie, it isn't a `dxil-` triple at all), then calling this function doesn't make any sense. We could arguably make the `default` case `llvm_unreachable()` and just crash if that were to happen.

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


More information about the llvm-commits mailing list