2020-06-04 17:05:35 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-02-03 21:02:25 +00:00
|
|
|
#include "src/semantic/intrinsic.h"
|
2020-06-04 17:05:35 +00:00
|
|
|
|
|
|
|
namespace tint {
|
2021-02-03 21:02:25 +00:00
|
|
|
namespace semantic {
|
2020-06-04 17:05:35 +00:00
|
|
|
|
2020-09-22 19:42:13 +00:00
|
|
|
std::ostream& operator<<(std::ostream& out, Intrinsic i) {
|
2021-02-03 21:02:25 +00:00
|
|
|
out << intrinsic::str(i);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace intrinsic {
|
|
|
|
|
|
|
|
const char* str(Intrinsic i) {
|
2020-11-11 14:30:25 +00:00
|
|
|
/// The emitted name matches the spelling in the WGSL spec.
|
|
|
|
/// including case.
|
2020-09-22 19:42:13 +00:00
|
|
|
switch (i) {
|
2021-01-14 16:50:07 +00:00
|
|
|
case Intrinsic::kNone:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "<not-an-intrinsic>";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAbs:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "abs";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAcos:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "acos";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAll:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "all";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAny:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "any";
|
2020-10-08 17:01:55 +00:00
|
|
|
case Intrinsic::kArrayLength:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "arrayLength";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAsin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "asin";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAtan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "atan";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAtan2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "atan2";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCeil:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "ceil";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kClamp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "clamp";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCos:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cos";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCosh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cosh";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCountOneBits:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "countOneBits";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCross:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cross";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDeterminant:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "determinant";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDistance:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "distance";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDot:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dot";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdx:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdx";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdxCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdxCoarse";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdxFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdxFine";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdy:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdy";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdyCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdyCoarse";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdyFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdyFine";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kExp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "exp";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kExp2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "exp2";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFaceForward:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "faceForward";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFloor:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "floor";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFma:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fma";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFract:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fract";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFrexp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "frexp";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidth:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidth";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidthCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidthCoarse";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidthFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidthFine";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kInverseSqrt:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "inverseSqrt";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsFinite:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isFinite";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsInf:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isInf";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsNan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isNan";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsNormal:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isNormal";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLdexp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "ldexp";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLength:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "length";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLog:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "log";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLog2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "log2";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMax:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "max";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "min";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMix:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "mix";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kModf:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "modf";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kNormalize:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "normalize";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kPow:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "pow";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kReflect:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "reflect";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kReverseBits:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "reverseBits";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kRound:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "round";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSelect:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "select";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSign:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sign";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sin";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSinh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sinh";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSmoothStep:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "smoothStep";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSqrt:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sqrt";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kStep:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "step";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "tan";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTanh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "tanh";
|
2021-01-14 16:50:07 +00:00
|
|
|
case Intrinsic::kTextureDimensions:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureDimensions";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureLoad:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureLoad";
|
2021-01-14 16:50:07 +00:00
|
|
|
case Intrinsic::kTextureNumLayers:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumLayers";
|
2021-01-14 18:06:57 +00:00
|
|
|
case Intrinsic::kTextureNumLevels:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumLevels";
|
2021-01-14 18:11:17 +00:00
|
|
|
case Intrinsic::kTextureNumSamples:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumSamples";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSample:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSample";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleBias:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleBias";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleCompare:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleCompare";
|
2020-11-18 21:19:22 +00:00
|
|
|
case Intrinsic::kTextureSampleGrad:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleGrad";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleLevel:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleLevel";
|
2021-01-14 16:50:07 +00:00
|
|
|
case Intrinsic::kTextureStore:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureStore";
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTrunc:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "trunc";
|
2020-09-22 19:42:13 +00:00
|
|
|
}
|
2021-02-03 21:02:25 +00:00
|
|
|
return "<unknown>";
|
2020-06-04 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
bool IsCoarseDerivative(Intrinsic i) {
|
2020-09-26 02:00:53 +00:00
|
|
|
return i == Intrinsic::kDpdxCoarse || i == Intrinsic::kDpdyCoarse ||
|
|
|
|
i == Intrinsic::kFwidthCoarse;
|
2020-06-04 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
bool IsFineDerivative(Intrinsic i) {
|
2020-09-22 19:42:13 +00:00
|
|
|
return i == Intrinsic::kDpdxFine || i == Intrinsic::kDpdyFine ||
|
|
|
|
i == Intrinsic::kFwidthFine;
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
bool IsDerivative(Intrinsic i) {
|
2020-09-22 19:42:13 +00:00
|
|
|
return i == Intrinsic::kDpdx || i == Intrinsic::kDpdy ||
|
|
|
|
i == Intrinsic::kFwidth || IsCoarseDerivative(i) ||
|
|
|
|
IsFineDerivative(i);
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
bool IsFloatClassificationIntrinsic(Intrinsic i) {
|
2020-09-22 19:42:13 +00:00
|
|
|
return i == Intrinsic::kIsFinite || i == Intrinsic::kIsInf ||
|
|
|
|
i == Intrinsic::kIsNan || i == Intrinsic::kIsNormal;
|
2020-08-31 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
bool IsTextureIntrinsic(Intrinsic i) {
|
2021-01-14 18:06:57 +00:00
|
|
|
return IsImageQueryIntrinsic(i) || i == Intrinsic::kTextureLoad ||
|
|
|
|
i == Intrinsic::kTextureSample ||
|
2020-09-22 19:42:13 +00:00
|
|
|
i == Intrinsic::kTextureSampleLevel ||
|
|
|
|
i == Intrinsic::kTextureSampleBias ||
|
2020-11-18 21:19:22 +00:00
|
|
|
i == Intrinsic::kTextureSampleCompare ||
|
2020-12-10 18:39:41 +00:00
|
|
|
i == Intrinsic::kTextureSampleGrad || i == Intrinsic::kTextureStore;
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 21:07:32 +00:00
|
|
|
bool IsImageQueryIntrinsic(Intrinsic i) {
|
2021-02-03 21:02:25 +00:00
|
|
|
return i == semantic::Intrinsic::kTextureDimensions ||
|
2021-01-14 18:11:17 +00:00
|
|
|
i == Intrinsic::kTextureNumLayers ||
|
|
|
|
i == Intrinsic::kTextureNumLevels ||
|
|
|
|
i == Intrinsic::kTextureNumSamples;
|
2021-01-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 17:05:35 +00:00
|
|
|
} // namespace intrinsic
|
2021-02-03 21:02:25 +00:00
|
|
|
} // namespace semantic
|
2020-06-04 17:05:35 +00:00
|
|
|
} // namespace tint
|