blob: 7b31abdfcd07f1395fa3b6671a4b608cedf68a05 [file]
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate access.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" -}}
{{- Import "src/tint/utils/templates/enums.tmpl.inc" -}}
{{- $access_enum := ($I.Sem.Enum "access") -}}
{{- $addr_space_enum := ($I.Sem.Enum "address_space") -}}
{{- $interpolation_sampling_enum := ($I.Sem.Enum "interpolation_sampling") -}}
{{- $interpolation_type_enum := ($I.Sem.Enum "interpolation_type") -}}
{{- $sampler_filtering_enum := ($I.Sem.Enum "sampler_filtering") -}}
{{- $texture_filterable_enum := ($I.Sem.Enum "texture_filterable") -}}
{{- $subgroup_matrix_kind_enum := ($I.Sem.Enum "subgroup_matrix_kind") -}}
{{- $texel_format_enum := ($I.Sem.Enum "texel_format") -}}
{{- $builtin_type_enum := ($I.Sem.Enum "builtin_type") -}}
{{- $builtin_value_enum := ($I.Sem.Enum "builtin_value") -}}
{{- $builtin_depth_mode_enum := ($I.Sem.Enum "builtin_depth_mode") -}}
{{- $attribute_enum := ($I.Sem.Enum "attribute") -}}
{{- Eval "OverrideEnumName" "Enum" $builtin_type_enum "Name" "BuiltinType" -}}
#ifndef SRC_TINT_LANG_CORE_ENUMS_H_
#define SRC_TINT_LANG_CORE_ENUMS_H_
// clang-format off
#include <cstdint>
#include "src/tint/utils/reflection.h"
#include "src/tint/utils/rtti/traits.h"
namespace tint::core {
/// Access of a given pointer.
{{ Eval "DeclareEnum" $access_enum}}
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $addr_space_enum}}
/// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
inline bool IsHostShareable(AddressSpace address_space) {
return address_space == AddressSpace::kUniform ||
address_space == AddressSpace::kStorage ||
address_space == AddressSpace::kImmediate;
}
/// The interpolation sampling.
{{ Eval "DeclareEnum" $interpolation_sampling_enum }}
/// The interpolation type.
{{ Eval "DeclareEnum" $interpolation_type_enum }}
/// The sampler filtering.
{{ Eval "DeclareEnum" $sampler_filtering_enum }}
/// The texture filterable.
{{ Eval "DeclareEnum" $texture_filterable_enum }}
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $subgroup_matrix_kind_enum }}
/// Enumerator of texel formats
{{ Eval "DeclareEnum" $texel_format_enum}}
/// An enumerator of builtin types.
{{ Eval "DeclareEnum" $builtin_type_enum}}
/// Builtin value defined with `@builtin(<name>)`.
{{ Eval "DeclareEnum" $builtin_value_enum}}
/// Builtin depth mode defined with `@builtin(<name>, <depth_mode>)`.
{{ Eval "DeclareEnum" $builtin_depth_mode_enum }}
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $attribute_enum}}
/// ParameterUsage is extra metadata for identifying a parameter based on its
/// overload position
enum class ParameterUsage : uint8_t {
{{- range $I.Sem.UniqueParameterNames }}
k{{PascalCase .}},
{{- end }}
kNone,
};
/// @param value the enum value
/// @returns the string for the given enum value
std::string_view ToString(ParameterUsage value);
/// @param out the stream to write to
/// @param value the ParameterUsage
/// @returns @p out so calls can be chained
template <typename STREAM>
requires(traits::IsOStream<STREAM>)
auto& operator<<(STREAM& out, ParameterUsage value) {
return out << ToString(value);
}
/// Enumerator of all builtin functions
enum class BuiltinFn : uint8_t {
{{- range $I.Sem.Builtins }}
k{{PascalCase .Name}},
{{- end }}
kNone,
};
/// Matches the BuiltinFn by name
/// @param name the builtin name to parse
/// @returns the parsed BuiltinFn, or BuiltinFn::kNone if `name` did not
/// match any builtin function.
BuiltinFn ParseBuiltinFn(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(BuiltinFn i);
/// Emits the name of the builtin function type. The spelling, including case,
/// matches the name in the WGSL spec.
template <typename STREAM>
requires(traits::IsOStream<STREAM>)
auto& operator<<(STREAM& o, BuiltinFn i) {
return o << str(i);
}
/// All builtin functions
constexpr BuiltinFn kBuiltinFns[] = {
{{- range $I.Sem.Builtins }}
BuiltinFn::k{{PascalCase .Name}},
{{- end }}
};
/// All builtin function names
constexpr const char* kBuiltinFnStrings[] = {
{{- 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 IsCoarseDerivative(BuiltinFn f);
/// Determines if the given `f` is a fine derivative.
/// @param f the builtin type
/// @returns true if the given derivative is fine.
bool IsFineDerivative(BuiltinFn 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 IsDerivative(BuiltinFn 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 IsTexture(BuiltinFn 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 IsImageQuery(BuiltinFn 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 IsDataPacking(BuiltinFn 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 IsDataUnpacking(BuiltinFn 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 IsBarrier(BuiltinFn 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 IsAtomic(BuiltinFn f);
/// Determines if the given `f` is a builtin defined in the language extension
/// `packed_4x8_integer_dot_product`.
/// @param f the builtin type
/// @returns true if the given `f` is a builtin defined in the language extension
/// `packed_4x8_integer_dot_product`.
bool IsPacked4x8IntegerDotProductBuiltin(BuiltinFn 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 IsSubgroup(BuiltinFn 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(BuiltinFn f);
} // namespace tint::core
namespace tint {
/// Access reflection information
TINT_REFLECT_ENUM_RANGE(core::{{ Eval "EnumName" $access_enum }}, {{Eval "EnumFirst" $access_enum }}, {{Eval "EnumLast" $access_enum}});
/// SubgroupMatrixType reflection information
TINT_REFLECT_ENUM_RANGE(core::{{ Eval "EnumName" $subgroup_matrix_kind_enum }}, {{Eval "EnumFirst" $subgroup_matrix_kind_enum }}, {{Eval "EnumLast" $subgroup_matrix_kind_enum}});
} // namespace tint
// clang-format on
#endif // SRC_TINT_LANG_CORE_ENUMS_H_