mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 08:57:26 +00:00
Fix structure builtin emission
Fix the Renamer to preserve builtin structure member names. Fix the HLSL writer to emit the modf / frexp result type even if there is no private / function storage usage of the types. Fixed: chromium:1236161 Change-Id: I93b9d92980682f9a9cb090d07b04e4c3f6a2f705 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60922 Reviewed-by: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
63e7ad699c
commit
3e92e9f8ba
@@ -896,7 +896,8 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) {
|
||||
// Disable auto-cloning of symbols, since we want to rename them.
|
||||
CloneContext ctx(&out, in, false);
|
||||
|
||||
// Swizzles and intrinsic calls need to keep their symbols preserved.
|
||||
// Swizzles, intrinsic calls and builtin structure members need to keep their
|
||||
// symbols preserved.
|
||||
std::unordered_set<ast::IdentifierExpression*> preserve;
|
||||
for (auto* node : in->ASTNodes().Objects()) {
|
||||
if (auto* member = node->As<ast::MemberAccessorExpression>()) {
|
||||
@@ -908,6 +909,12 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) {
|
||||
}
|
||||
if (sem->Is<sem::Swizzle>()) {
|
||||
preserve.emplace(member->member());
|
||||
} else if (auto* str_expr = in->Sem().Get(member->structure())) {
|
||||
if (auto* ty = str_expr->Type()->UnwrapRef()->As<sem::Struct>()) {
|
||||
if (ty->Declaration() == nullptr) { // Builtin structure
|
||||
preserve.emplace(member->member());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (auto* call = node->As<ast::CallExpression>()) {
|
||||
auto* sem = in->Sem().Get(call);
|
||||
|
||||
@@ -149,6 +149,41 @@ fn tint_symbol() -> [[builtin(position)]] vec4<f32> {
|
||||
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
|
||||
}
|
||||
|
||||
TEST_F(RenamerTest, PreserveBuiltinTypes) {
|
||||
auto* src = R"(
|
||||
[[stage(compute), workgroup_size(1)]]
|
||||
fn entry() {
|
||||
var a = modf(1.0).whole;
|
||||
var b = modf(1.0).fract;
|
||||
var c = frexp(1.0).sig;
|
||||
var d = frexp(1.0).exp;
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[stage(compute), workgroup_size(1)]]
|
||||
fn tint_symbol() {
|
||||
var tint_symbol_1 = modf(1.0).whole;
|
||||
var tint_symbol_2 = modf(1.0).fract;
|
||||
var tint_symbol_3 = frexp(1.0).sig;
|
||||
var tint_symbol_4 = frexp(1.0).exp;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Renamer>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
|
||||
auto* data = got.data.Get<Renamer::Data>();
|
||||
|
||||
ASSERT_NE(data, nullptr);
|
||||
Renamer::Data::Remappings expected_remappings = {
|
||||
{"entry", "tint_symbol"}, {"a", "tint_symbol_1"}, {"b", "tint_symbol_2"},
|
||||
{"c", "tint_symbol_3"}, {"d", "tint_symbol_4"},
|
||||
};
|
||||
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
|
||||
}
|
||||
|
||||
TEST_F(RenamerTest, AttemptSymbolCollision) {
|
||||
auto* src = R"(
|
||||
[[stage(vertex)]]
|
||||
|
||||
Reference in New Issue
Block a user