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 <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2023-02-18 12:37:34 +00:00 committed by Dawn LUCI CQ
parent 643f2aad43
commit 1b90f93742
39 changed files with 264 additions and 255 deletions

View File

@ -75,7 +75,9 @@ std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(GLFWwind
return std::move(desc); return std::move(desc);
} }
#else #else
{ return nullptr; } {
return nullptr;
}
#endif #endif
#else #else
return nullptr; return nullptr;

View File

@ -144,7 +144,7 @@ TEST_F(ITypBitsetTest, And) {
Bitset bits = {1 << 1 | 1 << 2 | 1 << 7}; Bitset bits = {1 << 1 | 1 << 2 | 1 << 7};
ExpectBits(bits, {1, 2, 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(bits2, {7});
ExpectBits(bits, {1, 2, 7}); ExpectBits(bits, {1, 2, 7});

View File

@ -74,7 +74,6 @@ enum extension {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class // https://gpuweb.github.io/gpuweb/wgsl/#storage-class
enum address_space { enum address_space {
@internal none
function function
private private
workgroup workgroup

View File

@ -225,7 +225,7 @@ class ProgramBuilder {
~VarOptions(); ~VarOptions();
ast::Type type; ast::Type type;
type::AddressSpace address_space = type::AddressSpace::kNone; type::AddressSpace address_space = type::AddressSpace::kUndefined;
type::Access access = type::Access::kUndefined; type::Access access = type::Access::kUndefined;
const ast::Expression* initializer = nullptr; const ast::Expression* initializer = nullptr;
utils::Vector<const ast::Attribute*, 4> attributes; utils::Vector<const ast::Attribute*, 4> attributes;

View File

@ -49,7 +49,7 @@ type::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) {
case spv::StorageClass::Workgroup: case spv::StorageClass::Workgroup:
return type::AddressSpace::kWorkgroup; return type::AddressSpace::kWorkgroup;
case spv::StorageClass::UniformConstant: case spv::StorageClass::UniformConstant:
return type::AddressSpace::kNone; return type::AddressSpace::kUndefined;
case spv::StorageClass::StorageBuffer: case spv::StorageClass::StorageBuffer:
return type::AddressSpace::kStorage; return type::AddressSpace::kStorage;
case spv::StorageClass::Private: case spv::StorageClass::Private:

View File

@ -130,7 +130,7 @@ INSTANTIATE_TEST_SUITE_P(
StorageClassCase{spv::StorageClass::Output, true, type::AddressSpace::kOut}, StorageClassCase{spv::StorageClass::Output, true, type::AddressSpace::kOut},
StorageClassCase{spv::StorageClass::Uniform, true, type::AddressSpace::kUniform}, StorageClassCase{spv::StorageClass::Uniform, true, type::AddressSpace::kUniform},
StorageClassCase{spv::StorageClass::Workgroup, true, type::AddressSpace::kWorkgroup}, 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::StorageBuffer, true, type::AddressSpace::kStorage},
StorageClassCase{spv::StorageClass::Private, true, type::AddressSpace::kPrivate}, StorageClassCase{spv::StorageClass::Private, true, type::AddressSpace::kPrivate},
StorageClassCase{spv::StorageClass::Function, true, type::AddressSpace::kFunction})); StorageClassCase{spv::StorageClass::Function, true, type::AddressSpace::kFunction}));

View File

@ -2521,11 +2521,11 @@ bool FunctionEmitter::EmitFunctionVariables() {
return false; 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{}); var_store_type, initializer, AttributeList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
AddStatement(var_decl_stmt); 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); identifier_types_.emplace(inst.result_id(), var_type);
} }
return success(); return success();
@ -3367,9 +3367,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
// no need to remap pointer properties. // no need to remap pointer properties.
auto* store_type = parser_impl_.ConvertType(def_inst->type_id()); auto* store_type = parser_impl_.ConvertType(def_inst->type_id());
AddStatement(create<ast::VariableDeclStatement>( AddStatement(create<ast::VariableDeclStatement>(
Source{}, parser_impl_.MakeVar(id, type::AddressSpace::kNone, store_type, nullptr, Source{}, parser_impl_.MakeVar(id, type::AddressSpace::kUndefined, store_type, nullptr,
AttributeList{}))); AttributeList{})));
auto* type = ty_.Reference(store_type, type::AddressSpace::kNone); auto* type = ty_.Reference(store_type, type::AddressSpace::kUndefined);
identifier_types_.emplace(id, type); identifier_types_.emplace(id, type);
} }
@ -6190,8 +6190,8 @@ bool FunctionEmitter::MakeVectorInsertDynamic(const spvtools::opt::Instruction&
// API in parser_impl_. // API in parser_impl_.
var_name = namer_.MakeDerivedName(original_value_name); var_name = namer_.MakeDerivedName(original_value_name);
auto* temp_var = builder_.Var(var_name, type->Build(builder_), type::AddressSpace::kNone, auto* temp_var = builder_.Var(var_name, type->Build(builder_),
src_vector.expr); type::AddressSpace::kUndefined, src_vector.expr);
AddStatement(builder_.Decl({}, temp_var)); 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 // It doesn't correspond to a SPIR-V ID, so we don't use the ordinary
// API in parser_impl_. // API in parser_impl_.
var_name = namer_.MakeDerivedName(original_value_name); var_name = namer_.MakeDerivedName(original_value_name);
auto* temp_var = builder_.Var(var_name, type->Build(builder_), type::AddressSpace::kNone, auto* temp_var = builder_.Var(var_name, type->Build(builder_),
src_composite.expr); type::AddressSpace::kUndefined, src_composite.expr);
AddStatement(builder_.Decl({}, temp_var)); AddStatement(builder_.Decl({}, temp_var));
} }

View File

