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: Call proper memory barrier functions #1680

Merged
merged 3 commits into from
Jan 21, 2022
Merged
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
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