Skip to content

Commit

Permalink
glsl-out: fix emission of location/binding attributes (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jul 17, 2021
1 parent 602368d commit e76824a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
25 changes: 16 additions & 9 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ impl Version {
}
}

/// Checks if the version supports explicit `layout(location=)` qualifiers.
/// Checks if the version supports all of the explicit layouts:
/// - `location=` qualifiers for bindings
/// - `binding=` qualifiers for resources
///
/// Note: `location=` for vertex inputs and fragment outputs is supported
/// unconditionally for GLES 300.
fn supports_explicit_locations(&self) -> bool {
*self >= Version::Embedded(300) || *self >= Version::Desktop(410)
*self >= Version::Embedded(310) || *self >= Version::Desktop(410)
}
}

Expand Down Expand Up @@ -865,19 +870,21 @@ impl<'a, W: Write> Writer<'a, W> {
ShaderStage::Fragment => !output,
_ => false,
};

// Write the I/O locations, if allowed
if self.options.version.supports_explicit_locations()
|| !emit_interpolation_and_auxiliary
{
write!(self.out, "layout(location = {}) ", location)?;
}

// Write the interpolation qualifier.
if let Some(interp) = interpolation {
if emit_interpolation_and_auxiliary {
write!(self.out, "{} ", glsl_interpolation(interp))?;
}
}

// Write the storage class
if !emit_interpolation_and_auxiliary
&& self.options.version.supports_explicit_locations()
{
write!(self.out, "layout(location = {}) ", location)?;
}

// Write the sampling auxiliary qualifier.
//
// Before GLSL 4.2, the `centroid` and `sample` qualifiers were required to appear
Expand Down
5 changes: 5 additions & 0 deletions tests/in/quad.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
spv_version: (1, 0),
spv_debug: true,
spv_adjust_coordinate_space: true,
glsl: (
version: Embedded(300),
writer_flags: (bits: 0),
binding_map: {},
),
)
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 @@ -25,7 +25,7 @@ vec2 a_pos1 = vec2(0, 0);

layout(location = 1) in vec2 _p2vs_location1;
layout(location = 0) in vec2 _p2vs_location0;
smooth out vec2 _vs2fs_location0;
layout(location = 0) smooth out vec2 _vs2fs_location0;

void main2() {
vec2 _expr12 = a_uv1;
Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/quad.fs_extra.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 310 es
#version 300 es

precision highp float;

Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/quad.main.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 310 es
#version 300 es

precision highp float;

Expand Down
3 changes: 1 addition & 2 deletions tests/out/glsl/quad.main.Vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 310 es
#version 300 es

precision highp float;

Expand All @@ -17,7 +17,6 @@ void main() {
VertexOutput _tmp_return = VertexOutput(uv, vec4((1.2 * pos), 0.0, 1.0));
_vs2fs_location0 = _tmp_return.uv;
gl_Position = _tmp_return.position;
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}

4 changes: 2 additions & 2 deletions tests/out/glsl/shadow.fs_main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ readonly buffer Lights_block_1 {

uniform highp sampler2DArrayShadow _group_0_binding_2;

smooth in vec3 _vs2fs_location0;
smooth in vec4 _vs2fs_location1;
layout(location = 0) smooth in vec3 _vs2fs_location0;
layout(location = 1) smooth in vec4 _vs2fs_location1;
layout(location = 0) out vec4 _fs2p_location0;

float fetch_shadow(uint light_id, vec4 homogeneous_coords) {
Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/skybox.fs_main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct VertexOutput {

layout(binding = 0) uniform highp samplerCube _group_0_binding_1;

smooth in vec3 _vs2fs_location0;
layout(location = 0) smooth in vec3 _vs2fs_location0;
layout(location = 0) out vec4 _fs2p_location0;

void main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/out/glsl/skybox.vs_main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ layout(binding = 0) uniform Data_block_0 {
mat4x4 view;
} _group_0_binding_0;

smooth out vec3 _vs2fs_location0;
layout(location = 0) smooth out vec3 _vs2fs_location0;

void main() {
uint vertex_index = uint(gl_VertexID);
Expand Down

0 comments on commit e76824a

Please sign in to comment.