diff --git a/drape_frontend/CMakeLists.txt b/drape_frontend/CMakeLists.txt index 3682aadc0d..918b4c8e84 100644 --- a/drape_frontend/CMakeLists.txt +++ b/drape_frontend/CMakeLists.txt @@ -53,8 +53,6 @@ set( backend_renderer.hpp base_renderer.cpp base_renderer.hpp - batch_merge_helper.cpp - batch_merge_helper.hpp batchers_pool.hpp circles_pack_shape.cpp circles_pack_shape.hpp diff --git a/drape_frontend/batch_merge_helper.cpp b/drape_frontend/batch_merge_helper.cpp deleted file mode 100644 index f93f75a99e..0000000000 --- a/drape_frontend/batch_merge_helper.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include "drape_frontend/batch_merge_helper.hpp" - -#include "shaders/program_manager.hpp" - -#include "drape/glextensions_list.hpp" -#include "drape/render_bucket.hpp" -#include "drape/vertex_array_buffer.hpp" - -#include -#include - -namespace df -{ -void ReadBufferData(void * dst, glConst target, uint32_t size) -{ -#ifdef OMIM_OS_DESKTOP - void * bufferPointer = GLFunctions::glMapBuffer(target, gl_const::GLReadOnly); -#else - void * bufferPointer = GLFunctions::glMapBufferRange(target, 0, size, gl_const::GLReadBufferBit); -#endif - - memcpy(dst, bufferPointer, size); -} - -struct NotSupported32BitIndex{}; -struct Supported32BitIndex{}; - -template -void TransformIndices(void * pointer, uint32_t count, uint32_t offset) -{ - ASSERT(false, ()); -} - -template<> -void TransformIndices(void * pointer, uint32_t count, uint32_t offset) -{ - auto indexPtr = reinterpret_cast(pointer); - for (uint32_t i = 0; i < count; ++i) - { - *indexPtr += offset; - ++indexPtr; - } -} - -template<> -void TransformIndices(void * pointer, uint32_t count, uint32_t offset) -{ - auto indexPtr = reinterpret_cast(pointer); - auto const indexOffset = static_cast(offset); - for (uint32_t i = 0; i < count; ++i) - { - *indexPtr += indexOffset; - ++indexPtr; - } -} - -bool BatchMergeHelper::IsMergeSupported() -{ -#if defined(OMIM_OS_DESKTOP) - return true; -#else - static bool isSupported = dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::MapBufferRange); - return isSupported; -#endif -} - -void BatchMergeHelper::MergeBatches(ref_ptr mng, bool isPerspective, - std::vector> & batches, - std::vector> & mergedBatches) -{ - ASSERT(!batches.empty(), ()); - if (batches.size() < 2) - { - mergedBatches.emplace_back(std::move(batches.front())); - return; - } - - uint32_t constexpr kIndexBufferSize = 30000; - uint32_t constexpr kVertexBufferSize = 20000; - - using TBuffer = dp::VertexArrayBuffer; - using TBucket = dp::RenderBucket; - - auto flushFn = [&](drape_ptr && bucket, ref_ptr buffer) - { - if (buffer->GetIndexCount() == 0) - return; - - ref_ptr oldGroup = make_ref(batches.front()); - drape_ptr newGroup = make_unique_dp(oldGroup->GetState(), oldGroup->GetTileKey()); - newGroup->m_params = oldGroup->m_params; - newGroup->AddBucket(std::move(bucket)); - - buffer->Preflush(); - - auto programPtr = mng->GetProgram(isPerspective ? newGroup->GetState().GetProgram3d() - : newGroup->GetState().GetProgram()); - ASSERT(programPtr != nullptr, ()); - programPtr->Bind(); - buffer->Build(programPtr); - mergedBatches.push_back(std::move(newGroup)); - }; - - auto allocateFn = [=](drape_ptr & bucket, ref_ptr & buffer) - { - bucket = make_unique_dp(make_unique_dp(kIndexBufferSize, kVertexBufferSize)); - buffer = bucket->GetBuffer(); - }; - - auto copyVertecesFn = [](TBuffer::BuffersMap::value_type const & vboNode, - vector & rawDataBuffer, - ref_ptr newBuffer) - { - dp::BindingInfo const & binding = vboNode.first; - ref_ptr vbo = vboNode.second->GetBuffer(); - uint32_t vertexCount = vbo->GetCurrentSize(); - uint32_t bufferLength = vertexCount * vbo->GetElementSize(); - if (rawDataBuffer.size() < bufferLength) - rawDataBuffer.resize(bufferLength); - - vbo->Bind(); - ReadBufferData(rawDataBuffer.data(), gl_const::GLArrayBuffer, bufferLength); - GLFunctions::glUnmapBuffer(gl_const::GLArrayBuffer); - - newBuffer->UploadData(binding, rawDataBuffer.data(), vertexCount); - }; - - drape_ptr bucket; - ref_ptr newBuffer; - allocateFn(bucket, newBuffer); - - vector rawDataBuffer; - - for (auto const & group : batches) - { - for (auto const & b : group->m_renderBuckets) - { - ASSERT(b->m_overlay.empty(), ()); - ref_ptr buffer = b->GetBuffer(); - uint32_t vertexCount = buffer->GetStartIndexValue(); - uint32_t indexCount = buffer->GetIndexCount(); - - if (newBuffer->GetAvailableIndexCount() < vertexCount || - newBuffer->GetAvailableVertexCount() < indexCount) - { - flushFn(std::move(bucket), newBuffer); - allocateFn(bucket, newBuffer); - } - - bucket->SetFeatureMinZoom(b->GetMinZoom()); - - auto const indexOffset = newBuffer->GetStartIndexValue(); - - for (auto const & vboNode : buffer->m_staticBuffers) - copyVertecesFn(vboNode, rawDataBuffer, newBuffer); - - for (auto const & vboNode : buffer->m_dynamicBuffers) - copyVertecesFn(vboNode, rawDataBuffer, newBuffer); - - auto const indexByteCount = indexCount * dp::IndexStorage::SizeOfIndex(); - if (rawDataBuffer.size() < indexByteCount) - rawDataBuffer.resize(indexByteCount); - - buffer->m_indexBuffer->GetBuffer()->Bind(); - ReadBufferData(rawDataBuffer.data(), gl_const::GLElementArrayBuffer, indexByteCount); - GLFunctions::glUnmapBuffer(gl_const::GLElementArrayBuffer); - - if (dp::IndexStorage::IsSupported32bit()) - TransformIndices(rawDataBuffer.data(), indexCount, indexOffset); - else - TransformIndices(rawDataBuffer.data(), indexCount, indexOffset); - - newBuffer->UploadIndexes(rawDataBuffer.data(), indexCount); - } - } - - if (newBuffer->GetIndexCount() > 0) - { - flushFn(std::move(bucket), newBuffer); - allocateFn(bucket, newBuffer); - } -} -} // namespace df diff --git a/drape_frontend/batch_merge_helper.hpp b/drape_frontend/batch_merge_helper.hpp deleted file mode 100644 index 21638cc487..0000000000 --- a/drape_frontend/batch_merge_helper.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "drape/pointers.hpp" -#include "drape_frontend/render_group.hpp" - -#include - -namespace dp -{ -class VertexArrayBuffer; -} // namespace dp - -namespace gpu -{ -class ProgramManager; -} // namespace gpu - -namespace df -{ -class BatchMergeHelper -{ -public: - static bool IsMergeSupported(); - - static void MergeBatches(ref_ptr mng, bool isPerspective, - std::vector> & batches, - std::vector> & mergedBatches); -}; -} // namespace df diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 83fa37ee39..960ef88b2d 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -344,7 +344,7 @@ void DrapeEngine::UpdateUserMarks(UserMarksProvider * provider, bool firstTime) } } -void DrapeEngine::SetRenderingEnabled(ref_ptr contextFactory) +void DrapeEngine::SetRenderingEnabled(ref_ptr contextFactory) { m_backend->SetRenderingEnabled(contextFactory); m_frontend->SetRenderingEnabled(contextFactory); diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index a1d1bf7136..db1320367a 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -37,7 +37,7 @@ namespace dp { class GlyphGenerator; -class GraphicContextFactory; +class GraphicsContextFactory; } // namespace dp namespace df @@ -51,7 +51,7 @@ public: struct Params { Params(dp::ApiVersion apiVersion, - ref_ptr factory, + ref_ptr factory, dp::Viewport const & viewport, MapDataProvider const & model, Hints const & hints, @@ -93,7 +93,7 @@ public: {} dp::ApiVersion m_apiVersion; - ref_ptr m_factory; + ref_ptr m_factory; dp::Viewport m_viewport; MapDataProvider m_model; Hints m_hints; @@ -141,7 +141,7 @@ public: void UpdateUserMarks(UserMarksProvider * provider, bool firstTime); void InvalidateUserMarks(); - void SetRenderingEnabled(ref_ptr contextFactory = nullptr); + void SetRenderingEnabled(ref_ptr contextFactory = nullptr); void SetRenderingDisabled(bool const destroyContext); void InvalidateRect(m2::RectD const & rect); void UpdateMapStyle(); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index b1b925b2ee..8fd15e4c3c 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -1,7 +1,6 @@ #include "drape_frontend/frontend_renderer.hpp" #include "drape_frontend/animation/interpolation_holder.hpp" #include "drape_frontend/animation_system.hpp" -#include "drape_frontend/batch_merge_helper.hpp" #include "drape_frontend/drape_measurer.hpp" #include "drape_frontend/drape_notifier.hpp" #include "drape_frontend/gui/drape_gui.hpp" @@ -54,23 +53,6 @@ double const kVSyncInterval = 0.06; std::string const kTransitBackgroundColor = "TransitBackground"; -struct MergedGroupKey -{ - dp::GLState m_state; - TileKey m_key; - - MergedGroupKey(dp::GLState const & state, TileKey const & tileKey) - : m_state(state), m_key(tileKey) - {} - - bool operator <(MergedGroupKey const & other) const - { - if (!(m_state == other.m_state)) - return m_state < other.m_state; - return m_key.LessStrict(other.m_key); - } -}; - template bool RemoveGroups(ToDo & filter, std::vector> & groups, ref_ptr tree) @@ -1319,8 +1301,6 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView, bool activeFram #if defined(DRAPE_MEASURER) && (defined(RENDER_STATISTIC) || defined(TRACK_GPU_MEM)) DrapeMeasurer::Instance().AfterRenderFrame(); #endif - - MergeBuckets(); } void FrontendRenderer::Render2dLayer(ScreenBase const & modelView) @@ -1520,64 +1500,6 @@ void FrontendRenderer::PrepareBucket(dp::GLState const & state, drape_ptrGetBuffer()->Build(isPerspective ? program3d : program); } -void FrontendRenderer::MergeBuckets() -{ - if (!BatchMergeHelper::IsMergeSupported()) - return; - - ++m_mergeBucketsCounter; - if (m_mergeBucketsCounter < 60) - return; - - m_mergeBucketsCounter = 0; - - auto mergeFn = [this](RenderLayer & layer, bool isPerspective) - { - if (layer.m_renderGroups.empty()) - return; - - using TGroupMap = std::map>>; - TGroupMap forMerge; - - std::vector> newGroups; - newGroups.reserve(layer.m_renderGroups.size()); - - size_t groupsCount = layer.m_renderGroups.size(); - for (size_t i = 0; i < groupsCount; ++i) - { - ref_ptr group = make_ref(layer.m_renderGroups[i]); - if (!group->IsPendingOnDelete()) - { - dp::GLState const state = group->GetState(); - auto const depthLayer = GetDepthLayer(state); - if (depthLayer != RenderState::GeometryLayer && depthLayer != RenderState::Geometry3dLayer) - ASSERT(false, ("Invalid depth layer for merging buckets")); - MergedGroupKey const k(state, group->GetTileKey()); - forMerge[k].push_back(std::move(layer.m_renderGroups[i])); - } - else - { - newGroups.push_back(std::move(layer.m_renderGroups[i])); - } - } - - for (auto & node : forMerge) - { - if (node.second.size() < 2) - newGroups.emplace_back(std::move(node.second.front())); - else - BatchMergeHelper::MergeBatches(make_ref(m_gpuProgramManager), isPerspective, node.second, newGroups); - } - - layer.m_renderGroups = std::move(newGroups); - layer.m_isDirty = true; - }; - - bool const isPerspective = m_userEventStream.GetCurrentScreen().isPerspective(); - mergeFn(m_layers[RenderState::GeometryLayer], isPerspective); - mergeFn(m_layers[RenderState::Geometry3dLayer], isPerspective); -} - void FrontendRenderer::RenderSingleGroup(ScreenBase const & modelView, ref_ptr group) { group->UpdateAnimation(); diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index 585fbb7792..982e0d1237 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -144,7 +144,6 @@ private: void OnResize(ScreenBase const & screen); void RenderScene(ScreenBase const & modelView, bool activeFrame); void PrepareBucket(dp::GLState const & state, drape_ptr & bucket); - void MergeBuckets(); void RenderSingleGroup(ScreenBase const & modelView, ref_ptr group); void RefreshProjection(ScreenBase const & screen); void RefreshZScale(ScreenBase const & screen); diff --git a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj index 13c98380d0..d765365911 100644 --- a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj +++ b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj @@ -172,8 +172,6 @@ 6709484E1BDF9C48005014C0 /* shape.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670948361BDF9C48005014C0 /* shape.hpp */; }; 6709484F1BDF9C48005014C0 /* skin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 670948371BDF9C48005014C0 /* skin.cpp */; }; 670948501BDF9C48005014C0 /* skin.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670948381BDF9C48005014C0 /* skin.hpp */; }; - 670E393A1C46C59000E9C0A6 /* batch_merge_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 670E39361C46C59000E9C0A6 /* batch_merge_helper.cpp */; }; - 670E393B1C46C59000E9C0A6 /* batch_merge_helper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670E39371C46C59000E9C0A6 /* batch_merge_helper.hpp */; }; 670E393C1C46C59000E9C0A6 /* color_constants.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 670E39381C46C59000E9C0A6 /* color_constants.cpp */; }; 670E393D1C46C59000E9C0A6 /* color_constants.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670E39391C46C59000E9C0A6 /* color_constants.hpp */; }; 672D249A1E892768004BB7B1 /* overlays_tracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 672D24981E892768004BB7B1 /* overlays_tracker.cpp */; }; @@ -453,8 +451,6 @@ 670948361BDF9C48005014C0 /* shape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = shape.hpp; sourceTree = ""; }; 670948371BDF9C48005014C0 /* skin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = skin.cpp; sourceTree = ""; }; 670948381BDF9C48005014C0 /* skin.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = skin.hpp; sourceTree = ""; }; - 670E39361C46C59000E9C0A6 /* batch_merge_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = batch_merge_helper.cpp; sourceTree = ""; }; - 670E39371C46C59000E9C0A6 /* batch_merge_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = batch_merge_helper.hpp; sourceTree = ""; }; 670E39381C46C59000E9C0A6 /* color_constants.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = color_constants.cpp; sourceTree = ""; }; 670E39391C46C59000E9C0A6 /* color_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = color_constants.hpp; sourceTree = ""; }; 672D24981E892768004BB7B1 /* overlays_tracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = overlays_tracker.cpp; sourceTree = ""; }; @@ -605,8 +601,6 @@ 670947ED1BDF9BF5005014C0 /* backend_renderer.hpp */, 670947EE1BDF9BF5005014C0 /* base_renderer.cpp */, 670947EF1BDF9BF5005014C0 /* base_renderer.hpp */, - 670E39361C46C59000E9C0A6 /* batch_merge_helper.cpp */, - 670E39371C46C59000E9C0A6 /* batch_merge_helper.hpp */, 670947F11BDF9BF5005014C0 /* batchers_pool.hpp */, 451A2A801EE8464E003E05A4 /* circles_pack_shape.cpp */, 451A2A811EE8464E003E05A4 /* circles_pack_shape.hpp */, @@ -889,7 +883,6 @@ 452C9EDD1CEDCF3200A55E57 /* linear_animation.hpp in Headers */, 454C19BB1CCE3EC0002A2C86 /* animation_constants.hpp in Headers */, 6709481F1BDF9C39005014C0 /* show_hide_animation.hpp in Headers */, - 670E393B1C46C59000E9C0A6 /* batch_merge_helper.hpp in Headers */, 670947931BDF9BE1005014C0 /* kinetic_scroller.hpp in Headers */, 670947E71BDF9BEC005014C0 /* frontend_renderer.hpp in Headers */, 45B241AE20EF9D0500A759D6 /* scale_fps_helper.hpp in Headers */, @@ -989,7 +982,6 @@ 56BF56DA1C7608C0006DD7CB /* choose_position_mark.cpp in Sources */, 6743D36D1C3A9F090095054B /* arrow3d.cpp in Sources */, BBD9E2D31F009D9E00DF189A /* user_mark_generator.cpp in Sources */, - 670E393A1C46C59000E9C0A6 /* batch_merge_helper.cpp in Sources */, 452C9EDA1CEDCF3200A55E57 /* interpolators.cpp in Sources */, 451A2A821EE8464E003E05A4 /* circles_pack_shape.cpp in Sources */, 67E91C781BDFC85E005CEE88 /* area_shape.cpp in Sources */,