Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pcwalton
Copy link
Contributor

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.

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.
@pcwalton pcwalton added C-Code-Quality A section of code that is hard to understand or change A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 21, 2024
@pcwalton pcwalton added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants