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-03-02 20:51:18 +00:00
|
|
|
TINT_INSTANTIATE_TYPEINFO(tint::semantic::Intrinsic);
|
2021-02-08 22:31:44 +00:00
|
|
|
|
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-03-19 16:45:10 +00:00
|
|
|
/// Name matches the spelling in the WGSL spec including case.
|
|
|
|
#define INTRINSIC_LIST() \
|
|
|
|
INTRINSIC(IntrinsicType::kNone, "<not-an-intrinsic>") \
|
|
|
|
INTRINSIC(IntrinsicType::kAbs, "abs") \
|
|
|
|
INTRINSIC(IntrinsicType::kAcos, "acos") \
|
|
|
|
INTRINSIC(IntrinsicType::kAll, "all") \
|
|
|
|
INTRINSIC(IntrinsicType::kAny, "any") \
|
|
|
|
INTRINSIC(IntrinsicType::kArrayLength, "arrayLength") \
|
|
|
|
INTRINSIC(IntrinsicType::kAsin, "asin") \
|
|
|
|
INTRINSIC(IntrinsicType::kAtan, "atan") \
|
|
|
|
INTRINSIC(IntrinsicType::kAtan2, "atan2") \
|
|
|
|
INTRINSIC(IntrinsicType::kCeil, "ceil") \
|
|
|
|
INTRINSIC(IntrinsicType::kClamp, "clamp") \
|
|
|
|
INTRINSIC(IntrinsicType::kCos, "cos") \
|
|
|
|
INTRINSIC(IntrinsicType::kCosh, "cosh") \
|
|
|
|
INTRINSIC(IntrinsicType::kCountOneBits, "countOneBits") \
|
|
|
|
INTRINSIC(IntrinsicType::kCross, "cross") \
|
|
|
|
INTRINSIC(IntrinsicType::kDeterminant, "determinant") \
|
|
|
|
INTRINSIC(IntrinsicType::kDistance, "distance") \
|
|
|
|
INTRINSIC(IntrinsicType::kDot, "dot") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdx, "dpdx") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdxCoarse, "dpdxCoarse") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdxFine, "dpdxFine") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdy, "dpdy") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdyCoarse, "dpdyCoarse") \
|
|
|
|
INTRINSIC(IntrinsicType::kDpdyFine, "dpdyFine") \
|
|
|
|
INTRINSIC(IntrinsicType::kExp, "exp") \
|
|
|
|
INTRINSIC(IntrinsicType::kExp2, "exp2") \
|
|
|
|
INTRINSIC(IntrinsicType::kFaceForward, "faceForward") \
|
|
|
|
INTRINSIC(IntrinsicType::kFloor, "floor") \
|
|
|
|
INTRINSIC(IntrinsicType::kFma, "fma") \
|
|
|
|
INTRINSIC(IntrinsicType::kFract, "fract") \
|
|
|
|
INTRINSIC(IntrinsicType::kFrexp, "frexp") \
|
|
|
|
INTRINSIC(IntrinsicType::kFwidth, "fwidth") \
|
|
|
|
INTRINSIC(IntrinsicType::kFwidthCoarse, "fwidthCoarse") \
|
|
|
|
INTRINSIC(IntrinsicType::kFwidthFine, "fwidthFine") \
|
|
|
|
INTRINSIC(IntrinsicType::kInverseSqrt, "inverseSqrt") \
|
|
|
|
INTRINSIC(IntrinsicType::kIsFinite, "isFinite") \
|
|
|
|
INTRINSIC(IntrinsicType::kIsInf, "isInf") \
|
|
|
|
INTRINSIC(IntrinsicType::kIsNan, "isNan") \
|
|
|
|
INTRINSIC(IntrinsicType::kIsNormal, "isNormal") \
|
|
|
|
INTRINSIC(IntrinsicType::kLdexp, "ldexp") \
|
|
|
|
INTRINSIC(IntrinsicType::kLength, "length") \
|
|
|
|
INTRINSIC(IntrinsicType::kLog, "log") \
|
|
|
|
INTRINSIC(IntrinsicType::kLog2, "log2") \
|
|
|
|
INTRINSIC(IntrinsicType::kMax, "max") \
|
|
|
|
INTRINSIC(IntrinsicType::kMin, "min") \
|
|
|
|
INTRINSIC(IntrinsicType::kMix, "mix") \
|
|
|
|
INTRINSIC(IntrinsicType::kModf, "modf") \
|
|
|
|
INTRINSIC(IntrinsicType::kNormalize, "normalize") \
|
|
|
|
INTRINSIC(IntrinsicType::kPack4x8Snorm, "pack4x8snorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kPack4x8Unorm, "pack4x8unorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kPack2x16Snorm, "pack2x16snorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kPack2x16Unorm, "pack2x16unorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kPack2x16Float, "pack2x16float") \
|
|
|
|
INTRINSIC(IntrinsicType::kPow, "pow") \
|
|
|
|
INTRINSIC(IntrinsicType::kReflect, "reflect") \
|
|
|
|
INTRINSIC(IntrinsicType::kReverseBits, "reverseBits") \
|
|
|
|
INTRINSIC(IntrinsicType::kRound, "round") \
|
|
|
|
INTRINSIC(IntrinsicType::kSelect, "select") \
|
|
|
|
INTRINSIC(IntrinsicType::kSign, "sign") \
|
|
|
|
INTRINSIC(IntrinsicType::kSin, "sin") \
|
|
|
|
INTRINSIC(IntrinsicType::kSinh, "sinh") \
|
|
|
|
INTRINSIC(IntrinsicType::kSmoothStep, "smoothStep") \
|
|
|
|
INTRINSIC(IntrinsicType::kSqrt, "sqrt") \
|
|
|
|
INTRINSIC(IntrinsicType::kStep, "step") \
|
2021-03-22 19:27:06 +00:00
|
|
|
INTRINSIC(IntrinsicType::kStorageBarrier, "storageBarrier") \
|
2021-03-19 16:45:10 +00:00
|
|
|
INTRINSIC(IntrinsicType::kTan, "tan") \
|
|
|
|
INTRINSIC(IntrinsicType::kTanh, "tanh") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureDimensions, "textureDimensions") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureLoad, "textureLoad") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureNumLayers, "textureNumLayers") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureNumLevels, "textureNumLevels") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureNumSamples, "textureNumSamples") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureSample, "textureSample") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureSampleBias, "textureSampleBias") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureSampleCompare, "textureSampleCompare") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureSampleGrad, "textureSampleGrad") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureSampleLevel, "textureSampleLevel") \
|
|
|
|
INTRINSIC(IntrinsicType::kTextureStore, "textureStore") \
|
|
|
|
INTRINSIC(IntrinsicType::kTrunc, "trunc") \
|
|
|
|
INTRINSIC(IntrinsicType::kUnpack2x16Float, "unpack2x16float") \
|
|
|
|
INTRINSIC(IntrinsicType::kUnpack2x16Snorm, "unpack2x16snorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kUnpack2x16Unorm, "unpack2x16unorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kUnpack4x8Snorm, "unpack4x8snorm") \
|
2021-03-22 19:27:06 +00:00
|
|
|
INTRINSIC(IntrinsicType::kUnpack4x8Unorm, "unpack4x8unorm") \
|
|
|
|
INTRINSIC(IntrinsicType::kWorkgroupBarrier, "workgroupBarrier")
|
2021-03-19 16:45:10 +00:00
|
|
|
|
2021-03-04 23:00:46 +00:00
|
|
|
IntrinsicType ParseIntrinsicType(const std::string& name) {
|
2021-03-19 16:45:10 +00:00
|
|
|
#define INTRINSIC(ENUM, NAME) \
|
|
|
|
if (name == NAME) { \
|
|
|
|
return ENUM; \
|
2021-03-04 23:00:46 +00:00
|
|
|
}
|
2021-03-19 16:45:10 +00:00
|
|
|
INTRINSIC_LIST()
|
|
|
|
#undef INTRINSIC
|
2021-03-04 23:00:46 +00:00
|
|
|
return IntrinsicType::kNone;
|
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:42 +00:00
|
|
|
const char* str(IntrinsicType i) {
|
2021-03-19 16:45:10 +00:00
|
|
|
#define INTRINSIC(ENUM, NAME) \
|
|
|
|
case ENUM: \
|
|
|
|
return NAME;
|
|
|
|
switch (i) { INTRINSIC_LIST() }
|
|
|
|
#undef INTRINSIC
|
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-03-22 19:27:06 +00:00
|
|
|
bool IsBarrierIntrinsic(IntrinsicType i) {
|
|
|
|
return i == IntrinsicType::kWorkgroupBarrier ||
|
|
|
|
i == IntrinsicType::kStorageBarrier;
|
|
|
|
}
|
|
|
|
|
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-03-22 19:27:06 +00:00
|
|
|
bool Intrinsic::IsBarrier() const {
|
|
|
|
return IsBarrierIntrinsic(type_);
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:02:25 +00:00
|
|
|
} // namespace semantic
|
2020-06-04 17:05:35 +00:00
|
|
|
} // namespace tint
|