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 other plugins to create renderer resources #9632

Closed
wants to merge 0 commits into from
Closed

Allow other plugins to create renderer resources #9632

wants to merge 0 commits into from

Conversation

awtterpip
Copy link
Contributor

@awtterpip awtterpip commented Aug 29, 2023

Objective

  • Allow other plugins to create the renderer resources. An example of where this would be required is my OpenXR plugin

Solution

  • Changed the bevy RenderPlugin to optionally take precreated render resources instead of a configuration.

Migration Guide

The RenderPlugin now takes a RenderSettings enum instead of WgpuSettings. RenderSettings::default() returns RenderSettings::Automatic(WgpuSettings::default()).

// before
RenderPlugin {
    wgpu_settings: WgpuSettings {
    ...
    },
}

// now
RenderPlugin {
    render_settings: RenderSettings::Automatic(WgpuSettings {
    ...
    }),
}

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use O-XR Specific to virtual and augmented reality platforms labels Aug 29, 2023
@alice-i-cecile alice-i-cecile modified the milestones: 0.11.2, 0.12 Aug 29, 2023
Copy link
Contributor

@JMS55 JMS55 left a comment

Choose a reason for hiding this comment

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

I'm for these changes overall. It'll also make DLSS nicer when I get around to implementing that again :)

I do have some small code refactor suggestions that would be nice, if you don't mind doing them while you're here.

crates/bevy_render/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_render/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_render/src/lib.rs Outdated Show resolved Hide resolved
@JMS55 JMS55 requested a review from alice-i-cecile September 1, 2023 05:06
@alice-i-cecile alice-i-cecile 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 Sep 8, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I think we can and should make the API better, by swapping to a "field on RenderPlugin" strategy.

More importantly though, the extracted function needs to be unsafe.

@awtterpip awtterpip closed this Sep 8, 2023
@awtterpip awtterpip reopened this Sep 8, 2023
@awtterpip awtterpip closed this Sep 8, 2023
@awtterpip
Copy link
Contributor Author

i believe i have implemented a better way to accomplish this

@awtterpip awtterpip reopened this Sep 8, 2023
crates/bevy_render/src/lib.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Sep 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@alice-i-cecile
Copy link
Member

I like the new initialization pattern a lot! Once there's a simple migration guide plus a SAFETY comment, this LGTM.

@awtterpip
Copy link
Contributor Author

where should i write the migration guide?

@paul-hansen
Copy link
Contributor

paul-hansen commented Sep 8, 2023

It goes in the PR description, here's an example from one of mine: #9516

The migration guides get created from a script that scrapes these from the PRs so make sure the header is exact. E.g.

## Migration Guide

Instructions for migrating code that will break

@mockersf mockersf requested review from mockersf and JMS55 September 8, 2023 23:31
@mockersf mockersf removed 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 Sep 8, 2023
@mockersf mockersf self-requested a review September 8, 2023 23:35
@superdump superdump self-requested a review September 9, 2023 05:43
@superdump
Copy link
Contributor

I want to carefully review this before it is merged. What is the reason for needing to provide the ‘future render resources’ from outside bevy? What configurability is missing?

@awtterpip
Copy link
Contributor Author

@superdump so the solution ended up actually changing. originally, i made FutureRendererResources a public struct, and i made the RenderPlugin skip creating the render resources if this already existed, this would allow other plugins to create these resources themselves. however, the solution has changed to making the RenderPlugin be able to take precreated render resources to prevent the resources being able to be edited at runtime. An example of where this would be needed is my openxr plugin for bevy. openxr has a very specific process to initalize render resources, requiring me to make these resources myself and then give them to the bevy RenderPlugin

@JMS55
Copy link
Contributor

JMS55 commented Sep 9, 2023

What is the reason for needing to provide the ‘future render resources’ from outside bevy? What configurability is missing?

It's mainly for importing rendering resources from outside of bevy. For instance, with XR, you have a specific vulkan resource, that you then map to a wgpu resource in a specific manner. For DLSS, I needed to use raw vulkan to load some extra nvidia-dlss-only extensions (so, stuff wgpu would never get) as part of device creation, and then create a wgpu device wrapping it.

