Skip to content

RenderCreation refactor#22714

Merged
mockersf merged 11 commits intobevyengine:mainfrom
atlv24:ad/render-creation-refactor
Jan 29, 2026
Merged

RenderCreation refactor#22714
mockersf merged 11 commits intobevyengine:mainfrom
atlv24:ad/render-creation-refactor

Conversation

@atlv24
Copy link
Copy Markdown
Contributor

@atlv24 atlv24 commented Jan 26, 2026

Objective

  • work towards renderer recovery

Solution

  • make render creation reusable
  • document weird stuff thats going

Testing

  • ci

note: reviewing by commit is easier. when a big block moves its just a copy paste, the minor tweaks are separated into other commits

@atlv24 atlv24 added A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 26, 2026
@atlv24 atlv24 added the S-Needs-Testing Testing must be done before this is safe to merge label Jan 26, 2026
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Jan 26, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Thanks for the easy-to-understand commit history; I shall be incorporating your technique in my own PR’s where appropriate 🍻

@mockersf
Copy link
Copy Markdown
Member

Doesn't work in wasm, either webgl2 or webgpu.

WARN crates/bevy_render/src/lib.rs:321 No backends found, renderer will not be initialized.
wasm_example.js:1195 ERROR crates/bevy_render/src/extract_resource.rs:38 Render app did not exist when trying to add `extract_resource` for <bevy_camera::clear_color::ClearColor>.
wasm_example.js:1699 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://developer.chrome.com/blog/autoplay/#web_audio
(anonymous) @ wasm_example.js:1699
wasm_example.js:1195 WARN crates/bevy_gizmos_render/src/lib.rs:114 bevy_render feature is enabled but RenderApp was not detected. Are you sure you loaded GizmoPlugin after RenderPlugin?
wasm_example.js:1195 WARN crates/bevy_render/src/texture/mod.rs:49 CompressedImageFormatSupport resource not found. It should either be initialized in finish() of RenderPlugin, or manually if not using the RenderPlugin or the WGPU backend.
wasm_example.js:1195 WARN crates/bevy_gltf/src/lib.rs:278 CompressedImageFormatSupport resource not found. It should either be initialized in finish() of RenderPlugin, or manually if not using the RenderPlugin or the WGPU backend.
wasm_example.js:1195 INFO crates/bevy_winit/src/system.rs:68 Creating new window App (0v0)
wasm_example.js:1195 INFO crates/bevy_render/src/renderer/mod.rs:287 AdapterInfo { name: "", vendor: 0, device: 0, device_type: Other, device_pci_bus_id: "", driver: "", driver_info: "", backend: BrowserWebGpu, subgroup_min_size: 4, subgroup_max_size: 128, transient_saves_memory: false }

@atlv24 atlv24 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Jan 27, 2026
@atlv24 atlv24 force-pushed the ad/render-creation-refactor branch from 3891d05 to 24f1591 Compare January 28, 2026 02:38
@atlv24 atlv24 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 28, 2026
@atlv24 atlv24 force-pushed the ad/render-creation-refactor branch from ba46ecf to 7061787 Compare January 28, 2026 04:07
@atlv24 atlv24 removed the C-Bug An unexpected or incorrect behavior label Jan 28, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Wasm’ing an example works for me now

Unfortunate that that unintuitive ready function lives to see another day

@atlv24
Copy link
Copy Markdown
Contributor Author

atlv24 commented Jan 28, 2026

Yeah, i aim to improve it in a followup but this PR is already larger than my preferred granularity

Comment on lines +347 to +354
// This is a little tricky. `FutureRenderResources` is added in `build`, which runs synchronously before `ready`.
// It is only added if there is a wgpu backend and thus the renderer can be created.
// Hence, if we try and get the resource and it is not present, that means we are ready, because we dont need it.
// On the other hand, if the resource is present, then we try and lock on it. The lock can fail, in which case
// we currently can assume that means the `FutureRenderResources` is in the act of being populated, because
// that is the only other place the lock may be held. If it is being populated, we can assume we're ready. This
// happens via the `and_then` falling through to the same `unwrap_or(true)` case as when there's no resource.
// If the lock succeeds, we can straightforwardly check if it is populated. If it is not, then we're not ready.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome, love the docs.

