Skip to content

Make TrackedRenderPass::set_vertex_buffer aware of slice size#14916

Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom
akimakinai:fix_set_vertex_buffer
Aug 28, 2024
Merged

Make TrackedRenderPass::set_vertex_buffer aware of slice size#14916
alice-i-cecile merged 4 commits intobevyengine:mainfrom
akimakinai:fix_set_vertex_buffer

Conversation

@akimakinai
Copy link
Contributor

Objective

Solution

  • Compute BufferSlice size manually and use it for comparison in TrackedRenderPass

Testing


Migration Guide

  • TrackedRenderPass::set_vertex_buffer function has been modified to update vertex buffers when the same buffer with the same offset is provided, but its size has changed. Some existing code may rely on the previous behavior, which did not update the vertex buffer in this scenario.

@akimakinai akimakinai changed the title Fix set vertex buffer Make TrackedRenderPass::set_vertex_buffer aware of slice size Aug 25, 2024
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 25, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Aug 25, 2024
@akimakinai akimakinai force-pushed the fix_set_vertex_buffer branch from b51d3df to 1508cf0 Compare August 25, 2024 15:13
@akimakinai
Copy link
Contributor Author

Rebased and removed workaround added in #14721.

Copy link
Member

@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 good to me. Wish this code was easier to test. The previous assumption was obviously that an immutable slice itself can't change, but didn't anticipate slicing the same part of the buffer differently. Thanks for tracking this down!


impl DrawState {
/// Marks the `pipeline` as bound.
pub fn set_pipeline(&mut self, pipeline: RenderPipelineId) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a note to other reviewers, it seems like this was a CI suggestion, and makes sense because DrawState is itself private to TrackedRenderPass.

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Looks good, just a small note around helper documentation.

Co-authored-by: Zachary Harrold <zac@harrold.com.au>
@tychedelia tychedelia 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 Aug 28, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 28, 2024
@alice-i-cecile alice-i-cecile added the A-Gizmos Visual editor and debug gizmos label Aug 28, 2024
Merged via the queue into bevyengine:main with commit 4648f7b Aug 28, 2024
@akimakinai akimakinai deleted the fix_set_vertex_buffer branch August 30, 2024 01:11
github-merge-queue bot pushed a commit that referenced this pull request Sep 30, 2025
…20468)

# Objective

- `offset` argument is misleading as the argument is not actually passed
to wgpu (used only for memoization and logging). `BufferSlice` already
contains an offset.
- wgpu's `set_index_buffer` [sets the offset according to
BufferSlice::offset](https://github.com/gfx-rs/wgpu/blob/e990388af98e4b4dff9f7fcc09a4eb5d2f71d227/wgpu/src/api/render_pass.rs#L98-L105)
- `TrackedRenderPass::set_vertex_buffer` was made aware of slice size
(#14916) but missed `set_index_buffer` counterpart

## Solution

- Removed `offset` argument from `TrackedRenderPass::set_index_buffer`
- Apply fix from #14916 to `TrackedRenderPass::is_index_buffer_set`
- ~~Cleanup code by using the newly added `BufferSlice` getters~~ split
out to #21289

## Testing

- Ran a few examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Gizmos Visual editor and debug gizmos A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide 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.

TrackedRenderPass::set_vertex_buffer does not update if the size of sliced buffer changed

4 participants