Removed BatchMergeHelper.

This commit is contained in:
Daria Volvenkova 2018-08-01 15:41:23 +03:00 committed by Roman Kuznetsov
parent 0b7f3017fe
commit 78d4b47d1c
8 changed files with 5 additions and 306 deletions

View file

@ -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

View file

@ -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 <cstring>
#include <utility>
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<typename TSupported>
void TransformIndices(void * pointer, uint32_t count, uint32_t offset)
{
ASSERT(false, ());
}
template<>
void TransformIndices<Supported32BitIndex>(void * pointer, uint32_t count, uint32_t offset)
{
auto indexPtr = reinterpret_cast<uint32_t *>(pointer);
for (uint32_t i = 0; i < count; ++i)
{
*indexPtr += offset;
++indexPtr;
}
}
template<>
void TransformIndices<NotSupported32BitIndex>(void * pointer, uint32_t count, uint32_t offset)
{
auto indexPtr = reinterpret_cast<uint16_t *>(pointer);
auto const indexOffset = static_cast<uint16_t>(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<gpu::ProgramManager> mng, bool isPerspective,
std::vector<drape_ptr<RenderGroup>> & batches,
std::vector<drape_ptr<RenderGroup>> & 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<TBucket> && bucket, ref_ptr<TBuffer> buffer)
{
if (buffer->GetIndexCount() == 0)
return;
ref_ptr<RenderGroup> oldGroup = make_ref(batches.front());
drape_ptr<RenderGroup> newGroup = make_unique_dp<RenderGroup>(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<gpu::Program>()
: newGroup->GetState().GetProgram<gpu::Program>());
ASSERT(programPtr != nullptr, ());
programPtr->Bind();
buffer->Build(programPtr);
mergedBatches.push_back(std::move(newGroup));
};
auto allocateFn = [=](drape_ptr<TBucket> & bucket, ref_ptr<TBuffer> & buffer)
{
bucket = make_unique_dp<TBucket>(make_unique_dp<TBuffer>(kIndexBufferSize, kVertexBufferSize));
buffer = bucket->GetBuffer();
};
auto copyVertecesFn = [](TBuffer::BuffersMap::value_type const & vboNode,
vector<uint8_t> & rawDataBuffer,
ref_ptr<TBuffer> newBuffer)
{
dp::BindingInfo const & binding = vboNode.first;
ref_ptr<dp::DataBufferBase> 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<TBucket> bucket;
ref_ptr<TBuffer> newBuffer;
allocateFn(bucket, newBuffer);
vector<uint8_t> rawDataBuffer;
for (auto const & group : batches)
{
for (auto const & b : group->m_renderBuckets)
{
ASSERT(b->m_overlay.empty(), ());
ref_ptr<TBuffer> 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<Supported32BitIndex>(rawDataBuffer.data(), indexCount, indexOffset);
else
TransformIndices<NotSupported32BitIndex>(rawDataBuffer.data(), indexCount, indexOffset);
newBuffer->UploadIndexes(rawDataBuffer.data(), indexCount);
}
}
if (newBuffer->GetIndexCount() > 0)
{
flushFn(std::move(bucket), newBuffer);
allocateFn(bucket, newBuffer);
}
}
} // namespace df

View file

@ -1,29 +0,0 @@
#pragma once
#include "drape/pointers.hpp"
#include "drape_frontend/render_group.hpp"
#include <vector>
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<gpu::ProgramManager> mng, bool isPerspective,
std::vector<drape_ptr<RenderGroup>> & batches,
std::vector<drape_ptr<RenderGroup>> & mergedBatches);
};
} // namespace df

View file

@ -344,7 +344,7 @@ void DrapeEngine::UpdateUserMarks(UserMarksProvider * provider, bool firstTime)
}
}
void DrapeEngine::SetRenderingEnabled(ref_ptr<dp::GraphicContextFactory> contextFactory)
void DrapeEngine::SetRenderingEnabled(ref_ptr<dp::GraphicsContextFactory> contextFactory)
{
m_backend->SetRenderingEnabled(contextFactory);
m_frontend->SetRenderingEnabled(contextFactory);

View file

@ -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<dp::GraphicContextFactory> factory,
ref_ptr<dp::GraphicsContextFactory> factory,
dp::Viewport const & viewport,
MapDataProvider const & model,
Hints const & hints,
@ -93,7 +93,7 @@ public:
{}
dp::ApiVersion m_apiVersion;
ref_ptr<dp::GraphicContextFactory> m_factory;
ref_ptr<dp::GraphicsContextFactory> 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<dp::GraphicContextFactory> contextFactory = nullptr);
void SetRenderingEnabled(ref_ptr<dp::GraphicsContextFactory> contextFactory = nullptr);
void SetRenderingDisabled(bool const destroyContext);
void InvalidateRect(m2::RectD const & rect);
void UpdateMapStyle();

View file

@ -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 <typename ToDo>
bool RemoveGroups(ToDo & filter, std::vector<drape_ptr<RenderGroup>> & groups,
ref_ptr<dp::OverlayTree> 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_ptr<dp::Re
bucket->GetBuffer()->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<MergedGroupKey, std::vector<drape_ptr<RenderGroup>>>;
TGroupMap forMerge;
std::vector<drape_ptr<RenderGroup>> newGroups;
newGroups.reserve(layer.m_renderGroups.size());
size_t groupsCount = layer.m_renderGroups.size();
for (size_t i = 0; i < groupsCount; ++i)
{
ref_ptr<RenderGroup> 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<BaseRenderGroup> group)
{
group->UpdateAnimation();

View file

@ -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<dp::RenderBucket> & bucket);
void MergeBuckets();
void RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group);
void RefreshProjection(ScreenBase const & screen);
void RefreshZScale(ScreenBase const & screen);

View file

@ -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 = "<group>"; };
670948371BDF9C48005014C0 /* skin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = skin.cpp; sourceTree = "<group>"; };
670948381BDF9C48005014C0 /* skin.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = skin.hpp; sourceTree = "<group>"; };
670E39361C46C59000E9C0A6 /* batch_merge_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = batch_merge_helper.cpp; sourceTree = "<group>"; };
670E39371C46C59000E9C0A6 /* batch_merge_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = batch_merge_helper.hpp; sourceTree = "<group>"; };
670E39381C46C59000E9C0A6 /* color_constants.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = color_constants.cpp; sourceTree = "<group>"; };
670E39391C46C59000E9C0A6 /* color_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = color_constants.hpp; sourceTree = "<group>"; };
672D24981E892768004BB7B1 /* overlays_tracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = overlays_tracker.cpp; sourceTree = "<group>"; };
@ -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 */,