Skip to content

Commit

Permalink
cache object to temp disk
Browse files Browse the repository at this point in the history
  • Loading branch information
1445643474 committed Nov 6, 2023
1 parent 08d20a6 commit 1a1b4b5
Show file tree
Hide file tree
Showing 26 changed files with 246 additions and 55 deletions.
8 changes: 8 additions & 0 deletions ui/zenoedit/cache/zcachemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ZCacheMgr::ZCacheMgr()
, m_isNew(true)
, m_cacheOpt(Opt_Undefined)
{
m_objTmpCacheDir.setAutoRemove(true);
}

bool ZCacheMgr::initCacheDir(bool bTempDir, QDir dirCacheRoot, bool bAutoCleanCache)
Expand Down Expand Up @@ -61,6 +62,13 @@ QString ZCacheMgr::cachePath() const
}
}

QString ZCacheMgr::objCachePath() const
{
QString path = m_objTmpCacheDir.path();
zeno::log_debug("node cache dir {}", path.toStdString());
return path;
}

std::shared_ptr<QTemporaryDir> ZCacheMgr::getTempDir() const
{
return m_spTmpCacheDir;
Expand Down
3 changes: 2 additions & 1 deletion ui/zenoedit/cache/zcachemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ZCacheMgr
ZCacheMgr();
bool initCacheDir(bool bTempDir, QDir dir, bool bAutoCleanCache);
QString cachePath() const;
QString objCachePath() const;
std::shared_ptr<QTemporaryDir> getTempDir() const;
QDir getPersistenceDir() const;

Expand All @@ -25,7 +26,7 @@ class ZCacheMgr
bool hasCacheOnly(QDir dir, bool& empty);

private:

QTemporaryDir m_objTmpCacheDir;
std::shared_ptr<QTemporaryDir> m_spTmpCacheDir;
QDir m_spCacheDir;
bool m_bTempDir;
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/launch/corelaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct LAUNCH_PARAM {
bool enableCache = false;
bool tempDir = false;
QString cacheDir = "";
QString objCacheDir = "";
int cacheNum = 1;
bool autoRmCurcache = false; //auto remove cache when recording
bool autoCleanCacheInCacheRoot = true; //auto remove cachedir in cache root
Expand Down
51 changes: 25 additions & 26 deletions ui/zenoedit/launch/runnermain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void send_packet(std::string_view info, const char *buf, size_t len) {
#endif
}

static int runner_start(std::string const &progJson, int sessionid, bool bZenCache, int cachenum, std::string cachedir, bool cacheautorm, bool cacheLightCameraOnly, bool cacheMaterialOnly, std::string zsg_path, std::string projectFps) {
static int runner_start(std::string const &progJson, int sessionid, const LAUNCH_PARAM& param) {
zeno::log_trace("runner got program JSON: {}", progJson);
//MessageBox(0, "runner", "runner", MB_OK); //convient to attach process by debugger, at windows.
zeno::scope_exit sp([=]() { std::cout.flush(); });
Expand All @@ -95,15 +95,17 @@ static int runner_start(std::string const &progJson, int sessionid, bool bZenCac
auto graph = session->createGraph();

//$ZSG value
zeno::setConfigVariable("ZSG", zsg_path);
zeno::setConfigVariable("ZSG", param.zsgPath.toStdString());
//$FPS, getFrameTime value
zeno::setConfigVariable("FPS", projectFps);
zeno::setConfigVariable("FPS", QString::number(param.projectFps).toStdString());

float fps = std::stof(projectFps);
zeno::getSession().globalComm->objTmpCachePath = param.objCacheDir.toStdString();

float fps = param.projectFps;
zeno::getSession().globalState->frame_time = (fps > 0) ? (1.f / fps) : 24;

if (bZenCache) {
zeno::getSession().globalComm->frameCache(cachedir, cachenum);
if (param.enableCache) {
zeno::getSession().globalComm->frameCache(param.cacheDir.toStdString(), param.cacheNum);
}
else {
zeno::getSession().globalComm->frameCache("", 0);
Expand Down Expand Up @@ -153,13 +155,13 @@ static int runner_start(std::string const &progJson, int sessionid, bool bZenCac

send_packet("{\"action\":\"newFrame\",\"key\":\"" + std::to_string(frame) +"\"}", "", 0);

if (bZenCache) {
if (param.enableCache) {
//construct cache lock.
std::string sLockFile = cachedir + "/" + zeno::iotags::sZencache_lockfile_prefix + std::to_string(frame) + ".lock";
std::string sLockFile = param.cacheDir.toStdString() + "/" + zeno::iotags::sZencache_lockfile_prefix + std::to_string(frame) + ".lock";
QLockFile lckFile(QString::fromStdString(sLockFile));
bool ret = lckFile.tryLock();
//dump cache to disk.
session->globalComm->dumpFrameCache(frame, cacheLightCameraOnly, cacheMaterialOnly);
session->globalComm->dumpFrameCache(frame, param.applyLightAndCameraOnly, param.applyMaterialOnly);
} else {
auto const& viewObjs = session->globalComm->getViewObjects();
zeno::log_debug("runner got {} view objects", viewObjs.size());
Expand Down Expand Up @@ -187,16 +189,10 @@ int runner_main(const QCoreApplication& app) {
#ifdef __linux__
stderr = freopen("/dev/stdout", "w", stderr);
#endif
LAUNCH_PARAM param;
int sessionid = 0;
int port = -1;
bool enablecache = true;
int cachenum = 1;
std::string cachedir = "";
bool cacheLightCameraOnly = false;
bool cacheMaterialOnly = false;
bool cacheautorm = false;
std::string zsg_path = "";
std::string projectFps = "";
std::string objcachedir = "";
QCommandLineParser cmdParser;
cmdParser.addHelpOption();
cmdParser.addOptions({
Expand All @@ -211,28 +207,31 @@ int runner_main(const QCoreApplication& app) {
{"cacheautorm", "cacheautoremove", "remove cache after render"},
{"zsg", "zsg", "zsg"},
{"projectFps", "current project fps", "fps"},
{"objcachedir", "objcachedir", "obj temp cache dir"},
});
cmdParser.process(app);
if (cmdParser.isSet("sessionid"))
sessionid = cmdParser.value("sessionid").toInt();
if (cmdParser.isSet("port"))
port = cmdParser.value("port").toInt();
if (cmdParser.isSet("enablecache"))
enablecache = cmdParser.value("enablecache").toInt();
param.enableCache = cmdParser.value("enablecache").toInt();
if (cmdParser.isSet("cachenum"))
cachenum = cmdParser.value("cachenum").toInt();
param.cacheNum = cmdParser.value("cachenum").toInt();
if (cmdParser.isSet("cachedir"))
cachedir = cmdParser.value("cachedir").toStdString();
param.cacheDir = cmdParser.value("cachedir");
if (cmdParser.isSet("objcachedir"))
param.objCacheDir = cmdParser.value("objcachedir");
if (cmdParser.isSet("cacheLightCameraOnly"))
cacheLightCameraOnly = cmdParser.value("cacheLightCameraOnly").toInt();
param.applyLightAndCameraOnly = cmdParser.value("cacheLightCameraOnly").toInt();
if (cmdParser.isSet("cacheMaterialOnly"))
cacheMaterialOnly = cmdParser.value("cacheMaterialOnly").toInt();
param.applyMaterialOnly = cmdParser.value("cacheMaterialOnly").toInt();
if (cmdParser.isSet("cacheautorm"))
cacheautorm = cmdParser.value("cacheautorm").toInt();
param.autoRmCurcache = cmdParser.value("cacheautorm").toInt();
if (cmdParser.isSet("zsg"))
zsg_path = cmdParser.value("zsg").toStdString();
param.zsgPath = cmdParser.value("zsg");
if (cmdParser.isSet("projectFps"))
projectFps = cmdParser.value("projectFps").toStdString();
param.projectFps = cmdParser.value("projectFps").toInt();

std::cerr.rdbuf(std::cout.rdbuf());
std::clog.rdbuf(std::cout.rdbuf());
Expand Down Expand Up @@ -269,6 +268,6 @@ int runner_main(const QCoreApplication& app) {
}(), 0);
#endif

return runner_start(progJson, sessionid, enablecache, cachenum, cachedir, cacheautorm, cacheLightCameraOnly, cacheMaterialOnly, zsg_path, projectFps);
return runner_start(progJson, sessionid, param);
}
#endif
4 changes: 4 additions & 0 deletions ui/zenoedit/launch/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgId
}
}
}
if (opts & OPT_CACHE)
{
AddStringList({ "cacheToDisk", ident}, writer);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/launch/ztcpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void ZTcpServer::startProc(const std::string& progJson, LAUNCH_PARAM param)
"--cacheautorm", QString::number(param.autoRmCurcache),
"--zsg", param.zsgPath,
"--projectFps", QString::number(param.projectFps),
"--objcachedir", zenoApp->cacheMgr()->objCachePath(),
};

m_proc->start(QCoreApplication::applicationFilePath(), args);
Expand Down
12 changes: 12 additions & 0 deletions ui/zenoedit/nodesys/zenonode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ void ZenoNode::onZoomed()
}
if (m_bodyWidget)
m_bodyWidget->setBorder(ZenoStyle::scaleWidth(2), QColor(18, 20, 22));
m_dirtyMarker->resize(m_dirtyMarker->rect().width(), ZenoStyle::scaleWidth(3));
}

void ZenoNode::setGroupNode(GroupNode *pNode)
Expand Down Expand Up @@ -1880,6 +1881,17 @@ void ZenoNode::onOptionsBtnToggled(STATUS_BTN btn, bool toggled)
options ^= OPT_VIEW;
}
}
else if (btn == STATUS_CACHE)
{
if (toggled)
{
options |= OPT_CACHE;
}
else
{
options ^= OPT_CACHE;
}
}

STATUS_UPDATE_INFO info;
info.role = ROLE_OPTIONS;
Expand Down
2 changes: 2 additions & 0 deletions ui/zenoedit/res/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
<file>icons/min_MUTE_dark.svg</file>
<file>icons/min_ONCE_dark.svg</file>
<file>icons/min_VIEW_dark.svg</file>
<file>icons/min_CACHE_dark.svg</file>
<file>icons/min_MUTE_light.svg</file>
<file>icons/min_CACHE_light.svg</file>
<file>icons/min_ONCE_light.svg</file>
<file>icons/min_VIEW_light.svg</file>
<file>icons/MUTE_dark.svg</file>
Expand Down
13 changes: 13 additions & 0 deletions ui/zenoedit/res/icons/min_CACHE_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ui/zenoedit/res/icons/min_CACHE_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions ui/zenoedit/res/icons/min_ONCE_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ui/zenoedit/res/templates/node-example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<component id="name" x="75" y="75" w="116" h="22">
<text id="" x="75" y="75" w="116" h="22" font-family="Consolas">ReadVDBGrid</text>
</component>
<component id="status" x="32" y="24" w="208" h="48">
<component id="status" x="32" y="24" w="308" h="48">
<image id="mute" x="48" y="32" w="24" h="24" normal=":/icons/min_MUTE_dark.svg" hovered=":/icons/min_MUTE_light.svg" selected=":/icons/min_MUTE_light.svg"/>
<image id="view" x="96" y="32" w="24" h="24" normal=":/icons/min_VIEW_dark.svg" hovered=":/icons/min_VIEW_light.svg" selected=":/icons/min_VIEW_light.svg"/>
<image id="prep" x="144" y="32" w="24" h="24" normal=":/icons/min_ONCE_dark.svg" hovered=":/icons/min_ONCE_light.svg" selected=":/icons/min_ONCE_light.svg"/>
<image id="cache" x="192" y="32" w="24" h="24" normal=":/icons/min_CACHE_dark.svg" hovered=":/icons/min_CACHE_light.svg" selected=":/icons/min_CACHE_light.svg"/>
</component>
<component id="control" x="32" y="72" w="32" h="32">
<image id="collapse" x="47" y="86" w="16" h="16" normal=":/icons/collaspe.svg" hovered="" selected=":/icons/uncollaspe.svg"/>
Expand Down
3 changes: 2 additions & 1 deletion ui/zenomodel/include/modeldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ enum NODE_OPTION {
OPT_ONCE = 1,
OPT_MUTE = 1 << 1,
OPT_VIEW = 1 << 2,
OPT_PREP = 1 << 3
OPT_PREP = 1 << 3,
OPT_CACHE = 1 << 4
};

enum SOCKET_PROPERTY {
Expand Down
24 changes: 22 additions & 2 deletions ui/zenomodel/src/graphsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,26 @@ void GraphsModel::_markNodeChanged(const QModelIndex& nodeIdx)
ZASSERT_EXIT(pModel);
pModel->setData(nodeIdx, true, ROLE_NODE_DATACHANGED);
m_changedNodes.insert(nodeIdx);
if (NodeParamModel* nodeParams = QVariantPtr<NodeParamModel>::asPtr(nodeIdx.data(ROLE_NODE_PARAMS)))
{
for (const auto& sock : nodeParams->getOutputIndice())
{
PARAM_LINKS links = sock.data(ROLE_PARAM_LINKS).value<PARAM_LINKS>();
for (const auto& link : links)
{
if (link.isValid())
{
QModelIndex insock = link.data(ROLE_INSOCK_IDX).toModelIndex();
ZASSERT_EXIT(insock.isValid());
const auto& inNodeIdx = insock.data(ROLE_NODE_IDX).toModelIndex();
if (inNodeIdx.isValid() && inNodeIdx.data(ROLE_NODE_DATACHANGED).toBool() == false)
{
_markNodeChanged(inNodeIdx);
}
}
}
}
}
}

void GraphsModel::clearNodeDataChanged()
Expand Down Expand Up @@ -1716,8 +1736,8 @@ void GraphsModel::updateNodeStatus(const QString& nodeid, STATUS_UPDATE_INFO inf
{
QModelIndex nodeIdx = index(nodeid, subgIdx);
ModelSetData(nodeIdx, info.newValue, info.role);
if (ROLE_OPTIONS == info.role)
markNodeDataChanged(nodeIdx);
//if (ROLE_OPTIONS == info.role)
// markNodeDataChanged(nodeIdx);
}

void GraphsModel::updateBlackboard(const QString &id, const QVariant &newInfo, const QModelIndex &subgIdx, bool enableTransaction)
Expand Down
Loading

0 comments on commit 1a1b4b5

Please sign in to comment.