Skip to content

Upload every mip level and layer when updating an image in place - #26320

Merged
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
stuartparmenter:gpu-image-mip-upload
Oct 27, 2026
Merged

alice-i-cecile merged 1 commit into
bevyengine:mainfrom
stuartparmenter:gpu-image-mip-upload

Conversation

@stuartparmenter

@stuartparmenter stuartparmenter commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Objective

When an Image changes but keeps the same texture descriptor, GpuImage reuses the existing texture and writes the new data with a single write_texture call that assumes the data holds only mip 0. For images with more than one mip level:

  • Mip levels 1 and up keep the data from the first upload.
  • Array layers after the first are written from the wrong part of the data, because each layer's data also contains its mip levels.

Solution

Write each mip level and array layer separately, using the same data layout as create_texture_with_data, which handles the first upload. If the data is shorter than the texture needs, write the levels that fit and log a warning.

Testing

  • Talin tested this change and confirmed it works.
  • Rendered comparison images (see below).

Showcase

A 2-layer image with 2 mip levels is uploaded gray, then updated with a different color for each layer and mip level. Each column shows one layer and mip level. Before this PR, mip 1 keeps its old gray data, and layer 1 picks up a row of layer 0's mip 1 data. The reference row shows the same data uploaded to a new texture.

Mip and layer update comparison

AI Disclosure

This was AI assisted w/ Opus 5.5. Talin reported on Discord that uploading new data to an existing image didn't replace all of it. I used Opus to look at whether the fix belonged in asset processing or in the image upload, and we settled on the upload, since there's nothing to re-process at that point and the bug is that the new data was just being ignored. I also used Opus to build a sample app and test that render the before and after images. I then reviewed it, cleaned it up, had Talin test it, and opened PR.

@stuartparmenter stuartparmenter added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 26, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Oct 26, 2026
@IceSentry IceSentry 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 Oct 27, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Oct 27, 2026
Merged via the queue into bevyengine:main with commit 4e2eb99 Oct 27, 2026
56 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering Oct 27, 2026
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 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: Done

Development

Successfully merging this pull request may close these issues.

4 participants