GLSL: call renamer transform from GLSL transform.

This significantly simplifies the calling code from Dawn.
It does require moving the SingleEntryPoint transform above the
renamer, since we need to call SEP with the original name. That is
probably also an optimization, since we do the subsequent transforms
with a culled AST.

Bug: tint:1268
Change-Id: I1f48ec0238ea76310742c60b119311747dd3dbac
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80020
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2022-02-10 16:22:28 +00:00 committed by Tint LUCI CQ
parent 8bbdda7e89
commit 0b3dfef469
6 changed files with 25 additions and 29 deletions

View File

@ -1109,9 +1109,6 @@ int main(int argc, const char** argv) {
} }
#if TINT_BUILD_GLSL_WRITER #if TINT_BUILD_GLSL_WRITER
case Format::kGlsl: { case Format::kGlsl: {
transform_inputs.Add<tint::transform::Renamer::Config>(
tint::transform::Renamer::Target::kGlslKeywords);
transform_manager.Add<tint::transform::Renamer>();
break; break;
} }
#endif // TINT_BUILD_GLSL_WRITER #endif // TINT_BUILD_GLSL_WRITER

View File

@ -30,6 +30,7 @@
#include "src/transform/pad_array_elements.h" #include "src/transform/pad_array_elements.h"
#include "src/transform/promote_side_effects_to_decl.h" #include "src/transform/promote_side_effects_to_decl.h"
#include "src/transform/remove_phonies.h" #include "src/transform/remove_phonies.h"
#include "src/transform/renamer.h"
#include "src/transform/simplify_pointers.h" #include "src/transform/simplify_pointers.h"
#include "src/transform/single_entry_point.h" #include "src/transform/single_entry_point.h"
#include "src/transform/unshadow.h" #include "src/transform/unshadow.h"
@ -50,6 +51,12 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) const {
auto* cfg = inputs.Get<Config>(); auto* cfg = inputs.Get<Config>();
if (cfg && !cfg->entry_point.empty()) {
manager.Add<SingleEntryPoint>();
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
}
manager.Add<Renamer>();
data.Add<Renamer::Config>(Renamer::Target::kGlslKeywords);
manager.Add<Unshadow>(); manager.Add<Unshadow>();
// Attempt to convert `loop`s into for-loops. This is to try and massage the // Attempt to convert `loop`s into for-loops. This is to try and massage the
@ -62,10 +69,6 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) const {
// ZeroInitWorkgroupMemory may inject new builtin parameters. // ZeroInitWorkgroupMemory may inject new builtin parameters.
manager.Add<ZeroInitWorkgroupMemory>(); manager.Add<ZeroInitWorkgroupMemory>();
} }
if (cfg && !cfg->entry_point.empty()) {
manager.Add<SingleEntryPoint>();
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
}
manager.Add<CanonicalizeEntryPointIO>(); manager.Add<CanonicalizeEntryPointIO>();
manager.Add<SimplifyPointers>(); manager.Add<SimplifyPointers>();

View File

