Skip to content

Conversation

@SpeedCrash100
Copy link
Contributor

Connections
fixes #8473

Description
This fix for race where compute pass writes to texture which then copy to buffer. The race can be seen only on Mesa radeonsi drivers.

Testing
It tested on this gist https://gist.github.com/SpeedCrash100/6c60d121a32ef5bd6077c1822da19a38 with AMD RX 9070 XT.
The test switches white and black images and find inconsistency. For example when parts of white images found when the black one image were passed to input. The gist will print error:

!!! ERROR !!!. Iteration 150, 5997060 errors
!!! ERROR !!!. Iteration 151, 5735112 errors
!!! ERROR !!!. Iteration 152, 6104640 errors
!!! ERROR !!!. Iteration 153, 5704908 errors
!!! ERROR !!!. Iteration 154, 5863704 errors

Before the changes if run with WGPU_BACKEND=gl env (to force use radeonsi) the errors were detected by the gist. The error no longer printing by the test program.

Squash or Rebase?

Squash

Test run results

     Summary [  24.578s] 1039 tests run: 1033 passed, 6 failed, 12 skipped
        FAIL [   0.698s] wgpu-test::wgpu-gpu [Executed Failure: BACKEND] [Gl/AMD Radeon RX 9070 XT (radeonsi, gfx1201, LLVM 21.1.5, DRM 3.64, 6.17.7-5-cachyos)/1] wgpu_gpu::clear_texture::clear_texture_uncompressed
        FAIL [   3.233s] wgpu-examples [Executed Failure: BACKEND] [Vulkan/AMD Radeon RX 9070 XT (RADV GFX1201)/0] water
        FAIL [   3.270s] wgpu-examples [Executed Failure: BACKEND & ADAPTER] [Vulkan/AMD Radeon RX 9070 XT (RADV GFX1201)/0] ray_cube_normals
        FAIL [   0.198s] wgpu-test::wgpu-gpu [Executed Failure: BACKEND] [Vulkan/AMD Radeon RX 9070 XT (RADV GFX1201)/0] wgpu_gpu::shader::struct_layout::uniform_input
        FAIL [   0.098s] wgpu-test::wgpu-gpu [Executed] [Vulkan/AMD Radeon RX 9070 XT (RADV GFX1201)/0] wgpu_gpu::push_constants::render_pass_test
     SIGSEGV [   0.757s] wgpu-test::wgpu-gpu [Executed] [Vulkan/AMD Radeon RX 9070 XT (RADV GFX1201)/0] wgpu_gpu::ray_tracing::shader::prevent_invalid_ray_query_calls

If shader writes to texture in any way the barrier should be placed to avoid race when downloading texture somewhere else
@Vecvec
Copy link
Contributor

Vecvec commented Nov 15, 2025

@SpeedCrash100 could you create an issue with the output from the test wgpu_gpu::ray_tracing::shader::prevent_invalid_ray_query_calls when it fails?

@SpeedCrash100
Copy link
Contributor Author

@Vecvec see #8530

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

Thanks for digging deeper into this!
Beside needing to clarify what happens in queue.rs, please also add a changelog entry, thanks :)

@SpeedCrash100 SpeedCrash100 force-pushed the radeonsi-race-fix branch 2 times, most recently from 547cea5 to 24f68d6 Compare November 16, 2025 10:52
@SpeedCrash100
Copy link
Contributor Author

SpeedCrash100 commented Nov 16, 2025

Replaced barrier from GL_SHADER_IMAGE_ACCESS_BARRIER_BIT to GL_PIXEL_BUFFER_BARRIER_BIT because it seems that it is designed for cases when moving from shader to buffer

@SpeedCrash100 SpeedCrash100 force-pushed the radeonsi-race-fix branch 2 times, most recently from 71756ce to 3c97b93 Compare November 16, 2025 11:30
@Wumpf Wumpf self-requested a review November 16, 2025 11:31
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

looking great now & makes sense to me :)
thanks again!

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

(oops, didn't click Approve)

@Wumpf Wumpf merged commit c78f944 into gfx-rs:trunk Nov 16, 2025
42 checks passed
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.

[GL] The race condition if copy from texture to buffer command submited with compute pass

3 participants