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 2 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
17 changes: 12 additions & 5 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,13 +1771,20 @@ 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)?;
writeln!(self.out, "{}memoryBarrierImage();", level)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current semantics of crate::Barrier::STORAGE doesn't include images. Trying to clarify that with the group. So we should probably remove it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to add the Image barrier after taking a look at the naga HLSL-out writer, which produces a DeviceMemoryBarrier() function call. Then I looked for more information and found this: https://github.com/microsoft/DirectXShaderCompiler/blob/master/docs/SPIR-V.rst#synchronization-intrinsics
Anyway, I will remove this for now.

writeln!(self.out, "{}memoryBarrierAtomicCounter();", level)?;
francesco-cattoglio marked this conversation as resolved.
Show resolved Hide resolved
}

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
8 changes: 6 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,12 @@ void loop_switch_continue(int x) {
void main() {
uvec3 global_id = gl_GlobalInvocationID;
int pos = 0;
groupMemoryBarrier();
groupMemoryBarrier();
memoryBarrierBuffer();
memoryBarrierImage();
memoryBarrierAtomicCounter();
barrier();
memoryBarrierShared();
barrier();
switch(1) {
default:
pos = 1;
Expand Down