Split out the IndirectParametersMetadata into CPU-populated and GPU-populated buffers.#17863
Merged
superdump merged 3 commits intobevyengine:mainfrom Feb 18, 2025
Merged
Conversation
GPU-populated buffers. The GPU can fill out many of the fields in `IndirectParametersMetadata` using information it already has: * `early_instance_count` and `late_instance_count` are always initialized to zero. * `mesh_index` is already present in the work item buffer as the `input_index` of the first work item in each batch. This patch moves these fields to a separate buffer, the *GPU indirect parameters metadata* buffer. That way, it avoids having to write them on CPU during `batch_and_prepare_binned_render_phase`. This effectively reduces the number of bits that that function must write per mesh from 160 to 64 (in addition to the 64 bits per mesh *instance*). Additionally, this PR refactors `UntypedPhaseIndirectParametersBuffers` to add another layer, `MeshClassIndirectParametersBuffers`, which allows abstracting over the buffers corresponding indexed and non-indexed meshes. This patch doesn't make much use of this abstraction, but forthcoming patches will, and it's overall a cleaner approach. This didn't seem to have much of an effect by itself on `batch_and_prepare_binned_render_phase` time, but subsequent PRs dependent on this PR yield roughly a 2× speedup.
780ad40 to
bf6d8f8
Compare
superdump
reviewed
Feb 17, 2025
| /// The buffers containing all the information that indirect draw commands use | ||
| /// to draw the scene, for a single mesh class (indexed or non-indexed), for a | ||
| /// single phase. | ||
| pub struct MeshClassIndirectParametersBuffers<IP> |
Contributor
There was a problem hiding this comment.
While I'm not super keen on the word 'class', I don't have a better suggestion. I like how much gets ripped out of this.
superdump
approved these changes
Feb 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The GPU can fill out many of the fields in
IndirectParametersMetadatausing information it already has:early_instance_countandlate_instance_countare always initialized to zero.mesh_indexis already present in the work item buffer as theinput_indexof the first work item in each batch.This patch moves these fields to a separate buffer, the GPU indirect parameters metadata buffer. That way, it avoids having to write them on CPU during
batch_and_prepare_binned_render_phase. This effectively reduces the number of bits that that function must write per mesh from 160 to 64 (in addition to the 64 bits per mesh instance).Additionally, this PR refactors
UntypedPhaseIndirectParametersBuffersto add another layer,MeshClassIndirectParametersBuffers, which allows abstracting over the buffers corresponding indexed and non-indexed meshes. This patch doesn't make much use of this abstraction, but forthcoming patches will, and it's overall a cleaner approach.This didn't seem to have much of an effect by itself on
batch_and_prepare_binned_render_phasetime, but subsequent PRs dependent on this PR yield roughly a 2× speedup.