| {{- /* |
| -------------------------------------------------------------------------------- |
| 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; |
| } |
| |
| 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) { |
| return f == BuiltinFn::kSubgroupBallot || f == BuiltinFn::kSubgroupBroadcast; |
| } |
| |
| 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::kTextureStore: |
| case BuiltinFn::kWorkgroupUniformLoad: |
| return true; |
| default: |
| break; |
| } |
| return false; |
| } |
| |
| } // namespace tint::wgsl |