@ -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") o << " requires_named_let_def: " << (di.requires_named_let_def ? "true" : "false")
<< " requires_hoisted_var_def: " << (di.requires_hoisted_var_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); o << " sc:" << int(di.pointer.address_space);
} }
switch (di.skip) { switch (di.skip) {

View File

@ -1222,11 +1222,6 @@ const Type* ParserImpl::ConvertType(uint32_t type_id,
} }
auto ast_address_space = enum_converter_.ToAddressSpace(storage_class); 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<uint32_t>(storage_class);
return nullptr;
}
if (ast_address_space == type::AddressSpace::kUniform && if (ast_address_space == type::AddressSpace::kUniform &&
remap_buffer_block_type_.count(pointee_type_id)) { remap_buffer_block_type_.count(pointee_type_id)) {
ast_address_space = type::AddressSpace::kStorage; ast_address_space = type::AddressSpace::kStorage;
@ -1459,7 +1454,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
continue; continue;
} }
switch (enum_converter_.ToAddressSpace(spirv_storage_class)) { switch (enum_converter_.ToAddressSpace(spirv_storage_class)) {
case type::AddressSpace::kNone: case type::AddressSpace::kUndefined:
case type::AddressSpace::kIn: case type::AddressSpace::kIn:
case type::AddressSpace::kOut: case type::AddressSpace::kOut:
case type::AddressSpace::kUniform: case type::AddressSpace::kUniform:
@ -1476,7 +1471,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
return false; return false;
} }
const Type* ast_store_type = nullptr; 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) { if (spirv_storage_class == spv::StorageClass::UniformConstant) {
// These are opaque handles: samplers or textures // These are opaque handles: samplers or textures
ast_store_type = GetHandleTypeForSpirvHandle(var); 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 // Handle variables (textures and samplers) are always in the handle
// address space, so we don't mention the address space. // address space, so we don't mention the address space.
if (address_space == type::AddressSpace::kHandle) { if (address_space == type::AddressSpace::kHandle) {
address_space = type::AddressSpace::kNone; address_space = type::AddressSpace::kUndefined;
} }
if (!ConvertDecorationsForVariable(id, &storage_type, &decorations, if (!ConvertDecorationsForVariable(id, &storage_type, &decorations,

View File

@ -423,7 +423,7 @@ class ParserImpl : Reader {
/// Creates an AST 'var' node for a SPIR-V ID, including any attached decorations, unless it's /// Creates an AST 'var' node for a SPIR-V ID, including any attached decorations, unless it's
/// an ignorable builtin variable. /// an ignorable builtin variable.
/// @param id the SPIR-V result ID /// @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 storage_type the storage type of the variable
/// @param initializer the variable initializer /// @param initializer the variable initializer
/// @param decorations the variable decorations /// @param decorations the variable decorations

View File

@ -783,22 +783,6 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) {
EXPECT_TRUE(p->error().empty()); 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<Pointer>());
auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kNone);
EXPECT_TRUE(p->error().empty());
}
TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) { TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) {
auto p = parser(test::Assemble(Preamble() + R"( auto p = parser(test::Assemble(Preamble() + R"(
%float = OpTypeFloat 32 %float = OpTypeFloat 32

View File

@ -29,8 +29,8 @@ TEST(SpvParserTypeTest, SameArgumentsGivesSamePointer) {
EXPECT_EQ(ty.U32(), ty.U32()); EXPECT_EQ(ty.U32(), ty.U32());
EXPECT_EQ(ty.F32(), ty.F32()); EXPECT_EQ(ty.F32(), ty.F32());
EXPECT_EQ(ty.I32(), ty.I32()); EXPECT_EQ(ty.I32(), ty.I32());
EXPECT_EQ(ty.Pointer(ty.I32(), type::AddressSpace::kNone), EXPECT_EQ(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined),
ty.Pointer(ty.I32(), type::AddressSpace::kNone)); ty.Pointer(ty.I32(), type::AddressSpace::kUndefined));
EXPECT_EQ(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 3)); 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.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)); 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, {})); Symbol sym_b(Symbol(2, {}));
TypeManager ty; TypeManager ty;
EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kNone), EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined),
ty.Pointer(ty.U32(), type::AddressSpace::kNone)); ty.Pointer(ty.U32(), type::AddressSpace::kUndefined));
EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kNone), EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined),
ty.Pointer(ty.I32(), type::AddressSpace::kIn)); 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.U32(), 3));
EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 2)); EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 2));

View File

