Emit std430 layout qualifiers for storage buffers (#1435)

* Remove unused petgraph dependency from glsl-out

* Emit std430 layout qualifiers for storage buffers
This commit is contained in:
Igor Shaposhnik 2021-09-29 19:24:34 +03:00 committed by GitHub
parent 2e73e48657
commit a4bf25a0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 9 deletions

View File

@ -35,7 +35,7 @@ default = []
dot-out = []
glsl-in = ["pp-rs"]
glsl-validate = []
glsl-out = ["petgraph"]
glsl-out = []
msl-out = []
serialize = ["serde", "indexmap/serde-1"]
deserialize = ["serde", "indexmap/serde-1"]

View File

@ -129,6 +129,10 @@ impl Version {
fn supports_early_depth_test(&self) -> bool {
*self >= Version::Desktop(130) || *self >= Version::Embedded(310)
}
fn supports_std430_layout(&self) -> bool {
*self >= Version::Desktop(430) || *self >= Version::Embedded(310)
}
}
impl PartialOrd for Version {
@ -816,8 +820,28 @@ impl<'a, W: Write> Writer<'a, W> {
if self.options.version.supports_explicit_locations() {
if let Some(ref br) = global.binding {
match self.options.binding_map.get(br) {
Some(binding) => write!(self.out, "layout(binding = {}) ", binding)?,
None => log::debug!("unassigned binding for {:?}", global.name),
Some(binding) => {
let layout = match global.class {
crate::StorageClass::Storage { .. } => {
if self.options.version.supports_std430_layout() {
"std430, "
} else {
"std140, "
}
}
crate::StorageClass::Uniform => "std140, ",
_ => "",
};
write!(self.out, "layout({}binding = {}) ", layout, binding)?
}
None => {
log::debug!("unassigned binding for {:?}", global.name);
if let crate::StorageClass::Storage { .. } = global.class {
if self.options.version.supports_std430_layout() {
write!(self.out, "layout(std430) ")?
}
}
}
}
}
}

View File

@ -5,7 +5,7 @@ precision highp int;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
buffer Bar_block_0Cs {
layout(std430) buffer Bar_block_0Cs {
mat4x4 matrix;
int atom;
uvec2 arr[2];

View File

@ -3,7 +3,7 @@
precision highp float;
precision highp int;
buffer Bar_block_0Vs {
layout(std430) buffer Bar_block_0Vs {
mat4x4 matrix;
int atom;
uvec2 arr[2];

View File

@ -20,11 +20,11 @@ uniform SimParams_block_0Cs {
float rule3Scale;
} _group_0_binding_0;
readonly buffer Particles_block_1Cs {
layout(std430) readonly buffer Particles_block_1Cs {
Particle particles[];
} _group_0_binding_1;
buffer Particles_block_2Cs {
layout(std430) buffer Particles_block_2Cs {
Particle particles[];
} _group_0_binding_2;

View File

@ -13,7 +13,7 @@ uniform Globals_block_0Fs {
uvec4 num_lights;
} _group_0_binding_0;
readonly buffer Lights_block_1Fs {
layout(std430) readonly buffer Lights_block_1Fs {
Light data[];
} _group_0_binding_1;

View File

@ -8,7 +8,7 @@ struct VertexOutput {
vec3 uv;
};
layout(binding = 0) uniform Data_block_0Vs {
layout(std140, binding = 0) uniform Data_block_0Vs {
mat4x4 proj_inv;
mat4x4 view;
} _group_0_binding_0;