Skip to content

Commit

Permalink
glsl-out: Call proper memory barrier functions (#1680)
Browse files Browse the repository at this point in the history
* glsl-out: Call proper memory barrier functions

* glsl-out: Change test for control flow

* Removed two unnecessary calls
  • Loading branch information
francesco-cattoglio authored Jan 21, 2022
1 parent 4bd1efc commit 8647e06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,13 +1771,18 @@ impl<'a, W: Write> Writer<'a, W> {
// keyword which ceases all further processing in a fragment shader, it's called OpKill
// in spir-v that's why it's called `Statement::Kill`
Statement::Kill => writeln!(self.out, "{}discard;", level)?,
// Issue an execution or a memory barrier.
// Issue a memory barrier. Please note that to ensure visibility,
// OpenGL always requires a call to the `barrier()` function after a `memoryBarrier*()`
Statement::Barrier(flags) => {
if flags.is_empty() {
writeln!(self.out, "{}barrier();", level)?;
} else {
writeln!(self.out, "{}groupMemoryBarrier();", level)?;
if flags.contains(crate::Barrier::STORAGE) {
writeln!(self.out, "{}memoryBarrierBuffer();", level)?;
}

if flags.contains(crate::Barrier::WORK_GROUP) {
writeln!(self.out, "{}memoryBarrierShared();", level)?;
}

writeln!(self.out, "{}barrier();", level)?;
}
// Stores in glsl are just variable assignments written as `pointer = value;`
Statement::Store { pointer, value } => {
Expand Down
6 changes: 4 additions & 2 deletions tests/out/glsl/control-flow.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ void loop_switch_continue(int x) {
void main() {
uvec3 global_id = gl_GlobalInvocationID;
int pos = 0;
groupMemoryBarrier();
groupMemoryBarrier();
memoryBarrierBuffer();
barrier();
memoryBarrierShared();
barrier();
switch(1) {
default:
pos = 1;
Expand Down

0 comments on commit 8647e06

Please sign in to comment.