@atlv24 atlv24 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 Jan 28, 2026
@mockersf
Copy link
Copy Markdown
Member

@atlv24 could you update the PR description with the most recent state?

@mockersf mockersf added this pull request to the merge queue Jan 29, 2026
Merged via the queue into bevyengine:main with commit fbb75d4 Jan 29, 2026
38 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Jan 30, 2026
# Objective

- Another step towards render recovery after #22714 and #16481
- We need RenderResource unpacking to be reusable from a non-app context

## Solution

- Make it take main and render worlds as input
- Use subapp destructure to get mutable access to both worlds
simultaneously
- Move it to live next to the struct def
- Document
- Also move shader library loads up to build because theres no reason
for them to be in finish

## Testing

- 3d_scene runs

Note: reviewing commit by commit is easier, when a large block moves its
just copy paste
@atlv24 atlv24 mentioned this pull request Feb 1, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2026
# Objective

- Recover from rendering errors.
- Another step towards render recovery after #22714 #22759 and #16481 

## Solution

- Use `wgpu::Device::set_device_lost_callback` and
`wgpu::Device::on_uncaptured_error` to listen for errors.
- Add a state machine for the renderer
- Update it on error
- Add a `RenderErrorHandler` to let users specify behavior on error by
returning a specific `RenderErrorPolicy`
- This lets us for example ignore validation errors, delete responsible
entities, or reload the renderer if the device was lost.

## Testing

- #22757 with any of
```rs
    .insert_resource(bevy_render::error_handler::RenderErrorHandler(|_, _, _| {
        bevy_render::error_handler::RenderErrorPolicy::StopRendering
    }))
```
```rs
    .insert_resource(bevy_render::error_handler::RenderErrorHandler(|_, _, _| {
        bevy_render::error_handler::RenderErrorPolicy::Recover(default())
    }))
```

Note: no release note yet, as recovery does not exactly work well: this
PR gets us to the point of being able to care about it, but we currently
instantly crash on recover due to gpu resources not existing anymore. We
need to build more resilience before publicizing imo.

---------

Co-authored-by: Kristoffer Søholm <k.soeholm@gmail.com>
github-merge-queue bot pushed a commit that referenced this pull request Mar 23, 2026
# Objective

- Completes goal and closes #23029
- Culmination of #22761, #23350, #23349, #23433, #23458, #23444, #23459,
#23461, #23463, #22714, #22759, #16481

## Solution

- Add a release note.
- Re-export a wgpu type that you need to match on to handle errors.

## Testing

- cargo run --example render_recovery with all the other PRs merged in.
Press 5 and then V, the app will not crash. Note that D for "destroy
device" will still crash: this is a WGPU problem resolved by
gfx-rs/wgpu#9281.

# Note

I opted not to change the default recovery behavior yet. I believe we
need testing in user projects and just general trodding of this code
path before committing to a new default. It works in a simple example,
it might not work in a complex project. We need to field test this and
likely iterate to really call this ready IMO.
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

- Completes goal and closes bevyengine#23029
- Culmination of bevyengine#22761, bevyengine#23350, bevyengine#23349, bevyengine#23433, bevyengine#23458, bevyengine#23444, bevyengine#23459,
bevyengine#23461, bevyengine#23463, bevyengine#22714, bevyengine#22759, bevyengine#16481

## Solution

- Add a release note.
- Re-export a wgpu type that you need to match on to handle errors.

## Testing

- cargo run --example render_recovery with all the other PRs merged in.
Press 5 and then V, the app will not crash. Note that D for "destroy
device" will still crash: this is a WGPU problem resolved by
gfx-rs/wgpu#9281.

# Note

I opted not to change the default recovery behavior yet. I believe we
need testing in user projects and just general trodding of this code
path before committing to a new default. It works in a simple example,
it might not work in a complex project. We need to field test this and
likely iterate to really call this ready IMO.
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 D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants