writer/hlsl: Use Symbols().New()

Instead of rolling another implementation inside GeneratorImpl.

Bug: tint:712
Change-Id: I26af0d68f6529c0c6dc45f51233f4618389edb55
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47638
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-04-13 23:48:07 +00:00 committed by Commit Bot service account
parent 5c34060a4e
commit 3dd4fae775
5 changed files with 159 additions and 172 deletions

View File

@ -47,7 +47,7 @@ const char kInStructNameSuffix[] = "in";
const char kOutStructNameSuffix[] = "out"; const char kOutStructNameSuffix[] = "out";
const char kTintStructInVarPrefix[] = "tint_in"; const char kTintStructInVarPrefix[] = "tint_in";
const char kTintStructOutVarPrefix[] = "tint_out"; const char kTintStructOutVarPrefix[] = "tint_out";
const char kTempNamePrefix[] = "_tint_tmp"; const char kTempNamePrefix[] = "tint_tmp";
bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) { bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) {
if (stmts->empty()) { if (stmts->empty()) {
@ -176,18 +176,7 @@ void GeneratorImpl::register_global(ast::Variable* global) {
} }
std::string GeneratorImpl::generate_name(const std::string& prefix) { std::string GeneratorImpl::generate_name(const std::string& prefix) {
if (!builder_.Symbols().Get(prefix).IsValid()) { return builder_.Symbols().NameFor(builder_.Symbols().New(prefix));
builder_.Symbols().Register(prefix);
return prefix;
}
for (uint32_t i = 0;; i++) {
std::string name = prefix + "_" + std::to_string(i);
if (builder_.Symbols().Get(name).IsValid()) {
continue;
}
builder_.Symbols().Register(name);
return name;
}
} }
std::string GeneratorImpl::current_ep_var_name(VarType type) { std::string GeneratorImpl::current_ep_var_name(VarType type) {

View File

@ -241,10 +241,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)"); EXPECT_EQ(result(), "(tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left; EXPECT_EQ(pre_result(), R"(bool tint_tmp = left;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = right; tint_tmp = right;
} }
)"); )");
} }
@ -264,18 +264,18 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp_0)"); EXPECT_EQ(result(), "(tint_tmp_1)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a; EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = b; tint_tmp = b;
} }
bool _tint_tmp_0 = (_tint_tmp); bool tint_tmp_1 = (tint_tmp);
if (!_tint_tmp_0) { if (!tint_tmp_1) {
bool _tint_tmp_1 = c; bool tint_tmp_2 = c;
if (!_tint_tmp_1) { if (!tint_tmp_2) {
_tint_tmp_1 = d; tint_tmp_2 = d;
} }
_tint_tmp_0 = (_tint_tmp_1); tint_tmp_1 = (tint_tmp_2);
} }
)"); )");
} }
@ -290,10 +290,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)"); EXPECT_EQ(result(), "(tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left; EXPECT_EQ(pre_result(), R"(bool tint_tmp = left;
if (!_tint_tmp) { if (!tint_tmp) {
_tint_tmp = right; tint_tmp = right;
} }
)"); )");
} }
@ -336,18 +336,18 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool tint_tmp = a;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = b; tint_tmp = b;
} }
if ((_tint_tmp)) { if ((tint_tmp)) {
return 1; return 1;
} else { } else {
bool _tint_tmp_0 = b; bool tint_tmp_1 = b;
if (!_tint_tmp_0) { if (!tint_tmp_1) {
_tint_tmp_0 = c; tint_tmp_1 = c;
} }
if ((_tint_tmp_0)) { if ((tint_tmp_1)) {
return 2; return 2;
} else { } else {
return 3; return 3;
@ -369,15 +369,15 @@ TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool tint_tmp = a;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = b; tint_tmp = b;
} }
bool _tint_tmp_0 = (_tint_tmp); bool tint_tmp_1 = (tint_tmp);
if (!_tint_tmp_0) { if (!tint_tmp_1) {
_tint_tmp_0 = c; tint_tmp_1 = c;
} }
return (_tint_tmp_0); return (tint_tmp_1);
)"); )");
} }
@ -397,15 +397,15 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b; EXPECT_EQ(result(), R"(bool tint_tmp = b;
if (!_tint_tmp) { if (!tint_tmp) {
_tint_tmp = c; tint_tmp = c;
} }
bool _tint_tmp_0 = (_tint_tmp); bool tint_tmp_1 = (tint_tmp);
if (_tint_tmp_0) { if (tint_tmp_1) {
_tint_tmp_0 = d; tint_tmp_1 = d;
} }
a = (_tint_tmp_0); a = (tint_tmp_1);
)"); )");
} }
@ -432,15 +432,15 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, decl)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, decl)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b; EXPECT_EQ(result(), R"(bool tint_tmp = b;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = c; tint_tmp = c;
} }
bool _tint_tmp_0 = (_tint_tmp); bool tint_tmp_1 = (tint_tmp);
if (!_tint_tmp_0) { if (!tint_tmp_1) {
_tint_tmp_0 = d; tint_tmp_1 = d;
} }
bool a = (_tint_tmp_0); bool a = (tint_tmp_1);
)"); )");
} }
@ -460,16 +460,16 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a; EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
if (_tint_tmp) { if (tint_tmp) {
bool _tint_tmp_0 = b; bool tint_tmp_1 = b;
if (!_tint_tmp_0) { if (!tint_tmp_1) {
_tint_tmp_0 = c; tint_tmp_1 = c;
} }
_tint_tmp = (_tint_tmp_0); tint_tmp = (tint_tmp_1);
} }
)"); )");
EXPECT_EQ(result(), R"(asint((_tint_tmp)))"); EXPECT_EQ(result(), R"(asint((tint_tmp)))");
} }
TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
@ -500,27 +500,27 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool tint_tmp = a;
if (_tint_tmp) { if (tint_tmp) {
_tint_tmp = b; tint_tmp = b;
} }
bool _tint_tmp_0 = c; bool tint_tmp_1 = c;
if (!_tint_tmp_0) { if (!tint_tmp_1) {
_tint_tmp_0 = d; tint_tmp_1 = d;
} }
bool _tint_tmp_1 = a; bool tint_tmp_2 = a;
if (!_tint_tmp_1) { if (!tint_tmp_2) {
_tint_tmp_1 = c; tint_tmp_2 = c;
} }
bool _tint_tmp_2 = (_tint_tmp_1); bool tint_tmp_3 = (tint_tmp_2);
if (_tint_tmp_2) { if (tint_tmp_3) {
bool _tint_tmp_3 = b; bool tint_tmp_4 = b;
if (!_tint_tmp_3) { if (!tint_tmp_4) {
_tint_tmp_3 = d; tint_tmp_4 = d;
} }
_tint_tmp_2 = (_tint_tmp_3); tint_tmp_3 = (tint_tmp_4);
} }
foo((_tint_tmp), (_tint_tmp_0), (_tint_tmp_2)); foo((tint_tmp), (tint_tmp_1), (tint_tmp_3));
)"); )");
} }

View File

@ -278,10 +278,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int4 _tint_tmp = int4(round(clamp(p1, " EXPECT_THAT(pre_result(), HasSubstr("int4 tint_tmp = int4(round(clamp(p1, "
"-1.0, 1.0) * 127.0)) & 0xff;")); "-1.0, 1.0) * 127.0)) & 0xff;"));
EXPECT_THAT(result(), HasSubstr("asuint(_tint_tmp.x | _tint_tmp.y << 8 | " EXPECT_THAT(result(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 8 | "
"_tint_tmp.z << 16 | _tint_tmp.w << 24)")); "tint_tmp.z << 16 | tint_tmp.w << 24)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
@ -292,10 +292,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint4 _tint_tmp = uint4(round(clamp(p1, " EXPECT_THAT(pre_result(), HasSubstr("uint4 tint_tmp = uint4(round(clamp(p1, "
"0.0, 1.0) * 255.0));")); "0.0, 1.0) * 255.0));"));
EXPECT_THAT(result(), HasSubstr("(_tint_tmp.x | _tint_tmp.y << 8 | " EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 8 | "
"_tint_tmp.z << 16 | _tint_tmp.w << 24)")); "tint_tmp.z << 16 | tint_tmp.w << 24)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
@ -306,9 +306,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int2 _tint_tmp = int2(round(clamp(p1, " EXPECT_THAT(pre_result(), HasSubstr("int2 tint_tmp = int2(round(clamp(p1, "
"-1.0, 1.0) * 32767.0)) & 0xffff;")); "-1.0, 1.0) * 32767.0)) & 0xffff;"));
EXPECT_THAT(result(), HasSubstr("asuint(_tint_tmp.x | _tint_tmp.y << 16)")); EXPECT_THAT(result(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 16)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
@ -319,9 +319,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint2 _tint_tmp = uint2(round(clamp(p1, " EXPECT_THAT(pre_result(), HasSubstr("uint2 tint_tmp = uint2(round(clamp(p1, "
"0.0, 1.0) * 65535.0));")); "0.0, 1.0) * 65535.0));"));
EXPECT_THAT(result(), HasSubstr("(_tint_tmp.x | _tint_tmp.y << 16)")); EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) { TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
@ -332,8 +332,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint2 _tint_tmp = f32tof16(p1);")); EXPECT_THAT(pre_result(), HasSubstr("uint2 tint_tmp = f32tof16(p1);"));
EXPECT_THAT(result(), HasSubstr("(_tint_tmp.x | _tint_tmp.y << 16)")); EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
@ -344,12 +344,12 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int _tint_tmp_0 = int(p1);")); EXPECT_THAT(pre_result(), HasSubstr("int tint_tmp_1 = int(p1);"));
EXPECT_THAT(pre_result(), EXPECT_THAT(pre_result(),
HasSubstr("int4 _tint_tmp = int4(_tint_tmp_0 << 24, _tint_tmp_0 " HasSubstr("int4 tint_tmp = int4(tint_tmp_1 << 24, tint_tmp_1 "
"<< 16, _tint_tmp_0 << 8, _tint_tmp_0) >> 24;")); "<< 16, tint_tmp_1 << 8, tint_tmp_1) >> 24;"));
EXPECT_THAT(result(), EXPECT_THAT(result(),
HasSubstr("clamp(float4(_tint_tmp) / 127.0, -1.0, 1.0)")); HasSubstr("clamp(float4(tint_tmp) / 127.0, -1.0, 1.0)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
@ -360,12 +360,12 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint _tint_tmp_0 = p1;")); EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp_1 = p1;"));
EXPECT_THAT( EXPECT_THAT(
pre_result(), pre_result(),
HasSubstr("uint4 _tint_tmp = uint4(_tint_tmp_0 & 0xff, (_tint_tmp_0 >> " HasSubstr("uint4 tint_tmp = uint4(tint_tmp_1 & 0xff, (tint_tmp_1 >> "
"8) & 0xff, (_tint_tmp_0 >> 16) & 0xff, _tint_tmp_0 >> 24);")); "8) & 0xff, (tint_tmp_1 >> 16) & 0xff, tint_tmp_1 >> 24);"));
EXPECT_THAT(result(), HasSubstr("float4(_tint_tmp) / 255.0")); EXPECT_THAT(result(), HasSubstr("float4(tint_tmp) / 255.0"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
@ -376,13 +376,12 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int _tint_tmp_0 = int(p1);")); EXPECT_THAT(pre_result(), HasSubstr("int tint_tmp_1 = int(p1);"));
EXPECT_THAT( EXPECT_THAT(
pre_result(), pre_result(),
HasSubstr( HasSubstr("int2 tint_tmp = int2(tint_tmp_1 << 16, tint_tmp_1) >> 16;"));
"int2 _tint_tmp = int2(_tint_tmp_0 << 16, _tint_tmp_0) >> 16;"));
EXPECT_THAT(result(), EXPECT_THAT(result(),
HasSubstr("clamp(float2(_tint_tmp) / 32767.0, -1.0, 1.0)")); HasSubstr("clamp(float2(tint_tmp) / 32767.0, -1.0, 1.0)"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) { TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
@ -393,12 +392,12 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint _tint_tmp_0 = p1;")); EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp_1 = p1;"));
EXPECT_THAT( EXPECT_THAT(
pre_result(), pre_result(),
HasSubstr( HasSubstr(
"uint2 _tint_tmp = uint2(_tint_tmp_0 & 0xffff, _tint_tmp_0 >> 16);")); "uint2 tint_tmp = uint2(tint_tmp_1 & 0xffff, tint_tmp_1 >> 16);"));
EXPECT_THAT(result(), HasSubstr("float2(_tint_tmp) / 65535.0")); EXPECT_THAT(result(), HasSubstr("float2(tint_tmp) / 65535.0"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) { TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
@ -409,10 +408,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint _tint_tmp = p1;")); EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp = p1;"));
EXPECT_THAT( EXPECT_THAT(result(),
result(), HasSubstr("f16tof32(uint2(tint_tmp & 0xffff, tint_tmp >> 16))"));
HasSubstr("f16tof32(uint2(_tint_tmp & 0xffff, _tint_tmp >> 16))"));
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) { TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) {

View File

@ -41,27 +41,27 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kDimensionsStorageRO1d: case ValidTextureOverload::kDimensionsStorageRO1d:
case ValidTextureOverload::kDimensionsStorageWO1d: case ValidTextureOverload::kDimensionsStorageWO1d:
return { return {
R"(int _tint_tmp; R"(int tint_tmp;
tint_texture.GetDimensions(_tint_tmp); tint_texture.GetDimensions(tint_tmp);
)", )",
"_tint_tmp", "tint_tmp",
}; };
case ValidTextureOverload::kDimensions2d: case ValidTextureOverload::kDimensions2d:
case ValidTextureOverload::kDimensionsDepth2d: case ValidTextureOverload::kDimensionsDepth2d:
case ValidTextureOverload::kDimensionsStorageRO2d: case ValidTextureOverload::kDimensionsStorageRO2d:
case ValidTextureOverload::kDimensionsStorageWO2d: case ValidTextureOverload::kDimensionsStorageWO2d:
return { return {
R"(int2 _tint_tmp; R"(int2 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y);
)", )",
"_tint_tmp", "tint_tmp",
}; };
case ValidTextureOverload::kDimensionsMultisampled2d: case ValidTextureOverload::kDimensionsMultisampled2d:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.xy", "tint_tmp.xy",
}; };
case ValidTextureOverload::kDimensions2dArray: case ValidTextureOverload::kDimensions2dArray:
@ -69,81 +69,81 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kDimensionsStorageRO2dArray: case ValidTextureOverload::kDimensionsStorageRO2dArray:
case ValidTextureOverload::kDimensionsStorageWO2dArray: case ValidTextureOverload::kDimensionsStorageWO2dArray:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.xy", "tint_tmp.xy",
}; };
case ValidTextureOverload::kDimensionsMultisampled2dArray: case ValidTextureOverload::kDimensionsMultisampled2dArray:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.xy", "tint_tmp.xy",
}; };
case ValidTextureOverload::kDimensions3d: case ValidTextureOverload::kDimensions3d:
case ValidTextureOverload::kDimensionsStorageRO3d: case ValidTextureOverload::kDimensionsStorageRO3d:
case ValidTextureOverload::kDimensionsStorageWO3d: case ValidTextureOverload::kDimensionsStorageWO3d:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp", "tint_tmp",
}; };
case ValidTextureOverload::kDimensionsCube: case ValidTextureOverload::kDimensionsCube:
case ValidTextureOverload::kDimensionsDepthCube: case ValidTextureOverload::kDimensionsDepthCube:
return { return {
R"(int2 _tint_tmp; R"(int2 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y);
)", )",
"_tint_tmp.xyy", "tint_tmp.xyy",
}; };
case ValidTextureOverload::kDimensionsCubeArray: case ValidTextureOverload::kDimensionsCubeArray:
case ValidTextureOverload::kDimensionsDepthCubeArray: case ValidTextureOverload::kDimensionsDepthCubeArray:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.xyy", "tint_tmp.xyy",
}; };
case ValidTextureOverload::kDimensions2dLevel: case ValidTextureOverload::kDimensions2dLevel:
case ValidTextureOverload::kDimensionsDepth2dLevel: case ValidTextureOverload::kDimensionsDepth2dLevel:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.xy", "tint_tmp.xy",
}; };
case ValidTextureOverload::kDimensions2dArrayLevel: case ValidTextureOverload::kDimensions2dArrayLevel:
case ValidTextureOverload::kDimensionsDepth2dArrayLevel: case ValidTextureOverload::kDimensionsDepth2dArrayLevel:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.xy", "tint_tmp.xy",
}; };
case ValidTextureOverload::kDimensions3dLevel: case ValidTextureOverload::kDimensions3dLevel:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.xyz", "tint_tmp.xyz",
}; };
case ValidTextureOverload::kDimensionsCubeLevel: case ValidTextureOverload::kDimensionsCubeLevel:
case ValidTextureOverload::kDimensionsDepthCubeLevel: case ValidTextureOverload::kDimensionsDepthCubeLevel:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.xyy", "tint_tmp.xyy",
}; };
case ValidTextureOverload::kDimensionsCubeArrayLevel: case ValidTextureOverload::kDimensionsCubeArrayLevel:
case ValidTextureOverload::kDimensionsDepthCubeArrayLevel: case ValidTextureOverload::kDimensionsDepthCubeArrayLevel:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.xyy", "tint_tmp.xyy",
}; };
case ValidTextureOverload::kNumLayers2dArray: case ValidTextureOverload::kNumLayers2dArray:
case ValidTextureOverload::kNumLayersDepth2dArray: case ValidTextureOverload::kNumLayersDepth2dArray:
@ -151,17 +151,17 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kNumLayersDepthCubeArray: case ValidTextureOverload::kNumLayersDepthCubeArray:
case ValidTextureOverload::kNumLayersStorageWO2dArray: case ValidTextureOverload::kNumLayersStorageWO2dArray:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.z", "tint_tmp.z",
}; };
case ValidTextureOverload::kNumLayersMultisampled2dArray: case ValidTextureOverload::kNumLayersMultisampled2dArray:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.z", "tint_tmp.z",
}; };
case ValidTextureOverload::kNumLevels2d: case ValidTextureOverload::kNumLevels2d:
@ -169,10 +169,10 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kNumLevelsDepth2d: case ValidTextureOverload::kNumLevelsDepth2d:
case ValidTextureOverload::kNumLevelsDepthCube: case ValidTextureOverload::kNumLevelsDepthCube:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.z", "tint_tmp.z",
}; };
case ValidTextureOverload::kNumLevels2dArray: case ValidTextureOverload::kNumLevels2dArray:
case ValidTextureOverload::kNumLevels3d: case ValidTextureOverload::kNumLevels3d:
@ -180,24 +180,24 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kNumLevelsDepth2dArray: case ValidTextureOverload::kNumLevelsDepth2dArray:
case ValidTextureOverload::kNumLevelsDepthCubeArray: case ValidTextureOverload::kNumLevelsDepthCubeArray:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.w", "tint_tmp.w",
}; };
case ValidTextureOverload::kNumSamplesMultisampled2d: case ValidTextureOverload::kNumSamplesMultisampled2d:
return { return {
R"(int3 _tint_tmp; R"(int3 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z);
)", )",
"_tint_tmp.z", "tint_tmp.z",
}; };
case ValidTextureOverload::kNumSamplesMultisampled2dArray: case ValidTextureOverload::kNumSamplesMultisampled2dArray:
return { return {
R"(int4 _tint_tmp; R"(int4 tint_tmp;
tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w);
)", )",
"_tint_tmp.w", "tint_tmp.w",
}; };
case ValidTextureOverload::kSample1dF32: case ValidTextureOverload::kSample1dF32:
return R"(tint_texture.Sample(tint_sampler, 1.0f))"; return R"(tint_texture.Sample(tint_sampler, 1.0f))";

View File

@ -47,9 +47,9 @@ TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out"); ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out");
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_0");
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_3"); ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_3");
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_4"); ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_4");
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_5");
} }
struct HlslBuiltinData { struct HlslBuiltinData {