-
Notifications
You must be signed in to change notification settings - Fork 70
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
After despawning, new ParticleEffects don't produce particles #106
Comments
Fix bind groups not re-created correctly when an effect is despawned in the same frame as another effect is spawned. Add a partial workaround for the `vfx_indirect.wgsl` shader accessing GPU buffers in order from index 0, which requires all GPU particle buffers to be in use without any gap. The partial workaround first destroys buffers for de-allocated effects, before re-creating new buffers for newly-spawned ones. This is not perfect, because this doesn't account for gaps when more buffers are de-allocated than created in the same frame, in which case `vfx_indirect` accesses the first N buffers, but some of them are not in use and some in use are skipped. We're missing an indirection here. Fixes #106
Fix bind groups not re-created correctly when an effect is despawned in the same frame as another effect is spawned. Add a partial workaround for the `vfx_indirect.wgsl` shader accessing GPU buffers in order from index 0, which requires all GPU particle buffers to be in use without any gap. The partial workaround first destroys buffers for de-allocated effects, before re-creating new buffers for newly-spawned ones. This is not perfect, because this doesn't account for gaps when more buffers are de-allocated than created in the same frame, in which case `vfx_indirect` accesses the first N buffers, but some of them are not in use and some in use are skipped. We're missing an indirection here. Fixes #106
There's 2 bugs here:
|
Fix bind groups not re-created correctly when an effect is despawned in the same frame as another effect is spawned. Add a partial workaround for the `vfx_indirect.wgsl` shader accessing GPU buffers in order from index 0, which requires all GPU particle buffers to be in use without any gap. The partial workaround first destroys buffers for de-allocated effects, before re-creating new buffers for newly-spawned ones. This is not perfect, because this doesn't account for gaps when more buffers are de-allocated than created in the same frame, in which case `vfx_indirect` accesses the first N buffers, but some of them are not in use and some in use are skipped. We're missing an indirection here. Fixes #106
Re-opening; this is only partially fixed as explained above. |
Just ran into this - I'd be happy to help contribute a fix once you know what solution you'd like |
Fix the invalid addressing of the indirect dispatch shader, which assumed that all allocated particle effects were tightly packed into the global dispatch indirect and render buffers. This is not true, due to the fact despawned effects leave an empty entry into those two buffers, and the buffers are indexed simultaneously by the CPU and GPU so cannot easily be compacted into a continuous array. This change fixes the addressing by leveraging the actual effect index stored per allocated effect into the spawner table, which is uploaded from CPU to GPU each frame, and therefore contains an up-to-date view of the allocations into the indirect and render dispatch tables. Using that index to indirect the compute shader's thread ID allows effectively addressing all the allocated effects, even when gaps exist into the dispatch tables. This fixes some effects not being simulated or rendered correctly when spawned after other effects have despawned and left gaps into those tables. Fixes #106
Fix the invalid addressing of the indirect dispatch shader, which assumed that all allocated particle effects were tightly packed into the global dispatch indirect and render buffers. This is not true, due to the fact despawned effects leave an empty entry into those two buffers, and the buffers are indexed simultaneously by the CPU and GPU so cannot easily be compacted into a continuous array. This change fixes the addressing by leveraging the actual effect index stored per allocated effect into the spawner table, which is uploaded from CPU to GPU each frame, and therefore contains an up-to-date view of the allocations into the indirect and render dispatch tables. Using that index to indirect the compute shader's thread ID allows effectively addressing all the allocated effects, even when gaps exist into the dispatch tables. This fixes some effects not being simulated or rendered correctly when spawned after other effects have despawned and left gaps into those tables. Fixes #106
Fix the invalid addressing of the indirect dispatch shader, which assumed that all allocated particle effects were tightly packed into the global dispatch indirect and render buffers. This is not true, due to the fact despawned effects leave an empty entry into those two buffers, and the buffers are indexed simultaneously by the CPU and GPU so cannot easily be compacted into a continuous array. This change fixes the addressing by leveraging the actual effect index stored per allocated effect into the spawner table, which is uploaded from CPU to GPU each frame, and therefore contains an up-to-date view of the allocations into the indirect and render dispatch tables. Using that index to indirect the compute shader's thread ID allows effectively addressing all the allocated effects, even when gaps exist into the dispatch tables. This fixes some effects not being simulated or rendered correctly when spawned after other effects have despawned and left gaps into those tables. Fixes #106
Fix the invalid addressing of the indirect dispatch shader, which assumed that all allocated particle effects were tightly packed into the global dispatch indirect and render buffers. This is not true, due to the fact despawned effects leave an empty entry into those two buffers, and the buffers are indexed simultaneously by the CPU and GPU so cannot easily be compacted into a continuous array. This change fixes the addressing by leveraging the actual effect index stored per allocated effect into the spawner table, which is uploaded from CPU to GPU each frame, and therefore contains an up-to-date view of the allocations into the indirect and render dispatch tables. Using that index to indirect the compute shader's thread ID allows effectively addressing all the allocated effects, even when gaps exist into the dispatch tables. This fixes some effects not being simulated or rendered correctly when spawned after other effects have despawned and left gaps into those tables. Fixes #106
Environment
bevy: 0.9
bevy_hanabi: 0.5
OS: MacOS
Issue
After despawning
ParticleEffect
entities, newly spawnedParticleEffect
entities don't produce particlesReproducing
See the following code for a reproduction: theon@132ce0b
The reproduction code spawns a new ParticleEffect entity every second. Once there are
MAX_EFFECTS
entities it despawns the oldest entity before spawning the next.Setting
MAX_EFFECTS
in that example seems to determine when the issue starts:Example where
MAX_EFFECTS=5
and the 7th spawned entity onwards doesn't produce particles:https://user-images.githubusercontent.com/759170/209003169-085f376e-8465-41cd-91a8-1649c318d691.mp4
Note: There is no issue when commenting out the line with
despawn_recursive()
The text was updated successfully, but these errors were encountered: