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

Misc. OpenGL improvements and fixes #573

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

maurhofer-ubique
Copy link
Contributor

@maurhofer-ubique maurhofer-ubique commented Jan 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a shorter string representation for Tiled2dMapTileInfo to provide more concise output.
    • Increased the maximum number of graphics tasks and extended the maximum time for graphics tasks to enhance performance.
  • Performance Improvements

    • Optimized OpenGL buffer handling across various graphical objects to prevent redundant operations.
    • Improved control flow for updating raster tiles and vector source data management.
  • Bug Fixes

    • Fixed shader uniform value setting logic for line and polygon styles.
    • Corrected the conditional logic in the ValueEvaluator class to enhance reliability.
  • Refactor

    • Streamlined OpenGL data buffer generation checks with a unified flag across multiple classes.
    • Reorganized class implementations and lifecycles for Tiled2dMapVectorSymbolObject.
  • Documentation

    • No visible changes for end-users.
  • Style

    • No visible changes for end-users.
  • Tests

    • No visible changes for end-users.
  • Chores

    • No visible changes for end-users.
  • Revert

    • No visible changes for end-users.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2024

Warning

Rate Limit Exceeded

@maurhofer-ubique has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 43 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8410049 and 11ade9f.

Walkthrough

The updates across various files in the Android graphics package reflect an optimization effort, primarily focusing on improving the management of OpenGL data buffers. A new boolean flag glDataBuffersGenerated is introduced to track buffer generation, preventing redundant operations. The changes streamline buffer generation and deletion processes, enhance dynamic data buffer handling, and adjust shader uniform settings. Additionally, the thread pool scheduler's parameters are tweaked to better accommodate graphics tasks.

Changes

File Path Change Summary
.../graphics/objects/*2dOpenGl.cpp
.../graphics/objects/*2dOpenGl.h
Introduced glDataBuffersGenerated to manage OpenGL buffer generation and deletion.
.../graphics/objects/Quad2dInstancedOpenGl.cpp
.../graphics/objects/Quad2dStretchedInstancedOpenGl.cpp
.../graphics/objects/Text2dInstancedOpenGl.cpp
Updated to use dynamic instance data buffers and modified attribute pointer settings.
.../graphics/shader/Color*2dShaderOpenGl.cpp Modified glUniform1fv call parameters and adjusted uniform value setting logic.
.../map/layers/tiled/vector/sourcemanagers/*2dMapVectorSource*.cpp
.../map/layers/tiled/vector/sourcemanagers/*2dMapVectorSource*.h
Optimized control flow logic for updating mask objects and managing pending updates.
.../map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp
.../map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h
Added destructor and placedInCache method, reorganized class implementation.
shared/public/Tiled2dMapTileInfo.h Added to_string_short method for concise string representation.
shared/public/Value.h Included "Logger.h" header and refined conditional logic within ValueEvaluator.
shared/src/map/scheduling/ThreadPoolSchedulerImpl.h Increased the number of graphics tasks and the maximum time allocation for them.

🐇✨
To buffers born and buffers gone,
The rabbit hopped from dusk till dawn.
With flags unfurled and data tight,
It leapt through code with all its might.
🎉🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8ebf024 and 5561ef6.
Files selected for processing (29)
  • android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.cpp (3 hunks)
  • android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.h (1 hunks)
  • android/src/main/cpp/graphics/objects/Polygon2dOpenGl.cpp (2 hunks)
  • android/src/main/cpp/graphics/objects/Polygon2dOpenGl.h (1 hunks)
  • android/src/main/cpp/graphics/objects/PolygonGroup2dOpenGl.cpp (2 hunks)
  • android/src/main/cpp/graphics/objects/PolygonGroup2dOpenGl.h (1 hunks)
  • android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.cpp (2 hunks)
  • android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.h (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (4 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.h (2 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (5 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.h (2 hunks)
  • android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (5 hunks)
  • android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.h (2 hunks)
  • android/src/main/cpp/graphics/objects/Text2dOpenGl.cpp (2 hunks)
  • android/src/main/cpp/graphics/objects/Text2dOpenGl.h (1 hunks)
  • android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/shader/ColorPolygonGroup2dShaderOpenGl.cpp (2 hunks)
  • shared/public/Tiled2dMapTileInfo.h (1 hunks)
  • shared/public/Value.h (3 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceRasterTileDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.h (1 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceVectorTileDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1 hunks)
  • shared/src/map/scheduling/ThreadPoolSchedulerImpl.h (1 hunks)
Additional comments: 55
shared/public/Tiled2dMapTileInfo.h (1)
  • 51-53: The addition of the to_string_short method provides a more concise string representation of the Tiled2dMapTileInfo object, which could be useful for logging or debugging purposes where the full class name is not required.
android/src/main/cpp/graphics/objects/PolygonGroup2dOpenGl.h (1)
  • 62-66: Initializing the attribBuffer and indexBuffer to -1 and glDataBuffersGenerated to false is a good practice to ensure that these variables have a known state before they are used.
shared/src/map/scheduling/ThreadPoolSchedulerImpl.h (1)
  • 60-61: Increasing the MAX_NUM_GRAPHICS_TASKS to 128 and MAX_TIME_GRAPHICS_TASKS_MS to 6 milliseconds is a reasonable change to potentially improve the handling of graphics tasks within the thread pool scheduler.
android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.h (1)
  • 67-71: Initializing vertexAttribBuffer and indexBuffer with default values and adding the glDataBuffersGenerated member variable are good changes for managing OpenGL data buffers more efficiently.
android/src/main/cpp/graphics/objects/Polygon2dOpenGl.h (1)
  • 69-70: The addition of the glDataBuffersGenerated boolean member variable is a good practice to track the generation state of OpenGL data buffers, which can help prevent unnecessary buffer operations.
android/src/main/cpp/graphics/objects/Text2dOpenGl.h (1)
  • 77-77: Replacing the hasVertexBuffer and hasIndexBuffer flags with a single glDataBuffersGenerated flag simplifies the logic related to OpenGL data buffer generation.
android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.h (1)
  • 84-84: The introduction of the glDataBuffersGenerated boolean member variable in the PolygonPatternGroup2dOpenGl class is a good addition for tracking OpenGL buffer state.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.h (1)
  • 76-76: Adding the std::atomic_flag named noPendingUpdateMasks is a thread-safe way to manage the state of pending updates, which can improve the efficiency of the update mechanism.
android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.h (1)
  • 110-133: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [92-128]

The consolidation of buffer-related member variables into dynamicInstanceDataBuffer and the renaming of the writeToBuffer method to writeToDynamicInstanceDataBuffer are good changes that simplify the buffer management strategy.

android/src/main/cpp/graphics/shader/ColorPolygonGroup2dShaderOpenGl.cpp (2)
  • 56-56: The modification of the glUniform1fv function call to use the correct size parameters ensures that the correct number of style values are passed to the shader, which is crucial for rendering the polygons with the correct styles.
  • 69-69: Moving the assignment of this->numStyles to before the end of the setStyles method is a logical change that ensures the member variable is updated after the styles are copied.
android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.h (1)
  • 115-135: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [97-130]

The addition of the glDataBuffersGenerated boolean member and the dynamicInstanceDataBuffer, along with the removal of specific buffer variables, are good changes that streamline the management of OpenGL data buffers.

android/src/main/cpp/graphics/objects/PolygonGroup2dOpenGl.cpp (1)
  • 58-75: The conditional generation and deletion of OpenGL buffers in the setup and removeGlBuffers methods, along with the use of the glDataBuffersGenerated flag, are good practices that can help prevent redundant OpenGL operations and optimize performance.
android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.h (1)
  • 117-142: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [99-138]

The introduction of the glDataBuffersGenerated flag and the dynamicInstanceDataBuffer, as well as the removal of specific buffer variables and the addition of static constants for buffer offsets, are good changes that simplify the buffer management and improve the code structure.

android/src/main/cpp/graphics/objects/Polygon2dOpenGl.cpp (1)
  • 61-77: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [64-95]

The conditional generation and deletion of OpenGL buffers in the prepareGlData and removeGlBuffers methods, along with the introduction of the glDataBuffersGenerated flag, are good practices that can help prevent redundant OpenGL operations and optimize performance.

android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.cpp (4)
  • 63-65: The conditional generation of the vertex buffer is correctly implemented, ensuring it's only done if glDataBuffersGenerated is false.
  • 70-72: The conditional generation of the index buffer follows the same correct pattern as the vertex buffer.
  • 81-81: Setting glDataBuffersGenerated to true after generating the buffers ensures that the buffers won't be unnecessarily regenerated.
  • 93-97: The conditional deletion of both vertex and index buffers is correctly implemented, with the flag being reset after deletion.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (2)
  • 55-55: Ensure that the destructor definition for Tiled2dMapVectorSymbolObject has been correctly moved to the implementation file.
Verification successful

The output from the shell script confirms that the destructor for Tiled2dMapVectorSymbolObject has been defined in the corresponding .cpp file, which is shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp. This verifies that the structural change mentioned in the review comment has been correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the destructor is defined in the corresponding .cpp file
rg "Tiled2dMapVectorSymbolObject::~Tiled2dMapVectorSymbolObject" --type cpp

Length of output: 216

* 57-57: Similarly, verify that the `placedInCache` method definition is present in the implementation file.
Verification successful

The placedInCache method definition for the Tiled2dMapVectorSymbolObject class is indeed present in the corresponding .cpp file as confirmed by the output of the executed script.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the placedInCache method is defined in the corresponding .cpp file
rg "void Tiled2dMapVectorSymbolObject::placedInCache" --type cpp

Length of output: 194

android/src/main/cpp/graphics/objects/Quad2dOpenGl.cpp (1)
  • 125-129: The conditional deletion of OpenGL buffers in removeGlBuffers is correctly implemented, with the flag being reset after deletion.
android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.cpp (3)
  • 69-71: The conditional generation of the vertex buffer in prepareGlData is correctly implemented, ensuring it's only done if glDataBuffersGenerated is false.
  • 77-79: The conditional generation of the index buffer follows the same correct pattern as the vertex buffer.
  • 99-103: The conditional deletion of both vertex and index buffers in removeGlBuffers is correctly implemented, with the flag being reset after deletion.
android/src/main/cpp/graphics/objects/Text2dOpenGl.cpp (3)
  • 140-147: The conditional generation of vertex and index buffers in prepareGlData is correctly implemented, ensuring it's only done if glDataBuffersGenerated is false.
  • 161-161: Setting glDataBuffersGenerated to true after generating the buffers ensures that the buffers won't be unnecessarily regenerated.
  • 166-169: The conditional deletion of both vertex and index buffers in removeGlBuffers is correctly implemented, with the flag being reset after deletion.
android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (7)
  • 84-86: The conditional generation of the vertex buffer in prepareGlData is correctly implemented, ensuring it's only done if glDataBuffersGenerated is false.
  • 90-95: The conditional generation of the dynamic instance data buffer is correctly implemented, which is crucial for instanced rendering.
  • 98-100: The conditional generation of the index buffer follows the same correct pattern as the vertex buffer.
  • 113-113: Setting glDataBuffersGenerated to true after generating the buffers ensures that the buffers won't be unnecessarily regenerated.
  • 138-143: The conditional deletion of vertex, index, and dynamic instance data buffers in removeGlBuffers is correctly implemented, with the flag being reset after deletion.
  • 225-238: The attribute pointer settings for position, rotation, texture coordinates, scales, and alphas are correctly updated to use dynamic instance data buffers.
  • 302-341: The method writeToDynamicInstanceDataBuffer is correctly implemented to update the dynamic instance data buffer with new data.
android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (4)
  • 82-99: The conditional generation of OpenGL buffers using the glDataBuffersGenerated flag is correctly implemented to avoid redundant buffer generation. This should improve performance by ensuring buffers are only created once.
  • 138-144: The conditional deletion of OpenGL buffers using the glDataBuffersGenerated flag is correctly implemented to ensure buffers are deleted only if they have been created.
  • 219-232: The attribute pointer settings and buffer data writing methods have been updated correctly to use the dynamicInstanceDataBuffer. This change is part of the refactoring for managing dynamic instance data buffers.
  • 297-331: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [300-352]

The writeToDynamicInstanceDataBuffer method is correctly used to update buffer data, and the buffersNotReady flag is updated accordingly. This ensures that buffer data is only written when the object is ready, and the flags are cleared when the data is successfully written.

android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (4)
  • 85-101: The conditional generation of OpenGL buffers using the glDataBuffersGenerated flag is correctly implemented, similar to the previous file. This change is consistent and follows the same pattern for buffer management.
  • 140-145: The conditional deletion of OpenGL buffers is correctly implemented, ensuring that buffers are deleted only if they have been created, which is consistent with the changes in the Text2dInstancedOpenGl.cpp file.
  • 224-246: The attribute pointer settings and buffer data writing methods have been updated correctly to use the dynamicInstanceDataBuffer, which is part of the refactoring for managing dynamic instance data buffers.
  • 318-364: The writeToDynamicInstanceDataBuffer method is used correctly to update buffer data, and the buffersNotReady flag is updated accordingly. This ensures that buffer data is only written when the object is ready, and the flags are cleared when the data is successfully written.
android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp (1)
  • 53-53: The modification to the glUniform1fv call to use numStyles * sizeLineValues as the size parameter is correct. This change ensures that the correct size is used when setting uniform values for line styles in the shader.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceRasterTileDataManager.cpp (1)
  • 154-154: The direct clearing of noPendingUpdateMasks without calling updateMaskObjects is a control flow change that simplifies the logic. This change is consistent with the PR objectives to streamline the update process for map vector sources and symbols.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceVectorTileDataManager.cpp (1)
  • 158-158: The direct call to noPendingUpdateMasks.clear() replaces a previous message dispatching mechanism. This change simplifies the control flow and potentially improves performance by avoiding the overhead of message dispatching.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.cpp (1)
  • 20-22: The addition of a conditional check using noPendingUpdateMasks.test_and_set() before calling updateMaskObjects() is a good practice to ensure that the update is only performed when necessary, which can help in avoiding redundant operations and improving performance.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (4)
  • 561-561: The introduction of the clearCoordinator boolean variable is a good practice to avoid unnecessary operations if tilesToClear is empty.
  • 561-567: The logic to clear symbol groups only when tilesToClear is not empty is correctly implemented.
  • 567-567: Clearing the tilesToClear vector after processing is a good practice to prevent memory leaks and ensure that the data is up-to-date.
  • 569-569: Conditionally clearing animation coordinators based on the clearCoordinator flag is an efficient way to manage resources.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (3)
  • 164-172: The destructor correctly manages the lifecycle of the animationCoordinator by checking ownership and decreasing usage. This is important for proper resource management.
  • 174-181: The new method placedInCache is added to handle the case when the symbol object is placed in the cache. It properly clears the ownership flag if the object is the owner, which is consistent with the logic in the destructor.
  • 183-184: The updateLayerDescription method's parameters have been reordered for consistency. This change should be cross-checked to ensure all calls to this method have been updated accordingly.
shared/public/Value.h (1)
  • 43-43: The inclusion of "Logger.h" is added to provide logging capabilities within this file. This is a standard practice for enabling logging.

maurhofer-ubique and others added 4 commits January 22, 2024 08:57
…s in source tile data manager on update, allow more gl tasks on pre-render (within given time constraint), don't cache zoom-dependent values (prevent cache overflow)
@maurhofer-ubique maurhofer-ubique force-pushed the bugfix/opengl-cleanup-improvements branch from 5561ef6 to 11ade9f Compare January 22, 2024 07:58
@maurhofer-ubique maurhofer-ubique merged commit 39e9356 into develop Jan 22, 2024
2 checks passed
@maurhofer-ubique maurhofer-ubique deleted the bugfix/opengl-cleanup-improvements branch January 22, 2024 08:04
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