Skip to content

Commit 02974a6

Browse files
committed
initial
1 parent dfa5ee2 commit 02974a6

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,108 @@ def SPIRV_GLFMixOp :
10291029
let hasVerifier = 0;
10301030
}
10311031

1032+
// -----
1033+
1034+
def SPIRV_GLDistanceOp : SPIRV_GLOp<"Distance", 67, [Pure]> {
1035+
let summary = "Return distance between two points";
1036+
1037+
let description = [{
1038+
Result is the distance between x and y. This is |x - y|, where |x| is the
1039+
length of x computed as sqrt(x * x).
1040+
1041+
The operands must all be vectors whose component type is floating-point.
1042+
Result Type must be a scalar floating-point type.
1043+
1044+
#### Example:
1045+
1046+
```mlir
1047+
%2 = spirv.GL.Distance %0, %1 : vector<3xf32>, vector<3xf32> -> f32
1048+
```
1049+
}];
1050+
1051+
let arguments = (ins
1052+
SPIRV_ScalarOrVectorOf<SPIRV_Float>:$p0,
1053+
SPIRV_ScalarOrVectorOf<SPIRV_Float>:$p1
1054+
);
1055+
1056+
let results = (outs
1057+
SPIRV_Float:$result
1058+
);
1059+
1060+
let assemblyFormat = [{
1061+
operands attr-dict `:` type($p0) `,` type($p1) `->` type($result)
1062+
}];
1063+
}
1064+
1065+
// -----
1066+
1067+
def SPIRV_GLCrossOp : SPIRV_GLBinaryArithmeticOp<"Cross", 68, SPIRV_Float> {
1068+
let summary = "Return the cross product of two 3-component vectors";
1069+
1070+
let description = [{
1071+
Result is the cross product of x and y, i.e. dot(x,y).
1072+
1073+
Arguments x and y must be vectors of size 3, of floating-point type.
1074+
Results are computed per component.
1075+
The result is a vector of the same type as the inputs.
1076+
1077+
#### Example:
1078+
1079+
```mlir
1080+
%2 = spirv.GL.Cross %0, %1 : vector<3xf32>
1081+
%3 = spirv.GL.Cross %0, %1 : vector<3xf16>
1082+
```
1083+
}];
1084+
}
1085+
1086+
// -----
1087+
1088+
def SPIRV_GLNormalizeOp : SPIRV_GLUnaryArithmeticOp<"Normalize", 69, SPIRV_Float> {
1089+
let summary = "Normalizes a vector operand";
1090+
1091+
let description = [{
1092+
Result is the vector v/sqrt(dot(v,v)).
1093+
The result is undefined if dot(v,v) is less than or equal to 0.
1094+
1095+
The operand v must be a vector whose component type is floating-point.
1096+
The Result Type must be the same type as v.
1097+
Results are computed per component.
1098+
1099+
#### Example:
1100+
1101+
```mlir
1102+
%2 = spirv.GL.Normalize %0 : vector<3xf32>
1103+
%3 = spirv.GL.Normalize %1 : vector<4xf16>
1104+
```
1105+
}];
1106+
}
1107+
1108+
// -----
1109+
1110+
def SPIRV_GLReflectOp : SPIRV_GLBinaryArithmeticOp<"Reflect", 71, SPIRV_Float> {
1111+
let summary = "Calculate reflection direction vector";
1112+
1113+
let description = [{
1114+
Result is the reflection direction vector: I - 2 * dot(N, I) * N, where I is
1115+
the incident vector and N is the surface orientation vector.
1116+
1117+
N must be normalized to achieve the desired result.
1118+
1119+
The operands must all be a scalar or vector whose component type is floating-point.
1120+
Result Type and the type of all operands must be the same type.
1121+
Results are computed per component.
1122+
1123+
#### Example:
1124+
1125+
```mlir
1126+
%2 = spirv.GL.Reflect %0, %1 : f32
1127+
%3 = spirv.GL.Reflect %0, %1 : vector<3xf32>
1128+
```
1129+
}];
1130+
}
1131+
1132+
// ----
1133+
10321134
def SPIRV_GLFindUMsbOp : SPIRV_GLUnaryArithmeticOp<"FindUMsb", 75, SPIRV_Int32> {
10331135
let summary = "Unsigned-integer most-significant bit";
10341136

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,3 +2094,30 @@ LogicalResult spirv::VectorTimesScalarOp::verify() {
20942094
return emitOpError("scalar operand and result element type match");
20952095
return success();
20962096
}
2097+
2098+
//===----------------------------------------------------------------------===//
2099+
// spirv.GLDistanceOp
2100+
//===----------------------------------------------------------------------===//
2101+
2102+
LogicalResult spirv::GLDistanceOp::verify() {
2103+
auto p0Type = getP0().getType();
2104+
auto p1Type = getP1().getType();
2105+
auto resultType = getResult().getType();
2106+
2107+
auto p0VectorType = p0Type.dyn_cast<VectorType>();
2108+
auto p1VectorType = p1Type.dyn_cast<VectorType>();
2109+
if (!p0VectorType || !p1VectorType)
2110+
return emitOpError("operands must be vectors");
2111+
2112+
if (p0VectorType.getShape() != p1VectorType.getShape())
2113+
return emitOpError("operands must have same shape");
2114+
2115+
if (!resultType.isa<FloatType>())
2116+
return emitOpError("result must be scalar float");
2117+
2118+
if (p0VectorType.getElementType() != resultType ||
2119+
p1VectorType.getElementType() != resultType)
2120+
return emitOpError("operand vector elements must match result type");
2121+
2122+
return success();
2123+
}

0 commit comments

Comments
 (0)