Mesh: Draw triangle index buffer creation improvements
commit0f46e02310c98e212f50dc0af9a46a76c844358a
authorHans Goudey <hans@blender.org>
Thu, 11 Apr 2024 02:49:27 +0000 (11 04:49 +0200)
committerHans Goudey <hooglyboogly@noreply.localhost>
Thu, 11 Apr 2024 02:49:27 +0000 (11 04:49 +0200)
tree12e1e1f1f1cf38398625f18438ccf70cff9bf137
parent6bafe65d289cb61f3897e848dcfe01dff28ea4ea
Mesh: Draw triangle index buffer creation improvements

This PR is another step in the refactor described by #116901.
This change applies to the triangle index buffer. The main improvement
is the ability to recognize when the mesh corner triangles index array
can be uploaded directly (when there is a single material and no hidden
faces). In that case the index data should be copied directly to the
GPU rather than to a temporary array owned by the IBO first. Though
that isn't implemented yet since it will be handled by the GPU module
later, the code is now structured to make that change simple from the
data extraction perspective.

Other than that, the main change is to not use the extractor iterator
framework anymore, and to set index data directly instead of using GPU
API functions. Though we're mainly bottlenecked by memory-bandwidth
anyway, it's nice to avoid function call overhead.

We also now avoid creating the array of sorted triangle indices when
there is a single material and no hidden faces. And we don't use
restart indices for the single-material case anymore. For Metal that's
nice because we can avoid `strip_restart_indices`.

I didn't notice significant performance improvements in my test files
beyond a few percent here and there. With a hacked implementation of
the copy-directly-to-the-gpu optimization, I did see more consistent
improvements though.

Pull Request: https://projects.blender.org/blender/blender/pulls/119130
source/blender/draw/intern/draw_cache_extract.hh
source/blender/draw/intern/draw_cache_extract_mesh.cc
source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
source/blender/draw/intern/mesh_extractors/extract_mesh.cc
source/blender/draw/intern/mesh_extractors/extract_mesh.hh
source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
source/blender/gpu/GPU_index_buffer.hh
source/blender/gpu/intern/gpu_index_buffer.cc