@ -22,7 +22,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/transform/glsl.h" #include "src/transform/glsl.h"
#include "src/transform/manager.h" #include "src/transform/manager.h"
#include "src/transform/renamer.h"
#include "src/writer/glsl/generator_impl.h" #include "src/writer/glsl/generator_impl.h"
namespace tint { namespace tint {
@ -81,9 +80,6 @@ class TestHelperBase : public BODY, public ProgramBuilder {
transform::Manager transform_manager; transform::Manager transform_manager;
transform::DataMap transform_data; transform::DataMap transform_data;
transform_data.Add<transform::Renamer::Config>(
transform::Renamer::Target::kGlslKeywords);
transform_manager.Add<tint::transform::Renamer>();
transform_manager.Add<tint::transform::Glsl>(); transform_manager.Add<tint::transform::Glsl>();
auto result = transform_manager.Run(program.get(), transform_data); auto result = transform_manager.Run(program.get(), transform_data);
[&]() { [&]() {

View File

@ -58,8 +58,8 @@ VertexOutput vs_main(VertexInput tint_symbol) {
} }
void main() { void main() {
VertexInput tint_symbol_3 = VertexInput(position_1, color_1, quad_pos_1); VertexInput tint_symbol_2 = VertexInput(position_1, color_1, quad_pos_1);
VertexOutput inner_result = vs_main(tint_symbol_3); VertexOutput inner_result = vs_main(tint_symbol_2);
gl_Position = inner_result.position; gl_Position = inner_result.position;
color_2 = inner_result.color; color_2 = inner_result.color;
quad_pos_2 = inner_result.quad_pos; quad_pos_2 = inner_result.quad_pos;
@ -72,7 +72,7 @@ precision mediump float;
layout(location = 0) in vec4 color_1; layout(location = 0) in vec4 color_1;
layout(location = 1) in vec2 quad_pos_1; layout(location = 1) in vec2 quad_pos_1;
layout(location = 0) out vec4 value_1; layout(location = 0) out vec4 value;
struct RenderParams { struct RenderParams {
mat4 modelViewProjectionMatrix; mat4 modelViewProjectionMatrix;
vec3 right; vec3 right;
@ -114,9 +114,9 @@ vec4 fs_main(VertexOutput tint_symbol) {
} }
void main() { void main() {
VertexOutput tint_symbol_3 = VertexOutput(gl_FragCoord, color_1, quad_pos_1); VertexOutput tint_symbol_1 = VertexOutput(gl_FragCoord, color_1, quad_pos_1);
vec4 inner_result = fs_main(tint_symbol_3); vec4 inner_result = fs_main(tint_symbol_1);
value_1 = inner_result; value = inner_result;
return; return;
} }
#version 310 es #version 310 es
@ -170,7 +170,7 @@ struct UBO {
uint width; uint width;
}; };
uniform highp sampler2D tint_symbol_2_1; uniform highp sampler2D tint_symbol_1;
void simulate(uvec3 GlobalInvocationID) { void simulate(uvec3 GlobalInvocationID) {
rand_seed = ((sim_params.seed.xy + vec2(GlobalInvocationID.xy)) * sim_params.seed.zw); rand_seed = ((sim_params.seed.xy + vec2(GlobalInvocationID.xy)) * sim_params.seed.zw);
uint idx = GlobalInvocationID.x; uint idx = GlobalInvocationID.x;
@ -182,8 +182,8 @@ void simulate(uvec3 GlobalInvocationID) {
if ((particle.lifetime < 0.0f)) { if ((particle.lifetime < 0.0f)) {
ivec2 coord = ivec2(0, 0); ivec2 coord = ivec2(0, 0);
{ {
for(int level = (textureQueryLevels(tint_symbol_2_1); - 1); (level > 0); level = (level - 1)) { for(int level = (textureQueryLevels(tint_symbol_1); - 1); (level > 0); level = (level - 1)) {
vec4 probabilites = texelFetch(tint_symbol_2_1, coord, level); vec4 probabilites = texelFetch(tint_symbol_1, coord, level);
vec4 value = vec4(rand()); vec4 value = vec4(rand());
bvec4 mask = (greaterThanEqual(value, vec4(0.0f, probabilites.xyz)) & lessThan(value, probabilites)); bvec4 mask = (greaterThanEqual(value, vec4(0.0f, probabilites.xyz)) & lessThan(value, probabilites));
coord = (coord * 2); coord = (coord * 2);
@ -191,9 +191,9 @@ void simulate(uvec3 GlobalInvocationID) {
coord.y = (coord.y + (any(mask.zw) ? 1 : 0)); coord.y = (coord.y + (any(mask.zw) ? 1 : 0));
} }
} }
vec2 uv = (vec2(coord) / vec2(textureSize(tint_symbol_2_1, 0))); vec2 uv = (vec2(coord) / vec2(textureSize(tint_symbol_1, 0)));
particle.position = vec3((((uv - 0.5f) * 3.0f) * vec2(1.0f, -1.0f)), 0.0f); particle.position = vec3((((uv - 0.5f) * 3.0f) * vec2(1.0f, -1.0f)), 0.0f);
particle.color = texelFetch(tint_symbol_2_1, coord, 0); particle.color = texelFetch(tint_symbol_1, coord, 0);
particle.velocity.x = ((rand() - 0.5f) * 0.100000001f); particle.velocity.x = ((rand() - 0.5f) * 0.100000001f);
particle.velocity.y = ((rand() - 0.5f) * 0.100000001f); particle.velocity.y = ((rand() - 0.5f) * 0.100000001f);
particle.velocity.z = (rand() * 0.300000012f); particle.velocity.z = (rand() * 0.300000012f);
@ -322,13 +322,13 @@ void export_level(uvec3 coord) {
if (all(lessThan(coord.xy, uvec2(imageSize(tex_out))))) { if (all(lessThan(coord.xy, uvec2(imageSize(tex_out))))) {
uint dst_offset = (coord.x + (coord.y * ubo.width)); uint dst_offset = (coord.x + (coord.y * ubo.width));
uint src_offset = ((coord.x * 2u) + ((coord.y * 2u) * ubo.width)); uint src_offset = ((coord.x * 2u) + ((coord.y * 2u) * ubo.width));
float a_1 = buf_in.weights[(src_offset + 0u)]; float a = buf_in.weights[(src_offset + 0u)];
float b = buf_in.weights[(src_offset + 1u)]; float b = buf_in.weights[(src_offset + 1u)];
float c = buf_in.weights[((src_offset + 0u) + ubo.width)]; float c = buf_in.weights[((src_offset + 0u) + ubo.width)];
float d = buf_in.weights[((src_offset + 1u) + ubo.width)]; float d = buf_in.weights[((src_offset + 1u) + ubo.width)];
float sum = dot(vec4(a_1, b, c, d), vec4(1.0f)); float sum = dot(vec4(a, b, c, d), vec4(1.0f));
buf_out.weights[dst_offset] = (sum / 4.0f); buf_out.weights[dst_offset] = (sum / 4.0f);
vec4 probabilities = (vec4(a_1, (a_1 + b), ((a_1 + b) + c), sum) / max(sum, 0.0001f)); vec4 probabilities = (vec4(a, (a + b), ((a + b) + c), sum) / max(sum, 0.0001f));
imageStore(tex_out, ivec2(coord.xy), probabilities); imageStore(tex_out, ivec2(coord.xy), probabilities);
} }
} }

View File

@ -19,8 +19,8 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() { void unused_entry_point() {
return; return;
} }
void i() { void tint_symbol() {
float s = tint_modf(1.0f).whole; float tint_symbol_1 = tint_modf(1.0f).whole;
} }
Error parsing GLSL shader: Error parsing GLSL shader:

View File

@ -26,7 +26,7 @@ void uses_b() {
b = (b * 2); b = (b * 2);
} }
void main2(uint local_invocation_index_1) { void main2(uint local_invocation_index) {
{ {
b = 0; b = 0;
} }
@ -67,7 +67,7 @@ void outer() {
no_uses(); no_uses();
} }
void main3(uint local_invocation_index_2) { void main3(uint local_invocation_index) {
{ {
a = 0; a = 0;
b = 0; b = 0;