Skip to content

Commit

Permalink
parallelize command encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 8, 2024
1 parent d73e90d commit 41d1a56
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 281 deletions.
20 changes: 1 addition & 19 deletions engine/src/drawables/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::GfxContext;
use std::rc::Rc;
use wgpu::RenderPass;

mod instanced_mesh;
Expand All @@ -20,7 +19,7 @@ use std::sync::Arc;

pub type IndexType = u32;

pub trait Drawable {
pub trait Drawable: Send + Sync {
fn draw<'a>(&'a self, gfx: &'a GfxContext, rp: &mut RenderPass<'a>);

#[allow(unused)]
Expand Down Expand Up @@ -50,23 +49,6 @@ impl<T: ?Sized + Drawable> Drawable for Arc<T> {
}
}

impl<T: ?Sized + Drawable> Drawable for Rc<T> {
fn draw<'a>(&'a self, gfx: &'a GfxContext, rp: &mut RenderPass<'a>) {
let s: &T = self;
s.draw(gfx, rp);
}

fn draw_depth<'a>(
&'a self,
gfx: &'a GfxContext,
rp: &mut RenderPass<'a>,
shadow_cascade: Option<&Matrix4>,
) {
let s: &T = self;
s.draw_depth(gfx, rp, shadow_cascade);
}
}

impl<T: Drawable> Drawable for Option<T> {
fn draw<'a>(&'a self, gfx: &'a GfxContext, rp: &mut RenderPass<'a>) {
if let Some(s) = self {
Expand Down
27 changes: 12 additions & 15 deletions engine/src/framework.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rayon::ThreadPoolBuilder;
use std::sync::Arc;
use std::time::Instant;

Expand Down Expand Up @@ -123,23 +124,18 @@ async fn run<S: State>(el: EventLoop<()>, window: Arc<Window>) {
state.update(&mut ctx);

let (mut enc, view) = ctx.gfx.start_frame(&sco);
ctx.engine_time = ctx
(ctx.engine_time, ctx.gui_time) = ctx
.gfx
.render_objs(&mut enc, &view, |fc| state.render(fc))
.as_secs_f32();

let gui_start = Instant::now();
#[allow(unused_mut)]
ctx.gfx.render_gui(&mut enc, &view, |mut gctx| {
#[cfg(feature = "yakui")]
ctx.yakui.render(&mut gctx, || {
state.render_yakui();
});
ctx.egui.render(gctx, |ui| {
state.render_gui(ui);
.render(&mut enc, &view, &mut state, |state, mut gctx| {
#[cfg(feature = "yakui")]
ctx.yakui.render(&mut gctx, || {
state.render_yakui();
});
ctx.egui.render(gctx, |ui| {
state.render_gui(ui);
});
});
});
ctx.gui_time = gui_start.elapsed().as_secs_f32();

ctx.gfx.finish_frame(enc);
ctx.gfx.window.set_cursor_icon(get_cursor_icon());
ctx.input.end_frame();
Expand Down Expand Up @@ -170,6 +166,7 @@ pub fn init() {
}

pub fn start<S: State>() {
let _ = ThreadPoolBuilder::new().num_threads(8).build_global();
let el = EventLoop::new().expect("Failed to create event loop");

#[cfg(target_arch = "wasm32")]
Expand Down
Loading

0 comments on commit 41d1a56

Please sign in to comment.