| {{- /* | |
| -------------------------------------------------------------------------------- | |
| Template file for use with tools/src/cmd/gen to generate function.h | |
| 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/core/core.def" -}} | |
| #ifndef SRC_TINT_LANG_CORE_FUNCTION_H_ | |
| #define SRC_TINT_LANG_CORE_FUNCTION_H_ | |
| #include <cstdint> | |
| #include <string> | |
| #include "src/tint/utils/traits/traits.h" | |
| // \cond DO_NOT_DOCUMENT | |
| namespace tint::core { | |
| /// Enumerator of all builtin functions | |
| enum class Function : uint8_t { | |
| {{- range $I.Sem.Builtins }} | |
| k{{PascalCase .Name}}, | |
| {{- end }} | |
| kNone, | |
| }; | |
| /// Matches the Function by name | |
| /// @param name the builtin name to parse | |
| /// @returns the parsed Function, or Function::kNone if `name` did not | |
| /// match any builtin function. | |
| Function ParseFunction(std::string_view name); | |
| /// @returns the name of the builtin function type. The spelling, including | |
| /// case, matches the name in the WGSL spec. | |
| const char* str(Function i); | |
| /// Emits the name of the builtin function type. The spelling, including case, | |
| /// matches the name in the WGSL spec. | |
| template <typename STREAM, typename = traits::EnableIfIsOStream<STREAM>> | |
| auto& operator<<(STREAM& o, Function i) { | |
| return o << str(i); | |
| } | |
| /// All builtin functions | |
| constexpr Function kFunctions[] = { | |
| {{- range $I.Sem.Builtins }} | |
| Function::k{{PascalCase .Name}}, | |
| {{- end }} | |
| }; | |
| /// All builtin function names | |
| constexpr const char* kFunctionStrings[] = { | |
| {{- range $I.Sem.Builtins }} | |
| "{{.Name}}", | |
| {{- end }} | |
| }; | |
| /// Determines if the given `f` is a coarse derivative. | |
| /// @param f the builtin type | |
| /// @returns true if the given derivative is coarse. | |
| bool IsCoarseDerivativeBuiltin(Function f); | |
| /// Determines if the given `f` is a fine derivative. | |
| /// @param f the builtin type | |
| /// @returns true if the given derivative is fine. | |
| bool IsFineDerivativeBuiltin(Function f); | |
| /// Determine if the given `f` is a derivative builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a derivative builtin | |
| bool IsDerivativeBuiltin(Function f); | |
| /// Determines if the given `f` is a texture operation builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a texture operation builtin | |
| bool IsTextureBuiltin(Function f); | |
| /// Determines if the given `f` is an image query builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is an image query builtin | |
| bool IsImageQueryBuiltin(Function f); | |
| /// Determines if the given `f` is a data packing builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a data packing builtin | |
| bool IsDataPackingBuiltin(Function f); | |
| /// Determines if the given `f` is a data unpacking builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a data unpacking builtin | |
| bool IsDataUnpackingBuiltin(Function f); | |
| /// Determines if the given `f` is a barrier builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a barrier builtin | |
| bool IsBarrierBuiltin(Function f); | |
| /// Determines if the given `f` is an atomic builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is an atomic builtin | |
| bool IsAtomicBuiltin(Function f); | |
| /// Determines if the given `f` is a DP4a builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a DP4a builtin | |
| bool IsDP4aBuiltin(Function f); | |
| /// Determines if the given `f` is a subgroup builtin. | |
| /// @param f the builtin type | |
| /// @returns true if the given `f` is a subgroup builtin | |
| bool IsSubgroupBuiltin(Function f); | |
| /// Determines if the given `f` may have side-effects (i.e. writes to at least one of its inputs) | |
| /// @returns true if intrinsic may have side-effects | |
| bool HasSideEffects(Function f); | |
| } // namespace tint::core | |
| // \endcond | |
| #endif // SRC_TINT_LANG_CORE_FUNCTION_H_ |