Skip to content

Fix usage of active_submission_index.fetch_add#6

Merged
gents83 merged 1 commit intogents83:masterfrom
niklaskorz:atomic-fetch-add
Apr 7, 2023
Merged

Fix usage of active_submission_index.fetch_add#6
gents83 merged 1 commit intogents83:masterfrom
niklaskorz:atomic-fetch-add

Conversation

@niklaskorz
Copy link
Copy Markdown

@niklaskorz niklaskorz commented Apr 7, 2023

From https://doc.rust-lang.org/std/sync/atomic/struct.AtomicU64.html#method.fetch_add:

Adds to the current value, returning the previous value.

Thus, receiving the new active submission index after incrementing it requires adding 1 to the return value locally as well.

For comparison, the other uses of fetch_add in wgpu (unrelated to the current changes) treat the atomic as a "next id" variable instead of an "active id", thus not requiring to increment the return value of fetch_add:

https://github.com/gfx-rs/wgpu/blob/dd64343f942ff519f980a2adc02fa60f3a7b72a3/wgpu/src/backend/web.rs#L29

https://github.com/gfx-rs/wgpu/blob/dd64343f942ff519f980a2adc02fa60f3a7b72a3/wgpu-hal/src/gles/device.rs#L1094

@gents83
Copy link
Copy Markdown
Owner

gents83 commented Apr 7, 2023

Very good catch!

@gents83 gents83 merged commit c7b08db into gents83:master Apr 7, 2023
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.

2 participants