Skip to content

Commit c78f944

Browse files
Fix: Race condition when compute shader writes to texture. (#8527)
1 parent 07d4db5 commit c78f944

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ By @SupaMaggie70Incorporated in [#8206](https://github.com/gfx-rs/wgpu/pull/8206
163163

164164
- Fixed a bug where the texture aspect was not passed through when calling `copy_texture_to_buffer` in WebGPU, causing the copy to fail for depth/stencil textures. By @Tim-Evans-Seequent in [#8445](https://github.com/gfx-rs/wgpu/pull/8445).
165165

166+
#### GLES
167+
168+
- Fix race when downloading texture from compute shader pass. By @SpeedCrash100 in [#8527](https://github.com/gfx-rs/wgpu/pull/8527)
169+
166170
#### hal
167171

168172
- `DropCallback`s are now called after dropping all other fields of their parent structs. By @jerzywilczek in [#8353](https://github.com/gfx-rs/wgpu/pull/8353)

wgpu-hal/src/gles/command.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
311311
let mut combined_usage = wgt::TextureUses::empty();
312312
for bar in barriers {
313313
// GLES only synchronizes storage -> anything explicitly
314-
if !bar
315-
.usage
316-
.from
317-
.contains(wgt::TextureUses::STORAGE_READ_WRITE)
318-
{
314+
// if shader writes to a texture then barriers should be placed
315+
if !bar.usage.from.intersects(
316+
wgt::TextureUses::STORAGE_READ_WRITE | wgt::TextureUses::STORAGE_WRITE_ONLY,
317+
) {
319318
continue;
320319
}
321320
// unlike buffers, there is no need for a concrete texture

wgpu-hal/src/gles/queue.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,10 @@ impl super::Queue {
12571257
}
12581258
unsafe { gl.memory_barrier(flags) };
12591259
}
1260+
// because `STORAGE_WRITE_ONLY` and `STORAGE_READ_WRITE` are only states
1261+
// we can transit from due OpenGL memory barriers are used to make _subsequent_
1262+
// operations see changes from the _shader_ side. We filter out usage changes that are
1263+
// does not comes from the shader side in `transition_textures`
12601264
C::TextureBarrier(usage) => {
12611265
let mut flags = 0;
12621266
if usage.contains(wgt::TextureUses::RESOURCE) {
@@ -1269,6 +1273,9 @@ impl super::Queue {
12691273
) {
12701274
flags |= glow::SHADER_IMAGE_ACCESS_BARRIER_BIT;
12711275
}
1276+
if usage.intersects(wgt::TextureUses::COPY_SRC) {
1277+
flags |= glow::PIXEL_BUFFER_BARRIER_BIT;
1278+
}
12721279
if usage.contains(wgt::TextureUses::COPY_DST) {
12731280
flags |= glow::TEXTURE_UPDATE_BARRIER_BIT;
12741281
}

0 commit comments

Comments
 (0)