tint: Reduce repetition for ty.type_name()

Rename the type_name() method with  operator().

`ty.type_name("blah")` becomes `ty("blah")`

Change-Id: Ia0b2bc304e7bb208c2e40a469332044b394535d9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118401
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton
2023-02-03 14:01:43 +00:00
committed by Dawn LUCI CQ
parent 6bd233fe54
commit 2117f80f8b
40 changed files with 296 additions and 310 deletions

View File

@@ -459,7 +459,7 @@ struct CanonicalizeEntryPointIO::State {
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func_ast, in_struct);
// Create a new function parameter using this struct type.
auto* param = ctx.dst->Param(InputStructSymbol(), ctx.dst->ty.type_name(struct_name));
auto* param = ctx.dst->Param(InputStructSymbol(), ctx.dst->ty(struct_name));
wrapper_ep_parameters.Push(param);
}
@@ -503,7 +503,7 @@ struct CanonicalizeEntryPointIO::State {
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func_ast, out_struct);
// Create the output struct object, assign its members, and return it.
auto* result_object = ctx.dst->Var(wrapper_result, ctx.dst->ty.type_name(out_struct->name));
auto* result_object = ctx.dst->Var(wrapper_result, ctx.dst->ty(out_struct->name));
wrapper_body.Push(ctx.dst->Decl(result_object));
for (auto* assignment : assignments) {
wrapper_body.Push(assignment);
@@ -633,9 +633,7 @@ struct CanonicalizeEntryPointIO::State {
CreateGlobalOutputVariables();
} else {
auto* output_struct = CreateOutputStruct();
wrapper_ret_type = [&, output_struct] {
return ctx.dst->ty.type_name(output_struct->name);
};
wrapper_ret_type = [&, output_struct] { return ctx.dst->ty(output_struct->name); };
}
}

View File