It's the kind of stuff bevy_render is never going to handle itself, for very specific platforms with custom rendering devices.

@awtterpip
Copy link
Contributor Author

i believe that is a satisfactory migration guide. if it needs improving please let me know

@patchedsoul
Copy link

Is there anything else holding this up now?

@alice-i-cecile
Copy link
Member

Waiting on final review from @superdump :) It's in the 0.12 milestone, so it will be considered.

RenderQueue,
RenderAdapterInfo,
RenderAdapter,
Mutex<Instance>,
Copy link
Member

Choose a reason for hiding this comment

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

the mutex here is to allow interior mutability, which breaks the assumption that setting up a plugin doesn't mutate it

Copy link

@TheButlah TheButlah Sep 20, 2023

Choose a reason for hiding this comment

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

(Not a bevy maintainer): from what I could tell, all methods on wgpu::Instance are on a shared ref, and the type is Send and Sync. Is there a reason that cloning a Arc<wgpu::Instance> cannot be used instead of taking from a Mutex<Instance>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mockersf my most recent commit should have fixed this. i implemented what @TheButlah recommended

@awtterpip
Copy link
Contributor Author

i had to rebuild my pr since i was having some merge conflicts and forgot to make a new branch when i started making this pr, however, github won't let me reopen this PR without the original branch, so i had to create a duplicate of this pr here: #9925

github-merge-queue bot pushed a commit that referenced this pull request Sep 26, 2023
This is a duplicate of #9632, it was created since I forgot to make a
new branch when I first made this PR, so I was having trouble resolving
merge conflicts, meaning I had to rebuild my PR.

# Objective

- Allow other plugins to create the renderer resources. An example of
where this would be required is my [OpenXR
plugin](https://github.com/awtterpip/bevy_openxr)

## Solution

- Changed the bevy RenderPlugin to optionally take precreated render
resources instead of a configuration.

## Migration Guide

The `RenderPlugin` now takes a `RenderCreation` enum instead of
`WgpuSettings`. `RenderSettings::default()` returns
`RenderSettings::Automatic(WgpuSettings::default())`. `RenderSettings`
also implements `From<WgpuSettings>`.

```rust
// before
RenderPlugin {
    wgpu_settings: WgpuSettings {
    ...
    },
}

// now
RenderPlugin {
    render_creation: RenderCreation::Automatic(WgpuSettings {
    ...
    }),
}
// or
RenderPlugin {
    render_creation: WgpuSettings {
    ...
    }.into(),
}
```

---------

Co-authored-by: Malek <[email protected]>
Co-authored-by: Robert Swain <[email protected]>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
This is a duplicate of bevyengine#9632, it was created since I forgot to make a
new branch when I first made this PR, so I was having trouble resolving
merge conflicts, meaning I had to rebuild my PR.

# Objective

- Allow other plugins to create the renderer resources. An example of
where this would be required is my [OpenXR
plugin](https://github.com/awtterpip/bevy_openxr)

## Solution

- Changed the bevy RenderPlugin to optionally take precreated render
resources instead of a configuration.

## Migration Guide

The `RenderPlugin` now takes a `RenderCreation` enum instead of
`WgpuSettings`. `RenderSettings::default()` returns
`RenderSettings::Automatic(WgpuSettings::default())`. `RenderSettings`
also implements `From<WgpuSettings>`.

```rust
// before
RenderPlugin {
    wgpu_settings: WgpuSettings {
    ...
    },
}

// now
RenderPlugin {
    render_creation: RenderCreation::Automatic(WgpuSettings {
    ...
    }),
}
// or
RenderPlugin {
    render_creation: WgpuSettings {
    ...
    }.into(),
}
```

---------

Co-authored-by: Malek <[email protected]>
Co-authored-by: Robert Swain <[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-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide O-XR Specific to virtual and augmented reality platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants