From 6392579ee1f146e346ca308abc98d76da60a83ae Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Fri, 17 Feb 2023 21:56:35 +0000 Subject: [PATCH] Move BuiltinValue to builtin/ This CL moves the BuiltinValue enum to the builtin/ folder. Change-Id: I9db5128c1bc272e8e8d5181d629e6724ac38322e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120361 Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair Kokoro: Kokoro --- src/tint/BUILD.gn | 20 +- src/tint/CMakeLists.txt | 2 +- src/tint/ast/builtin_attribute.cc | 5 +- src/tint/ast/builtin_attribute.h | 6 +- src/tint/ast/builtin_attribute_test.cc | 4 +- src/tint/ast/variable_test.cc | 2 +- src/tint/{ast => builtin}/builtin_value.cc | 8 +- .../{ast => builtin}/builtin_value.cc.tmpl | 6 +- src/tint/{ast => builtin}/builtin_value.h | 12 +- .../{ast => builtin}/builtin_value.h.tmpl | 10 +- .../{ast => builtin}/builtin_value_bench.cc | 8 +- .../builtin_value_bench.cc.tmpl | 6 +- .../{ast => builtin}/builtin_value_test.cc | 11 +- .../builtin_value_test.cc.tmpl | 9 +- src/tint/inspector/inspector.cc | 16 +- src/tint/inspector/inspector.h | 2 +- src/tint/inspector/inspector_test.cc | 44 ++-- src/tint/program_builder.h | 4 +- src/tint/reader/spirv/enum_converter.cc | 30 +-- src/tint/reader/spirv/enum_converter.h | 4 +- src/tint/reader/spirv/enum_converter_test.cc | 37 +-- src/tint/reader/spirv/function.cc | 6 +- src/tint/reader/spirv/parser_impl.cc | 2 +- src/tint/reader/wgsl/parser_impl.cc | 4 +- src/tint/reader/wgsl/parser_impl.h | 2 +- .../wgsl/parser_impl_param_list_test.cc | 2 +- ...arser_impl_variable_attribute_list_test.cc | 2 +- .../parser_impl_variable_attribute_test.cc | 27 +-- .../resolver/attribute_validation_test.cc | 18 +- src/tint/resolver/builtins_validation_test.cc | 221 +++++++++--------- .../resolver/entry_point_validation_test.cc | 54 +++-- src/tint/resolver/function_validation_test.cc | 2 +- src/tint/resolver/resolver_test.cc | 7 +- .../struct_pipeline_stage_use_test.cc | 19 +- src/tint/resolver/uniformity.cc | 4 +- src/tint/resolver/validation_test.cc | 2 +- src/tint/resolver/validator.cc | 34 +-- .../transform/canonicalize_entry_point_io.cc | 82 +++---- src/tint/transform/clamp_frag_depth.cc | 4 +- src/tint/transform/first_index_offset.cc | 12 +- .../transform/num_workgroups_from_uniform.cc | 4 +- src/tint/transform/vertex_pulling.cc | 12 +- .../transform/zero_init_workgroup_memory.cc | 6 +- src/tint/writer/glsl/generator_impl.cc | 6 +- src/tint/writer/glsl/generator_impl.h | 4 +- .../glsl/generator_impl_function_test.cc | 8 +- src/tint/writer/glsl/generator_impl_test.cc | 4 +- src/tint/writer/hlsl/generator_impl.cc | 24 +- src/tint/writer/hlsl/generator_impl.h | 2 +- .../hlsl/generator_impl_function_test.cc | 8 +- src/tint/writer/hlsl/generator_impl_test.cc | 25 +- src/tint/writer/msl/generator_impl.cc | 28 +-- src/tint/writer/msl/generator_impl.h | 2 +- .../msl/generator_impl_function_test.cc | 8 +- src/tint/writer/msl/generator_impl_test.cc | 32 +-- src/tint/writer/spirv/builder.cc | 32 +-- src/tint/writer/spirv/builder.h | 2 +- .../writer/spirv/builder_entry_point_test.cc | 10 +- .../spirv/builder_function_attribute_test.cc | 4 +- .../spirv/builder_global_variable_test.cc | 35 +-- .../wgsl/generator_impl_function_test.cc | 2 +- .../writer/wgsl/generator_impl_type_test.cc | 2 +- 62 files changed, 530 insertions(+), 480 deletions(-) rename src/tint/{ast => builtin}/builtin_value.cc (96%) rename src/tint/{ast => builtin}/builtin_value.cc.tmpl (84%) rename src/tint/{ast => builtin}/builtin_value.h (89%) rename src/tint/{ast => builtin}/builtin_value.h.tmpl (76%) rename src/tint/{ast => builtin}/builtin_value_bench.cc (95%) rename src/tint/{ast => builtin}/builtin_value_bench.cc.tmpl (86%) rename src/tint/{ast => builtin}/builtin_value_test.cc (96%) rename src/tint/{ast => builtin}/builtin_value_test.cc.tmpl (83%) diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index f0ca1dd33c..d54b9307e5 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -431,6 +431,7 @@ libtint_source_set("libtint_transform_src") { deps = [ ":libtint_ast_src", ":libtint_base_src", + ":libtint_builtins_src", ":libtint_program_src", ":libtint_sem_src", ":libtint_text_src", @@ -452,7 +453,6 @@ libtint_source_set("libtint_ast_hdrs") { "ast/break_if_statement.h", "ast/break_statement.h", "ast/builtin_attribute.h", - "ast/builtin_value.h", "ast/call_expression.h", "ast/call_statement.h", "ast/case_selector.h", @@ -519,6 +519,7 @@ libtint_source_set("libtint_ast_hdrs") { ] deps = [ ":libtint_base_src", + ":libtint_builtins_src", ":libtint_clone_context_hdrs", ":libtint_type_src", ] @@ -538,7 +539,6 @@ libtint_source_set("libtint_ast_src") { "ast/break_if_statement.cc", "ast/break_statement.cc", "ast/builtin_attribute.cc", - "ast/builtin_value.cc", "ast/call_expression.cc", "ast/call_statement.cc", "ast/case_selector.cc", @@ -690,6 +690,13 @@ libtint_source_set("libtint_sem_src") { ] } +libtint_source_set("libtint_builtins_src") { + sources = [ + "builtin/builtin_value.cc", + "builtin/builtin_value.h", + ] +} + libtint_source_set("libtint_type_src") { sources = [ "type/abstract_float.cc", @@ -826,6 +833,7 @@ libtint_source_set("libtint_spv_reader_src") { deps = [ ":libtint_ast_src", ":libtint_base_src", + ":libtint_builtins_src", ":libtint_program_src", ":libtint_reader_src", ":libtint_sem_src", @@ -1212,7 +1220,6 @@ if (tint_build_unittests) { "ast/builtin_attribute_test.cc", "ast/builtin_texture_helper_test.cc", "ast/builtin_texture_helper_test.h", - "ast/builtin_value_test.cc", "ast/call_expression_test.cc", "ast/call_statement_test.cc", "ast/case_selector_test.cc", @@ -1274,6 +1281,11 @@ if (tint_build_unittests) { } } + tint_unittests_source_set("tint_unittests_builtins_src") { + sources = [ "builtin/builtin_value_test.cc" ] + deps = [ ":libtint_builtins_src" ] + } + tint_unittests_source_set("tint_unittests_diagnostic_src") { sources = [ "diagnostic/diagnostic_test.cc", @@ -1614,6 +1626,7 @@ if (tint_build_unittests) { deps = [ ":libtint_base_src", + ":libtint_builtins_src", ":libtint_spv_writer_src", ":tint_unittests_ast_src", "${tint_spirv_tools_dir}/:spvtools", @@ -1931,6 +1944,7 @@ if (tint_build_unittests) { ":libtint_wgsl_writer_src", ":tint_unittests_ast_src", ":tint_unittests_base_src", + ":tint_unittests_builtins_src", ":tint_unittests_constant_src", ":tint_unittests_core_src", ":tint_unittests_demangler_src", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 868bce5adf..385e906411 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -548,7 +548,7 @@ list(APPEND TINT_LIB_SRCS writer/writer.h ) -tint_generated(ast/builtin_value BENCH TEST) +tint_generated(builtin/builtin_value BENCH TEST) tint_generated(ast/diagnostic_control BENCH TEST) tint_generated(ast/extension BENCH TEST) tint_generated(ast/interpolate_attribute BENCH TEST) diff --git a/src/tint/ast/builtin_attribute.cc b/src/tint/ast/builtin_attribute.cc index d5aace008a..e3f9d7b44f 100644 --- a/src/tint/ast/builtin_attribute.cc +++ b/src/tint/ast/builtin_attribute.cc @@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinAttribute); namespace tint::ast { -BuiltinAttribute::BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, BuiltinValue b) +BuiltinAttribute::BuiltinAttribute(ProgramID pid, + NodeID nid, + const Source& src, + builtin::BuiltinValue b) : Base(pid, nid, src), builtin(b) {} BuiltinAttribute::~BuiltinAttribute() = default; diff --git a/src/tint/ast/builtin_attribute.h b/src/tint/ast/builtin_attribute.h index 0aae24b57c..6f9b1563ce 100644 --- a/src/tint/ast/builtin_attribute.h +++ b/src/tint/ast/builtin_attribute.h @@ -18,7 +18,7 @@ #include #include "src/tint/ast/attribute.h" -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" namespace tint::ast { @@ -30,7 +30,7 @@ class BuiltinAttribute final : public Castable { /// @param nid the unique node identifier /// @param src the source of this node /// @param builtin the builtin value - BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, BuiltinValue builtin); + BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, builtin::BuiltinValue builtin); ~BuiltinAttribute() override; /// @returns the WGSL name for the attribute @@ -43,7 +43,7 @@ class BuiltinAttribute final : public Castable { const BuiltinAttribute* Clone(CloneContext* ctx) const override; /// The builtin value - const BuiltinValue builtin; + const builtin::BuiltinValue builtin; }; } // namespace tint::ast diff --git a/src/tint/ast/builtin_attribute_test.cc b/src/tint/ast/builtin_attribute_test.cc index dba6997faa..3421e0fe20 100644 --- a/src/tint/ast/builtin_attribute_test.cc +++ b/src/tint/ast/builtin_attribute_test.cc @@ -20,8 +20,8 @@ namespace { using BuiltinAttributeTest = TestHelper; TEST_F(BuiltinAttributeTest, Creation) { - auto* d = create(BuiltinValue::kFragDepth); - EXPECT_EQ(BuiltinValue::kFragDepth, d->builtin); + auto* d = create(builtin::BuiltinValue::kFragDepth); + EXPECT_EQ(builtin::BuiltinValue::kFragDepth, d->builtin); } } // namespace diff --git a/src/tint/ast/variable_test.cc b/src/tint/ast/variable_test.cc index ff97b2f558..88bcdc46a5 100644 --- a/src/tint/ast/variable_test.cc +++ b/src/tint/ast/variable_test.cc @@ -93,7 +93,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Initializer) { TEST_F(VariableTest, WithAttributes) { auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Location(1_u), - Builtin(BuiltinValue::kPosition), Id(1200_u)); + Builtin(builtin::BuiltinValue::kPosition), Id(1200_u)); auto& attributes = var->attributes; EXPECT_TRUE(ast::HasAttribute(attributes)); diff --git a/src/tint/ast/builtin_value.cc b/src/tint/builtin/builtin_value.cc similarity index 96% rename from src/tint/ast/builtin_value.cc rename to src/tint/builtin/builtin_value.cc index 0a4439ba10..740ebcc9b8 100644 --- a/src/tint/ast/builtin_value.cc +++ b/src/tint/builtin/builtin_value.cc @@ -15,14 +15,14 @@ //////////////////////////////////////////////////////////////////////////////// // File generated by tools/src/cmd/gen // using the template: -// src/tint/ast/builtin_value.cc.tmpl +// src/tint/builtin/builtin_value.cc.tmpl // // Do not modify this file directly //////////////////////////////////////////////////////////////////////////////// -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" -namespace tint::ast { +namespace tint::builtin { /// ParseBuiltinValue parses a BuiltinValue from a string. /// @param str the string to parse @@ -101,4 +101,4 @@ std::ostream& operator<<(std::ostream& out, BuiltinValue value) { return out << ""; } -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/ast/builtin_value.cc.tmpl b/src/tint/builtin/builtin_value.cc.tmpl similarity index 84% rename from src/tint/ast/builtin_value.cc.tmpl rename to src/tint/builtin/builtin_value.cc.tmpl index 7340c8806f..02ba5debcc 100644 --- a/src/tint/ast/builtin_value.cc.tmpl +++ b/src/tint/builtin/builtin_value.cc.tmpl @@ -11,12 +11,12 @@ See: {{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- $enum := (Sem.Enum "builtin_value") -}} -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" -namespace tint::ast { +namespace tint::builtin { {{ Eval "ParseEnum" $enum}} {{ Eval "EnumOStream" $enum}} -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/ast/builtin_value.h b/src/tint/builtin/builtin_value.h similarity index 89% rename from src/tint/ast/builtin_value.h rename to src/tint/builtin/builtin_value.h index 3a3c7869ae..1d5b4d4137 100644 --- a/src/tint/ast/builtin_value.h +++ b/src/tint/builtin/builtin_value.h @@ -15,17 +15,17 @@ //////////////////////////////////////////////////////////////////////////////// // File generated by tools/src/cmd/gen // using the template: -// src/tint/ast/builtin_value.h.tmpl +// src/tint/builtin/builtin_value.h.tmpl // // Do not modify this file directly //////////////////////////////////////////////////////////////////////////////// -#ifndef SRC_TINT_AST_BUILTIN_VALUE_H_ -#define SRC_TINT_AST_BUILTIN_VALUE_H_ +#ifndef SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ +#define SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ #include -namespace tint::ast { +namespace tint::builtin { /// Builtin value defined with `@builtin()`. enum class BuiltinValue { @@ -64,6 +64,6 @@ constexpr const char* kBuiltinValueStrings[] = { "vertex_index", "workgroup_id", }; -} // namespace tint::ast +} // namespace tint::builtin -#endif // SRC_TINT_AST_BUILTIN_VALUE_H_ +#endif // SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ diff --git a/src/tint/ast/builtin_value.h.tmpl b/src/tint/builtin/builtin_value.h.tmpl similarity index 76% rename from src/tint/ast/builtin_value.h.tmpl rename to src/tint/builtin/builtin_value.h.tmpl index ea63d563ff..46e806e058 100644 --- a/src/tint/ast/builtin_value.h.tmpl +++ b/src/tint/builtin/builtin_value.h.tmpl @@ -11,16 +11,16 @@ See: {{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- $enum := (Sem.Enum "builtin_value") -}} -#ifndef SRC_TINT_AST_BUILTIN_VALUE_H_ -#define SRC_TINT_AST_BUILTIN_VALUE_H_ +#ifndef SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ +#define SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ #include -namespace tint::ast { +namespace tint::builtin { /// Builtin value defined with `@builtin()`. {{ Eval "DeclareEnum" $enum}} -} // namespace tint::ast +} // namespace tint::builtin -#endif // SRC_TINT_AST_BUILTIN_VALUE_H_ +#endif // SRC_TINT_BUILTIN_BUILTIN_VALUE_H_ diff --git a/src/tint/ast/builtin_value_bench.cc b/src/tint/builtin/builtin_value_bench.cc similarity index 95% rename from src/tint/ast/builtin_value_bench.cc rename to src/tint/builtin/builtin_value_bench.cc index 879b0a545a..50d677e66b 100644 --- a/src/tint/ast/builtin_value_bench.cc +++ b/src/tint/builtin/builtin_value_bench.cc @@ -15,18 +15,18 @@ //////////////////////////////////////////////////////////////////////////////// // File generated by tools/src/cmd/gen // using the template: -// src/tint/ast/builtin_value_bench.cc.tmpl +// src/tint/builtin/builtin_value_bench.cc.tmpl // // Do not modify this file directly //////////////////////////////////////////////////////////////////////////////// -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" #include #include "benchmark/benchmark.h" -namespace tint::ast { +namespace tint::builtin { namespace { void BuiltinValueParser(::benchmark::State& state) { @@ -127,4 +127,4 @@ void BuiltinValueParser(::benchmark::State& state) { BENCHMARK(BuiltinValueParser); } // namespace -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/ast/builtin_value_bench.cc.tmpl b/src/tint/builtin/builtin_value_bench.cc.tmpl similarity index 86% rename from src/tint/ast/builtin_value_bench.cc.tmpl rename to src/tint/builtin/builtin_value_bench.cc.tmpl index f50bd20d7e..aa0ee17f8d 100644 --- a/src/tint/ast/builtin_value_bench.cc.tmpl +++ b/src/tint/builtin/builtin_value_bench.cc.tmpl @@ -11,16 +11,16 @@ See: {{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- $enum := (Sem.Enum "builtin_value") -}} -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" #include #include "benchmark/benchmark.h" -namespace tint::ast { +namespace tint::builtin { namespace { {{ Eval "BenchmarkParseEnum" $enum }} } // namespace -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/ast/builtin_value_test.cc b/src/tint/builtin/builtin_value_test.cc similarity index 96% rename from src/tint/ast/builtin_value_test.cc rename to src/tint/builtin/builtin_value_test.cc index 0ee2206275..b245250f79 100644 --- a/src/tint/ast/builtin_value_test.cc +++ b/src/tint/builtin/builtin_value_test.cc @@ -15,19 +15,20 @@ //////////////////////////////////////////////////////////////////////////////// // File generated by tools/src/cmd/gen // using the template: -// src/tint/ast/builtin_value_test.cc.tmpl +// src/tint/builtin/builtin_value_test.cc.tmpl // // Do not modify this file directly //////////////////////////////////////////////////////////////////////////////// -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" + +#include #include -#include "src/tint/ast/test_helper.h" #include "src/tint/utils/string.h" -namespace tint::ast { +namespace tint::builtin { namespace { namespace parse_print_tests { @@ -119,4 +120,4 @@ INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValuePrintTest, testing::ValuesIn(kV } // namespace parse_print_tests } // namespace -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/ast/builtin_value_test.cc.tmpl b/src/tint/builtin/builtin_value_test.cc.tmpl similarity index 83% rename from src/tint/ast/builtin_value_test.cc.tmpl rename to src/tint/builtin/builtin_value_test.cc.tmpl index 213a81b3cc..e629eed982 100644 --- a/src/tint/ast/builtin_value_test.cc.tmpl +++ b/src/tint/builtin/builtin_value_test.cc.tmpl @@ -11,17 +11,18 @@ See: {{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- $enum := (Sem.Enum "builtin_value") -}} -#include "src/tint/ast/builtin_value.h" +#include "src/tint/builtin/builtin_value.h" + +#include #include -#include "src/tint/ast/test_helper.h" #include "src/tint/utils/string.h" -namespace tint::ast { +namespace tint::builtin { namespace { {{ Eval "TestParsePrintEnum" $enum}} } // namespace -} // namespace tint::ast +} // namespace tint::builtin diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index 26202e3b0e..2a9c27db1d 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -216,15 +216,15 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) { param->Location(), entry_point.input_variables); entry_point.input_position_used |= ContainsBuiltin( - ast::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes); + builtin::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes); entry_point.front_facing_used |= ContainsBuiltin( - ast::BuiltinValue::kFrontFacing, param->Type(), param->Declaration()->attributes); + builtin::BuiltinValue::kFrontFacing, param->Type(), param->Declaration()->attributes); entry_point.sample_index_used |= ContainsBuiltin( - ast::BuiltinValue::kSampleIndex, param->Type(), param->Declaration()->attributes); + builtin::BuiltinValue::kSampleIndex, param->Type(), param->Declaration()->attributes); entry_point.input_sample_mask_used |= ContainsBuiltin( - ast::BuiltinValue::kSampleMask, param->Type(), param->Declaration()->attributes); + builtin::BuiltinValue::kSampleMask, param->Type(), param->Declaration()->attributes); entry_point.num_workgroups_used |= ContainsBuiltin( - ast::BuiltinValue::kNumWorkgroups, param->Type(), param->Declaration()->attributes); + builtin::BuiltinValue::kNumWorkgroups, param->Type(), param->Declaration()->attributes); } if (!sem->ReturnType()->Is()) { @@ -232,9 +232,9 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) { sem->ReturnLocation(), entry_point.output_variables); entry_point.output_sample_mask_used = ContainsBuiltin( - ast::BuiltinValue::kSampleMask, sem->ReturnType(), func->return_type_attributes); + builtin::BuiltinValue::kSampleMask, sem->ReturnType(), func->return_type_attributes); entry_point.frag_depth_used = ContainsBuiltin( - ast::BuiltinValue::kFragDepth, sem->ReturnType(), func->return_type_attributes); + builtin::BuiltinValue::kFragDepth, sem->ReturnType(), func->return_type_attributes); } for (auto* var : sem->TransitivelyReferencedGlobals()) { @@ -681,7 +681,7 @@ void Inspector::AddEntryPointInOutVariables(std::string name, variables.push_back(stage_variable); } -bool Inspector::ContainsBuiltin(ast::BuiltinValue builtin, +bool Inspector::ContainsBuiltin(builtin::BuiltinValue builtin, const type::Type* type, utils::VectorRef attributes) const { auto* unwrapped_type = type->UnwrapRef(); diff --git a/src/tint/inspector/inspector.h b/src/tint/inspector/inspector.h index b16fadf275..5854125644 100644 --- a/src/tint/inspector/inspector.h +++ b/src/tint/inspector/inspector.h @@ -183,7 +183,7 @@ class Inspector { /// Recursively determine if the type contains builtin. /// If `type` is a struct, recurse into members to check for the attribute. /// Otherwise, check `attributes` for the attribute. - bool ContainsBuiltin(ast::BuiltinValue builtin, + bool ContainsBuiltin(builtin::BuiltinValue builtin, const type::Type* type, utils::VectorRef attributes) const; diff --git a/src/tint/inspector/inspector_test.cc b/src/tint/inspector/inspector_test.cc index fe4cba133b..c9762a1ee0 100644 --- a/src/tint/inspector/inspector_test.cc +++ b/src/tint/inspector/inspector_test.cc @@ -464,7 +464,7 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { auto* in_var0 = Param("in_var0", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), }); auto* in_var1 = Param("in_var1", ty.f32(), utils::Vector{ @@ -478,7 +478,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); Inspector& inspector = Build(); @@ -1049,7 +1049,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltinNotReferenced) { TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) { auto* in_var = Param("in_var", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleMask), + Builtin(builtin::BuiltinValue::kSampleMask), }); Func("ep_func", utils::Vector{in_var}, ty.void_(), utils::Vector{ @@ -1069,7 +1069,8 @@ TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, InputSampleMaskStructReferenced) { utils::Vector members{ - Member("inner_position", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}), + Member("inner_position", ty.u32(), + utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}), }; Structure("in_struct", members); @@ -1097,7 +1098,7 @@ TEST_F(InspectorGetEntryPointTest, InputSampleMaskStructReferenced) { TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) { Func("ep_func", utils::Vector{ - Param("in_var", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}), + Param("in_var", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}), }, ty.u32(), utils::Vector{ @@ -1107,7 +1108,7 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kSampleMask), + Builtin(builtin::BuiltinValue::kSampleMask), }); Inspector& inspector = Build(); @@ -1121,7 +1122,7 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, OutputSampleMaskStructReferenced) { Structure("out_struct", utils::Vector{ Member("inner_sample_mask", ty.u32(), - utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}), + utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}), }); Func("ep_func", utils::Empty, ty("out_struct"), @@ -1144,7 +1145,8 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskStructReferenced) { TEST_F(InspectorGetEntryPointTest, InputPositionSimpleReferenced) { Func("ep_func", utils::Vector{ - Param("in_var", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Param("in_var", ty.vec4(), + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), }, ty.void_(), utils::Vector{ @@ -1165,7 +1167,7 @@ TEST_F(InspectorGetEntryPointTest, InputPositionSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, InputPositionStructReferenced) { Structure("in_struct", utils::Vector{ Member("inner_position", ty.vec4(), - utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), }); Func("ep_func", @@ -1191,7 +1193,8 @@ TEST_F(InspectorGetEntryPointTest, InputPositionStructReferenced) { TEST_F(InspectorGetEntryPointTest, FrontFacingSimpleReferenced) { Func("ep_func", utils::Vector{ - Param("in_var", ty.bool_(), utils::Vector{Builtin(ast::BuiltinValue::kFrontFacing)}), + Param("in_var", ty.bool_(), + utils::Vector{Builtin(builtin::BuiltinValue::kFrontFacing)}), }, ty.void_(), utils::Vector{ @@ -1212,7 +1215,7 @@ TEST_F(InspectorGetEntryPointTest, FrontFacingSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, FrontFacingStructReferenced) { Structure("in_struct", utils::Vector{ Member("inner_position", ty.bool_(), - utils::Vector{Builtin(ast::BuiltinValue::kFrontFacing)}), + utils::Vector{Builtin(builtin::BuiltinValue::kFrontFacing)}), }); Func("ep_func", @@ -1238,7 +1241,7 @@ TEST_F(InspectorGetEntryPointTest, FrontFacingStructReferenced) { TEST_F(InspectorGetEntryPointTest, SampleIndexSimpleReferenced) { Func("ep_func", utils::Vector{ - Param("in_var", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), + Param("in_var", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}), }, ty.void_(), utils::Vector{ @@ -1259,7 +1262,7 @@ TEST_F(InspectorGetEntryPointTest, SampleIndexSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, SampleIndexStructReferenced) { Structure("in_struct", utils::Vector{ Member("inner_position", ty.u32(), - utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), + utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}), }); Func("ep_func", @@ -1286,7 +1289,7 @@ TEST_F(InspectorGetEntryPointTest, NumWorkgroupsSimpleReferenced) { Func("ep_func", utils::Vector{ Param("in_var", ty.vec3(), - utils::Vector{Builtin(ast::BuiltinValue::kNumWorkgroups)}), + utils::Vector{Builtin(builtin::BuiltinValue::kNumWorkgroups)}), }, ty.void_(), utils::Vector{ @@ -1303,10 +1306,11 @@ TEST_F(InspectorGetEntryPointTest, NumWorkgroupsSimpleReferenced) { } TEST_F(InspectorGetEntryPointTest, NumWorkgroupsStructReferenced) { - Structure("in_struct", utils::Vector{ - Member("inner_position", ty.vec3(), - utils::Vector{Builtin(ast::BuiltinValue::kNumWorkgroups)}), - }); + Structure("in_struct", + utils::Vector{ + Member("inner_position", ty.vec3(), + utils::Vector{Builtin(builtin::BuiltinValue::kNumWorkgroups)}), + }); Func("ep_func", utils::Vector{ @@ -1335,7 +1339,7 @@ TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); Inspector& inspector = Build(); @@ -1349,7 +1353,7 @@ TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) { TEST_F(InspectorGetEntryPointTest, FragDepthStructReferenced) { Structure("out_struct", utils::Vector{ Member("inner_frag_depth", ty.f32(), - utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), + utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}), }); Func("ep_func", utils::Empty, ty("out_struct"), diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 265219d389..cc57ed30e9 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -3436,14 +3436,14 @@ class ProgramBuilder { /// @param source the source information /// @param builtin the builtin value /// @returns the builtin attribute pointer - const ast::BuiltinAttribute* Builtin(const Source& source, ast::BuiltinValue builtin) { + const ast::BuiltinAttribute* Builtin(const Source& source, builtin::BuiltinValue builtin) { return create(source, builtin); } /// Creates an ast::BuiltinAttribute /// @param builtin the builtin value /// @returns the builtin attribute pointer - const ast::BuiltinAttribute* Builtin(ast::BuiltinValue builtin) { + const ast::BuiltinAttribute* Builtin(builtin::BuiltinValue builtin) { return create(source_, builtin); } diff --git a/src/tint/reader/spirv/enum_converter.cc b/src/tint/reader/spirv/enum_converter.cc index 901401fba1..41792ce7d4 100644 --- a/src/tint/reader/spirv/enum_converter.cc +++ b/src/tint/reader/spirv/enum_converter.cc @@ -64,40 +64,40 @@ type::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) { return type::AddressSpace::kUndefined; } -ast::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) { +builtin::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) { switch (b) { case spv::BuiltIn::Position: - return ast::BuiltinValue::kPosition; + return builtin::BuiltinValue::kPosition; case spv::BuiltIn::VertexIndex: - return ast::BuiltinValue::kVertexIndex; + return builtin::BuiltinValue::kVertexIndex; case spv::BuiltIn::InstanceIndex: - return ast::BuiltinValue::kInstanceIndex; + return builtin::BuiltinValue::kInstanceIndex; case spv::BuiltIn::FrontFacing: - return ast::BuiltinValue::kFrontFacing; + return builtin::BuiltinValue::kFrontFacing; case spv::BuiltIn::FragCoord: - return ast::BuiltinValue::kPosition; + return builtin::BuiltinValue::kPosition; case spv::BuiltIn::FragDepth: - return ast::BuiltinValue::kFragDepth; + return builtin::BuiltinValue::kFragDepth; case spv::BuiltIn::LocalInvocationId: - return ast::BuiltinValue::kLocalInvocationId; + return builtin::BuiltinValue::kLocalInvocationId; case spv::BuiltIn::LocalInvocationIndex: - return ast::BuiltinValue::kLocalInvocationIndex; + return builtin::BuiltinValue::kLocalInvocationIndex; case spv::BuiltIn::GlobalInvocationId: - return ast::BuiltinValue::kGlobalInvocationId; + return builtin::BuiltinValue::kGlobalInvocationId; case spv::BuiltIn::NumWorkgroups: - return ast::BuiltinValue::kNumWorkgroups; + return builtin::BuiltinValue::kNumWorkgroups; case spv::BuiltIn::WorkgroupId: - return ast::BuiltinValue::kWorkgroupId; + return builtin::BuiltinValue::kWorkgroupId; case spv::BuiltIn::SampleId: - return ast::BuiltinValue::kSampleIndex; + return builtin::BuiltinValue::kSampleIndex; case spv::BuiltIn::SampleMask: - return ast::BuiltinValue::kSampleMask; + return builtin::BuiltinValue::kSampleMask; default: break; } Fail() << "unknown SPIR-V builtin: " << uint32_t(b); - return ast::BuiltinValue::kUndefined; + return builtin::BuiltinValue::kUndefined; } type::TextureDimension EnumConverter::ToDim(spv::Dim dim, bool arrayed) { diff --git a/src/tint/reader/spirv/enum_converter.h b/src/tint/reader/spirv/enum_converter.h index f3cc0374cb..7cdbfac339 100644 --- a/src/tint/reader/spirv/enum_converter.h +++ b/src/tint/reader/spirv/enum_converter.h @@ -17,8 +17,8 @@ #include "spirv/unified1/spirv.h" #include "spirv/unified1/spirv.hpp11" -#include "src/tint/ast/builtin_value.h" #include "src/tint/ast/pipeline_stage.h" +#include "src/tint/builtin/builtin_value.h" #include "src/tint/reader/spirv/fail_stream.h" #include "src/tint/type/address_space.h" #include "src/tint/type/storage_texture.h" @@ -51,7 +51,7 @@ class EnumConverter { /// On failure, logs an error and returns kNone /// @param b the SPIR-V builtin /// @returns a Tint AST builtin - ast::BuiltinValue ToBuiltin(spv::BuiltIn b); + builtin::BuiltinValue ToBuiltin(spv::BuiltIn b); /// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension. /// On failure, logs an error and returns kNone diff --git a/src/tint/reader/spirv/enum_converter_test.cc b/src/tint/reader/spirv/enum_converter_test.cc index e0982ace31..4d1a8fdfac 100644 --- a/src/tint/reader/spirv/enum_converter_test.cc +++ b/src/tint/reader/spirv/enum_converter_test.cc @@ -145,7 +145,7 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterBad, struct BuiltinCase { spv::BuiltIn builtin; bool expect_success; - ast::BuiltinValue expected; + builtin::BuiltinValue expected; }; inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) { out << "BuiltinCase{ spv::BuiltIn::" << int(bc.builtin) @@ -185,32 +185,35 @@ INSTANTIATE_TEST_SUITE_P( EnumConverterGood_Input, SpvBuiltinTest, testing::Values( - BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition}, - BuiltinCase{spv::BuiltIn::InstanceIndex, true, ast::BuiltinValue::kInstanceIndex}, - BuiltinCase{spv::BuiltIn::FrontFacing, true, ast::BuiltinValue::kFrontFacing}, - BuiltinCase{spv::BuiltIn::FragCoord, true, ast::BuiltinValue::kPosition}, - BuiltinCase{spv::BuiltIn::LocalInvocationId, true, ast::BuiltinValue::kLocalInvocationId}, + BuiltinCase{spv::BuiltIn::Position, true, builtin::BuiltinValue::kPosition}, + BuiltinCase{spv::BuiltIn::InstanceIndex, true, builtin::BuiltinValue::kInstanceIndex}, + BuiltinCase{spv::BuiltIn::FrontFacing, true, builtin::BuiltinValue::kFrontFacing}, + BuiltinCase{spv::BuiltIn::FragCoord, true, builtin::BuiltinValue::kPosition}, + BuiltinCase{spv::BuiltIn::LocalInvocationId, true, + builtin::BuiltinValue::kLocalInvocationId}, BuiltinCase{spv::BuiltIn::LocalInvocationIndex, true, - ast::BuiltinValue::kLocalInvocationIndex}, - BuiltinCase{spv::BuiltIn::GlobalInvocationId, true, ast::BuiltinValue::kGlobalInvocationId}, - BuiltinCase{spv::BuiltIn::NumWorkgroups, true, ast::BuiltinValue::kNumWorkgroups}, - BuiltinCase{spv::BuiltIn::WorkgroupId, true, ast::BuiltinValue::kWorkgroupId}, - BuiltinCase{spv::BuiltIn::SampleId, true, ast::BuiltinValue::kSampleIndex}, - BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask})); + builtin::BuiltinValue::kLocalInvocationIndex}, + BuiltinCase{spv::BuiltIn::GlobalInvocationId, true, + builtin::BuiltinValue::kGlobalInvocationId}, + BuiltinCase{spv::BuiltIn::NumWorkgroups, true, builtin::BuiltinValue::kNumWorkgroups}, + BuiltinCase{spv::BuiltIn::WorkgroupId, true, builtin::BuiltinValue::kWorkgroupId}, + BuiltinCase{spv::BuiltIn::SampleId, true, builtin::BuiltinValue::kSampleIndex}, + BuiltinCase{spv::BuiltIn::SampleMask, true, builtin::BuiltinValue::kSampleMask})); INSTANTIATE_TEST_SUITE_P( EnumConverterGood_Output, SpvBuiltinTest, - testing::Values(BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition}, - BuiltinCase{spv::BuiltIn::FragDepth, true, ast::BuiltinValue::kFragDepth}, - BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask})); + testing::Values(BuiltinCase{spv::BuiltIn::Position, true, builtin::BuiltinValue::kPosition}, + BuiltinCase{spv::BuiltIn::FragDepth, true, builtin::BuiltinValue::kFragDepth}, + BuiltinCase{spv::BuiltIn::SampleMask, true, + builtin::BuiltinValue::kSampleMask})); INSTANTIATE_TEST_SUITE_P(EnumConverterBad, SpvBuiltinTest, testing::Values(BuiltinCase{static_cast(9999), false, - ast::BuiltinValue::kUndefined}, + builtin::BuiltinValue::kUndefined}, BuiltinCase{static_cast(9999), false, - ast::BuiltinValue::kUndefined})); + builtin::BuiltinValue::kUndefined})); // Dim diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index a23ca20380..82c7310e6a 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -21,7 +21,6 @@ #include "src/tint/ast/bitcast_expression.h" #include "src/tint/ast/break_statement.h" #include "src/tint/ast/builtin_attribute.h" -#include "src/tint/ast/builtin_value.h" #include "src/tint/ast/call_statement.h" #include "src/tint/ast/continue_statement.h" #include "src/tint/ast/discard_statement.h" @@ -32,6 +31,7 @@ #include "src/tint/ast/switch_statement.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/variable_decl_statement.h" +#include "src/tint/builtin/builtin_value.h" #include "src/tint/sem/builtin_type.h" #include "src/tint/transform/spirv_atomic.h" #include "src/tint/type/depth_texture.h" @@ -760,7 +760,7 @@ struct LoopStatementBuilder final : public Castable decos) { if (auto* builtin = ast::GetAttribute(decos)) { - return builtin->builtin == ast::BuiltinValue::kSampleMask; + return builtin->builtin == builtin::BuiltinValue::kSampleMask; } return false; } @@ -1331,7 +1331,7 @@ bool FunctionEmitter::EmitEntryPointAsWrapper() { // a gl_Position variable. Substitute the type. const Type* param_type = ty_.Vector(ty_.F32(), 4); AttributeList out_decos{ - create(source, ast::BuiltinValue::kPosition)}; + create(source, builtin::BuiltinValue::kPosition)}; const auto var_name = namer_.GetName(var_id); return_members.Push( diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 2589d8e91c..8a373fdc7a 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -1699,7 +1699,7 @@ bool ParserImpl::ConvertDecorationsForVariable(uint32_t id, break; } auto ast_builtin = enum_converter_.ToBuiltin(spv_builtin); - if (ast_builtin == ast::BuiltinValue::kUndefined) { + if (ast_builtin == builtin::BuiltinValue::kUndefined) { // A diagnostic has already been emitted. return false; } diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 0fbb29f950..2fe2386233 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -1648,8 +1648,8 @@ Expect ParserImpl::expect_interpolation_type_name() { // | sample_mask // | vertex_index // | workgroup_id -Expect ParserImpl::expect_builtin() { - return expect_enum("builtin", ast::ParseBuiltinValue, ast::kBuiltinValueStrings); +Expect ParserImpl::expect_builtin() { + return expect_enum("builtin", builtin::ParseBuiltinValue, builtin::kBuiltinValueStrings); } // compound_statement diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index 455300d8dc..76654e3953 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -540,7 +540,7 @@ class ParserImpl { /// Parses a builtin identifier, erroring if the next token does not match a /// valid builtin name. /// @returns the parsed builtin. - Expect expect_builtin(); + Expect expect_builtin(); /// Parses a `compound_statement` grammar element, erroring on parse failure. /// @param use a description of what was being parsed if an error was raised /// @returns the parsed statements diff --git a/src/tint/reader/wgsl/parser_impl_param_list_test.cc b/src/tint/reader/wgsl/parser_impl_param_list_test.cc index 4829294ae1..696d79184d 100644 --- a/src/tint/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/tint/reader/wgsl/parser_impl_param_list_test.cc @@ -102,7 +102,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) { auto attrs_0 = e.value[0]->attributes; ASSERT_EQ(attrs_0.Length(), 1u); EXPECT_TRUE(attrs_0[0]->Is()); - EXPECT_EQ(attrs_0[0]->As()->builtin, ast::BuiltinValue::kPosition); + EXPECT_EQ(attrs_0[0]->As()->builtin, builtin::BuiltinValue::kPosition); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); ASSERT_EQ(e.value[0]->source.range.begin.column, 20u); diff --git a/src/tint/reader/wgsl/parser_impl_variable_attribute_list_test.cc b/src/tint/reader/wgsl/parser_impl_variable_attribute_list_test.cc index 9de2a3d5b1..163396e05a 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_attribute_list_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_attribute_list_test.cc @@ -38,7 +38,7 @@ TEST_F(ParserImplTest, AttributeList_Parses) { EXPECT_EQ(exp->value, 4u); ASSERT_TRUE(attr_1->Is()); - EXPECT_EQ(attr_1->As()->builtin, ast::BuiltinValue::kPosition); + EXPECT_EQ(attr_1->As()->builtin, builtin::BuiltinValue::kPosition); } TEST_F(ParserImplTest, AttributeList_Invalid) { diff --git a/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc b/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc index 602cc20014..bc0c2c9b8e 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc @@ -217,7 +217,7 @@ TEST_F(ParserImplTest, Attribute_Location_MissingInvalid) { struct BuiltinData { const char* input; - ast::BuiltinValue result; + builtin::BuiltinValue result; }; inline std::ostream& operator<<(std::ostream& out, BuiltinData data) { out << std::string(data.input); @@ -261,18 +261,19 @@ TEST_P(BuiltinTest, Attribute_Builtin_TrailingComma) { INSTANTIATE_TEST_SUITE_P( ParserImplTest, BuiltinTest, - testing::Values(BuiltinData{"position", ast::BuiltinValue::kPosition}, - BuiltinData{"vertex_index", ast::BuiltinValue::kVertexIndex}, - BuiltinData{"instance_index", ast::BuiltinValue::kInstanceIndex}, - BuiltinData{"front_facing", ast::BuiltinValue::kFrontFacing}, - BuiltinData{"frag_depth", ast::BuiltinValue::kFragDepth}, - BuiltinData{"local_invocation_id", ast::BuiltinValue::kLocalInvocationId}, - BuiltinData{"local_invocation_index", ast::BuiltinValue::kLocalInvocationIndex}, - BuiltinData{"global_invocation_id", ast::BuiltinValue::kGlobalInvocationId}, - BuiltinData{"workgroup_id", ast::BuiltinValue::kWorkgroupId}, - BuiltinData{"num_workgroups", ast::BuiltinValue::kNumWorkgroups}, - BuiltinData{"sample_index", ast::BuiltinValue::kSampleIndex}, - BuiltinData{"sample_mask", ast::BuiltinValue::kSampleMask})); + testing::Values(BuiltinData{"position", builtin::BuiltinValue::kPosition}, + BuiltinData{"vertex_index", builtin::BuiltinValue::kVertexIndex}, + BuiltinData{"instance_index", builtin::BuiltinValue::kInstanceIndex}, + BuiltinData{"front_facing", builtin::BuiltinValue::kFrontFacing}, + BuiltinData{"frag_depth", builtin::BuiltinValue::kFragDepth}, + BuiltinData{"local_invocation_id", builtin::BuiltinValue::kLocalInvocationId}, + BuiltinData{"local_invocation_index", + builtin::BuiltinValue::kLocalInvocationIndex}, + BuiltinData{"global_invocation_id", builtin::BuiltinValue::kGlobalInvocationId}, + BuiltinData{"workgroup_id", builtin::BuiltinValue::kWorkgroupId}, + BuiltinData{"num_workgroups", builtin::BuiltinValue::kNumWorkgroups}, + BuiltinData{"sample_index", builtin::BuiltinValue::kSampleIndex}, + BuiltinData{"sample_mask", builtin::BuiltinValue::kSampleMask})); TEST_F(ParserImplTest, Attribute_Builtin_MissingLeftParen) { auto p = parser("builtin position)"); diff --git a/src/tint/resolver/attribute_validation_test.cc b/src/tint/resolver/attribute_validation_test.cc index 0f09306ca4..2e4084e9a2 100644 --- a/src/tint/resolver/attribute_validation_test.cc +++ b/src/tint/resolver/attribute_validation_test.cc @@ -95,7 +95,7 @@ static utils::Vector createAttributes(const Source& so case AttributeKind::kBinding: return {builder.Binding(source, 1_a)}; case AttributeKind::kBuiltin: - return {builder.Builtin(source, ast::BuiltinValue::kPosition)}; + return {builder.Builtin(source, builtin::BuiltinValue::kPosition)}; case AttributeKind::kDiagnostic: return {builder.DiagnosticAttribute(source, ast::DiagnosticSeverity::kInfo, "chromium_unreachable_code")}; @@ -257,7 +257,7 @@ TEST_P(FragmentShaderParameterAttributeTest, IsValid) { auto& params = GetParam(); auto attrs = createAttributes(Source{{12, 34}}, *this, params.kind); if (params.kind != AttributeKind::kBuiltin && params.kind != AttributeKind::kLocation) { - attrs.Push(Builtin(Source{{34, 56}}, ast::BuiltinValue::kPosition)); + attrs.Push(Builtin(Source{{34, 56}}, builtin::BuiltinValue::kPosition)); } auto* p = Param("a", ty.vec4(), attrs); Func("frag_main", utils::Vector{p}, ty.void_(), utils::Empty, @@ -306,7 +306,7 @@ TEST_P(VertexShaderParameterAttributeTest, IsValid) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); if (params.should_pass) { @@ -453,7 +453,7 @@ TEST_P(VertexShaderReturnTypeAttributeTest, IsValid) { auto attrs = createAttributes(Source{{12, 34}}, *this, params.kind); // a vertex shader must include the 'position' builtin in its return type if (params.kind != AttributeKind::kBuiltin) { - attrs.Push(Builtin(Source{{34, 56}}, ast::BuiltinValue::kPosition)); + attrs.Push(Builtin(Source{{34, 56}}, builtin::BuiltinValue::kPosition)); } Func("vertex_main", utils::Empty, ty.vec4(), utils::Vector{ @@ -654,7 +654,7 @@ TEST_F(StructMemberAttributeTest, InvariantAttributeWithPosition) { Member("a", ty.vec4(), utils::Vector{ Invariant(), - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1374,7 +1374,7 @@ TEST_F(InvariantAttributeTests, InvariantWithPosition) { auto* param = Param("p", ty.vec4(), utils::Vector{ Invariant(Source{{12, 34}}), - Builtin(Source{{56, 78}}, ast::BuiltinValue::kPosition), + Builtin(Source{{56, 78}}, builtin::BuiltinValue::kPosition), }); Func("main", utils::Vector{param}, ty.vec4(), utils::Vector{ @@ -1619,7 +1619,7 @@ TEST_F(InterpolateTest, VertexOutput_Integer_MissingFlatInterpolation) { auto* s = Structure( "S", utils::Vector{ - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), Member(Source{{12, 34}}, "u", ty.u32(), utils::Vector{Location(0_a)}), }); Func("main", utils::Empty, ty.Of(s), @@ -1642,7 +1642,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_Parameter) { utils::Vector{ Param("a", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat, ast::InterpolationSampling::kUndefined), }), @@ -1666,7 +1666,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_ReturnType) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat, ast::InterpolationSampling::kUndefined), }); diff --git a/src/tint/resolver/builtins_validation_test.cc b/src/tint/resolver/builtins_validation_test.cc index 69ab01bbf2..0921c2ef7d 100644 --- a/src/tint/resolver/builtins_validation_test.cc +++ b/src/tint/resolver/builtins_validation_test.cc @@ -33,67 +33,79 @@ class ResolverBuiltinsValidationTest : public resolver::TestHelper, public testi namespace StageTest { struct Params { builder::ast_type_func_ptr type; - ast::BuiltinValue builtin; + builtin::BuiltinValue builtin; ast::PipelineStage stage; bool is_valid; }; template -constexpr Params ParamsFor(ast::BuiltinValue builtin, ast::PipelineStage stage, bool is_valid) { +constexpr Params ParamsFor(builtin::BuiltinValue builtin, ast::PipelineStage stage, bool is_valid) { return Params{DataType::AST, builtin, stage, is_valid}; } static constexpr Params cases[] = { - ParamsFor>(ast::BuiltinValue::kPosition, ast::PipelineStage::kVertex, false), - ParamsFor>(ast::BuiltinValue::kPosition, ast::PipelineStage::kFragment, true), - ParamsFor>(ast::BuiltinValue::kPosition, ast::PipelineStage::kCompute, false), + ParamsFor>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kVertex, false), + ParamsFor>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kFragment, true), + ParamsFor>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kCompute, false), - ParamsFor(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kVertex, true), - ParamsFor(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kFragment, false), - ParamsFor(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kCompute, false), + ParamsFor(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kVertex, true), + ParamsFor(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kFragment, false), + ParamsFor(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kCompute, false), - ParamsFor(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kVertex, true), - ParamsFor(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kFragment, false), - ParamsFor(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kCompute, false), + ParamsFor(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kVertex, true), + ParamsFor(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kFragment, false), + ParamsFor(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kCompute, false), - ParamsFor(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kVertex, false), - ParamsFor(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kFragment, true), - ParamsFor(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kCompute, false), + ParamsFor(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kVertex, false), + ParamsFor(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kFragment, true), + ParamsFor(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kCompute, false), - ParamsFor>(ast::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kVertex, false), - ParamsFor>(ast::BuiltinValue::kLocalInvocationId, - ast::PipelineStage::kFragment, - false), - ParamsFor>(ast::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kCompute, true), - - ParamsFor(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kVertex, false), - ParamsFor(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kFragment, false), - ParamsFor(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kCompute, true), - - ParamsFor>(ast::BuiltinValue::kGlobalInvocationId, + ParamsFor>(builtin::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kVertex, false), - ParamsFor>(ast::BuiltinValue::kGlobalInvocationId, + ParamsFor>(builtin::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kFragment, false), - ParamsFor>(ast::BuiltinValue::kGlobalInvocationId, + ParamsFor>(builtin::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kCompute, true), - ParamsFor>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kVertex, false), - ParamsFor>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kFragment, false), - ParamsFor>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kCompute, true), + ParamsFor(builtin::BuiltinValue::kLocalInvocationIndex, + ast::PipelineStage::kVertex, + false), + ParamsFor(builtin::BuiltinValue::kLocalInvocationIndex, + ast::PipelineStage::kFragment, + false), + ParamsFor(builtin::BuiltinValue::kLocalInvocationIndex, + ast::PipelineStage::kCompute, + true), - ParamsFor>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kVertex, false), - ParamsFor>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kFragment, false), - ParamsFor>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kCompute, true), + ParamsFor>(builtin::BuiltinValue::kGlobalInvocationId, + ast::PipelineStage::kVertex, + false), + ParamsFor>(builtin::BuiltinValue::kGlobalInvocationId, + ast::PipelineStage::kFragment, + false), + ParamsFor>(builtin::BuiltinValue::kGlobalInvocationId, + ast::PipelineStage::kCompute, + true), - ParamsFor(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kVertex, false), - ParamsFor(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kFragment, true), - ParamsFor(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kCompute, false), + ParamsFor>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kVertex, false), + ParamsFor>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kFragment, false), + ParamsFor>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kCompute, true), - ParamsFor(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kVertex, false), - ParamsFor(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kFragment, true), - ParamsFor(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kCompute, false), + ParamsFor>(builtin::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kVertex, false), + ParamsFor>(builtin::BuiltinValue::kNumWorkgroups, + ast::PipelineStage::kFragment, + false), + ParamsFor>(builtin::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kCompute, true), + + ParamsFor(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kVertex, false), + ParamsFor(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kFragment, true), + ParamsFor(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kCompute, false), + + ParamsFor(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kVertex, false), + ParamsFor(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kFragment, true), + ParamsFor(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kCompute, false), }; using ResolverBuiltinsStageTest = ResolverTestWithParam; @@ -108,7 +120,7 @@ TEST_P(ResolverBuiltinsStageTest, All_input) { Func("main", utils::Vector{input}, ty.vec4(), utils::Vector{Return(p)}, utils::Vector{Stage(ast::PipelineStage::kVertex)}, utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition), }); break; case ast::PipelineStage::kFragment: @@ -152,7 +164,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsInput_Fail) { utils::Vector{ Param("fd", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth), }), }, ty.f32(), @@ -182,7 +194,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsInputStruct_Fail) { utils::Vector{ Member("frag_depth", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth), }), }); @@ -217,7 +229,7 @@ TEST_F(ResolverBuiltinsValidationTest, StructBuiltinInsideEntryPoint_Ignored) { Structure("S", utils::Vector{ Member("idx", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kVertexIndex), + Builtin(builtin::BuiltinValue::kVertexIndex), }), }); @@ -241,7 +253,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionNotF32_Struct_Fail) { utils::Vector{ Member("position", ty.vec4(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition), }), }); Func("fragShader", @@ -272,7 +284,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionNotF32_ReturnType_Fail) { }, utils::Vector{Stage(ast::PipelineStage::kVertex)}, utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition), }); EXPECT_FALSE(r()->Resolve()); @@ -290,7 +302,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthNotF32_Struct_Fail) { utils::Vector{ Member("frag_depth", ty.i32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth), }), }); Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(), @@ -315,13 +327,13 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskNotU32_Struct_Fail) { // @fragment // fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; } - auto* s = Structure("MyInputs", - utils::Vector{ - Member("m", ty.f32(), - utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask), - }), - }); + auto* s = Structure( + "MyInputs", utils::Vector{ + Member("m", ty.f32(), + utils::Vector{ + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask), + }), + }); Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(), utils::Vector{ Return(1_f), @@ -345,7 +357,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskNotU32_ReturnType_Fail) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask), }); EXPECT_FALSE(r()->Resolve()); @@ -361,7 +373,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskIsNotU32_Fail) { utils::Vector{ Param("arg", ty.bool_(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask), }), }, ty.f32(), @@ -385,13 +397,13 @@ TEST_F(ResolverBuiltinsValidationTest, SampleIndexIsNotU32_Struct_Fail) { // @fragment // fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; } - auto* s = Structure("MyInputs", - utils::Vector{ - Member("m", ty.f32(), - utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleIndex), - }), - }); + auto* s = Structure( + "MyInputs", utils::Vector{ + Member("m", ty.f32(), + utils::Vector{ + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleIndex), + }), + }); Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(), utils::Vector{ Return(1_f), @@ -416,7 +428,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleIndexIsNotU32_Fail) { utils::Vector{ Param("arg", ty.bool_(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleIndex), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleIndex), }), }, ty.f32(), @@ -442,7 +454,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionIsNotF32_Fail) { utils::Vector{ Param("p", ty.vec3(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition), }), }, ty.f32(), @@ -472,7 +484,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsNotF32_Fail) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth), }); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(frag_depth) must be 'f32'"); @@ -486,18 +498,18 @@ TEST_F(ResolverBuiltinsValidationTest, VertexIndexIsNotU32_Fail) { // ) -> @builtin(kPosition) vec4 { return vec4(); } auto* p = Param("p", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); auto* vi = Param("vi", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kVertexIndex), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kVertexIndex), }); Func("main", utils::Vector{vi, p}, ty.vec4(), utils::Vector{Return(Expr("p"))}, utils::Vector{ Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(vertex_index) must be 'u32'"); @@ -511,18 +523,18 @@ TEST_F(ResolverBuiltinsValidationTest, InstanceIndexIsNotU32) { // ) -> @builtin(kPosition) vec4 { return vec4(); } auto* p = Param("p", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); auto* ii = Param("ii", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kInstanceIndex), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kInstanceIndex), }); Func("main", utils::Vector{ii, p}, ty.vec4(), utils::Vector{Return(Expr("p"))}, utils::Vector{ Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(instance_index) must be 'u32'"); @@ -538,19 +550,19 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltin_Pass) { // ) -> @builtin(frag_depth) f32 { var fd: f32; return fd; } auto* p = Param("p", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); auto* ff = Param("ff", ty.bool_(), utils::Vector{ - Builtin(ast::BuiltinValue::kFrontFacing), + Builtin(builtin::BuiltinValue::kFrontFacing), }); auto* si = Param("si", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), }); auto* sm = Param("sm", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleMask), + Builtin(builtin::BuiltinValue::kSampleMask), }); auto* var_fd = Var("fd", ty.f32()); Func("fs_main", utils::Vector{p, ff, si, sm}, ty.f32(), @@ -562,7 +574,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltin_Pass) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); } @@ -575,12 +587,12 @@ TEST_F(ResolverBuiltinsValidationTest, VertexBuiltin_Pass) { // ) -> @builtin(position) vec4 { var p :vec4; return p; } auto* vi = Param("vi", ty.u32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kVertexIndex), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kVertexIndex), }); auto* ii = Param("ii", ty.u32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kInstanceIndex), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kInstanceIndex), }); auto* p = Var("p", ty.vec4()); Func("main", utils::Vector{vi, ii}, ty.vec4(), @@ -590,7 +602,7 @@ TEST_F(ResolverBuiltinsValidationTest, VertexBuiltin_Pass) { }, utils::Vector{Stage(ast::PipelineStage::kVertex)}, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -608,23 +620,23 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_Pass) { auto* li_id = Param("li_id", ty.vec3(), utils::Vector{ - Builtin(ast::BuiltinValue::kLocalInvocationId), + Builtin(builtin::BuiltinValue::kLocalInvocationId), }); auto* li_index = Param("li_index", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kLocalInvocationIndex), + Builtin(builtin::BuiltinValue::kLocalInvocationIndex), }); auto* gi = Param("gi", ty.vec3(), utils::Vector{ - Builtin(ast::BuiltinValue::kGlobalInvocationId), + Builtin(builtin::BuiltinValue::kGlobalInvocationId), }); auto* wi = Param("wi", ty.vec3(), utils::Vector{ - Builtin(ast::BuiltinValue::kWorkgroupId), + Builtin(builtin::BuiltinValue::kWorkgroupId), }); auto* nwgs = Param("nwgs", ty.vec3(), utils::Vector{ - Builtin(ast::BuiltinValue::kNumWorkgroups), + Builtin(builtin::BuiltinValue::kNumWorkgroups), }); Func("main", utils::Vector{li_id, li_index, gi, wi, nwgs}, ty.void_(), utils::Empty, @@ -637,7 +649,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_Pass) { TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_WorkGroupIdNotVec3U32) { auto* wi = Param("wi", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kWorkgroupId), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kWorkgroupId), }); Func("main", utils::Vector{wi}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), @@ -652,7 +664,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_WorkGroupIdNotVec3U32) { TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_NumWorkgroupsNotVec3U32) { auto* nwgs = Param("nwgs", ty.f32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kNumWorkgroups), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kNumWorkgroups), }); Func("main", utils::Vector{nwgs}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), @@ -667,7 +679,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_NumWorkgroupsNotVec3U32) { TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_GlobalInvocationNotVec3U32) { auto* gi = Param("gi", ty.vec3(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kGlobalInvocationId), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kGlobalInvocationId), }); Func("main", utils::Vector{gi}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), @@ -680,10 +692,11 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_GlobalInvocationNotVec3U32 } TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationIndexNotU32) { - auto* li_index = Param("li_index", ty.vec3(), - utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kLocalInvocationIndex), - }); + auto* li_index = + Param("li_index", ty.vec3(), + utils::Vector{ + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kLocalInvocationIndex), + }); Func("main", utils::Vector{li_index}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), WorkgroupSize(Expr(Source{Source::Location{12, 34}}, 2_i))}); @@ -697,7 +710,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationIndexNotU32 TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationNotVec3U32) { auto* li_id = Param("li_id", ty.vec2(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kLocalInvocationId), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kLocalInvocationId), }); Func("main", utils::Vector{li_id}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), @@ -722,19 +735,19 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltinStruct_Pass) { auto* s = Structure("MyInputs", utils::Vector{ Member("position", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }), Member("front_facing", ty.bool_(), utils::Vector{ - Builtin(ast::BuiltinValue::kFrontFacing), + Builtin(builtin::BuiltinValue::kFrontFacing), }), Member("sample_index", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), }), Member("sample_mask", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleMask), + Builtin(builtin::BuiltinValue::kSampleMask), }), }); Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(), @@ -758,7 +771,7 @@ TEST_F(ResolverBuiltinsValidationTest, FrontFacingParamIsNotBool_Fail) { auto* is_front = Param("is_front", ty.i32(), utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFrontFacing), + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFrontFacing), }); Func("fs_main", utils::Vector{is_front}, ty.f32(), utils::Vector{ @@ -782,13 +795,13 @@ TEST_F(ResolverBuiltinsValidationTest, FrontFacingMemberIsNotBool_Fail) { // @fragment // fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; } - auto* s = Structure("MyInputs", - utils::Vector{ - Member("pos", ty.f32(), - utils::Vector{ - Builtin(Source{{12, 34}}, ast::BuiltinValue::kFrontFacing), - }), - }); + auto* s = Structure( + "MyInputs", utils::Vector{ + Member("pos", ty.f32(), + utils::Vector{ + Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFrontFacing), + }), + }); Func("fragShader", utils::Vector{Param("is_front", ty.Of(s))}, ty.f32(), utils::Vector{ Return(1_f), diff --git a/src/tint/resolver/entry_point_validation_test.cc b/src/tint/resolver/entry_point_validation_test.cc index 2ca3e93b75..ebf2c93b6a 100644 --- a/src/tint/resolver/entry_point_validation_test.cc +++ b/src/tint/resolver/entry_point_validation_test.cc @@ -74,7 +74,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Builtin) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -111,7 +111,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Multiple) { }, utils::Vector{ Location(Source{{13, 43}}, 0_a), - Builtin(Source{{14, 52}}, ast::BuiltinValue::kPosition), + Builtin(Source{{14, 52}}, builtin::BuiltinValue::kPosition), }); EXPECT_FALSE(r()->Resolve()); @@ -129,10 +129,11 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_Valid) { // return Output(); // } auto* output = Structure( - "Output", utils::Vector{ - Member("a", ty.f32(), utils::Vector{Location(0_a)}), - Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), - }); + "Output", + utils::Vector{ + Member("a", ty.f32(), utils::Vector{Location(0_a)}), + Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}), + }); Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), utils::Vector{ Return(Call(ty.Of(output))), @@ -157,7 +158,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_MemberMultipleAttribu utils::Vector{ Member("a", ty.f32(), utils::Vector{Location(Source{{13, 43}}, 0_a), - Builtin(Source{{14, 52}}, ast::BuiltinValue::kFragDepth)}), + Builtin(Source{{14, 52}}, builtin::BuiltinValue::kFragDepth)}), }); Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), utils::Vector{ @@ -211,10 +212,11 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_DuplicateBuiltins) { // return Output(); // } auto* output = Structure( - "Output", utils::Vector{ - Member("a", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), - Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), - }); + "Output", + utils::Vector{ + Member("a", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}), + Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}), + }); Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), utils::Vector{ Return(Call(ty.Of(output))), @@ -272,7 +274,7 @@ TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Multiple) { auto* param = Param("param", ty.u32(), utils::Vector{ Location(Source{{13, 43}}, 0_a), - Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex), + Builtin(Source{{14, 52}}, builtin::BuiltinValue::kSampleIndex), }); Func(Source{{12, 34}}, "main", utils::Vector{ @@ -296,10 +298,11 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_Valid) { // @fragment // fn main(param : Input) {} auto* input = Structure( - "Input", utils::Vector{ - Member("a", ty.f32(), utils::Vector{Location(0_a)}), - Member("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), - }); + "Input", + utils::Vector{ + Member("a", ty.f32(), utils::Vector{Location(0_a)}), + Member("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}), + }); auto* param = Param("param", ty.Of(input)); Func(Source{{12, 34}}, "main", utils::Vector{ @@ -324,7 +327,7 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_MemberMultipleAttribut utils::Vector{ Member("a", ty.u32(), utils::Vector{Location(Source{{13, 43}}, 0_a), - Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex)}), + Builtin(Source{{14, 52}}, builtin::BuiltinValue::kSampleIndex)}), }); auto* param = Param("param", ty.Of(input)); Func(Source{{12, 34}}, "main", @@ -375,11 +378,11 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_DuplicateBuiltins) { // @builtin(sample_index) param_b : u32) {} auto* param_a = Param("param_a", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), }); auto* param_b = Param("param_b", ty.u32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), }); Func(Source{{12, 34}}, "main", utils::Vector{ @@ -409,12 +412,12 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_DuplicateBuiltins) { auto* input_a = Structure( "InputA", utils::Vector{ - Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), + Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}), }); auto* input_b = Structure( "InputB", utils::Vector{ - Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), + Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}), }); auto* param_a = Param("param_a", ty.Of(input_a)); auto* param_b = Param("param_b", ty.Of(input_b)); @@ -984,10 +987,11 @@ TEST_F(LocationAttributeTests, ReturnType_Struct_Valid) { // return Output(); // } auto* output = Structure( - "Output", utils::Vector{ - Member("a", ty.f32(), utils::Vector{Location(0_a)}), - Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), - }); + "Output", + utils::Vector{ + Member("a", ty.f32(), utils::Vector{Location(0_a)}), + Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}), + }); Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), utils::Vector{ Return(Call(ty.Of(output))), diff --git a/src/tint/resolver/function_validation_test.cc b/src/tint/resolver/function_validation_test.cc index 511d37945f..961511d2e4 100644 --- a/src/tint/resolver/function_validation_test.cc +++ b/src/tint/resolver/function_validation_test.cc @@ -188,7 +188,7 @@ TEST_F(ResolverFunctionValidationTest, DiscardCalledDirectlyFromVertexEntryPoint Return(Call(ty.vec4())), }, utils::Vector{Stage(ast::PipelineStage::kVertex)}, - utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index 3d327998d6..c0d48bcec4 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -873,7 +873,8 @@ TEST_F(ResolverTest, Function_Parameters) { TEST_F(ResolverTest, Function_Parameters_Locations) { auto* param_a = Param("a", ty.f32(), utils::Vector{Location(3_a)}); - auto* param_b = Param("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kVertexIndex)}); + auto* param_b = + Param("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)}); auto* param_c = Param("c", ty.u32(), utils::Vector{Location(1_a)}); GlobalVar("my_vec", ty.vec4(), type::AddressSpace::kPrivate); @@ -891,7 +892,7 @@ TEST_F(ResolverTest, Function_Parameters_Locations) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -974,7 +975,7 @@ TEST_F(ResolverTest, Function_ReturnType_NoLocation) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/struct_pipeline_stage_use_test.cc b/src/tint/resolver/struct_pipeline_stage_use_test.cc index 1ffc90747f..90e9505c9d 100644 --- a/src/tint/resolver/struct_pipeline_stage_use_test.cc +++ b/src/tint/resolver/struct_pipeline_stage_use_test.cc @@ -69,7 +69,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderParam) { Func("main", utils::Vector{Param("param", ty.Of(s))}, ty.vec4(), utils::Vector{Return(Call(ty.vec4()))}, utils::Vector{Stage(ast::PipelineStage::kVertex)}, - utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -80,9 +80,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderParam) { } TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderReturnType) { - auto* s = - Structure("S", utils::Vector{Member("a", ty.vec4(), - utils::Vector{Builtin(ast::BuiltinValue::kPosition)})}); + auto* s = Structure( + "S", utils::Vector{Member("a", ty.vec4(), + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})}); Func("main", utils::Empty, ty.Of(s), utils::Vector{Return(Call(ty.Of(s)))}, utils::Vector{Stage(ast::PipelineStage::kVertex)}); @@ -125,8 +125,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) { auto* s = Structure( - "S", utils::Vector{Member( - "a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kLocalInvocationIndex)})}); + "S", + utils::Vector{Member( + "a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kLocalInvocationIndex)})}); Func("main", utils::Vector{Param("param", ty.Of(s))}, ty.void_(), utils::Empty, utils::Vector{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1_i)}); @@ -140,9 +141,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) { } TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) { - auto* s = - Structure("S", utils::Vector{Member("a", ty.vec4(), - utils::Vector{Builtin(ast::BuiltinValue::kPosition)})}); + auto* s = Structure( + "S", utils::Vector{Member("a", ty.vec4(), + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})}); Func("vert_main", utils::Empty, ty.Of(s), utils::Vector{Return(Call(ty.Of(s)))}, utils::Vector{Stage(ast::PipelineStage::kVertex)}); diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index 0b8fd7f991..61e0dad810 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -1148,8 +1148,8 @@ class UniformityGraph { auto has_nonuniform_entry_point_attribute = [](auto* obj) { // Only the num_workgroups and workgroup_id builtins are uniform. if (auto* builtin = ast::GetAttribute(obj->attributes)) { - if (builtin->builtin == ast::BuiltinValue::kNumWorkgroups || - builtin->builtin == ast::BuiltinValue::kWorkgroupId) { + if (builtin->builtin == builtin::BuiltinValue::kNumWorkgroups || + builtin->builtin == builtin::BuiltinValue::kWorkgroupId) { return false; } } diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index 634e3a2f16..73fa9b879e 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -75,7 +75,7 @@ TEST_F(ResolverValidationTest, WorkgroupMemoryUsedInVertexStage) { Stage(ast::PipelineStage::kVertex), }, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 0a7abcf56c..2a73bead68 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -868,7 +868,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, bool is_stage_mismatch = false; bool is_output = !is_input; switch (attr->builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: if (stage != ast::PipelineStage::kNone && !((is_input && stage == ast::PipelineStage::kFragment) || (is_output && stage == ast::PipelineStage::kVertex))) { @@ -880,10 +880,10 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kGlobalInvocationId: - case ast::BuiltinValue::kLocalInvocationId: - case ast::BuiltinValue::kNumWorkgroups: - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kNumWorkgroups: + case builtin::BuiltinValue::kWorkgroupId: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kCompute && is_input)) { is_stage_mismatch = true; @@ -894,7 +894,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kFragment && !is_input)) { is_stage_mismatch = true; @@ -904,7 +904,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kFragment && is_input)) { is_stage_mismatch = true; @@ -914,7 +914,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kCompute && is_input)) { is_stage_mismatch = true; @@ -924,8 +924,8 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kVertexIndex: - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kInstanceIndex: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kVertex && is_input)) { is_stage_mismatch = true; @@ -935,7 +935,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kFragment)) { is_stage_mismatch = true; } @@ -944,7 +944,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr, return false; } break; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kFragment && is_input)) { is_stage_mismatch = true; @@ -1076,7 +1076,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage) // order to catch conflicts. // TODO(jrprice): This state could be stored in sem::Function instead, and then passed to // sem::Function since it would be useful there too. - utils::Hashset builtins; + utils::Hashset builtins; utils::Hashset locations; enum class ParamOrRetType { kParameter, @@ -1211,7 +1211,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage) bool has_position = false; if (pipeline_io_attribute) { if (auto* builtin = pipeline_io_attribute->As()) { - has_position = (builtin->builtin == ast::BuiltinValue::kPosition); + has_position = (builtin->builtin == builtin::BuiltinValue::kPosition); } } if (!has_position) { @@ -1275,13 +1275,13 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage) } if (decl->PipelineStage() == ast::PipelineStage::kVertex && - !builtins.Contains(ast::BuiltinValue::kPosition)) { + !builtins.Contains(builtin::BuiltinValue::kPosition)) { // Check module-scope variables, as the SPIR-V sanitizer generates these. bool found = false; for (auto* global : func->TransitivelyReferencedGlobals()) { if (auto* builtin = ast::GetAttribute(global->Declaration()->attributes)) { - if (builtin->builtin == ast::BuiltinValue::kPosition) { + if (builtin->builtin == builtin::BuiltinValue::kPosition) { found = true; break; } @@ -2123,7 +2123,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons /* is_input */ false)) { return false; } - if (builtin->builtin == ast::BuiltinValue::kPosition) { + if (builtin->builtin == builtin::BuiltinValue::kPosition) { has_position = true; } return true; diff --git a/src/tint/transform/canonicalize_entry_point_io.cc b/src/tint/transform/canonicalize_entry_point_io.cc index 81c2821ed9..049e9ca1dd 100644 --- a/src/tint/transform/canonicalize_entry_point_io.cc +++ b/src/tint/transform/canonicalize_entry_point_io.cc @@ -47,33 +47,33 @@ struct MemberInfo { /// FXC is sensitive to field order in structures, this is used by StructMemberComparator to ensure /// that FXC is happy with the order of emitted fields. -uint32_t BuiltinOrder(ast::BuiltinValue builtin) { +uint32_t BuiltinOrder(builtin::BuiltinValue builtin) { switch (builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: return 1; - case ast::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kVertexIndex: return 2; - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kInstanceIndex: return 3; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: return 4; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: return 5; - case ast::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: return 6; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: return 7; - case ast::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kGlobalInvocationId: return 8; - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kWorkgroupId: return 9; - case ast::BuiltinValue::kNumWorkgroups: + case builtin::BuiltinValue::kNumWorkgroups: return 10; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: return 11; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: return 12; - case ast::BuiltinValue::kPointSize: + case builtin::BuiltinValue::kPointSize: return 13; default: break; @@ -118,7 +118,7 @@ bool IsShaderIOAttribute(const ast::Attribute* attr) { // Returns true if `attrs` contains a `sample_mask` builtin. bool HasSampleMask(utils::VectorRef attrs) { auto* builtin = ast::GetAttribute(attrs); - return builtin && builtin->builtin == ast::BuiltinValue::kSampleMask; + return builtin && builtin->builtin == builtin::BuiltinValue::kSampleMask; } } // namespace @@ -244,7 +244,7 @@ struct CanonicalizeEntryPointIO::State { if (builtin) { if (cfg.shader_style == ShaderStyle::kGlsl) { value = FromGLSLBuiltin(builtin->builtin, value, ast_type); - } else if (builtin->builtin == ast::BuiltinValue::kSampleMask) { + } else if (builtin->builtin == builtin::BuiltinValue::kSampleMask) { // Vulkan requires the type of a SampleMask builtin to be an array. // Declare it as array and then load the first element. ast_type = ctx.dst->ty.array(ast_type, 1_u); @@ -422,7 +422,7 @@ struct CanonicalizeEntryPointIO::State { // No existing sample mask builtin was found, so create a new output value // using the fixed sample mask. AddOutput("fixed_sample_mask", ctx.dst->create(), std::nullopt, - {ctx.dst->Builtin(ast::BuiltinValue::kSampleMask)}, + {ctx.dst->Builtin(builtin::BuiltinValue::kSampleMask)}, ctx.dst->Expr(u32(cfg.fixed_sample_mask))); } @@ -430,7 +430,7 @@ struct CanonicalizeEntryPointIO::State { void AddVertexPointSize() { // Create a new output value and assign it a literal 1.0 value. AddOutput("vertex_point_size", ctx.dst->create(), std::nullopt, - {ctx.dst->Builtin(ast::BuiltinValue::kPointSize)}, ctx.dst->Expr(1_f)); + {ctx.dst->Builtin(builtin::BuiltinValue::kPointSize)}, ctx.dst->Expr(1_f)); } /// Create an expression for gl_Position.[component] @@ -675,11 +675,11 @@ struct CanonicalizeEntryPointIO::State { /// @param stage the current pipeline stage /// @param address_space the address space (input or output) /// @returns the gl_ string corresponding to that builtin - const char* GLSLBuiltinToString(ast::BuiltinValue builtin, + const char* GLSLBuiltinToString(builtin::BuiltinValue builtin, ast::PipelineStage stage, type::AddressSpace address_space) { switch (builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: switch (stage) { case ast::PipelineStage::kVertex: return "gl_Position"; @@ -688,27 +688,27 @@ struct CanonicalizeEntryPointIO::State { default: return ""; } - case ast::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kVertexIndex: return "gl_VertexID"; - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kInstanceIndex: return "gl_InstanceID"; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: return "gl_FrontFacing"; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: return "gl_FragDepth"; - case ast::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: return "gl_LocalInvocationID"; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: return "gl_LocalInvocationIndex"; - case ast::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kGlobalInvocationId: return "gl_GlobalInvocationID"; - case ast::BuiltinValue::kNumWorkgroups: + case builtin::BuiltinValue::kNumWorkgroups: return "gl_NumWorkGroups"; - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kWorkgroupId: return "gl_WorkGroupID"; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: return "gl_SampleID"; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: if (address_space == type::AddressSpace::kIn) { return "gl_SampleMaskIn"; } else { @@ -725,18 +725,18 @@ struct CanonicalizeEntryPointIO::State { /// @param ast_type (inout) the incoming WGSL and outgoing GLSL types /// @returns an expression representing the GLSL builtin converted to what /// WGSL expects - const ast::Expression* FromGLSLBuiltin(ast::BuiltinValue builtin, + const ast::Expression* FromGLSLBuiltin(builtin::BuiltinValue builtin, const ast::Expression* value, ast::Type& ast_type) { switch (builtin) { - case ast::BuiltinValue::kVertexIndex: - case ast::BuiltinValue::kInstanceIndex: - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kSampleIndex: // GLSL uses i32 for these, so bitcast to u32. value = ctx.dst->Bitcast(ast_type, value); ast_type = ctx.dst->ty.i32(); break; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: // gl_SampleMask is an array of i32. Retrieve the first element and // bitcast it to u32. value = ctx.dst->IndexAccessor(value, 0_i); @@ -755,14 +755,14 @@ struct CanonicalizeEntryPointIO::State { /// @param value the value to convert /// @param type (out) the type to which the value was converted /// @returns the converted value which can be assigned to the GLSL builtin - const ast::Expression* ToGLSLBuiltin(ast::BuiltinValue builtin, + const ast::Expression* ToGLSLBuiltin(builtin::BuiltinValue builtin, const ast::Expression* value, const type::Type*& type) { switch (builtin) { - case ast::BuiltinValue::kVertexIndex: - case ast::BuiltinValue::kInstanceIndex: - case ast::BuiltinValue::kSampleIndex: - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleMask: type = ctx.dst->create(); value = ctx.dst->Bitcast(CreateASTTypeFor(ctx, type), value); break; diff --git a/src/tint/transform/clamp_frag_depth.cc b/src/tint/transform/clamp_frag_depth.cc index 0b8d8f747e..feacf82f01 100644 --- a/src/tint/transform/clamp_frag_depth.cc +++ b/src/tint/transform/clamp_frag_depth.cc @@ -18,10 +18,10 @@ #include "src/tint/ast/attribute.h" #include "src/tint/ast/builtin_attribute.h" -#include "src/tint/ast/builtin_value.h" #include "src/tint/ast/function.h" #include "src/tint/ast/module.h" #include "src/tint/ast/struct.h" +#include "src/tint/builtin/builtin_value.h" #include "src/tint/program_builder.h" #include "src/tint/sem/function.h" #include "src/tint/sem/statement.h" @@ -38,7 +38,7 @@ namespace { bool ContainsFragDepth(utils::VectorRef attributes) { for (auto* attribute : attributes) { if (auto* builtin_attribute = attribute->As()) { - if (builtin_attribute->builtin == ast::BuiltinValue::kFragDepth) { + if (builtin_attribute->builtin == builtin::BuiltinValue::kFragDepth) { return true; } } diff --git a/src/tint/transform/first_index_offset.cc b/src/tint/transform/first_index_offset.cc index afc946da06..e739faec79 100644 --- a/src/tint/transform/first_index_offset.cc +++ b/src/tint/transform/first_index_offset.cc @@ -88,13 +88,13 @@ Transform::ApplyResult FirstIndexOffset::Apply(const Program* src, if (auto* var = node->As()) { for (auto* attr : var->attributes) { if (auto* builtin_attr = attr->As()) { - ast::BuiltinValue builtin = builtin_attr->builtin; - if (builtin == ast::BuiltinValue::kVertexIndex) { + builtin::BuiltinValue builtin = builtin_attr->builtin; + if (builtin == builtin::BuiltinValue::kVertexIndex) { auto* sem_var = ctx.src->Sem().Get(var); builtin_vars.emplace(sem_var, kFirstVertexName); has_vertex_or_instance_index = true; } - if (builtin == ast::BuiltinValue::kInstanceIndex) { + if (builtin == builtin::BuiltinValue::kInstanceIndex) { auto* sem_var = ctx.src->Sem().Get(var); builtin_vars.emplace(sem_var, kFirstInstanceName); has_vertex_or_instance_index = true; @@ -105,13 +105,13 @@ Transform::ApplyResult FirstIndexOffset::Apply(const Program* src, if (auto* member = node->As()) { for (auto* attr : member->attributes) { if (auto* builtin_attr = attr->As()) { - ast::BuiltinValue builtin = builtin_attr->builtin; - if (builtin == ast::BuiltinValue::kVertexIndex) { + builtin::BuiltinValue builtin = builtin_attr->builtin; + if (builtin == builtin::BuiltinValue::kVertexIndex) { auto* sem_mem = ctx.src->Sem().Get(member); builtin_members.emplace(sem_mem, kFirstVertexName); has_vertex_or_instance_index = true; } - if (builtin == ast::BuiltinValue::kInstanceIndex) { + if (builtin == builtin::BuiltinValue::kInstanceIndex) { auto* sem_mem = ctx.src->Sem().Get(member); builtin_members.emplace(sem_mem, kFirstInstanceName); has_vertex_or_instance_index = true; diff --git a/src/tint/transform/num_workgroups_from_uniform.cc b/src/tint/transform/num_workgroups_from_uniform.cc index 72b32dfd8b..35e59fbc30 100644 --- a/src/tint/transform/num_workgroups_from_uniform.cc +++ b/src/tint/transform/num_workgroups_from_uniform.cc @@ -33,7 +33,7 @@ namespace { bool ShouldRun(const Program* program) { for (auto* node : program->ASTNodes().Objects()) { if (auto* attr = node->As()) { - if (attr->builtin == ast::BuiltinValue::kNumWorkgroups) { + if (attr->builtin == builtin::BuiltinValue::kNumWorkgroups) { return true; } } @@ -100,7 +100,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src, for (auto* member : str->Members()) { auto* builtin = ast::GetAttribute(member->Declaration()->attributes); - if (!builtin || builtin->builtin != ast::BuiltinValue::kNumWorkgroups) { + if (!builtin || builtin->builtin != builtin::BuiltinValue::kNumWorkgroups) { continue; } diff --git a/src/tint/transform/vertex_pulling.cc b/src/tint/transform/vertex_pulling.cc index 11984cdaef..8d151bf37f 100644 --- a/src/tint/transform/vertex_pulling.cc +++ b/src/tint/transform/vertex_pulling.cc @@ -778,11 +778,11 @@ struct VertexPulling::State { return; } // Check for existing vertex_index and instance_index builtins. - if (builtin->builtin == ast::BuiltinValue::kVertexIndex) { + if (builtin->builtin == builtin::BuiltinValue::kVertexIndex) { vertex_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->name->symbol)); }; - } else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) { + } else if (builtin->builtin == builtin::BuiltinValue::kInstanceIndex) { instance_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->name->symbol)); }; @@ -831,9 +831,9 @@ struct VertexPulling::State { return; } // Check for existing vertex_index and instance_index builtins. - if (builtin->builtin == ast::BuiltinValue::kVertexIndex) { + if (builtin->builtin == builtin::BuiltinValue::kVertexIndex) { vertex_index_expr = member_expr; - } else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) { + } else if (builtin->builtin == builtin::BuiltinValue::kInstanceIndex) { instance_index_expr = member_expr; } members_to_clone.Push(member); @@ -899,7 +899,7 @@ struct VertexPulling::State { auto name = b.Symbols().New("tint_pulling_vertex_index"); new_function_parameters.Push( b.Param(name, b.ty.u32(), - utils::Vector{b.Builtin(ast::BuiltinValue::kVertexIndex)})); + utils::Vector{b.Builtin(builtin::BuiltinValue::kVertexIndex)})); vertex_index_expr = [this, name]() { return b.Expr(name); }; break; } @@ -911,7 +911,7 @@ struct VertexPulling::State { auto name = b.Symbols().New("tint_pulling_instance_index"); new_function_parameters.Push( b.Param(name, b.ty.u32(), - utils::Vector{b.Builtin(ast::BuiltinValue::kInstanceIndex)})); + utils::Vector{b.Builtin(builtin::BuiltinValue::kInstanceIndex)})); instance_index_expr = [this, name]() { return b.Expr(name); }; break; } diff --git a/src/tint/transform/zero_init_workgroup_memory.cc b/src/tint/transform/zero_init_workgroup_memory.cc index e4943a7fb1..49d96d901f 100644 --- a/src/tint/transform/zero_init_workgroup_memory.cc +++ b/src/tint/transform/zero_init_workgroup_memory.cc @@ -159,7 +159,7 @@ struct ZeroInitWorkgroupMemory::State { std::function local_index; for (auto* param : fn->params) { if (auto* builtin = ast::GetAttribute(param->attributes)) { - if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) { + if (builtin->builtin == builtin::BuiltinValue::kLocalInvocationIndex) { local_index = [=] { return b.Expr(ctx.Clone(param->name->symbol)); }; break; } @@ -169,7 +169,7 @@ struct ZeroInitWorkgroupMemory::State { for (auto* member : str->Members()) { if (auto* builtin = ast::GetAttribute( member->Declaration()->attributes)) { - if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) { + if (builtin->builtin == builtin::BuiltinValue::kLocalInvocationIndex) { local_index = [=] { auto* param_expr = b.Expr(ctx.Clone(param->name->symbol)); auto* member_name = ctx.Clone(member->Declaration()->name); @@ -185,7 +185,7 @@ struct ZeroInitWorkgroupMemory::State { // No existing local index parameter. Append one to the entry point. auto* param = b.Param(b.Symbols().New("local_invocation_index"), b.ty.u32(), utils::Vector{ - b.Builtin(ast::BuiltinValue::kLocalInvocationIndex), + b.Builtin(builtin::BuiltinValue::kLocalInvocationIndex), }); ctx.InsertBack(fn->params, param); local_index = [=] { return b.Expr(param->name->symbol); }; diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 58479234a6..1ea30d402c 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -90,10 +90,10 @@ bool IsRelational(tint::ast::BinaryOp op) { op == tint::ast::BinaryOp::kGreaterThanEqual; } -bool RequiresOESSampleVariables(tint::ast::BuiltinValue builtin) { +bool RequiresOESSampleVariables(tint::builtin::BuiltinValue builtin) { switch (builtin) { - case tint::ast::BuiltinValue::kSampleIndex: - case tint::ast::BuiltinValue::kSampleMask: + case tint::builtin::BuiltinValue::kSampleIndex: + case tint::builtin::BuiltinValue::kSampleMask: return true; default: return false; diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index e972b12e3e..71fb23e980 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -471,11 +471,11 @@ class GeneratorImpl : public TextGenerator { /// @param builtin the builtin to convert /// @param stage pipeline stage in which this builtin is used /// @returns the string name of the builtin or blank on error - const char* builtin_to_string(ast::BuiltinValue builtin, ast::PipelineStage stage); + const char* builtin_to_string(builtin::BuiltinValue builtin, ast::PipelineStage stage); /// Converts a builtin to a type::Type appropriate for GLSL. /// @param builtin the builtin to convert /// @returns the appropriate semantic type or null on error. - type::Type* builtin_type(ast::BuiltinValue builtin); + type::Type* builtin_type(builtin::BuiltinValue builtin); private: enum class VarType { kIn, kOut }; diff --git a/src/tint/writer/glsl/generator_impl_function_test.cc b/src/tint/writer/glsl/generator_impl_function_test.cc index db16749523..2d1ed02d48 100644 --- a/src/tint/writer/glsl/generator_impl_function_test.cc +++ b/src/tint/writer/glsl/generator_impl_function_test.cc @@ -166,7 +166,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built // return coord.x; // } auto* coord_in = - Param("coord", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); + Param("coord", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}); Func("frag_main", utils::Vector{ coord_in, @@ -179,7 +179,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); GeneratorImpl& gen = SanitizeAndBuild(); @@ -217,7 +217,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_Di auto* interface_struct = Structure( "Interface", utils::Vector{ - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), Member("col1", ty.f32(), utils::Vector{Location(1_a)}), Member("col2", ty.f32(), utils::Vector{Location(2_a)}), }); @@ -297,7 +297,7 @@ TEST_F(GlslGeneratorImplTest_Function, // } auto* vertex_output_struct = Structure( "VertexOutput", - {Member("pos", ty.vec4(), {Builtin(ast::BuiltinValue::kPosition)})}); + {Member("pos", ty.vec4(), {Builtin(builtin::BuiltinValue::kPosition)})}); Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct), {Return(Call(ty.Of(vertex_output_struct), diff --git a/src/tint/writer/glsl/generator_impl_test.cc b/src/tint/writer/glsl/generator_impl_test.cc index abb391faa3..b449253d70 100644 --- a/src/tint/writer/glsl/generator_impl_test.cc +++ b/src/tint/writer/glsl/generator_impl_test.cc @@ -59,7 +59,7 @@ void my_func() { TEST_F(GlslGeneratorImplTest, GenerateSampleIndexES) { GlobalVar("gl_SampleID", ty.i32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), Disable(ast::DisabledValidation::kIgnoreAddressSpace), }, type::AddressSpace::kIn); @@ -84,7 +84,7 @@ int my_func() { TEST_F(GlslGeneratorImplTest, GenerateSampleIndexDesktop) { GlobalVar("gl_SampleID", ty.i32(), utils::Vector{ - Builtin(ast::BuiltinValue::kSampleIndex), + Builtin(builtin::BuiltinValue::kSampleIndex), Disable(ast::DisabledValidation::kIgnoreAddressSpace), }, type::AddressSpace::kIn); diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 4e37faa879..ad1d50dead 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -3154,29 +3154,29 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { return true; } -std::string GeneratorImpl::builtin_to_attribute(ast::BuiltinValue builtin) const { +std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) const { switch (builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: return "SV_Position"; - case ast::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kVertexIndex: return "SV_VertexID"; - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kInstanceIndex: return "SV_InstanceID"; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: return "SV_IsFrontFace"; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: return "SV_Depth"; - case ast::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: return "SV_GroupThreadID"; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: return "SV_GroupIndex"; - case ast::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kGlobalInvocationId: return "SV_DispatchThreadID"; - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kWorkgroupId: return "SV_GroupID"; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: return "SV_SampleIndex"; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: return "SV_Coverage"; default: break; diff --git a/src/tint/writer/hlsl/generator_impl.h b/src/tint/writer/hlsl/generator_impl.h index 7b2d97fa35..b5f53bfd4d 100644 --- a/src/tint/writer/hlsl/generator_impl.h +++ b/src/tint/writer/hlsl/generator_impl.h @@ -495,7 +495,7 @@ class GeneratorImpl : public TextGenerator { /// Converts a builtin to an attribute name /// @param builtin the builtin to convert /// @returns the string name of the builtin or blank on error - std::string builtin_to_attribute(ast::BuiltinValue builtin) const; + std::string builtin_to_attribute(builtin::BuiltinValue builtin) const; /// Converts interpolation attributes to a HLSL modifiers /// @param type the interpolation type diff --git a/src/tint/writer/hlsl/generator_impl_function_test.cc b/src/tint/writer/hlsl/generator_impl_function_test.cc index bf9eb7ab89..afad67cf5a 100644 --- a/src/tint/writer/hlsl/generator_impl_function_test.cc +++ b/src/tint/writer/hlsl/generator_impl_function_test.cc @@ -157,7 +157,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built // return coord.x; // } auto* coord_in = - Param("coord", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); + Param("coord", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}); Func("frag_main", utils::Vector{coord_in}, ty.f32(), utils::Vector{ Return(MemberAccessor("coord", "x")), @@ -166,7 +166,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); GeneratorImpl& gen = SanitizeAndBuild(); @@ -209,7 +209,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_Di auto* interface_struct = Structure( "Interface", utils::Vector{ - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), Member("col1", ty.f32(), utils::Vector{Location(1_a)}), Member("col2", ty.f32(), utils::Vector{Location(2_a)}), }); @@ -292,7 +292,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_He auto* vertex_output_struct = Structure("VertexOutput", utils::Vector{Member("pos", ty.vec4(), - utils::Vector{Builtin(ast::BuiltinValue::kPosition)})}); + utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})}); Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct), utils::Vector{ diff --git a/src/tint/writer/hlsl/generator_impl_test.cc b/src/tint/writer/hlsl/generator_impl_test.cc index 8fa11562e1..1f3801f843 100644 --- a/src/tint/writer/hlsl/generator_impl_test.cc +++ b/src/tint/writer/hlsl/generator_impl_test.cc @@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest, Generate) { } struct HlslBuiltinData { - ast::BuiltinValue builtin; + builtin::BuiltinValue builtin; const char* attribute_name; }; inline std::ostream& operator<<(std::ostream& out, HlslBuiltinData data) { @@ -66,17 +66,18 @@ TEST_P(HlslBuiltinConversionTest, Emit) { INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest, HlslBuiltinConversionTest, - testing::Values(HlslBuiltinData{ast::BuiltinValue::kPosition, "SV_Position"}, - HlslBuiltinData{ast::BuiltinValue::kVertexIndex, "SV_VertexID"}, - HlslBuiltinData{ast::BuiltinValue::kInstanceIndex, "SV_InstanceID"}, - HlslBuiltinData{ast::BuiltinValue::kFrontFacing, "SV_IsFrontFace"}, - HlslBuiltinData{ast::BuiltinValue::kFragDepth, "SV_Depth"}, - HlslBuiltinData{ast::BuiltinValue::kLocalInvocationId, "SV_GroupThreadID"}, - HlslBuiltinData{ast::BuiltinValue::kLocalInvocationIndex, "SV_GroupIndex"}, - HlslBuiltinData{ast::BuiltinValue::kGlobalInvocationId, "SV_DispatchThreadID"}, - HlslBuiltinData{ast::BuiltinValue::kWorkgroupId, "SV_GroupID"}, - HlslBuiltinData{ast::BuiltinValue::kSampleIndex, "SV_SampleIndex"}, - HlslBuiltinData{ast::BuiltinValue::kSampleMask, "SV_Coverage"})); + testing::Values(HlslBuiltinData{builtin::BuiltinValue::kPosition, "SV_Position"}, + HlslBuiltinData{builtin::BuiltinValue::kVertexIndex, "SV_VertexID"}, + HlslBuiltinData{builtin::BuiltinValue::kInstanceIndex, "SV_InstanceID"}, + HlslBuiltinData{builtin::BuiltinValue::kFrontFacing, "SV_IsFrontFace"}, + HlslBuiltinData{builtin::BuiltinValue::kFragDepth, "SV_Depth"}, + HlslBuiltinData{builtin::BuiltinValue::kLocalInvocationId, "SV_GroupThreadID"}, + HlslBuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, "SV_GroupIndex"}, + HlslBuiltinData{builtin::BuiltinValue::kGlobalInvocationId, + "SV_DispatchThreadID"}, + HlslBuiltinData{builtin::BuiltinValue::kWorkgroupId, "SV_GroupID"}, + HlslBuiltinData{builtin::BuiltinValue::kSampleIndex, "SV_SampleIndex"}, + HlslBuiltinData{builtin::BuiltinValue::kSampleMask, "SV_Coverage"})); } // namespace } // namespace tint::writer::hlsl diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index febde27f52..243fb114ad 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -1905,33 +1905,33 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { return true; } -std::string GeneratorImpl::builtin_to_attribute(ast::BuiltinValue builtin) const { +std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) const { switch (builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: return "position"; - case ast::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kVertexIndex: return "vertex_id"; - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kInstanceIndex: return "instance_id"; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: return "front_facing"; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: return "depth(any)"; - case ast::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: return "thread_position_in_threadgroup"; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: return "thread_index_in_threadgroup"; - case ast::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kGlobalInvocationId: return "thread_position_in_grid"; - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kWorkgroupId: return "threadgroup_position_in_grid"; - case ast::BuiltinValue::kNumWorkgroups: + case builtin::BuiltinValue::kNumWorkgroups: return "threadgroups_per_grid"; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: return "sample_id"; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: return "sample_mask"; - case ast::BuiltinValue::kPointSize: + case builtin::BuiltinValue::kPointSize: return "point_size"; default: break; diff --git a/src/tint/writer/msl/generator_impl.h b/src/tint/writer/msl/generator_impl.h index f98350644a..750bed561f 100644 --- a/src/tint/writer/msl/generator_impl.h +++ b/src/tint/writer/msl/generator_impl.h @@ -360,7 +360,7 @@ class GeneratorImpl : public TextGenerator { /// Converts a builtin to an attribute name /// @param builtin the builtin to convert /// @returns the string name of the builtin or blank on error - std::string builtin_to_attribute(ast::BuiltinValue builtin) const; + std::string builtin_to_attribute(builtin::BuiltinValue builtin) const; /// Converts interpolation attributes to an MSL attribute /// @param type the interpolation type diff --git a/src/tint/writer/msl/generator_impl_function_test.cc b/src/tint/writer/msl/generator_impl_function_test.cc index a93d262841..de88ecb53d 100644 --- a/src/tint/writer/msl/generator_impl_function_test.cc +++ b/src/tint/writer/msl/generator_impl_function_test.cc @@ -136,7 +136,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_WithInOut_Builtins) { // return coord.x; // } auto* coord_in = - Param("coord", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); + Param("coord", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}); Func("frag_main", utils::Vector{coord_in}, ty.f32(), utils::Vector{ Return(MemberAccessor("coord", "x")), @@ -145,7 +145,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_WithInOut_Builtins) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); GeneratorImpl& gen = SanitizeAndBuild(); @@ -190,7 +190,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_DifferentSta utils::Vector{ Member("col1", ty.f32(), utils::Vector{Location(1_a)}), Member("col2", ty.f32(), utils::Vector{Location(2_a)}), - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), }); Func("vert_main", utils::Empty, ty.Of(interface_struct), @@ -271,7 +271,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_HelperFuncti auto* vertex_output_struct = Structure( "VertexOutput", utils::Vector{ - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), }); Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct), diff --git a/src/tint/writer/msl/generator_impl_test.cc b/src/tint/writer/msl/generator_impl_test.cc index 7f0e8f54df..a6d5cb7b25 100644 --- a/src/tint/writer/msl/generator_impl_test.cc +++ b/src/tint/writer/msl/generator_impl_test.cc @@ -61,7 +61,7 @@ kernel void my_func() { } struct MslBuiltinData { - ast::BuiltinValue builtin; + builtin::BuiltinValue builtin; const char* attribute_name; }; inline std::ostream& operator<<(std::ostream& out, MslBuiltinData data) { @@ -80,25 +80,25 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslBuiltinConversionTest, testing::Values( - MslBuiltinData{ast::BuiltinValue::kPosition, "position"}, - MslBuiltinData{ast::BuiltinValue::kVertexIndex, "vertex_id"}, - MslBuiltinData{ast::BuiltinValue::kInstanceIndex, "instance_id"}, - MslBuiltinData{ast::BuiltinValue::kFrontFacing, "front_facing"}, - MslBuiltinData{ast::BuiltinValue::kFragDepth, "depth(any)"}, - MslBuiltinData{ast::BuiltinValue::kLocalInvocationId, "thread_position_in_threadgroup"}, - MslBuiltinData{ast::BuiltinValue::kLocalInvocationIndex, "thread_index_in_threadgroup"}, - MslBuiltinData{ast::BuiltinValue::kGlobalInvocationId, "thread_position_in_grid"}, - MslBuiltinData{ast::BuiltinValue::kWorkgroupId, "threadgroup_position_in_grid"}, - MslBuiltinData{ast::BuiltinValue::kNumWorkgroups, "threadgroups_per_grid"}, - MslBuiltinData{ast::BuiltinValue::kSampleIndex, "sample_id"}, - MslBuiltinData{ast::BuiltinValue::kSampleMask, "sample_mask"}, - MslBuiltinData{ast::BuiltinValue::kPointSize, "point_size"})); + MslBuiltinData{builtin::BuiltinValue::kPosition, "position"}, + MslBuiltinData{builtin::BuiltinValue::kVertexIndex, "vertex_id"}, + MslBuiltinData{builtin::BuiltinValue::kInstanceIndex, "instance_id"}, + MslBuiltinData{builtin::BuiltinValue::kFrontFacing, "front_facing"}, + MslBuiltinData{builtin::BuiltinValue::kFragDepth, "depth(any)"}, + MslBuiltinData{builtin::BuiltinValue::kLocalInvocationId, "thread_position_in_threadgroup"}, + MslBuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, "thread_index_in_threadgroup"}, + MslBuiltinData{builtin::BuiltinValue::kGlobalInvocationId, "thread_position_in_grid"}, + MslBuiltinData{builtin::BuiltinValue::kWorkgroupId, "threadgroup_position_in_grid"}, + MslBuiltinData{builtin::BuiltinValue::kNumWorkgroups, "threadgroups_per_grid"}, + MslBuiltinData{builtin::BuiltinValue::kSampleIndex, "sample_id"}, + MslBuiltinData{builtin::BuiltinValue::kSampleMask, "sample_mask"}, + MslBuiltinData{builtin::BuiltinValue::kPointSize, "point_size"})); TEST_F(MslGeneratorImplTest, HasInvariantAttribute_True) { auto* out = Structure("Out", utils::Vector{ Member("pos", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), Invariant(), }), }); @@ -136,7 +136,7 @@ TEST_F(MslGeneratorImplTest, HasInvariantAttribute_False) { auto* out = Structure("Out", utils::Vector{ Member("pos", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }), }); Func("vert_main", utils::Empty, ty.Of(out), utils::Vector{Return(Call(ty.Of(out)))}, diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 008cf412b9..541bb371df 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -549,7 +549,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) { } for (auto builtin : func_sem->TransitivelyReferencedBuiltinVariables()) { - if (builtin.second->builtin == ast::BuiltinValue::kFragDepth) { + if (builtin.second->builtin == builtin::BuiltinValue::kFragDepth) { push_execution_mode(spv::Op::OpExecutionMode, {Operand(id), U32Operand(SpvExecutionModeDepthReplacing)}); } @@ -4004,9 +4004,9 @@ SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const { return SpvStorageClassMax; } -SpvBuiltIn Builder::ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace storage) { +SpvBuiltIn Builder::ConvertBuiltin(builtin::BuiltinValue builtin, type::AddressSpace storage) { switch (builtin) { - case ast::BuiltinValue::kPosition: + case builtin::BuiltinValue::kPosition: if (storage == type::AddressSpace::kIn) { return SpvBuiltInFragCoord; } else if (TINT_LIKELY(storage == type::AddressSpace::kOut)) { @@ -4015,32 +4015,32 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace TINT_ICE(Writer, builder_.Diagnostics()) << "invalid address space for builtin"; break; } - case ast::BuiltinValue::kVertexIndex: + case builtin::BuiltinValue::kVertexIndex: return SpvBuiltInVertexIndex; - case ast::BuiltinValue::kInstanceIndex: + case builtin::BuiltinValue::kInstanceIndex: return SpvBuiltInInstanceIndex; - case ast::BuiltinValue::kFrontFacing: + case builtin::BuiltinValue::kFrontFacing: return SpvBuiltInFrontFacing; - case ast::BuiltinValue::kFragDepth: + case builtin::BuiltinValue::kFragDepth: return SpvBuiltInFragDepth; - case ast::BuiltinValue::kLocalInvocationId: + case builtin::BuiltinValue::kLocalInvocationId: return SpvBuiltInLocalInvocationId; - case ast::BuiltinValue::kLocalInvocationIndex: + case builtin::BuiltinValue::kLocalInvocationIndex: return SpvBuiltInLocalInvocationIndex; - case ast::BuiltinValue::kGlobalInvocationId: + case builtin::BuiltinValue::kGlobalInvocationId: return SpvBuiltInGlobalInvocationId; - case ast::BuiltinValue::kPointSize: + case builtin::BuiltinValue::kPointSize: return SpvBuiltInPointSize; - case ast::BuiltinValue::kWorkgroupId: + case builtin::BuiltinValue::kWorkgroupId: return SpvBuiltInWorkgroupId; - case ast::BuiltinValue::kNumWorkgroups: + case builtin::BuiltinValue::kNumWorkgroups: return SpvBuiltInNumWorkgroups; - case ast::BuiltinValue::kSampleIndex: + case builtin::BuiltinValue::kSampleIndex: push_capability(SpvCapabilitySampleRateShading); return SpvBuiltInSampleId; - case ast::BuiltinValue::kSampleMask: + case builtin::BuiltinValue::kSampleMask: return SpvBuiltInSampleMask; - case ast::BuiltinValue::kUndefined: + case builtin::BuiltinValue::kUndefined: break; } return SpvBuiltInMax; diff --git a/src/tint/writer/spirv/builder.h b/src/tint/writer/spirv/builder.h index 6f9bf5d99f..9262e15f75 100644 --- a/src/tint/writer/spirv/builder.h +++ b/src/tint/writer/spirv/builder.h @@ -213,7 +213,7 @@ class Builder { /// @param builtin the builtin to convert /// @param storage the address space that this builtin is being used with /// @returns the SPIR-V builtin or SpvBuiltInMax on error. - SpvBuiltIn ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace storage); + SpvBuiltIn ConvertBuiltin(builtin::BuiltinValue builtin, type::AddressSpace storage); /// Converts an interpolate attribute to SPIR-V decorations and pushes a /// capability if needed. diff --git a/src/tint/writer/spirv/builder_entry_point_test.cc b/src/tint/writer/spirv/builder_entry_point_test.cc index 7b55804006..59e1848e2b 100644 --- a/src/tint/writer/spirv/builder_entry_point_test.cc +++ b/src/tint/writer/spirv/builder_entry_point_test.cc @@ -16,11 +16,11 @@ #include "gtest/gtest.h" #include "src/tint/ast/builtin_attribute.h" -#include "src/tint/ast/builtin_value.h" #include "src/tint/ast/location_attribute.h" #include "src/tint/ast/return_statement.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/variable.h" +#include "src/tint/builtin/builtin_value.h" #include "src/tint/program.h" #include "src/tint/type/address_space.h" #include "src/tint/type/f32.h" @@ -44,7 +44,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) { // } auto* coord = Param("coord", ty.vec4(), utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); auto* loc1 = Param("loc1", ty.f32(), utils::Vector{ @@ -212,7 +212,7 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) { "Interface", utils::Vector{ Member("value", ty.f32(), utils::Vector{Location(1_u)}), - Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), + Member("pos", ty.vec4(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}), }); auto* vert_retval = Call(ty.Of(interface), 42_f, vec4()); @@ -228,7 +228,7 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) { }, utils::Vector{Stage(ast::PipelineStage::kFragment)}, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); spirv::Builder& b = SanitizeAndBuild(); @@ -322,7 +322,7 @@ OpFunctionEnd TEST_F(BuilderTest, SampleIndex_SampleRateShadingCapability) { Func("main", utils::Vector{Param("sample_index", ty.u32(), - utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)})}, + utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)})}, ty.void_(), utils::Empty, utils::Vector{ Stage(ast::PipelineStage::kFragment), diff --git a/src/tint/writer/spirv/builder_function_attribute_test.cc b/src/tint/writer/spirv/builder_function_attribute_test.cc index 8776842071..555c9eaf33 100644 --- a/src/tint/writer/spirv/builder_function_attribute_test.cc +++ b/src/tint/writer/spirv/builder_function_attribute_test.cc @@ -56,7 +56,7 @@ TEST_P(Attribute_StageTest, Emit) { utils::Vector body; if (params.stage == ast::PipelineStage::kVertex) { ret_type = ty.vec4(); - ret_type_attrs.Push(Builtin(ast::BuiltinValue::kPosition)); + ret_type_attrs.Push(Builtin(builtin::BuiltinValue::kPosition)); body.Push(Return(Call(ty.vec4()))); } @@ -226,7 +226,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) { Stage(ast::PipelineStage::kFragment), }, utils::Vector{ - Builtin(ast::BuiltinValue::kFragDepth), + Builtin(builtin::BuiltinValue::kFragDepth), }); spirv::Builder& b = SanitizeAndBuild(); diff --git a/src/tint/writer/spirv/builder_global_variable_test.cc b/src/tint/writer/spirv/builder_global_variable_test.cc index a246cbd657..2e586603a9 100644 --- a/src/tint/writer/spirv/builder_global_variable_test.cc +++ b/src/tint/writer/spirv/builder_global_variable_test.cc @@ -251,7 +251,7 @@ OpDecorate %1 DescriptorSet 3 } struct BuiltinData { - ast::BuiltinValue builtin; + builtin::BuiltinValue builtin; type::AddressSpace storage; SpvBuiltIn result; }; @@ -271,32 +271,35 @@ INSTANTIATE_TEST_SUITE_P( BuilderTest_Type, BuiltinDataTest, testing::Values( - BuiltinData{ast::BuiltinValue::kUndefined, type::AddressSpace::kNone, SpvBuiltInMax}, - BuiltinData{ast::BuiltinValue::kPosition, type::AddressSpace::kIn, SpvBuiltInFragCoord}, - BuiltinData{ast::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition}, + BuiltinData{builtin::BuiltinValue::kUndefined, type::AddressSpace::kNone, SpvBuiltInMax}, + BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kIn, SpvBuiltInFragCoord}, + BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition}, BuiltinData{ - ast::BuiltinValue::kVertexIndex, + builtin::BuiltinValue::kVertexIndex, type::AddressSpace::kIn, SpvBuiltInVertexIndex, }, - BuiltinData{ast::BuiltinValue::kInstanceIndex, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kInstanceIndex, type::AddressSpace::kIn, SpvBuiltInInstanceIndex}, - BuiltinData{ast::BuiltinValue::kFrontFacing, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kFrontFacing, type::AddressSpace::kIn, SpvBuiltInFrontFacing}, - BuiltinData{ast::BuiltinValue::kFragDepth, type::AddressSpace::kOut, SpvBuiltInFragDepth}, - BuiltinData{ast::BuiltinValue::kLocalInvocationId, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kFragDepth, type::AddressSpace::kOut, + SpvBuiltInFragDepth}, + BuiltinData{builtin::BuiltinValue::kLocalInvocationId, type::AddressSpace::kIn, SpvBuiltInLocalInvocationId}, - BuiltinData{ast::BuiltinValue::kLocalInvocationIndex, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, type::AddressSpace::kIn, SpvBuiltInLocalInvocationIndex}, - BuiltinData{ast::BuiltinValue::kGlobalInvocationId, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kGlobalInvocationId, type::AddressSpace::kIn, SpvBuiltInGlobalInvocationId}, - BuiltinData{ast::BuiltinValue::kWorkgroupId, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kWorkgroupId, type::AddressSpace::kIn, SpvBuiltInWorkgroupId}, - BuiltinData{ast::BuiltinValue::kNumWorkgroups, type::AddressSpace::kIn, + BuiltinData{builtin::BuiltinValue::kNumWorkgroups, type::AddressSpace::kIn, SpvBuiltInNumWorkgroups}, - BuiltinData{ast::BuiltinValue::kSampleIndex, type::AddressSpace::kIn, SpvBuiltInSampleId}, - BuiltinData{ast::BuiltinValue::kSampleMask, type::AddressSpace::kIn, SpvBuiltInSampleMask}, - BuiltinData{ast::BuiltinValue::kSampleMask, type::AddressSpace::kOut, + BuiltinData{builtin::BuiltinValue::kSampleIndex, type::AddressSpace::kIn, + SpvBuiltInSampleId}, + BuiltinData{builtin::BuiltinValue::kSampleMask, type::AddressSpace::kIn, + SpvBuiltInSampleMask}, + BuiltinData{builtin::BuiltinValue::kSampleMask, type::AddressSpace::kOut, SpvBuiltInSampleMask})); TEST_F(BuilderTest, GlobalVar_DeclReadOnly) { diff --git a/src/tint/writer/wgsl/generator_impl_function_test.cc b/src/tint/writer/wgsl/generator_impl_function_test.cc index 42e0184f99..34e26b40da 100644 --- a/src/tint/writer/wgsl/generator_impl_function_test.cc +++ b/src/tint/writer/wgsl/generator_impl_function_test.cc @@ -112,7 +112,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { auto vec4 = ty.vec4(); auto* coord = Param("coord", vec4, utils::Vector{ - Builtin(ast::BuiltinValue::kPosition), + Builtin(builtin::BuiltinValue::kPosition), }); auto* loc1 = Param("loc1", ty.f32(), utils::Vector{ diff --git a/src/tint/writer/wgsl/generator_impl_type_test.cc b/src/tint/writer/wgsl/generator_impl_type_test.cc index bad1440c1a..39322f23c4 100644 --- a/src/tint/writer/wgsl/generator_impl_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_type_test.cc @@ -268,7 +268,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithAttribute) { TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointAttributes) { auto* s = Structure( "S", utils::Vector{ - Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kVertexIndex)}), + Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)}), Member("b", ty.f32(), utils::Vector{Location(2_a)}), });