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

Igor Wodiany llvmlistbot at llvm.org
Tue Jul 29 03:35:52 PDT 2025


================
@@ -575,6 +575,83 @@ 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]() {
----------------
IgWod-IMG wrote:

I wonder if having it more explicit would be easier to read and it's equally compact. It'd make more sense to do it this way if it extended beyond 3, however 1D is followed by Cube, followed by Rect, so it won't fit into the macro anymore. But again, it’s quite subjective so up to you.

```c++
spirv::Dim dim;
switch(rank) {
  case 1:
    dim = spirv::Dim::Dim1D;
    break;
  case 2:
    dim = spirv::Dim::Dim2D;
    break;
  case 3:
    dim = spirv::Dim::Dim3D;
    break;
  default:
    llvm_unreachable("Invalid memref rank!");
}
```

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


More information about the Mlir-commits mailing list