Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
8d1392be6a debug output 2023-10-03 17:26:28 +03:00
da855cd1f5 WIP wireframe mode 2023-10-03 17:26:03 +03:00
c257a9a2bd filtering stats 2023-10-01 22:00:38 +03:00
0292812430 [drape] Fix run-time lines filtering stats
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
2023-09-30 20:17:18 +03:00
8 changed files with 181 additions and 99 deletions

View file

@ -1,12 +1,12 @@
#pragma once
//#define DRAW_TILE_NET
#define DRAW_TILE_NET
//#define DEBUG_OVERLAYS_OUTPUT
//#define CHECK_VBO_BOUNDS
//#define TRACK_POINTERS
//#define DEBUG_ANIMATIONS
//#define LINES_GENERATION_CALC_FILTERED_POINTS
#define LINES_GENERATION_CALC_FILTERED_POINTS
//#define GPS_TRACK_SHOW_RAW_POINTS
//#define DEBUG_MESSAGE_QUEUE
//#define RENDER_DEBUG_INFO_LABELS

View file

@ -63,71 +63,6 @@ df::ColorConstant const kRoadShieldOrangeBackgroundColor = "RoadShieldOrangeBack
uint32_t const kPathTextBaseTextIndex = 128;
uint32_t const kShieldBaseTextIndex = 0;
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
class LinesStat
{
public:
~LinesStat()
{
map<int, TValue> zoomValues;
for (pair<TKey, TValue> const & f : m_features)
{
TValue & v = zoomValues[f.first.second];
v.m_neededPoints += f.second.m_neededPoints;
v.m_readedPoints += f.second.m_readedPoints;
}
LOG(LINFO, ("========================"));
for (pair<int, TValue> const & v : zoomValues)
LOG(LINFO, ("Zoom = ", v.first, " Percent = ", 1 - v.second.m_neededPoints / (double)v.second.m_readedPoints));
}
static LinesStat & Get()
{
static LinesStat s_stat;
return s_stat;
}
void InsertLine(FeatureID const & id, double scale, int vertexCount, int renderVertexCount)
{
int s = 0;
double factor = 5.688;
while (factor < scale)
{
s++;
factor = factor * 2.0;
}
InsertLine(id, s, vertexCount, renderVertexCount);
}
void InsertLine(FeatureID const & id, int scale, int vertexCount, int renderVertexCount)
{
TKey key(id, scale);
lock_guard<mutex> g(m_mutex);
if (m_features.find(key) != m_features.end())
return;
TValue & v = m_features[key];
v.m_readedPoints = vertexCount;
v.m_neededPoints = renderVertexCount;
}
private:
LinesStat() = default;
using TKey = pair<FeatureID, int>;
struct TValue
{
int m_readedPoints = 0;
int m_neededPoints = 0;
};
map<TKey, TValue> m_features;
mutex m_mutex;
};
#endif
void Extract(::LineDefProto const * lineRule, df::LineViewParams & params)
{
double const scale = df::VisualParams::Instance().GetVisualScale();
@ -751,7 +686,8 @@ ApplyLineFeatureGeometry::ApplyLineFeatureGeometry(TileKey const & tileKey, TIns
: TBase(tileKey, insertShape, id, rank, CaptionDescription())
, m_currentScaleGtoP(static_cast<float>(currentScaleGtoP))
, m_minSegmentSqrLength(base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale() / currentScaleGtoP))
, m_simplify(tileKey.m_zoomLevel >= 10 && tileKey.m_zoomLevel <= 12)
//, m_simplify(tileKey.m_zoomLevel >= 10 && tileKey.m_zoomLevel <= 12)
, m_simplify(false)
, m_smooth(smooth)
, m_initialPointsCount(pointsCount)
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
@ -864,7 +800,7 @@ void ApplyLineFeatureGeometry::ProcessLineRule(TRuleWrapper const & rule)
void ApplyLineFeatureGeometry::Finish()
{
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
LinesStat::Get().InsertLine(m_id, m_currentScaleGtoP, m_readCount, static_cast<int>(m_spline->GetSize()));
LinesStat::Get().InsertLine(m_id, m_tileKey.m_zoomLevel, m_readCount, static_cast<int>(m_spline->GetSize()));
#endif
}
@ -1060,8 +996,8 @@ void ApplyLineFeatureAdditional::Finish(ref_ptr<dp::TextureManager> texMng,
params.m_featureId = m_id;
params.m_depth = m_captionDepth;
params.m_rank = m_rank;
params.m_mainText = m_captions.GetMainText();
params.m_auxText = m_captions.GetAuxText();
//params.m_mainText = m_captions.GetMainText(); //pastk
//params.m_auxText = m_captions.GetAuxText();
params.m_textFont = fontDecl;
params.m_baseGtoPScale = m_currentScaleGtoP;

View file

@ -27,6 +27,67 @@ class TextureManager;
namespace df
{
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
class LinesStat
{
public:
~LinesStat()
{
DumpStats();
}
void DumpStats() const
{
std::map<int, TValue> zoomValues;
for (std::pair<TKey, TValue> const & f : m_features)
{
TValue & v = zoomValues[f.first.second];
v.m_neededPoints += f.second.m_neededPoints;
v.m_readPoints += f.second.m_readPoints;
}
LOG(LINFO, ("===== Lines filtering stats ====="));
for (std::pair<int, TValue> const & v : zoomValues)
{
int const filtered = v.second.m_readPoints - v.second.m_neededPoints;
LOG(LINFO, ("Zoom =", v.first, "Filtered", 100 * filtered / (double)v.second.m_readPoints, "% (",
filtered, "out of", v.second.m_readPoints, "points)"));
}
}
static LinesStat & Get()
{
static LinesStat s_stat;
return s_stat;
}
void InsertLine(FeatureID const & id, int scale, int vertexCount, int renderVertexCount)
{
TKey key(id, scale);
std::lock_guard g(m_mutex);
if (m_features.find(key) != m_features.end())
return;
TValue & v = m_features[key];
v.m_readPoints = vertexCount;
v.m_neededPoints = renderVertexCount;
}
private:
LinesStat() = default;
using TKey = std::pair<FeatureID, int>;
struct TValue
{
int m_readPoints = 0;
int m_neededPoints = 0;
};
std::map<TKey, TValue> m_features;
std::mutex m_mutex;
};
#endif
struct TextViewParams;
class MapShape;
struct BuildingOutline;

View file

@ -14,6 +14,8 @@
#include "drape_frontend/user_mark_shapes.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape_frontend/apply_feature_functors.hpp"
#include "shaders/programs.hpp"
#include "drape/constants.hpp"
@ -327,6 +329,9 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
{
#if defined(DRAPE_MEASURER_BENCHMARK) && defined(GENERATING_STATISTIC)
DrapeMeasurer::Instance().EndScenePreparing();
#endif
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
df::LinesStat::Get().DumpStats();
#endif
m_trafficRenderer->OnGeometryReady(GetCurrentZoom());

View file

@ -54,6 +54,8 @@ private:
struct BaseBuilderParams
{
dp::TextureManager::ColorRegion m_color;
dp::TextureManager::ColorRegion m_capColor;
dp::TextureManager::ColorRegion m_joinColor;
float m_pxHalfWidth;
float m_depth;
bool m_depthTestEnabled;
@ -69,9 +71,12 @@ public:
BaseLineBuilder(BaseBuilderParams const & params, size_t geomsSize, size_t joinsSize)
: m_params(params)
, m_colorCoord(glsl::ToVec2(params.m_color.GetTexRect().Center()))
, m_capColorCoord(glsl::ToVec2(params.m_capColor.GetTexRect().Center()))
, m_joinColorCoord(glsl::ToVec2(params.m_joinColor.GetTexRect().Center()))
{
m_geometry.reserve(geomsSize);
m_joinGeom.reserve(joinsSize);
m_params.m_cap = dp::LineCap::RoundCap; //pastk
}
dp::BindingInfo const & GetBindingInfo() override
@ -88,7 +93,7 @@ public:
{
return static_cast<uint32_t>(m_geometry.size());
}
/*
ref_ptr<void> GetJoinData() override
{
return make_ref(m_joinGeom.data());
@ -98,6 +103,7 @@ public:
{
return static_cast<uint32_t>(m_joinGeom.size());
}
*/
float GetHalfWidth()
{
@ -114,6 +120,11 @@ public:
return GetState();
}
dp::RenderState GetJoinState() override
{
return GetState();
}
ref_ptr<void> GetCapData() override
{
return ref_ptr<void>();
@ -124,6 +135,16 @@ public:
return 0;
}
ref_ptr<void> GetJoinData() override
{
return ref_ptr<void>();
}
uint32_t GetJoinSize() override
{
return 0;
}
float GetSide(bool isLeft) const
{
return isLeft ? 1.0f : -1.0f;
@ -134,10 +155,12 @@ protected:
using TGeometryBuffer = gpu::VBReservedSizeT<V>;
TGeometryBuffer m_geometry;
TGeometryBuffer m_joinGeom;
TGeometryBuffer m_joinGeom; //pastk not used??
BaseBuilderParams m_params;
glsl::vec2 const m_colorCoord;
glsl::vec2 const m_capColorCoord; //pastk
glsl::vec2 const m_joinColorCoord;
};
class SolidLineBuilder : public BaseLineBuilder<gpu::LineVertex>
@ -175,7 +198,7 @@ public:
dp::RenderState GetState() override
{
auto state = CreateRenderState(gpu::Program::Line, m_params.m_depthLayer);
state.SetColorTexture(m_params.m_color.GetTexture());
state.SetColorTexture(m_params.m_capColor.GetTexture()); //pastk
state.SetDepthTestEnabled(m_params.m_depthTestEnabled);
return state;
}
@ -206,7 +229,19 @@ public:
auto state = CreateRenderState(gpu::Program::CapJoin, m_params.m_depthLayer);
state.SetDepthTestEnabled(m_params.m_depthTestEnabled);
state.SetColorTexture(m_params.m_color.GetTexture());
state.SetColorTexture(m_params.m_capColor.GetTexture()); //pastk
state.SetDepthFunction(dp::TestFunction::Less);
return state;
}
dp::RenderState GetJoinState() override
{
if (m_params.m_cap == dp::ButtCap)
return TBase::GetCapState();
auto state = CreateRenderState(gpu::Program::CapJoin, m_params.m_depthLayer);
state.SetDepthTestEnabled(m_params.m_depthTestEnabled);
state.SetColorTexture(m_params.m_joinColor.GetTexture()); //pastk
state.SetDepthFunction(dp::TestFunction::Less);
return state;
}
@ -221,6 +256,16 @@ public:
return static_cast<uint32_t>(m_capGeometry.size());
}
ref_ptr<void> GetJoinData() override
{
return make_ref<void>(m_jGeometry.data());
}
uint32_t GetJoinSize() override
{
return static_cast<uint32_t>(m_jGeometry.size());
}
void SubmitVertex(glsl::vec3 const & pivot, glsl::vec2 const & normal, bool isLeft)
{
float const halfWidth = GetHalfWidth();
@ -229,36 +274,41 @@ public:
void SubmitJoin(glsl::vec2 const & pos)
{
if (m_params.m_join == dp::RoundJoin)
CreateRoundCap(pos);
//if (m_params.m_join == dp::RoundJoin)
CreateRoundCap(pos, false);
}
void SubmitCap(glsl::vec2 const & pos)
{
if (m_params.m_cap != dp::ButtCap)
CreateRoundCap(pos);
//if (m_params.m_cap != dp::ButtCap) /pastk
CreateRoundCap(pos, true);
}
private:
void CreateRoundCap(glsl::vec2 const & pos)
void CreateRoundCap(glsl::vec2 const & pos, bool isCap)
{
// Here we use an equilateral triangle to render circle (incircle of a triangle).
static float const kSqrt3 = sqrt(3.0f);
float const size = isCap ? 2.0f : 1.6f;
float const radius = GetHalfWidth();
auto const color = isCap ? m_capColorCoord : m_joinColorCoord;
auto bucket = isCap ? &m_capGeometry : &m_jGeometry;
float const depth = isCap ? dp::kMaxDepth : dp::kMaxDepth - 1;
m_capGeometry.emplace_back(CapVertex::TPosition(pos, m_params.m_depth),
CapVertex::TNormal(-radius * kSqrt3, -radius, radius),
CapVertex::TTexCoord(m_colorCoord));
m_capGeometry.emplace_back(CapVertex::TPosition(pos, m_params.m_depth),
CapVertex::TNormal(radius * kSqrt3, -radius, radius),
CapVertex::TTexCoord(m_colorCoord));
m_capGeometry.emplace_back(CapVertex::TPosition(pos, m_params.m_depth),
CapVertex::TNormal(0, 2.0f * radius, radius),
CapVertex::TTexCoord(m_colorCoord));
bucket->emplace_back(CapVertex::TPosition(pos, depth),
CapVertex::TNormal(-radius * kSqrt3 * size, -radius * size, radius * size),
CapVertex::TTexCoord(color));
bucket->emplace_back(CapVertex::TPosition(pos, depth),
CapVertex::TNormal(radius * kSqrt3 * size, -radius * size, radius * size),
CapVertex::TTexCoord(color));
bucket->emplace_back(CapVertex::TPosition(pos, depth),
CapVertex::TNormal(0, 2.0f * radius * size, radius * size),
CapVertex::TTexCoord(color));
}
private:
TCapBuffer m_capGeometry;
TCapBuffer m_jGeometry;
};
class SimpleSolidLineBuilder : public BaseLineBuilder<gpu::AreaVertex>
@ -427,8 +477,8 @@ void LineShape::Construct<SolidLineBuilder>(SolidLineBuilder & builder) const
// skip joins generation
float const kJoinsGenerationThreshold = 2.5f;
bool generateJoins = true;
if (builder.GetHalfWidth() <= kJoinsGenerationThreshold)
generateJoins = false;
//if (builder.GetHalfWidth() <= kJoinsGenerationThreshold) //pastk
// generateJoins = false;
// build geometry
glsl::vec2 firstPoint = ToShapeVertex2(path.front());
@ -508,16 +558,26 @@ void LineShape::Prepare(ref_ptr<dp::TextureManager> textures) const
p.m_depthTestEnabled = m_params.m_depthTestEnabled;
p.m_depth = m_params.m_depth;
p.m_depthLayer = m_params.m_depthLayer;
p.m_join = m_params.m_join;
p.m_pxHalfWidth = m_params.m_width / 2;
p.m_join = dp::LineJoin::RoundJoin; //m_params.m_join; pastk
p.m_pxHalfWidth = 1; //m_params.m_width / 2; pastk
dp::TextureManager::ColorRegion capColorRegion;
textures->GetColorRegion(dp::Color::Red(), capColorRegion);
p.m_capColor = capColorRegion;
dp::TextureManager::ColorRegion joinColorRegion;
textures->GetColorRegion(dp::Color::Blue(), joinColorRegion);
p.m_joinColor = joinColorRegion;
};
if (m_params.m_pattern.empty())
{
int lineWidth = 1;
m_isSimple = CanBeSimplified(lineWidth);
m_isSimple = false; //pastk
if (m_isSimple)
{
// Uses GL lines primitives for rendering.
SimpleSolidLineBuilder::BuilderParams p;
commonParamsBuilder(p);
@ -527,6 +587,7 @@ void LineShape::Prepare(ref_ptr<dp::TextureManager> textures) const
}
else
{
// Expands lines to quads on CPU side.
SolidLineBuilder::BuilderParams p;
commonParamsBuilder(p);
@ -566,13 +627,23 @@ void LineShape::Draw(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::Batcher>
{
batcher->InsertListOfStrip(context, state, make_ref(&provider), dp::Batcher::VertexPerQuad);
uint32_t const joinSize = m_lineShapeInfo->GetJoinSize();
/*
uint32_t const joinSize = m_lineShapeInfo->GetJoinSize(); //pastk not used
if (joinSize > 0)
{
dp::AttributeProvider joinsProvider(1, joinSize);
joinsProvider.InitStream(0, m_lineShapeInfo->GetBindingInfo(), m_lineShapeInfo->GetJoinData());
batcher->InsertTriangleList(context, state, make_ref(&joinsProvider));
}
*/
uint32_t const joinSize = m_lineShapeInfo->GetJoinSize();
if (joinSize > 0)
{
dp::AttributeProvider joinProvider(1, joinSize);
joinProvider.InitStream(0, m_lineShapeInfo->GetCapBindingInfo(), m_lineShapeInfo->GetJoinData());
batcher->InsertTriangleList(context, m_lineShapeInfo->GetJoinState(), make_ref(&joinProvider));
}
uint32_t const capSize = m_lineShapeInfo->GetCapSize();
if (capSize > 0)

View file

@ -25,6 +25,7 @@ public:
virtual ref_ptr<void> GetJoinData() = 0;
virtual uint32_t GetJoinSize() = 0;
virtual dp::RenderState GetJoinState() = 0;
virtual dp::BindingInfo const & GetCapBindingInfo() = 0;
virtual dp::RenderState GetCapState() = 0;

View file

@ -306,8 +306,8 @@ void RuleDrawer::ProcessAreaStyle(FeatureType & f, Stylist const & s, TInsertSha
areaMinHeight, areaHeight, f.GetRank(),
s.GetCaptionDescription());
f.ForEachTriangle(apply, zoomLevel);
if (applyPointStyle)
apply(featureCenter, true /* hasArea */);
//if (applyPointStyle)
// apply(featureCenter, true /* hasArea */);
if (CheckCancelled())
return;
@ -335,8 +335,8 @@ void RuleDrawer::ProcessAreaStyle(FeatureType & f, Stylist const & s, TInsertSha
s.ForEachRule(std::bind(&ApplyAreaFeature::ProcessAreaRule, &apply, _1));
/// @todo Can we put this check in the beginning of this function?
if (!IsDiscardCustomFeature(f.GetID()))
apply.Finish(m_context->GetTextureManager());
//if (!IsDiscardCustomFeature(f.GetID()))
// apply.Finish(m_context->GetTextureManager());
}
void RuleDrawer::ProcessLineStyle(FeatureType & f, Stylist const & s, TInsertShapeFn const & insertShape)
@ -344,6 +344,10 @@ void RuleDrawer::ProcessLineStyle(FeatureType & f, Stylist const & s, TInsertSha
int const zoomLevel = m_context->GetTileKey().m_zoomLevel;
bool const smooth = ftypes::IsIsolineChecker::Instance()(f);
if (f.GetID().m_index == 88) //pastk 1347
LOG(LINFO, ("POINTS z", zoomLevel, f.DebugString(10, false), "pts:", f.GetPointsCount()));
//f.ResetGeometry();
//f.ParseGeometry(12); //geom1
ApplyLineFeatureGeometry applyGeom(m_context->GetTileKey(), insertShape, f.GetID(), m_currentScaleGtoP,
f.GetRank(), f.GetPointsCount(), smooth);
f.ForEachPoint(applyGeom, zoomLevel);
@ -378,6 +382,7 @@ void RuleDrawer::ProcessLineStyle(FeatureType & f, Stylist const & s, TInsertSha
m_usedMetalines.insert(metalineSpline.Get());
}
needAdditional = false;
if (needAdditional && !clippedSplines.empty())
{
ApplyLineFeatureAdditional applyAdditional(m_context->GetTileKey(), insertShape, f.GetID(), m_currentScaleGtoP,
@ -499,7 +504,7 @@ void RuleDrawer::operator()(FeatureType & f)
else
{
ASSERT(s.m_pointStyleExists, ());
ProcessPointStyle(f, s, insertShape);
//ProcessPointStyle(f, s, insertShape);
}
if (CheckCancelled())

View file

@ -485,6 +485,9 @@ void FeatureType::ParseGeometry(int scale)
}
points.emplace_back(m_points.back());
if (m_id.m_index == 88) //pastk
LOG(LINFO, ("Load zoom", scale, "geom", ind, "mask:", m_ptsSimpMask, "points:", points.size()));
m_points.swap(points);
}