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 "DEG_depsgraph.h"
#include "BLI_hash.hh"
#include "CLG_log.h"
@ -19,13 +18,6 @@
#include "object.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 {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;

View File

@ -8,6 +8,14 @@
#include <pxr/usd/sdf/path.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 {

View File

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