@ -292,7 +292,7 @@ class ParserImpl {
/// Variable name /// Variable name
std::string name; std::string name;
/// Variable address space /// Variable address space
type::AddressSpace address_space = type::AddressSpace::kNone; type::AddressSpace address_space = type::AddressSpace::kUndefined;
/// Variable access control /// Variable access control
type::Access access = type::Access::kUndefined; type::Access access = type::Access::kUndefined;
/// Variable type /// Variable type
@ -302,7 +302,7 @@ class ParserImpl {
/// VariableQualifier contains the parsed information for a variable qualifier /// VariableQualifier contains the parsed information for a variable qualifier
struct VariableQualifier { struct VariableQualifier {
/// The variable's address space /// The variable's address space
type::AddressSpace address_space = type::AddressSpace::kNone; type::AddressSpace address_space = type::AddressSpace::kUndefined;
/// The variable's access control /// The variable's access control
type::Access access = type::Access::kUndefined; type::Access access = type::Access::kUndefined;
}; };
@ -449,7 +449,7 @@ class ParserImpl {
Maybe<ast::Type> type_specifier(); Maybe<ast::Type> type_specifier();
/// Parses an `address_space` grammar element, erroring on parse failure. /// Parses an `address_space` grammar element, erroring on parse failure.
/// @param use a description of what was being parsed if an error was raised. /// @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<type::AddressSpace> expect_address_space(std::string_view use); Expect<type::AddressSpace> expect_address_space(std::string_view use);
/// Parses a `struct_decl` grammar element. /// Parses a `struct_decl` grammar element.
/// @returns the struct type or nullptr on error /// @returns the struct type or nullptr on error

View File

@ -1104,7 +1104,7 @@ INSTANTIATE_TEST_SUITE_P(
ResolverTest, ResolverTest,
ResolverFunctionParameterValidationTest, ResolverFunctionParameterValidationTest,
testing::Values( testing::Values(
TestParams{type::AddressSpace::kNone, Expectation::kInvalid}, TestParams{type::AddressSpace::kUndefined, Expectation::kInvalid},
TestParams{type::AddressSpace::kIn, Expectation::kInvalid}, TestParams{type::AddressSpace::kIn, Expectation::kInvalid},
TestParams{type::AddressSpace::kOut, Expectation::kInvalid}, TestParams{type::AddressSpace::kOut, Expectation::kInvalid},
TestParams{type::AddressSpace::kUniform, Expectation::kPassWithFullPtrParameterExtension}, TestParams{type::AddressSpace::kUniform, Expectation::kPassWithFullPtrParameterExtension},

View File

@ -1275,8 +1275,8 @@ Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type,
params.Reserve(match.parameters.Length()); params.Reserve(match.parameters.Length());
for (auto& p : match.parameters) { for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>( params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, type::AddressSpace::kNone, nullptr, static_cast<uint32_t>(params.Length()), p.type,
type::Access::kUndefined, p.usage)); type::AddressSpace::kUndefined, type::Access::kUndefined, p.usage));
} }
sem::PipelineStageSet supported_stages; sem::PipelineStageSet supported_stages;
if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) { if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) {
@ -1476,8 +1476,8 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
params.Reserve(match.parameters.Length()); params.Reserve(match.parameters.Length());
for (auto& p : match.parameters) { for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>( params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, type::AddressSpace::kNone, nullptr, static_cast<uint32_t>(params.Length()), p.type,
type::Access::kUndefined, p.usage)); type::AddressSpace::kUndefined, type::Access::kUndefined, p.usage));
} }
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime; : sem::EvaluationStage::kRuntime;
@ -1491,7 +1491,7 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
// Conversion. // Conversion.
auto* target = converters.GetOrCreate(match, [&]() { auto* target = converters.GetOrCreate(match, [&]() {
auto param = builder.create<sem::Parameter>( auto param = builder.create<sem::Parameter>(
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); type::Access::kUndefined, match.parameters[0].usage);
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime; : sem::EvaluationStage::kRuntime;

View File

@ -255,11 +255,11 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
ty = rhs->Type()->UnwrapRef(); // Implicit load of RHS 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; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty),
v->source)) { v->source)) {
AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol),
v->source); v->source);
@ -269,12 +269,12 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
sem::Variable* sem = nullptr; sem::Variable* sem = nullptr;
if (is_global) { if (is_global) {
sem = builder_->create<sem::GlobalVariable>( sem = builder_->create<sem::GlobalVariable>(
v, ty, sem::EvaluationStage::kRuntime, type::AddressSpace::kNone, v, ty, sem::EvaluationStage::kRuntime, type::AddressSpace::kUndefined,
type::Access::kUndefined, type::Access::kUndefined,
/* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt); /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
} else { } else {
sem = builder_->create<sem::LocalVariable>(v, ty, sem::EvaluationStage::kRuntime, sem = builder_->create<sem::LocalVariable>(v, ty, sem::EvaluationStage::kRuntime,
type::AddressSpace::kNone, type::AddressSpace::kUndefined,
type::Access::kUndefined, current_statement_, type::Access::kUndefined, current_statement_,
/* constant_value */ nullptr); /* constant_value */ nullptr);
} }
@ -318,11 +318,11 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
return nullptr; return nullptr;
} }
if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kNone, ty, rhs)) { if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kUndefined, ty, rhs)) {
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty),
v->source)) { v->source)) {
AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol),
v->source); v->source);
@ -330,7 +330,8 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
} }
auto* sem = builder_->create<sem::GlobalVariable>( auto* sem = builder_->create<sem::GlobalVariable>(
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); /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
sem->SetInitializer(rhs); sem->SetInitializer(rhs);
@ -411,11 +412,11 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
ty = rhs->Type(); ty = rhs->Type();
} }
if (!validator_.VariableInitializer(c, type::AddressSpace::kNone, ty, rhs)) { if (!validator_.VariableInitializer(c, type::AddressSpace::kUndefined, ty, rhs)) {
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty),
c->source)) { c->source)) {
AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol), AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol),
c->source); c->source);
@ -423,12 +424,13 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
} }
const auto value = rhs->ConstantValue(); const auto value = rhs->ConstantValue();
auto* sem = is_global ? static_cast<sem::Variable*>(builder_->create<sem::GlobalVariable>( auto* sem = is_global
c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kNone, ? static_cast<sem::Variable*>(builder_->create<sem::GlobalVariable>(
type::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt)) c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined,
: static_cast<sem::Variable*>(builder_->create<sem::LocalVariable>( type::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt))
c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kNone, : static_cast<sem::Variable*>(builder_->create<sem::LocalVariable>(
type::Access::kUndefined, current_statement_, value)); c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined,
type::Access::kUndefined, current_statement_, value));
sem->SetInitializer(rhs); sem->SetInitializer(rhs);
builder_->Sem().Add(c, sem); 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; 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. // No declared address space. Infer from usage / type.
if (!is_global) { if (!is_global) {
address_space = type::AddressSpace::kFunction; address_space = type::AddressSpace::kFunction;
@ -608,7 +610,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, ty, param->type->source)) { if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, ty, param->type->source)) {
add_note(); add_note();
return nullptr; return nullptr;
} }
@ -659,7 +661,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
} }
auto* sem = builder_->create<sem::Parameter>( auto* sem = builder_->create<sem::Parameter>(
param, index, ty, type::AddressSpace::kNone, type::Access::kUndefined, param, index, ty, type::AddressSpace::kUndefined, type::Access::kUndefined,
sem::ParameterUsage::kNone, binding_point, location); sem::ParameterUsage::kNone, binding_point, location);
builder_->Sem().Add(param, sem); builder_->Sem().Add(param, sem);
return sem; return sem;
@ -919,7 +921,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
} }
if (auto* str = return_type->As<sem::Struct>()) { if (auto* str = return_type->As<sem::Struct>()) {
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, str, decl->source)) { if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, str, decl->source)) {
AddNote("while instantiating return type for " + AddNote("while instantiating return type for " +
builder_->Symbols().NameFor(decl->name->symbol), builder_->Symbols().NameFor(decl->name->symbol),
decl->source); decl->source);
@ -2009,10 +2011,10 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&]() -> sem::TypeInitializer* { [&]() -> sem::TypeInitializer* {
auto params = utils::Transform(args, [&](auto, size_t i) { auto params = utils::Transform(args, [&](auto, size_t i) {
return builder_->create<sem::Parameter>( return builder_->create<sem::Parameter>(
nullptr, // declaration nullptr, // declaration
static_cast<uint32_t>(i), // index static_cast<uint32_t>(i), // index
arr->ElemType(), // type arr->ElemType(), // type
type::AddressSpace::kNone, // address_space type::AddressSpace::kUndefined, // address_space
type::Access::kUndefined); type::Access::kUndefined);
}); });
return builder_->create<sem::TypeInitializer>(arr, std::move(params), return builder_->create<sem::TypeInitializer>(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())); params.Resize(std::min(args.Length(), str->Members().Length()));
for (size_t i = 0, n = params.Length(); i < n; i++) { for (size_t i = 0, n = params.Length(); i < n; i++) {
params[i] = builder_->create<sem::Parameter>( params[i] = builder_->create<sem::Parameter>(
nullptr, // declaration nullptr, // declaration
static_cast<uint32_t>(i), // index static_cast<uint32_t>(i), // index
str->Members()[i]->Type(), // type str->Members()[i]->Type(), // type
type::AddressSpace::kNone, // address_space type::AddressSpace::kUndefined, // address_space
type::Access::kUndefined); // access type::Access::kUndefined); // access
} }
return builder_->create<sem::TypeInitializer>(str, std::move(params), return builder_->create<sem::TypeInitializer>(str, std::move(params),
args_stage); args_stage);

View File

@ -1901,7 +1901,7 @@ TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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) { TEST_F(ResolverTest, Access_SetForStorageBuffer) {

View File

@ -72,7 +72,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) {
TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) {
auto* a = GlobalVar("a", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), 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); auto* expr = Expr(a);
WrapInFunction(Call("textureDimensions", expr)); WrapInFunction(Call("textureDimensions", expr));

View File

@ -46,7 +46,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromParameter) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kNone)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) { TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) {
@ -58,7 +58,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kNone)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableFromGlobal) { TEST_F(ResolverAddressSpaceUseTest, StructReachableFromGlobal) {

View File

@ -612,7 +612,7 @@ bool Validator::GlobalVariable(
return false; 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); AddError("module-scope 'var' declaration must have a address space", decl->source);
return false; return false;
} }
@ -697,7 +697,7 @@ bool Validator::Var(const sem::Variable* v) const {
} }
if (store_ty->is_handle()) { 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 // 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 // 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. // must not have a address space attribute. The address space will always be handle.

View File

@ -113,7 +113,7 @@ TEST_F(ResolverVariableValidationTest, VarTypeNotConstructible) {
// var p : pointer<function, i32> = &v; // var p : pointer<function, i32> = &v;
auto* i = Var("i", ty.i32()); auto* i = Var("i", ty.i32());
auto* p = Var("a", ty.pointer<i32>(Source{{56, 78}}, type::AddressSpace::kFunction), auto* p = Var("a", ty.pointer<i32>(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); WrapInFunction(i, p);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -321,7 +321,7 @@ struct ModuleScopeVarToEntryPointParam::State {
bool needs_processing = false; bool needs_processing = false;
for (auto* var : func_sem->TransitivelyReferencedGlobals()) { for (auto* var : func_sem->TransitivelyReferencedGlobals()) {
if (var->AddressSpace() != type::AddressSpace::kNone) { if (var->AddressSpace() != type::AddressSpace::kUndefined) {
needs_processing = true; needs_processing = true;
break; break;
} }
@ -378,7 +378,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// Process and redeclare all variables referenced by the function. // Process and redeclare all variables referenced by the function.
for (auto* var : func_sem->TransitivelyReferencedGlobals()) { for (auto* var : func_sem->TransitivelyReferencedGlobals()) {
if (var->AddressSpace() == type::AddressSpace::kNone) { if (var->AddressSpace() == type::AddressSpace::kUndefined) {
continue; continue;
} }
if (local_private_vars_.count(var)) { if (local_private_vars_.count(var)) {
@ -470,7 +470,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// For entry points, pass non-handle types as pointers. // For entry points, pass non-handle types as pointers.
for (auto* target_var : target_sem->TransitivelyReferencedGlobals()) { for (auto* target_var : target_sem->TransitivelyReferencedGlobals()) {
auto sc = target_var->AddressSpace(); auto sc = target_var->AddressSpace();
if (sc == type::AddressSpace::kNone) { if (sc == type::AddressSpace::kUndefined) {
continue; continue;
} }
@ -501,7 +501,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// Now remove all module-scope variables with these address spaces. // Now remove all module-scope variables with these address spaces.
for (auto* var_ast : ctx.src->AST().GlobalVariables()) { for (auto* var_ast : ctx.src->AST().GlobalVariables()) {
auto* var_sem = ctx.src->Sem().Get(var_ast); 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); ctx.Remove(ctx.src->AST().GlobalDeclarations(), var_ast);
} }
} }

View File

@ -59,8 +59,6 @@ std::ostream& operator<<(std::ostream& out, AddressSpace value) {
return out << "handle"; return out << "handle";
case AddressSpace::kIn: case AddressSpace::kIn:
return out << "in"; return out << "in";
case AddressSpace::kNone:
return out << "none";
case AddressSpace::kOut: case AddressSpace::kOut:
return out << "out"; return out << "out";
case AddressSpace::kPrivate: case AddressSpace::kPrivate:

View File

@ -33,7 +33,6 @@ enum class AddressSpace {
kFunction, kFunction,
kHandle, // Tint-internal enum entry - not parsed kHandle, // Tint-internal enum entry - not parsed
kIn, // 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 kOut, // Tint-internal enum entry - not parsed
kPrivate, kPrivate,
kPushConstant, kPushConstant,

View File

@ -45,7 +45,7 @@ bool Pointer::Equals(const UniqueNode& other) const {
std::string Pointer::FriendlyName(const SymbolTable& symbols) const { std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out; std::ostringstream out;
out << "ptr<"; out << "ptr<";
if (address_space_ != AddressSpace::kNone) { if (address_space_ != AddressSpace::kUndefined) {
out << address_space_ << ", "; out << address_space_ << ", ";
} }
out << subtype_->FriendlyName(symbols) << ", " << access_; out << subtype_->FriendlyName(symbols) << ", " << access_;

View File

@ -59,7 +59,7 @@ TEST_F(PointerTest, Equals) {
} }
TEST_F(PointerTest, FriendlyName) { TEST_F(PointerTest, FriendlyName) {
auto* r = create<Pointer>(create<I32>(), AddressSpace::kNone, type::Access::kRead); auto* r = create<Pointer>(create<I32>(), AddressSpace::kUndefined, type::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32, read>"); EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32, read>");
} }

View File

@ -44,7 +44,7 @@ bool Reference::Equals(const UniqueNode& other) const {
std::string Reference::FriendlyName(const SymbolTable& symbols) const { std::string Reference::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out; std::ostringstream out;
out << "ref<"; out << "ref<";
if (address_space_ != AddressSpace::kNone) { if (address_space_ != AddressSpace::kUndefined) {
out << address_space_ << ", "; out << address_space_ << ", ";
} }
out << subtype_->FriendlyName(symbols) << ", " << access_; out << subtype_->FriendlyName(symbols) << ", " << access_;

View File

@ -59,7 +59,7 @@ TEST_F(ReferenceTest, Equals) {
} }
TEST_F(ReferenceTest, FriendlyName) { TEST_F(ReferenceTest, FriendlyName) {
auto* r = create<Reference>(create<I32>(), AddressSpace::kNone, type::Access::kRead); auto* r = create<Reference>(create<I32>(), AddressSpace::kUndefined, type::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32, read>"); EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32, read>");
} }

View File

@ -137,7 +137,7 @@ const sem::Call* AppendVector(ProgramBuilder* b,
auto* scalar_cast_target = b->create<sem::TypeConversion>( auto* scalar_cast_target = b->create<sem::TypeConversion>(
packed_el_sem_ty, packed_el_sem_ty,
b->create<sem::Parameter>(nullptr, 0u, scalar_sem->Type()->UnwrapRef(), b->create<sem::Parameter>(nullptr, 0u, scalar_sem->Type()->UnwrapRef(),
type::AddressSpace::kNone, type::Access::kUndefined), type::AddressSpace::kUndefined, type::Access::kUndefined),
sem::EvaluationStage::kRuntime); sem::EvaluationStage::kRuntime);
auto* scalar_cast_sem = b->create<sem::Call>( auto* scalar_cast_sem = b->create<sem::Call>(
scalar_cast_ast, scalar_cast_target, sem::EvaluationStage::kRuntime, 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* { [&](const tint::sem::ValueExpression* arg, size_t i) -> const sem::Parameter* {
return b->create<sem::Parameter>( return b->create<sem::Parameter>(
nullptr, static_cast<uint32_t>(i), arg->Type()->UnwrapRef(), nullptr, static_cast<uint32_t>(i), arg->Type()->UnwrapRef(),
type::AddressSpace::kNone, type::Access::kUndefined); type::AddressSpace::kUndefined, type::Access::kUndefined);
}), }),
sem::EvaluationStage::kRuntime); sem::EvaluationStage::kRuntime);
auto* initializer_sem = auto* initializer_sem =

View File

@ -374,7 +374,8 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression*
dst_type->is_float_scalar_or_vector()) { dst_type->is_float_scalar_or_vector()) {
out << "uintBitsToFloat"; out << "uintBitsToFloat";
} else { } 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; return false;
} }
} }
@ -437,12 +438,12 @@ bool GeneratorImpl::EmitBitwiseBoolOp(std::ostream& out, const ast::BinaryExpres
auto* uint_type = BoolTypeToUint(bool_type); auto* uint_type = BoolTypeToUint(bool_type);
// Cast result to bool scalar or vector 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; return false;
} }
ScopedParen outerCastParen(out); ScopedParen outerCastParen(out);
// Cast LHS to uint scalar or vector type. // 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; return false;
} }
{ {
@ -462,7 +463,7 @@ bool GeneratorImpl::EmitBitwiseBoolOp(std::ostream& out, const ast::BinaryExpres
return false; return false;
} }
// Cast RHS to uint scalar or vector type. // 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; return false;
} }
{ {
@ -480,43 +481,43 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi
auto* ret_ty = TypeOf(expr)->UnwrapRef(); auto* ret_ty = TypeOf(expr)->UnwrapRef();
auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef(); auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef();
auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef(); auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef();
fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, fn = utils::GetOrCreate(
[&]() -> std::string { float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, [&]() -> std::string {
TextBuffer b; TextBuffer b;
TINT_DEFER(helpers_.Append(b)); TINT_DEFER(helpers_.Append(b));
auto fn_name = UniqueIdentifier("tint_float_modulo"); auto fn_name = UniqueIdentifier("tint_float_modulo");
std::vector<std::string> parameter_names; std::vector<std::string> parameter_names;
{ {
auto decl = line(&b); auto decl = line(&b);
if (!EmitTypeAndName(decl, ret_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(decl, ret_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, fn_name)) { type::Access::kUndefined, fn_name)) {
return ""; return "";
} }
{ {
ScopedParen sp(decl); ScopedParen sp(decl);
const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); const auto* ty = TypeOf(expr->lhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "lhs")) { type::Access::kUndefined, "lhs")) {
return ""; return "";
} }
decl << ", "; decl << ", ";
ty = TypeOf(expr->rhs)->UnwrapRef(); ty = TypeOf(expr->rhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "rhs")) { type::Access::kUndefined, "rhs")) {
return ""; return "";
} }
} }
decl << " {"; decl << " {";
} }
{ {
ScopedIndent si(&b); ScopedIndent si(&b);
line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; line(&b) << "return (lhs - rhs * trunc(lhs / rhs));";
} }
line(&b) << "}"; line(&b) << "}";
line(&b); line(&b);
return fn_name; return fn_name;
}); });
if (fn.empty()) { if (fn.empty()) {
return false; return false;
@ -826,7 +827,8 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
bool GeneratorImpl::EmitTypeConversion(std::ostream& out, bool GeneratorImpl::EmitTypeConversion(std::ostream& out,
const sem::Call* call, const sem::Call* call,
const sem::TypeConversion* conv) { 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; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -849,7 +851,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out,
return EmitZeroValue(out, type); 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; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -919,7 +921,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ {
auto pre = line(); auto pre = line();
if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, result)) { type::Access::kUndefined, result)) {
return false; 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) { bool GeneratorImpl::EmitCountOneBitsCall(std::ostream& out, const ast::CallExpression* expr) {
// GLSL's bitCount returns an integer type, so cast it to the appropriate // GLSL's bitCount returns an integer type, so cast it to the appropriate
// unsigned type. // unsigned type.
if (!EmitType(out, TypeOf(expr)->UnwrapRef(), type::AddressSpace::kNone, if (!EmitType(out, TypeOf(expr)->UnwrapRef(), type::AddressSpace::kUndefined,
type::Access::kReadWrite, "")) { type::Access::kReadWrite, "")) {
return false; return false;
} }
@ -1129,24 +1131,24 @@ bool GeneratorImpl::EmitDotCall(std::ostream& out,
std::string v; std::string v;
{ {
std::stringstream s; 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 ""; return "";
} }
v = s.str(); v = s.str();
} }
{ // (u)int tint_int_dot([i|u]vecN a, [i|u]vecN b) { { // (u)int tint_int_dot([i|u]vecN a, [i|u]vecN b) {
auto l = line(&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 ""; return "";
} }
l << " " << fn_name << "("; 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 ""; return "";
} }
l << " a, "; 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 ""; return "";
} }
l << " b) {"; l << " b) {";
@ -1197,7 +1199,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out,
{ {
auto l = line(b); auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, "")) { type::Access::kUndefined, "")) {
return false; return false;
} }
@ -1223,7 +1225,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
{ {
auto l = line(b); auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, "")) { type::Access::kUndefined, "")) {
return false; return false;
} }
@ -1881,8 +1883,8 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
{ {
auto out = line(); auto out = line();
auto name = builder_.Symbols().NameFor(func->name->symbol); 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; return false;
} }
@ -1907,7 +1909,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
type = ptr->StoreType(); 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 // the sanitizer transforms generates load / store functions for storage
// or uniform buffers. These functions have a buffer parameter with // or uniform buffers. These functions have a buffer parameter with
// AddressSpace::kStorage or AddressSpace::kUniform. This is required to // 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; return true;
}, },
[&](const type::Vector* v) { [&](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; return false;
} }
@ -2360,7 +2362,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const constant::Value* const
return true; return true;
}, },
[&](const type::Matrix* m) { [&](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; return false;
} }
@ -2377,7 +2379,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const constant::Value* const
return true; return true;
}, },
[&](const type::Array* a) { [&](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; return false;
} }
@ -2469,7 +2471,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
} else if (type->Is<type::U32>()) { } else if (type->Is<type::U32>()) {
out << "0u"; out << "0u";
} else if (auto* vec = type->As<type::Vector>()) { } else if (auto* vec = type->As<type::Vector>()) {
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) {
return false; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -2482,7 +2484,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
} }
} }
} else if (auto* mat = type->As<type::Matrix>()) { } else if (auto* mat = type->As<type::Matrix>()) {
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) {
return false; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -2495,7 +2497,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
} }
} }
} else if (auto* str = type->As<sem::Struct>()) { } else if (auto* str = type->As<sem::Struct>()) {
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) {
return false; return false;
} }
bool first = true; bool first = true;
@ -2509,7 +2511,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
EmitZeroValue(out, member->Type()); EmitZeroValue(out, member->Type());
} }
} else if (auto* arr = type->As<type::Array>()) { } else if (auto* arr = type->As<type::Array>()) {
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kUndefined, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) {
return false; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -3052,7 +3054,8 @@ bool GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) {
auto out = line(b); 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; return false;
} }
out << ";"; out << ";";
@ -3120,7 +3123,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
auto out = line(); auto out = line();
// TODO(senorblanco): handle const // 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))) { builder_.Symbols().NameFor(let->name->symbol))) {
return false; return false;
} }
@ -3142,7 +3145,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) {
auto out = line(); auto out = line();
out << "const "; 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))) { builder_.Symbols().NameFor(var->name->symbol))) {
return false; return false;
} }
@ -3169,7 +3172,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
std::vector<std::string> parameter_names; std::vector<std::string> parameter_names;
{ {
auto decl = line(&b); 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)) { type::Access::kUndefined, fn_name)) {
return ""; return "";
} }
@ -3185,7 +3188,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
decl << "inout "; decl << "inout ";
ty = ptr->StoreType(); ty = ptr->StoreType();
} }
if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, param_name)) { type::Access::kUndefined, param_name)) {
return ""; return "";
} }

