-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Refactor batch_and_prepare_binned_render_phase
in preparation for bin retention.
#16922
base: main
Are you sure you want to change the base?
Conversation
retention. This commit makes the following changes: * `IndirectParametersBuffer` has been changed from a `BufferVec` to a `RawBufferVec`. This won about 20us or so on Bistro by avoiding `encase` overhead. * The methods on the `GetFullBatchData` trait no longer have the `entity` parameter, as it was unused. * `PreprocessWorkItem`, which specifies a transform-and-cull operation, now supplies the mesh instance uniform output index directly instead of having the shader look it up from the indirect draw parameters. Accordingly, the responsibility of writing the output index to the indirect draw parameters has been moved from the CPU to the GPU. This is in preparation for retained indirect instance draw commands, where the mesh instance uniform output index may change from frame to frame, while the indirect instance draw commands will be cached. We won't want the CPU to have to upload the same indirect draw parameters again and again if a batch didn't change from frame to frame. * `batch_and_prepare_binned_render_phase` and `batch_and_prepare_sorted_render_phase` now allocate indirect draw commands for an entire batch set at a time when possible, instead of one batch at a time. This change will allow us to retain the indirect draw commands for whole batch sets. * `GetFullBatchData::get_batch_indirect_parameters_index` has been replaced with `GetFullBatchData::write_batch_indirect_parameters`, which takes an offset and writes into it instead of allocating. This is necessary in order to use the optimization mentioned in the previous point. * At the WGSL level, `IndirectParameters` has been factored out into `mesh_preprocess_types.wgsl`. This is because we'll need a new compute shader that zeroes out the instance counts in preparation for a new frame. That shader will need to access `IndirectParameters`, so it was moved to a separate file. * Bins are no longer raw vectors but are instances of a separate type, `RenderBin`. This is so that the bin can eventually contain its retained batches.
// `first_vertex` in both structures. | ||
first_vertex: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment does not agree with the name or comments on the Rust struct, there it's first_vertex_or_first_index
.
// `first_instance` or `base_vertex`. | ||
first_instance_or_base_vertex: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Rust struct it's called base_vertex_or_first_instance
, both are fine but they should agree I think.
This commit makes the following changes:
IndirectParametersBuffer
has been changed from aBufferVec
to aRawBufferVec
. This won about 20us or so on Bistro by avoidingencase
overhead.The methods on the
GetFullBatchData
trait no longer have theentity
parameter, as it was unused.PreprocessWorkItem
, which specifies a transform-and-cull operation, now supplies the mesh instance uniform output index directly instead of having the shader look it up from the indirect draw parameters. Accordingly, the responsibility of writing the output index to the indirect draw parameters has been moved from the CPU to the GPU. This is in preparation for retained indirect instance draw commands, where the mesh instance uniform output index may change from frame to frame, while the indirect instance draw commands will be cached. We won't want the CPU to have to upload the same indirect draw parameters again and again if a batch didn't change from frame to frame.batch_and_prepare_binned_render_phase
andbatch_and_prepare_sorted_render_phase
now allocate indirect draw commands for an entire batch set at a time when possible, instead of one batch at a time. This change will allow us to retain the indirect draw commands for whole batch sets.GetFullBatchData::get_batch_indirect_parameters_index
has been replaced withGetFullBatchData::write_batch_indirect_parameters
, which takes an offset and writes into it instead of allocating. This is necessary in order to use the optimization mentioned in the previous point.At the WGSL level,
IndirectParameters
has been factored out intomesh_preprocess_types.wgsl
. This is because we'll need a new compute shader that zeroes out the instance counts in preparation for a new frame. That shader will need to accessIndirectParameters
, so it was moved to a separate file.Bins are no longer raw vectors but are instances of a separate type,
RenderBin
. This is so that the bin can eventually contain its retained batches.