GPU clustering: `metadata_staging_pending_buffers` grows by one buffer every frame

Aperta Adatta ai principianti
#26,283 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
performance

Direzione di ricerca

Leggi crates/bevy_pbr/src/cluster/gpu.rs, in particolare ViewClusteringReadbackData::get_or_create_staging_buffer e schedule_readback_buffer_map; l’issue segnala un vettore di buffer in attesa su cui si scrive soltanto e il callback che ricicla i buffer. Controlla i test esistenti del clustering GPU oppure esegui l’esempio della scena 3D per un periodo prolungato. Il lavoro è completato quando gli staging buffer non si accumulano più e la memoria rimane stabile durante il carico di lavoro segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-Rendering C-Bug C-Performance S-Ready-For-Implementation

Bevy version and features

  • Bevy 0.20.0 (also 0.19.1; the code is unchanged on main as of 84e2d2c)
  • Features: bevy_render, bevy_core_pipeline, bevy_pbr, default GPU clustering

Relevant system information

  • macOS 27 on Apple M1 Max, Metal backend (also seen on iOS 27 / iPadOS 27 devices: A20 Pro, M5)
  • Log: GPU clustering is supported on this device.

What you did

Ran a small 3D scene (one DirectionalLight with shadows, a plane and a few meshes, one Camera3d) for 15–60 minutes. examples/3d/3d_scene.rs should show the same.

What went wrong

Memory grows for as long as the app runs, about 150 KB per minute at 60 fps (twice that at 120 Hz). Over 60 minutes the process footprint grew 304 → 308 MB (release) and 310 → 317 MB (debug), still rising at the end.

A heap analysis with MallocStackLogging shows a single block that keeps being reallocated to a larger size, allocated from bevy_pbr::cluster::gpu::cluster_on_gpu.

ViewClusteringReadbackData::get_or_create_staging_buffer (crates/bevy_pbr/src/cluster/gpu.rs) pushes every staging buffer into metadata_staging_pending_buffers:

self.metadata_staging_pending_buffers
    .push(staging_buffer.clone());

Nothing ever removes entries from that Vec. The map callback in schedule_readback_buffer_map only pushes the recycled buffer into metadata_staging_free_buffers, so metadata_staging_pending_buffers gains one Buffer per view per frame for the lifetime of the app. The field is never read.

Additional information

  • The iOS simulator is not affected because GPU clustering is disabled there (target_abi = "sim").
  • Workaround: set GlobalClusterSettings::gpu_clustering to None after PbrPlugin::finish (we do it in a Startup system). With CPU clustering the growing block is gone and the heap stays flat over 30 minutes.
  • Possible fix: remove metadata_staging_pending_buffers entirely (it is write-only), or remove the buffer from it in the map callback.
Lingua principale
Rust
Stelle
49.7k
Fork
5k
Merge medio
3g 19h
PR unite (30g)
134

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bevyengine/bevy

Tutte le issue di bevyengine/bevy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.