|
15 | 15 | #define MLIR_DIALECT_SPIRV_IR_IMAGE_OPS
|
16 | 16 |
|
17 | 17 | include "mlir/Dialect/SPIRV/IR/SPIRVBase.td"
|
| 18 | +include "mlir/Dialect/SPIRV/Interfaces/SPIRVImageInterfaces.td" |
18 | 19 | include "mlir/Interfaces/SideEffectInterfaces.td"
|
19 | 20 |
|
20 | 21 | // -----
|
@@ -48,14 +49,19 @@ class SPIRV_DimIsNot<string operand, list<string> values, string transform="$_se
|
48 | 49 |
|
49 | 50 | class SPIRV_NoneOrElementMatchImage<string operand, string image, string transform="$_self"> : PredOpTrait<
|
50 | 51 | "the " # operand # " component type must match the image sampled type",
|
51 |
| - CPred<"::llvm::isa<NoneType>(cast<ImageType>(" # !subst("$_self", "$" # image # ".getType()", transform) # ").getElementType()) ||" |
| 52 | + CPred<"::llvm::isa<NoneType>(cast<::mlir::spirv::ImageType>(" # !subst("$_self", "$" # image # ".getType()", transform) # ").getElementType()) ||" |
52 | 53 | "(getElementTypeOrSelf($" # operand # ")"
|
53 | 54 | "=="
|
54 |
| - "cast<ImageType>(" # !subst("$_self", "$" # image # ".getType()", transform) # ").getElementType())" |
| 55 | + "cast<::mlir::spirv::ImageType>(" # !subst("$_self", "$" # image # ".getType()", transform) # ").getElementType())" |
55 | 56 | >
|
56 | 57 | >;
|
57 | 58 |
|
58 |
| -def SPIRV_SampledImageTransform : StrFunc<"llvm::cast<spirv::SampledImageType>($_self).getImageType()">; |
| 59 | +class SPIRV_ImageOperandIsPresent<string operand, list<string> values> : PredOpTrait< |
| 60 | + "either " # !interleave(values, " or ") # " image operands must be present", |
| 61 | + CPred<"::mlir::spirv::bitEnumContainsAny($" # operand # ", " # "::mlir::spirv::ImageOperands::" # !interleave(values, " | ::mlir::spirv::ImageOperands::") # ")"> |
| 62 | +>; |
| 63 | + |
| 64 | +def SPIRV_SampledImageTransform : StrFunc<"llvm::cast<::mlir::spirv::SampledImageType>($_self).getImageType()">; |
59 | 65 |
|
60 | 66 | // -----
|
61 | 67 |
|
@@ -89,7 +95,7 @@ def SPIRV_ImageDrefGatherOp : SPIRV_Op<"ImageDrefGather",
|
89 | 95 |
|
90 | 96 | ```mlir
|
91 | 97 | %0 = spirv.ImageDrefGather %1, %2, %3 : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, vector<4xf32>, f32 -> vector<4xi32>
|
92 |
| - %0 = spirv.ImageDrefGather %1, %2, %3 : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, vector<4xf32>, f32 ["NonPrivateTexel"] -> vector<4xi32> |
| 98 | + %0 = spirv.ImageDrefGather %1, %2, %3 ["NonPrivateTexel"] : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, vector<4xf32>, f32 -> vector<4xi32> |
93 | 99 | ```
|
94 | 100 | }];
|
95 | 101 |
|
@@ -268,4 +274,214 @@ def SPIRV_ImageOp : SPIRV_Op<"Image",
|
268 | 274 | let hasVerifier = 0;
|
269 | 275 | }
|
270 | 276 |
|
271 |
| -#endif // MLIR_DIALECT_SPIRV_IR_GL_OPS |
| 277 | +// ----- |
| 278 | + |
| 279 | +def SPIRV_ImageSampleExplicitLodOp : SPIRV_Op<"ImageSampleExplicitLod", |
| 280 | + [SPIRV_DimIsNot<"sampled_image", ["Buffer"], SPIRV_SampledImageTransform.result>, |
| 281 | + SPIRV_MSOperandIs<"sampled_image", ["SingleSampled"], SPIRV_SampledImageTransform.result>, |
| 282 | + SPIRV_NoneOrElementMatchImage<"result", "sampled_image", SPIRV_SampledImageTransform.result>, |
| 283 | + SPIRV_ImageOperandIsPresent<"image_operands", ["Lod", "Grad"]>, |
| 284 | + DeclareOpInterfaceMethods<SPIRV_ExplicitLodOpInterface>]> { |
| 285 | + let summary = "Sample an image using an explicit level of detail."; |
| 286 | + |
| 287 | + let description = [{ |
| 288 | + Result Type must be a vector of four components of floating-point type |
| 289 | + or integer type. Its components must be the same as Sampled Type of the |
| 290 | + underlying OpTypeImage (unless that underlying Sampled Type is |
| 291 | + OpTypeVoid). |
| 292 | + |
| 293 | + Sampled Image must be an object whose type is OpTypeSampledImage. Its |
| 294 | + OpTypeImage must not have a Dim of Buffer. The MS operand of the |
| 295 | + underlying OpTypeImage must be 0. |
| 296 | + |
| 297 | + Coordinate must be a scalar or vector of floating-point type or integer |
| 298 | + type. It contains (u[, v] ... [, array layer]) as needed by the |
| 299 | + definition of Sampled Image. Unless the Kernel capability is declared, |
| 300 | + it must be floating point. It may be a vector larger than needed, but |
| 301 | + all unused components appear after all used components. |
| 302 | + |
| 303 | + Image Operands encodes what operands follow, as per Image Operands. |
| 304 | + Either Lod or Grad image operands must be present. |
| 305 | + |
| 306 | + <!-- End of AutoGen section --> |
| 307 | + |
| 308 | + #### Example: |
| 309 | + |
| 310 | + ```mlir |
| 311 | + %result = spirv.ImageSampleExplicitLod %image, %coord ["Lod"](%lod) : |
| 312 | + !spirv.sampled_image<!spirv.image<f32, Dim2D, NoDepth, NonArrayed, SingleSampled, NeedSampler, Unknown>>, |
| 313 | + vector<2xf32> (f32) -> vector<4xf32> |
| 314 | + ``` |
| 315 | + }]; |
| 316 | + |
| 317 | + let arguments = (ins |
| 318 | + SPIRV_AnySampledImage:$sampled_image, |
| 319 | + AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>]>:$coordinate, |
| 320 | + SPIRV_ImageOperandsAttr:$image_operands, |
| 321 | + Variadic<SPIRV_Type>:$operand_arguments |
| 322 | + ); |
| 323 | + |
| 324 | + let results = (outs |
| 325 | + AnyTypeOf<[SPIRV_Vec4<SPIRV_Integer>, SPIRV_Vec4<SPIRV_Float>]>:$result |
| 326 | + ); |
| 327 | + |
| 328 | + let assemblyFormat = [{ |
| 329 | + $sampled_image `,` $coordinate custom<ImageOperands>($image_operands) ( `,` $operand_arguments^ )? attr-dict |
| 330 | + `:` type($sampled_image) `,` type($coordinate) ( `,` type($operand_arguments)^ )? |
| 331 | + `->` type($result) |
| 332 | + }]; |
| 333 | +} |
| 334 | + |
| 335 | +// ----- |
| 336 | + |
| 337 | +def SPIRV_ImageSampleImplicitLodOp : SPIRV_Op<"ImageSampleImplicitLod", |
| 338 | + [SPIRV_DimIsNot<"sampled_image", ["Buffer"], SPIRV_SampledImageTransform.result>, |
| 339 | + SPIRV_MSOperandIs<"sampled_image", ["SingleSampled"], SPIRV_SampledImageTransform.result>, |
| 340 | + SPIRV_NoneOrElementMatchImage<"result", "sampled_image", SPIRV_SampledImageTransform.result>, |
| 341 | + DeclareOpInterfaceMethods<SPIRV_ImplicitLodOpInterface>]> { |
| 342 | + let summary = "Sample an image with an implicit level of detail."; |
| 343 | + |
| 344 | + let description = [{ |
| 345 | + An invocation will not execute a dynamic instance of this instruction |
| 346 | + (X') until all invocations in its derivative group have executed all |
| 347 | + dynamic instances that are program-ordered before X'. |
| 348 | + |
| 349 | + Result Type must be a vector of four components of floating-point type |
| 350 | + or integer type. Its components must be the same as Sampled Type of the |
| 351 | + underlying OpTypeImage (unless that underlying Sampled Type is |
| 352 | + OpTypeVoid). |
| 353 | + |
| 354 | + Sampled Image must be an object whose type is OpTypeSampledImage. Its |
| 355 | + OpTypeImage must not have a Dim of Buffer. The MS operand of the |
| 356 | + underlying OpTypeImage must be 0. |
| 357 | + |
| 358 | + Coordinate must be a scalar or vector of floating-point type. It |
| 359 | + contains (u[, v] ... [, array layer]) as needed by the definition of |
| 360 | + Sampled Image. It may be a vector larger than needed, but all unused |
| 361 | + components appear after all used components. |
| 362 | + |
| 363 | + Image Operands encodes what operands follow, as per Image Operands. |
| 364 | + |
| 365 | + This instruction is only valid in the Fragment Execution Model. In |
| 366 | + addition, it consumes an implicit derivative that can be affected by |
| 367 | + code motion. |
| 368 | + |
| 369 | + <!-- End of AutoGen section --> |
| 370 | + |
| 371 | + #### Example: |
| 372 | + |
| 373 | + ```mlir |
| 374 | + %result = spirv.ImageSampleImplicitLod %image, %coord : |
| 375 | + !spirv.sampled_image<!spirv.image<f32, Cube, NoDepth, NonArrayed, SingleSampled, NeedSampler, Unknown>>, |
| 376 | + vector<3xf32> -> vector<4xf32> |
| 377 | + ``` |
| 378 | + }]; |
| 379 | + |
| 380 | + let availability = [ |
| 381 | + MinVersion<SPIRV_V_1_0>, |
| 382 | + MaxVersion<SPIRV_V_1_6>, |
| 383 | + Extension<[]>, |
| 384 | + Capability<[SPIRV_C_Shader]> |
| 385 | + ]; |
| 386 | + |
| 387 | + let arguments = (ins |
| 388 | + SPIRV_AnySampledImage:$sampled_image, |
| 389 | + SPIRV_ScalarOrVectorOf<SPIRV_Float>:$coordinate, |
| 390 | + OptionalAttr<SPIRV_ImageOperandsAttr>:$image_operands, |
| 391 | + Variadic<SPIRV_Type>:$operand_arguments |
| 392 | + ); |
| 393 | + |
| 394 | + let results = (outs |
| 395 | + AnyTypeOf<[SPIRV_Vec4<SPIRV_Integer>, SPIRV_Vec4<SPIRV_Float>]>:$result |
| 396 | + ); |
| 397 | + |
| 398 | + let assemblyFormat = [{ |
| 399 | + $sampled_image `,` $coordinate custom<ImageOperands>($image_operands) ( `,` $operand_arguments^ )? attr-dict |
| 400 | + `:` type($sampled_image) `,` type($coordinate) ( `,` type($operand_arguments)^ )? |
| 401 | + `->` type($result) |
| 402 | + }]; |
| 403 | +} |
| 404 | + |
| 405 | +// ----- |
| 406 | + |
| 407 | +def SPIRV_ImageSampleProjDrefImplicitLodOp : SPIRV_Op<"ImageSampleProjDrefImplicitLod", |
| 408 | + [SPIRV_DimIsNot<"sampled_image", ["Buffer"], SPIRV_SampledImageTransform.result>, |
| 409 | + SPIRV_MSOperandIs<"sampled_image", ["SingleSampled"], SPIRV_SampledImageTransform.result>, |
| 410 | + TypesMatchWith<"type of 'result' matches image type of 'sampled_image'", |
| 411 | + "sampled_image", "result", |
| 412 | + "::llvm::cast<::mlir::spirv::ImageType>(::llvm::cast<spirv::SampledImageType>($_self).getImageType()).getElementType()">, |
| 413 | + DeclareOpInterfaceMethods<SPIRV_ImplicitLodOpInterface>]> { |
| 414 | + |
| 415 | + let summary = [{ |
| 416 | + Sample an image with a project coordinate, doing depth-comparison, with |
| 417 | + an implicit level of detail. |
| 418 | + }]; |
| 419 | + |
| 420 | + let description = [{ |
| 421 | + An invocation will not execute a dynamic instance of this instruction |
| 422 | + (X') until all invocations in its derivative group have executed all |
| 423 | + dynamic instances that are program-ordered before X'. |
| 424 | + |
| 425 | + Result Type must be a scalar of integer type or floating-point type. It |
| 426 | + must be the same as Sampled Type of the underlying OpTypeImage. |
| 427 | + |
| 428 | + Sampled Image must be an object whose type is OpTypeSampledImage. The |
| 429 | + Dim operand of the underlying OpTypeImage must be 1D, 2D, 3D, or Rect, |
| 430 | + and the Arrayed and MS operands must be 0. |
| 431 | + |
| 432 | + Coordinate must be a vector of floating-point type. It contains (u[, |
| 433 | + v] [, w], q), as needed by the definition of Sampled Image, with the q |
| 434 | + component consumed for the projective division. That is, the actual |
| 435 | + sample coordinate is (u/q [, v/q] [, w/q]), as needed by the definition |
| 436 | + of Sampled Image. It may be a vector larger than needed, but all unused |
| 437 | + components appear after all used components. |
| 438 | + |
| 439 | + Dref/q is the depth-comparison reference value. Dref must be a 32-bit |
| 440 | + floating-point type scalar. |
| 441 | + |
| 442 | + Image Operands encodes what operands follow, as per Image Operands. |
| 443 | + |
| 444 | + This instruction is only valid in the Fragment Execution Model. In |
| 445 | + addition, it consumes an implicit derivative that can be affected by |
| 446 | + code motion. |
| 447 | + |
| 448 | + <!-- End of AutoGen section --> |
| 449 | + |
| 450 | + #### Example: |
| 451 | + |
| 452 | + ```mlir |
| 453 | + %result = spirv.ImageSampleProjDrefImplicitLod %image, %coord, %dref : |
| 454 | + !spirv.sampled_image<!spirv.image<f32, Dim2D, IsDepth, NonArrayed, SingleSampled, NeedSampler, Unknown>>, |
| 455 | + vector<4xf16>, f32 -> f32 |
| 456 | + ``` |
| 457 | + }]; |
| 458 | + |
| 459 | + let availability = [ |
| 460 | + MinVersion<SPIRV_V_1_0>, |
| 461 | + MaxVersion<SPIRV_V_1_6>, |
| 462 | + Extension<[]>, |
| 463 | + Capability<[SPIRV_C_Shader]> |
| 464 | + ]; |
| 465 | + |
| 466 | + let arguments = (ins |
| 467 | + SPIRV_AnySampledImage:$sampled_image, |
| 468 | + AnyTypeOf<[SPIRV_ScalarOrVectorOf<SPIRV_Float>, SPIRV_ScalarOrVectorOf<SPIRV_Integer>]>:$coordinate, |
| 469 | + SPIRV_Float32:$dref, |
| 470 | + OptionalAttr<SPIRV_ImageOperandsAttr>:$image_operands, |
| 471 | + Variadic<SPIRV_Type>:$operand_arguments |
| 472 | + ); |
| 473 | + |
| 474 | + let results = (outs |
| 475 | + AnyTypeOf<[SPIRV_Integer, SPIRV_Float]>:$result |
| 476 | + ); |
| 477 | + |
| 478 | + let assemblyFormat = [{ |
| 479 | + $sampled_image `,` $coordinate `,` $dref custom<ImageOperands>($image_operands) ( `,` $operand_arguments^ )? attr-dict |
| 480 | + `:` type($sampled_image) `,` type($coordinate) `,` type($dref) ( `,` type($operand_arguments)^ )? |
| 481 | + `->` type($result) |
| 482 | + }]; |
| 483 | +} |
| 484 | + |
| 485 | +// ----- |
| 486 | + |
| 487 | +#endif // MLIR_DIALECT_SPIRV_IR_IMAGE_OPS |
0 commit comments