Add floats to storage buffers with the GPU's own atomic add instead of a compare-and-swap loop #2336

Closed
opened 2026-11-11 15:10:05 +00:00 by mooki000 · 1 comment
mooki000 commented 2026-11-11 15:10:05 +00:00 (Migrated from github.com)

The idea

Compute programs that run every frame in Kakariko and on Death Mountain Trail add floats to storage buffers, and the shader translator makes each of those adds a compare-and-swap loop. On an RTX 4090 the busiest of them takes 77 to 80 attempts per add on average. With the GPU's own float add (VK_EXT_shader_atomic_float, shaderBufferFloat32AtomicAdd) the frame's GPU time there is 0.4 to 0.6 ms lower, about 7%.

GPUs that can add floats atomically should do it in one instruction; the others keep the loop.

Anything else

  • Claim: #2306 is open with it, its tests and the measurements. By docs/workflow.md: S3 (1), a small frame-rate gain x reach (GPUs whose driver offers the feature; measured on NVIDIA only) x confidence 1.0 for the RTX 4090.
  • The idea is yassine-milal's, from #886, which was closed to keep the queue clear. #2306 is written again on current main, with no code copied from it.
  • Measured on an RTX 4090 only; AMD and Intel are not measured, as the pull request says.
  • I can test on Linux with an RTX 4090 (NVIDIA 615.78.08) and an Intel UHD 770 (Mesa 26.2.5), not on Windows or AMD.
### The idea Compute programs that run every frame in Kakariko and on Death Mountain Trail add floats to storage buffers, and the shader translator makes each of those adds a compare-and-swap loop. On an RTX 4090 the busiest of them takes 77 to 80 attempts per add on average. With the GPU's own float add (`VK_EXT_shader_atomic_float`, `shaderBufferFloat32AtomicAdd`) the frame's GPU time there is 0.4 to 0.6 ms lower, about 7%. GPUs that can add floats atomically should do it in one instruction; the others keep the loop. ### Anything else - Claim: #2306 is open with it, its tests and the measurements. By `docs/workflow.md`: S3 (1), a small frame-rate gain x reach (GPUs whose driver offers the feature; measured on NVIDIA only) x confidence 1.0 for the RTX 4090. - The idea is yassine-milal's, from #886, which was closed to keep the queue clear. #2306 is written again on current `main`, with no code copied from it. - Measured on an RTX 4090 only; AMD and Intel are not measured, as the pull request says. - I can test on Linux with an RTX 4090 (NVIDIA 615.78.08) and an Intel UHD 770 (Mesa 26.2.5), not on Windows or AMD.
NotRexed commented 2026-11-11 21:31:32 +00:00 (Migrated from github.com)

This is being done in your pull request #2306; closing the issue so the work is tracked in one place there.

This is being done in your pull request #2306; closing the issue so the work is tracked in one place there.
Commenting is not possible because the repository is archived.
No milestone
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Hookshot#2336
No description provided.