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

glsl-out: Bake Constant expressions #1950

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,17 @@ impl<'a, W: Write> Writer<'a, W> {
writeln!(self.out, ";")?
}

// Loop trough all Constant expressions and bake them if needed.
for (handle, expr) in ctx.expressions.iter() {
if let crate::Expression::Constant(_) = *expr {
if self.need_bake_expressions.contains(&handle) {
let name = format!("{}{}", back::BAKE_PREFIX, handle.index());
write!(self.out, "{}", back::Level(1))?;
self.write_named_expr(handle, name, &ctx)?;
}
}
}

// Write the function body (statement list)
for sta in func.body.iter() {
// Write a statement, the indentation should always be 1 when writing the function body
Expand Down
5 changes: 3 additions & 2 deletions tests/out/glsl/boids.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ void main() {
vec2 pos = vec2(0.0);
vec2 vel = vec2(0.0);
uint i = 0u;
uint _e0 = 1500u;
uint index = global_invocation_id.x;
if ((index >= 1500u)) {
if ((index >= _e0)) {
return;
}
vec2 _e10 = _group_0_binding_1_cs.particles[index].pos;
Expand All @@ -60,7 +61,7 @@ void main() {
}
loop_init = false;
uint _e37 = i;
if ((_e37 >= 1500u)) {
if ((_e37 >= _e0)) {
break;
}
uint _e39 = i;
Expand Down
5 changes: 3 additions & 2 deletions tests/out/glsl/image.gather.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ uniform highp sampler2DShadow _group_1_binding_2_fs;
layout(location = 0) out vec4 _fs2p_location0;

void main() {
float _e21 = 0.5;
vec2 tc = vec2(0.5);
vec4 s2d = textureGather(_group_0_binding_1_fs, vec2(tc), 1);
vec4 s2d_offset = textureGatherOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1), 3);
vec4 s2d_depth = textureGather(_group_1_binding_2_fs, vec2(tc), 0.5);
vec4 s2d_depth_offset = textureGatherOffset(_group_1_binding_2_fs, vec2(tc), 0.5, ivec2(3, 1));
vec4 s2d_depth = textureGather(_group_1_binding_2_fs, vec2(tc), _e21);
vec4 s2d_depth_offset = textureGatherOffset(_group_1_binding_2_fs, vec2(tc), _e21, ivec2(3, 1));
_fs2p_location0 = (((s2d + s2d_offset) + s2d_depth) + s2d_depth_offset);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/out/glsl/image.texture_sample.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ uniform highp sampler2D _group_0_binding_1_fs;
layout(location = 0) out vec4 _fs2p_location0;

void main() {
float _e18 = 2.299999952316284;
vec2 tc = vec2(0.5);
vec4 s1d = texture(_group_0_binding_0_fs, vec2(tc.x, 0.0));
vec4 s2d = texture(_group_0_binding_1_fs, vec2(tc));
vec4 s2d_offset = textureOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1));
vec4 s2d_level = textureLod(_group_0_binding_1_fs, vec2(tc), 2.299999952316284);
vec4 s2d_level_offset = textureLodOffset(_group_0_binding_1_fs, vec2(tc), 2.299999952316284, ivec2(3, 1));
vec4 s2d_level = textureLod(_group_0_binding_1_fs, vec2(tc), _e18);
vec4 s2d_level_offset = textureLodOffset(_group_0_binding_1_fs, vec2(tc), _e18, ivec2(3, 1));
vec4 s2d_bias_offset = textureOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1), 2.0);
_fs2p_location0 = ((((s1d + s2d) + s2d_offset) + s2d_level) + s2d_level_offset);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ uniform highp samplerCubeShadow _group_1_binding_3_fs;
layout(location = 0) out float _fs2p_location0;

void main() {
float _e21 = 0.5;
vec2 tc = vec2(0.5);
float s2d_depth = texture(_group_1_binding_2_fs, vec3(tc, 0.5));
float s2d_depth_level = textureLod(_group_1_binding_2_fs, vec3(tc, 0.5), 0.0);
float scube_depth_level = textureGrad(_group_1_binding_3_fs, vec4(vec3(0.5), 0.5), vec3(0.0), vec3(0.0));
float s2d_depth = texture(_group_1_binding_2_fs, vec3(tc, _e21));
float s2d_depth_level = textureLod(_group_1_binding_2_fs, vec3(tc, _e21), 0.0);
float scube_depth_level = textureGrad(_group_1_binding_3_fs, vec4(vec3(0.5), _e21), vec3(0.0), vec3(0.0));
_fs2p_location0 = (s2d_depth + s2d_depth_level);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/out/glsl/math-functions.main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ precision highp int;


void main() {
float _e0 = 1.0;
vec4 v = vec4(0.0);
float a = degrees(1.0);
float b = radians(1.0);
float a = degrees(_e0);
float b = radians(_e0);
vec4 c = degrees(v);
vec4 d = radians(v);
}
Expand Down
20 changes: 12 additions & 8 deletions tests/out/glsl/operators.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ struct Foo {
};

vec4 builtins() {
int s1_ = (true ? 1 : 0);
vec4 s2_ = (true ? vec4(1.0, 1.0, 1.0, 1.0) : vec4(0.0, 0.0, 0.0, 0.0));
vec4 s3_ = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(0.0, 0.0, 0.0, 0.0), bvec4(false, false, false, false));
vec4 m1_ = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0), vec4(0.5, 0.5, 0.5, 0.5));
vec4 m2_ = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0), 0.10000000149011612);
float b1_ = intBitsToFloat(ivec4(1, 1, 1, 1).x);
vec4 b2_ = intBitsToFloat(ivec4(1, 1, 1, 1));
ivec4 v_i32_zero = ivec4(vec4(0.0, 0.0, 0.0, 0.0));
vec4 _e1 = vec4(1.0, 1.0, 1.0, 1.0);
ivec4 _e2 = ivec4(1, 1, 1, 1);
vec4 _e3 = vec4(0.0, 0.0, 0.0, 0.0);
bool _e4 = true;
int s1_ = (_e4 ? 1 : 0);
vec4 s2_ = (_e4 ? _e1 : _e3);
vec4 s3_ = mix(_e1, _e3, bvec4(false, false, false, false));
vec4 m1_ = mix(_e3, _e1, vec4(0.5, 0.5, 0.5, 0.5));
vec4 m2_ = mix(_e3, _e1, 0.10000000149011612);
float b1_ = intBitsToFloat(_e2.x);
vec4 b2_ = intBitsToFloat(_e2);
ivec4 v_i32_zero = ivec4(_e3);
return (((((vec4((ivec4(s1_) + v_i32_zero)) + s2_) + m1_) + m2_) + vec4(b1_)) + b2_);
}

Expand Down