[Mlir-commits] [mlir] [mlir][spirv] Add definition for ImageWriteOp (PR #124124)
Igor Wodiany
llvmlistbot at llvm.org
Tue Feb 4 08:10:13 PST 2025
================
@@ -2020,6 +2020,65 @@ LogicalResult spirv::ImageDrefGatherOp::verify() {
return verifyImageOperands(*this, attr, operandArguments);
}
+//===----------------------------------------------------------------------===//
+// spirv.ImageWriteOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult spirv::ImageWriteOp::verify() {
+ ImageType imageType = llvm::cast<ImageType>(getImage().getType());
+ Type sampledType = imageType.getElementType();
+ ImageSamplerUseInfo samplerInfo = imageType.getSamplerUseInfo();
+
+ if (samplerInfo != spirv::ImageSamplerUseInfo::SamplerUnknown &&
+ samplerInfo != spirv::ImageSamplerUseInfo::NoSampler) {
+ return emitOpError(
+ "the sampled operand of the underlying image must be 0 or 2");
+ }
+
+ // TODO: Do we need check for: "If the Arrayed operand is 1, then additional
+ // capabilities may be required; e.g., ImageCubeArray, or ImageMSArray.".
+
+ if (imageType.getDim() == spirv::Dim::SubpassData) {
+ return emitOpError(
+ "the Dim operand of the underlying image must not be SubpassData");
+ }
+
+ Type texelType = getTexel().getType();
+ if (llvm::isa<VectorType>(texelType)) {
+ texelType = llvm::cast<VectorType>(texelType).getElementType();
----------------
IgWod-IMG wrote:
I don't think this can be achieved with current ODS classes. `AllElementsTypesMatch` can extract element type from the `texel` but then it won't work for `image` as it is not a shaped type, so requires extra processing. On the other hand `TypesMatchWith` allows to transform the `image` to get the right information, but then it cannot get the `texel` element type as it only calls `getType()` and `texel` can be either scalar or vector, so that will not extract element type of the vector. I guess we would need something like `AllElementsTypesMatchWith` so it can both extract element type and transform `image` to extract the `sampledType`. There is also the case where the image type is `void`. I would be inclined to say it is out of the scope of this PR, unless I missed something.
I have however found a more compact C++ implementation of this check. I'll push patch updating this and addressing the comment below soon.
https://github.com/llvm/llvm-project/pull/124124
More information about the Mlir-commits
mailing list