transform: s/_tint_/tint_ for reserved keywords

Bug: tint:640
Change-Id: I7525ac97d8942fffa651847d703bf37a10cbc71d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47636
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:44:57 +00:00 committed by Commit Bot service account
parent a5a31d35f6
commit 4d349b5391
7 changed files with 204 additions and 114 deletions

View File

@ -309,7 +309,7 @@ fn main() {
auto expect = R"( auto expect = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn main() { fn main() {
var _tint_)" + keyword + var tint_)" + keyword +
R"( : i32; R"( : i32;
} }
)"; )";
@ -318,6 +318,51 @@ fn main() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_P(HlslReservedKeywordTest, AttemptSymbolCollision) {
auto keyword = GetParam();
auto src = R"(
[[stage(fragment)]]
fn main() {
var tint_)" +
keyword +
R"( : i32;
var tint_)" +
keyword +
R"(_1 : i32;
var )" + keyword +
R"( : i32;
var tint_)" +
keyword +
R"(_2 : i32;
var tint_)" +
keyword +
R"(_3 : i32;
}
)";
auto expect = R"(
[[stage(fragment)]]
fn main() {
var tint_)" + keyword +
R"( : i32;
var tint_)" + keyword +
R"(_1 : i32;
var tint_)" + keyword +
R"(_2 : i32;
var tint_)" + keyword +
R"(_2_1 : i32;
var tint_)" + keyword +
R"(_3 : i32;
}
)";
auto got = Run<Hlsl>(src);
EXPECT_EQ(expect, str(got));
}
INSTANTIATE_TEST_SUITE_P(HlslReservedKeywordTest, INSTANTIATE_TEST_SUITE_P(HlslReservedKeywordTest,
HlslReservedKeywordTest, HlslReservedKeywordTest,
testing::Values("AddressU", testing::Values("AddressU",

View File

@ -36,22 +36,22 @@ fn main() {
var half : f32; var half : f32;
var half1 : f32; var half1 : f32;
var half2 : f32; var half2 : f32;
var _tint_half2 : f32; var tint_half2 : f32;
} }
)"; )";
auto* expect = R"( auto* expect = R"(
struct _tint_class { struct tint_class {
_tint_delete : i32; tint_delete : i32;
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn _tint_main() { fn tint_main() {
var foo : i32; var foo : i32;
var _tint_half : f32; var tint_half : f32;
var half1 : f32; var half1 : f32;
var _tint_half2 : f32; var tint_half2 : f32;
var _tint_half2_1 : f32; var tint_half2_1 : f32;
} }
)"; )";
@ -73,8 +73,8 @@ fn main() {
auto expect = R"( auto expect = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn _tint_main() { fn tint_main() {
var _tint_)" + keyword + var tint_)" + keyword +
R"( : i32; R"( : i32;
} }
)"; )";
@ -83,6 +83,51 @@ fn _tint_main() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_P(MslReservedKeywordTest, AttemptSymbolCollision) {
auto keyword = GetParam();
auto src = R"(
[[stage(fragment)]]
fn frag_main() {
var tint_)" +
keyword +
R"( : i32;
var tint_)" +
keyword +
R"(_1 : i32;
var )" + keyword +
R"( : i32;
var tint_)" +
keyword +
R"(_2 : i32;
var tint_)" +
keyword +
R"(_3 : i32;
}
)";
auto expect = R"(
[[stage(fragment)]]
fn frag_main() {
var tint_)" + keyword +
R"( : i32;
var tint_)" + keyword +
R"(_1 : i32;
var tint_)" + keyword +
R"(_2 : i32;
var tint_)" + keyword +
R"(_2_1 : i32;
var tint_)" + keyword +
R"(_3 : i32;
}
)";
auto got = Run<Msl>(src);
EXPECT_EQ(expect, str(got));
}
INSTANTIATE_TEST_SUITE_P(MslReservedKeywordTest, INSTANTIATE_TEST_SUITE_P(MslReservedKeywordTest,
MslReservedKeywordTest, MslReservedKeywordTest,
testing::Values( testing::Values(

View File

@ -63,7 +63,7 @@ void Transform::RenameReservedKeywords(CloneContext* ctx,
ctx->ReplaceAll([=](Symbol in) { ctx->ReplaceAll([=](Symbol in) {
auto name_in = ctx->src->Symbols().NameFor(in); auto name_in = ctx->src->Symbols().NameFor(in);
if (std::binary_search(names, names + count, name_in)) { if (std::binary_search(names, names + count, name_in)) {
return ctx->dst->Symbols().New("_tint_" + name_in); return ctx->dst->Symbols().New("tint_" + name_in);
} }
return ctx->dst->Symbols().New(name_in); return ctx->dst->Symbols().New(name_in);
}); });

View File

@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) {
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(typedef float _tint_float; EXPECT_THAT(result(), HasSubstr(R"(typedef float tint_float;
)")); )"));
} }

View File

@ -60,7 +60,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"( void _tint_GeometryShader() { EXPECT_THAT(result(), HasSubstr(R"( void tint_GeometryShader() {
return; return;
})")); })"));
} }
@ -877,7 +877,7 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void _tint_GeometryShader() { EXPECT_EQ(result(), R"(void tint_GeometryShader() {
return; return;
} }