@@ -124,7 +124,7 @@ Transform::ApplyResult ClampFragDepth::Apply(const Program* src, const DataMap&,
utils::Vector{b.Member("min", b.ty.f32()), b.Member("max", b.ty.f32())});
auto args_sym = b.Symbols().New("frag_depth_clamp_args");
b.GlobalVar(args_sym, b.ty.type_name("FragDepthClampArgs"), type::AddressSpace::kPushConstant);
b.GlobalVar(args_sym, b.ty("FragDepthClampArgs"), type::AddressSpace::kPushConstant);
auto base_fn_sym = b.Symbols().New("clamp_frag_depth");
b.Func(base_fn_sym, utils::Vector{b.Param("v", b.ty.f32())}, b.ty.f32(),

View File

@@ -87,7 +87,7 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src,
return name;
});
auto* count = ctx.Clone(ast->count);
return b.ty.array(b.ty.type_name(el_ty), count);
return b.ty.array(b.ty(el_ty), count);
}
if (ast::GetAttribute<ast::StrideAttribute>(ast->attributes)) {
// Strip the @stride attribute

View File

@@ -510,16 +510,15 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
// }
ProgramBuilder b;
b.Alias("ARR", b.ty.array<f32, 4u>(32));
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR"))});
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR"))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, type::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{
b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("a", b.ty("ARR"), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor(b.MemberAccessor("s", "a"), 1_i))),
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.type_name("ARR"))),
b.Assign(b.MemberAccessor("s", "a"),
b.Construct(b.ty.type_name("ARR"), 1_f, 2_f, 3_f, 4_f)),
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty("ARR"))),
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty("ARR"), 1_f, 2_f, 3_f, 4_f)),
b.Assign(b.IndexAccessor(b.MemberAccessor("s", "a"), 1_i), 5_f),
},
utils::Vector{
@@ -577,20 +576,20 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
ProgramBuilder b;
b.Alias("ARR_A", b.ty.array<f32, 2>(8));
b.Alias("ARR_B",
b.ty.array( //
b.ty.array(b.ty.type_name("ARR_A"), 3_u, 16), //
b.ty.array( //
b.ty.array(b.ty("ARR_A"), 3_u, 16), //
4_u, 128));
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR_B"))});
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR_B"))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, type::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{
b.Decl(b.Let("a", b.ty.type_name("ARR_B"), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.array(b.ty.type_name("ARR_A"), 3_u, 16),
b.Decl(b.Let("a", b.ty("ARR_B"), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.array(b.ty("ARR_A"), 3_u, 16),
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3_i))),
b.Decl(b.Let("c", b.ty.type_name("ARR_A"),
b.Decl(b.Let("c", b.ty("ARR_A"),
b.IndexAccessor( //
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
@@ -604,7 +603,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
3_i),
2_i),
1_i))),
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.type_name("ARR_B"))),
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty("ARR_B"))),
b.Assign(b.IndexAccessor( //
b.IndexAccessor( //
b.IndexAccessor( //

View File

@@ -187,7 +187,7 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&,
// Declare a struct to hold the result values.
auto* result_struct = sem_call->Type()->As<sem::Struct>();
auto* atomic_ty = result_struct->Members()[0]->Type();
result_ty = b.ty.type_name(
result_ty = b.ty(
utils::GetOrCreate(atomic_cmpxchg_result_types, atomic_ty, [&]() {
auto name = b.Sym();
b.Structure(

View File

@@ -1075,7 +1075,7 @@ struct DirectVariableAccess::State {
b.Alias(symbol, b.ty.array(b.ty.u32(), u32(num_dyn_indices)));
return symbol;
});
return name.IsValid() ? b.ty.type_name(name) : nullptr;
return name.IsValid() ? b.ty(name) : nullptr;
}
/// @returns a name describing the given shape

View File

@@ -144,9 +144,8 @@ struct MultiplanarExternalTexture::State {
b.GlobalVar(syms.plane_1, b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()),
b.Group(AInt(bps.plane_1.group)), b.Binding(AInt(bps.plane_1.binding)));
syms.params = b.Symbols().New("ext_tex_params");
b.GlobalVar(syms.params, b.ty.type_name("ExternalTextureParams"),
type::AddressSpace::kUniform, b.Group(AInt(bps.params.group)),
b.Binding(AInt(bps.params.binding)));
b.GlobalVar(syms.params, b.ty("ExternalTextureParams"), type::AddressSpace::kUniform,
b.Group(AInt(bps.params.group)), b.Binding(AInt(bps.params.binding)));
// Replace the original texture_external binding with a texture_2d<f32> binding.
auto cloned_attributes = ctx.Clone(global->attributes);
@@ -184,7 +183,7 @@ struct MultiplanarExternalTexture::State {
ctx.Replace(param, b.Param(syms.plane_0, tex2d_f32()));
ctx.InsertAfter(fn->params, param, b.Param(syms.plane_1, tex2d_f32()));
ctx.InsertAfter(fn->params, param,
b.Param(syms.params, b.ty.type_name(params_struct_sym)));
b.Param(syms.params, b.ty(params_struct_sym)));
}
}
}
@@ -261,8 +260,8 @@ struct MultiplanarExternalTexture::State {
b.Member("numPlanes", b.ty.u32()),
b.Member("doYuvToRgbConversionOnly", b.ty.u32()),
b.Member("yuvToRgbConversionMatrix", b.ty.mat3x4<f32>()),
b.Member("gammaDecodeParams", b.ty.type_name("GammaTransferParams")),
b.Member("gammaEncodeParams", b.ty.type_name("GammaTransferParams")),
b.Member("gammaDecodeParams", b.ty("GammaTransferParams")),
b.Member("gammaEncodeParams", b.ty("GammaTransferParams")),
b.Member("gamutConversionMatrix", b.ty.mat3x3<f32>()),
b.Member("coordTransformationMatrix", b.ty.mat3x2<f32>())};
@@ -280,7 +279,7 @@ struct MultiplanarExternalTexture::State {
gamma_correction_sym,
utils::Vector{
b.Param("v", b.ty.vec3<f32>()),
b.Param("params", b.ty.type_name(gamma_transfer_struct_sym)),
b.Param("params", b.ty(gamma_transfer_struct_sym)),
},
b.ty.vec3<f32>(),
utils::Vector{
@@ -428,7 +427,7 @@ struct MultiplanarExternalTexture::State {
b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())),
b.Param("smp", b.ty.sampler(type::SamplerKind::kSampler)),
b.Param("coord", b.ty.vec2(b.ty.f32())),
b.Param("params", b.ty.type_name(params_struct_sym)),
b.Param("params", b.ty(params_struct_sym)),
},
b.ty.vec4(b.ty.f32()),
buildTextureBuiltinBody(sem::BuiltinType::kTextureSampleBaseClampToEdge));
@@ -475,7 +474,7 @@ struct MultiplanarExternalTexture::State {
b.Param("plane1",
b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())),
b.Param("coord", CreateASTTypeFor(ctx, coord_ty)),
b.Param("params", b.ty.type_name(params_struct_sym)),
b.Param("params", b.ty(params_struct_sym)),
},
b.ty.vec4(b.ty.f32()), //
buildTextureBuiltinBody(sem::BuiltinType::kTextureLoad));

View File

@@ -197,7 +197,7 @@ struct SpirvAtomic::State {
ty, //
[&](const type::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const type::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const sem::Struct* str) { return b.ty.type_name(Fork(str->Declaration()).name); },
[&](const sem::Struct* str) { return b.ty(Fork(str->Declaration()).name); },
[&](const type::Array* arr) -> const ast::Type* {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
return b.ty.array(AtomicTypeFor(arr->ElemType()));

View File

@@ -405,7 +405,7 @@ struct Std140::State {
ty, //
[&](const sem::Struct* str) -> const ast::Type* {
if (auto std140 = std140_structs.Find(str)) {
return b.ty.type_name(*std140);
return b.ty(*std140);
}
return nullptr;
},
@@ -423,7 +423,7 @@ struct Std140::State {
utils::Transform(members, [&](auto* member) { return member->symbol; }),
};
});
return b.ty.type_name(std140_mat.name);
return b.ty(std140_mat.name);
}
return nullptr;
},

