From 177487897ff5bf96ab754a8ba8a0c1db03954bfa Mon Sep 17 00:00:00 2001 From: rachytski Date: Wed, 16 Nov 2011 17:21:08 +0400 Subject: [PATCH] fixed UpdateActualTarget problem in PartialRenderPolicy. --- android/jni/com/mapswithme/maps/Framework.cpp | 2 +- map/partial_render_policy.cpp | 48 ++++++++++++------- map/partial_render_policy.hpp | 2 + map/render_policy_mt.cpp | 4 ++ map/render_policy_st.cpp | 3 ++ map/render_queue_routine.cpp | 43 ++++++++--------- map/tiling_render_policy_mt.cpp | 5 ++ map/tiling_render_policy_st.cpp | 5 ++ qt_tstfrm/tstwidgets.cpp | 4 ++ yg/render_state.hpp | 3 ++ yg/render_state_updater.cpp | 10 ++-- yg/render_state_updater.hpp | 1 - yg/renderer.cpp | 5 ++ yg/renderer.hpp | 1 + yg/resource_manager.cpp | 26 +++++++--- yg/resource_manager.hpp | 6 ++- 16 files changed, 114 insertions(+), 54 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 798001335b..c9e02d9495 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -94,7 +94,7 @@ namespace android yg::ResourceManager::Params rmParams; rmParams.m_videoMemoryLimit = 15 * 1024 * 1024; - rmParams.m_rtTarget = yg::Rt8Bpp; + rmParams.m_rtFormat = yg::Rt8Bpp; m_work.SetRenderPolicy(new PartialRenderPolicy(m_videoTimer, params, rmParams, make_shared_ptr(new android::RenderContext()))); diff --git a/map/partial_render_policy.cpp b/map/partial_render_policy.cpp index cbf1fff0aa..d1406401f8 100644 --- a/map/partial_render_policy.cpp +++ b/map/partial_render_policy.cpp @@ -26,7 +26,8 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, sizeof(yg::gl::Vertex), 10000 * sizeof(unsigned short), sizeof(unsigned short), - 15, + 4, + true, false, 1, "primaryStorage"); @@ -35,9 +36,10 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, sizeof(yg::gl::Vertex), 4000 * sizeof(unsigned short), sizeof(unsigned short), - 100, + 4, + true, false, - 1, + 3, "smallStorage"); rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex), @@ -46,6 +48,7 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, sizeof(unsigned short), 50, true, + true, 1, "blitStorage"); @@ -55,12 +58,13 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, sizeof(unsigned short), 20, true, + true, 1, "tinyStorage"); rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, - 10, + 6, rmp.m_rtFormat, true, true, @@ -70,7 +74,7 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, - 5, + 6, rmp.m_rtFormat, true, true, @@ -88,6 +92,8 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer, rmp.m_useSingleThreadedOGL = true; rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported; + rmp.fitIntoLimits(); + m_resourceManager.reset(new yg::ResourceManager(rmp)); Platform::FilesList fonts; @@ -158,7 +164,7 @@ void PartialRenderPolicy::DrawFrame(shared_ptr const & e, if (!m_state) { m_state = screen->createState(); - m_state->m_isDebugging = true; + m_state->m_isDebugging = m_IsDebugging; } screen->getState(m_state.get()); @@ -166,7 +172,7 @@ void PartialRenderPolicy::DrawFrame(shared_ptr const & e, m_curState = m_state; unsigned cmdProcessed = 0; - unsigned const maxCmdPerFrame = 10; + unsigned const maxCmdPerFrame = 10000; while (true) { @@ -177,24 +183,29 @@ void PartialRenderPolicy::DrawFrame(shared_ptr const & e, cmdProcessed++; if (m_currentPacket.m_state) { + m_currentPacket.m_state->m_isDebugging = m_IsDebugging; m_currentPacket.m_state->apply(m_curState.get()); m_curState = m_currentPacket.m_state; } + m_currentPacket.m_command->setIsDebugging(m_IsDebugging); m_currentPacket.m_command->perform(); } else break; } - /// should we continue drawing commands on the next frame - if ((cmdProcessed == maxCmdPerFrame) && m_hasPacket) + if (m_IsDebugging) { - LOG(LINFO, ("will continue on the next frame(", cmdProcessed, ")")); - } - else - { - if (cmdProcessed != 0) - LOG(LINFO, ("finished sequence of commands(", cmdProcessed, ")")); + /// should we continue drawing commands on the next frame + if ((cmdProcessed == maxCmdPerFrame) && m_hasPacket) + { + LOG(LINFO, ("will continue on the next frame(", cmdProcessed, ")")); + } + else + { + if (cmdProcessed != 0) + LOG(LINFO, ("finished sequence of commands(", cmdProcessed, ")")); + } } { @@ -237,14 +248,17 @@ void PartialRenderPolicy::DrawFrame(shared_ptr const & e, void PartialRenderPolicy::BeginFrame(shared_ptr const & paintEvent, ScreenBase const & screenBase) { - LOG(LINFO, ("-------BeginFrame-------")); + m_IsDebugging = false; + if (m_IsDebugging) + LOG(LINFO, ("-------BeginFrame-------")); } void PartialRenderPolicy::EndFrame(shared_ptr const & paintEvent, ScreenBase const & screenBase) { m_renderQueue->renderState().m_mutex->Unlock(); - LOG(LINFO, ("-------EndFrame-------")); + if (m_IsDebugging) + LOG(LINFO, ("-------EndFrame-------")); } bool PartialRenderPolicy::NeedRedraw() const diff --git a/map/partial_render_policy.hpp b/map/partial_render_policy.hpp index fbedb2eac4..2385f5a8c4 100644 --- a/map/partial_render_policy.hpp +++ b/map/partial_render_policy.hpp @@ -27,6 +27,8 @@ private: void ProcessRenderQueue(list & renderQueue); + bool m_IsDebugging; + public: PartialRenderPolicy(VideoTimer * videoTimer, diff --git a/map/render_policy_mt.cpp b/map/render_policy_mt.cpp index 2a31ec0261..ffdf602073 100644 --- a/map/render_policy_mt.cpp +++ b/map/render_policy_mt.cpp @@ -28,6 +28,7 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 7, false, + true, 10, "primaryStorage"); @@ -37,6 +38,7 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 7, false, + true, 5, "smallStorage"); @@ -46,6 +48,7 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 7, true, + true, 1, "blitStorage"); @@ -55,6 +58,7 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 7, true, + true, 1, "tinyStorage"); diff --git a/map/render_policy_st.cpp b/map/render_policy_st.cpp index 7960803355..a0d68f0204 100644 --- a/map/render_policy_st.cpp +++ b/map/render_policy_st.cpp @@ -26,6 +26,7 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 15, false, + true, 1, "primaryStorage"); @@ -35,6 +36,7 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 100, false, + true, 1, "smallStorage"); @@ -44,6 +46,7 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 50, true, + true, 1, "blitStorage"); diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index 542d718d7c..6576257cef 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -124,6 +124,9 @@ void RenderQueueRoutine::processResize(ScreenBase const & frameScreen) /// TODO : make as a command m_renderState->m_actualScreen = frameScreen; + m_renderState->m_shadowActualTarget = m_renderState->m_actualTarget; + m_renderState->m_shadowBackBuffer = m_renderState->m_backBuffer; + m_renderState->m_isResized = false; } } @@ -386,28 +389,6 @@ void RenderQueueRoutine::Do() } } -// if (m_currentRenderCommand->m_paintEvent->isCancelled()) -// { -// /// cancelling all the commands in the queue -// if (m_glQueue) -// { -// m_glQueue->Clear(); -// -// { -// threads::ConditionGuard guard(*m_glCondition); -// if (m_glQueue->Empty()) -// guard.Wait(); -// } -// } -// -// { -// threads::MutexGuard guard(*m_renderState->m_mutex.get()); -// /// refreshing shadow parameters from the primary parameters -// m_renderState->m_shadowActualTarget = m_renderState->m_actualTarget; -// m_renderState->m_shadowBackBuffer = m_renderState->m_backBuffer; -// } -// } - /// if something were actually drawn, or (exclusive or) we are repainting the whole rect if ((!m_renderState->m_isEmptyModelCurrent) || (fullRectRepaint)) m_renderState->m_isEmptyModelActual = m_renderState->m_isEmptyModelCurrent; @@ -441,6 +422,24 @@ void RenderQueueRoutine::Do() invalidate(); } + /// waiting for all collected commands to complete. + if (m_glQueue) + { + { + threads::ConditionGuard guard(*m_glCondition); + if (!m_glQueue->Empty()) + guard.Wait(); + } + } + + { + threads::MutexGuard guard(*m_renderState->m_mutex.get()); + /// refreshing shadow parameters from the primary parameters + m_renderState->m_shadowActualTarget = m_renderState->m_actualTarget; + m_renderState->m_shadowBackBuffer = m_renderState->m_backBuffer; + } + + } // By VNG: We can't destroy render context in drawing thread. diff --git a/map/tiling_render_policy_mt.cpp b/map/tiling_render_policy_mt.cpp index a7efc36a91..b66e3927c3 100644 --- a/map/tiling_render_policy_mt.cpp +++ b/map/tiling_render_policy_mt.cpp @@ -28,6 +28,7 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 15, false, + true, 1, "primaryStorage"); @@ -37,6 +38,7 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 100, false, + true, 1, "smallStorage"); @@ -46,6 +48,7 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 50, true, + true, 1, "blitStorage"); @@ -55,6 +58,7 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 10, true, + true, 1, "multiBlitStorage"); @@ -64,6 +68,7 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer, sizeof(unsigned short), 20, true, + true, 1, "tinyStorage"); diff --git a/map/tiling_render_policy_st.cpp b/map/tiling_render_policy_st.cpp index 786b94da9c..1241357302 100644 --- a/map/tiling_render_policy_st.cpp +++ b/map/tiling_render_policy_st.cpp @@ -30,6 +30,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 15, false, + true, 1, "primaryStorage"); @@ -39,6 +40,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 100, false, + true, 1, "smallStorage"); @@ -48,6 +50,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 50, true, + true, 1, "blitStorage"); @@ -57,6 +60,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 10, true, + true, 1, "multiBlitStorage"); @@ -66,6 +70,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(unsigned short), 20, true, + true, 1, "tinyStorage"); diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index f117ac8f01..01e1ae7b39 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -51,6 +51,7 @@ void GLDrawWidget::initializeGL() sizeof(unsigned short), 20, false, + true, 1, "primaryStorage"); @@ -60,6 +61,7 @@ void GLDrawWidget::initializeGL() sizeof(unsigned short), 100, false, + true, 1, "smallStorage"); @@ -69,6 +71,7 @@ void GLDrawWidget::initializeGL() sizeof(unsigned short), 30, true, + true, 1, "blitStorage"); @@ -78,6 +81,7 @@ void GLDrawWidget::initializeGL() sizeof(unsigned short), 10, true, + true, 1, "multiBlitStorage"); diff --git a/yg/render_state.hpp b/yg/render_state.hpp index b2ed3421e4..127a3b043a 100644 --- a/yg/render_state.hpp +++ b/yg/render_state.hpp @@ -51,6 +51,9 @@ namespace yg bool m_isEmptyModelCurrent; /// @} + shared_ptr m_shadowActualTarget; + shared_ptr m_shadowBackBuffer; + /// Surface height and width. unsigned int m_surfaceWidth; unsigned int m_surfaceHeight; diff --git a/yg/render_state_updater.cpp b/yg/render_state_updater.cpp index b18fc25f04..4ed863b107 100644 --- a/yg/render_state_updater.cpp +++ b/yg/render_state_updater.cpp @@ -78,9 +78,9 @@ namespace yg OGLCHECK(glClear(GL_COLOR_BUFFER_BIT)); shared_ptr immDrawTexturedRect( - new IMMDrawTexturedRect(m2::RectF(0, 0, m_actualTarget->width(), m_actualTarget->height()), + new IMMDrawTexturedRect(m2::RectF(0, 0, m_renderState->m_actualTarget->width(), m_renderState->m_actualTarget->height()), m2::RectF(0, 0, 1, 1), - m_actualTarget, + m_renderState->m_actualTarget, m_resourceManager)); immDrawTexturedRect->perform(); @@ -106,6 +106,8 @@ namespace yg m_renderState->m_mutex->Lock(); + swap(m_renderState->m_shadowActualTarget, m_renderState->m_shadowBackBuffer); + shared_ptr command(new UpdateActualTarget()); command->m_renderState = m_renderState; command->m_currentScreen = m_renderState->m_currentScreen; @@ -114,7 +116,7 @@ namespace yg processCommand(command); shared_ptr command1(new UpdateBackBuffer()); - command1->m_actualTarget = m_renderState->m_actualTarget; + command1->m_renderState = m_renderState; command1->m_resourceManager = resourceManager(); command1->m_isClipRectEnabled = clipRectEnabled(); @@ -122,7 +124,7 @@ namespace yg /// blitting will be performed through /// non-multisampled framebuffer for the sake of speed - setRenderTarget(m_renderState->m_backBuffer); + setRenderTarget(m_renderState->m_shadowBackBuffer); m_renderState->m_mutex->Unlock(); diff --git a/yg/render_state_updater.hpp b/yg/render_state_updater.hpp index c19cb5db23..476a873717 100644 --- a/yg/render_state_updater.hpp +++ b/yg/render_state_updater.hpp @@ -36,7 +36,6 @@ namespace yg struct UpdateBackBuffer : base_t::Command { - shared_ptr m_actualTarget; shared_ptr m_renderState; shared_ptr m_resourceManager; bool m_isClipRectEnabled; diff --git a/yg/renderer.cpp b/yg/renderer.cpp index 6a0eae66c0..e0a5f18b56 100644 --- a/yg/renderer.cpp +++ b/yg/renderer.cpp @@ -23,6 +23,11 @@ namespace yg return m_isDebugging; } + void Renderer::Command::setIsDebugging(bool flag) + { + m_isDebugging = flag; + } + Renderer::Command::Command() : m_isDebugging(false) {} diff --git a/yg/renderer.hpp b/yg/renderer.hpp index 468c42fe94..2cc685703a 100644 --- a/yg/renderer.hpp +++ b/yg/renderer.hpp @@ -46,6 +46,7 @@ namespace yg public: bool isDebugging() const; + void setIsDebugging(bool flag); Command(); diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index bc589f4832..4be59ecec0 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -74,7 +74,8 @@ namespace yg m_ibSize(0), m_indexSize(0), m_storagesCount(0), - m_isFixed(true), + m_isFixedBufferSize(true), + m_isFixedBufferCount(true), m_scalePriority(0), m_poolName(poolName) {} @@ -84,7 +85,8 @@ namespace yg size_t ibSize, size_t indexSize, size_t storagesCount, - bool isFixed, + bool isFixedBufferSize, + bool isFixedBufferCount, int scalePriority, string const & poolName) : m_vbSize(vbSize), @@ -92,14 +94,15 @@ namespace yg m_ibSize(ibSize), m_indexSize(indexSize), m_storagesCount(storagesCount), - m_isFixed(isFixed), + m_isFixedBufferSize(isFixedBufferSize), + m_isFixedBufferCount(isFixedBufferCount), m_scalePriority(scalePriority), m_poolName(poolName) {} bool ResourceManager::StoragePoolParams::isFixed() const { - return m_isFixed; + return m_isFixedBufferSize && m_isFixedBufferCount; } bool ResourceManager::StoragePoolParams::isValid() const @@ -117,11 +120,20 @@ namespace yg int oldMemoryUsage = memoryUsage(); int oldVBSize = m_vbSize; int oldIBSize = m_ibSize; + int oldStoragesCount = m_storagesCount; + + if (!m_isFixedBufferSize) + { + m_vbSize *= k; + m_ibSize *= k; + k = 1; + } + + if (!m_isFixedBufferCount) + m_storagesCount *= k; - m_vbSize *= k; - m_ibSize *= k; LOG(LINFO, ("resizing ", m_poolName)); - LOG(LINFO, (" from : ", oldVBSize / m_vertexSize, " vertices, ", oldIBSize / m_indexSize, " indices, ", m_storagesCount, " storages, ", oldMemoryUsage, " bytes total")); + LOG(LINFO, (" from : ", oldVBSize / m_vertexSize, " vertices, ", oldIBSize / m_indexSize, " indices, ", oldStoragesCount, " storages, ", oldMemoryUsage, " bytes total")); LOG(LINFO, (" to : ", m_vbSize / m_vertexSize, " vertices, ", m_ibSize / m_indexSize, " indices, ", m_storagesCount, " storages, ", memoryUsage(), " bytes total")); } diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index b503086188..14f354f33f 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -80,7 +80,8 @@ namespace yg size_t m_indexSize; size_t m_storagesCount; - bool m_isFixed; + bool m_isFixedBufferSize; + bool m_isFixedBufferCount; int m_scalePriority; double m_scaleFactor; @@ -92,7 +93,8 @@ namespace yg size_t ibSize, size_t indexSize, size_t storagesCount, - bool isFixed, + bool isFixedBufferSize, + bool isFixedBufferCount, int scalePriority, string const & poolName);