blob: 77c7433d93bf64308fcede4807b0c8298c422f45 [file] [log] [blame]
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate builtin_fn.cc
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- $I := LoadIntrinsics "src/tint/lang/wgsl/wgsl.def" -}}
#include "src/tint/lang/wgsl/builtin_fn.h"
namespace tint::wgsl {
BuiltinFn ParseBuiltinFn(std::string_view name) {
{{- range $I.Sem.Builtins }}
if (name == "{{.Name}}") {
return BuiltinFn::k{{PascalCase .Name}};
}
{{- end }}
return BuiltinFn::kNone;
}
const char* str(BuiltinFn i) {
switch (i) {
case BuiltinFn::kNone:
return "<none>";
{{- range $I.Sem.Builtins }}
case BuiltinFn::k{{PascalCase .Name}}:
return "{{.Name}}";
{{- end }}
}
return "<unknown>";
}
bool IsCoarseDerivative(BuiltinFn f) {
return f == BuiltinFn::kDpdxCoarse || f == BuiltinFn::kDpdyCoarse ||
f == BuiltinFn::kFwidthCoarse;
}
bool IsFineDerivative(BuiltinFn f) {
return f == BuiltinFn::kDpdxFine || f == BuiltinFn::kDpdyFine ||
f == BuiltinFn::kFwidthFine;
}
bool IsDerivative(BuiltinFn f) {
return f == BuiltinFn::kDpdx || f == BuiltinFn::kDpdy ||
f == BuiltinFn::kFwidth || IsCoarseDerivative(f) ||
IsFineDerivative(f);
}
bool IsTexture(BuiltinFn f) {
return IsImageQuery(f) || //
f == BuiltinFn::kTextureGather || //
f == BuiltinFn::kTextureGatherCompare || //
f == BuiltinFn::kTextureLoad || //
f == BuiltinFn::kTextureSample || //
f == BuiltinFn::kTextureSampleBaseClampToEdge || //
f == BuiltinFn::kTextureSampleBias || //
f == BuiltinFn::kTextureSampleCompare || //
f == BuiltinFn::kTextureSampleCompareLevel || //
f == BuiltinFn::kTextureSampleGrad || //
f == BuiltinFn::kTextureSampleLevel || //
f == BuiltinFn::kTextureStore || f == BuiltinFn::kInputAttachmentLoad;
}
bool IsImageQuery(BuiltinFn f) {
return f == BuiltinFn::kTextureDimensions ||
f == BuiltinFn::kTextureNumLayers || f == BuiltinFn::kTextureNumLevels ||
f == BuiltinFn::kTextureNumSamples;
}
bool IsDataPacking(BuiltinFn f) {
return f == BuiltinFn::kPack4X8Snorm || f == BuiltinFn::kPack4X8Unorm ||
f == BuiltinFn::kPack2X16Snorm || f == BuiltinFn::kPack2X16Unorm ||
f == BuiltinFn::kPack2X16Float;
}
bool IsDataUnpacking(BuiltinFn f) {
return f == BuiltinFn::kUnpack4X8Snorm || f == BuiltinFn::kUnpack4X8Unorm ||
f == BuiltinFn::kUnpack2X16Snorm || f == BuiltinFn::kUnpack2X16Unorm ||
f == BuiltinFn::kUnpack2X16Float;
}
bool IsBarrier(BuiltinFn f) {
return f == BuiltinFn::kWorkgroupBarrier || f == BuiltinFn::kStorageBarrier ||
f == BuiltinFn::kTextureBarrier;
}
bool IsAtomic(BuiltinFn f) {
return f == BuiltinFn::kAtomicLoad || f == BuiltinFn::kAtomicStore ||
f == BuiltinFn::kAtomicAdd || f == BuiltinFn::kAtomicSub ||
f == BuiltinFn::kAtomicMax || f == BuiltinFn::kAtomicMin ||
f == BuiltinFn::kAtomicAnd || f == BuiltinFn::kAtomicOr ||
f == BuiltinFn::kAtomicXor || f == BuiltinFn::kAtomicExchange ||
f == BuiltinFn::kAtomicCompareExchangeWeak;
}
bool IsPacked4x8IntegerDotProductBuiltin(BuiltinFn f) {
return f == BuiltinFn::kDot4I8Packed || f == BuiltinFn::kDot4U8Packed ||
f == BuiltinFn::kPack4XI8 || f == BuiltinFn::kPack4XU8 ||
f == BuiltinFn::kPack4XI8Clamp || f == BuiltinFn::kPack4XU8Clamp ||
f == BuiltinFn::kUnpack4XI8 || f == BuiltinFn::kUnpack4XU8;
}
bool IsSubgroup(BuiltinFn f) {
switch (f) {
case BuiltinFn::kSubgroupBallot:
case BuiltinFn::kSubgroupElect:
case BuiltinFn::kSubgroupBroadcast:
case BuiltinFn::kSubgroupBroadcastFirst:
case BuiltinFn::kSubgroupShuffle:
case BuiltinFn::kSubgroupShuffleXor:
case BuiltinFn::kSubgroupShuffleUp:
case BuiltinFn::kSubgroupShuffleDown:
case BuiltinFn::kSubgroupAdd:
case BuiltinFn::kSubgroupInclusiveAdd:
case BuiltinFn::kSubgroupExclusiveAdd:
case BuiltinFn::kSubgroupMul:
case BuiltinFn::kSubgroupInclusiveMul:
case BuiltinFn::kSubgroupExclusiveMul:
case BuiltinFn::kSubgroupAnd:
case BuiltinFn::kSubgroupOr:
case BuiltinFn::kSubgroupXor:
case BuiltinFn::kSubgroupMin:
case BuiltinFn::kSubgroupMax:
case BuiltinFn::kSubgroupAll:
case BuiltinFn::kSubgroupAny:
case BuiltinFn::kQuadBroadcast:
case BuiltinFn::kQuadSwapX:
case BuiltinFn::kQuadSwapY:
case BuiltinFn::kQuadSwapDiagonal:
return true;
default:
return false;
}
}
bool IsQuadSwap(BuiltinFn f) {
switch (f) {
case BuiltinFn::kQuadSwapX:
case BuiltinFn::kQuadSwapY:
case BuiltinFn::kQuadSwapDiagonal:
return true;
default:
return false;
}
}
bool HasSideEffects(BuiltinFn f) {
switch (f) {
case BuiltinFn::kAtomicAdd:
case BuiltinFn::kAtomicAnd:
case BuiltinFn::kAtomicCompareExchangeWeak:
case BuiltinFn::kAtomicExchange:
case BuiltinFn::kAtomicMax:
case BuiltinFn::kAtomicMin:
case BuiltinFn::kAtomicOr:
case BuiltinFn::kAtomicStore:
case BuiltinFn::kAtomicSub:
case BuiltinFn::kAtomicXor:
case BuiltinFn::kDpdx:
case BuiltinFn::kDpdxCoarse:
case BuiltinFn::kDpdxFine:
case BuiltinFn::kDpdy:
case BuiltinFn::kDpdyCoarse:
case BuiltinFn::kDpdyFine:
case BuiltinFn::kFwidth:
case BuiltinFn::kFwidthCoarse:
case BuiltinFn::kFwidthFine:
case BuiltinFn::kTextureSample:
case BuiltinFn::kTextureSampleBias:
case BuiltinFn::kTextureSampleCompare:
case BuiltinFn::kTextureStore:
case BuiltinFn::kWorkgroupUniformLoad:
return true;
default:
break;
}
return false;
}
} // namespace tint::wgsl