-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
Experimental support for integration with existing wgpu
apps.
#221
Conversation
@JMS55 wdyt? Would this solve your original need? I don't have an example for using the new builder method, but the code seems like it should work as expected. |
I completely forget what my original issue is tbh. Pixels has been working well for me ever since I'm also very busy the next few days - I'll review sometime next week (probably). |
Completely understandable! I'm in no rush with this one. Just want to start working toward #117. Just some additional context that might help your memory: One of the pseudo-goals here is to promote |
Code itself looks good. One nit: instead of separate build methods, perhaps it's better to make those builder methods, and then have only one build function? Not convinced either way. Maybe we just need different names for the functions that are more clear that you have to provide the wgpu stuff yourself, since However I have some concerns with the overall idea. Is there any need to continue to have pixels borrow the wgpu stuff? As far as I see it, there's 3 scenarios:
Right now 1. and 2. are in a good state. This PR is for adding support for 3. But I'm not sure it makes sense to continue to have pixels borrow wgpu state and be in charge of things (when it comes to supporting 3). It seems weird that for the case where pixels is a small part of your overall program, you have to give it a permanent reference to your wgpu structs, and structure your code around it, instead of just passing it things as needed. What do you think of splitting things into a pure (no state) library, and another library that wraps the previous one and sets up all the wgpu[1] state for you? We could call them [1] Potentially also winit, like we discussed in the webgl PR. An additional concern: Is there any current demand for 3? My original use case was just UI/post-processing I believe, which pixels currently covers well. I'm concerned about making major changes if we have no way to test whether it's a good fit or not. |
Awesome review! Thanks for looking at this.
I put together the following API from this suggestion. It replaces the second build method with an optional builder method to borrow Click to expand...impl<'wgpu, ..> PixelsBuilder<'wgpu, ..> {
/// Borrow the given `wgpu` state.
///
/// [`Pixels`] owns `wgpu` state by default. This method allows it to borrow state. Use this
/// when integrating `pixels` into an application that already uses `wgpu`.
///
/// Note that the following builder methods will become no-ops after this method is called:
///
/// - [`PixelsBuilder::request_adapter_options`]
/// - [`PixelsBuilder::device_descriptor`]
/// - [`PixelsBuilder::wgpu_backend`]
pub fn with_borrowed_wgpu(
mut self,
surface: &'wgpu wgpu::Surface,
adapter: &'wgpu wgpu::Adapter,
device: &'wgpu wgpu::Device,
queue: &'wgpu wgpu::Queue,
) -> Self;
/// Create a pixel buffer from the options builder.
///
/// # Errors
///
/// Returns an error when a [`wgpu::Adapter`] or [`wgpu::Device`] cannot be found.
pub fn build(mut self) -> Result<Pixels<'wgpu>, Error>;
} It wasn't too hard to refactor the code for this. (Gotta love Rust!)
I agree with the overall sentiment. It does seem weird that
Yes! I think this is a much cleaner design. It looks like the "Internal Render Data" middleware API roughly maps to ours. But instead of a
I'm all for creating another higher-level crate to manage
None at the moment. One of my other projects is a level editor for an old SNES game, so I also received a question today asking how to account for the size of UI elements like the menubar in the |
- Also simplify the return values in builder methods
Just tried the Closing all of these for now. |
This has a few unavoidable breaking changes. The first is that the closure provided by
Pixels::render_with()
no longer accepts a reference toPixelsContext
, but an owned copy of one.PixelsContext
is now a view of the poorly namedPixelsInternalContext
(which is what now owns or borrows the top-levelwgpu
state).The second breaking change is related to the first:
Pixels::context()
now returns an ownedPixelsContext
. This was ultimately the reason that the closure signature had to change, since this method cannot return a reference to aPixelsContext
view borrowed from the stack. The closure signature was changed for consistency.There are now three ways to build a
Pixels
instance:Pixels::new()
remains unchanged. Simply callsPixelsBuilder::build()
.PixelsBuilder::build()
remains unchanged. Creates aPixels
instance that owns the top-levelwgpu
state.PixelsBuilder::build_with_wgpu()
is new, and allowsPixels
to borrow existing top-levelwgpu
state. See Render-api-v2 further enhancements #107 for details.This PR needs an example before it's ready to merge.