blob: ba6596e5c122775d73f9c72b01eaa1b520870c35 [file] [log] [blame]
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate enums.h
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" -}}
{{- Import "src/tint/utils/templates/enums.tmpl.inc" -}}
{{- $extensions_enum := ($I.Sem.Enum "extension") -}}
{{- $language_feature_enum := ($I.Sem.Enum "language_feature") -}}
#ifndef SRC_TINT_LANG_WGSL_ENUMS_H_
#define SRC_TINT_LANG_WGSL_ENUMS_H_
#include <cstdint>
#include <string>
#include <variant>
#include "src/tint/utils/containers/hashmap.h"
#include "src/tint/utils/containers/unique_vector.h"
#include "src/tint/utils/diagnostic/diagnostic.h"
#include "src/tint/utils/rtti/traits.h"
namespace tint::wgsl {
/// WGSL core diagnostic rules.
{{ Eval "DeclareEnum" ($I.Sem.Enum "core_diagnostic_rule") }}
/// Chromium-specific diagnostic rules.
{{ Eval "DeclareEnum" ($I.Sem.Enum "chromium_diagnostic_rule") }}
/// An enumerator of WGSL extensions
/// @see src/tint/lang/wgsl/intrinsics.def for extension descriptions
{{ Eval "DeclareEnum" $extensions_enum}}
/// All extensions
static constexpr Extension kAllExtensions[] = {
{{- range $entry := $extensions_enum.Entries }}
Extension::k{{PascalCase $entry.Name}},
{{- end }}
};
/// An enumerator of WGSL language features
/// @see src/tint/lang/wgsl/wgsl.def for language feature descriptions
{{ Eval "DeclareEnum" "Enum" $language_feature_enum "EmitOStream" false}}
/// All features
static constexpr LanguageFeature kAllLanguageFeatures[] = {
{{- range $entry := $language_feature_enum.Entries }}
LanguageFeature::k{{PascalCase $entry.Name}},
{{- end }}
};
/// A unique vector of extensions
using Extensions = UniqueVector<Extension, 4>;
/// All diagnostic rules understood by Tint.
using DiagnosticRule = std::variant<CoreDiagnosticRule, ChromiumDiagnosticRule>;
/// The diagnostic severity control.
{{ Eval "DeclareEnum" ($I.Sem.Enum "diagnostic_severity") }}
/// Convert a DiagnosticSeverity to the corresponding diag::Severity.
diag::Severity ToSeverity(DiagnosticSeverity sc);
/// DiagnosticRuleSeverities is a map from diagnostic rule to diagnostic severity.
using DiagnosticRuleSeverities = Hashmap<DiagnosticRule, DiagnosticSeverity, 1>;
/// 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` is a subgroup matrix builtin.
/// @param f the builtin type
/// @returns true if the given `f` is a subgroup matrix builtin
bool IsSubgroupMatrix(BuiltinFn f);
/// Determines if the given `f` is a quadSwap* builtin.
/// @param f the builtin type
/// @returns true if the given `f` is a quadSwap* builtin
bool IsQuadSwap(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::wgsl
#endif // SRC_TINT_LANG_WGSL_ENUMS_H_