Skip to content

Commit

Permalink
Discard draws when the instance/vertex/index count is zero (gfx-rs#5137)
Browse files Browse the repository at this point in the history
  • Loading branch information
nical authored Jan 25, 2024
1 parent efb35d4 commit d47534e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
20 changes: 13 additions & 7 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,12 @@ impl RenderBundleEncoder {
})
.map_pass_err(scope);
}
commands.extend(state.flush_vertices());
commands.extend(state.flush_binds(used_bind_groups, base.dynamic_offsets));
commands.push(command);

if instance_count > 0 && vertex_count > 0 {
commands.extend(state.flush_vertices());
commands.extend(state.flush_binds(used_bind_groups, base.dynamic_offsets));
commands.push(command);
}
}
RenderCommand::DrawIndexed {
index_count,
Expand Down Expand Up @@ -556,10 +559,13 @@ impl RenderBundleEncoder {
})
.map_pass_err(scope);
}
commands.extend(state.flush_index());
commands.extend(state.flush_vertices());
commands.extend(state.flush_binds(used_bind_groups, base.dynamic_offsets));
commands.push(command);

if instance_count > 0 && index_count > 0 {
commands.extend(state.flush_index());
commands.extend(state.flush_vertices());
commands.extend(state.flush_binds(used_bind_groups, base.dynamic_offsets));
commands.push(command);
}
}
RenderCommand::MultiDrawIndirect {
buffer_id,
Expand Down
25 changes: 17 additions & 8 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

unsafe {
raw.draw(first_vertex, vertex_count, first_instance, instance_count);
if instance_count > 0 && vertex_count > 0 {
raw.draw(
first_vertex,
vertex_count,
first_instance,
instance_count,
);
}
}
}
RenderCommand::DrawIndexed {
Expand Down Expand Up @@ -1972,13 +1979,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

unsafe {
raw.draw_indexed(
first_index,
index_count,
base_vertex,
first_instance,
instance_count,
);
if instance_count > 0 && index_count > 0 {
raw.draw_indexed(
first_index,
index_count,
base_vertex,
first_instance,
instance_count,
);
}
}
}
RenderCommand::MultiDrawIndirect {
Expand Down

0 comments on commit d47534e

Please sign in to comment.