Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redundant struct literal expressions in generated code #96

Open
leod opened this issue Apr 4, 2023 · 0 comments
Open

Fix redundant struct literal expressions in generated code #96

leod opened this issue Apr 4, 2023 · 0 comments

Comments

@leod
Copy link
Owner

leod commented Apr 4, 2023

Currently, the implementation of Object::expr() returns a new Rc in each call. This is necessary to allow users to construct structs as normal Rust literals.

Since we use Rcs to deduplicate expressions, this has the downside of generating redundant struct literal expressions:

    vec4 var_0 = texture(uniforms_b, vertex_output_uv);
    float var_1 = var_0.x;
    float var_2 = var_0.y;
    float var_3 = var_0.z;
    vec3 var_4 = mix(((1.055 * pow(vec3(var_1, var_2, var_3), vec3(0.41666666, 0.41666666, 0.41666666))) - 0.055), (vec3(var_1, var_2, var_3) * 12.92), lessThan(vec3(var_1, var_2, var_3), vec3(0.0031308, 0.0031308, 0.0031308)));

Here, the vec3(var_1, var_2, var_3) is redundant.

We could fix this by caching struct literal expressions in Trace somehow. Maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant