From 1b90f937422b1526245f3224194a99c0ed5ee5bc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 18 Feb 2023 12:37:34 +0000 Subject: [PATCH] tint: Remove type::AddressSpace::kNone Just use kUndefined. Change-Id: I26eada75a31b26f83e132a9a15c8ff64f7821676 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120404 Reviewed-by: Dan Sinclair Kokoro: Kokoro Commit-Queue: Ben Clayton --- src/dawn/glfw/utils.cpp | 4 +- src/dawn/tests/unittests/ITypBitsetTests.cpp | 2 +- src/tint/intrinsics.def | 1 - src/tint/program_builder.h | 2 +- src/tint/reader/spirv/enum_converter.cc | 2 +- src/tint/reader/spirv/enum_converter_test.cc | 2 +- src/tint/reader/spirv/function.cc | 16 +- src/tint/reader/spirv/function.h | 2 +- src/tint/reader/spirv/parser_impl.cc | 11 +- src/tint/reader/spirv/parser_impl.h | 2 +- .../spirv/parser_impl_convert_type_test.cc | 16 -- src/tint/reader/spirv/parser_type_test.cc | 10 +- src/tint/reader/wgsl/parser_impl.h | 6 +- src/tint/resolver/function_validation_test.cc | 2 +- src/tint/resolver/intrinsic_table.cc | 10 +- src/tint/resolver/resolver.cc | 58 ++++---- src/tint/resolver/resolver_test.cc | 2 +- src/tint/resolver/root_identifier_test.cc | 2 +- .../resolver/struct_address_space_use_test.cc | 4 +- src/tint/resolver/validator.cc | 4 +- src/tint/resolver/variable_validation_test.cc | 2 +- .../module_scope_var_to_entry_point_param.cc | 8 +- src/tint/type/address_space.cc | 2 - src/tint/type/address_space.h | 1 - src/tint/type/pointer.cc | 2 +- src/tint/type/pointer_test.cc | 2 +- src/tint/type/reference.cc | 2 +- src/tint/type/reference_test.cc | 2 +- src/tint/writer/append_vector.cc | 4 +- src/tint/writer/glsl/generator_impl.cc | 137 +++++++++--------- .../writer/glsl/generator_impl_type_test.cc | 47 +++--- src/tint/writer/hlsl/generator_impl.cc | 84 ++++++----- .../writer/hlsl/generator_impl_binary_test.cc | 2 +- .../writer/hlsl/generator_impl_type_test.cc | 46 +++--- src/tint/writer/msl/generator_impl.cc | 5 +- src/tint/writer/spirv/builder.cc | 8 +- .../spirv/builder_global_variable_test.cc | 3 +- src/tint/writer/spirv/builder_type_test.cc | 2 +- src/tint/writer/wgsl/generator_impl.cc | 2 +- 39 files changed, 264 insertions(+), 255 deletions(-) diff --git a/src/dawn/glfw/utils.cpp b/src/dawn/glfw/utils.cpp index 0ae95ff589..3a123ad1fe 100644 --- a/src/dawn/glfw/utils.cpp +++ b/src/dawn/glfw/utils.cpp @@ -75,7 +75,9 @@ std::unique_ptr SetupWindowAndGetSurfaceDescriptor(GLFWwind return std::move(desc); } #else - { return nullptr; } + { + return nullptr; + } #endif #else return nullptr; diff --git a/src/dawn/tests/unittests/ITypBitsetTests.cpp b/src/dawn/tests/unittests/ITypBitsetTests.cpp index ac82acec4a..68b7ddb3dc 100644 --- a/src/dawn/tests/unittests/ITypBitsetTests.cpp +++ b/src/dawn/tests/unittests/ITypBitsetTests.cpp @@ -144,7 +144,7 @@ TEST_F(ITypBitsetTest, And) { Bitset bits = {1 << 1 | 1 << 2 | 1 << 7}; ExpectBits(bits, {1, 2, 7}); - Bitset bits2 = bits & Bitset{1 << 0 | 1 << 3 | 1 << 7}; + Bitset bits2 = bits& Bitset{1 << 0 | 1 << 3 | 1 << 7}; ExpectBits(bits2, {7}); ExpectBits(bits, {1, 2, 7}); diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index 5985921229..ee280106d9 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -74,7 +74,6 @@ enum extension { // https://gpuweb.github.io/gpuweb/wgsl/#storage-class enum address_space { - @internal none function private workgroup diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 0f8a6edfc4..1c04faf85c 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -225,7 +225,7 @@ class ProgramBuilder { ~VarOptions(); ast::Type type; - type::AddressSpace address_space = type::AddressSpace::kNone; + type::AddressSpace address_space = type::AddressSpace::kUndefined; type::Access access = type::Access::kUndefined; const ast::Expression* initializer = nullptr; utils::Vector attributes; diff --git a/src/tint/reader/spirv/enum_converter.cc b/src/tint/reader/spirv/enum_converter.cc index 41792ce7d4..4f9e07bdb6 100644 --- a/src/tint/reader/spirv/enum_converter.cc +++ b/src/tint/reader/spirv/enum_converter.cc @@ -49,7 +49,7 @@ type::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) { case spv::StorageClass::Workgroup: return type::AddressSpace::kWorkgroup; case spv::StorageClass::UniformConstant: - return type::AddressSpace::kNone; + return type::AddressSpace::kUndefined; case spv::StorageClass::StorageBuffer: return type::AddressSpace::kStorage; case spv::StorageClass::Private: diff --git a/src/tint/reader/spirv/enum_converter_test.cc b/src/tint/reader/spirv/enum_converter_test.cc index 4d1a8fdfac..66e99ff721 100644 --- a/src/tint/reader/spirv/enum_converter_test.cc +++ b/src/tint/reader/spirv/enum_converter_test.cc @@ -130,7 +130,7 @@ INSTANTIATE_TEST_SUITE_P( StorageClassCase{spv::StorageClass::Output, true, type::AddressSpace::kOut}, StorageClassCase{spv::StorageClass::Uniform, true, type::AddressSpace::kUniform}, StorageClassCase{spv::StorageClass::Workgroup, true, type::AddressSpace::kWorkgroup}, - StorageClassCase{spv::StorageClass::UniformConstant, true, type::AddressSpace::kNone}, + StorageClassCase{spv::StorageClass::UniformConstant, true, type::AddressSpace::kUndefined}, StorageClassCase{spv::StorageClass::StorageBuffer, true, type::AddressSpace::kStorage}, StorageClassCase{spv::StorageClass::Private, true, type::AddressSpace::kPrivate}, StorageClassCase{spv::StorageClass::Function, true, type::AddressSpace::kFunction})); diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index d63a8f11d3..046780fec1 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -2521,11 +2521,11 @@ bool FunctionEmitter::EmitFunctionVariables() { return false; } } - auto* var = parser_impl_.MakeVar(inst.result_id(), type::AddressSpace::kNone, + auto* var = parser_impl_.MakeVar(inst.result_id(), type::AddressSpace::kUndefined, var_store_type, initializer, AttributeList{}); auto* var_decl_stmt = create(Source{}, var); AddStatement(var_decl_stmt); - auto* var_type = ty_.Reference(var_store_type, type::AddressSpace::kNone); + auto* var_type = ty_.Reference(var_store_type, type::AddressSpace::kUndefined); identifier_types_.emplace(inst.result_id(), var_type); } return success(); @@ -3367,9 +3367,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info, // no need to remap pointer properties. auto* store_type = parser_impl_.ConvertType(def_inst->type_id()); AddStatement(create( - Source{}, parser_impl_.MakeVar(id, type::AddressSpace::kNone, store_type, nullptr, + Source{}, parser_impl_.MakeVar(id, type::AddressSpace::kUndefined, store_type, nullptr, AttributeList{}))); - auto* type = ty_.Reference(store_type, type::AddressSpace::kNone); + auto* type = ty_.Reference(store_type, type::AddressSpace::kUndefined); identifier_types_.emplace(id, type); } @@ -6190,8 +6190,8 @@ bool FunctionEmitter::MakeVectorInsertDynamic(const spvtools::opt::Instruction& // API in parser_impl_. var_name = namer_.MakeDerivedName(original_value_name); - auto* temp_var = builder_.Var(var_name, type->Build(builder_), type::AddressSpace::kNone, - src_vector.expr); + auto* temp_var = builder_.Var(var_name, type->Build(builder_), + type::AddressSpace::kUndefined, src_vector.expr); AddStatement(builder_.Decl({}, temp_var)); } @@ -6260,8 +6260,8 @@ bool FunctionEmitter::MakeCompositeInsert(const spvtools::opt::Instruction& inst // It doesn't correspond to a SPIR-V ID, so we don't use the ordinary // API in parser_impl_. var_name = namer_.MakeDerivedName(original_value_name); - auto* temp_var = builder_.Var(var_name, type->Build(builder_), type::AddressSpace::kNone, - src_composite.expr); + auto* temp_var = builder_.Var(var_name, type->Build(builder_), + type::AddressSpace::kUndefined, src_composite.expr); AddStatement(builder_.Decl({}, temp_var)); } diff --git a/src/tint/reader/spirv/function.h b/src/tint/reader/spirv/function.h index 53495375ff..d035591ecb 100644 --- a/src/tint/reader/spirv/function.h +++ b/src/tint/reader/spirv/function.h @@ -368,7 +368,7 @@ inline std::ostream& operator<<(std::ostream& o, const DefInfo& di) { } o << " requires_named_let_def: " << (di.requires_named_let_def ? "true" : "false") << " requires_hoisted_var_def: " << (di.requires_hoisted_var_def ? "true" : "false"); - if (di.pointer.address_space != type::AddressSpace::kNone) { + if (di.pointer.address_space != type::AddressSpace::kUndefined) { o << " sc:" << int(di.pointer.address_space); } switch (di.skip) { diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 8a373fdc7a..5707bf14e6 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -1222,11 +1222,6 @@ const Type* ParserImpl::ConvertType(uint32_t type_id, } auto ast_address_space = enum_converter_.ToAddressSpace(storage_class); - if (ast_address_space == type::AddressSpace::kUndefined) { - Fail() << "SPIR-V pointer type with ID " << type_id << " has invalid storage class " - << static_cast(storage_class); - return nullptr; - } if (ast_address_space == type::AddressSpace::kUniform && remap_buffer_block_type_.count(pointee_type_id)) { ast_address_space = type::AddressSpace::kStorage; @@ -1459,7 +1454,7 @@ bool ParserImpl::EmitModuleScopeVariables() { continue; } switch (enum_converter_.ToAddressSpace(spirv_storage_class)) { - case type::AddressSpace::kNone: + case type::AddressSpace::kUndefined: case type::AddressSpace::kIn: case type::AddressSpace::kOut: case type::AddressSpace::kUniform: @@ -1476,7 +1471,7 @@ bool ParserImpl::EmitModuleScopeVariables() { return false; } const Type* ast_store_type = nullptr; - type::AddressSpace ast_address_space = type::AddressSpace::kNone; + type::AddressSpace ast_address_space = type::AddressSpace::kUndefined; if (spirv_storage_class == spv::StorageClass::UniformConstant) { // These are opaque handles: samplers or textures ast_store_type = GetHandleTypeForSpirvHandle(var); @@ -1600,7 +1595,7 @@ const ast::Var* ParserImpl::MakeVar(uint32_t id, // Handle variables (textures and samplers) are always in the handle // address space, so we don't mention the address space. if (address_space == type::AddressSpace::kHandle) { - address_space = type::AddressSpace::kNone; + address_space = type::AddressSpace::kUndefined; } if (!ConvertDecorationsForVariable(id, &storage_type, &decorations, diff --git a/src/tint/reader/spirv/parser_impl.h b/src/tint/reader/spirv/parser_impl.h index 1e64866b21..5d6daa4380 100644 --- a/src/tint/reader/spirv/parser_impl.h +++ b/src/tint/reader/spirv/parser_impl.h @@ -423,7 +423,7 @@ class ParserImpl : Reader { /// Creates an AST 'var' node for a SPIR-V ID, including any attached decorations, unless it's /// an ignorable builtin variable. /// @param id the SPIR-V result ID - /// @param address_space the address space, which cannot be type::AddressSpace::kNone + /// @param address_space the address space, which cannot be type::AddressSpace::kUndefined /// @param storage_type the storage type of the variable /// @param initializer the variable initializer /// @param decorations the variable decorations diff --git a/src/tint/reader/spirv/parser_impl_convert_type_test.cc b/src/tint/reader/spirv/parser_impl_convert_type_test.cc index 0dc8ddc3fb..8530b774bd 100644 --- a/src/tint/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/tint/reader/spirv/parser_impl_convert_type_test.cc @@ -783,22 +783,6 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) { EXPECT_TRUE(p->error().empty()); } -TEST_F(SpvParserTest, ConvertType_PointerUniformConstant) { - auto p = parser(test::Assemble(Preamble() + R"( - %float = OpTypeFloat 32 - %3 = OpTypePointer UniformConstant %float - )" + MainBody())); - EXPECT_TRUE(p->BuildInternalModule()); - - auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); - EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type->Is()); - EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kNone); - EXPECT_TRUE(p->error().empty()); -} - TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) { auto p = parser(test::Assemble(Preamble() + R"( %float = OpTypeFloat 32 diff --git a/src/tint/reader/spirv/parser_type_test.cc b/src/tint/reader/spirv/parser_type_test.cc index 232c2c5bb7..af1d090242 100644 --- a/src/tint/reader/spirv/parser_type_test.cc +++ b/src/tint/reader/spirv/parser_type_test.cc @@ -29,8 +29,8 @@ TEST(SpvParserTypeTest, SameArgumentsGivesSamePointer) { EXPECT_EQ(ty.U32(), ty.U32()); EXPECT_EQ(ty.F32(), ty.F32()); EXPECT_EQ(ty.I32(), ty.I32()); - EXPECT_EQ(ty.Pointer(ty.I32(), type::AddressSpace::kNone), - ty.Pointer(ty.I32(), type::AddressSpace::kNone)); + EXPECT_EQ(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), + ty.Pointer(ty.I32(), type::AddressSpace::kUndefined)); EXPECT_EQ(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 3)); EXPECT_EQ(ty.Matrix(ty.I32(), 3, 2), ty.Matrix(ty.I32(), 3, 2)); EXPECT_EQ(ty.Array(ty.I32(), 3, 2), ty.Array(ty.I32(), 3, 2)); @@ -54,9 +54,9 @@ TEST(SpvParserTypeTest, DifferentArgumentsGivesDifferentPointer) { Symbol sym_b(Symbol(2, {})); TypeManager ty; - EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kNone), - ty.Pointer(ty.U32(), type::AddressSpace::kNone)); - EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kNone), + EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), + ty.Pointer(ty.U32(), type::AddressSpace::kUndefined)); + EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), ty.Pointer(ty.I32(), type::AddressSpace::kIn)); EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.U32(), 3)); EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 2)); diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index fe42cac659..f692d777b2 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -292,7 +292,7 @@ class ParserImpl { /// Variable name std::string name; /// Variable address space - type::AddressSpace address_space = type::AddressSpace::kNone; + type::AddressSpace address_space = type::AddressSpace::kUndefined; /// Variable access control type::Access access = type::Access::kUndefined; /// Variable type @@ -302,7 +302,7 @@ class ParserImpl { /// VariableQualifier contains the parsed information for a variable qualifier struct VariableQualifier { /// The variable's address space - type::AddressSpace address_space = type::AddressSpace::kNone; + type::AddressSpace address_space = type::AddressSpace::kUndefined; /// The variable's access control type::Access access = type::Access::kUndefined; }; @@ -449,7 +449,7 @@ class ParserImpl { Maybe type_specifier(); /// Parses an `address_space` grammar element, erroring on parse failure. /// @param use a description of what was being parsed if an error was raised. - /// @returns the address space or type::AddressSpace::kNone if none matched + /// @returns the address space or type::AddressSpace::kUndefined if none matched Expect expect_address_space(std::string_view use); /// Parses a `struct_decl` grammar element. /// @returns the struct type or nullptr on error diff --git a/src/tint/resolver/function_validation_test.cc b/src/tint/resolver/function_validation_test.cc index 7ef446ab71..b04831ee62 100644 --- a/src/tint/resolver/function_validation_test.cc +++ b/src/tint/resolver/function_validation_test.cc @@ -1104,7 +1104,7 @@ INSTANTIATE_TEST_SUITE_P( ResolverTest, ResolverFunctionParameterValidationTest, testing::Values( - TestParams{type::AddressSpace::kNone, Expectation::kInvalid}, + TestParams{type::AddressSpace::kUndefined, Expectation::kInvalid}, TestParams{type::AddressSpace::kIn, Expectation::kInvalid}, TestParams{type::AddressSpace::kOut, Expectation::kInvalid}, TestParams{type::AddressSpace::kUniform, Expectation::kPassWithFullPtrParameterExtension}, diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc index 7c58444216..ecaefb20ce 100644 --- a/src/tint/resolver/intrinsic_table.cc +++ b/src/tint/resolver/intrinsic_table.cc @@ -1275,8 +1275,8 @@ Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type, params.Reserve(match.parameters.Length()); for (auto& p : match.parameters) { params.Push(builder.create( - nullptr, static_cast(params.Length()), p.type, type::AddressSpace::kNone, - type::Access::kUndefined, p.usage)); + nullptr, static_cast(params.Length()), p.type, + type::AddressSpace::kUndefined, type::Access::kUndefined, p.usage)); } sem::PipelineStageSet supported_stages; if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) { @@ -1476,8 +1476,8 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type, params.Reserve(match.parameters.Length()); for (auto& p : match.parameters) { params.Push(builder.create( - nullptr, static_cast(params.Length()), p.type, type::AddressSpace::kNone, - type::Access::kUndefined, p.usage)); + nullptr, static_cast(params.Length()), p.type, + type::AddressSpace::kUndefined, type::Access::kUndefined, p.usage)); } auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant : sem::EvaluationStage::kRuntime; @@ -1491,7 +1491,7 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type, // Conversion. auto* target = converters.GetOrCreate(match, [&]() { auto param = builder.create( - nullptr, 0u, match.parameters[0].type, type::AddressSpace::kNone, + nullptr, 0u, match.parameters[0].type, type::AddressSpace::kUndefined, type::Access::kUndefined, match.parameters[0].usage); auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant : sem::EvaluationStage::kRuntime; diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 8c36ad72e8..b87852f646 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -255,11 +255,11 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) { ty = rhs->Type()->UnwrapRef(); // Implicit load of RHS } - if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kNone, ty, rhs)) { + if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kUndefined, ty, rhs)) { return nullptr; } - if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), + if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast(ty), v->source)) { AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol), v->source); @@ -269,12 +269,12 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) { sem::Variable* sem = nullptr; if (is_global) { sem = builder_->create( - v, ty, sem::EvaluationStage::kRuntime, type::AddressSpace::kNone, + v, ty, sem::EvaluationStage::kRuntime, type::AddressSpace::kUndefined, type::Access::kUndefined, /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt); } else { sem = builder_->create(v, ty, sem::EvaluationStage::kRuntime, - type::AddressSpace::kNone, + type::AddressSpace::kUndefined, type::Access::kUndefined, current_statement_, /* constant_value */ nullptr); } @@ -318,11 +318,11 @@ sem::Variable* Resolver::Override(const ast::Override* v) { return nullptr; } - if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kNone, ty, rhs)) { + if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kUndefined, ty, rhs)) { return nullptr; } - if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), + if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast(ty), v->source)) { AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol), v->source); @@ -330,7 +330,8 @@ sem::Variable* Resolver::Override(const ast::Override* v) { } auto* sem = builder_->create( - v, ty, sem::EvaluationStage::kOverride, type::AddressSpace::kNone, type::Access::kUndefined, + v, ty, sem::EvaluationStage::kOverride, type::AddressSpace::kUndefined, + type::Access::kUndefined, /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt); sem->SetInitializer(rhs); @@ -411,11 +412,11 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) { ty = rhs->Type(); } - if (!validator_.VariableInitializer(c, type::AddressSpace::kNone, ty, rhs)) { + if (!validator_.VariableInitializer(c, type::AddressSpace::kUndefined, ty, rhs)) { return nullptr; } - if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), + if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast(ty), c->source)) { AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol), c->source); @@ -423,12 +424,13 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) { } const auto value = rhs->ConstantValue(); - auto* sem = is_global ? static_cast(builder_->create( - c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kNone, - type::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt)) - : static_cast(builder_->create( - c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kNone, - type::Access::kUndefined, current_statement_, value)); + auto* sem = is_global + ? static_cast(builder_->create( + c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined, + type::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt)) + : static_cast(builder_->create( + c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined, + type::Access::kUndefined, current_statement_, value)); sem->SetInitializer(rhs); builder_->Sem().Add(c, sem); @@ -472,7 +474,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) { } auto address_space = var->declared_address_space; - if (address_space == type::AddressSpace::kNone) { + if (address_space == type::AddressSpace::kUndefined) { // No declared address space. Infer from usage / type. if (!is_global) { address_space = type::AddressSpace::kFunction; @@ -608,7 +610,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index) return nullptr; } - if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, ty, param->type->source)) { + if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, ty, param->type->source)) { add_note(); return nullptr; } @@ -659,7 +661,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index) } auto* sem = builder_->create( - param, index, ty, type::AddressSpace::kNone, type::Access::kUndefined, + param, index, ty, type::AddressSpace::kUndefined, type::Access::kUndefined, sem::ParameterUsage::kNone, binding_point, location); builder_->Sem().Add(param, sem); return sem; @@ -919,7 +921,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) { } if (auto* str = return_type->As()) { - if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, str, decl->source)) { + if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, str, decl->source)) { AddNote("while instantiating return type for " + builder_->Symbols().NameFor(decl->name->symbol), decl->source); @@ -2009,10 +2011,10 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { [&]() -> sem::TypeInitializer* { auto params = utils::Transform(args, [&](auto, size_t i) { return builder_->create( - nullptr, // declaration - static_cast(i), // index - arr->ElemType(), // type - type::AddressSpace::kNone, // address_space + nullptr, // declaration + static_cast(i), // index + arr->ElemType(), // type + type::AddressSpace::kUndefined, // address_space type::Access::kUndefined); }); return builder_->create(arr, std::move(params), @@ -2038,11 +2040,11 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { params.Resize(std::min(args.Length(), str->Members().Length())); for (size_t i = 0, n = params.Length(); i < n; i++) { params[i] = builder_->create( - nullptr, // declaration - static_cast(i), // index - str->Members()[i]->Type(), // type - type::AddressSpace::kNone, // address_space - type::Access::kUndefined); // access + nullptr, // declaration + static_cast(i), // index + str->Members()[i]->Type(), // type + type::AddressSpace::kUndefined, // address_space + type::Access::kUndefined); // access } return builder_->create(str, std::move(params), args_stage); diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index c0d48bcec4..c926f7ac2b 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -1901,7 +1901,7 @@ TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kNone); + EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kUndefined); } TEST_F(ResolverTest, Access_SetForStorageBuffer) { diff --git a/src/tint/resolver/root_identifier_test.cc b/src/tint/resolver/root_identifier_test.cc index 6e81e42528..4f4a42067e 100644 --- a/src/tint/resolver/root_identifier_test.cc +++ b/src/tint/resolver/root_identifier_test.cc @@ -72,7 +72,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { auto* a = GlobalVar("a", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), - type::AddressSpace::kNone, Group(0_a), Binding(0_a)); + type::AddressSpace::kUndefined, Group(0_a), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(Call("textureDimensions", expr)); diff --git a/src/tint/resolver/struct_address_space_use_test.cc b/src/tint/resolver/struct_address_space_use_test.cc index 2d011bbc22..ae4e544744 100644 --- a/src/tint/resolver/struct_address_space_use_test.cc +++ b/src/tint/resolver/struct_address_space_use_test.cc @@ -46,7 +46,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromParameter) { auto* sem = TypeOf(s)->As(); ASSERT_NE(sem, nullptr); - EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kNone)); + EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined)); } TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) { @@ -58,7 +58,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) { auto* sem = TypeOf(s)->As(); ASSERT_NE(sem, nullptr); - EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kNone)); + EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined)); } TEST_F(ResolverAddressSpaceUseTest, StructReachableFromGlobal) { diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 44d6c5b643..5b399cfb14 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -612,7 +612,7 @@ bool Validator::GlobalVariable( return false; } - if (global->AddressSpace() == type::AddressSpace::kNone) { + if (global->AddressSpace() == type::AddressSpace::kUndefined) { AddError("module-scope 'var' declaration must have a address space", decl->source); return false; } @@ -697,7 +697,7 @@ bool Validator::Var(const sem::Variable* v) const { } if (store_ty->is_handle()) { - if (var->declared_address_space != type::AddressSpace::kNone) { + if (var->declared_address_space != type::AddressSpace::kUndefined) { // https://gpuweb.github.io/gpuweb/wgsl/#module-scope-variables // If the store type is a texture type or a sampler type, then the variable declaration // must not have a address space attribute. The address space will always be handle. diff --git a/src/tint/resolver/variable_validation_test.cc b/src/tint/resolver/variable_validation_test.cc index 738d926992..3898d1534f 100644 --- a/src/tint/resolver/variable_validation_test.cc +++ b/src/tint/resolver/variable_validation_test.cc @@ -113,7 +113,7 @@ TEST_F(ResolverVariableValidationTest, VarTypeNotConstructible) { // var p : pointer = &v; auto* i = Var("i", ty.i32()); auto* p = Var("a", ty.pointer(Source{{56, 78}}, type::AddressSpace::kFunction), - type::AddressSpace::kNone, AddressOf(Source{{12, 34}}, "i")); + type::AddressSpace::kUndefined, AddressOf(Source{{12, 34}}, "i")); WrapInFunction(i, p); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/transform/module_scope_var_to_entry_point_param.cc b/src/tint/transform/module_scope_var_to_entry_point_param.cc index 364087bebf..ff65fecf1e 100644 --- a/src/tint/transform/module_scope_var_to_entry_point_param.cc +++ b/src/tint/transform/module_scope_var_to_entry_point_param.cc @@ -321,7 +321,7 @@ struct ModuleScopeVarToEntryPointParam::State { bool needs_processing = false; for (auto* var : func_sem->TransitivelyReferencedGlobals()) { - if (var->AddressSpace() != type::AddressSpace::kNone) { + if (var->AddressSpace() != type::AddressSpace::kUndefined) { needs_processing = true; break; } @@ -378,7 +378,7 @@ struct ModuleScopeVarToEntryPointParam::State { // Process and redeclare all variables referenced by the function. for (auto* var : func_sem->TransitivelyReferencedGlobals()) { - if (var->AddressSpace() == type::AddressSpace::kNone) { + if (var->AddressSpace() == type::AddressSpace::kUndefined) { continue; } if (local_private_vars_.count(var)) { @@ -470,7 +470,7 @@ struct ModuleScopeVarToEntryPointParam::State { // For entry points, pass non-handle types as pointers. for (auto* target_var : target_sem->TransitivelyReferencedGlobals()) { auto sc = target_var->AddressSpace(); - if (sc == type::AddressSpace::kNone) { + if (sc == type::AddressSpace::kUndefined) { continue; } @@ -501,7 +501,7 @@ struct ModuleScopeVarToEntryPointParam::State { // Now remove all module-scope variables with these address spaces. for (auto* var_ast : ctx.src->AST().GlobalVariables()) { auto* var_sem = ctx.src->Sem().Get(var_ast); - if (var_sem->AddressSpace() != type::AddressSpace::kNone) { + if (var_sem->AddressSpace() != type::AddressSpace::kUndefined) { ctx.Remove(ctx.src->AST().GlobalDeclarations(), var_ast); } } diff --git a/src/tint/type/address_space.cc b/src/tint/type/address_space.cc index c8d9e821be..68f2c71f84 100644 --- a/src/tint/type/address_space.cc +++ b/src/tint/type/address_space.cc @@ -59,8 +59,6 @@ std::ostream& operator<<(std::ostream& out, AddressSpace value) { return out << "handle"; case AddressSpace::kIn: return out << "in"; - case AddressSpace::kNone: - return out << "none"; case AddressSpace::kOut: return out << "out"; case AddressSpace::kPrivate: diff --git a/src/tint/type/address_space.h b/src/tint/type/address_space.h index 9b70ea5e63..5b3855c2c9 100644 --- a/src/tint/type/address_space.h +++ b/src/tint/type/address_space.h @@ -33,7 +33,6 @@ enum class AddressSpace { kFunction, kHandle, // Tint-internal enum entry - not parsed kIn, // Tint-internal enum entry - not parsed - kNone, // Tint-internal enum entry - not parsed kOut, // Tint-internal enum entry - not parsed kPrivate, kPushConstant, diff --git a/src/tint/type/pointer.cc b/src/tint/type/pointer.cc index 809d05b38f..3dcb0788a4 100644 --- a/src/tint/type/pointer.cc +++ b/src/tint/type/pointer.cc @@ -45,7 +45,7 @@ bool Pointer::Equals(const UniqueNode& other) const { std::string Pointer::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; out << "ptr<"; - if (address_space_ != AddressSpace::kNone) { + if (address_space_ != AddressSpace::kUndefined) { out << address_space_ << ", "; } out << subtype_->FriendlyName(symbols) << ", " << access_; diff --git a/src/tint/type/pointer_test.cc b/src/tint/type/pointer_test.cc index aa8d14e829..a0c8bbbfaa 100644 --- a/src/tint/type/pointer_test.cc +++ b/src/tint/type/pointer_test.cc @@ -59,7 +59,7 @@ TEST_F(PointerTest, Equals) { } TEST_F(PointerTest, FriendlyName) { - auto* r = create(create(), AddressSpace::kNone, type::Access::kRead); + auto* r = create(create(), AddressSpace::kUndefined, type::Access::kRead); EXPECT_EQ(r->FriendlyName(Symbols()), "ptr"); } diff --git a/src/tint/type/reference.cc b/src/tint/type/reference.cc index 5951f3843a..6a7e2c6caf 100644 --- a/src/tint/type/reference.cc +++ b/src/tint/type/reference.cc @@ -44,7 +44,7 @@ bool Reference::Equals(const UniqueNode& other) const { std::string Reference::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; out << "ref<"; - if (address_space_ != AddressSpace::kNone) { + if (address_space_ != AddressSpace::kUndefined) { out << address_space_ << ", "; } out << subtype_->FriendlyName(symbols) << ", " << access_; diff --git a/src/tint/type/reference_test.cc b/src/tint/type/reference_test.cc index 8b3ae183ed..ceee77fa72 100644 --- a/src/tint/type/reference_test.cc +++ b/src/tint/type/reference_test.cc @@ -59,7 +59,7 @@ TEST_F(ReferenceTest, Equals) { } TEST_F(ReferenceTest, FriendlyName) { - auto* r = create(create(), AddressSpace::kNone, type::Access::kRead); + auto* r = create(create(), AddressSpace::kUndefined, type::Access::kRead); EXPECT_EQ(r->FriendlyName(Symbols()), "ref"); } diff --git a/src/tint/writer/append_vector.cc b/src/tint/writer/append_vector.cc index 3d38c7faf6..e702c901ba 100644 --- a/src/tint/writer/append_vector.cc +++ b/src/tint/writer/append_vector.cc @@ -137,7 +137,7 @@ const sem::Call* AppendVector(ProgramBuilder* b, auto* scalar_cast_target = b->create( packed_el_sem_ty, b->create(nullptr, 0u, scalar_sem->Type()->UnwrapRef(), - type::AddressSpace::kNone, type::Access::kUndefined), + type::AddressSpace::kUndefined, type::Access::kUndefined), sem::EvaluationStage::kRuntime); auto* scalar_cast_sem = b->create( scalar_cast_ast, scalar_cast_target, sem::EvaluationStage::kRuntime, @@ -160,7 +160,7 @@ const sem::Call* AppendVector(ProgramBuilder* b, [&](const tint::sem::ValueExpression* arg, size_t i) -> const sem::Parameter* { return b->create( nullptr, static_cast(i), arg->Type()->UnwrapRef(), - type::AddressSpace::kNone, type::Access::kUndefined); + type::AddressSpace::kUndefined, type::Access::kUndefined); }), sem::EvaluationStage::kRuntime); auto* initializer_sem = diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index a09af2f965..cd8639a603 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -374,7 +374,8 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression* dst_type->is_float_scalar_or_vector()) { out << "uintBitsToFloat"; } else { - if (!EmitType(out, dst_type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, dst_type, type::AddressSpace::kUndefined, type::Access::kReadWrite, + "")) { return false; } } @@ -437,12 +438,12 @@ bool GeneratorImpl::EmitBitwiseBoolOp(std::ostream& out, const ast::BinaryExpres auto* uint_type = BoolTypeToUint(bool_type); // Cast result to bool scalar or vector type. - if (!EmitType(out, bool_type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, bool_type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } ScopedParen outerCastParen(out); // Cast LHS to uint scalar or vector type. - if (!EmitType(out, uint_type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, uint_type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } { @@ -462,7 +463,7 @@ bool GeneratorImpl::EmitBitwiseBoolOp(std::ostream& out, const ast::BinaryExpres return false; } // Cast RHS to uint scalar or vector type. - if (!EmitType(out, uint_type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, uint_type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } { @@ -480,43 +481,43 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi auto* ret_ty = TypeOf(expr)->UnwrapRef(); auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef(); auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef(); - fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, - [&]() -> std::string { - TextBuffer b; - TINT_DEFER(helpers_.Append(b)); + fn = utils::GetOrCreate( + float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, [&]() -> std::string { + TextBuffer b; + TINT_DEFER(helpers_.Append(b)); - auto fn_name = UniqueIdentifier("tint_float_modulo"); - std::vector parameter_names; - { - auto decl = line(&b); - if (!EmitTypeAndName(decl, ret_ty, type::AddressSpace::kNone, - type::Access::kUndefined, fn_name)) { - return ""; - } - { - ScopedParen sp(decl); - const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, - type::Access::kUndefined, "lhs")) { - return ""; - } - decl << ", "; - ty = TypeOf(expr->rhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, - type::Access::kUndefined, "rhs")) { - return ""; - } - } - decl << " {"; - } - { - ScopedIndent si(&b); - line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; - } - line(&b) << "}"; - line(&b); - return fn_name; - }); + auto fn_name = UniqueIdentifier("tint_float_modulo"); + std::vector parameter_names; + { + auto decl = line(&b); + if (!EmitTypeAndName(decl, ret_ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, fn_name)) { + return ""; + } + { + ScopedParen sp(decl); + const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); + if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, "lhs")) { + return ""; + } + decl << ", "; + ty = TypeOf(expr->rhs)->UnwrapRef(); + if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, "rhs")) { + return ""; + } + } + decl << " {"; + } + { + ScopedIndent si(&b); + line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; + } + line(&b) << "}"; + line(&b); + return fn_name; + }); if (fn.empty()) { return false; @@ -826,7 +827,8 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out, bool GeneratorImpl::EmitTypeConversion(std::ostream& out, const sem::Call* call, const sem::TypeConversion* conv) { - if (!EmitType(out, conv->Target(), type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, conv->Target(), type::AddressSpace::kUndefined, type::Access::kReadWrite, + "")) { return false; } ScopedParen sp(out); @@ -849,7 +851,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out, return EmitZeroValue(out, type); } - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } ScopedParen sp(out); @@ -919,7 +921,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, { auto pre = line(); - if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, result)) { return false; } @@ -1057,7 +1059,7 @@ bool GeneratorImpl::EmitEmulatedFMA(std::ostream& out, const ast::CallExpression bool GeneratorImpl::EmitCountOneBitsCall(std::ostream& out, const ast::CallExpression* expr) { // GLSL's bitCount returns an integer type, so cast it to the appropriate // unsigned type. - if (!EmitType(out, TypeOf(expr)->UnwrapRef(), type::AddressSpace::kNone, + if (!EmitType(out, TypeOf(expr)->UnwrapRef(), type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } @@ -1129,24 +1131,24 @@ bool GeneratorImpl::EmitDotCall(std::ostream& out, std::string v; { std::stringstream s; - if (!EmitType(s, vec_ty->type(), type::AddressSpace::kNone, type::Access::kRead, - "")) { + if (!EmitType(s, vec_ty->type(), type::AddressSpace::kUndefined, + type::Access::kRead, "")) { return ""; } v = s.str(); } { // (u)int tint_int_dot([i|u]vecN a, [i|u]vecN b) { auto l = line(&b); - if (!EmitType(l, vec_ty->type(), type::AddressSpace::kNone, type::Access::kRead, - "")) { + if (!EmitType(l, vec_ty->type(), type::AddressSpace::kUndefined, + type::Access::kRead, "")) { return ""; } l << " " << fn_name << "("; - if (!EmitType(l, vec_ty, type::AddressSpace::kNone, type::Access::kRead, "")) { + if (!EmitType(l, vec_ty, type::AddressSpace::kUndefined, type::Access::kRead, "")) { return ""; } l << " a, "; - if (!EmitType(l, vec_ty, type::AddressSpace::kNone, type::Access::kRead, "")) { + if (!EmitType(l, vec_ty, type::AddressSpace::kUndefined, type::Access::kRead, "")) { return ""; } l << " b) {"; @@ -1197,7 +1199,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out, { auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -1223,7 +1225,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out, { auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -1881,8 +1883,8 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { { auto out = line(); auto name = builder_.Symbols().NameFor(func->name->symbol); - if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kNone, type::Access::kReadWrite, - "")) { + if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kUndefined, + type::Access::kReadWrite, "")) { return false; } @@ -1907,7 +1909,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { type = ptr->StoreType(); } - // Note: WGSL only allows for AddressSpace::kNone on parameters, however + // Note: WGSL only allows for AddressSpace::kUndefined on parameters, however // the sanitizer transforms generates load / store functions for storage // or uniform buffers. These functions have a buffer parameter with // AddressSpace::kStorage or AddressSpace::kUniform. This is required to @@ -2339,7 +2341,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const constant::Value* const return true; }, [&](const type::Vector* v) { - if (!EmitType(out, v, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, v, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -2360,7 +2362,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const constant::Value* const return true; }, [&](const type::Matrix* m) { - if (!EmitType(out, m, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, m, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -2377,7 +2379,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const constant::Value* const return true; }, [&](const type::Array* a) { - if (!EmitType(out, a, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, a, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -2469,7 +2471,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) { } else if (type->Is()) { out << "0u"; } else if (auto* vec = type->As()) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } ScopedParen sp(out); @@ -2482,7 +2484,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) { } } } else if (auto* mat = type->As()) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } ScopedParen sp(out); @@ -2495,7 +2497,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) { } } } else if (auto* str = type->As()) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } bool first = true; @@ -2509,7 +2511,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) { EmitZeroValue(out, member->Type()); } } else if (auto* arr = type->As()) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } ScopedParen sp(out); @@ -3052,7 +3054,8 @@ bool GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) { auto out = line(b); - if (!EmitTypeAndName(out, ty, type::AddressSpace::kNone, type::Access::kReadWrite, name)) { + if (!EmitTypeAndName(out, ty, type::AddressSpace::kUndefined, type::Access::kReadWrite, + name)) { return false; } out << ";"; @@ -3120,7 +3123,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { auto out = line(); // TODO(senorblanco): handle const - if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, + if (!EmitTypeAndName(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, builder_.Symbols().NameFor(let->name->symbol))) { return false; } @@ -3142,7 +3145,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "const "; - if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, + if (!EmitTypeAndName(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, builder_.Symbols().NameFor(var->name->symbol))) { return false; } @@ -3169,7 +3172,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out, std::vector parameter_names; { auto decl = line(&b); - if (!EmitTypeAndName(decl, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(decl, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, fn_name)) { return ""; } @@ -3185,7 +3188,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out, decl << "inout "; ty = ptr->StoreType(); } - if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined, type::Access::kUndefined, param_name)) { return ""; } diff --git a/src/tint/writer/glsl/generator_impl_type_test.cc b/src/tint/writer/glsl/generator_impl_type_test.cc index b5389798d0..1f1c8a6795 100644 --- a/src/tint/writer/glsl/generator_impl_type_test.cc +++ b/src/tint/writer/glsl/generator_impl_type_test.cc @@ -39,7 +39,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[4]"); @@ -52,7 +52,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[5][4]"); @@ -65,7 +65,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[6][5][4]"); @@ -78,7 +78,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool[4]"); @@ -90,7 +90,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Bool) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, bool_, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, bool_, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool"); } @@ -101,7 +102,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, f32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float"); } @@ -114,7 +116,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F16) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f16, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, f16, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float16_t"); } @@ -125,7 +128,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_I32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, i32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, i32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "int"); } @@ -138,7 +142,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, mat2x3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "mat2x3"); } @@ -153,7 +158,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F16) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, mat2x3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "f16mat2x3"); } @@ -189,7 +195,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct) { auto* sem_s = program->TypeOf(s)->As(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sem_s, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, sem_s, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "S"); } @@ -237,7 +244,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_U32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, u32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, u32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "uint"); } @@ -249,7 +257,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, vec3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, vec3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "vec3"); } @@ -263,7 +272,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F16) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, vec3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, vec3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "f16vec3"); } @@ -274,7 +284,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Void) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, void_, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, void_, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "void"); } @@ -286,7 +297,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSampler) { std::stringstream out; ASSERT_FALSE( - gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); } @@ -297,7 +308,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) { std::stringstream out; ASSERT_FALSE( - gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); } @@ -503,7 +514,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, s, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE(gen.EmitType(out, s, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "highp sampler2DMS"); } diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index aab30d28ea..df7de5cbed 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -642,7 +642,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression* } out << "as"; - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } out << "("; @@ -1030,7 +1030,8 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out, bool GeneratorImpl::EmitTypeConversion(std::ostream& out, const sem::Call* call, const sem::TypeConversion* conv) { - if (!EmitType(out, conv->Target(), type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, conv->Target(), type::AddressSpace::kUndefined, type::Access::kReadWrite, + "")) { return false; } out << "("; @@ -1075,7 +1076,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out, if (brackets) { out << "{"; } else { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } out << "("; @@ -1592,13 +1593,13 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( auto rmw = [&](const char* hlsl) -> bool { { auto fn = line(&buf); - if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, - name)) { + if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, name)) { return false; } fn << "(RWByteAddressBuffer buffer, uint offset, "; - if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, - "value")) { + if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, "value")) { return false; } fn << ") {"; @@ -1613,8 +1614,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( { auto l = line(&buf); - if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, - "original_value")) { + if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined, + type::Access::kUndefined, "original_value")) { return false; } l << " = 0;"; @@ -1662,7 +1663,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( // InterlockedOr using 0 as the OR value { auto fn = line(&buf); - if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, name)) { return false; } @@ -1678,7 +1679,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( { auto l = line(&buf); - if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "value")) { return false; } @@ -1696,7 +1697,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( { auto fn = line(&buf); fn << "void " << name << "(RWByteAddressBuffer buffer, uint offset, "; - if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "value")) { return false; } @@ -1712,7 +1713,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( { auto l = line(&buf); - if (!EmitTypeAndName(l, value_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(l, value_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "ignored")) { return false; } @@ -1727,17 +1728,17 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( auto* value_ty = params[2]->Type()->UnwrapRef(); { auto fn = line(&buf); - if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, name)) { return false; } fn << "(RWByteAddressBuffer buffer, uint offset, "; - if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "compare")) { return false; } fn << ", "; - if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "value")) { return false; } @@ -1753,7 +1754,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic( { // T result = {0}; auto l = line(&buf); - if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, "result")) { return false; } @@ -1788,7 +1789,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, if (!builtin->ReturnType()->Is()) { auto pre = line(); - if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, result)) { return false; } @@ -1852,7 +1853,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, { // T result = 0; auto pre = line(); auto* value_ty = builtin->Parameters()[1]->Type()->UnwrapRef(); - if (!EmitTypeAndName(pre, value_ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(pre, value_ty, type::AddressSpace::kUndefined, type::Access::kUndefined, result)) { return false; } @@ -1891,7 +1892,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, { // T compare_value = ; auto pre = line(); if (!EmitTypeAndName(pre, TypeOf(compare_value)->UnwrapRef(), - type::AddressSpace::kNone, type::Access::kUndefined, + type::AddressSpace::kUndefined, type::Access::kUndefined, compare)) { return false; } @@ -2001,7 +2002,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out, { auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -2043,7 +2044,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out, line(b) << member_type << " fract = frexp(" << in << ", exp);"; { auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -2081,7 +2082,7 @@ bool GeneratorImpl::EmitRadiansCall(std::ostream& out, // type after the call to `sign`. bool GeneratorImpl::EmitSignCall(std::ostream& out, const sem::Call* call, const sem::Builtin*) { auto* arg = call->Arguments()[0]; - if (!EmitType(out, arg->Type(), type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, arg->Type(), type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } out << "(sign("; @@ -2883,14 +2884,14 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { auto typedef_name = UniqueIdentifier(name + "_ret"); auto pre = line(); pre << "typedef "; - if (!EmitTypeAndName(pre, sem->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(pre, sem->ReturnType(), type::AddressSpace::kUndefined, type::Access::kReadWrite, typedef_name)) { return false; } pre << ";"; out << typedef_name; } else { - if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kNone, + if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) { return false; } @@ -2907,7 +2908,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { first = false; auto const* type = v->Type(); - auto address_space = type::AddressSpace::kNone; + auto address_space = type::AddressSpace::kUndefined; auto access = type::Access::kUndefined; if (auto* ptr = type->As()) { @@ -2928,7 +2929,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { } } - // Note: WGSL only allows for AddressSpace::kNone on parameters, however + // Note: WGSL only allows for AddressSpace::kUndefined on parameters, however // the sanitizer transforms generates load / store functions for storage // or uniform buffers. These functions have a buffer parameter with // AddressSpace::kStorage or AddressSpace::kUniform. This is required to @@ -2981,7 +2982,7 @@ bool GeneratorImpl::EmitFunctionBodyWithDiscard(const ast::Function* func) { auto name = builder_.Symbols().NameFor(builder_.Symbols().New("unused")); { auto out = line(); - if (!EmitTypeAndName(out, sem->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(out, sem->ReturnType(), type::AddressSpace::kUndefined, type::Access::kReadWrite, name)) { return false; } @@ -3335,7 +3336,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, return true; } - if (!EmitType(out, v, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, v, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -3352,7 +3353,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, return true; }, [&](const type::Matrix* m) { - if (!EmitType(out, m, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, m, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) { return false; } @@ -3371,7 +3372,8 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, [&](const type::Array* a) { if (constant->AllZero()) { out << "("; - if (!EmitType(out, a, type::AddressSpace::kNone, type::Access::kUndefined, "")) { + if (!EmitType(out, a, type::AddressSpace::kUndefined, type::Access::kUndefined, + "")) { return false; } out << ")0"; @@ -3511,7 +3513,8 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val return true; }, [&](const type::Vector* vec) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, + "")) { return false; } ScopedParen sp(out); @@ -3526,7 +3529,8 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val return true; }, [&](const type::Matrix* mat) { - if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { + if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, + "")) { return false; } ScopedParen sp(out); @@ -3543,12 +3547,14 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val [&](const sem::Struct*) { out << "("; TINT_DEFER(out << ")" << value); - return EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, ""); + return EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, + ""); }, [&](const type::Array*) { out << "("; TINT_DEFER(out << ")" << value); - return EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, ""); + return EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, + ""); }, [&](Default) { diagnostics_.add_error( @@ -4232,7 +4238,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { } out << pre; - if (!EmitTypeAndName(out, ty, type::AddressSpace::kNone, type::Access::kReadWrite, + if (!EmitTypeAndName(out, ty, type::AddressSpace::kUndefined, type::Access::kReadWrite, mem_name)) { return false; } @@ -4302,7 +4308,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { auto out = line(); out << "const "; - if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, + if (!EmitTypeAndName(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, builder_.Symbols().NameFor(let->name->symbol))) { return false; } @@ -4329,7 +4335,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out, std::vector parameter_names; { auto decl = line(&b); - if (!EmitTypeAndName(decl, builtin->ReturnType(), type::AddressSpace::kNone, + if (!EmitTypeAndName(decl, builtin->ReturnType(), type::AddressSpace::kUndefined, type::Access::kUndefined, fn_name)) { return ""; } @@ -4345,7 +4351,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out, decl << "inout "; ty = ptr->StoreType(); } - if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, + if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined, type::Access::kUndefined, param_name)) { return ""; } diff --git a/src/tint/writer/hlsl/generator_impl_binary_test.cc b/src/tint/writer/hlsl/generator_impl_binary_test.cc index 325ca67804..eee3fedd0a 100644 --- a/src/tint/writer/hlsl/generator_impl_binary_test.cc +++ b/src/tint/writer/hlsl/generator_impl_binary_test.cc @@ -575,7 +575,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) { GlobalVar("d", ty.bool_(), type::AddressSpace::kPrivate); auto* var = - Var("a", ty.bool_(), type::AddressSpace::kNone, + Var("a", ty.bool_(), type::AddressSpace::kUndefined, create( ast::BinaryOp::kLogicalOr, create(ast::BinaryOp::kLogicalAnd, Expr("b"), Expr("c")), diff --git a/src/tint/writer/hlsl/generator_impl_type_test.cc b/src/tint/writer/hlsl/generator_impl_type_test.cc index be5a90057a..fc347ac648 100644 --- a/src/tint/writer/hlsl/generator_impl_type_test.cc +++ b/src/tint/writer/hlsl/generator_impl_type_test.cc @@ -39,7 +39,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[4]"); @@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[5][4]"); @@ -65,7 +65,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[6][5][4]"); @@ -78,7 +78,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool[4]"); @@ -90,7 +90,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, bool_, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, bool_, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool"); } @@ -101,7 +102,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F16) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f16, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, f16, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float16_t"); } @@ -112,7 +114,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, f32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float"); } @@ -123,7 +126,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, i32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, i32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "int"); } @@ -136,7 +140,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix_F16) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, mat2x3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "matrix"); } @@ -149,7 +154,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix_F32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, mat2x3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float2x3"); } @@ -198,7 +204,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) { auto* sem_s = program->TypeOf(s)->As(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sem_s, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, sem_s, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "S"); } @@ -245,7 +252,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, u32, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, u32, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "uint"); } @@ -257,7 +265,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, vec3, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, vec3, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "float3"); } @@ -268,7 +277,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, void_, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, void_, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "void"); } @@ -279,7 +289,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSampler) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "SamplerState"); } @@ -290,7 +301,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE( + gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "SamplerComparisonState"); } @@ -500,7 +512,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, s, type::AddressSpace::kNone, type::Access::kReadWrite, "")) + ASSERT_TRUE(gen.EmitType(out, s, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "Texture2DMS"); } diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 87928b436f..39c3ec7693 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -3027,7 +3027,6 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) { switch (sem->AddressSpace()) { case type::AddressSpace::kFunction: case type::AddressSpace::kHandle: - case type::AddressSpace::kNone: break; case type::AddressSpace::kPrivate: out << "thread "; @@ -3056,7 +3055,7 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) { } } else if (sem->AddressSpace() == type::AddressSpace::kPrivate || sem->AddressSpace() == type::AddressSpace::kFunction || - sem->AddressSpace() == type::AddressSpace::kNone) { + sem->AddressSpace() == type::AddressSpace::kUndefined) { out << " = "; if (!EmitZeroValue(out, type)) { return false; @@ -3076,7 +3075,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { switch (sem->AddressSpace()) { case type::AddressSpace::kFunction: case type::AddressSpace::kHandle: - case type::AddressSpace::kNone: + case type::AddressSpace::kUndefined: break; case type::AddressSpace::kPrivate: out << "thread "; diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 74825586d9..efee8667a9 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -778,8 +778,8 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) { auto result = result_op(); auto var_id = std::get(result); - auto sc = sem->AddressSpace() == type::AddressSpace::kNone ? type::AddressSpace::kPrivate - : sem->AddressSpace(); + auto sc = sem->AddressSpace() == type::AddressSpace::kUndefined ? type::AddressSpace::kPrivate + : sem->AddressSpace(); auto type_id = GenerateTypeIfNeeded(sem->Type()); if (type_id == 0) { @@ -3978,8 +3978,6 @@ bool Builder::GenerateVectorType(const type::Vector* vec, const Operand& result) SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const { switch (klass) { - case type::AddressSpace::kUndefined: - return SpvStorageClassMax; case type::AddressSpace::kIn: return SpvStorageClassInput; case type::AddressSpace::kOut: @@ -3998,7 +3996,7 @@ SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const { return SpvStorageClassPrivate; case type::AddressSpace::kFunction: return SpvStorageClassFunction; - case type::AddressSpace::kNone: + case type::AddressSpace::kUndefined: break; } return SpvStorageClassMax; diff --git a/src/tint/writer/spirv/builder_global_variable_test.cc b/src/tint/writer/spirv/builder_global_variable_test.cc index ea9c6a8f7e..dae3a504d7 100644 --- a/src/tint/writer/spirv/builder_global_variable_test.cc +++ b/src/tint/writer/spirv/builder_global_variable_test.cc @@ -271,7 +271,8 @@ INSTANTIATE_TEST_SUITE_P( BuilderTest_Type, BuiltinDataTest, testing::Values( - BuiltinData{builtin::BuiltinValue::kUndefined, type::AddressSpace::kNone, SpvBuiltInMax}, + BuiltinData{builtin::BuiltinValue::kUndefined, type::AddressSpace::kUndefined, + SpvBuiltInMax}, BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kIn, SpvBuiltInFragCoord}, BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition}, BuiltinData{ diff --git a/src/tint/writer/spirv/builder_type_test.cc b/src/tint/writer/spirv/builder_type_test.cc index cf3566294d..93831afb70 100644 --- a/src/tint/writer/spirv/builder_type_test.cc +++ b/src/tint/writer/spirv/builder_type_test.cc @@ -623,7 +623,7 @@ TEST_P(PtrDataTest, ConvertAddressSpace) { INSTANTIATE_TEST_SUITE_P( BuilderTest_Type, PtrDataTest, - testing::Values(PtrData{type::AddressSpace::kNone, SpvStorageClassMax}, + testing::Values(PtrData{type::AddressSpace::kUndefined, SpvStorageClassMax}, PtrData{type::AddressSpace::kIn, SpvStorageClassInput}, PtrData{type::AddressSpace::kOut, SpvStorageClassOutput}, PtrData{type::AddressSpace::kUniform, SpvStorageClassUniform}, diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 10bd9d8549..ae34abb7dc 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -475,7 +475,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, const ast::Variable* v) { out << "var"; auto address_space = var->declared_address_space; auto ac = var->declared_access; - if (address_space != type::AddressSpace::kNone || ac != type::Access::kUndefined) { + if (address_space != type::AddressSpace::kUndefined || ac != type::Access::kUndefined) { out << "<" << address_space; if (ac != type::Access::kUndefined) { out << ", ";