Skip to content

Vector Rendering First-Frame Performance Plan - #95

Open
pmeems wants to merge 6 commits into
developmentfrom
vector-rendering-gdi-first-frame
Open

pmeems wants to merge 6 commits into
developmentfrom
vector-rendering-gdi-first-frame

Conversation

@pmeems

@pmeems pmeems commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of the vector rendering first-frame performance plan: measurement and the primary fix land together, and the new benchmark proves the fix.

Motivation

Opening the 10.3 MB, 2,459-feature shapefile took 7+ seconds before the polygons appeared (Debug; ~2 s Release). Triangulation was ~94% of time-to-first-pixel because the first OnDraw synchronously triangulated every polygon on the UI thread.

Changes

  • GDI-first first paint — with the default Automatic preference, a Fill-mode frame whose layers have no fill meshes yet is painted entirely with the GDI direct-ring path (~31 ms on the test dataset); OpenGL is retried on later frames once the meshes exist. One frame still uses a single backend. An explicit OpenGL preference keeps the previous lazy on-draw triangulation, documented until Phase 2 adds background preparation.
  • Backend reporting — RenderingBackend reports GDI and RenderingStatus states that GDI rendered the frame while the OpenGL fill meshes are pending.
  • End-to-end benchmark — new opt-in RenderingBaseline tests host CMapWinGISControl through its class factory (no registry registration), load MWG_RENDERING_BASELINE_DATASET through LoadVectorDatasetEx and Begin/EndLoadVectorDataset, and force the first OnDraw into a 1280x720 memory DC. Threshold-free assertions: the first frame reports GDI and performs zero triangulations.
  • Instrumentation — the FrameRender scope no longer double-counts triangulation, and the GPU buffer build/upload has its own OpenGlGpuBufferUpload scope.
  • Test host — the status bar shows the load time and first-frame time for debugger-free comparison with MapWinGIS 5.

Results (test dataset, one workstation, recorded in docs/TESTING.md)

Path Release Debug
LoadVectorDatasetEx → first presented frame 213 ms 1,164 ms
Begin/EndLoadVectorDataset → first presented frame 198 ms 1,162 ms

Both targets are met (≤ 250 ms Release / ≤ 1.5 s Debug). Debug and Release CTest suites pass (484 tests each, no new warnings); the C# test host builds.

Memory: updated architecture/activex.md (Automatic GDI-first contract) and build/cmake.md (plain-shell cmake/vs2026 preset locations).

Remaining limitations

  • With Automatic, fill rendering stays on GDI until meshes exist; Phase 2 adds background mesh preparation and the view invalidation that switches to OpenGL.
  • The OGR scene read (~165 ms Release) now dominates load; Phase 3 evaluates batch reading.

…e pending

- Add an end-to-end RenderingBaseline benchmark that hosts the control through its class factory, loads the dataset through LoadVectorDatasetEx and Begin/EndLoadVectorDataset, and forces the first OnDraw into a memory DC
- Assert the GDI-first contract without timing thresholds: the first Automatic frame reports GDI and performs zero triangulations
- In Automatic Fill mode, draw the frame with GDI when layers have no fill meshes yet and retry OpenGL once the meshes exist; an explicit OpenGL preference keeps lazy on-draw triangulation
- Report the active backend and a diagnostic that states GDI is in use while the meshes are pending
- Show the load time and first-paint time in the ActiveXTestHost status bar
- Fix the FrameRender scope so it no longer double-counts triangulation and add an OpenGlGpuBufferUpload scope for the GPU buffer build/upload breakdown
- Record the Release and Debug end-to-end baselines in docs/TESTING.md
Copilot AI balanced review requested due to automatic review settings November 25, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Automatic rendering can still trigger paint-thread triangulation after failed preparation, while unconditional OpenGL assertions break tests on unsupported drivers and benchmark checks miss failed triangulation attempts.

3 open issues
What changed in this PR

Implements Phase 1 of MapWinGIS6’s first-frame performance plan, using GDI for Automatic fill frames with pending meshes to avoid synchronous triangulation. Background mesh preparation remains deferred to Phase 2.

Changes:

  • Adds mesh-readiness checks and GDI-first backend reporting.
  • Adds hosted synchronous/asynchronous load benchmarks and separate GPU-buffer upload timing.
  • Adds test-host timings and documents measured results and remaining work.

