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
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
TINT_INSTANTIATE_CLASS_ID(tint::semantic::Intrinsic);
|
|
|
|
|
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
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
std::ostream& operator<<(std::ostream& out, IntrinsicType i) {
|
2021-02-08 22:31:44 +00:00
|
|
|
out << str(i);
|
2021-02-03 21:02:25 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
const char* Intrinsic::str() const {
|
|
|
|
return semantic::str(type_);
|
|
|
|
}
|
2021-02-03 21:02:25 +00:00
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
const char* str(IntrinsicType 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-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kNone:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "<not-an-intrinsic>";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAbs:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "abs";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAcos:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "acos";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAll:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "all";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAny:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "any";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kArrayLength:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "arrayLength";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAsin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "asin";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAtan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "atan";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kAtan2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "atan2";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kCeil:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "ceil";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kClamp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "clamp";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kCos:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cos";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kCosh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cosh";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kCountOneBits:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "countOneBits";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kCross:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "cross";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDeterminant:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "determinant";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDistance:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "distance";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDot:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dot";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdx:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdx";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdxCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdxCoarse";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdxFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdxFine";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdy:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdy";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdyCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdyCoarse";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kDpdyFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "dpdyFine";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kExp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "exp";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kExp2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "exp2";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFaceForward:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "faceForward";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFloor:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "floor";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFma:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fma";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFract:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fract";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFrexp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "frexp";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFwidth:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidth";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFwidthCoarse:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidthCoarse";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kFwidthFine:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "fwidthFine";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kInverseSqrt:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "inverseSqrt";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kIsFinite:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isFinite";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kIsInf:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isInf";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kIsNan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isNan";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kIsNormal:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "isNormal";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kLdexp:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "ldexp";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kLength:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "length";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kLog:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "log";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kLog2:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "log2";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kMax:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "max";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kMin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "min";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kMix:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "mix";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kModf:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "modf";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kNormalize:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "normalize";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPack4x8Snorm:
|
2021-02-04 16:17:49 +00:00
|
|
|
return "pack4x8snorm";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPack4x8Unorm:
|
2021-02-04 16:17:49 +00:00
|
|
|
return "pack4x8unorm";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPack2x16Snorm:
|
2021-02-04 16:17:49 +00:00
|
|
|
return "pack2x16snorm";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPack2x16Unorm:
|
2021-02-04 16:17:49 +00:00
|
|
|
return "pack2x16unorm";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPack2x16Float:
|
2021-02-04 16:17:49 +00:00
|
|
|
return "pack2x16float";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kPow:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "pow";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kReflect:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "reflect";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kReverseBits:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "reverseBits";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kRound:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "round";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSelect:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "select";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSign:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sign";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSin:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sin";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSinh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sinh";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSmoothStep:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "smoothStep";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kSqrt:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "sqrt";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kStep:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "step";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTan:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "tan";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTanh:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "tanh";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureDimensions:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureDimensions";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureLoad:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureLoad";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureNumLayers:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumLayers";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureNumLevels:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumLevels";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureNumSamples:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureNumSamples";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureSample:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSample";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureSampleBias:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleBias";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureSampleCompare:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleCompare";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureSampleGrad:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleGrad";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureSampleLevel:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureSampleLevel";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTextureStore:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "textureStore";
|
2021-02-08 19:53:42 +00:00
|
|
|
case IntrinsicType::kTrunc:
|
2021-02-03 21:02:25 +00:00
|
|
|
return "trunc";
|
2021-02-09 21:23:00 +00:00
|
|
|
case IntrinsicType::kUnpack4x8Snorm:
|
|
|
|
return "unpack4x8snorm";
|
|
|
|
case IntrinsicType::kUnpack4x8Unorm:
|
|
|
|
return "unpack4x8unorm";
|
|
|
|
case IntrinsicType::kUnpack2x16Snorm:
|
|
|
|
return "unpack2x16snorm";
|
|
|
|
case IntrinsicType::kUnpack2x16Unorm:
|
|
|
|
return "unpack2x16unorm";
|
|
|
|
case IntrinsicType::kUnpack2x16Float:
|
|
|
|
return "unpack2x16float";
|
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
|
|
|
}
|
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
bool IsCoarseDerivativeIntrinsic(IntrinsicType i) {
|
2021-02-08 19:53:42 +00:00
|
|
|
return i == IntrinsicType::kDpdxCoarse || i == IntrinsicType::kDpdyCoarse ||
|
|
|
|
i == IntrinsicType::kFwidthCoarse;
|
2020-06-04 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
bool IsFineDerivativeIntrinsic(IntrinsicType i) {
|
2021-02-08 19:53:42 +00:00
|
|
|
return i == IntrinsicType::kDpdxFine || i == IntrinsicType::kDpdyFine ||
|
|
|
|
i == IntrinsicType::kFwidthFine;
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
bool IsDerivativeIntrinsic(IntrinsicType i) {
|
2021-02-08 19:53:42 +00:00
|
|
|
return i == IntrinsicType::kDpdx || i == IntrinsicType::kDpdy ||
|
2021-02-08 22:31:44 +00:00
|
|
|
i == IntrinsicType::kFwidth || IsCoarseDerivativeIntrinsic(i) ||
|
|
|
|
IsFineDerivativeIntrinsic(i);
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
bool IsFloatClassificationIntrinsic(IntrinsicType i) {
|
|
|
|
return i == IntrinsicType::kIsFinite || i == IntrinsicType::kIsInf ||
|
|
|
|
i == IntrinsicType::kIsNan || i == IntrinsicType::kIsNormal;
|
2020-08-31 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
bool IsTextureIntrinsic(IntrinsicType i) {
|
|
|
|
return IsImageQueryIntrinsic(i) || i == IntrinsicType::kTextureLoad ||
|
|
|
|
i == IntrinsicType::kTextureSample ||
|
|
|
|
i == IntrinsicType::kTextureSampleLevel ||
|
|
|
|
i == IntrinsicType::kTextureSampleBias ||
|
|
|
|
i == IntrinsicType::kTextureSampleCompare ||
|
|
|
|
i == IntrinsicType::kTextureSampleGrad ||
|
|
|
|
i == IntrinsicType::kTextureStore;
|
2020-06-04 17:05:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
bool IsImageQueryIntrinsic(IntrinsicType i) {
|
2021-02-08 22:31:44 +00:00
|
|
|
return i == IntrinsicType::kTextureDimensions ||
|
2021-02-08 19:53:42 +00:00
|
|
|
i == IntrinsicType::kTextureNumLayers ||
|
|
|
|
i == IntrinsicType::kTextureNumLevels ||
|
|
|
|
i == IntrinsicType::kTextureNumSamples;
|
2021-01-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
bool IsDataPackingIntrinsic(IntrinsicType i) {
|
|
|
|
return i == IntrinsicType::kPack4x8Snorm ||
|
|
|
|
i == IntrinsicType::kPack4x8Unorm ||
|
|
|
|
i == IntrinsicType::kPack2x16Snorm ||
|
|
|
|
i == IntrinsicType::kPack2x16Unorm ||
|
|
|
|
i == IntrinsicType::kPack2x16Float;
|
2021-02-04 16:17:49 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 21:23:00 +00:00
|
|
|
bool IsDataUnpackingIntrinsic(IntrinsicType i) {
|
|
|
|
return i == IntrinsicType::kUnpack4x8Snorm ||
|
|
|
|
i == IntrinsicType::kUnpack4x8Unorm ||
|
|
|
|
i == IntrinsicType::kUnpack2x16Snorm ||
|
|
|
|
i == IntrinsicType::kUnpack2x16Unorm ||
|
|
|
|
i == IntrinsicType::kUnpack2x16Float;
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
Intrinsic::Intrinsic(IntrinsicType type,
|
|
|
|
type::Type* return_type,
|
2021-02-09 15:37:44 +00:00
|
|
|
const ParameterList& parameters)
|
2021-02-08 22:31:44 +00:00
|
|
|
: Base(return_type, parameters), type_(type) {}
|
|
|
|
|
|
|
|
Intrinsic::~Intrinsic() = default;
|
|
|
|
|
|
|
|
bool Intrinsic::IsCoarseDerivative() const {
|
|
|
|
return IsCoarseDerivativeIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsFineDerivative() const {
|
|
|
|
return IsFineDerivativeIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsDerivative() const {
|
|
|
|
return IsDerivativeIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsFloatClassification() const {
|
|
|
|
return IsFloatClassificationIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsTexture() const {
|
|
|
|
return IsTextureIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsImageQuery() const {
|
|
|
|
return IsImageQueryIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intrinsic::IsDataPacking() const {
|
|
|
|
return IsDataPackingIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:23:00 +00:00
|
|
|
bool Intrinsic::IsDataUnpacking() const {
|
|
|
|
return IsDataUnpackingIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:02:25 +00:00
|
|
|
} // namespace semantic
|
2020-06-04 17:05:35 +00:00
|
|
|
} // namespace tint
|