You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm learning wgpu and at some point came to an idea to make a single generalized "launcher" to render all my wgpu stuff.
Initially, I wanted to utilize a single render pass to render in it, but it turned into a nightmare.
I made a method like this:
The idea is simple, I take this method and render what I want inside it. It looks something like this:
fn main(){
let launcher.new();
let canvas = canvas.new();
let ui = ui.new();
let cube = cube.new();
event_loop.run(move |event, ...|{
...
launcher.render(|rpass| {
canvas.draw(rpass);
ui.draw(rpass);
cube.draw(rpass);
});
}
})
But after I did the implementation and tried to launch, everything was just ruined by a lifetime on the wgpu::RenderPass. The compiler errors that my canvas/ui/cube must outlive rpass (which by the logic they already do but compiler still errors). Then because my whole event loop must outlive 'static because it takes ownership of canvas/ui/cube... At this point I gave up, I don't know how to fix this mess anymore.
I changed .draw() method to accept &mut wgpu::CommandEncoder and &wgpu::TextureView instead of &'a mut wgpu::RenderPass and create render passes inside every .draw(). Now this finally works.
My question is, is it okay performance wise to create many render passes like this? At least they render unrelated to each other pieces.
I'd like to go back to rendering everything in a single render pass, but the lifetime made it unbearable (at least for me as a beginner).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I'm learning wgpu and at some point came to an idea to make a single generalized "launcher" to render all my wgpu stuff.
Initially, I wanted to utilize a single render pass to render in it, but it turned into a nightmare.
I made a method like this:
The idea is simple, I take this method and render what I want inside it. It looks something like this:
But after I did the implementation and tried to launch, everything was just ruined by a lifetime on the
wgpu::RenderPass
. The compiler errors that my canvas/ui/cube must outlive rpass (which by the logic they already do but compiler still errors). Then because my whole event loop must outlive'static
because it takes ownership of canvas/ui/cube... At this point I gave up, I don't know how to fix this mess anymore.I changed
.draw()
method to accept&mut wgpu::CommandEncoder
and&wgpu::TextureView
instead of&'a mut wgpu::RenderPass
and create render passes inside every.draw()
. Now this finally works.My question is, is it okay performance wise to create many render passes like this? At least they render unrelated to each other pieces.
I'd like to go back to rendering everything in a single render pass, but the lifetime made it unbearable (at least for me as a beginner).
Beta Was this translation helpful? Give feedback.
All reactions