mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 14:41:50 +00:00
CloneContext: Don't create named symbols from unnamed
Registering a new Symbol with the NameFor() of the source symbol creates a new *named* symbol. When mixing these with unnamed symbols we can have collisions. Update CloneContext::Clone(Symbol) to properly clone unnamed symbols. Update (most) the transforms to ctx.Clone() the symbols instead of registering the names directly. Fix up the tests where the symbol IDs have changed. Note: We can still have symbol collisions if a program is authored with identifiers like 'tint_symbol_3'. This will be fixed up in a later change. Change-Id: I0ce559644da3d60e1060f2eef185fa55ae284521 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46866 Commit-Queue: Ben Clayton <bclayton@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
3bfb6817df
commit
1b8d9f227b
@@ -45,7 +45,7 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
||||
->IsAnyOf<ast::BuiltinDecoration, ast::LocationDecoration>();
|
||||
});
|
||||
new_struct_members.push_back(
|
||||
ctx.dst->Member(ctx.src->Symbols().NameFor(member->symbol()),
|
||||
ctx.dst->Member(ctx.Clone(member->symbol()),
|
||||
ctx.Clone(member->type()), new_decorations));
|
||||
}
|
||||
|
||||
@@ -70,10 +70,9 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
||||
auto new_struct_param_symbol = ctx.dst->Symbols().New();
|
||||
ast::StructMemberList new_struct_members;
|
||||
for (auto* param : func->params()) {
|
||||
auto param_name = ctx.src->Symbols().NameFor(param->symbol());
|
||||
auto param_name = ctx.Clone(param->symbol());
|
||||
auto* param_ty = ctx.src->Sem().Get(param)->Type();
|
||||
|
||||
auto func_const_symbol = ctx.dst->Symbols().Register(param_name);
|
||||
ast::Expression* func_const_initializer = nullptr;
|
||||
|
||||
if (auto* struct_ty =
|
||||
@@ -90,7 +89,7 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
||||
return !deco->IsAnyOf<ast::BuiltinDecoration,
|
||||
ast::LocationDecoration>();
|
||||
});
|
||||
auto member_name = ctx.src->Symbols().NameFor(member->symbol());
|
||||
auto member_name = ctx.Clone(member->symbol());
|
||||
new_struct_members.push_back(ctx.dst->Member(
|
||||
member_name, ctx.Clone(member->type()), new_decorations));
|
||||
init_values.push_back(
|
||||
@@ -118,15 +117,15 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
||||
|
||||
// Create a function-scope const to replace the parameter.
|
||||
// Initialize it with the value extracted from the new struct parameter.
|
||||
auto* func_const = ctx.dst->Const(
|
||||
func_const_symbol, ctx.Clone(param_ty), func_const_initializer);
|
||||
auto* func_const = ctx.dst->Const(param_name, ctx.Clone(param_ty),
|
||||
func_const_initializer);
|
||||
ctx.InsertBefore(func->body()->statements(), *func->body()->begin(),
|
||||
ctx.dst->WrapInStatement(func_const));
|
||||
|
||||
// Replace all uses of the function parameter with the function const.
|
||||
for (auto* user : ctx.src->Sem().Get(param)->Users()) {
|
||||
ctx.Replace<ast::Expression>(user->Declaration(),
|
||||
ctx.dst->Expr(func_const_symbol));
|
||||
ctx.dst->Expr(param_name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,9 +162,9 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
||||
return !deco->IsAnyOf<ast::BuiltinDecoration,
|
||||
ast::LocationDecoration>();
|
||||
});
|
||||
auto member_name = ctx.src->Symbols().NameFor(member->symbol());
|
||||
new_struct_members.push_back(ctx.dst->Member(
|
||||
member_name, ctx.Clone(member->type()), new_decorations));
|
||||
new_struct_members.push_back(
|
||||
ctx.dst->Member(ctx.Clone(member->symbol()),
|
||||
ctx.Clone(member->type()), new_decorations));
|
||||
}
|
||||
} else {
|
||||
new_struct_members.push_back(
|
||||
|
||||
@@ -121,7 +121,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
|
||||
->IsAnyOf<ast::BuiltinDecoration, ast::LocationDecoration>();
|
||||
});
|
||||
new_struct_members.push_back(
|
||||
ctx.dst->Member(ctx.src->Symbols().NameFor(member->symbol()),
|
||||
ctx.dst->Member(ctx.Clone(member->symbol()),
|
||||
ctx.Clone(member->type()), new_decorations));
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void Spirv::HandleSampleMaskBuiltins(CloneContext& ctx) const {
|
||||
}
|
||||
|
||||
// Use the same name as the old variable.
|
||||
std::string var_name = ctx.src->Symbols().NameFor(var->symbol());
|
||||
auto var_name = ctx.Clone(var->symbol());
|
||||
// Use `array<u32, 1>` for the new variable.
|
||||
auto* type = ctx.dst->ty.array(ctx.dst->ty.u32(), 1u);
|
||||
// Create the new variable.
|
||||
|
||||
@@ -74,7 +74,7 @@ fn frag_main([[location(1)]] loc1 : myf32) -> void {
|
||||
auto* expect = R"(
|
||||
type myf32 = f32;
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_1 : myf32;
|
||||
[[location(1)]] var<in> tint_symbol_2 : myf32;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
@@ -95,15 +95,15 @@ fn vert_main() -> [[builtin(position)]] vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(position)]] var<out> tint_symbol_2 : vec4<f32>;
|
||||
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
||||
|
||||
fn tint_symbol_3(tint_symbol_1 : vec4<f32>) -> void {
|
||||
tint_symbol_2 = tint_symbol_1;
|
||||
fn tint_symbol_2(tint_symbol_3 : vec4<f32>) -> void {
|
||||
tint_symbol_1 = tint_symbol_3;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
tint_symbol_3(vec4<f32>(1.0, 2.0, 3.0, 0.0));
|
||||
tint_symbol_2(vec4<f32>(1.0, 2.0, 3.0, 0.0));
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -127,19 +127,19 @@ fn frag_main([[location(0)]] loc_in : u32) -> [[location(0)]] f32 {
|
||||
auto* expect = R"(
|
||||
[[location(0)]] var<in> tint_symbol_1 : u32;
|
||||
|
||||
[[location(0)]] var<out> tint_symbol_3 : f32;
|
||||
[[location(0)]] var<out> tint_symbol_2 : f32;
|
||||
|
||||
fn tint_symbol_4(tint_symbol_2 : f32) -> void {
|
||||
tint_symbol_3 = tint_symbol_2;
|
||||
fn tint_symbol_3(tint_symbol_4 : f32) -> void {
|
||||
tint_symbol_2 = tint_symbol_4;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
if ((tint_symbol_1 > 10u)) {
|
||||
tint_symbol_4(0.5);
|
||||
tint_symbol_3(0.5);
|
||||
return;
|
||||
}
|
||||
tint_symbol_4(1.0);
|
||||
tint_symbol_3(1.0);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -165,21 +165,21 @@ fn frag_main([[location(0)]] loc_in : u32) -> [[location(0)]] myf32 {
|
||||
auto* expect = R"(
|
||||
type myf32 = f32;
|
||||
|
||||
[[location(0)]] var<in> tint_symbol_1 : u32;
|
||||
[[location(0)]] var<in> tint_symbol_2 : u32;
|
||||
|
||||
[[location(0)]] var<out> tint_symbol_3 : myf32;
|
||||
|
||||
fn tint_symbol_5(tint_symbol_2 : myf32) -> void {
|
||||
tint_symbol_3 = tint_symbol_2;
|
||||
fn tint_symbol_4(tint_symbol_5 : myf32) -> void {
|
||||
tint_symbol_3 = tint_symbol_5;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
if ((tint_symbol_1 > 10u)) {
|
||||
tint_symbol_5(0.5);
|
||||
if ((tint_symbol_2 > 10u)) {
|
||||
tint_symbol_4(0.5);
|
||||
return;
|
||||
}
|
||||
tint_symbol_5(1.0);
|
||||
tint_symbol_4(1.0);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -214,8 +214,8 @@ struct FragmentInput {
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
const tint_symbol_6 : FragmentInput = FragmentInput(tint_symbol_4, tint_symbol_5);
|
||||
var col : f32 = (tint_symbol_6.coord.x * tint_symbol_6.value);
|
||||
const tint_symbol_7 : FragmentInput = FragmentInput(tint_symbol_4, tint_symbol_5);
|
||||
var col : f32 = (tint_symbol_7.coord.x * tint_symbol_7.value);
|
||||
}
|
||||
)";
|
||||
|
||||
@@ -275,23 +275,23 @@ struct VertexOutput {
|
||||
value : f32;
|
||||
};
|
||||
|
||||
[[builtin(position)]] var<out> tint_symbol_5 : vec4<f32>;
|
||||
[[builtin(position)]] var<out> tint_symbol_4 : vec4<f32>;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_6 : f32;
|
||||
[[location(1)]] var<out> tint_symbol_5 : f32;
|
||||
|
||||
fn tint_symbol_7(tint_symbol_4 : VertexOutput) -> void {
|
||||
tint_symbol_5 = tint_symbol_4.pos;
|
||||
tint_symbol_6 = tint_symbol_4.value;
|
||||
fn tint_symbol_6(tint_symbol_7 : VertexOutput) -> void {
|
||||
tint_symbol_4 = tint_symbol_7.pos;
|
||||
tint_symbol_5 = tint_symbol_7.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
if (false) {
|
||||
tint_symbol_7(VertexOutput());
|
||||
tint_symbol_6(VertexOutput());
|
||||
return;
|
||||
}
|
||||
var pos : vec4<f32> = vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
||||
tint_symbol_7(VertexOutput(pos, 2.0));
|
||||
tint_symbol_6(VertexOutput(pos, 2.0));
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -320,16 +320,16 @@ struct Interface {
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_3 : f32;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_6 : f32;
|
||||
[[location(1)]] var<out> tint_symbol_4 : f32;
|
||||
|
||||
fn tint_symbol_7(tint_symbol_5 : Interface) -> void {
|
||||
tint_symbol_6 = tint_symbol_5.value;
|
||||
fn tint_symbol_5(tint_symbol_6 : Interface) -> void {
|
||||
tint_symbol_4 = tint_symbol_6.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
const tint_symbol_4 : Interface = Interface(tint_symbol_3);
|
||||
tint_symbol_7(tint_symbol_4);
|
||||
const tint_symbol_8 : Interface = Interface(tint_symbol_3);
|
||||
tint_symbol_5(tint_symbol_8);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -361,15 +361,15 @@ struct Interface {
|
||||
value : f32;
|
||||
};
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_4 : f32;
|
||||
[[location(1)]] var<out> tint_symbol_3 : f32;
|
||||
|
||||
fn tint_symbol_5(tint_symbol_3 : Interface) -> void {
|
||||
tint_symbol_4 = tint_symbol_3.value;
|
||||
fn tint_symbol_4(tint_symbol_5 : Interface) -> void {
|
||||
tint_symbol_3 = tint_symbol_5.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
tint_symbol_5(Interface(42.0));
|
||||
tint_symbol_4(Interface(42.0));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -377,8 +377,8 @@ fn vert_main() -> void {
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
const tint_symbol_8 : Interface = Interface(tint_symbol_7);
|
||||
var x : f32 = tint_symbol_8.value;
|
||||
const tint_symbol_9 : Interface = Interface(tint_symbol_7);
|
||||
var x : f32 = tint_symbol_9.value;
|
||||
}
|
||||
)";
|
||||
|
||||
@@ -423,16 +423,16 @@ struct FragmentOutput {
|
||||
|
||||
[[builtin(frag_coord)]] var<in> tint_symbol_6 : vec4<f32>;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_9 : f32;
|
||||
[[location(1)]] var<out> tint_symbol_7 : f32;
|
||||
|
||||
fn tint_symbol_10(tint_symbol_8 : FragmentOutput) -> void {
|
||||
tint_symbol_9 = tint_symbol_8.value;
|
||||
fn tint_symbol_8(tint_symbol_9 : FragmentOutput) -> void {
|
||||
tint_symbol_7 = tint_symbol_9.value;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
const tint_symbol_7 : FragmentInput = FragmentInput(tint_symbol_5, tint_symbol_6);
|
||||
tint_symbol_10(FragmentOutput((tint_symbol_7.coord.x * tint_symbol_7.value)));
|
||||
const tint_symbol_11 : FragmentInput = FragmentInput(tint_symbol_5, tint_symbol_6);
|
||||
tint_symbol_8(FragmentOutput((tint_symbol_11.coord.x * tint_symbol_11.value)));
|
||||
return;
|
||||
}
|
||||
)";
|
||||
@@ -467,8 +467,8 @@ struct VertexOutput {
|
||||
|
||||
[[builtin(position)]] var<out> tint_symbol_4 : vec4<f32>;
|
||||
|
||||
fn tint_symbol_5(tint_symbol_3 : VertexOutput) -> void {
|
||||
tint_symbol_4 = tint_symbol_3.Position;
|
||||
fn tint_symbol_5(tint_symbol_6 : VertexOutput) -> void {
|
||||
tint_symbol_4 = tint_symbol_6.Position;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
@@ -585,19 +585,19 @@ fn main([[builtin(sample_index)]] sample_index : u32,
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(sample_index)]] var<in> tint_symbol_1 : u32;
|
||||
[[builtin(sample_index)]] var<in> tint_symbol_3 : u32;
|
||||
|
||||
[[builtin(sample_mask_in)]] var<in> tint_symbol_2 : array<u32, 1>;
|
||||
[[builtin(sample_mask_in)]] var<in> tint_symbol_1 : array<u32, 1>;
|
||||
|
||||
[[builtin(sample_mask_out)]] var<out> tint_symbol_4 : array<u32, 1>;
|
||||
[[builtin(sample_mask_out)]] var<out> tint_symbol_2 : array<u32, 1>;
|
||||
|
||||
fn tint_symbol_5(tint_symbol_3 : u32) -> void {
|
||||
tint_symbol_4[0] = tint_symbol_3;
|
||||
fn tint_symbol_4(tint_symbol_5 : u32) -> void {
|
||||
tint_symbol_2[0] = tint_symbol_5;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() -> void {
|
||||
tint_symbol_5(tint_symbol_2[0]);
|
||||
tint_symbol_4(tint_symbol_1[0]);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
|
||||
Reference in New Issue
Block a user