DRW: Make batch validation run first during iteration

This reduces the cost of querying the batches to the batch cache.
This commit is contained in:
Clément Foucault 2019-05-07 23:21:16 +02:00
parent 05b0f52aa7
commit 0030e4da70
Notes: blender-bot 2023-02-14 06:00:49 +01:00
Referenced by issue #64366, DRW: Crash opening Mr Elephant scene since recent commit
8 changed files with 52 additions and 4 deletions

View File

@ -3953,6 +3953,28 @@ GPUBatch *DRW_cache_cursor_get(bool crosshair_lines)
/** \name Batch Cache Impl. common
* \{ */
void drw_batch_cache_validate(Object *ob)
{
switch (ob->type) {
case OB_MESH:
DRW_mesh_batch_cache_validate((Mesh *)ob->data);
break;
case OB_CURVE:
case OB_FONT:
case OB_SURF:
DRW_curve_batch_cache_validate((Curve *)ob->data);
break;
case OB_MBALL:
DRW_mball_batch_cache_validate((MetaBall *)ob->data);
break;
case OB_LATTICE:
DRW_lattice_batch_cache_validate((Lattice *)ob->data);
break;
default:
break;
}
}
void drw_batch_cache_generate_requested(Object *ob)
{
const DRWContextState *draw_ctx = DRW_context_state_get();

View File

@ -44,15 +44,19 @@ struct bGPdata;
/* Expose via BKE callbacks */
void DRW_mball_batch_cache_dirty_tag(struct MetaBall *mb, int mode);
void DRW_mball_batch_cache_validate(struct MetaBall *mb);
void DRW_mball_batch_cache_free(struct MetaBall *mb);
void DRW_curve_batch_cache_dirty_tag(struct Curve *cu, int mode);
void DRW_curve_batch_cache_validate(struct Curve *cu);
void DRW_curve_batch_cache_free(struct Curve *cu);
void DRW_mesh_batch_cache_dirty_tag(struct Mesh *me, int mode);
void DRW_mesh_batch_cache_validate(struct Mesh *me);
void DRW_mesh_batch_cache_free(struct Mesh *me);
void DRW_lattice_batch_cache_dirty_tag(struct Lattice *lt, int mode);
void DRW_lattice_batch_cache_validate(struct Lattice *lt);
void DRW_lattice_batch_cache_free(struct Lattice *lt);
void DRW_particle_batch_cache_dirty_tag(struct ParticleSystem *psys, int mode);

View File

@ -474,12 +474,16 @@ static void curve_batch_cache_init(Curve *cu)
cache->is_dirty = false;
}
static CurveBatchCache *curve_batch_cache_get(Curve *cu)
void DRW_curve_batch_cache_validate(Curve *cu)
{
if (!curve_batch_cache_valid(cu)) {
curve_batch_cache_clear(cu);
curve_batch_cache_init(cu);
}
}
static CurveBatchCache *curve_batch_cache_get(Curve *cu)
{
return cu->batch_cache;
}

View File

@ -340,12 +340,16 @@ static void lattice_batch_cache_init(Lattice *lt)
cache->is_dirty = false;
}
static LatticeBatchCache *lattice_batch_cache_get(Lattice *lt)
void DRW_lattice_batch_cache_validate(Lattice *lt)
{
if (!lattice_batch_cache_valid(lt)) {
lattice_batch_cache_clear(lt);
lattice_batch_cache_init(lt);
}
}
static LatticeBatchCache *lattice_batch_cache_get(Lattice *lt)
{
return lt->batch_cache;
}

View File

@ -2095,12 +2095,16 @@ static void mesh_batch_cache_init(Mesh *me)
drw_mesh_weight_state_clear(&cache->weight_state);
}
static MeshBatchCache *mesh_batch_cache_get(Mesh *me)
void DRW_mesh_batch_cache_validate(Mesh *me)
{
if (!mesh_batch_cache_valid(me)) {
mesh_batch_cache_clear(me);
mesh_batch_cache_init(me);
}
}
static MeshBatchCache *mesh_batch_cache_get(Mesh *me)
{
return me->runtime.batch_cache;
}

View File

@ -98,12 +98,16 @@ static void metaball_batch_cache_init(MetaBall *mb)
cache->is_manifold = false;
}
static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb)
void DRW_mball_batch_cache_validate(MetaBall *mb)
{
if (!metaball_batch_cache_valid(mb)) {
metaball_batch_cache_clear(mb);
metaball_batch_cache_init(mb);
}
}
static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb)
{
return mb->batch_cache;
}

View File

@ -1157,6 +1157,8 @@ static void drw_engines_cache_populate(Object *ob)
* ourselves here. */
drw_drawdata_unlink_dupli((ID *)ob);
drw_batch_cache_validate(ob);
int i = 0;
for (LinkData *link = DST.enabled_engines.first; link; link = link->next, i++) {
DrawEngineType *engine = link->data;
@ -2096,6 +2098,9 @@ void DRW_render_object_iter(
DST.dupli_parent = data_.dupli_parent;
DST.dupli_source = data_.dupli_object_current;
DST.ob_state = NULL;
drw_batch_cache_validate(ob);
callback(vedata, ob, engine, depsgraph);
drw_batch_cache_generate_requested(DST.dupli_source ? DST.dupli_source->ob : ob);

View File

@ -442,6 +442,7 @@ void drw_state_set(DRWState state);
void drw_debug_draw(void);
void drw_debug_init(void);
void drw_batch_cache_validate(Object *ob);
void drw_batch_cache_generate_requested(struct Object *ob);
extern struct GPUVertFormat *g_pos_format;