View File

@ -39,7 +39,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[4]"); EXPECT_EQ(out.str(), "bool ary[4]");
@ -52,7 +52,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[5][4]"); EXPECT_EQ(out.str(), "bool ary[5][4]");
@ -65,7 +65,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[6][5][4]"); EXPECT_EQ(out.str(), "bool ary[6][5][4]");
@ -78,7 +78,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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, "")) type::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool[4]"); EXPECT_EQ(out.str(), "bool[4]");
@ -90,7 +90,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Bool) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "bool"); EXPECT_EQ(out.str(), "bool");
} }
@ -101,7 +102,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float"); EXPECT_EQ(out.str(), "float");
} }
@ -114,7 +116,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float16_t"); EXPECT_EQ(out.str(), "float16_t");
} }
@ -125,7 +128,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "int"); EXPECT_EQ(out.str(), "int");
} }
@ -138,7 +142,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "mat2x3"); EXPECT_EQ(out.str(), "mat2x3");
} }
@ -153,7 +158,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "f16mat2x3"); EXPECT_EQ(out.str(), "f16mat2x3");
} }
@ -189,7 +195,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct) {
auto* sem_s = program->TypeOf(s)->As<sem::Struct>(); auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "S"); EXPECT_EQ(out.str(), "S");
} }
@ -237,7 +244,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_U32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "uint"); EXPECT_EQ(out.str(), "uint");
} }
@ -249,7 +257,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "vec3"); EXPECT_EQ(out.str(), "vec3");
} }
@ -263,7 +272,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "f16vec3"); EXPECT_EQ(out.str(), "f16vec3");
} }
@ -274,7 +284,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Void) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "void"); EXPECT_EQ(out.str(), "void");
} }
@ -286,7 +297,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSampler) {
std::stringstream out; std::stringstream out;
ASSERT_FALSE( ASSERT_FALSE(
gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
} }
@ -297,7 +308,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) {
std::stringstream out; std::stringstream out;
ASSERT_FALSE( ASSERT_FALSE(
gen.EmitType(out, sampler, type::AddressSpace::kNone, type::Access::kReadWrite, "")) gen.EmitType(out, sampler, type::AddressSpace::kUndefined, type::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
} }
@ -503,7 +514,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "highp sampler2DMS"); EXPECT_EQ(out.str(), "highp sampler2DMS");
} }

