[Mlir-commits] [mlir] [mlir][spirv] Add SPIRV_FetchOpInterface to SPIRV_ImageFetchOp (PR #192986)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 20 07:39:24 PDT 2026
https://github.com/moscickimilosz created https://github.com/llvm/llvm-project/pull/192986
SPIRV_ImageFetchOp was missing the SPIRV_FetchOpInterface interface. Without it, the Lod image operand validation in ImageOps.cpp would reject Lod on spirv.ImageFetch because line 77 checks `(!isa<spirv::ExplicitLodOpInterface>(imageOp) &&
!isa<spirv::FetchOpInterface>(imageOp))`. The fix adds DeclareOpInterfaceMethods<SPIRV_FetchOpInterface> to the op's trait list.
>From 3815779ae3283df0f0173c744aa0023726f63cc2 Mon Sep 17 00:00:00 2001
From: Milosz Moscicki <Milosz.Moscicki at imgtec.com>
Date: Mon, 13 Apr 2026 15:46:30 +0100
Subject: [PATCH] [mlir][spirv] Add SPIRV_FetchOpInterface to
SPIRV_ImageFetchOp
SPIRV_ImageFetchOp was missing the SPIRV_FetchOpInterface interface.
Without it, the Lod image operand validation in ImageOps.cpp would
reject Lod on spirv.ImageFetch because line 77 checks
(!isa<spirv::ExplicitLodOpInterface>(imageOp) &&
!isa<spirv::FetchOpInterface>(imageOp)). The fix adds
DeclareOpInterfaceMethods<SPIRV_FetchOpInterface> to the op's trait
list.
---
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td | 3 ++-
mlir/test/Dialect/SPIRV/IR/image-ops.mlir | 12 +++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
index e5ff4c5d96b4a..6d51d479f7562 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
@@ -592,7 +592,8 @@ def SPIRV_ImageSampleProjDrefImplicitLodOp : SPIRV_Op<"ImageSampleProjDrefImplic
def SPIRV_ImageFetchOp : SPIRV_Op<"ImageFetch",
[SPIRV_DimIsNot<"image", ["Cube"]>,
SPIRV_SampledOperandIs<"image", ["NeedSampler"]>,
- SPIRV_NoneOrElementMatchImage<"result", "image">]> {
+ SPIRV_NoneOrElementMatchImage<"result", "image">,
+ DeclareOpInterfaceMethods<SPIRV_FetchOpInterface>]> {
let summary = "Fetch a single texel from an image whose Sampled operand is 1. ";
let description = [{
diff --git a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
index c4f90cfcb9a49..9b17ca54b628d 100644
--- a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
@@ -405,7 +405,17 @@ func.func @lod_with_rect(%arg0 : !spirv.sampled_image<!spirv.image<f32, Rect, No
// TODO: We cannot currently test Lod with MS != 0 as all implemented explicit operations already check for that.
-// TODO: Add Lod tests for fetch operations once available.
+// -----
+
+// Lod is valid for spirv.ImageFetch (fetch instruction).
+func.func @lod_with_image_fetch(%arg0: !spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>,
+ %arg1: vector<2xsi32>, %arg2: si32) -> () {
+ // CHECK: {{%.*}} = spirv.ImageFetch {{%.*}}, {{%.*}} ["Lod"], {{%.*}} : !spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>, vector<2xsi32>, si32 -> vector<4xf32>
+ %0 = spirv.ImageFetch %arg0, %arg1 ["Lod"], %arg2 :
+ !spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>,
+ vector<2xsi32>, si32 -> vector<4xf32>
+ spirv.Return
+}
// -----
More information about the Mlir-commits
mailing list