diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-08-28 11:03:21 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-08-28 11:03:21 +0300 |
commit | 3f3ccdf6677b0413fd00af2f6285786c9e491010 (patch) | |
tree | 8035baea85e676534b47d88a2df1c8c7970be128 /source | |
parent | e3e86e9f59c27cabe683f77107013d605455b470 (diff) |
Fix multi material mesh
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_command.cc | 11 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_command_shared.hh | 26 | ||||
-rw-r--r-- | source/blender/draw/intern/shaders/draw_command_generate_comp.glsl | 6 | ||||
-rw-r--r-- | source/blender/gpu/GPU_batch.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_batch.cc | 7 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_index_buffer_private.hh | 8 |
6 files changed, 43 insertions, 18 deletions
diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc index 31f7970cee3..569f56967a0 100644 --- a/source/blender/draw/intern/draw_command.cc +++ b/source/blender/draw/intern/draw_command.cc @@ -486,9 +486,10 @@ void DrawCommandBuf::bind(RecordingState &state, Draw &cmd = commands[header.index].draw; - int batch_vert_len, batch_inst_len; + int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len; /* Now that GPUBatches are guaranteed to be finished, extract their parameters. */ - GPU_batch_draw_parameter_get(cmd.batch, &batch_vert_len, &batch_inst_len); + GPU_batch_draw_parameter_get( + cmd.batch, &batch_vert_len, &batch_vert_first, &batch_base_index, &batch_inst_len); /* 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); @@ -537,7 +538,11 @@ void DrawMultiBuf::bind(RecordingState &state, int batch_inst_len; /* Now that GPUBatches are guaranteed to be finished, extract their parameters. */ - GPU_batch_draw_parameter_get(group.gpu_batch, &group.vertex_len, &batch_inst_len); + GPU_batch_draw_parameter_get(group.gpu_batch, + &group.vertex_len, + &group.vertex_first, + &group.base_index, + &batch_inst_len); /* Tag group as using index draw (changes indirect draw call structure). */ if (group.gpu_batch->elem != nullptr) { diff --git a/source/blender/draw/intern/draw_command_shared.hh b/source/blender/draw/intern/draw_command_shared.hh index f412e609fbe..22d1facfb09 100644 --- a/source/blender/draw/intern/draw_command_shared.hh +++ b/source/blender/draw/intern/draw_command_shared.hh @@ -35,24 +35,30 @@ struct DrawGroup { uint front_facing_len; /** GPUBatch values to be copied to DrawCommand after sorting (if not overriden). */ - int vertex_len; /** NOTE: Negative if using indexed draw. */ + int vertex_len; + int vertex_first; + int base_index; + /** Atomic counters used during command sorting. */ - uint front_facing_counter; - uint back_facing_counter; uint total_counter; - /** For debug printing only. */ - uint front_proto_len; - uint back_proto_len; - #ifndef GPU_SHADER /* NOTE: Union just to make sure the struct has always the same size on all platform. */ union { - /** Needed to create the correct draw call. */ - GPUBatch *gpu_batch; + struct { + /** For debug printing only. */ + uint front_proto_len; + uint back_proto_len; + /** Needed to create the correct draw call. */ + GPUBatch *gpu_batch; + }; + struct { #endif - uint2 _pad0; + uint front_facing_counter; + uint back_facing_counter; + uint _pad0, _pad1; #ifndef GPU_SHADER + }; }; #endif }; 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 031a35e4864..5adcb0b441d 100644 --- a/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl +++ b/source/blender/draw/intern/shaders/draw_command_generate_comp.glsl @@ -12,9 +12,9 @@ void write_draw_call(DrawGroup group, uint group_id) { DrawCommand cmd; cmd.vertex_len = abs(group.vertex_len); - cmd.vertex_first = 0; - if (group.vertex_len < 0) { - cmd.base_index = 0; + cmd.vertex_first = group.vertex_first; + if (group.base_index != -1) { + cmd.base_index = group.base_index; cmd.instance_first_indexed = group.start; } else { diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index ba3ab3265a1..8616df510a1 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -164,7 +164,8 @@ 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)); -void GPU_batch_draw_parameter_get(GPUBatch *batch, int *r_v_count, int *r_i_count); +void GPU_batch_draw_parameter_get( + GPUBatch *batch, int *r_v_count, int *r_v_first, int *r_base_index, int *r_i_count); void GPU_batch_draw(GPUBatch *batch); void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count); diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc index 138e617fc0e..9092ad5110c 100644 --- a/source/blender/gpu/intern/gpu_batch.cc +++ b/source/blender/gpu/intern/gpu_batch.cc @@ -220,15 +220,20 @@ void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader) /** \name Drawing / Drawcall functions * \{ */ -void GPU_batch_draw_parameter_get(GPUBatch *gpu_batch, int *r_v_count, int *r_i_count) +void GPU_batch_draw_parameter_get( + GPUBatch *gpu_batch, int *r_v_count, int *r_v_first, int *r_base_index, int *r_i_count) { Batch *batch = static_cast<Batch *>(gpu_batch); if (batch->elem) { *r_v_count = batch->elem_()->index_len_get(); + *r_v_first = batch->elem_()->index_start_get(); + *r_base_index = batch->elem_()->index_base_get(); } else { *r_v_count = batch->verts_(0)->vertex_len; + *r_v_first = 0; + *r_base_index = -1; } int i_count = (batch->inst[0]) ? batch->inst_(0)->vertex_len : 1; diff --git a/source/blender/gpu/intern/gpu_index_buffer_private.hh b/source/blender/gpu/intern/gpu_index_buffer_private.hh index 6ce62ae852e..84903b05273 100644 --- a/source/blender/gpu/intern/gpu_index_buffer_private.hh +++ b/source/blender/gpu/intern/gpu_index_buffer_private.hh @@ -70,6 +70,14 @@ class IndexBuf { * They can lead to graphical glitches on some systems. (See T96892) */ return is_empty_ ? 0 : index_len_; } + uint32_t index_start_get() const + { + return index_start_; + } + uint32_t index_base_get() const + { + return index_base_; + } /* Return size in byte of the drawable data buffer range. Actual buffer size might be bigger. */ size_t size_get() const { |