Skip to content

Commit 41c6bb6

Browse files
author
git apple-llvm automerger
committed
Merge commit '9eb7e64145f6' from llvm.org/main into next
2 parents 70d67f7 + 9eb7e64 commit 41c6bb6

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

mlir/lib/Dialect/SPIRV/IR/ImageOps.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,36 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
4242
// The order we process operands is important. In case of multiple argument
4343
// taking operands, the arguments are ordered starting with operands having
4444
// smaller-numbered bits first.
45+
if (spirv::bitEnumContainsAny(attr.getValue(), spirv::ImageOperands::Bias)) {
46+
if (!isa<spirv::ImplicitLodOpInterface>(imageOp))
47+
return imageOp->emitError(
48+
"Bias is only valid with implicit-lod instructions");
49+
50+
if (index + 1 > operands.size())
51+
return imageOp->emitError("Bias operand requires 1 argument");
52+
53+
if (!isa<FloatType>(operands[index].getType()))
54+
return imageOp->emitError("Bias must be a floating-point type scalar");
55+
56+
auto samplingOp = cast<spirv::SamplingOpInterface>(imageOp);
57+
auto sampledImageType =
58+
cast<spirv::SampledImageType>(samplingOp.getSampledImage().getType());
59+
auto imageType = cast<spirv::ImageType>(sampledImageType.getImageType());
60+
61+
if (!llvm::is_contained({spirv::Dim::Dim1D, spirv::Dim::Dim2D,
62+
spirv::Dim::Dim3D, spirv::Dim::Cube},
63+
imageType.getDim()))
64+
return imageOp->emitError(
65+
"Bias must only be used with an image type that has "
66+
"a dim operand of 1D, 2D, 3D, or Cube");
67+
68+
if (imageType.getSamplingInfo() != spirv::ImageSamplingInfo::SingleSampled)
69+
return imageOp->emitError("Bias must only be used with an image type "
70+
"that has a MS operand of 0");
71+
72+
++index;
73+
}
74+
4575
if (spirv::bitEnumContainsAny(attr.getValue(), spirv::ImageOperands::Lod)) {
4676
if (!isa<spirv::ExplicitLodOpInterface>(imageOp) &&
4777
!isa<spirv::FetchOpInterface>(imageOp))
@@ -74,12 +104,13 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
74104
if (!llvm::is_contained({spirv::Dim::Dim1D, spirv::Dim::Dim2D,
75105
spirv::Dim::Dim3D, spirv::Dim::Cube},
76106
imageType.getDim()))
77-
return imageOp->emitError("Lod only be used with an image type that has "
78-
"a dim operand of 1D, 2D, 3D, or Cube");
107+
return imageOp->emitError(
108+
"Lod must only be used with an image type that has "
109+
"a dim operand of 1D, 2D, 3D, or Cube");
79110

80111
if (imageType.getSamplingInfo() != spirv::ImageSamplingInfo::SingleSampled)
81-
return imageOp->emitError(
82-
"Lod only be used with an image type that has a MS operand of 0");
112+
return imageOp->emitError("Lod must only be used with an image type that "
113+
"has a MS operand of 0");
83114

84115
++index;
85116
}
@@ -99,8 +130,8 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
99130
auto imageType = cast<spirv::ImageType>(sampledImageType.getImageType());
100131

101132
if (imageType.getSamplingInfo() != spirv::ImageSamplingInfo::SingleSampled)
102-
return imageOp->emitError(
103-
"Grad only be used with an image type that has a MS operand of 0");
133+
return imageOp->emitError("Grad must only be used with an image type "
134+
"that has a MS operand of 0");
104135

105136
int64_t numberOfComponents = 0;
106137

@@ -147,10 +178,9 @@ static LogicalResult verifyImageOperands(Operation *imageOp,
147178

148179
// TODO: Add the validation rules for the following Image Operands.
149180
spirv::ImageOperands noSupportOperands =
150-
spirv::ImageOperands::Bias | spirv::ImageOperands::ConstOffset |
151-
spirv::ImageOperands::Offset | spirv::ImageOperands::ConstOffsets |
152-
spirv::ImageOperands::Sample | spirv::ImageOperands::MinLod |
153-
spirv::ImageOperands::MakeTexelAvailable |
181+
spirv::ImageOperands::ConstOffset | spirv::ImageOperands::Offset |
182+
spirv::ImageOperands::ConstOffsets | spirv::ImageOperands::Sample |
183+
spirv::ImageOperands::MinLod | spirv::ImageOperands::MakeTexelAvailable |
154184
spirv::ImageOperands::MakeTexelVisible |
155185
spirv::ImageOperands::SignExtend | spirv::ImageOperands::ZeroExtend;
156186

mlir/test/Dialect/SPIRV/IR/image-ops.mlir

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,36 @@ func.func @sample_implicit_proj_dref(%arg0 : !spirv.sampled_image<!spirv.image<f
276276

277277
// -----
278278

279+
//===----------------------------------------------------------------------===//
280+
// spirv.ImageOperands: Bias
281+
//===----------------------------------------------------------------------===//
282+
283+
func.func @bias_too_many_arguments(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : f32, %arg2 : f32) -> () {
284+
// expected-error @+1 {{too many image operand arguments have been provided}}
285+
%0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Bias"], %arg2, %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, f32, f32, f32 -> vector<4xf32>
286+
spirv.Return
287+
}
288+
289+
// -----
290+
291+
func.func @bias_too_many_arguments(%arg0 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : f32, %arg2 : i32) -> () {
292+
// expected-error @+1 {{Bias must be a floating-point type scalar}}
293+
%0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Bias"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Dim1D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, f32, i32 -> vector<4xf32>
294+
spirv.Return
295+
}
296+
297+
// -----
298+
299+
func.func @bias_with_rect(%arg0 : !spirv.sampled_image<!spirv.image<f32, Rect, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : f32, %arg2 : f32) -> () {
300+
// expected-error @+1 {{Bias must only be used with an image type that has a dim operand of 1D, 2D, 3D, or Cube}}
301+
%0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Bias"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Rect, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, f32, f32 -> vector<4xf32>
302+
spirv.Return
303+
}
304+
305+
// TODO: We cannot currently test Bias with MS != 0 as all implemented implicit operations already check for that.
306+
307+
// -----
308+
279309
//===----------------------------------------------------------------------===//
280310
// spirv.ImageOperands: Lod
281311
//===----------------------------------------------------------------------===//
@@ -305,7 +335,7 @@ func.func @lod_too_many_arguments(%arg0 : !spirv.sampled_image<!spirv.image<f32,
305335
// -----
306336

307337
func.func @lod_with_rect(%arg0 : !spirv.sampled_image<!spirv.image<f32, Rect, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, %arg1 : vector<2xf32>, %arg2 : f32) -> () {
308-
// expected-error @+1 {{Lod only be used with an image type that has a dim operand of 1D, 2D, 3D, or Cube}}
338+
// expected-error @+1 {{Lod must only be used with an image type that has a dim operand of 1D, 2D, 3D, or Cube}}
309339
%0 = spirv.ImageSampleExplicitLod %arg0, %arg1 ["Lod"], %arg2 : !spirv.sampled_image<!spirv.image<f32, Rect, NoDepth, NonArrayed, SingleSampled, NeedSampler, Rgba8>>, vector<2xf32>, f32 -> vector<4xf32>
310340
spirv.Return
311341
}

0 commit comments

Comments
 (0)