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

Allow phase items not associated with meshes to be binned. #14029

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

pcwalton
Copy link
Contributor

As reported in #14004, many third-party plugins, such as Hanabi, enqueue entities that don't have meshes into render phases. However, the introduction of indirect mode added a dependency on mesh-specific data, breaking this workflow. This is because GPU preprocessing requires that the render phases manage indirect draw parameters, which don't apply to objects that aren't meshes. The existing code skips over binned entities that don't have indirect draw parameters, which causes the rendering to be skipped for such objects.

To support this workflow, this commit adds a new field, non_mesh_items, to BinnedRenderPhase. This field contains a simple list of (bin key, entity) pairs. After drawing batchable and unbatchable objects, the non-mesh items are drawn one after another. Bevy itself doesn't enqueue any items into this list; it exists solely for the application and/or plugins to use.

Additionally, this commit switches the asset ID in the standard bin keys to be an untyped asset ID rather than that of a mesh. This allows more flexibility, allowing bins to be keyed off any type of asset.

This patch adds a new example, custom_phase_item, which simultaneously serves to demonstrate how to use this new feature and to act as a regression test so this doesn't break again.

Fixes #14004.

Changelog

Added

  • BinnedRenderPhase now contains a non_mesh_items field for plugins to add custom items to.

@pcwalton pcwalton added this to the 0.14 milestone Jun 26, 2024
@pcwalton pcwalton added C-Bug An unexpected or incorrect behavior C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen P-Regression Functionality that used to work but no longer does. Add a test for this! labels Jun 26, 2024
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jun 26, 2024
As reported in bevyengine#14004, many third-party plugins, such as Hanabi, enqueue
entities that don't have meshes into render phases. However, the
introduction of indirect mode added a dependency on mesh-specific data,
breaking this workflow. This is because GPU preprocessing requires that
the render phases manage indirect draw parameters, which don't apply to
objects that aren't meshes. The existing code skips over binned entities
that don't have indirect draw parameters, which causes the rendering to
be skipped for such objects.

To support this workflow, this commit adds a new field,
`non_mesh_items`, to `BinnedRenderPhase`.  This field contains a simple
list of (bin key, entity) pairs. After drawing batchable and unbatchable
objects, the non-mesh items are drawn one after another. Bevy itself
doesn't enqueue any items into this list; it exists solely for the
application and/or plugins to use.

Additionally, this commit switches the asset ID in the standard bin keys
to be an untyped asset ID rather than that of a mesh. This allows more
flexibility, allowing bins to be keyed off any type of asset.

This patch adds a new example, `custom_phase_item`, which simultaneously
serves to demonstrate how to use this new feature and to act as a
regression test so this doesn't break again.

Fixes bevyengine#14004.
Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done any testing yet, but the code and overall approach looks good. I'll do some testing tomorrow to make sure it didn't break anything unexpected.

Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, ty! Just some nits on the example. Just one request: could you also try to add visibility logic with check_visibility for the non-mesh? It would be great to document this in the examples as it's another gotcha.

examples/shader/custom_phase_item.rs Outdated Show resolved Hide resolved
examples/shader/custom_phase_item.rs Outdated Show resolved Hide resolved
examples/shader/custom_phase_item.rs Outdated Show resolved Hide resolved
@superdump
Copy link
Contributor

Before reviewing, the only thing that comes to mind is - can asset ids of different types collide when compared as untyped asset ids? I think they can. In that case, I think keying on both mesh assets and other assets could cause such items to be binned together when they shouldn’t be?

@pcwalton
Copy link
Contributor Author

@superdump I modified the PartialOrd impl on UntypedAssetId to address this.

@pcwalton
Copy link
Contributor Author

Review comments addressed.

@djeedai
Copy link
Contributor

djeedai commented Jun 26, 2024

I'll look later but the Changelog looks wrong, again BinnedRenderPhase didn't exist in 0.13 so we can't reference it. I think it would make more sense to collate with the release notes and Changelog of the original feature adding bin/sort phases.

@alice-i-cecile alice-i-cecile 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 Jun 26, 2024
@pcwalton
Copy link
Contributor Author

The problem is there's no way in the pull request message to apply a patch to an existing changelog entry. I could delete the changelog entry if you want.

@tychedelia
Copy link
Contributor

tychedelia commented Jun 26, 2024

Tbh, I think having the incremental change log is helpful for developers who build off main. I've identified and upgrading things myself this way in between release cycles. Perhaps we just need to disambiguate change fields better.

crates/bevy_core_pipeline/src/core_3d/mod.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jun 26, 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-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 26, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 27, 2024
Merged via the queue into bevyengine:main with commit 44db8b7 Jun 27, 2024
32 checks passed
mockersf pushed a commit that referenced this pull request Jun 27, 2024
As reported in #14004, many third-party plugins, such as Hanabi, enqueue
entities that don't have meshes into render phases. However, the
introduction of indirect mode added a dependency on mesh-specific data,
breaking this workflow. This is because GPU preprocessing requires that
the render phases manage indirect draw parameters, which don't apply to
objects that aren't meshes. The existing code skips over binned entities
that don't have indirect draw parameters, which causes the rendering to
be skipped for such objects.

To support this workflow, this commit adds a new field,
`non_mesh_items`, to `BinnedRenderPhase`. This field contains a simple
list of (bin key, entity) pairs. After drawing batchable and unbatchable
objects, the non-mesh items are drawn one after another. Bevy itself
doesn't enqueue any items into this list; it exists solely for the
application and/or plugins to use.

Additionally, this commit switches the asset ID in the standard bin keys
to be an untyped asset ID rather than that of a mesh. This allows more
flexibility, allowing bins to be keyed off any type of asset.

This patch adds a new example, `custom_phase_item`, which simultaneously
serves to demonstrate how to use this new feature and to act as a
regression test so this doesn't break again.

Fixes #14004.

## Changelog

### Added

* `BinnedRenderPhase` now contains a `non_mesh_items` field for plugins
to add custom items to.
zmbush pushed a commit to zmbush/bevy that referenced this pull request Jul 3, 2024
…e#14029)

As reported in bevyengine#14004, many third-party plugins, such as Hanabi, enqueue
entities that don't have meshes into render phases. However, the
introduction of indirect mode added a dependency on mesh-specific data,
breaking this workflow. This is because GPU preprocessing requires that
the render phases manage indirect draw parameters, which don't apply to
objects that aren't meshes. The existing code skips over binned entities
that don't have indirect draw parameters, which causes the rendering to
be skipped for such objects.

To support this workflow, this commit adds a new field,
`non_mesh_items`, to `BinnedRenderPhase`. This field contains a simple
list of (bin key, entity) pairs. After drawing batchable and unbatchable
objects, the non-mesh items are drawn one after another. Bevy itself
doesn't enqueue any items into this list; it exists solely for the
application and/or plugins to use.

Additionally, this commit switches the asset ID in the standard bin keys
to be an untyped asset ID rather than that of a mesh. This allows more
flexibility, allowing bins to be keyed off any type of asset.

This patch adds a new example, `custom_phase_item`, which simultaneously
serves to demonstrate how to use this new feature and to act as a
regression test so this doesn't break again.

Fixes bevyengine#14004.

## Changelog

### Added

* `BinnedRenderPhase` now contains a `non_mesh_items` field for plugins
to add custom items to.
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-Bug An unexpected or incorrect behavior C-Feature A new feature, making something new possible P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't upgrade to 0.14, impossible to render AlphaMask3d phase items without mesh
6 participants