Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 3D Map View movement performance #60246

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dvdkon
Copy link
Contributor

@dvdkon dvdkon commented Jan 23, 2025

Description

This PR improves the performance of the 3D map view, specifically removing some large stutters when moving the camera.

Currently, all work associated with camera movement (incl. finding which chunks should be visible and loading them) is done in the mouse movement event handler. This is an issue, since such events can come 1000 times a second with standard mice. These events accumulate and overrun the main thread, resulting in stutters.

With this PR, I've changed the event handler to only do the necessary event-specific computations, while leaving the rest to be done at the start of the frame.

I've also added some caching to QgsCameraController::sampleDepthBuffer, which sometimes computes the average depth over the whole depth buffer. This was also happening on every mouse move event and took >20ms on my machine (though release builds are likely to be faster due to inlining, I haven't checked). In this PR, I've added a cache, so this only happens once per frame.

I've also added some new QgsEventTracing trace points which were helpful with analysing performance and finding issues.

@github-actions github-actions bot added this to the 3.42.0 milestone Jan 23, 2025
Previously the entire camera change was handled on every input event,
which led to slowdown and stutters, since we can get ~1000/s such events
with common mice. We don't care about intermediate camera states and
can only process the last state before rendering.
Previously the average could be computed on every mouse move event. This
is a problem, since the loop can be slow, especially on debug builds
where nothing gets inlined.
@wonder-sk wonder-sk added the 3D Relates to QGIS' 3D engine or rendering label Jan 23, 2025
Copy link

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit ee6d434)

Copy link
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

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

Awesome! 🕺

Copy link

Tests failed for Qt 6

One or more tests failed using the build from commit ee6d434

dem_terrain_filtered_2 (testFilteredDemTerrain)

dem_terrain_filtered_2

Test failed at testFilteredDemTerrain at tests/src/3d/testqgs3drendering.cpp:1927

Rendered image did not match tests/testdata/control_images/3d/expected_dem_terrain_filtered_2/expected_dem_terrain_filtered_2.png (found 103123 pixels different)

depth_retrieve_image (testDepthBuffer)

depth_retrieve_image

Test failed at testDepthBuffer at tests/src/3d/testqgs3drendering.cpp:2098

Rendered image did not match tests/testdata/control_images/3d/expected_depth_retrieve_image/expected_depth_retrieve_image.png (found 307008 pixels different)

debug_map_1 (testDebugMap)

debug_map_1

Test failed at testDebugMap at tests/src/3d/testqgs3drendering.cpp:2235

Rendered image did not match tests/testdata/control_images/3d/expected_debug_map_1/qt6/expected_debug_map_1.png (found 3510 pixels different)

virtual_pointcloud_3d_overview (testPointCloud3DOverview)

virtual_pointcloud_3d_overview

Test failed at testPointCloud3DOverview at tests/src/3d/testqgspointcloud3drendering.cpp:603

The full test report (included comparison of rendered vs expected images) can be found here.

Further documentation on the QGIS test infrastructure can be found in the Developer's Guide.

Copy link

Tests failed for Qt 5

One or more tests failed using the build from commit ee6d434

depth_wheel_action_3 (testDepthBuffer)

depth_wheel_action_3

Test failed at testDepthBuffer at tests/src/3d/testqgs3drendering.cpp:2148

Rendered image did not match tests/testdata/control_images/3d/expected_depth_wheel_action_3/expected_depth_wheel_action_3.png (found 23775 pixels different)

debug_map_2 (testDebugMap)

debug_map_2

Test failed at testDebugMap at tests/src/3d/testqgs3drendering.cpp:2249

Rendered image did not match tests/testdata/control_images/3d/expected_debug_map_2/expected_debug_map_2.png (found 520 pixels different)

virtual_pointcloud_3d_overview (testPointCloud3DOverview)

virtual_pointcloud_3d_overview

Test failed at testPointCloud3DOverview at tests/src/3d/testqgspointcloud3drendering.cpp:603

The full test report (included comparison of rendered vs expected images) can be found here.

Further documentation on the QGIS test infrastructure can be found in the Developer's Guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3D Relates to QGIS' 3D engine or rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants