Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-08-29 15:19:59 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-08-29 15:19:59 +0300
commit299542545458e5a1fd6e3765567c75d680ee8697 (patch)
treeb67f14cc72ffe609994b4e800109654f9fda365e
parent048ca79b326dc1d81057e43d9d4674b654a45af9 (diff)
Bypass drawing batches with 0 vertex
-rw-r--r--source/blender/draw/intern/draw_command.cc35
-rw-r--r--source/blender/draw/intern/shaders/draw_command_generate_comp.glsl6
-rw-r--r--source/blender/gpu/GPU_batch.h4
3 files changed, 22 insertions, 23 deletions
diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc
index b531f3f9e29..5e75d7c8e49 100644
--- a/source/blender/draw/intern/draw_command.cc
+++ b/source/blender/draw/intern/draw_command.cc
@@ -85,26 +85,28 @@ void DrawMulti::execute(RecordingState &state) const
uint group_index = this->group_first;
while (group_index != (uint)-1) {
- const DrawGroup &grp = groups[group_index];
+ const DrawGroup &group = groups[group_index];
- GPU_batch_set_shader(grp.gpu_batch, state.shader);
+ if (group.vertex_len > 0) {
+ GPU_batch_set_shader(group.gpu_batch, state.shader);
- constexpr intptr_t stride = sizeof(DrawCommand);
- /* We have 2 indirect command reserved per draw group. */
- intptr_t offset = stride * group_index * 2;
+ constexpr intptr_t stride = sizeof(DrawCommand);
+ /* We have 2 indirect command reserved per draw group. */
+ intptr_t offset = stride * group_index * 2;
- /* Draw negatively scaled geometry first. */
- if (grp.len - grp.front_facing_len > 0) {
- state.front_facing_set(true);
- GPU_batch_draw_indirect(grp.gpu_batch, indirect_buf, offset);
- }
+ /* Draw negatively scaled geometry first. */
+ if (group.len - group.front_facing_len > 0) {
+ state.front_facing_set(true);
+ GPU_batch_draw_indirect(group.gpu_batch, indirect_buf, offset);
+ }
- if (grp.front_facing_len > 0) {
- state.front_facing_set(false);
- GPU_batch_draw_indirect(grp.gpu_batch, indirect_buf, offset + stride);
+ if (group.front_facing_len > 0) {
+ state.front_facing_set(false);
+ GPU_batch_draw_indirect(group.gpu_batch, indirect_buf, offset + stride);
+ }
}
- group_index = grp.next;
+ group_index = group.next;
}
}
@@ -546,11 +548,6 @@ void DrawMultiBuf::bind(RecordingState &state,
&group.base_index,
&batch_inst_len);
- /* Tag group as using index draw (changes indirect draw call structure). */
- if (group.gpu_batch->elem != nullptr) {
- group.base_index = -1;
- }
-
/* Instancing attributes are not supported using the new pipeline since we use the base
* instance to set the correct resource_id. Workaround is a storage_buf + gl_InstanceID. */
BLI_assert(batch_inst_len == 1);
diff --git a/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl b/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl
index e1aeb08410e..d166a2fe9a1 100644
--- a/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl
+++ b/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl
@@ -20,13 +20,11 @@ void write_draw_call(DrawGroup group, uint group_id)
else {
cmd._instance_first_array = group.start;
}
- /* NOTE: Set instance count to 0 if vertex count is 0 to avoid a crash in some drivers. */
-
/* Back-facing command. */
- cmd.instance_len = (cmd.vertex_len == 0) ? 0 : group_buf[group_id].back_facing_counter;
+ cmd.instance_len = group_buf[group_id].back_facing_counter;
command_buf[group_id * 2 + 0] = cmd;
/* Front-facing command. */
- cmd.instance_len = (cmd.vertex_len == 0) ? 0 : group_buf[group_id].front_facing_counter;
+ cmd.instance_len = group_buf[group_id].front_facing_counter;
command_buf[group_id * 2 + 1] = cmd;
/* Reset the counters for a next command gen dispatch. Avoids resending the whole data just
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 8616df510a1..8f524f72fa1 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -164,6 +164,10 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
#define GPU_batch_texture_bind(batch, name, tex) \
GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
+/**
+ * Return indirect draw call parameters for this batch.
+ * NOTE: r_base_index is set to -1 if not using an index buffer.
+ */
void GPU_batch_draw_parameter_get(
GPUBatch *batch, int *r_v_count, int *r_v_first, int *r_base_index, int *r_i_count);