diff --git a/ui/zenoedit/cache/zcachemgr.cpp b/ui/zenoedit/cache/zcachemgr.cpp index 16cd5af4f2..0b8a105b19 100644 --- a/ui/zenoedit/cache/zcachemgr.cpp +++ b/ui/zenoedit/cache/zcachemgr.cpp @@ -10,7 +10,7 @@ ZCacheMgr::ZCacheMgr() bool ZCacheMgr::initCacheDir(bool bTempDir, QDir dirCacheRoot) { - if (!m_isNew && (m_cacheOpt == Opt_RunLightCameraMaterial || m_cacheOpt == Opt_AlwaysOnLightCameraMaterial)) { + if (!m_isNew && (m_cacheOpt == Opt_RunLightCameraMaterial || m_cacheOpt == Opt_AlwaysOn)) { return true; } m_bTempDir = bTempDir; diff --git a/ui/zenoedit/cache/zcachemgr.h b/ui/zenoedit/cache/zcachemgr.h index 5fc1216dfb..d693a8e908 100644 --- a/ui/zenoedit/cache/zcachemgr.h +++ b/ui/zenoedit/cache/zcachemgr.h @@ -16,8 +16,7 @@ class ZCacheMgr Opt_Undefined = 0, Opt_RunAll, Opt_RunLightCameraMaterial, - Opt_AlwaysOnAll, - Opt_AlwaysOnLightCameraMaterial + Opt_AlwaysOn }; void setCacheOpt(cacheOption opt); void setNewCacheDir(bool setNew); diff --git a/ui/zenoedit/dock/docktabcontent.cpp b/ui/zenoedit/dock/docktabcontent.cpp index a691bbc60f..8bdecf79ce 100644 --- a/ui/zenoedit/dock/docktabcontent.cpp +++ b/ui/zenoedit/dock/docktabcontent.cpp @@ -344,6 +344,7 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) QObject::connect(m_btnAlways, &ZComboBox::_textActivated, [=](const QString &text) { std::shared_ptr mgr = zenoApp->getMainWindow()->cacheMgr(); ZASSERT_EXIT(mgr); + mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOn); ZenoMainWindow *pMainWin = zenoApp->getMainWindow(); ZASSERT_EXIT(pMainWin); std::function resetAlways = [=]() { @@ -360,10 +361,8 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) connect(zenoApp->graphsManagment(), &GraphsManagment::modelInited, this, resetAlways); if (text == tr("alwaysAll")) { - mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOnAll); pMainWin->setAlways(true); pMainWin->setAlwaysLightCameraMaterial(false, false); - pMainWin->onRunTriggered(); } else if (text == tr("alwaysLightCamera") || text == tr("alwaysMaterial")) { QSettings settings(zsCompanyName, zsEditor); @@ -376,13 +375,10 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout) } else if (text == tr("alwaysMaterial")) { pMainWin->setAlwaysLightCameraMaterial(false, true); } - mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOnAll); pMainWin->setAlways(false); - pMainWin->onRunTriggered(); } } else { - mgr->setCacheOpt(ZCacheMgr::Opt_Undefined); pMainWin->setAlways(false); pMainWin->setAlwaysLightCameraMaterial(false, false); } diff --git a/ui/zenoedit/zenomainwindow.cpp b/ui/zenoedit/zenomainwindow.cpp index 1ef3127011..a2b60c66bb 100644 --- a/ui/zenoedit/zenomainwindow.cpp +++ b/ui/zenoedit/zenomainwindow.cpp @@ -648,12 +648,21 @@ void ZenoMainWindow::initTimelineDock() connect(graphs, &GraphsManagment::modelDataChanged, this, [=]() { std::shared_ptr mgr = zenoApp->getMainWindow()->cacheMgr(); ZASSERT_EXIT(mgr); + mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOn); m_pTimeline->togglePlayButton(false); int nFrame = m_pTimeline->value(); QVector views = viewports(); + std::function setOptixUpdateSeparately = [=](bool updateLightCameraOnly, bool updateMatlOnly) { + QVector views = viewports(); + for (auto displayWid : views) { + if (!displayWid->isGLViewport()) { + displayWid->setRenderSeparately(updateLightCameraOnly, updateMatlOnly); + } + } + }; for (DisplayWidget *view : views) { if (m_bAlways) { - mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOnAll); + setOptixUpdateSeparately(false, false); LAUNCH_PARAM launchParam; launchParam.beginFrame = nFrame; launchParam.endFrame = nFrame; @@ -661,16 +670,7 @@ void ZenoMainWindow::initTimelineDock() view->onRun(launchParam); } else if (m_bAlwaysLightCamera || m_bAlwaysMaterial) { - std::function setOptixUpdateSeparately = [=](bool updateLightCameraOnly, bool updateMatlOnly) { - QVector views = viewports(); - for (auto displayWid : views) { - if (!displayWid->isGLViewport()) { - displayWid->setRenderSeparately(updateLightCameraOnly, updateMatlOnly); - } - } - }; setOptixUpdateSeparately(m_bAlwaysLightCamera, m_bAlwaysMaterial); - mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOnLightCameraMaterial); LAUNCH_PARAM launchParam; launchParam.beginFrame = nFrame; launchParam.endFrame = nFrame; diff --git a/zeno/src/extra/GlobalComm.cpp b/zeno/src/extra/GlobalComm.cpp index d9566dd674..0796e8485b 100644 --- a/zeno/src/extra/GlobalComm.cpp +++ b/zeno/src/extra/GlobalComm.cpp @@ -93,10 +93,8 @@ static void toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &o size_t currentFrameSize = 0; for (int i = 0; i < 3; i++) { - if (poses[i].size() == 0) - { + if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1)) continue; - } keys[i].push_back('\a'); keys[i] = "ZENCACHE" + std::to_string(poses[i].size()) + keys[i]; poses[i].push_back(bufCaches[i].size()); @@ -126,7 +124,7 @@ static void toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &o } for (int i = 0; i < 3; i++) { - if (poses[i].size() == 0) + if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1)) continue; log_critical("dump cache to disk {}", cachepath[i]); std::ofstream ofs(cachepath[i], std::ios::binary); diff --git a/zenovis/src/optx/RenderEngineOptx.cpp b/zenovis/src/optx/RenderEngineOptx.cpp index 928fa6da2e..8111bcd06d 100644 --- a/zenovis/src/optx/RenderEngineOptx.cpp +++ b/zenovis/src/optx/RenderEngineOptx.cpp @@ -570,14 +570,18 @@ struct GraphicsManager { bool changelight = false; for (auto const &[key, obj] : objs) { - if (scene->drawOptions->updateMatlOnly && ins.may_emplace(key)) - { - changelight = false; - } - else if(ins.may_emplace(key)) { + if(ins.may_emplace(key)) { changelight = true; } } + { //when turn off last node in always mode + static int objsNum = 0; + if (objsNum > objs.size() && !changelight) + changelight = true; + objsNum = objs.size(); + if (scene->drawOptions->updateMatlOnly) + changelight = false; + } auto &ud = zeno::getSession().userData(); bool show_background = ud.get2("optix_show_background", false); @@ -667,6 +671,12 @@ struct GraphicsManager { ins.try_emplace(key, std::move(ig)); } } + { //when turn off last node in always mode + static int objsNum = 0; + if (objsNum > objs.size() && !changed) + changed = true; + objsNum = objs.size(); + } // return ins.has_changed(); return changed; } @@ -763,6 +773,23 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy { }; std::set cachedMeshesMaterials, cachedSphereMaterials; + std::map cachedMeshMatLUT; + bool meshMatLUTChanged(std::map& newLUT) { + bool changed = false; + if (cachedMeshMatLUT.size() != newLUT.size()) { + changed = true; + } + else { + for (auto const& [matkey, matidx] : newLUT) + { + if (cachedMeshMatLUT.count(matkey) == 0) + changed = true; + else if (cachedMeshMatLUT[matkey] != newLUT[matkey]) + changed = true; + } + } + return changed; + } void ensure_shadtmpl(ShaderTemplateInfo &_template) { @@ -1077,9 +1104,18 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy { xinxinoptix::SpheresCrowded.sbt_count = _sphere_shader_list.size(); OptixUtil::matIDtoShaderIndex = matIDtoShaderIndex; - if (meshNeedUpdate) + bool bMeshMatLUTChanged = false; //if meshMatLUT need update + if (scene->drawOptions->updateMatlOnly) { + bMeshMatLUTChanged = meshMatLUTChanged(meshMatLUT); + } + if (bMeshMatLUTChanged || matNeedUpdate && (staticNeedUpdate || meshNeedUpdate)) { + std::map().swap(cachedMeshMatLUT); + cachedMeshMatLUT = meshMatLUT; + } + + if (meshNeedUpdate || bMeshMatLUTChanged) { - + OptixUtil::logInfoVRAM("Before update Mesh"); if(staticNeedUpdate)