Skip to content

Conversation

@robtfm
Copy link
Contributor

@robtfm robtfm commented Mar 20, 2024

Objective

make morph targets and tonemapping more tolerant of delayed image loading.

neither of these actually fail currently unless using a bespoke loader (and even then it would be rare), but i am working on adding throttling for asset gpu uploads (as a stopgap until we can do proper asset streaming) and they break with that.

Solution

when a mesh with morph targets is uploaded to the gpu, the prepare function uploads the morph target texture if it's available, otherwise it uploads without morph targets. this is generally fine as long as morph targets are typically loaded from bytes (in gltf loader), but may fail for a custom loader if the asset server async-loads the target texture and the texture is not available yet. the mesh fails to render and doesn't update when the image is loaded
-> if morph targets are specified but not ready yet, retry mesh upload next frame

tonemapping unwraps on the lookup table image. this is never a problem since the image is added via include_bytes!, but could be a problem in future with asset gpu throttling/streaming.
-> if the lookup texture is not yet available, use a fallback
-> in the node, check if the fallback was used before caching the bind group

@robtfm robtfm added A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change labels Mar 20, 2024
@robtfm robtfm mentioned this pull request Mar 21, 2024
@james7132 james7132 requested a review from superdump March 23, 2024 02:40
@JMS55 JMS55 added this to the 0.14 milestone Mar 30, 2024
@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 7, 2024
@superdump superdump added this pull request to the merge queue Apr 7, 2024
Merged via the queue into bevyengine:main with commit 452821d Apr 7, 2024
github-merge-queue bot pushed a commit that referenced this pull request Apr 26, 2024
# Objective

allow throttling of gpu uploads to prevent choppy framerate when many
textures/meshes are loaded in.

## Solution

- `RenderAsset`s can implement `byte_len()` which reports their size.
implemented this for `Mesh` and `Image`
- users can add a `RenderAssetBytesPerFrame` which specifies max bytes
to attempt to upload in a frame
- `render_assets::<A>` checks how many bytes have been written before
attempting to upload assets. the limit is a soft cap: assets will be
written until the total has exceeded the cap, to ensure some forward
progress every frame

notes:
- this is a stopgap until we have multiple wgpu queues for proper
streaming of data
- requires #12606

issues
- ~~fonts sometimes only partially upload. i have no clue why, needs to
be fixed~~ fixed now.
- choosing the #bytes is tricky as it should be hardware / framerate
dependent
- many features are not tested (env maps, light probes, etc) - they
won't break unless `RenderAssetBytesPerFrame` is explicitly used though

---------

Co-authored-by: IceSentry <[email protected]>
Co-authored-by: François Mockers <[email protected]>
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: Done

Development

Successfully merging this pull request may close these issues.

4 participants