From a891eb071b84ad29a246e727df479fed9d608723 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Tue, 22 Aug 2023 11:13:55 +0200 Subject: [PATCH] dont set projection bindgroup every draw call --- assets_gui/src/gui.rs | 7 +++---- engine/src/drawables/instanced_mesh.rs | 3 --- engine/src/drawables/lit_mesh.rs | 3 --- engine/src/drawables/mod.rs | 21 +++++++------------ engine/src/drawables/multispritebatch.rs | 3 +-- engine/src/drawables/spritebatch.rs | 2 +- engine/src/drawables/terrain.rs | 4 +--- engine/src/drawables/water.rs | 2 +- engine/src/gfx.rs | 9 ++++++-- .../src/rendering/map_rendering/trees.rs | 3 +-- 10 files changed, 22 insertions(+), 35 deletions(-) diff --git a/assets_gui/src/gui.rs b/assets_gui/src/gui.rs index 2f4a23df..2cde6c90 100644 --- a/assets_gui/src/gui.rs +++ b/assets_gui/src/gui.rs @@ -2,7 +2,7 @@ use egui::{Color32, Ui}; use egui_dock::{DockArea, NodeIndex, Style, TabStyle, Tree}; use engine::meshload::MeshProperties; -use engine::wgpu::{BindGroup, RenderPass}; +use engine::wgpu::RenderPass; use engine::{Drawable, GfxContext, Mesh, SpriteBatch}; use geom::Matrix4; @@ -174,12 +174,11 @@ impl Drawable for Shown { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a BindGroup, ) { match self { Shown::None | Shown::Error(_) => {} - Shown::Model((mesh, _)) => mesh.draw_depth(gfx, rp, shadow_cascade, proj), - Shown::Sprite(sprite) => sprite.draw_depth(gfx, rp, shadow_cascade, proj), + Shown::Model((mesh, _)) => mesh.draw_depth(gfx, rp, shadow_cascade), + Shown::Sprite(sprite) => sprite.draw_depth(gfx, rp, shadow_cascade), } } } diff --git a/engine/src/drawables/instanced_mesh.rs b/engine/src/drawables/instanced_mesh.rs index 386306bd..8010bd41 100644 --- a/engine/src/drawables/instanced_mesh.rs +++ b/engine/src/drawables/instanced_mesh.rs @@ -78,7 +78,6 @@ pub struct InstancedMesh { impl Drawable for InstancedMesh { fn draw<'a>(&'a self, gfx: &'a GfxContext, rp: &mut RenderPass<'a>) { - rp.set_bind_group(0, &gfx.projection.bindgroup, &[]); rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(3, &gfx.simplelit_bg, &[]); rp.set_vertex_buffer(0, self.mesh.vertex_buffer.slice(..)); @@ -104,9 +103,7 @@ impl Drawable for InstancedMesh { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { - rp.set_bind_group(0, proj, &[]); rp.set_vertex_buffer(0, self.mesh.vertex_buffer.slice(..)); rp.set_vertex_buffer(1, self.instance_buffer.slice(..)); rp.set_index_buffer(self.mesh.index_buffer.slice(..), IndexFormat::Uint32); diff --git a/engine/src/drawables/lit_mesh.rs b/engine/src/drawables/lit_mesh.rs index 6f3abca2..12531195 100644 --- a/engine/src/drawables/lit_mesh.rs +++ b/engine/src/drawables/lit_mesh.rs @@ -244,7 +244,6 @@ impl PipelineBuilder for MeshPipeline { impl Drawable for Mesh { fn draw<'a>(&'a self, gfx: &'a GfxContext, rp: &mut RenderPass<'a>) { - rp.set_bind_group(0, &gfx.projection.bindgroup, &[]); rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(3, &gfx.simplelit_bg, &[]); rp.set_vertex_buffer(0, self.vertex_buffer.slice(..)); @@ -268,12 +267,10 @@ impl Drawable for Mesh { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { if self.skip_depth { return; } - rp.set_bind_group(0, proj, &[]); rp.set_vertex_buffer(0, self.vertex_buffer.slice(..)); rp.set_index_buffer(self.index_buffer.slice(..), IndexFormat::Uint32); diff --git a/engine/src/drawables/mod.rs b/engine/src/drawables/mod.rs index 5f9a415f..e2e7226e 100644 --- a/engine/src/drawables/mod.rs +++ b/engine/src/drawables/mod.rs @@ -29,7 +29,6 @@ pub trait Drawable { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { } } @@ -45,10 +44,9 @@ impl Drawable for Arc { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { let s: &T = self; - s.draw_depth(gfx, rp, shadow_cascade, proj); + s.draw_depth(gfx, rp, shadow_cascade); } } @@ -63,10 +61,9 @@ impl Drawable for Rc { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { let s: &T = self; - s.draw_depth(gfx, rp, shadow_cascade, proj); + s.draw_depth(gfx, rp, shadow_cascade); } } @@ -82,10 +79,9 @@ impl Drawable for Option { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { if let Some(s) = self { - s.draw_depth(gfx, rp, shadow_cascade, proj); + s.draw_depth(gfx, rp, shadow_cascade); } } } @@ -102,10 +98,9 @@ impl Drawable for [T] { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { for s in self { - s.draw_depth(gfx, rp, shadow_cascade, proj); + s.draw_depth(gfx, rp, shadow_cascade); } } } @@ -122,10 +117,9 @@ impl Drawable for Vec { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { for s in self { - s.draw_depth(gfx, rp, shadow_cascade, proj); + s.draw_depth(gfx, rp, shadow_cascade); } } } @@ -141,9 +135,8 @@ impl Drawable for (T, U) { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { - self.0.draw_depth(gfx, rp, shadow_cascade, proj); - self.1.draw_depth(gfx, rp, shadow_cascade, proj); + self.0.draw_depth(gfx, rp, shadow_cascade); + self.1.draw_depth(gfx, rp, shadow_cascade); } } diff --git a/engine/src/drawables/multispritebatch.rs b/engine/src/drawables/multispritebatch.rs index eb80652a..f48d99d3 100644 --- a/engine/src/drawables/multispritebatch.rs +++ b/engine/src/drawables/multispritebatch.rs @@ -16,9 +16,8 @@ impl Drawable for MultiSpriteBatch { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { - self.sbs.draw_depth(gfx, rp, shadow_cascade, proj); + self.sbs.draw_depth(gfx, rp, shadow_cascade); } } diff --git a/engine/src/drawables/spritebatch.rs b/engine/src/drawables/spritebatch.rs index f58199e9..8728aa2a 100644 --- a/engine/src/drawables/spritebatch.rs +++ b/engine/src/drawables/spritebatch.rs @@ -151,7 +151,7 @@ impl Drawable for SpriteBatch { rp.set_pipeline(pipeline); rp.set_vertex_buffer(0, gfx.screen_uv_vertices.slice(..)); rp.set_vertex_buffer(1, self.instance_buf.slice(..)); - rp.set_bind_group(0, &gfx.projection.bindgroup, &[]); + rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(2, &gfx.material(self.material).bg, &[]); rp.set_bind_group(3, &gfx.simplelit_bg, &[]); diff --git a/engine/src/drawables/terrain.rs b/engine/src/drawables/terrain.rs index be2bc566..a01964c0 100644 --- a/engine/src/drawables/terrain.rs +++ b/engine/src/drawables/terrain.rs @@ -421,7 +421,7 @@ impl Drawable for TerrainPrepared { }); rp.set_pipeline(pipeline); - rp.set_bind_group(0, &gfx.projection.bindgroup, &[]); + rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(2, &self.terrainbg, &[]); rp.set_bind_group(3, &gfx.simplelit_bg, &[]); @@ -434,7 +434,6 @@ impl Drawable for TerrainPrepared { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a wgpu::BindGroup, ) { if shadow_cascade.is_some() { return; @@ -443,7 +442,6 @@ impl Drawable for TerrainPrepared { depth: true, smap: false, })); - rp.set_bind_group(0, proj, &[]); rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(2, &self.terrainbg, &[]); diff --git a/engine/src/drawables/water.rs b/engine/src/drawables/water.rs index 6239bcab..79f82847 100644 --- a/engine/src/drawables/water.rs +++ b/engine/src/drawables/water.rs @@ -95,7 +95,7 @@ impl Drawable for Water { let pipeline = gfx.get_pipeline(WaterPipeline); rp.set_pipeline(pipeline); - rp.set_bind_group(0, &gfx.projection.bindgroup, &[]); + rp.set_bind_group(1, &gfx.render_params.bindgroup, &[]); rp.set_bind_group(2, &gfx.fbos.depth_bg, &[]); rp.set_bind_group(3, &self.wavy_bg, &[]); diff --git a/engine/src/gfx.rs b/engine/src/gfx.rs index 393271f0..b526740b 100644 --- a/engine/src/gfx.rs +++ b/engine/src/gfx.rs @@ -517,8 +517,10 @@ impl GfxContext { }), }); + depth_prepass.set_bind_group(0, &self.projection.bindgroup, &[]); + for obj in objsref.iter() { - obj.draw_depth(self, &mut depth_prepass, None, &self.projection.bindgroup); + obj.draw_depth(self, &mut depth_prepass, None); } drop(depth_prepass); *enc_dep_ext = Some(prepass.finish()); @@ -557,8 +559,10 @@ impl GfxContext { }), }); + sun_shadow_pass.set_bind_group(0, &u.bindgroup, &[]); + for obj in objsref.iter() { - obj.draw_depth(self, &mut sun_shadow_pass, Some(u.value()), &u.bindgroup); + obj.draw_depth(self, &mut sun_shadow_pass, Some(u.value())); } } *enc_smap_ext = Some(smap_enc.finish()); @@ -621,6 +625,7 @@ impl GfxContext { stencil_ops: None, }), }); + render_pass.set_bind_group(0, &self.projection.bindgroup, &[]); for obj in objsref.iter() { obj.draw(self, &mut render_pass); diff --git a/native_app/src/rendering/map_rendering/trees.rs b/native_app/src/rendering/map_rendering/trees.rs index d7943a4a..911950f9 100644 --- a/native_app/src/rendering/map_rendering/trees.rs +++ b/native_app/src/rendering/map_rendering/trees.rs @@ -74,7 +74,6 @@ impl TreesRender { gfx: &'a GfxContext, rp: &mut RenderPass<'a>, shadow_cascade: Option<&Matrix4>, - proj: &'a engine::wgpu::BindGroup, ) { if let Some(v) = shadow_cascade { let pos = v.mul(self.1.w(1.0)); @@ -94,7 +93,7 @@ impl TreesRender { return; } } - self.0.draw_depth(gfx, rp, shadow_cascade, proj); + self.0.draw_depth(gfx, rp, shadow_cascade); } }