diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLOps.td --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLOps.td @@ -1123,5 +1123,43 @@ let verifier = [{ return ::verify(*this); }]; } +def SPV_GLSLFMixOp : + SPV_GLSLOp<"FMix", 46, [ + NoSideEffect, AllTypesMatch<["x", "y", "a", "result"]>]> { + let summary = "Builds the linear blend of x and y"; + + let description = [{ + Result is the linear blend of x and y, i.e., x * (1 - a) + y * a. + + The operands must all be a scalar or vector whose component type is floating-point. + + Result Type and the type of all operands must be the same type. Results are computed per component. + + + + #### Example: + + ```mlir + %0 = spv.GLSL.FMix %x : f32, %y : f32, %a : f32 -> f32 + %0 = spv.GLSL.FMix %x : vector<4xf32>, %y : vector<4xf32>, %a : vector<4xf32> -> vector<4xf32> + ``` + }]; + + let arguments = (ins + SPV_ScalarOrVectorOf:$x, + SPV_ScalarOrVectorOf:$y, + SPV_ScalarOrVectorOf:$a + ); + + let results = (outs + SPV_ScalarOrVectorOf:$result + ); + + let assemblyFormat = [{ + attr-dict $x `:` type($x) `,` $y `:` type($y) `,` $a `:` type($a) `->` type($result) + }]; + + let verifier = [{ return success(); }]; +} #endif // MLIR_DIALECT_SPIRV_IR_GLSL_OPS diff --git a/mlir/test/Dialect/SPIRV/IR/glsl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/glsl-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/glsl-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/glsl-ops.mlir @@ -463,3 +463,23 @@ %0 = spv.GLSL.Ldexp %arg0 : vector<3xf32>, %arg1 : vector<2xi32> -> vector<3xf32> return } + +// ----- + +//===----------------------------------------------------------------------===// +// spv.GLSL.FMix +//===----------------------------------------------------------------------===// + +func @fmix(%arg0 : f32, %arg1 : f32, %arg2 : f32) -> () { + // CHECK: {{%.*}} = spv.GLSL.FMix {{%.*}} : f32, {{%.*}} : f32, {{%.*}} : f32 -> f32 + %0 = spv.GLSL.FMix %arg0 : f32, %arg1 : f32, %arg2 : f32 -> f32 + return +} + +// ----- +func @fmix_vector(%arg0 : vector<3xf32>, %arg1 : vector<3xf32>, %arg2 : vector<3xf32>) -> () { + // CHECK: {{%.*}} = spv.GLSL.FMix {{%.*}} : vector<3xf32>, {{%.*}} : vector<3xf32>, {{%.*}} : vector<3xf32> -> vector<3xf32> + %0 = spv.GLSL.FMix %arg0 : vector<3xf32>, %arg1 : vector<3xf32>, %arg2 : vector<3xf32> -> vector<3xf32> + return +} + diff --git a/mlir/test/Target/SPIRV/glsl-ops.mlir b/mlir/test/Target/SPIRV/glsl-ops.mlir --- a/mlir/test/Target/SPIRV/glsl-ops.mlir +++ b/mlir/test/Target/SPIRV/glsl-ops.mlir @@ -32,6 +32,8 @@ %13 = spv.GLSL.FrexpStruct %arg0 : f32 -> !spv.struct<(f32, i32)> // CHECK: {{%.*}} = spv.GLSL.Ldexp {{%.*}} : f32, {{%.*}} : i32 -> f32 %14 = spv.GLSL.Ldexp %arg0 : f32, %arg2 : i32 -> f32 + // CHECK: {{%.*}} = spv.GLSL.FMix {{%.*}} : f32, {{%.*}} : f32, {{%.*}} : f32 -> f32 + %15 = spv.GLSL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32 spv.Return }