src/sem: Generate IntrinsicType from intrinsics.def

Add a template file to generate intrinsic_type.h and
intrinsic_type.cc when using tools/intrinsic-gen

Bug: tint:832
Change-Id: I35ddfd497d6ab424dc49a18a9fd7e5eb7f8363b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/52643
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-06-01 09:55:00 +00:00
committed by Tint LUCI CQ
parent 131cbcc6af
commit 21f8772d65
16 changed files with 772 additions and 307 deletions

View File

@@ -28,113 +28,6 @@ const char* Intrinsic::str() const {
return sem::str(type_);
}
/// 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") \
INTRINSIC(IntrinsicType::kStorageBarrier, "storageBarrier") \
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") \
INTRINSIC(IntrinsicType::kUnpack4x8Unorm, "unpack4x8unorm") \
INTRINSIC(IntrinsicType::kWorkgroupBarrier, "workgroupBarrier")
IntrinsicType ParseIntrinsicType(const std::string& name) {
#define INTRINSIC(ENUM, NAME) \
if (name == NAME) { \
return ENUM; \
}
INTRINSIC_LIST()
#undef INTRINSIC
return IntrinsicType::kNone;
}
const char* str(IntrinsicType i) {
#define INTRINSIC(ENUM, NAME) \
case ENUM: \
return NAME;
switch (i) { INTRINSIC_LIST() }
#undef INTRINSIC
return "<unknown>";
}
bool IsCoarseDerivativeIntrinsic(IntrinsicType i) {
return i == IntrinsicType::kDpdxCoarse || i == IntrinsicType::kDpdyCoarse ||
i == IntrinsicType::kFwidthCoarse;
@@ -174,19 +67,19 @@ bool IsImageQueryIntrinsic(IntrinsicType i) {
}
bool IsDataPackingIntrinsic(IntrinsicType i) {
return i == IntrinsicType::kPack4x8Snorm ||
i == IntrinsicType::kPack4x8Unorm ||
i == IntrinsicType::kPack2x16Snorm ||
i == IntrinsicType::kPack2x16Unorm ||
i == IntrinsicType::kPack2x16Float;
return i == IntrinsicType::kPack4x8snorm ||
i == IntrinsicType::kPack4x8unorm ||
i == IntrinsicType::kPack2x16snorm ||
i == IntrinsicType::kPack2x16unorm ||
i == IntrinsicType::kPack2x16float;
}
bool IsDataUnpackingIntrinsic(IntrinsicType i) {
return i == IntrinsicType::kUnpack4x8Snorm ||
i == IntrinsicType::kUnpack4x8Unorm ||
i == IntrinsicType::kUnpack2x16Snorm ||
i == IntrinsicType::kUnpack2x16Unorm ||
i == IntrinsicType::kUnpack2x16Float;
return i == IntrinsicType::kUnpack4x8snorm ||
i == IntrinsicType::kUnpack4x8unorm ||
i == IntrinsicType::kUnpack2x16snorm ||
i == IntrinsicType::kUnpack2x16unorm ||
i == IntrinsicType::kUnpack2x16float;
}
bool IsBarrierIntrinsic(IntrinsicType i) {

View File

@@ -18,109 +18,11 @@
#include <string>
#include "src/sem/call_target.h"
#include "src/sem/intrinsic_type.h"
namespace tint {
namespace sem {
enum class IntrinsicType {
kNone = -1,
kAbs,
kAcos,
kAll,
kAny,
kArrayLength,
kAsin,
kAtan,
kAtan2,
kCeil,
kClamp,
kCos,
kCosh,
kCountOneBits,
kCross,
kDeterminant,
kDistance,
kDot,
kDpdx,
kDpdxCoarse,
kDpdxFine,
kDpdy,
kDpdyCoarse,
kDpdyFine,
kExp,
kExp2,
kFaceForward,
kFloor,
kFma,
kFract,
kFrexp,
kFwidth,
kFwidthCoarse,
kFwidthFine,
kInverseSqrt,
kIsFinite,
kIsInf,
kIsNan,
kIsNormal,
kLdexp,
kLength,
kLog,
kLog2,
kMax,
kMin,
kMix,
kModf,
kNormalize,
kPack2x16Float,
kPack2x16Snorm,
kPack2x16Unorm,
kPack4x8Snorm,
kPack4x8Unorm,
kPow,
kReflect,
kReverseBits,
kRound,
kSelect,
kSign,
kSin,
kSinh,
kSmoothStep,
kSqrt,
kStep,
kStorageBarrier,
kTan,
kTanh,
kTextureDimensions,
kTextureLoad,
kTextureNumLayers,
kTextureNumLevels,
kTextureNumSamples,
kTextureSample,
kTextureSampleBias,
kTextureSampleCompare,
kTextureSampleGrad,
kTextureSampleLevel,
kTextureStore,
kTrunc,
kUnpack2x16Float,
kUnpack2x16Snorm,
kUnpack2x16Unorm,
kUnpack4x8Snorm,
kUnpack4x8Unorm,
kWorkgroupBarrier,
};
/// Matches the IntrisicType by name
/// @param name the intrinsic name to parse
/// @returns the parsed IntrinsicType, or IntrinsicType::kNone if `name` did not
/// match any intrinsic.
IntrinsicType ParseIntrinsicType(const std::string& name);
/// @returns the name of the intrinsic function type. The spelling, including
/// case, matches the name in the WGSL spec.
const char* str(IntrinsicType i);
/// Determines if the given `i` is a coarse derivative
/// @param i the intrinsic type
/// @returns true if the given derivative is coarse.

View File

@@ -114,11 +114,11 @@ INSTANTIATE_TEST_SUITE_P(
IntrinsicData{"textureSampleGrad", IntrinsicType::kTextureSampleGrad},
IntrinsicData{"textureSampleLevel", IntrinsicType::kTextureSampleLevel},
IntrinsicData{"trunc", IntrinsicType::kTrunc},
IntrinsicData{"unpack2x16float", IntrinsicType::kUnpack2x16Float},
IntrinsicData{"unpack2x16snorm", IntrinsicType::kUnpack2x16Snorm},
IntrinsicData{"unpack2x16unorm", IntrinsicType::kUnpack2x16Unorm},
IntrinsicData{"unpack4x8snorm", IntrinsicType::kUnpack4x8Snorm},
IntrinsicData{"unpack4x8unorm", IntrinsicType::kUnpack4x8Unorm},
IntrinsicData{"unpack2x16float", IntrinsicType::kUnpack2x16float},
IntrinsicData{"unpack2x16snorm", IntrinsicType::kUnpack2x16snorm},
IntrinsicData{"unpack2x16unorm", IntrinsicType::kUnpack2x16unorm},
IntrinsicData{"unpack4x8snorm", IntrinsicType::kUnpack4x8snorm},
IntrinsicData{"unpack4x8unorm", IntrinsicType::kUnpack4x8unorm},
IntrinsicData{"workgroupBarrier", IntrinsicType::kWorkgroupBarrier}));
TEST_F(IntrinsicTypeTest, ParseNoMatch) {

458
src/sem/intrinsic_type.cc Normal file
View File

@@ -0,0 +1,458 @@
// Copyright 2021 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/intrinsic-gen
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/sem/intrinsic_type.h"
namespace tint {
namespace sem {
IntrinsicType ParseIntrinsicType(const std::string& name) {
if (name == "abs") {
return IntrinsicType::kAbs;
}
if (name == "acos") {
return IntrinsicType::kAcos;
}
if (name == "all") {
return IntrinsicType::kAll;
}
if (name == "any") {
return IntrinsicType::kAny;
}
if (name == "arrayLength") {
return IntrinsicType::kArrayLength;
}
if (name == "asin") {
return IntrinsicType::kAsin;
}
if (name == "atan") {
return IntrinsicType::kAtan;
}
if (name == "atan2") {
return IntrinsicType::kAtan2;
}
if (name == "ceil") {
return IntrinsicType::kCeil;
}
if (name == "clamp") {
return IntrinsicType::kClamp;
}
if (name == "cos") {
return IntrinsicType::kCos;
}
if (name == "cosh") {
return IntrinsicType::kCosh;
}
if (name == "countOneBits") {
return IntrinsicType::kCountOneBits;
}
if (name == "cross") {
return IntrinsicType::kCross;
}
if (name == "determinant") {
return IntrinsicType::kDeterminant;
}
if (name == "distance") {
return IntrinsicType::kDistance;
}
if (name == "dot") {
return IntrinsicType::kDot;
}
if (name == "dpdx") {
return IntrinsicType::kDpdx;
}
if (name == "dpdxCoarse") {
return IntrinsicType::kDpdxCoarse;
}
if (name == "dpdxFine") {
return IntrinsicType::kDpdxFine;
}
if (name == "dpdy") {
return IntrinsicType::kDpdy;
}
if (name == "dpdyCoarse") {
return IntrinsicType::kDpdyCoarse;
}
if (name == "dpdyFine") {
return IntrinsicType::kDpdyFine;
}
if (name == "exp") {
return IntrinsicType::kExp;
}
if (name == "exp2") {
return IntrinsicType::kExp2;
}
if (name == "faceForward") {
return IntrinsicType::kFaceForward;
}
if (name == "floor") {
return IntrinsicType::kFloor;
}
if (name == "fma") {
return IntrinsicType::kFma;
}
if (name == "fract") {
return IntrinsicType::kFract;
}
if (name == "frexp") {
return IntrinsicType::kFrexp;
}
if (name == "fwidth") {
return IntrinsicType::kFwidth;
}
if (name == "fwidthCoarse") {
return IntrinsicType::kFwidthCoarse;
}
if (name == "fwidthFine") {
return IntrinsicType::kFwidthFine;
}
if (name == "inverseSqrt") {
return IntrinsicType::kInverseSqrt;
}
if (name == "isFinite") {
return IntrinsicType::kIsFinite;
}
if (name == "isInf") {
return IntrinsicType::kIsInf;
}
if (name == "isNan") {
return IntrinsicType::kIsNan;
}
if (name == "isNormal") {
return IntrinsicType::kIsNormal;
}
if (name == "ldexp") {
return IntrinsicType::kLdexp;
}
if (name == "length") {
return IntrinsicType::kLength;
}
if (name == "log") {
return IntrinsicType::kLog;
}
if (name == "log2") {
return IntrinsicType::kLog2;
}
if (name == "max") {
return IntrinsicType::kMax;
}
if (name == "min") {
return IntrinsicType::kMin;
}
if (name == "mix") {
return IntrinsicType::kMix;
}
if (name == "modf") {
return IntrinsicType::kModf;
}
if (name == "normalize") {
return IntrinsicType::kNormalize;
}
if (name == "pack2x16float") {
return IntrinsicType::kPack2x16float;
}
if (name == "pack2x16snorm") {
return IntrinsicType::kPack2x16snorm;
}
if (name == "pack2x16unorm") {
return IntrinsicType::kPack2x16unorm;
}
if (name == "pack4x8snorm") {
return IntrinsicType::kPack4x8snorm;
}
if (name == "pack4x8unorm") {
return IntrinsicType::kPack4x8unorm;
}
if (name == "pow") {
return IntrinsicType::kPow;
}
if (name == "reflect") {
return IntrinsicType::kReflect;
}
if (name == "reverseBits") {
return IntrinsicType::kReverseBits;
}
if (name == "round") {
return IntrinsicType::kRound;
}
if (name == "select") {
return IntrinsicType::kSelect;
}
if (name == "sign") {
return IntrinsicType::kSign;
}
if (name == "sin") {
return IntrinsicType::kSin;
}
if (name == "sinh") {
return IntrinsicType::kSinh;
}
if (name == "smoothStep") {
return IntrinsicType::kSmoothStep;
}
if (name == "sqrt") {
return IntrinsicType::kSqrt;
}
if (name == "step") {
return IntrinsicType::kStep;
}
if (name == "storageBarrier") {
return IntrinsicType::kStorageBarrier;
}
if (name == "tan") {
return IntrinsicType::kTan;
}
if (name == "tanh") {
return IntrinsicType::kTanh;
}
if (name == "trunc") {
return IntrinsicType::kTrunc;
}
if (name == "unpack2x16float") {
return IntrinsicType::kUnpack2x16float;
}
if (name == "unpack2x16snorm") {
return IntrinsicType::kUnpack2x16snorm;
}
if (name == "unpack2x16unorm") {
return IntrinsicType::kUnpack2x16unorm;
}
if (name == "unpack4x8snorm") {
return IntrinsicType::kUnpack4x8snorm;
}
if (name == "unpack4x8unorm") {
return IntrinsicType::kUnpack4x8unorm;
}
if (name == "workgroupBarrier") {
return IntrinsicType::kWorkgroupBarrier;
}
if (name == "textureDimensions") {
return IntrinsicType::kTextureDimensions;
}
if (name == "textureNumLayers") {
return IntrinsicType::kTextureNumLayers;
}
if (name == "textureNumLevels") {
return IntrinsicType::kTextureNumLevels;
}
if (name == "textureNumSamples") {
return IntrinsicType::kTextureNumSamples;
}
if (name == "textureSample") {
return IntrinsicType::kTextureSample;
}
if (name == "textureSampleBias") {
return IntrinsicType::kTextureSampleBias;
}
if (name == "textureSampleCompare") {
return IntrinsicType::kTextureSampleCompare;
}
if (name == "textureSampleGrad") {
return IntrinsicType::kTextureSampleGrad;
}
if (name == "textureSampleLevel") {
return IntrinsicType::kTextureSampleLevel;
}
if (name == "textureStore") {
return IntrinsicType::kTextureStore;
}
if (name == "textureLoad") {
return IntrinsicType::kTextureLoad;
}
return IntrinsicType::kNone;
}
const char* str(IntrinsicType i) {
switch (i) {
case IntrinsicType::kNone:
return "<none>";
case IntrinsicType::kAbs:
return "abs";
case IntrinsicType::kAcos:
return "acos";
case IntrinsicType::kAll:
return "all";
case IntrinsicType::kAny:
return "any";
case IntrinsicType::kArrayLength:
return "arrayLength";
case IntrinsicType::kAsin:
return "asin";
case IntrinsicType::kAtan:
return "atan";
case IntrinsicType::kAtan2:
return "atan2";
case IntrinsicType::kCeil:
return "ceil";
case IntrinsicType::kClamp:
return "clamp";
case IntrinsicType::kCos:
return "cos";
case IntrinsicType::kCosh:
return "cosh";
case IntrinsicType::kCountOneBits:
return "countOneBits";
case IntrinsicType::kCross:
return "cross";
case IntrinsicType::kDeterminant:
return "determinant";
case IntrinsicType::kDistance:
return "distance";
case IntrinsicType::kDot:
return "dot";
case IntrinsicType::kDpdx:
return "dpdx";
case IntrinsicType::kDpdxCoarse:
return "dpdxCoarse";
case IntrinsicType::kDpdxFine:
return "dpdxFine";
case IntrinsicType::kDpdy:
return "dpdy";
case IntrinsicType::kDpdyCoarse:
return "dpdyCoarse";
case IntrinsicType::kDpdyFine:
return "dpdyFine";
case IntrinsicType::kExp:
return "exp";
case IntrinsicType::kExp2:
return "exp2";
case IntrinsicType::kFaceForward:
return "faceForward";
case IntrinsicType::kFloor:
return "floor";
case IntrinsicType::kFma:
return "fma";
case IntrinsicType::kFract:
return "fract";
case IntrinsicType::kFrexp:
return "frexp";
case IntrinsicType::kFwidth:
return "fwidth";
case IntrinsicType::kFwidthCoarse:
return "fwidthCoarse";
case IntrinsicType::kFwidthFine:
return "fwidthFine";
case IntrinsicType::kInverseSqrt:
return "inverseSqrt";
case IntrinsicType::kIsFinite:
return "isFinite";
case IntrinsicType::kIsInf:
return "isInf";
case IntrinsicType::kIsNan:
return "isNan";
case IntrinsicType::kIsNormal:
return "isNormal";
case IntrinsicType::kLdexp:
return "ldexp";
case IntrinsicType::kLength:
return "length";
case IntrinsicType::kLog:
return "log";
case IntrinsicType::kLog2:
return "log2";
case IntrinsicType::kMax:
return "max";
case IntrinsicType::kMin:
return "min";
case IntrinsicType::kMix:
return "mix";
case IntrinsicType::kModf:
return "modf";
case IntrinsicType::kNormalize:
return "normalize";
case IntrinsicType::kPack2x16float:
return "pack2x16float";
case IntrinsicType::kPack2x16snorm:
return "pack2x16snorm";
case IntrinsicType::kPack2x16unorm:
return "pack2x16unorm";
case IntrinsicType::kPack4x8snorm:
return "pack4x8snorm";
case IntrinsicType::kPack4x8unorm:
return "pack4x8unorm";
case IntrinsicType::kPow:
return "pow";
case IntrinsicType::kReflect:
return "reflect";
case IntrinsicType::kReverseBits:
return "reverseBits";
case IntrinsicType::kRound:
return "round";
case IntrinsicType::kSelect:
return "select";
case IntrinsicType::kSign:
return "sign";
case IntrinsicType::kSin:
return "sin";
case IntrinsicType::kSinh:
return "sinh";
case IntrinsicType::kSmoothStep:
return "smoothStep";
case IntrinsicType::kSqrt:
return "sqrt";
case IntrinsicType::kStep:
return "step";
case IntrinsicType::kStorageBarrier:
return "storageBarrier";
case IntrinsicType::kTan:
return "tan";
case IntrinsicType::kTanh:
return "tanh";
case IntrinsicType::kTrunc:
return "trunc";
case IntrinsicType::kUnpack2x16float:
return "unpack2x16float";
case IntrinsicType::kUnpack2x16snorm:
return "unpack2x16snorm";
case IntrinsicType::kUnpack2x16unorm:
return "unpack2x16unorm";
case IntrinsicType::kUnpack4x8snorm:
return "unpack4x8snorm";
case IntrinsicType::kUnpack4x8unorm:
return "unpack4x8unorm";
case IntrinsicType::kWorkgroupBarrier:
return "workgroupBarrier";
case IntrinsicType::kTextureDimensions:
return "textureDimensions";
case IntrinsicType::kTextureNumLayers:
return "textureNumLayers";
case IntrinsicType::kTextureNumLevels:
return "textureNumLevels";
case IntrinsicType::kTextureNumSamples:
return "textureNumSamples";
case IntrinsicType::kTextureSample:
return "textureSample";
case IntrinsicType::kTextureSampleBias:
return "textureSampleBias";
case IntrinsicType::kTextureSampleCompare:
return "textureSampleCompare";
case IntrinsicType::kTextureSampleGrad:
return "textureSampleGrad";
case IntrinsicType::kTextureSampleLevel:
return "textureSampleLevel";
case IntrinsicType::kTextureStore:
return "textureStore";
case IntrinsicType::kTextureLoad:
return "textureLoad";
}
return "<unknown>";
}
} // namespace sem
} // namespace tint

View File

@@ -0,0 +1,38 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/intrinsic-gen to generate intrinsic_type.cc
See:
* tools/cmd/intrinsic-gen/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
#include "src/sem/intrinsic_type.h"
namespace tint {
namespace sem {
IntrinsicType ParseIntrinsicType(const std::string& name) {
{{- range .Sem.Functions }}
if (name == "{{.Name}}") {
return IntrinsicType::k{{Title .Name}};
}
{{- end }}
return IntrinsicType::kNone;
}
const char* str(IntrinsicType i) {
switch (i) {
case IntrinsicType::kNone:
return "<none>";
{{- range .Sem.Functions }}
case IntrinsicType::k{{Title .Name}}:
return "{{.Name}}";
{{- end }}
}
return "<unknown>";
}
} // namespace sem
} // namespace tint

130
src/sem/intrinsic_type.h Normal file
View File

@@ -0,0 +1,130 @@
// Copyright 2021 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/intrinsic-gen
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_SEM_INTRINSIC_TYPE_H_
#define SRC_SEM_INTRINSIC_TYPE_H_
#include <string>
namespace tint {
namespace sem {
/// Enumerator of all intrinsic functions
enum class IntrinsicType {
kNone = -1,
kAbs,
kAcos,
kAll,
kAny,
kArrayLength,
kAsin,
kAtan,
kAtan2,
kCeil,
kClamp,
kCos,
kCosh,
kCountOneBits,
kCross,
kDeterminant,
kDistance,
kDot,
kDpdx,
kDpdxCoarse,
kDpdxFine,
kDpdy,
kDpdyCoarse,
kDpdyFine,
kExp,
kExp2,
kFaceForward,
kFloor,
kFma,
kFract,
kFrexp,
kFwidth,
kFwidthCoarse,
kFwidthFine,
kInverseSqrt,
kIsFinite,
kIsInf,
kIsNan,
kIsNormal,
kLdexp,
kLength,
kLog,
kLog2,
kMax,
kMin,
kMix,
kModf,
kNormalize,
kPack2x16float,
kPack2x16snorm,
kPack2x16unorm,
kPack4x8snorm,
kPack4x8unorm,
kPow,
kReflect,
kReverseBits,
kRound,
kSelect,
kSign,
kSin,
kSinh,
kSmoothStep,
kSqrt,
kStep,
kStorageBarrier,
kTan,
kTanh,
kTrunc,
kUnpack2x16float,
kUnpack2x16snorm,
kUnpack2x16unorm,
kUnpack4x8snorm,
kUnpack4x8unorm,
kWorkgroupBarrier,
kTextureDimensions,
kTextureNumLayers,
kTextureNumLevels,
kTextureNumSamples,
kTextureSample,
kTextureSampleBias,
kTextureSampleCompare,
kTextureSampleGrad,
kTextureSampleLevel,
kTextureStore,
kTextureLoad,
};
/// Matches the IntrinsicType by name
/// @param name the intrinsic name to parse
/// @returns the parsed IntrinsicType, or IntrinsicType::kNone if `name` did not
/// match any intrinsic.
IntrinsicType ParseIntrinsicType(const std::string& name);
/// @returns the name of the intrinsic function type. The spelling, including
/// case, matches the name in the WGSL spec.
const char* str(IntrinsicType i);
} // namespace sem
} // namespace tint
#endif // SRC_SEM_INTRINSIC_TYPE_H_

View File

@@ -0,0 +1,40 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/intrinsic-gen to generate intrinsic_type.h
See:
* tools/cmd/intrinsic-gen/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
#ifndef SRC_SEM_INTRINSIC_TYPE_H_
#define SRC_SEM_INTRINSIC_TYPE_H_
#include <string>
namespace tint {
namespace sem {
/// Enumerator of all intrinsic functions
enum class IntrinsicType {
kNone = -1,
{{- range .Sem.Functions }}
k{{Title .Name}},
{{- end }}
};
/// Matches the IntrinsicType by name
/// @param name the intrinsic name to parse
/// @returns the parsed IntrinsicType, or IntrinsicType::kNone if `name` did not
/// match any intrinsic.
IntrinsicType ParseIntrinsicType(const std::string& name);
/// @returns the name of the intrinsic function type. The spelling, including
/// case, matches the name in the WGSL spec.
const char* str(IntrinsicType i);
} // namespace sem
} // namespace tint
#endif // SRC_SEM_INTRINSIC_TYPE_H_