tint/templates: Generate enum string arrays

This will be useful for emitting possible enum values when an enum fails to parse.

Bug: tint:1629
Change-Id: I0be177a2bc27962580f4465ec18fdc5f2e930a99
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105322
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2022-10-11 19:29:11 +00:00 committed by Dawn LUCI CQ
parent 3e0984afe0
commit b7aef033fa
5 changed files with 34 additions and 0 deletions

View File

@ -52,6 +52,10 @@ std::ostream& operator<<(std::ostream& out, AddressSpace value);
/// @returns the parsed enum, or AddressSpace::kInvalid if the string could not be parsed. /// @returns the parsed enum, or AddressSpace::kInvalid if the string could not be parsed.
AddressSpace ParseAddressSpace(std::string_view str); AddressSpace ParseAddressSpace(std::string_view str);
constexpr const char* kAddressSpaceStrings[] = {
"function", "private", "push_constant", "storage", "uniform", "workgroup",
};
/// @returns true if the AddressSpace is host-shareable /// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace /// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable /// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable

View File

@ -55,6 +55,15 @@ std::ostream& operator<<(std::ostream& out, BuiltinValue value);
/// @returns the parsed enum, or BuiltinValue::kInvalid if the string could not be parsed. /// @returns the parsed enum, or BuiltinValue::kInvalid if the string could not be parsed.
BuiltinValue ParseBuiltinValue(std::string_view str); BuiltinValue ParseBuiltinValue(std::string_view str);
constexpr const char* kBuiltinValueStrings[] = {
"frag_depth", "front_facing",
"global_invocation_id", "instance_index",
"local_invocation_id", "local_invocation_index",
"num_workgroups", "position",
"sample_index", "sample_mask",
"vertex_index", "workgroup_id",
};
} // namespace tint::ast } // namespace tint::ast
#endif // SRC_TINT_AST_BUILTIN_VALUE_H_ #endif // SRC_TINT_AST_BUILTIN_VALUE_H_

View File

@ -49,6 +49,13 @@ std::ostream& operator<<(std::ostream& out, Extension value);
/// @returns the parsed enum, or Extension::kInvalid if the string could not be parsed. /// @returns the parsed enum, or Extension::kInvalid if the string could not be parsed.
Extension ParseExtension(std::string_view str); Extension ParseExtension(std::string_view str);
constexpr const char* kExtensionStrings[] = {
"chromium_disable_uniformity_analysis",
"chromium_experimental_dp4a",
"chromium_experimental_push_constant",
"f16",
};
// A unique vector of extensions // A unique vector of extensions
using Extensions = utils::UniqueVector<Extension, 4>; using Extensions = utils::UniqueVector<Extension, 4>;

View File

@ -58,6 +58,12 @@ std::ostream& operator<<(std::ostream& out, TexelFormat value);
/// @returns the parsed enum, or TexelFormat::kInvalid if the string could not be parsed. /// @returns the parsed enum, or TexelFormat::kInvalid if the string could not be parsed.
TexelFormat ParseTexelFormat(std::string_view str); TexelFormat ParseTexelFormat(std::string_view str);
constexpr const char* kTexelFormatStrings[] = {
"r32float", "r32sint", "r32uint", "rg32float", "rg32sint", "rg32uint",
"rgba16float", "rgba16sint", "rgba16uint", "rgba32float", "rgba32sint", "rgba32uint",
"rgba8sint", "rgba8snorm", "rgba8uint", "rgba8unorm",
};
} // namespace tint::ast } // namespace tint::ast
#endif // SRC_TINT_AST_TEXEL_FORMAT_H_ #endif // SRC_TINT_AST_TEXEL_FORMAT_H_

View File

@ -28,6 +28,14 @@ std::ostream& operator<<(std::ostream& out, {{$enum}} value);
/// @returns the parsed enum, or {{$enum}}::kInvalid if the string could not be parsed. /// @returns the parsed enum, or {{$enum}}::kInvalid if the string could not be parsed.
{{$enum}} Parse{{$enum}}(std::string_view str); {{$enum}} Parse{{$enum}}(std::string_view str);
constexpr const char* k{{$enum}}Strings[] = {
{{- range $entry := $.Entries }}
{{- if not $entry.IsInternal}}
"{{$entry.Name}}",
{{- end }}
{{- end }}
};
{{- end -}} {{- end -}}