Cleanup: EEVEE: Use unique handle
- Move `ObjectRef` creation out of `object_sync`. - Make unique handle only when needed inside the sync functions. Pull Request: https://projects.blender.org/blender/blender/pulls/130294
This commit is contained in:
committed by
Clément Foucault
parent
49b968cf39
commit
ac58df78cc
@@ -123,7 +123,8 @@ static void eevee_cache_init(void *vedata)
|
||||
|
||||
static void eevee_cache_populate(void *vedata, Object *object)
|
||||
{
|
||||
reinterpret_cast<EEVEE_Data *>(vedata)->instance->object_sync(object);
|
||||
draw::ObjectRef ob_ref = DRW_object_ref_get(object);
|
||||
reinterpret_cast<EEVEE_Data *>(vedata)->instance->object_sync(ob_ref);
|
||||
}
|
||||
|
||||
static void eevee_cache_finish(void *vedata)
|
||||
|
||||
@@ -232,12 +232,13 @@ void Instance::begin_sync()
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::object_sync(Object *ob)
|
||||
void Instance::object_sync(ObjectRef &ob_ref)
|
||||
{
|
||||
if (!shaders_are_ready_) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object *ob = ob_ref.object;
|
||||
const bool is_renderable_type = ELEM(ob->type,
|
||||
OB_CURVES,
|
||||
OB_GREASE_PENCIL,
|
||||
@@ -246,7 +247,6 @@ void Instance::object_sync(Object *ob)
|
||||
OB_VOLUME,
|
||||
OB_LAMP,
|
||||
OB_LIGHTPROBE);
|
||||
const bool is_drawable_type = is_renderable_type && !ELEM(ob->type, OB_LAMP, OB_LIGHTPROBE);
|
||||
const int ob_visibility = DRW_object_visibility_in_active_context(ob);
|
||||
const bool partsys_is_visible = (ob_visibility & OB_VISIBLE_PARTICLES) != 0 &&
|
||||
(ob->type == OB_MESH);
|
||||
@@ -257,20 +257,14 @@ void Instance::object_sync(Object *ob)
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO cleanup. */
|
||||
ObjectRef ob_ref = DRW_object_ref_get(ob);
|
||||
ObjectHandle &ob_handle = sync.sync_object(ob_ref);
|
||||
ResourceHandle res_handle = {0};
|
||||
if (is_drawable_type) {
|
||||
res_handle = manager->resource_handle(ob_ref);
|
||||
}
|
||||
|
||||
if (partsys_is_visible && ob != DRW_context_state_get()->object_edit) {
|
||||
auto sync_hair =
|
||||
[&](ObjectHandle hair_handle, ModifierData &md, ParticleSystem &particle_sys) {
|
||||
ResourceHandle _res_handle = manager->resource_handle_for_psys(ob_ref,
|
||||
ob->object_to_world());
|
||||
sync.sync_curves(ob, hair_handle, _res_handle, ob_ref, &md, &particle_sys);
|
||||
sync.sync_curves(ob, hair_handle, ob_ref, _res_handle, &md, &particle_sys);
|
||||
};
|
||||
foreach_hair_particle_handle(ob, ob_handle, sync_hair);
|
||||
}
|
||||
@@ -281,18 +275,18 @@ void Instance::object_sync(Object *ob)
|
||||
lights.sync_light(ob, ob_handle);
|
||||
break;
|
||||
case OB_MESH:
|
||||
if (!sync.sync_sculpt(ob, ob_handle, res_handle, ob_ref)) {
|
||||
sync.sync_mesh(ob, ob_handle, res_handle, ob_ref);
|
||||
if (!sync.sync_sculpt(ob, ob_handle, ob_ref)) {
|
||||
sync.sync_mesh(ob, ob_handle, ob_ref);
|
||||
}
|
||||
break;
|
||||
case OB_POINTCLOUD:
|
||||
sync.sync_point_cloud(ob, ob_handle, res_handle, ob_ref);
|
||||
sync.sync_point_cloud(ob, ob_handle, ob_ref);
|
||||
break;
|
||||
case OB_VOLUME:
|
||||
sync.sync_volume(ob, ob_handle, res_handle, ob_ref);
|
||||
sync.sync_volume(ob, ob_handle, ob_ref);
|
||||
break;
|
||||
case OB_CURVES:
|
||||
sync.sync_curves(ob, ob_handle, res_handle, ob_ref);
|
||||
sync.sync_curves(ob, ob_handle, ob_ref);
|
||||
break;
|
||||
case OB_LIGHTPROBE:
|
||||
light_probes.sync_probe(ob, ob_handle);
|
||||
@@ -310,7 +304,8 @@ void Instance::object_sync_render(void *instance_,
|
||||
{
|
||||
UNUSED_VARS(engine, depsgraph);
|
||||
Instance &inst = *reinterpret_cast<Instance *>(instance_);
|
||||
inst.object_sync(ob);
|
||||
ObjectRef ob_ref = DRW_object_ref_get(ob);
|
||||
inst.object_sync(ob_ref);
|
||||
}
|
||||
|
||||
void Instance::end_sync()
|
||||
|
||||
@@ -189,7 +189,7 @@ class Instance {
|
||||
void view_update();
|
||||
|
||||
void begin_sync();
|
||||
void object_sync(Object *ob);
|
||||
void object_sync(ObjectRef &ob_ref);
|
||||
void end_sync();
|
||||
|
||||
/**
|
||||
|
||||
@@ -88,17 +88,21 @@ static inline void volume_call(
|
||||
/** \name Mesh
|
||||
* \{ */
|
||||
|
||||
void SyncModule::sync_mesh(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref)
|
||||
void SyncModule::sync_mesh(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref)
|
||||
{
|
||||
if (!inst_.use_surfaces) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ob->dt < OB_SOLID) && (inst_.is_viewport() && inst_.v3d->shading.type != OB_RENDER)) {
|
||||
/** Do not render objects with display type lower than solid when in material preview mode. */
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceHandle res_handle = inst_.manager->unique_handle(ob_ref);
|
||||
|
||||
bool has_motion = inst_.velocity.step_object_sync(
|
||||
ob, ob_handle.object_key, res_handle, ob_handle.recalc);
|
||||
ob_handle.object_key, ob_ref, ob_handle.recalc, res_handle);
|
||||
|
||||
MaterialArray &material_array = inst_.materials.material_array_get(ob, has_motion);
|
||||
|
||||
@@ -109,11 +113,6 @@ void SyncModule::sync_mesh(Object *ob,
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ob->dt < OB_SOLID) && (inst_.is_viewport() && inst_.v3d->shading.type != OB_RENDER)) {
|
||||
/** Do not render objects with display type lower than solid when in material preview mode. */
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_alpha_blend = false;
|
||||
bool has_transparent_shadows = false;
|
||||
bool has_volume = false;
|
||||
@@ -174,10 +173,7 @@ void SyncModule::sync_mesh(Object *ob,
|
||||
inst_.cryptomatte.sync_object(ob, res_handle);
|
||||
}
|
||||
|
||||
bool SyncModule::sync_sculpt(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref)
|
||||
bool SyncModule::sync_sculpt(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref)
|
||||
{
|
||||
if (!inst_.use_surfaces) {
|
||||
return false;
|
||||
@@ -188,6 +184,8 @@ bool SyncModule::sync_sculpt(Object *ob,
|
||||
return false;
|
||||
}
|
||||
|
||||
ResourceHandle res_handle = inst_.manager->unique_handle(ob_ref);
|
||||
|
||||
bool has_motion = false;
|
||||
MaterialArray &material_array = inst_.materials.material_array_get(ob, has_motion);
|
||||
|
||||
@@ -264,15 +262,14 @@ bool SyncModule::sync_sculpt(Object *ob,
|
||||
/** \name Point Cloud
|
||||
* \{ */
|
||||
|
||||
void SyncModule::sync_point_cloud(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref)
|
||||
void SyncModule::sync_point_cloud(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref)
|
||||
{
|
||||
const int material_slot = POINTCLOUD_MATERIAL_NR;
|
||||
|
||||
ResourceHandle res_handle = inst_.manager->unique_handle(ob_ref);
|
||||
|
||||
bool has_motion = inst_.velocity.step_object_sync(
|
||||
ob, ob_handle.object_key, res_handle, ob_handle.recalc);
|
||||
ob_handle.object_key, ob_ref, ob_handle.recalc, res_handle);
|
||||
|
||||
Material &material = inst_.materials.material_get(
|
||||
ob, has_motion, material_slot - 1, MAT_GEOM_POINT_CLOUD);
|
||||
@@ -334,15 +331,14 @@ void SyncModule::sync_point_cloud(Object *ob,
|
||||
/** \name Volume Objects
|
||||
* \{ */
|
||||
|
||||
void SyncModule::sync_volume(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref)
|
||||
void SyncModule::sync_volume(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref)
|
||||
{
|
||||
if (!inst_.use_volumes) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceHandle res_handle = inst_.manager->unique_handle(ob_ref);
|
||||
|
||||
const int material_slot = VOLUME_MATERIAL_NR;
|
||||
|
||||
/* Motion is not supported on volumes yet. */
|
||||
@@ -399,8 +395,8 @@ void SyncModule::sync_volume(Object *ob,
|
||||
|
||||
void SyncModule::sync_curves(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref,
|
||||
ResourceHandle res_handle,
|
||||
ModifierData *modifier_data,
|
||||
ParticleSystem *particle_sys)
|
||||
{
|
||||
@@ -413,8 +409,13 @@ void SyncModule::sync_curves(Object *ob,
|
||||
mat_nr = particle_sys->part->omat;
|
||||
}
|
||||
|
||||
if (res_handle.raw == 0) {
|
||||
/* For curve objects. */
|
||||
res_handle = inst_.manager->unique_handle(ob_ref);
|
||||
}
|
||||
|
||||
bool has_motion = inst_.velocity.step_object_sync(
|
||||
ob, ob_handle.object_key, res_handle, ob_handle.recalc, modifier_data, particle_sys);
|
||||
ob_handle.object_key, ob_ref, ob_handle.recalc, res_handle, modifier_data, particle_sys);
|
||||
Material &material = inst_.materials.material_get(ob, has_motion, mat_nr - 1, MAT_GEOM_CURVES);
|
||||
|
||||
auto drawcall_add = [&](MaterialPass &matpass) {
|
||||
|
||||
@@ -162,26 +162,14 @@ class SyncModule {
|
||||
ObjectHandle &sync_object(const ObjectRef &ob_ref);
|
||||
WorldHandle sync_world(const ::World &world);
|
||||
|
||||
void sync_mesh(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref);
|
||||
bool sync_sculpt(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref);
|
||||
void sync_point_cloud(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref);
|
||||
void sync_volume(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref);
|
||||
void sync_mesh(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref);
|
||||
bool sync_sculpt(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref);
|
||||
void sync_point_cloud(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref);
|
||||
void sync_volume(Object *ob, ObjectHandle &ob_handle, const ObjectRef &ob_ref);
|
||||
void sync_curves(Object *ob,
|
||||
ObjectHandle &ob_handle,
|
||||
ResourceHandle res_handle,
|
||||
const ObjectRef &ob_ref,
|
||||
ResourceHandle res_handle = 0,
|
||||
ModifierData *modifier_data = nullptr,
|
||||
ParticleSystem *particle_sys = nullptr);
|
||||
};
|
||||
|
||||
@@ -82,16 +82,18 @@ static void step_object_sync_render(void *instance,
|
||||
ObjectHandle &ob_handle = inst.sync.sync_object(ob_ref);
|
||||
|
||||
if (partsys_is_visible) {
|
||||
auto sync_hair =
|
||||
[&](ObjectHandle hair_handle, ModifierData &md, ParticleSystem &particle_sys) {
|
||||
inst.velocity.step_object_sync(
|
||||
ob, hair_handle.object_key, resource_handle, hair_handle.recalc, &md, &particle_sys);
|
||||
};
|
||||
auto sync_hair = [&](ObjectHandle hair_handle,
|
||||
ModifierData &md,
|
||||
ParticleSystem &particle_sys) {
|
||||
inst.velocity.step_object_sync(
|
||||
hair_handle.object_key, ob_ref, hair_handle.recalc, resource_handle, &md, &particle_sys);
|
||||
};
|
||||
foreach_hair_particle_handle(ob, ob_handle, sync_hair);
|
||||
};
|
||||
|
||||
if (object_is_visible) {
|
||||
inst.velocity.step_object_sync(ob, ob_handle.object_key, resource_handle, ob_handle.recalc);
|
||||
inst.velocity.step_object_sync(
|
||||
ob_handle.object_key, ob_ref, ob_handle.recalc, resource_handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +130,14 @@ void VelocityModule::step_camera_sync()
|
||||
}
|
||||
}
|
||||
|
||||
bool VelocityModule::step_object_sync(Object *ob,
|
||||
ObjectKey &object_key,
|
||||
ResourceHandle resource_handle,
|
||||
bool VelocityModule::step_object_sync(ObjectKey &object_key,
|
||||
const ObjectRef &object_ref,
|
||||
int /*IDRecalcFlag*/ recalc,
|
||||
ResourceHandle resource_handle,
|
||||
ModifierData *modifier_data /*=nullptr*/,
|
||||
ParticleSystem *particle_sys /*=nullptr*/)
|
||||
{
|
||||
Object *ob = object_ref.object;
|
||||
bool has_motion = object_has_velocity(ob) || (recalc & ID_RECALC_TRANSFORM);
|
||||
/* NOTE: Fragile. This will only work with 1 frame of lag since we can't record every geometry
|
||||
* just in case there might be an update the next frame. */
|
||||
|
||||
@@ -105,10 +105,10 @@ class VelocityModule {
|
||||
void step_sync(eVelocityStep step, float time);
|
||||
|
||||
/* Gather motion data. Returns true if the object **can** have motion. */
|
||||
bool step_object_sync(Object *ob,
|
||||
ObjectKey &object_key,
|
||||
bool step_object_sync(ObjectKey &object_key,
|
||||
const ObjectRef &object_ref,
|
||||
int recalc,
|
||||
ResourceHandle resource_handle,
|
||||
int recalc = 0,
|
||||
ModifierData *modifier_data = nullptr,
|
||||
ParticleSystem *particle_sys = nullptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user