Skip to content

Commit

Permalink
do not rerun in always mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqidong committed Aug 3, 2023
1 parent 1cee428 commit 8f87407
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ui/zenoedit/cache/zcachemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions ui/zenoedit/cache/zcachemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions ui/zenoedit/dock/docktabcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout)
QObject::connect(m_btnAlways, &ZComboBox::_textActivated, [=](const QString &text) {
std::shared_ptr<ZCacheMgr> mgr = zenoApp->getMainWindow()->cacheMgr();
ZASSERT_EXIT(mgr);
mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOn);
ZenoMainWindow *pMainWin = zenoApp->getMainWindow();
ZASSERT_EXIT(pMainWin);
std::function<void()> resetAlways = [=]() {
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
20 changes: 10 additions & 10 deletions ui/zenoedit/zenomainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,29 +648,29 @@ void ZenoMainWindow::initTimelineDock()
connect(graphs, &GraphsManagment::modelDataChanged, this, [=]() {
std::shared_ptr<ZCacheMgr> mgr = zenoApp->getMainWindow()->cacheMgr();
ZASSERT_EXIT(mgr);
mgr->setCacheOpt(ZCacheMgr::Opt_AlwaysOn);
m_pTimeline->togglePlayButton(false);
int nFrame = m_pTimeline->value();
QVector<DisplayWidget *> views = viewports();
std::function<void(bool, bool)> setOptixUpdateSeparately = [=](bool updateLightCameraOnly, bool updateMatlOnly) {
QVector<DisplayWidget *> 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;
AppHelper::initLaunchCacheParam(launchParam);
view->onRun(launchParam);
}
else if (m_bAlwaysLightCamera || m_bAlwaysMaterial) {
std::function<void(bool, bool)> setOptixUpdateSeparately = [=](bool updateLightCameraOnly, bool updateMatlOnly) {
QVector<DisplayWidget *> 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;
Expand Down
6 changes: 2 additions & 4 deletions zeno/src/extra/GlobalComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
50 changes: 43 additions & 7 deletions zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("optix_show_background", false);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -763,6 +773,23 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy {
};

std::set<std::string> cachedMeshesMaterials, cachedSphereMaterials;
std::map<std::string, int> cachedMeshMatLUT;
bool meshMatLUTChanged(std::map<std::string, int>& 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)
{
Expand Down Expand Up @@ -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<std::string, int>().swap(cachedMeshMatLUT);
cachedMeshMatLUT = meshMatLUT;
}

if (meshNeedUpdate || bMeshMatLUTChanged)
{

OptixUtil::logInfoVRAM("Before update Mesh");

if(staticNeedUpdate)
Expand Down

0 comments on commit 8f87407

Please sign in to comment.