View File

@ -642,7 +642,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression*
} }
out << "as"; out << "as";
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) {
return false; return false;
} }
out << "("; out << "(";
@ -1030,7 +1030,8 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
bool GeneratorImpl::EmitTypeConversion(std::ostream& out, bool GeneratorImpl::EmitTypeConversion(std::ostream& out,
const sem::Call* call, const sem::Call* call,
const sem::TypeConversion* conv) { 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; return false;
} }
out << "("; out << "(";
@ -1075,7 +1076,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out,
if (brackets) { if (brackets) {
out << "{"; out << "{";
} else { } else {
if (!EmitType(out, type, type::AddressSpace::kNone, type::Access::kReadWrite, "")) { if (!EmitType(out, type, type::AddressSpace::kUndefined, type::Access::kReadWrite, "")) {
return false; return false;
} }
out << "("; out << "(";
@ -1592,13 +1593,13 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
auto rmw = [&](const char* hlsl) -> bool { auto rmw = [&](const char* hlsl) -> bool {
{ {
auto fn = line(&buf); auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined,
name)) { type::Access::kUndefined, name)) {
return false; return false;
} }
fn << "(RWByteAddressBuffer buffer, uint offset, "; fn << "(RWByteAddressBuffer buffer, uint offset, ";
if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined,
"value")) { type::Access::kUndefined, "value")) {
return false; return false;
} }
fn << ") {"; fn << ") {";
@ -1613,8 +1614,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ {
auto l = line(&buf); auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, type::Access::kUndefined, if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined,
"original_value")) { type::Access::kUndefined, "original_value")) {
return false; return false;
} }
l << " = 0;"; l << " = 0;";
@ -1662,7 +1663,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
// InterlockedOr using 0 as the OR value // InterlockedOr using 0 as the OR value
{ {
auto fn = line(&buf); auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, name)) { type::Access::kUndefined, name)) {
return false; return false;
} }
@ -1678,7 +1679,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ {
auto l = line(&buf); auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "value")) { type::Access::kUndefined, "value")) {
return false; return false;
} }
@ -1696,7 +1697,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ {
auto fn = line(&buf); auto fn = line(&buf);
fn << "void " << name << "(RWByteAddressBuffer buffer, uint offset, "; 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")) { type::Access::kUndefined, "value")) {
return false; return false;
} }
@ -1712,7 +1713,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ {
auto l = line(&buf); auto l = line(&buf);
if (!EmitTypeAndName(l, value_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(l, value_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "ignored")) { type::Access::kUndefined, "ignored")) {
return false; return false;
} }
@ -1727,17 +1728,17 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
auto* value_ty = params[2]->Type()->UnwrapRef(); auto* value_ty = params[2]->Type()->UnwrapRef();
{ {
auto fn = line(&buf); auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(fn, result_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, name)) { type::Access::kUndefined, name)) {
return false; return false;
} }
fn << "(RWByteAddressBuffer buffer, uint offset, "; 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")) { type::Access::kUndefined, "compare")) {
return false; return false;
} }
fn << ", "; fn << ", ";
if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(fn, value_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "value")) { type::Access::kUndefined, "value")) {
return false; return false;
} }
@ -1753,7 +1754,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ // T result = {0}; { // T result = {0};
auto l = line(&buf); auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kNone, if (!EmitTypeAndName(l, result_ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, "result")) { type::Access::kUndefined, "result")) {
return false; return false;
} }
@ -1788,7 +1789,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
if (!builtin->ReturnType()->Is<type::Void>()) { if (!builtin->ReturnType()->Is<type::Void>()) {
auto pre = line(); auto pre = line();
if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitTypeAndName(pre, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, result)) { type::Access::kUndefined, result)) {
return false; return false;
} }
@ -1852,7 +1853,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ // T result = 0; { // T result = 0;
auto pre = line(); auto pre = line();
auto* value_ty = builtin->Parameters()[1]->Type()->UnwrapRef(); 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)) { type::Access::kUndefined, result)) {
return false; return false;
} }
@ -1891,7 +1892,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ // T compare_value = <compare_value>; { // T compare_value = <compare_value>;
auto pre = line(); auto pre = line();
if (!EmitTypeAndName(pre, TypeOf(compare_value)->UnwrapRef(), if (!EmitTypeAndName(pre, TypeOf(compare_value)->UnwrapRef(),
type::AddressSpace::kNone, type::Access::kUndefined, type::AddressSpace::kUndefined, type::Access::kUndefined,
compare)) { compare)) {
return false; return false;
} }
@ -2001,7 +2002,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out,
{ {
auto l = line(b); auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, "")) { type::Access::kUndefined, "")) {
return false; return false;
} }
@ -2043,7 +2044,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
line(b) << member_type << " fract = frexp(" << in << ", exp);"; line(b) << member_type << " fract = frexp(" << in << ", exp);";
{ {
auto l = line(b); auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kNone, if (!EmitType(l, builtin->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kUndefined, "")) { type::Access::kUndefined, "")) {
return false; return false;
} }
@ -2081,7 +2082,7 @@ bool GeneratorImpl::EmitRadiansCall(std::ostream& out,
// type after the call to `sign`. // type after the call to `sign`.
bool GeneratorImpl::EmitSignCall(std::ostream& out, const sem::Call* call, const sem::Builtin*) { bool GeneratorImpl::EmitSignCall(std::ostream& out, const sem::Call* call, const sem::Builtin*) {
auto* arg = call->Arguments()[0]; 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; return false;
} }
out << "(sign("; out << "(sign(";
@ -2883,14 +2884,14 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
auto typedef_name = UniqueIdentifier(name + "_ret"); auto typedef_name = UniqueIdentifier(name + "_ret");
auto pre = line(); auto pre = line();
pre << "typedef "; pre << "typedef ";
if (!EmitTypeAndName(pre, sem->ReturnType(), type::AddressSpace::kNone, if (!EmitTypeAndName(pre, sem->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kReadWrite, typedef_name)) { type::Access::kReadWrite, typedef_name)) {
return false; return false;
} }
pre << ";"; pre << ";";
out << typedef_name; out << typedef_name;
} else { } else {
if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kNone, if (!EmitType(out, sem->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kReadWrite, "")) { type::Access::kReadWrite, "")) {
return false; return false;
} }
@ -2907,7 +2908,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
first = false; first = false;
auto const* type = v->Type(); auto const* type = v->Type();
auto address_space = type::AddressSpace::kNone; auto address_space = type::AddressSpace::kUndefined;
auto access = type::Access::kUndefined; auto access = type::Access::kUndefined;
if (auto* ptr = type->As<type::Pointer>()) { if (auto* ptr = type->As<type::Pointer>()) {
@ -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 // the sanitizer transforms generates load / store functions for storage
// or uniform buffers. These functions have a buffer parameter with // or uniform buffers. These functions have a buffer parameter with
// AddressSpace::kStorage or AddressSpace::kUniform. This is required to // 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 name = builder_.Symbols().NameFor(builder_.Symbols().New("unused"));
{ {
auto out = line(); auto out = line();
if (!EmitTypeAndName(out, sem->ReturnType(), type::AddressSpace::kNone, if (!EmitTypeAndName(out, sem->ReturnType(), type::AddressSpace::kUndefined,
type::Access::kReadWrite, name)) { type::Access::kReadWrite, name)) {
return false; return false;
} }
@ -3335,7 +3336,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out,
return true; return true;
} }
if (!EmitType(out, v, type::AddressSpace::kNone, type::Access::kUndefined, "")) { if (!EmitType(out, v, type::AddressSpace::kUndefined, type::Access::kUndefined, "")) {
return false; return false;
} }
@ -3352,7 +3353,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out,
return true; return true;
}, },
[&](const type::Matrix* m) { [&](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; return false;
} }
@ -3371,7 +3372,8 @@ bool GeneratorImpl::EmitConstant(std::ostream& out,
[&](const type::Array* a) { [&](const type::Array* a) {
if (constant->AllZero()) { if (constant->AllZero()) {
out << "("; out << "(";
if (!EmitType(out, a, type::AddressSpace::kNone, type::Access::kUndefined, "")) { if (!EmitType(out, a, type::AddressSpace::kUndefined, type::Access::kUndefined,
"")) {
return false; return false;
} }
out << ")0"; out << ")0";
@ -3511,7 +3513,8 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val
return true; return true;
}, },
[&](const type::Vector* vec) { [&](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; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -3526,7 +3529,8 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val
return true; return true;
}, },
[&](const type::Matrix* mat) { [&](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; return false;
} }
ScopedParen sp(out); ScopedParen sp(out);
@ -3543,12 +3547,14 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val
[&](const sem::Struct*) { [&](const sem::Struct*) {
out << "("; out << "(";
TINT_DEFER(out << ")" << value); 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*) { [&](const type::Array*) {
out << "("; out << "(";
TINT_DEFER(out << ")" << value); 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) { [&](Default) {
diagnostics_.add_error( diagnostics_.add_error(
@ -4232,7 +4238,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
} }
out << pre; out << pre;
if (!EmitTypeAndName(out, ty, type::AddressSpace::kNone, type::Access::kReadWrite, if (!EmitTypeAndName(out, ty, type::AddressSpace::kUndefined, type::Access::kReadWrite,
mem_name)) { mem_name)) {
return false; return false;
} }
@ -4302,7 +4308,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
auto out = line(); auto out = line();
out << "const "; 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))) { builder_.Symbols().NameFor(let->name->symbol))) {
return false; return false;
} }
@ -4329,7 +4335,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
std::vector<std::string> parameter_names; std::vector<std::string> parameter_names;
{ {
auto decl = line(&b); 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)) { type::Access::kUndefined, fn_name)) {
return ""; return "";
} }
@ -4345,7 +4351,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
decl << "inout "; decl << "inout ";
ty = ptr->StoreType(); ty = ptr->StoreType();
} }
if (!EmitTypeAndName(decl, ty, type::AddressSpace::kNone, if (!EmitTypeAndName(decl, ty, type::AddressSpace::kUndefined,
type::Access::kUndefined, param_name)) { type::Access::kUndefined, param_name)) {
return ""; return "";
} }