View File

@@ -122,7 +122,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
if (auto* alias = type_decl->As<ast::Alias>()) {
if (ty == ctx.src->Sem().Get(alias)) {
// Alias found. Use the alias name to ensure types compare equal.
return ctx.dst->ty.type_name(ctx.Clone(alias->name));
return ctx.dst->ty(ctx.Clone(alias->name));
}
}
}
@@ -138,7 +138,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
return ctx.dst->ty.array(el, u32(count.value()), std::move(attrs));
}
if (auto* s = ty->As<sem::Struct>()) {
return ctx.dst->ty.type_name(ctx.Clone(s->Declaration()->name));
return ctx.dst->ty(ctx.Clone(s->Declaration()->name));
}
if (auto* s = ty->As<type::Reference>()) {
return CreateASTTypeFor(ctx, s->StoreType());

View File

@@ -139,15 +139,15 @@ Transform::ApplyResult TruncateInterstageVariables::Apply(const Program* src,
// Create the mapping function to truncate the shader io.
auto mapping_fn_sym = b.Symbols().New("truncate_shader_output");
b.Func(mapping_fn_sym,
utils::Vector{b.Param("io", ctx.Clone(func_ast->return_type))},
b.ty.type_name(new_struct_sym),
utils::Vector{b.Return(b.Construct(b.ty.type_name(new_struct_sym),
std::move(initializer_exprs)))});
b.Func(
mapping_fn_sym, utils::Vector{b.Param("io", ctx.Clone(func_ast->return_type))},
b.ty(new_struct_sym),
utils::Vector{
b.Return(b.Construct(b.ty(new_struct_sym), std::move(initializer_exprs)))});
return TruncatedStructAndConverter{new_struct_sym, mapping_fn_sym};
});
ctx.Replace(func_ast->return_type, b.ty.type_name(entry.truncated_struct));
ctx.Replace(func_ast->return_type, b.ty(entry.truncated_struct));
entry_point_functions_to_truncate_functions.Add(func_sem, entry.truncate_fn);
}