[clang] [HLSL][SPIRV] Add -fspv-use-unknown-image-format option (PR #155664)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 29 14:05:00 PDT 2025


================
@@ -513,14 +513,65 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
   return nullptr;
 }
 
+static unsigned
+getImageFormat(const LangOptions &LangOpts,
+               const HLSLAttributedResourceType::Attributes &attributes,
+               llvm::Type *SampledType, QualType Ty, unsigned NumChannels) {
+  // For images with `Sampled` operand equal to 2, there are restrictions on
+  // using the Unknown image format. To avoid these restrictions in common
+  // cases, we guess an image format for them based on the sampled type and the
+  // number of channels. This is intended to match the behaviour of DXC.
+  if (LangOpts.HLSLSpvUseUnknownImageFormat ||
+      attributes.ResourceClass != llvm::dxil::ResourceClass::UAV) {
+    return 0; // Unknown
+  }
+
+  if (SampledType->isIntegerTy(32)) {
+    if (Ty->isSignedIntegerType()) {
+      if (NumChannels == 1)
+        return 24; // R32i
----------------
shafik wrote:

We can use enums for these values and give them a name that clarifies intent and not have to worry about keeping comments up to date?

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


More information about the cfe-commits mailing list