Skip to content

Commit

Permalink
glsl-out: Write struct initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho committed Jan 4, 2022
1 parent 32205e3 commit b9c4893
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,17 @@ impl<'a, W: Write> Writer<'a, W> {
self.write_zero_init_value(base)?;
write!(self.out, ")")?;
}
TypeInner::Struct { ref members, .. } => {
let name = &self.names[&NameKey::Type(ty)];
write!(self.out, "{}(", name)?;
for (i, member) in members.iter().enumerate() {
self.write_zero_init_value(member.ty)?;
if i != members.len().saturating_sub(1) {
write!(self.out, ", ")?;
}
}
write!(self.out, ")")?;
}
_ => {} // TODO:
}

Expand Down Expand Up @@ -3086,6 +3097,9 @@ fn is_value_init_supported(module: &crate::Module, ty: Handle<crate::Type>) -> b
TypeInner::Array { base, size, .. } => {
size != crate::ArraySize::Dynamic && is_value_init_supported(module, base)
}
TypeInner::Struct { ref members, .. } => members
.iter()
.all(|member| is_value_init_supported(module, member.ty)),
_ => false,
}
}
2 changes: 1 addition & 1 deletion tests/out/glsl/interpolate.vert_main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ smooth centroid out float _vs2fs_location5;
smooth sample out float _vs2fs_location6;

void main() {
FragmentInput out_;
FragmentInput out_ = FragmentInput(vec4(0.0, 0.0, 0.0, 0.0), 0u, 0.0, vec2(0.0, 0.0), vec3(0.0, 0.0, 0.0), vec4(0.0, 0.0, 0.0, 0.0), 0.0, 0.0);
out_.position = vec4(2.0, 4.0, 5.0, 6.0);
out_.flat_ = 8u;
out_.linear = 27.0;
Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/operators.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ vec3 bool_cast(vec3 x) {
}

float constructors() {
Foo foo;
Foo foo = Foo(vec4(0.0, 0.0, 0.0, 0.0), 0);
foo = Foo(vec4(1.0), 1);
mat2x2 mat2comp = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0));
mat4x4 mat4comp = mat4x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/quad-vert.main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vec2 v_uv = vec2(0.0, 0.0);

vec2 a_uv_1 = vec2(0.0, 0.0);

gen_gl_PerVertex perVertexStruct;
gen_gl_PerVertex perVertexStruct = gen_gl_PerVertex(vec4(0.0, 0.0, 0.0, 1.0), 1.0, float[1](0.0), float[1](0.0));

vec2 a_pos_1 = vec2(0.0, 0.0);

Expand Down

0 comments on commit b9c4893

Please sign in to comment.