bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Redundant copies of MeshUniform

Open JMS55 opened this issue 1 year ago • 2 comments

Since https://github.com/bevyengine/bevy/pull/9685, each instance of batch_and_prepare_render_phase will append a copy of MeshUniform to the GpuArrayBuffer<MeshUniform> resource for each entity x phase. For 2 cameras, each with 3 phases (shadow, prepass, main pass), that's 6 total copies per entity... Additionally, each batch_and_prepare_render_phase cannot run in parallel with each other due to ResMut<GpuArrayBuffer>.

This was kind of intended as it makes it easy for each draw to find the correct MeshUniform in the shader, but it does have the above downsides.

JMS55 avatar Feb 07 '24 21:02 JMS55

Additionally, each batch_and_prepare_render_phase cannot run in parallel with each other due to ResMut<GpuArrayBuffer>.

This is potentially avoidable by splitting the resource based on phase, though I'm not sure how that would play out on the GPU side. Though that doesn't address the issue of the duplicate copies.

james7132 avatar Feb 11 '24 22:02 james7132

When trying to accelerate encase encoding, I found that the memory copy and encoding costs aren't the bottleneck in the batching systems. It may come down to the fact that we're computing the matrix inverses, potentially redundantly, across multiple render phases.

james7132 avatar Mar 05 '24 21:03 james7132