[Mlir-commits] [mlir] [mlir][memref][spirv] Add SPIR-V Image Lowering (PR #150978)

Jakub Kuderski llvmlistbot at llvm.org
Wed Jul 30 05:09:54 PDT 2025


================
@@ -575,6 +575,82 @@ static Type convertMemrefType(const spirv::TargetEnv &targetEnv,
   }
   spirv::StorageClass storageClass = attr.getValue();
 
+  // Images are a special case since they are an opaque type from which elements
+  // may be accessed via image specific ops or directly through a texture
+  // pointer.
+  if (storageClass == spirv::StorageClass::Image) {
+    const int64_t rank = type.getRank();
+    if (rank < 1 || rank > 3) {
+      LLVM_DEBUG(llvm::dbgs()
+                 << type << " illegal: cannot lower memref of rank " << rank
+                 << " to a SPIR-V Image\n");
+      return nullptr;
+    }
+
+    const auto dim = [rank]() {
+      switch (rank) {
+      case 1:
+        return spirv::Dim::Dim1D;
+      case 2:
+        return spirv::Dim::Dim2D;
+      case 3:
+        return spirv::Dim::Dim3D;
+      default:
+        llvm_unreachable("Invalid memref rank!");
+      }
+    }();
+
+    // Note that we currently only support lowering to single element texels
+    // e.g. R32f.
+    auto elementType = type.getElementType();
+    if (!elementType.isIntOrFloat()) {
+      LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot lower memref of "
+                              << elementType << " to a  SPIR-V Image\n");
----------------
kuhar wrote:

Also here: should we check for scalar types?

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


More information about the Mlir-commits mailing list