MeshBatchCache: Speedup: Do not return valid batch if geometry is empty

There was a huge overhead of batches that had no geometry. The loose
wire batch was the culprit.
This commit is contained in:
Clément Foucault 2019-06-18 22:25:37 +02:00
parent 82f569d75e
commit ba152cc88d
Notes: blender-bot 2023-02-14 05:44:22 +01:00
Referenced by issue #65918, Crash when add a any modifier to a curve
1 changed files with 13 additions and 2 deletions

View File

@ -2059,6 +2059,8 @@ typedef struct MeshBatchCache {
/* Valid only if edge_detection is up to date. */
bool is_manifold;
bool no_loose_wire;
} MeshBatchCache;
BLI_INLINE void mesh_batch_cache_add_request(MeshBatchCache *cache, DRWBatchFlag new_flag)
@ -3850,6 +3852,7 @@ static void mesh_create_loops_line_strips(MeshRenderData *rdata,
static void mesh_create_loose_edges_lines(MeshRenderData *rdata,
GPUIndexBuf *ibo,
bool *r_no_loose_wire,
const bool use_hide)
{
const int vert_len = mesh_render_data_verts_len_get_maybe_mapped(rdata);
@ -3892,6 +3895,8 @@ static void mesh_create_loose_edges_lines(MeshRenderData *rdata,
}
}
*r_no_loose_wire = (elb.index_len == 0);
GPU_indexbuf_build_in_place(&elb, ibo);
}
@ -4291,7 +4296,12 @@ GPUBatch *DRW_mesh_batch_cache_get_loose_edges(Mesh *me)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
mesh_batch_cache_add_request(cache, MBC_LOOSE_EDGES);
return DRW_batch_request(&cache->batch.loose_edges);
if (cache->no_loose_wire) {
return NULL;
}
else {
return DRW_batch_request(&cache->batch.loose_edges);
}
}
GPUBatch *DRW_mesh_batch_cache_get_surface_weights(Mesh *me)
@ -5304,7 +5314,8 @@ void DRW_mesh_batch_cache_create_requested(
rdata, cache->ibo.edges_adj_lines, &cache->is_manifold, use_hide);
}
if (DRW_ibo_requested(cache->ibo.loose_edges_lines)) {
mesh_create_loose_edges_lines(rdata, cache->ibo.loose_edges_lines, use_hide);
mesh_create_loose_edges_lines(
rdata, cache->ibo.loose_edges_lines, &cache->no_loose_wire, use_hide);
}
if (DRW_ibo_requested(cache->ibo.surf_tris)) {
mesh_create_surf_tris(rdata, cache->ibo.surf_tris, use_hide);