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.
|
|
|
|
|
|
|
|
#include "src/ast/intrinsic.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
|
2020-09-22 19:42:13 +00:00
|
|
|
std::ostream& operator<<(std::ostream& out, 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:
|
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAbs:
|
|
|
|
out << "abs";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAcos:
|
|
|
|
out << "acos";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAll:
|
|
|
|
out << "all";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAny:
|
|
|
|
out << "any";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-10-08 17:01:55 +00:00
|
|
|
case Intrinsic::kArrayLength:
|
|
|
|
out << "arrayLength";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAsin:
|
|
|
|
out << "asin";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAtan:
|
|
|
|
out << "atan";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kAtan2:
|
|
|
|
out << "atan2";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCeil:
|
|
|
|
out << "ceil";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kClamp:
|
|
|
|
out << "clamp";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCos:
|
|
|
|
out << "cos";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCosh:
|
|
|
|
out << "cosh";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCountOneBits:
|
|
|
|
out << "countOneBits";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kCross:
|
|
|
|
out << "cross";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDeterminant:
|
|
|
|
out << "determinant";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDistance:
|
|
|
|
out << "distance";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDot:
|
|
|
|
out << "dot";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdx:
|
|
|
|
out << "dpdx";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdxCoarse:
|
|
|
|
out << "dpdxCoarse";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdxFine:
|
|
|
|
out << "dpdxFine";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdy:
|
|
|
|
out << "dpdy";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdyCoarse:
|
|
|
|
out << "dpdyCoarse";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kDpdyFine:
|
|
|
|
out << "dpdyFine";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kExp:
|
|
|
|
out << "exp";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kExp2:
|
|
|
|
out << "exp2";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFaceForward:
|
|
|
|
out << "faceForward";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFloor:
|
|
|
|
out << "floor";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFma:
|
|
|
|
out << "fma";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFract:
|
|
|
|
out << "fract";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFrexp:
|
|
|
|
out << "frexp";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidth:
|
|
|
|
out << "fwidth";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidthCoarse:
|
|
|
|
out << "fwidthCoarse";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kFwidthFine:
|
|
|
|
out << "fwidthFine";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kInverseSqrt:
|
|
|
|
out << "inverseSqrt";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsFinite:
|
|
|
|
out << "isFinite";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsInf:
|
|
|
|
out << "isInf";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsNan:
|
|
|
|
out << "isNan";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kIsNormal:
|
|
|
|
out << "isNormal";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLdexp:
|
|
|
|
out << "ldexp";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLength:
|
|
|
|
out << "length";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLog:
|
|
|
|
out << "log";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kLog2:
|
|
|
|
out << "log2";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMax:
|
|
|
|
out << "max";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMin:
|
|
|
|
out << "min";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kMix:
|
|
|
|
out << "mix";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kModf:
|
|
|
|
out << "modf";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kNormalize:
|
|
|
|
out << "normalize";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kPow:
|
|
|
|
out << "pow";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kReflect:
|
|
|
|
out << "reflect";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kReverseBits:
|
|
|
|
out << "reverseBits";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kRound:
|
|
|
|
out << "round";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSelect:
|
|
|
|
out << "select";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSign:
|
|
|
|
out << "sign";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSin:
|
|
|
|
out << "sin";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSinh:
|
|
|
|
out << "sinh";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSmoothStep:
|
|
|
|
out << "smoothStep";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kSqrt:
|
|
|
|
out << "sqrt";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kStep:
|
|
|
|
out << "step";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTan:
|
|
|
|
out << "tan";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTanh:
|
|
|
|
out << "tanh";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
|
|
|
case Intrinsic::kTextureDimensions:
|
|
|
|
out << "textureDimensions";
|
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureLoad:
|
|
|
|
out << "textureLoad";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
|
|
|
case Intrinsic::kTextureNumLayers:
|
|
|
|
out << "textureNumLayers";
|
|
|
|
return out;
|
2021-01-14 18:06:57 +00:00
|
|
|
case Intrinsic::kTextureNumLevels:
|
|
|
|
out << "textureNumLevels";
|
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSample:
|
|
|
|
out << "textureSample";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleBias:
|
|
|
|
out << "textureSampleBias";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleCompare:
|
|
|
|
out << "textureSampleCompare";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-11-18 21:19:22 +00:00
|
|
|
case Intrinsic::kTextureSampleGrad:
|
|
|
|
out << "textureSampleGrad";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTextureSampleLevel:
|
|
|
|
out << "textureSampleLevel";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
|
|
|
case Intrinsic::kTextureStore:
|
|
|
|
out << "textureStore";
|
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
case Intrinsic::kTrunc:
|
|
|
|
out << "trunc";
|
2021-01-14 16:50:07 +00:00
|
|
|
return out;
|
2020-09-22 19:42:13 +00:00
|
|
|
}
|
2021-01-14 16:50:07 +00:00
|
|
|
out << "Unknown";
|
2020-09-22 19:42:13 +00:00
|
|
|
return out;
|
2020-06-04 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 19:42:13 +00:00
|
|
|
namespace intrinsic {
|
|
|
|
|
2020-11-18 21:19:22 +00:00
|
|
|
Signature::~Signature() = default;
|
|
|
|
TextureSignature::~TextureSignature() = default;
|
|
|
|
|
|
|
|
TextureSignature::Parameters::Index::Index() = default;
|
|
|
|
TextureSignature::Parameters::Index::Index(const Index&) = default;
|
|
|
|
|
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-01-14 16:50:07 +00:00
|
|
|
return i == ast::Intrinsic::kTextureDimensions ||
|
2021-01-14 18:06:57 +00:00
|
|
|
i == Intrinsic::kTextureNumLayers || i == Intrinsic::kTextureNumLevels;
|
2021-01-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 17:05:35 +00:00
|
|
|
} // namespace intrinsic
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|