Builds and tests were not run during this review.

File Description
tests/​MapWinGIS.ActiveX.Tests/​VectorLayerRendererTests.cpp Tests GDI-first rendering and subsequent OpenGL selection.
tests/​MapWinGIS.ActiveX.Tests/​RenderingBaselineTests.cpp Adds hosted first-frame benchmarks for both load APIs.
src/​MapWinGIS.Core/​include/​mapwingis/​diagnostics/​PerformanceDiagnostics.h Adds a GPU-buffer upload timing operation.
src/​MapWinGIS.ActiveX/​VectorLayerRenderer.h Documents Automatic and explicit OpenGL behavior.
src/​MapWinGIS.ActiveX/​VectorLayerRenderer.cpp Routes pending-mesh Automatic frames to GDI.
src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.h Declares fill-mesh readiness states and query.
src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp Implements readiness checks and adjusts timing scopes.
samples/​CSharp/​ActiveXTestHost/​README.md Explains backend behavior and displayed timings.
samples/​CSharp/​ActiveXTestHost/​MainForm.cs Displays load and first-repaint durations.
docs/​TESTING.md Documents benchmarks, instrumentation, and measured results.
docs/​ARCHITECTURE.md Describes the GDI-first rendering contract.
.github/​plans/​Vector-Rendering-First-Frame-Performance.md Records the phased plan and Phase 1 results.
.ai/​memory/​build/​cmake.md Records plain-shell CMake setup and presets.
.ai/​memory/​architecture/​activex.md Updates shared knowledge of backend selection.

Review effort: Balanced

@pmeems pmeems left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review. The final decision is with the human reviewer.

CI: VectorLayerRenderer.AutomaticFillWithSceneMeshesUsesOpenGl fails on every build job. Existing review comments already cover this failure (the missing FBO-availability skip), the Failed-readiness retriangulation, and the zero-TriangulationFailures assertion, so they are not repeated here.

…xt exists

- Probe OpenGL availability through the coordinator in AutomaticFillWithSceneMeshesUsesOpenGl and skip on S_FALSE, matching the other OpenGL-conditional tests
Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Automatic mode can still synchronously triangulate replacement or uncached scenes and stall the UI, while an incorrect fallback check causes a regression test to fail on GDI-only systems.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Failed readiness can trigger synchronous triangulation in Automatic mode

src/​MapWinGIS.ActiveX/​VectorLayerRenderer.cpp:49

Automatic still enters OpenGL for Failed readiness, which can synchronously triangulate a replacement scene or an uncached layer following a cached failure. This restores the UI stall because Draw prunes stale entries and prepares missing meshes before rejecting cached failures. Only attempt OpenGL when Automatic Fill readiness is Ready; otherwise prune and use GDI with pending/failure diagnostics, and cover replacement plus both failed/pending layer orders in regression tests.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Distant geometry can make GDI hide visible polygons, stale OpenGL cache entries can falsely report triangulation failures, and probe-contaminated diagnostics cause test failures on framebuffer-capable OpenGL systems.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Cull and clip off-screen polygons before GDI coordinate validation

src/​MapWinGIS.ActiveX/​VectorLayerRenderer.cpp:53

Automatic Fill now keeps complete, mesh-free scenes on GDI across zooms, but GDI skips an entire layer when any transformed vertex exceeds ±134,217,727 (GdiVectorLayerRenderer.cpp:128–143, 284–291). Distant off-screen geometry can therefore make visible polygons disappear, and subsequent Automatic draws cannot recover because they do not prepare meshes. Cull off-screen polygons and safely clip crossing polygons before GDI coordinate validation, with a regression covering visible and distant geometry in the same layer, without reintroducing paint-path triangulation.

3 resolved since last review

Review effort: Balanced

- Report replacement scenes as pending before cache pruning.

- Exclude availability-probe triangulation from test counters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because Automatic’s GDI fallback can discard entire visible layers at extreme zoom, while framebuffer allocation costs remain misattributed to rendering.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

pmeems and others added 2 commits November 25, 2026 16:50
- Move first-use framebuffer storage into the OpenGL initialization scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pmeems
pmeems enabled auto-merge (squash) November 25, 2026 16:33
@pmeems pmeems changed the title MapWinGIS6 – Vector Rendering First-Frame Performance Plan Vector Rendering First-Frame Performance Plan Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants