From 48ad8909cc4dfa9af202ea2f72b2373f754c8dfc Mon Sep 17 00:00:00 2001 From: parker Date: Sat, 2 Aug 2025 23:02:14 +0100 Subject: [PATCH] fix: general optimization, lazy cooking, transform caching, fix geometry copying --- .gitignore | 1 + src/Engine/Network/NetworkManager.cpp | 16 +++++------- src/Engine/Operator/Attribute.cpp | 26 +++++++++++++++++++ src/Engine/Operator/Attribute.h | 3 ++- src/Engine/Operator/Context.cpp | 4 ++- src/Engine/Operator/Geometry.cpp | 33 ++++++++++++++++++++++++ src/Engine/Operator/Geometry.h | 5 ++++ src/Engine/Operator/GeometryOperator.cpp | 8 +++++- src/Engine/Operator/GeometryOperator.h | 3 ++- src/Gui/Interface.cpp | 18 ------------- src/OpDefs/GopGeometryImport.cpp | 23 ++++------------- src/OpDefs/GopTransform.cpp | 26 +++++++++---------- 12 files changed, 104 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 5ef90d5..510848f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build .cache docs/html docs/latex +perf.data* diff --git a/src/Engine/Network/NetworkManager.cpp b/src/Engine/Network/NetworkManager.cpp index f73bca1..b94ea79 100644 --- a/src/Engine/Network/NetworkManager.cpp +++ b/src/Engine/Network/NetworkManager.cpp @@ -19,16 +19,13 @@ enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo) maxOpId_++; std::unique_ptr newOp = std::make_unique(maxOpId_, opInfo); newOp->nodeDirtied.connect( - [this](nt::OpId opId, bool dirtyDescendents) + [this](nt::OpId opId, bool dirtyDependents) { - IC(); - if(dirtyDescendents) + if(dirtyDependents) { - IC(); std::vector dependentIds = getDependentsGraph(opId); for(OpId dependentId : dependentIds) { - IC(); // dirty node enzo::nt::GeometryOperator& dependentOp = getGeoOperator(opId); std::cout << "dirtying id: " << dependentId << "\n"; @@ -37,7 +34,6 @@ enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo) // cook display op if(getDisplayOp().has_value() && getDisplayOp().value()==dependentId) { - IC(); cookOp(dependentId); updateDisplay(dependentOp.getOutputGeo(0)); } @@ -46,7 +42,6 @@ enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo) }); gopStore_.emplace(maxOpId_, std::move(newOp)); - std::cout << "adding operator " << maxOpId_ << "\n"; return maxOpId_; } @@ -96,8 +91,11 @@ void enzo::nt::NetworkManager::cookOp(enzo::nt::OpId opId) for(enzo::nt::OpId dependencyOpId : dependencyGraph) { enzo::nt::GeometryOperator& op = getGeoOperator(dependencyOpId); - enzo::op::Context context(dependencyOpId, enzo::nt::nm()); - op.cookOp(context); + if(op.isDirty()) + { + enzo::op::Context context(dependencyOpId, enzo::nt::nm()); + op.cookOp(context); + } } } diff --git a/src/Engine/Operator/Attribute.cpp b/src/Engine/Operator/Attribute.cpp index c240e48..048651f 100644 --- a/src/Engine/Operator/Attribute.cpp +++ b/src/Engine/Operator/Attribute.cpp @@ -29,6 +29,32 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type) } +ga::Attribute::Attribute(const Attribute& other) +{ + type_ = other.type_; + private_= other.private_; + hidden_ = other.hidden_; + readOnly_ = other.readOnly_; + name_ = other.name_; + + switch(type_) + { + case(AttrType::intT): + intStore_=std::make_shared>(*other.intStore_); + break; + case(AttrType::floatT): + floatStore_=std::make_shared>(*other.floatStore_); + break; + case(AttrType::vectorT): + vector3Store_=std::make_shared>(*other.vector3Store_); + break; + default: + throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for"); + + } +} + + ga::AttributeType ga::Attribute::getType() { return type_; diff --git a/src/Engine/Operator/Attribute.h b/src/Engine/Operator/Attribute.h index 8c675b7..365687e 100644 --- a/src/Engine/Operator/Attribute.h +++ b/src/Engine/Operator/Attribute.h @@ -20,6 +20,7 @@ namespace enzo{ { public: Attribute(std::string name, ga::AttributeType type); + Attribute(const Attribute& other); AttributeType getType(); std::string getName(); @@ -42,7 +43,7 @@ namespace enzo{ std::string name_; - void* data_; + // void* data_; // data stores std::shared_ptr> intStore_; diff --git a/src/Engine/Operator/Context.cpp b/src/Engine/Operator/Context.cpp index 8f8e0ab..408481e 100644 --- a/src/Engine/Operator/Context.cpp +++ b/src/Engine/Operator/Context.cpp @@ -25,7 +25,8 @@ enzo::geo::Geometry enzo::op::Context::cloneInputGeo(unsigned int inputIndex) auto inputConnection = inputConnections.at(inputIndex); if(auto inputConnectionSP = inputConnection.lock()) { - return networkManager_.getGeoOperator(inputConnectionSP->getInputOpId()).getOutputGeo(inputConnectionSP->getInputIndex()); + const nt::GeometryOperator& geoOp = networkManager_.getGeoOperator(inputConnectionSP->getInputOpId()); + return geoOp.getOutputGeo(inputConnectionSP->getInputIndex()); } else { @@ -33,6 +34,7 @@ enzo::geo::Geometry enzo::op::Context::cloneInputGeo(unsigned int inputIndex) } } +// TODO: cache value enzo::bt::floatT enzo::op::Context::evalFloatParm(const char* parmName) const { enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_); diff --git a/src/Engine/Operator/Geometry.cpp b/src/Engine/Operator/Geometry.cpp index 9e2abf0..d1cb843 100644 --- a/src/Engine/Operator/Geometry.cpp +++ b/src/Engine/Operator/Geometry.cpp @@ -17,6 +17,39 @@ geo::Geometry::Geometry() addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount"); } +geo::Geometry::Geometry(const Geometry& other) +{ + pointAttributes_ = deepCopyAttributes(other.pointAttributes_); + vertexAttributes_ = deepCopyAttributes(other.vertexAttributes_); + primitiveAttributes_ = deepCopyAttributes(other.primitiveAttributes_); + globalAttributes_ = deepCopyAttributes(other.globalAttributes_); + +} + +geo::Geometry::attribVector geo::Geometry::deepCopyAttributes(attribVector originalVector) +{ + geo::Geometry::attribVector copied; + const size_t sourceSize = originalVector.size(); + + copied.reserve(sourceSize); + + for(const std::shared_ptr sourceAttrib : originalVector) + { + if(sourceAttrib) + { + copied.push_back(std::make_shared(*sourceAttrib)); + } + else + { + copied.push_back(nullptr); + } + } + + return copied; + +} + + enzo::geo::HeMesh geo::Geometry::computeHalfEdgeMesh() { HeMesh heMesh; diff --git a/src/Engine/Operator/Geometry.h b/src/Engine/Operator/Geometry.h index fedac46..eb0271c 100644 --- a/src/Engine/Operator/Geometry.h +++ b/src/Engine/Operator/Geometry.h @@ -22,14 +22,19 @@ class Geometry { public: Geometry(); + Geometry(const Geometry& other); ga::AttributeHandle addIntAttribute(ga::AttributeOwner owner, std::string name); ga::AttributeHandle addVector3Attribute(ga::AttributeOwner owner, std::string name); + // TODO: return weak ptr std::shared_ptr getAttribByName(ga::AttributeOwner owner, std::string name); std::vector derivePointNormals(); HeMesh computeHalfEdgeMesh(); private: using attribVector = std::vector>; attribVector& getAttributeStore(ga::AttributeOwner& owner); + + attribVector deepCopyAttributes(attribVector source); + attribVector pointAttributes_; attribVector vertexAttributes_; attribVector primitiveAttributes_; diff --git a/src/Engine/Operator/GeometryOperator.cpp b/src/Engine/Operator/GeometryOperator.cpp index dc3bbd1..fb78193 100644 --- a/src/Engine/Operator/GeometryOperator.cpp +++ b/src/Engine/Operator/GeometryOperator.cpp @@ -53,13 +53,19 @@ void enzo::nt::GeometryOperator::dirtyNode(bool dirtyDescendents) nodeDirtied(opId_, dirtyDescendents); } +bool enzo::nt::GeometryOperator::isDirty() +{ + return dirty_; +} + + void enzo::nt::GeometryOperator::cookOp(op::Context context) { opDef_->cookOp(context); dirty_=false; } -geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex) +geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex) const { return opDef_->getOutputGeo(outputIndex); } diff --git a/src/Engine/Operator/GeometryOperator.h b/src/Engine/Operator/GeometryOperator.h index 35be946..ea4c364 100644 --- a/src/Engine/Operator/GeometryOperator.h +++ b/src/Engine/Operator/GeometryOperator.h @@ -20,7 +20,7 @@ public: GeometryOperator& operator=(const GeometryOperator&) = delete; void cookOp(op::Context context); - geo::Geometry& getOutputGeo(unsigned outputIndex); + geo::Geometry& getOutputGeo(unsigned outputIndex) const; void addInputConnection(std::shared_ptr connection); void addOutputConnection(std::shared_ptr connection); @@ -33,6 +33,7 @@ public: std::string getTypeName(); void dirtyNode(bool dirtyDescendents=true); + bool isDirty(); unsigned int getMinInputs() const; diff --git a/src/Gui/Interface.cpp b/src/Gui/Interface.cpp index 9a6a1bf..66baf14 100644 --- a/src/Gui/Interface.cpp +++ b/src/Gui/Interface.cpp @@ -57,22 +57,4 @@ EnzoUI::EnzoUI() connect(&enzo::nt::nm(), &enzo::nt::NetworkManager::updateDisplay, viewport, &Viewport::geometryChanged); enzo::nt::nm().displayNodeChanged.connect([parametersPanel](){parametersPanel->selectionChanged();}); // connect(&enzo::nt::nm(), &enzo::nt::NetworkManager::updateDisplay, parametersPanel, &ParametersPanel::selectionChanged); - -// ─── end of EnzoUI ctor ─── -QTimer::singleShot(0, this, [=] { -auto dump = [](const char* name, QWidget* w) { - qInfo().nospace() - << name - << " sizeHint=" << w->sizeHint() - << " minHint=" << w->minimumSizeHint() - << " min=" << w->minimumSize() - << " policy=" << w->sizePolicy(); -}; - - dump("Viewport ", viewport); - dump("ParametersPanel ", parametersPanel); - dump("Network ", network); - dump("NetworkSplitter ", networkSplitter_); // will show max(child‑mins) -}); - } diff --git a/src/OpDefs/GopGeometryImport.cpp b/src/OpDefs/GopGeometryImport.cpp index f129dca..978449e 100644 --- a/src/OpDefs/GopGeometryImport.cpp +++ b/src/OpDefs/GopGeometryImport.cpp @@ -20,6 +20,7 @@ void GopGeometryImport::cookOp(enzo::op::Context context) if(outputRequested(0)) { std::string filePath = "/home/parker/Downloads/Rat_Placeholder_Polycount_12.obj"; + std::cout << "COOKING IMPORT NODE\n"; geo::Geometry geo; @@ -59,31 +60,26 @@ void GopGeometryImport::cookOp(enzo::op::Context context) } const bt::Vector3 pointPos = {std::stod(result[1]), std::stod(result[2]), std::stod(result[3])}; PAttrHandle.addValue(pointPos); - std::cout << "adding vector: " << pointPos.x() << " " << pointPos.y() << " " << pointPos.z() << "\n"; } else if(firstChar=='f') { std::vector result; boost::split(result, line, isspace); - // if(result.size()<3) - // { - // continue; + if(result.size()<3) + { + continue; - // } + } // set vertex attributes - std::cout << "connecting:"; for(int i=1; i #include +#include GopTransform::GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo) : GeometryOpDef(network, opInfo) @@ -25,20 +27,18 @@ void GopTransform::cookOp(enzo::op::Context context) auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P"); ga::AttributeHandleVector3 PAttrHandle(PAttr); - for(int i=0; i