Tint/GLSL: rename identifiers containing double-underscores.

This is prohibited by the GLSL ES spec:

"In addition, all identifiers containing two consecutive underscores (__) are reserved for use by underlying
software layers. Defining such a name in a shader does not itself result in an error, but may result in
unintended behaviors that stem from having multiple definitions of the same name."

(https://registry.khronos.org/OpenGL/specs/es/3.1/GLSL_ES_Specification_3.10.withchanges.pdf, section 3.7).

However, while glslang validation will not give an error on this, NVidia
ES drivers will. So I've added a Dawn end2end test instead of a WGSL test.

Bug: tint:1944
Change-Id: I4b965af00039ca7a232bc11be884483f8e02ccf6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134140
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Stephen White 2023-05-26 04:53:17 +00:00 committed by Dawn LUCI CQ
parent 4957327cc9
commit 0c7a99f894
15 changed files with 128 additions and 86 deletions

View File

@ -1462,6 +1462,48 @@ fn main(@location(0) value : f32) -> @location(0) vec4f {
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(255, 255, 255, 255), renderPass.color, 0, 0);
}
// Test that identifiers containing double underscores are renamed in the GLSL backend.
TEST_P(ShaderTests, DoubleUnderscore) {
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
@vertex
fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f {
const pos = array(
vec2( 1.0, -1.0),
vec2(-1.0, -1.0),
vec2( 0.0, 1.0),
);
return vec4(pos[VertexIndex], 0.0, 1.0);
})");
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
diagnostic(off, derivative_uniformity);
@fragment
fn main() -> @location(0) vec4f {
let re__sult = vec4f(1.0);
return re__sult;
})");
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 1, 1);
utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList;
descriptor.cTargets[0].format = renderPass.colorFormat;
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline);
pass.Draw(3);
pass.End();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(255, 255, 255, 255), renderPass.color, 0, 0);
}
DAWN_INSTANTIATE_TEST(ShaderTests,
D3D11Backend(),
D3D12Backend(),

View File

@ -1350,7 +1350,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
kReservedKeywordsGLSL +
sizeof(kReservedKeywordsGLSL) / sizeof(const char*),
name) ||
name.compare(0, 3, "gl_") == 0;
name.compare(0, 3, "gl_") == 0 || name.find("__") != std::string::npos;
case Target::kHlslKeywords:
return std::binary_search(
kReservedKeywordsHLSL,

View File

@ -15,7 +15,7 @@ struct SB_RW {
int arg_0;
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -25,15 +25,15 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
} sb_rw;
void atomicCompareExchangeWeak_1bd40a() {
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, 1, 1);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_19 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_19, (x_19 == 1));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_19, (x_19 == 1));
res = tint_symbol_2;
return;
}
@ -66,7 +66,7 @@ struct SB_RW {
int arg_0;
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -76,15 +76,15 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
} sb_rw;
void atomicCompareExchangeWeak_1bd40a() {
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, 1, 1);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_19 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_19, (x_19 == 1));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_19, (x_19 == 1));
res = tint_symbol_2;
return;
}

View File

@ -15,7 +15,7 @@ struct SB_RW {
uint arg_0;
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -25,15 +25,15 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
} sb_rw;
void atomicCompareExchangeWeak_63d8e6() {
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, 1u, 1u);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1u;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_17 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_17, (x_17 == 1u));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_17, (x_17 == 1u));
res = tint_symbol_2;
return;
}
@ -66,7 +66,7 @@ struct SB_RW {
uint arg_0;
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -76,15 +76,15 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
} sb_rw;
void atomicCompareExchangeWeak_63d8e6() {
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, 1u, 1u);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1u;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_17 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_17, (x_17 == 1u));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_17, (x_17 == 1u));
res = tint_symbol_2;
return;
}

View File

@ -6,7 +6,7 @@ struct atomic_compare_exchange_result_i32 {
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -14,15 +14,15 @@ struct x__atomic_compare_exchange_resulti32 {
uint local_invocation_index_1 = 0u;
shared int arg_0;
void atomicCompareExchangeWeak_e88938() {
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(arg_0, 1, 1);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_18 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_18, (x_18 == 1));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_18, (x_18 == 1));
res = tint_symbol_2;
return;
}

View File

@ -6,7 +6,7 @@ struct atomic_compare_exchange_result_u32 {
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -14,15 +14,15 @@ struct x__atomic_compare_exchange_resultu32 {
uint local_invocation_index_1 = 0u;
shared uint arg_0;
void atomicCompareExchangeWeak_83580d() {
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(arg_0, 1u, 1u);
atomic_compare_result.exchanged = atomic_compare_result.old_value == 1u;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_17 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_17, (x_17 == 1u));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_17, (x_17 == 1u));
res = tint_symbol_2;
return;
}

View File

@ -15,7 +15,7 @@ struct SB_RW {
int arg_0;
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -27,7 +27,7 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
void atomicCompareExchangeWeak_1bd40a() {
int arg_1 = 0;
int arg_2 = 0;
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
arg_1 = 1;
arg_2 = 1;
int x_23 = arg_2;
@ -35,11 +35,11 @@ void atomicCompareExchangeWeak_1bd40a() {
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, x_24, x_23);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_24;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_25 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_25, (x_25 == x_23));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_25, (x_25 == x_23));
res = tint_symbol_2;
return;
}
@ -72,7 +72,7 @@ struct SB_RW {
int arg_0;
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -84,7 +84,7 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
void atomicCompareExchangeWeak_1bd40a() {
int arg_1 = 0;
int arg_2 = 0;
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
arg_1 = 1;
arg_2 = 1;
int x_23 = arg_2;
@ -92,11 +92,11 @@ void atomicCompareExchangeWeak_1bd40a() {
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, x_24, x_23);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_24;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_25 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_25, (x_25 == x_23));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_25, (x_25 == x_23));
res = tint_symbol_2;
return;
}