View File

@ -575,7 +575,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
GlobalVar("d", ty.bool_(), type::AddressSpace::kPrivate); GlobalVar("d", ty.bool_(), type::AddressSpace::kPrivate);
auto* var = auto* var =
Var("a", ty.bool_(), type::AddressSpace::kNone, Var("a", ty.bool_(), type::AddressSpace::kUndefined,
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("b"), Expr("c")), create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("b"), Expr("c")),

View File

@ -39,7 +39,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[4]"); EXPECT_EQ(out.str(), "bool ary[4]");
@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[5][4]"); EXPECT_EQ(out.str(), "bool ary[5][4]");
@ -65,7 +65,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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")) type::Access::kReadWrite, "ary"))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool ary[6][5][4]"); EXPECT_EQ(out.str(), "bool ary[6][5][4]");
@ -78,7 +78,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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, "")) type::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "bool[4]"); EXPECT_EQ(out.str(), "bool[4]");
@ -90,7 +90,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "bool"); EXPECT_EQ(out.str(), "bool");
} }
@ -101,7 +102,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float16_t"); EXPECT_EQ(out.str(), "float16_t");
} }
@ -112,7 +114,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float"); EXPECT_EQ(out.str(), "float");
} }
@ -123,7 +126,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "int"); EXPECT_EQ(out.str(), "int");
} }
@ -136,7 +140,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "matrix<float16_t, 2, 3>"); EXPECT_EQ(out.str(), "matrix<float16_t, 2, 3>");
} }
@ -149,7 +154,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float2x3"); EXPECT_EQ(out.str(), "float2x3");
} }
@ -198,7 +204,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
auto* sem_s = program->TypeOf(s)->As<sem::Struct>(); auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "S"); EXPECT_EQ(out.str(), "S");
} }
@ -245,7 +252,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "uint"); EXPECT_EQ(out.str(), "uint");
} }
@ -257,7 +265,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "float3"); EXPECT_EQ(out.str(), "float3");
} }
@ -268,7 +277,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "void"); EXPECT_EQ(out.str(), "void");
} }
@ -279,7 +289,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "SamplerState"); EXPECT_EQ(out.str(), "SamplerState");
} }
@ -290,7 +301,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "SamplerComparisonState"); EXPECT_EQ(out.str(), "SamplerComparisonState");
} }
@ -500,7 +512,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; 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(); << gen.error();
EXPECT_EQ(out.str(), "Texture2DMS<float4>"); EXPECT_EQ(out.str(), "Texture2DMS<float4>");
} }

