diff options
Diffstat (limited to 'indra/newview/llscenemonitor.cpp')
-rw-r--r-- | indra/newview/llscenemonitor.cpp | 357 |
1 files changed, 212 insertions, 145 deletions
diff --git a/indra/newview/llscenemonitor.cpp b/indra/newview/llscenemonitor.cpp index c592fd0a38..f744a924f5 100644 --- a/indra/newview/llscenemonitor.cpp +++ b/indra/newview/llscenemonitor.cpp @@ -50,36 +50,30 @@ LLSceneMonitorView* gSceneMonitorView = NULL; //2, (?) disable all sky and water; //3, capture frames periodically, by calling "capture()"; //4, compute pixel differences between two latest captured frames, by calling "compare()", results are stored at mDiff; -//5, compute the number of pixels in mDiff above some tolerance threshold in GPU, by calling "queryDiff() -> calcDiffAggregate()"; +//5, compute the number of pixels in mDiff above some tolerance threshold in GPU, by calling "calcDiffAggregate()"; //6, use gl occlusion query to fetch the result from GPU, by calling "fetchQueryResult()"; //END. // LLSceneMonitor::LLSceneMonitor() : - mEnabled(FALSE), + mEnabled(false), mDiff(NULL), mDiffResult(0.f), mDiffTolerance(0.1f), - mCurTarget(NULL), - mNeedsUpdateDiff(FALSE), - mHasNewDiff(FALSE), - mHasNewQueryResult(FALSE), - mDebugViewerVisible(FALSE), - mQuitting(FALSE), + mDiffState(WAITING_FOR_NEXT_DIFF), + mDebugViewerVisible(false), mQueryObject(0), - mSamplingTime(1.0f), mDiffPixelRatio(0.5f) { mFrames[0] = NULL; mFrames[1] = NULL; - mRecording = new LLTrace::ExtendableRecording(); - mRecording->start(); + mRecording = new LLTrace::ExtendablePeriodicRecording(); } LLSceneMonitor::~LLSceneMonitor() { - mQuitting = TRUE; + mDiffState = VIEWER_QUITTING; destroyClass(); } @@ -101,7 +95,8 @@ void LLSceneMonitor::reset() mFrames[0] = NULL; mFrames[1] = NULL; mDiff = NULL; - mCurTarget = NULL; + + mRecording->reset(); unfreezeScene(); @@ -173,54 +168,15 @@ void LLSceneMonitor::generateDitheringTexture(S32 width, S32 height) mDitherScaleT = (F32)height / mDitherMatrixWidth; } -void LLSceneMonitor::setDebugViewerVisible(BOOL visible) +void LLSceneMonitor::setDebugViewerVisible(bool visible) { mDebugViewerVisible = visible; } -bool LLSceneMonitor::preCapture() +LLRenderTarget& LLSceneMonitor::getCaptureTarget() { - static LLCachedControl<bool> monitor_enabled(gSavedSettings,"SceneLoadingMonitorEnabled"); - static LLFrameTimer timer; - - mCurTarget = NULL; - if (!LLGLSLShader::sNoFixedFunction) - { - return false; - } - - BOOL enabled = (BOOL)monitor_enabled || mDebugViewerVisible; - if(mEnabled != enabled) - { - if(mEnabled) - { - reset(); - unfreezeScene(); - } - else - { - freezeScene(); - } - - mEnabled = enabled; - } - - if(!mEnabled) - { - return false; - } + LLRenderTarget* cur_target = NULL; - if(gAgent.isPositionChanged()) - { - mRecording->reset(); - } - - if(timer.getElapsedTimeF32() < mSamplingTime) - { - return false; - } - timer.reset(); - S32 width = gViewerWindow->getWorldViewWidthRaw(); S32 height = gViewerWindow->getWorldViewHeightRaw(); @@ -232,7 +188,7 @@ bool LLSceneMonitor::preCapture() gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - mCurTarget = mFrames[0]; + cur_target = mFrames[0]; } else if(!mFrames[1]) { @@ -242,21 +198,22 @@ bool LLSceneMonitor::preCapture() gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - mCurTarget = mFrames[1]; + cur_target = mFrames[1]; } else //swap { - mCurTarget = mFrames[0]; + cur_target = mFrames[0]; mFrames[0] = mFrames[1]; - mFrames[1] = mCurTarget; + mFrames[1] = cur_target; } - if(mCurTarget->getWidth() != width || mCurTarget->getHeight() != height) //size changed + if(cur_target->getWidth() != width || cur_target->getHeight() != height) //size changed { - mCurTarget->resize(width, height, GL_RGB); + cur_target->resize(width, height, GL_RGB); } - return true; + // we're promising the target exists + return *cur_target; } void LLSceneMonitor::freezeAvatar(LLCharacter* avatarp) @@ -289,7 +246,7 @@ void LLSceneMonitor::unfreezeScene() //thaw all avatars mAvatarPauseHandles.clear(); - if(mQuitting) + if(mDiffState == VIEWER_QUITTING) { return; //we are quitting viewer. } @@ -308,61 +265,95 @@ void LLSceneMonitor::unfreezeScene() void LLSceneMonitor::capture() { static U32 last_capture_time = 0; + static LLCachedControl<bool> monitor_enabled(gSavedSettings, "SceneLoadingMonitorEnabled"); + static LLCachedControl<F32> scene_load_sample_time(gSavedSettings, "SceneLoadingMonitorSampleTime"); + static LLFrameTimer timer; - if(last_capture_time == gFrameCount) + LLTrace::Recording& last_frame_recording = LLTrace::get_frame_recording().getLastRecording(); + if (mEnabled + && (last_frame_recording.getSum(*LLViewerCamera::getVelocityStat()) > 0.001f + || last_frame_recording.getSum(*LLViewerCamera::getAngularVelocityStat()) > 0.01f)) { - return; + reset(); + freezeScene(); } - last_capture_time = gFrameCount; - - preCapture(); - if(!mCurTarget) + bool enabled = monitor_enabled || mDebugViewerVisible; + if(mEnabled != enabled) { - return; + if(mEnabled) + { + unfreezeScene(); + } + else + { + reset(); + freezeScene(); + } + + mEnabled = enabled; } - - U32 old_FBO = LLRenderTarget::sCurFBO; - gGL.getTexUnit(0)->bind(mCurTarget); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); //point to the main frame buffer. + if(timer.getElapsedTimeF32() > scene_load_sample_time() + && mEnabled + && LLGLSLShader::sNoFixedFunction + && last_capture_time != gFrameCount) + { + mRecording->resume(); + + timer.reset(); + + last_capture_time = gFrameCount; + + LLRenderTarget& cur_target = getCaptureTarget(); + + U32 old_FBO = LLRenderTarget::sCurFBO; + + gGL.getTexUnit(0)->bind(&cur_target); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); //point to the main frame buffer. - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, mCurTarget->getWidth(), mCurTarget->getHeight()); //copy the content + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, cur_target.getWidth(), cur_target.getHeight()); //copy the content - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glBindFramebuffer(GL_FRAMEBUFFER, old_FBO); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, old_FBO); - mCurTarget = NULL; - mNeedsUpdateDiff = TRUE; + mDiffState = NEED_DIFF; + } } bool LLSceneMonitor::needsUpdate() const { - return mNeedsUpdateDiff; + return mDiffState == NEED_DIFF; } +static LLFastTimer::DeclareTimer FTM_GENERATE_SCENE_LOAD_DITHER_TEXTURE("Generate Scene Load Dither Texture"); +static LLFastTimer::DeclareTimer FTM_SCENE_LOAD_IMAGE_DIFF("Scene Load Image Diff"); + void LLSceneMonitor::compare() { - if(!mNeedsUpdateDiff) + if(mDiffState != NEED_DIFF) { return; } - mNeedsUpdateDiff = FALSE; if(!mFrames[0] || !mFrames[1]) { return; } if(mFrames[0]->getWidth() != mFrames[1]->getWidth() || mFrames[0]->getHeight() != mFrames[1]->getHeight()) - { - return; //size does not match + { //size does not match + return; } + LLFastTimer _(FTM_SCENE_LOAD_IMAGE_DIFF); + mDiffState = EXECUTE_DIFF; + S32 width = gViewerWindow->getWindowWidthRaw(); S32 height = gViewerWindow->getWindowHeightRaw(); if(!mDiff) { + LLFastTimer _(FTM_GENERATE_SCENE_LOAD_DITHER_TEXTURE); mDiff = new LLRenderTarget(); mDiff->allocate(width, height, GL_RGBA, false, false, LLTexUnit::TT_TEXTURE, true); @@ -370,6 +361,7 @@ void LLSceneMonitor::compare() } else if(mDiff->getWidth() != width || mDiff->getHeight() != height) { + LLFastTimer _(FTM_GENERATE_SCENE_LOAD_DITHER_TEXTURE); mDiff->resize(width, height, GL_RGBA); generateDitheringTexture(width, height); } @@ -411,26 +403,18 @@ void LLSceneMonitor::compare() gGL.getTexUnit(2)->disable(); gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE); - mHasNewDiff = TRUE; - - //send out the query request. - queryDiff(); -} - -void LLSceneMonitor::queryDiff() -{ - if(mDebugViewerVisible) + if (!mDebugViewerVisible) { - return; + calcDiffAggregate(); } - - calcDiffAggregate(); } //calculate Diff aggregate information in GPU, and enable gl occlusion query to capture it. void LLSceneMonitor::calcDiffAggregate() { - if(!mHasNewDiff && !mDebugViewerVisible) + LLFastTimer _(FTM_SCENE_LOAD_IMAGE_DIFF); + + if(mDiffState != EXECUTE_DIFF && !mDebugViewerVisible) { return; } @@ -452,18 +436,17 @@ void LLSceneMonitor::calcDiffAggregate() gOneTextureFilterProgram.bind(); gOneTextureFilterProgram.uniform1f("tolerance", mDiffTolerance); - if(mHasNewDiff) + if(mDiffState == EXECUTE_DIFF) { glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryObject); } gl_draw_scaled_target(0, 0, S32(mDiff->getWidth() * mDiffPixelRatio), S32(mDiff->getHeight() * mDiffPixelRatio), mDiff); - if(mHasNewDiff) + if(mDiffState == EXECUTE_DIFF) { glEndQueryARB(GL_SAMPLES_PASSED_ARB); - mHasNewDiff = FALSE; - mHasNewQueryResult = TRUE; + mDiffState = WAIT_ON_RESULT; } gOneTextureFilterProgram.unbind(); @@ -482,67 +465,155 @@ void LLSceneMonitor::calcDiffAggregate() static LLTrace::MeasurementStatHandle<> sFramePixelDiff("FramePixelDifference"); void LLSceneMonitor::fetchQueryResult() { - if(!mHasNewQueryResult) - { - return; - } - mHasNewQueryResult = FALSE; + LLFastTimer _(FTM_SCENE_LOAD_IMAGE_DIFF); - GLuint available = 0; - glGetQueryObjectuivARB(mQueryObject, GL_QUERY_RESULT_AVAILABLE_ARB, &available); - if(!available) + if(mDiffState == WAIT_ON_RESULT) { - return; - } + mDiffState = WAITING_FOR_NEXT_DIFF; - GLuint count = 0; - glGetQueryObjectuivARB(mQueryObject, GL_QUERY_RESULT_ARB, &count); + GLuint available = 0; + glGetQueryObjectuivARB(mQueryObject, GL_QUERY_RESULT_AVAILABLE_ARB, &available); + if(available) + { + GLuint count = 0; + glGetQueryObjectuivARB(mQueryObject, GL_QUERY_RESULT_ARB, &count); - mDiffResult = count * 0.5f / (mDiff->getWidth() * mDiff->getHeight() * mDiffPixelRatio * mDiffPixelRatio); //0.5 -> (front face + back face) - - addMonitorResult(); + mDiffResult = count * 0.5f / (mDiff->getWidth() * mDiff->getHeight() * mDiffPixelRatio * mDiffPixelRatio); //0.5 -> (front face + back face) + + LL_DEBUGS("SceneMonitor") << "Frame difference: " << std::setprecision(4) << mDiffResult << LL_ENDL; + sample(sFramePixelDiff, mDiffResult); + + static LLCachedControl<F32> diff_threshold(gSavedSettings,"SceneLoadingPixelDiffThreshold"); + if(mDiffResult > diff_threshold()) + { + mRecording->extend(); + } + else + { + mRecording->getPotentialRecording().nextPeriod(); + } + } + } } -void LLSceneMonitor::addMonitorResult() +//dump results to a file _scene_xmonitor_results.csv +void LLSceneMonitor::dumpToFile(std::string file_name) { - const F32 diff_threshold = 0.001f; - if(mDiffResult < diff_threshold) + LL_INFOS("SceneMonitor") << "Saving scene load stats to " << file_name << LL_ENDL; + + std::ofstream os(file_name.c_str()); + + //total scene loading time + os << std::setprecision(4); + + LLTrace::PeriodicRecording& scene_load_recording = mRecording->getAcceptedRecording(); + U32 frame_count = scene_load_recording.getNumPeriods(); + + LLUnit<LLUnits::Seconds, F64> frame_time; + + os << "Stat"; + for (S32 frame = 0; frame < frame_count; frame++) { - return; + frame_time += scene_load_recording.getPrevRecording(frame_count - frame).getDuration(); + os << ", " << frame_time.value(); } + os << std::endl; + + for (LLTrace::CountStatHandle<F64>::instance_iter it = LLTrace::CountStatHandle<F64>::beginInstances(), end_it = LLTrace::CountStatHandle<F64>::endInstances(); + it != end_it; + ++it) + { + std::ostringstream row; + row << it->getName(); - mRecording->extend(); - sample(sFramePixelDiff, mDiffResult); + S32 samples = 0; - ll_monitor_result_t result; - result.mTimeStamp = LLImageGL::sLastFrameTime; - result.mDiff = mDiffResult; - mMonitorResults.push_back(result); + for (S32 i = frame_count - 1; i >= 0; --i) + { + samples += scene_load_recording.getPrevRecording(i).getSampleCount(*it); + row << ", " << scene_load_recording.getPrevRecording(i).getSum(*it); + } + + row << std::endl; + + if (samples > 0) + { + os << row.str(); + } } -//dump results to a file _scene_monitor_results.csv -void LLSceneMonitor::dumpToFile(std::string file_name) -{ - if(mMonitorResults.empty() || !getRecording()) + for (LLTrace::CountStatHandle<S64>::instance_iter it = LLTrace::CountStatHandle<S64>::beginInstances(), end_it = LLTrace::CountStatHandle<S64>::endInstances(); + it != end_it; + ++it) { - return; //nothing to dump + std::ostringstream row; + row << it->getName(); + + S32 samples = 0; + + for (S32 i = frame_count - 1; i >= 0; --i) + { + samples += scene_load_recording.getPrevRecording(i).getSampleCount(*it); + row << ", " << scene_load_recording.getPrevRecording(i).getSum(*it); + } + + row << std::endl; + + if (samples > 0) + { + os << row.str(); + } } - std::ofstream os(file_name.c_str()); + for (LLTrace::MeasurementStatHandle<F64>::instance_iter it = LLTrace::MeasurementStatHandle<F64>::beginInstances(), end_it = LLTrace::MeasurementStatHandle<F64>::endInstances(); + it != end_it; + ++it) + { + std::ostringstream row; + row << it->getName(); - //total scene loading time - os << llformat("Scene Loading time: %.4f seconds\n", (F32)getRecording()->getAcceptedRecording().getDuration().value()); + S32 samples = 0; + + for (S32 i = frame_count - 1; i >= 0; --i) + { + samples += scene_load_recording.getPrevRecording(i).getSampleCount(*it); + row << ", " << scene_load_recording.getPrevRecording(i).getMean(*it); + } - S32 num_results = mMonitorResults.size(); - for(S32 i = 0; i < num_results; i++) + row << std::endl; + + if (samples > 0) + { + os << row.str(); + } + } + + for (LLTrace::MeasurementStatHandle<S64>::instance_iter it = LLTrace::MeasurementStatHandle<S64>::beginInstances(), end_it = LLTrace::MeasurementStatHandle<S64>::endInstances(); + it != end_it; + ++it) { - os << llformat("%.4f %.4f\n", mMonitorResults[i].mTimeStamp, mMonitorResults[i].mDiff); + std::ostringstream row; + row << it->getName(); + + S32 samples = 0; + + for (S32 i = frame_count - 1; i >= 0; --i) + { + samples += scene_load_recording.getPrevRecording(i).getSampleCount(*it); + row << ", " << scene_load_recording.getPrevRecording(i).getMean(*it); + } + + row << std::endl; + + if (samples > 0) + { + os << row.str(); + } } os.flush(); os.close(); - mMonitorResults.clear(); } //------------------------------------------------------------------------------------------------------------- @@ -563,12 +634,10 @@ void LLSceneMonitorView::onClickCloseBtn() setVisible(false); } -void LLSceneMonitorView::setVisible(BOOL visible) +void LLSceneMonitorView::onVisibilityChange(BOOL visible) { visible = visible && LLGLSLShader::sNoFixedFunction; LLSceneMonitor::getInstance()->setDebugViewerVisible(visible); - - LLView::setVisible(visible); } void LLSceneMonitorView::draw() @@ -582,8 +651,6 @@ void LLSceneMonitorView::draw() F32 ratio = LLSceneMonitor::getInstance()->getDiffPixelRatio(); S32 height = (S32)(target->getHeight() * ratio); S32 width = (S32)(target->getWidth() * ratio); - //S32 height = (S32) (gViewerWindow->getWindowRectScaled().getHeight()*0.5f); - //S32 width = (S32) (gViewerWindow->getWindowRectScaled().getWidth() * 0.5f); LLRect new_rect; new_rect.setLeftTopAndSize(getRect().mLeft, getRect().mTop, width, height); @@ -608,7 +675,7 @@ void LLSceneMonitorView::draw() LLFontGL::getFontMonospace()->renderUTF8(num_str, 0, 5, getRect().getHeight() - line_height * lines, color, LLFontGL::LEFT, LLFontGL::TOP); lines++; - num_str = llformat("Sampling time: %.3f seconds", LLSceneMonitor::getInstance()->getSamplingTime()); + num_str = llformat("Sampling time: %.3f seconds", gSavedSettings.getF32("SceneLoadingMonitorSampleTime")); LLFontGL::getFontMonospace()->renderUTF8(num_str, 0, 5, getRect().getHeight() - line_height * lines, color, LLFontGL::LEFT, LLFontGL::TOP); lines++; |