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

Conversation

francesco-cattoglio
Copy link
Contributor

@francesco-cattoglio francesco-cattoglio commented Jan 21, 2022

This should fix #1677
OpenGL memory barriers and visibility are really confusing to me, but I spent some time researching to the best of my ability to make this correct: I started from https://www.khronos.org/opengl/wiki/Memory_Model#Ensuring_visibility and then read some extra questions/answers/blog posts around the net to confirm that I understood the khronos wiki correctly.

After the code change I did run cargo test --all-features --workspace and it reported no error, then I ran make validate-glsl and finally committed the new (modified) test output.

Edit: P.S: the barrier() GLSL function can only be called in a compute shader, but I am pretty sure this is fine because WGSL synchronization built-in functions can only be called in compute shaders anyway.

src/back/glsl/mod.rs Outdated Show resolved Hide resolved
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.

@kvark kvark added the can backport PR that can be back-ported to a release branch label Jan 21, 2022
@kvark kvark enabled auto-merge (squash) January 21, 2022 15:31
@kvark kvark merged commit 8647e06 into gfx-rs:master Jan 21, 2022
kvark pushed a commit to kvark/naga that referenced this pull request Jan 24, 2022
* glsl-out: Call proper memory barrier functions

* glsl-out: Change test for control flow

* Removed two unnecessary calls
@kvark kvark mentioned this pull request Jan 24, 2022
kvark pushed a commit that referenced this pull request Jan 24, 2022
* glsl-out: Call proper memory barrier functions

* glsl-out: Change test for control flow

* Removed two unnecessary calls
@kvark kvark removed the can backport PR that can be back-ported to a release branch label Jan 24, 2022
@kvark
Copy link
Member

kvark commented Jan 24, 2022

published in 0.8.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GLSL barriers should come with barrier()
2 participants