View File

@ -3027,7 +3027,6 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) {
switch (sem->AddressSpace()) { switch (sem->AddressSpace()) {
case type::AddressSpace::kFunction: case type::AddressSpace::kFunction:
case type::AddressSpace::kHandle: case type::AddressSpace::kHandle:
case type::AddressSpace::kNone:
break; break;
case type::AddressSpace::kPrivate: case type::AddressSpace::kPrivate:
out << "thread "; out << "thread ";
@ -3056,7 +3055,7 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) {
} }
} else if (sem->AddressSpace() == type::AddressSpace::kPrivate || } else if (sem->AddressSpace() == type::AddressSpace::kPrivate ||
sem->AddressSpace() == type::AddressSpace::kFunction || sem->AddressSpace() == type::AddressSpace::kFunction ||
sem->AddressSpace() == type::AddressSpace::kNone) { sem->AddressSpace() == type::AddressSpace::kUndefined) {
out << " = "; out << " = ";
if (!EmitZeroValue(out, type)) { if (!EmitZeroValue(out, type)) {
return false; return false;
@ -3076,7 +3075,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
switch (sem->AddressSpace()) { switch (sem->AddressSpace()) {
case type::AddressSpace::kFunction: case type::AddressSpace::kFunction:
case type::AddressSpace::kHandle: case type::AddressSpace::kHandle:
case type::AddressSpace::kNone: case type::AddressSpace::kUndefined:
break; break;
case type::AddressSpace::kPrivate: case type::AddressSpace::kPrivate:
out << "thread "; out << "thread ";

View File

@ -778,8 +778,8 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
auto result = result_op(); auto result = result_op();
auto var_id = std::get<uint32_t>(result); auto var_id = std::get<uint32_t>(result);
auto sc = sem->AddressSpace() == type::AddressSpace::kNone ? type::AddressSpace::kPrivate auto sc = sem->AddressSpace() == type::AddressSpace::kUndefined ? type::AddressSpace::kPrivate
: sem->AddressSpace(); : sem->AddressSpace();
auto type_id = GenerateTypeIfNeeded(sem->Type()); auto type_id = GenerateTypeIfNeeded(sem->Type());
if (type_id == 0) { 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 { SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const {
switch (klass) { switch (klass) {
case type::AddressSpace::kUndefined:
return SpvStorageClassMax;
case type::AddressSpace::kIn: case type::AddressSpace::kIn:
return SpvStorageClassInput; return SpvStorageClassInput;
case type::AddressSpace::kOut: case type::AddressSpace::kOut:
@ -3998,7 +3996,7 @@ SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const {
return SpvStorageClassPrivate; return SpvStorageClassPrivate;
case type::AddressSpace::kFunction: case type::AddressSpace::kFunction:
return SpvStorageClassFunction; return SpvStorageClassFunction;
case type::AddressSpace::kNone: case type::AddressSpace::kUndefined:
break; break;
} }
return SpvStorageClassMax; return SpvStorageClassMax;

View File

@ -271,7 +271,8 @@ INSTANTIATE_TEST_SUITE_P(
BuilderTest_Type, BuilderTest_Type,
BuiltinDataTest, BuiltinDataTest,
testing::Values( 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::kIn, SpvBuiltInFragCoord},
BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition}, BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition},
BuiltinData{ BuiltinData{

View File

@ -623,7 +623,7 @@ TEST_P(PtrDataTest, ConvertAddressSpace) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
BuilderTest_Type, BuilderTest_Type,
PtrDataTest, PtrDataTest,
testing::Values(PtrData{type::AddressSpace::kNone, SpvStorageClassMax}, testing::Values(PtrData{type::AddressSpace::kUndefined, SpvStorageClassMax},
PtrData{type::AddressSpace::kIn, SpvStorageClassInput}, PtrData{type::AddressSpace::kIn, SpvStorageClassInput},
PtrData{type::AddressSpace::kOut, SpvStorageClassOutput}, PtrData{type::AddressSpace::kOut, SpvStorageClassOutput},
PtrData{type::AddressSpace::kUniform, SpvStorageClassUniform}, PtrData{type::AddressSpace::kUniform, SpvStorageClassUniform},

View File

@ -475,7 +475,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, const ast::Variable* v) {
out << "var"; out << "var";
auto address_space = var->declared_address_space; auto address_space = var->declared_address_space;
auto ac = var->declared_access; 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; out << "<" << address_space;
if (ac != type::Access::kUndefined) { if (ac != type::Access::kUndefined) {
out << ", "; out << ", ";