Skip to content

Commit

Permalink
dont set projection bindgroup every draw call
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 22, 2023
1 parent b7e401d commit a891eb0
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 35 deletions.
7 changes: 3 additions & 4 deletions assets_gui/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
}
}
}
3 changes: 0 additions & 3 deletions engine/src/drawables/instanced_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..));
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions engine/src/drawables/lit_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..));
Expand All @@ -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);

Expand Down
21 changes: 7 additions & 14 deletions engine/src/drawables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub trait Drawable {
gfx: &'a GfxContext,
rp: &mut RenderPass<'a>,
shadow_cascade: Option<&Matrix4>,
proj: &'a wgpu::BindGroup,
) {
}
}
Expand All @@ -45,10 +44,9 @@ impl<T: ?Sized + Drawable> Drawable for Arc<T> {
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);
}
}

Expand All @@ -63,10 +61,9 @@ impl<T: ?Sized + Drawable> Drawable for Rc<T> {
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);
}
}

Expand All @@ -82,10 +79,9 @@ impl<T: Drawable> Drawable for Option<T> {
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);
}
}
}
Expand All @@ -102,10 +98,9 @@ impl<T: Drawable> 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);
}
}
}
Expand All @@ -122,10 +117,9 @@ impl<T: Drawable> Drawable for Vec<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);
}
}
}
Expand All @@ -141,9 +135,8 @@ impl<T: Drawable, U: Drawable> 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);
}
}
3 changes: 1 addition & 2 deletions engine/src/drawables/multispritebatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/drawables/spritebatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &[]);
Expand Down
4 changes: 1 addition & 3 deletions engine/src/drawables/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &[]);
Expand All @@ -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;
Expand All @@ -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, &[]);

Expand Down
2 changes: 1 addition & 1 deletion engine/src/drawables/water.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &[]);
Expand Down
9 changes: 7 additions & 2 deletions engine/src/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions native_app/src/rendering/map_rendering/trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -94,7 +93,7 @@ impl TreesRender {
return;
}
}
self.0.draw_depth(gfx, rp, shadow_cascade, proj);
self.0.draw_depth(gfx, rp, shadow_cascade);
}
}

Expand Down

0 comments on commit a891eb0

Please sign in to comment.