View File

@ -15,7 +15,7 @@ struct SB_RW {
uint arg_0;
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -27,7 +27,7 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
void atomicCompareExchangeWeak_63d8e6() {
uint arg_1 = 0u;
uint arg_2 = 0u;
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
arg_1 = 1u;
arg_2 = 1u;
uint x_21 = arg_2;
@ -35,11 +35,11 @@ void atomicCompareExchangeWeak_63d8e6() {
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, x_22, x_21);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_22;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_23 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_23, (x_23 == x_21));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_23, (x_23 == x_21));
res = tint_symbol_2;
return;
}
@ -72,7 +72,7 @@ struct SB_RW {
uint arg_0;
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -84,7 +84,7 @@ layout(binding = 0, std430) buffer sb_rw_block_ssbo {
void atomicCompareExchangeWeak_63d8e6() {
uint arg_1 = 0u;
uint arg_2 = 0u;
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
arg_1 = 1u;
arg_2 = 1u;
uint x_21 = arg_2;
@ -92,11 +92,11 @@ void atomicCompareExchangeWeak_63d8e6() {
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(sb_rw.inner.arg_0, x_22, x_21);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_22;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_23 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_23, (x_23 == x_21));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_23, (x_23 == x_21));
res = tint_symbol_2;
return;
}

View File

@ -6,7 +6,7 @@ struct atomic_compare_exchange_result_i32 {
};
struct x__atomic_compare_exchange_resulti32 {
struct tint_symbol {
int old_value;
bool exchanged;
};
@ -16,7 +16,7 @@ shared int arg_0;
void atomicCompareExchangeWeak_e88938() {
int arg_1 = 0;
int arg_2 = 0;
x__atomic_compare_exchange_resulti32 res = x__atomic_compare_exchange_resulti32(0, false);
tint_symbol res = tint_symbol(0, false);
arg_1 = 1;
arg_2 = 1;
int x_22 = arg_2;
@ -24,11 +24,11 @@ void atomicCompareExchangeWeak_e88938() {
atomic_compare_exchange_result_i32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(arg_0, x_23, x_22);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_23;
atomic_compare_exchange_result_i32 tint_symbol = atomic_compare_result;
int old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_i32 tint_symbol_1 = atomic_compare_result;
int old_value_1 = tint_symbol_1.old_value;
int x_24 = old_value_1;
x__atomic_compare_exchange_resulti32 tint_symbol_1 = x__atomic_compare_exchange_resulti32(x_24, (x_24 == x_22));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_24, (x_24 == x_22));
res = tint_symbol_2;
return;
}

View File

@ -6,7 +6,7 @@ struct atomic_compare_exchange_result_u32 {
};
struct x__atomic_compare_exchange_resultu32 {
struct tint_symbol {
uint old_value;
bool exchanged;
};
@ -16,7 +16,7 @@ shared uint arg_0;
void atomicCompareExchangeWeak_83580d() {
uint arg_1 = 0u;
uint arg_2 = 0u;
x__atomic_compare_exchange_resultu32 res = x__atomic_compare_exchange_resultu32(0u, false);
tint_symbol res = tint_symbol(0u, false);
arg_1 = 1u;
arg_2 = 1u;
uint x_21 = arg_2;
@ -24,11 +24,11 @@ void atomicCompareExchangeWeak_83580d() {
atomic_compare_exchange_result_u32 atomic_compare_result;
atomic_compare_result.old_value = atomicCompSwap(arg_0, x_22, x_21);
atomic_compare_result.exchanged = atomic_compare_result.old_value == x_22;
atomic_compare_exchange_result_u32 tint_symbol = atomic_compare_result;
uint old_value_1 = tint_symbol.old_value;
atomic_compare_exchange_result_u32 tint_symbol_1 = atomic_compare_result;
uint old_value_1 = tint_symbol_1.old_value;
uint x_23 = old_value_1;
x__atomic_compare_exchange_resultu32 tint_symbol_1 = x__atomic_compare_exchange_resultu32(x_23, (x_23 == x_21));
res = tint_symbol_1;
tint_symbol tint_symbol_2 = tint_symbol(x_23, (x_23 == x_21));
res = tint_symbol_2;
return;
}

View File

@ -7,14 +7,14 @@ void unused_entry_point() {
void a() {
}
void a__() {
void tint_symbol() {
}
void b() {
a();
}
void b__() {
a__();
void tint_symbol_1() {
tint_symbol();
}

View File

@ -6,8 +6,8 @@ void unused_entry_point() {
}
void f() {
int a = 1;
int a__ = a;
int tint_symbol = a;
int b = a;
int b__ = a__;
int tint_symbol_1 = tint_symbol;
}

View File

@ -4,7 +4,7 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f(int a__) {
int b = a__;
void f(int tint_symbol) {
int b = tint_symbol;
}

View File

@ -8,12 +8,12 @@ struct a {
int b;
};
struct a__ {
int b__;
struct tint_symbol {
int tint_symbol_1;
};
void f() {
a__ c = a__(0);
int d = c.b__;
tint_symbol c = tint_symbol(0);
int d = c.tint_symbol_1;
}

View File

@ -5,9 +5,9 @@ void unused_entry_point() {
return;
}
int a = 1;
int a__ = 2;
int tint_symbol = 2;
void f() {
int b = a;
int b__ = a__;
int tint_symbol_1 = tint_symbol;
}