Move to use blender::Map container instead std::unordered_map #47

Merged
Bogdan Nagirniak merged 17 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-418 into hydra-render 2023-06-02 12:02:46 +02:00
4 changed files with 42 additions and 47 deletions
Showing only changes of commit f202f145df - Show all commits

View File

@ -8,7 +8,6 @@
#include "BKE_context.h" #include "BKE_context.h"
#include "DEG_depsgraph.h" #include "DEG_depsgraph.h"
#include "BLI_hash.hh"
#include "CLG_log.h" #include "CLG_log.h"
@ -19,13 +18,6 @@
#include "object.h" #include "object.h"
#include "world.h" #include "world.h"
template<> struct blender::DefaultHash<pxr::SdfPath> {
uint64_t operator()(const pxr::SdfPath &value) const
{
return pxr::SdfPath::Hash()(value);
}
};
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;

View File

@ -8,6 +8,14 @@
#include <pxr/usd/sdf/path.h> #include <pxr/usd/sdf/path.h>
#include "DNA_ID.h" #include "DNA_ID.h"
#include "BLI_hash.hh"
template<> struct blender::DefaultHash<pxr::SdfPath> {
uint64_t operator()(const pxr::SdfPath &value) const
{
return pxr::SdfPath::Hash()(value);
}
};
namespace blender::render::hydra { namespace blender::render::hydra {

View File

@ -74,8 +74,8 @@ void InstancerData::insert()
void InstancerData::remove() void InstancerData::remove()
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
it.second.data->remove(); it.data->remove();
} }
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id); scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
@ -118,9 +118,9 @@ bool InstancerData::update_visibility()
if (ret) { if (ret) {
auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker();
change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility);
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
it.second.data->visible = visible; it.data->visible = visible;
for (auto &p : it.second.data->submesh_paths()) { for (auto &p : it.data->submesh_paths()) {
change_tracker.MarkRprimDirty(p, pxr::HdChangeTracker::DirtyVisibility); change_tracker.MarkRprimDirty(p, pxr::HdChangeTracker::DirtyVisibility);
} }
} }
@ -179,8 +179,8 @@ ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
pxr::SdfPathVector InstancerData::prototypes() const pxr::SdfPathVector InstancerData::prototypes() const
{ {
pxr::SdfPathVector paths; pxr::SdfPathVector paths;
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
for (auto &p : it.second.data->submesh_paths()) { for (auto &p : it.data->submesh_paths()) {
paths.push_back(p); paths.push_back(p);
} }
} }
@ -194,7 +194,7 @@ void InstancerData::check_update(Object *object)
if (m_inst) { if (m_inst) {
if (!is_instance_visible(object)) { if (!is_instance_visible(object)) {
m_inst->data->remove(); m_inst->data->remove();
mesh_instances_.erase(path); mesh_instances_.remove(path);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty); prim_id, pxr::HdChangeTracker::AllDirty);
return; return;
@ -243,7 +243,7 @@ void InstancerData::check_update(Object *object)
if (do_write_instances) { if (do_write_instances) {
write_instances(); write_instances();
if (!mesh_instances_.empty()) { if (!mesh_instances_.is_empty()) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty); prim_id, pxr::HdChangeTracker::AllDirty);
} }
@ -254,13 +254,13 @@ void InstancerData::check_update(Object *object)
void InstancerData::check_remove(std::set<std::string> &available_objects) void InstancerData::check_remove(std::set<std::string> &available_objects)
{ {
bool ret = false; bool ret = false;
for (auto it = mesh_instances_.begin(); it != mesh_instances_.end(); ++it) { for (auto it : mesh_instances_.items()) {
if (available_objects.find(it->first.GetName()) != available_objects.end()) { if (available_objects.find(it.key.GetName()) != available_objects.end()) {
continue; continue;
} }
it->second.data->remove(); it.value.data->remove();
mesh_instances_.erase(it); mesh_instances_.remove(it.key);
it = mesh_instances_.begin(); auto it = mesh_instances_.items().begin();
ret = true; ret = true;
} }
if (ret) { if (ret) {
@ -283,8 +283,8 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
{ {
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
((MeshData *)it.second.data.get())->available_materials(paths); ((MeshData *)it.data.get())->available_materials(paths);
} }
} }
@ -297,8 +297,8 @@ void InstancerData::update_as_parent()
void InstancerData::update_double_sided(MaterialData *mat_data) void InstancerData::update_double_sided(MaterialData *mat_data)
{ {
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
it.second.data->update_double_sided(mat_data); it.data->update_double_sided(mat_data);
} }
} }
@ -343,8 +343,8 @@ int InstancerData::light_prim_id_index(pxr::SdfPath const &id) const
void InstancerData::write_instances() void InstancerData::write_instances()
{ {
mesh_transforms_.clear(); mesh_transforms_.clear();
for (auto &it : mesh_instances_) { for (auto &it : mesh_instances_.values()) {
it.second.indices.clear(); it.indices.clear();
} }
for (auto &it : light_instances_) { for (auto &it : light_instances_) {
it.second.transforms.clear(); it.second.transforms.clear();
@ -372,27 +372,22 @@ void InstancerData::write_instances()
else { else {
MeshInstance *inst = mesh_instance(p_id); MeshInstance *inst = mesh_instance(p_id);
if (!inst) { if (!inst) {
inst = &mesh_instances_[p_id]; inst = mesh_instances_.lookup_ptr(p_id);
if (inst) {
inst->data = std::make_unique<MeshData>(scene_delegate_, ob, p_id); inst->data = std::make_unique<MeshData>(scene_delegate_, ob, p_id);
inst->data->init(); inst->data->init();
inst->data->insert(); inst->data->insert();
}
ID_LOG(2, "Mesh %s %d", inst->data->id->name, mesh_transforms_.size()); ID_LOG(2, "Mesh %s %d", inst->data->id->name, mesh_transforms_.size());
inst->indices.push_back(mesh_transforms_.size()); inst->indices.push_back(mesh_transforms_.size());
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat)); mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
} }
} }
}
}
free_object_duplilist(lb); free_object_duplilist(lb);
/* Remove mesh intances without indices */ /* Remove mesh intances without indices */
for (auto it = mesh_instances_.begin(); it != mesh_instances_.end(); ++it) { mesh_instances_.remove_if([&](auto item) {return item.value.indices.empty();});
if (!it->second.indices.empty()) {
continue;
}
it->second.data->remove();
mesh_instances_.erase(it);
it = mesh_instances_.begin();
}
/* Update light intances and remove instances without transforms */ /* Update light intances and remove instances without transforms */
for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) { for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) {
@ -461,11 +456,11 @@ void InstancerData::update_light_instance(LightInstance &inst)
InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id) const InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id) const
{ {
auto it = mesh_instances_.find(id.GetPathElementCount() == 4 ? id.GetParentPath() : id); auto it = mesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
if (it == mesh_instances_.end()) { if (it == nullptr) {
return nullptr; return nullptr;
} }
return const_cast<MeshInstance *>(&it->second); return const_cast<MeshInstance *>(it);
} }
InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const

View File

@ -57,7 +57,7 @@ class InstancerData : public ObjectData {
MeshInstance *mesh_instance(pxr::SdfPath const &id) const; MeshInstance *mesh_instance(pxr::SdfPath const &id) const;
LightInstance *light_instance(pxr::SdfPath const &id) const; LightInstance *light_instance(pxr::SdfPath const &id) const;
pxr::TfHashMap<pxr::SdfPath, MeshInstance, pxr::SdfPath::Hash> mesh_instances_; Map<pxr::SdfPath, MeshInstance> mesh_instances_;
pxr::TfHashMap<pxr::SdfPath, LightInstance, pxr::SdfPath::Hash> light_instances_; pxr::TfHashMap<pxr::SdfPath, LightInstance, pxr::SdfPath::Hash> light_instances_;
pxr::VtMatrix4dArray mesh_transforms_; pxr::VtMatrix4dArray mesh_transforms_;
}; };