View File

@ -42,7 +42,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -52,14 +52,14 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -70,14 +70,14 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -86,7 +86,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -94,7 +94,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -102,7 +102,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -110,7 +110,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -118,14 +118,14 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -133,7 +133,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -141,7 +141,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -152,14 +152,14 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -170,7 +170,7 @@ ExpectedResult expected_texture_overload(
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",
}; };
@ -181,168 +181,168 @@ ExpectedResult expected_texture_overload(
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))";
case ValidTextureOverload::kSample2dF32: case ValidTextureOverload::kSample2dF32:
return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f)))"; return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f)))";
case ValidTextureOverload::kSample2dOffsetF32: case ValidTextureOverload::kSample2dOffsetF32:
return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))";
case ValidTextureOverload::kSample2dArrayF32: case ValidTextureOverload::kSample2dArrayF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3))))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3))))";
case ValidTextureOverload::kSample2dArrayOffsetF32: case ValidTextureOverload::kSample2dArrayOffsetF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))";
case ValidTextureOverload::kSample3dF32: case ValidTextureOverload::kSample3dF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))";
case ValidTextureOverload::kSample3dOffsetF32: case ValidTextureOverload::kSample3dOffsetF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))";
case ValidTextureOverload::kSampleCubeF32: case ValidTextureOverload::kSampleCubeF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))";
case ValidTextureOverload::kSampleCubeArrayF32: case ValidTextureOverload::kSampleCubeArrayF32:
return R"(_tint_texture.Sample(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; return R"(tint_texture.Sample(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))";
case ValidTextureOverload::kSampleDepth2dF32: case ValidTextureOverload::kSampleDepth2dF32:
return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f)))"; return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f)))";
case ValidTextureOverload::kSampleDepth2dOffsetF32: case ValidTextureOverload::kSampleDepth2dOffsetF32:
return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))";
case ValidTextureOverload::kSampleDepth2dArrayF32: case ValidTextureOverload::kSampleDepth2dArrayF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3))))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3))))";
case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleDepth2dArrayOffsetF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))";
case ValidTextureOverload::kSampleDepthCubeF32: case ValidTextureOverload::kSampleDepthCubeF32:
return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))";
case ValidTextureOverload::kSampleDepthCubeArrayF32: case ValidTextureOverload::kSampleDepthCubeArrayF32:
return R"(_tint_texture.Sample(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; return R"(tint_texture.Sample(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))";
case ValidTextureOverload::kSampleBias2dF32: case ValidTextureOverload::kSampleBias2dF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; return R"(tint_texture.SampleBias(tint_sampler, float2(1.0f, 2.0f), 3.0f))";
case ValidTextureOverload::kSampleBias2dOffsetF32: case ValidTextureOverload::kSampleBias2dOffsetF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; return R"(tint_texture.SampleBias(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))";
case ValidTextureOverload::kSampleBias2dArrayF32: case ValidTextureOverload::kSampleBias2dArrayF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))";
case ValidTextureOverload::kSampleBias2dArrayOffsetF32: case ValidTextureOverload::kSampleBias2dArrayOffsetF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))";
case ValidTextureOverload::kSampleBias3dF32: case ValidTextureOverload::kSampleBias3dF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))";
case ValidTextureOverload::kSampleBias3dOffsetF32: case ValidTextureOverload::kSampleBias3dOffsetF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))";
case ValidTextureOverload::kSampleBiasCubeF32: case ValidTextureOverload::kSampleBiasCubeF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))";
case ValidTextureOverload::kSampleBiasCubeArrayF32: case ValidTextureOverload::kSampleBiasCubeArrayF32:
return R"(_tint_texture.SampleBias(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; return R"(tint_texture.SampleBias(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))";
case ValidTextureOverload::kSampleLevel2dF32: case ValidTextureOverload::kSampleLevel2dF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3.0f))";
case ValidTextureOverload::kSampleLevel2dOffsetF32: case ValidTextureOverload::kSampleLevel2dOffsetF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))";
case ValidTextureOverload::kSampleLevel2dArrayF32: case ValidTextureOverload::kSampleLevel2dArrayF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f))";
case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: case ValidTextureOverload::kSampleLevel2dArrayOffsetF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))";
case ValidTextureOverload::kSampleLevel3dF32: case ValidTextureOverload::kSampleLevel3dF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))";
case ValidTextureOverload::kSampleLevel3dOffsetF32: case ValidTextureOverload::kSampleLevel3dOffsetF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))";
case ValidTextureOverload::kSampleLevelCubeF32: case ValidTextureOverload::kSampleLevelCubeF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))";
case ValidTextureOverload::kSampleLevelCubeArrayF32: case ValidTextureOverload::kSampleLevelCubeArrayF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; return R"(tint_texture.SampleLevel(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))";
case ValidTextureOverload::kSampleLevelDepth2dF32: case ValidTextureOverload::kSampleLevelDepth2dF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3))"; return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3))";
case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: case ValidTextureOverload::kSampleLevelDepth2dOffsetF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))";
case ValidTextureOverload::kSampleLevelDepth2dArrayF32: case ValidTextureOverload::kSampleLevelDepth2dArrayF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4))";
case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))";
case ValidTextureOverload::kSampleLevelDepthCubeF32: case ValidTextureOverload::kSampleLevelDepthCubeF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4))"; return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4))";
case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: case ValidTextureOverload::kSampleLevelDepthCubeArrayF32:
return R"(_tint_texture.SampleLevel(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; return R"(tint_texture.SampleLevel(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5))";
case ValidTextureOverload::kSampleGrad2dF32: case ValidTextureOverload::kSampleGrad2dF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; return R"(tint_texture.SampleGrad(tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))";
case ValidTextureOverload::kSampleGrad2dOffsetF32: case ValidTextureOverload::kSampleGrad2dOffsetF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; return R"(tint_texture.SampleGrad(tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))";
case ValidTextureOverload::kSampleGrad2dArrayF32: case ValidTextureOverload::kSampleGrad2dArrayF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))";
case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: case ValidTextureOverload::kSampleGrad2dArrayOffsetF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))";
case ValidTextureOverload::kSampleGrad3dF32: case ValidTextureOverload::kSampleGrad3dF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))";
case ValidTextureOverload::kSampleGrad3dOffsetF32: case ValidTextureOverload::kSampleGrad3dOffsetF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))"; return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))";
case ValidTextureOverload::kSampleGradCubeF32: case ValidTextureOverload::kSampleGradCubeF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))";
case ValidTextureOverload::kSampleGradCubeArrayF32: case ValidTextureOverload::kSampleGradCubeArrayF32:
return R"(_tint_texture.SampleGrad(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))"; return R"(tint_texture.SampleGrad(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))";
case ValidTextureOverload::kSampleCompareDepth2dF32: case ValidTextureOverload::kSampleCompareDepth2dF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float2(1.0f, 2.0f), 3.0f))";
case ValidTextureOverload::kSampleCompareDepth2dOffsetF32: case ValidTextureOverload::kSampleCompareDepth2dOffsetF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))";
case ValidTextureOverload::kSampleCompareDepth2dArrayF32: case ValidTextureOverload::kSampleCompareDepth2dArrayF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))";
case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))";
case ValidTextureOverload::kSampleCompareDepthCubeF32: case ValidTextureOverload::kSampleCompareDepthCubeF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))";
case ValidTextureOverload::kSampleCompareDepthCubeArrayF32: case ValidTextureOverload::kSampleCompareDepthCubeArrayF32:
return R"(_tint_texture.SampleCmpLevelZero(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))";
case ValidTextureOverload::kLoad1dLevelF32: case ValidTextureOverload::kLoad1dLevelF32:
return R"(_tint_texture.Load(int2(1, 0), 3))"; return R"(tint_texture.Load(int2(1, 0), 3))";
case ValidTextureOverload::kLoad1dLevelU32: case ValidTextureOverload::kLoad1dLevelU32:
return R"(_tint_texture.Load(int2(1, 0), 3))"; return R"(tint_texture.Load(int2(1, 0), 3))";
case ValidTextureOverload::kLoad1dLevelI32: case ValidTextureOverload::kLoad1dLevelI32:
return R"(_tint_texture.Load(int2(1, 0), 3))"; return R"(tint_texture.Load(int2(1, 0), 3))";
case ValidTextureOverload::kLoad2dLevelF32: case ValidTextureOverload::kLoad2dLevelF32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoad2dLevelU32: case ValidTextureOverload::kLoad2dLevelU32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoad2dLevelI32: case ValidTextureOverload::kLoad2dLevelI32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoad2dArrayLevelF32: case ValidTextureOverload::kLoad2dArrayLevelF32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoad2dArrayLevelU32: case ValidTextureOverload::kLoad2dArrayLevelU32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoad2dArrayLevelI32: case ValidTextureOverload::kLoad2dArrayLevelI32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoad3dLevelF32: case ValidTextureOverload::kLoad3dLevelF32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoad3dLevelU32: case ValidTextureOverload::kLoad3dLevelU32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoad3dLevelI32: case ValidTextureOverload::kLoad3dLevelI32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoadMultisampled2dF32: case ValidTextureOverload::kLoadMultisampled2dF32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoadMultisampled2dU32: case ValidTextureOverload::kLoadMultisampled2dU32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoadMultisampled2dI32: case ValidTextureOverload::kLoadMultisampled2dI32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoadMultisampled2dArrayF32: case ValidTextureOverload::kLoadMultisampled2dArrayF32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoadMultisampled2dArrayU32: case ValidTextureOverload::kLoadMultisampled2dArrayU32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoadMultisampled2dArrayI32: case ValidTextureOverload::kLoadMultisampled2dArrayI32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoadDepth2dLevelF32: case ValidTextureOverload::kLoadDepth2dLevelF32:
return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; return R"(tint_texture.Load(int3(1, 2, 0), 3))";
case ValidTextureOverload::kLoadDepth2dArrayLevelF32: case ValidTextureOverload::kLoadDepth2dArrayLevelF32:
return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))";
case ValidTextureOverload::kLoadStorageRO1dRgba32float: case ValidTextureOverload::kLoadStorageRO1dRgba32float:
return R"(_tint_texture.Load(int2(1, 0)))"; return R"(tint_texture.Load(int2(1, 0)))";
case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: case ValidTextureOverload::kLoadStorageRO2dRgba8unorm:
case ValidTextureOverload::kLoadStorageRO2dRgba8snorm: case ValidTextureOverload::kLoadStorageRO2dRgba8snorm:
case ValidTextureOverload::kLoadStorageRO2dRgba8uint: case ValidTextureOverload::kLoadStorageRO2dRgba8uint:
@ -359,19 +359,19 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kLoadStorageRO2dRgba32uint: case ValidTextureOverload::kLoadStorageRO2dRgba32uint:
case ValidTextureOverload::kLoadStorageRO2dRgba32sint: case ValidTextureOverload::kLoadStorageRO2dRgba32sint:
case ValidTextureOverload::kLoadStorageRO2dRgba32float: case ValidTextureOverload::kLoadStorageRO2dRgba32float:
return R"(_tint_texture.Load(int3(1, 2, 0)))"; return R"(tint_texture.Load(int3(1, 2, 0)))";
case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float: case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float:
return R"(_tint_texture.Load(int4(1, 2, 3, 0)))"; return R"(tint_texture.Load(int4(1, 2, 3, 0)))";
case ValidTextureOverload::kLoadStorageRO3dRgba32float: case ValidTextureOverload::kLoadStorageRO3dRgba32float:
return R"(_tint_texture.Load(int4(1, 2, 3, 0)))"; return R"(tint_texture.Load(int4(1, 2, 3, 0)))";
case ValidTextureOverload::kStoreWO1dRgba32float: case ValidTextureOverload::kStoreWO1dRgba32float:
return R"(_tint_texture[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; return R"(tint_texture[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))";
case ValidTextureOverload::kStoreWO2dRgba32float: case ValidTextureOverload::kStoreWO2dRgba32float:
return R"(_tint_texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; return R"(tint_texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))";
case ValidTextureOverload::kStoreWO2dArrayRgba32float: case ValidTextureOverload::kStoreWO2dArrayRgba32float:
return R"(_tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; return R"(tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))";
case ValidTextureOverload::kStoreWO3dRgba32float: case ValidTextureOverload::kStoreWO3dRgba32float:
return R"(_tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; return R"(tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))";
} }
return "<unmatched texture overload>"; return "<unmatched texture overload>";
} // NOLINT - Ignore the length of this function } // NOLINT - Ignore the length of this function

View File

@ -236,8 +236,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(struct S { EXPECT_THAT(result(), HasSubstr(R"(struct S {
int _tint_double; int tint_double;
float _tint_float; float tint_float;
}; };
)")); )"));
} }