[Mlir-commits] [mlir] [mlir][spirv] Add definition for selected sample operations (PR #129558)
Igor Wodiany
llvmlistbot at llvm.org
Tue Mar 11 03:58:40 PDT 2025
================
@@ -268,4 +274,208 @@ def SPIRV_ImageOp : SPIRV_Op<"Image",
let hasVerifier = 0;
}
-#endif // MLIR_DIALECT_SPIRV_IR_GL_OPS
+// -----
+
+def SPIRV_ImageSampleExplicitLodOp : SPIRV_Op<"ImageSampleExplicitLod",
+ [SPIRV_DimIsNot<"sampled_image", ["Buffer"], SPIRV_SampledImageTransform.result>,
+ SPIRV_MSOperandIs<"sampled_image", ["SingleSampled"], SPIRV_SampledImageTransform.result>,
+ SPIRV_NoneOrElementMatchImage<"result", "sampled_image", SPIRV_SampledImageTransform.result>,
+ SPIRV_ImageOperandIsPresent<"image_operands", ["Lod", "Grad"]>,
+ DeclareOpInterfaceMethods<SPIRV_ExplicitLodOpInterface>]> {
+ let summary = "Sample an image using an explicit level of detail.";
+
+ let description = [{
+ Result Type must be a vector of four components of floating-point type
+ or integer type. Its components must be the same as Sampled Type of the
+ underlying OpTypeImage (unless that underlying Sampled Type is
+ OpTypeVoid).
+
+ Sampled Image must be an object whose type is OpTypeSampledImage. Its
+ OpTypeImage must not have a Dim of Buffer. The MS operand of the
+ underlying OpTypeImage must be 0.
+
+ Coordinate must be a scalar or vector of floating-point type or integer
+ type. It contains (u[, v] ... [, array layer]) as needed by the
+ definition of Sampled Image. Unless the Kernel capability is declared,
+ it must be floating point. It may be a vector larger than needed, but
+ all unused components appear after all used components.
+
+ Image Operands encodes what operands follow, as per Image Operands.
+ Either Lod or Grad image operands must be present.
+
+ <!-- End of AutoGen section -->
+
+ #### Example:
+
+ ```mlir
+ %result = spirv.ImageSampleExplicitLod %image, %coord ["Lod"](%lod) : !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Unknown>>, vector<2xf32> (f32) -> vector<4xf32>
----------------
IgWod-IMG wrote:
I split it into:
```mlir
%result = spirv.ImageSampleExplicitLod %image, %coord ["Lod"](%lod) :
!spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Unknown>>,
vector<2xf32> (f32) -> vector<4xf32>
```
It's ~110 characters but roughly fits the rest of the file. I'm happy to split it further if we want to get closer to the 80 characters limit.
https://github.com/llvm/llvm-project/pull/129558
More information about the Mlir-commits
mailing list