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

Clear the ShaderProgramPool cached on the Engine object when destroy shaderPass #2409

Closed
wants to merge 1 commit into from

Conversation

Sway007
Copy link
Member

@Sway007 Sway007 commented Oct 30, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • When ShaderPass._destroy is called, ShaderPass._getShaderProgram can still got the cached ShaderProgram from Engine. The PR fix it.
  • Maybe _clearShaderProgramPool is a better name than _destroy under current situation.

Summary by CodeRabbit

  • New Features

    • Introduced a more efficient shader resource management process.
    • Simplified the instantiation of ShaderPass objects with a consolidated constructor.
  • Deprecations

    • Marked getMacroByName and getPropertyByName methods as deprecated, encouraging users to adopt new access methods.
  • Bug Fixes

    • Enhanced the functionality of shader program pool management in the ShaderPass class.

@Sway007 Sway007 added Rendering Rendering related functions shader Shader related functions medium priority Medium priority issue labels Oct 30, 2024
@Sway007 Sway007 self-assigned this Oct 30, 2024
Copy link

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request introduces significant changes to the Shader and ShaderPass classes within the shader management system. The destroy method in the Shader class has been modified to call _clearShaderProgramPool, replacing the previous _destroy method. Additionally, several methods have been marked as deprecated to encourage the use of more specific alternatives. In the ShaderPass class, the _destroy method has been renamed to _clearShaderProgramPool, and the constructor has been simplified by consolidating multiple overloads into a single implementation.

Changes

File Path Change Summary
packages/core/src/shader/Shader.ts - destroy(force: boolean = false): boolean method updated to call _clearShaderProgramPool.
- getMacroByName and getPropertyByName methods marked as deprecated.
packages/core/src/shader/ShaderPass.ts - _destroy(): void method renamed to _clearShaderProgramPool(engine?: Engine): void.
- Constructor overloads consolidated into a single constructor.

Possibly related PRs

Suggested labels

bug, enhancement, high priority

Suggested reviewers

  • zhuxudong
  • GuoLei1990

Poem

In the land of shaders, bright and bold,
Changes afoot, new tales to be told.
With pools cleared and macros in line,
Our code grows stronger, oh how it will shine!
A hop and a skip, we embrace the new way,
For better resource management, hip-hip-hooray! 🐇✨


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member Author

@Sway007 Sway007 Oct 30, 2024

Choose a reason for hiding this comment

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

Not sure whether to change the open api destroy(force: boolean = false): boolean in Shader class to destroy(engine: Engine, forece = false): boolean

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 66.67%. Comparing base (137110e) to head (c9408d4).

Files with missing lines Patch % Lines
packages/core/src/shader/ShaderPass.ts 25.00% 3 Missing ⚠️
packages/core/src/shader/Shader.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           dev/1.4    #2409   +/-   ##
========================================
  Coverage    66.67%   66.67%           
========================================
  Files          895      895           
  Lines        92090    92093    +3     
  Branches      7274     7276    +2     
========================================
+ Hits         61397    61403    +6     
+ Misses       30448    30445    -3     
  Partials       245      245           
Flag Coverage Δ
unittests 66.67% <20.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Sway007 Sway007 marked this pull request as ready for review October 30, 2024 02:19
Copy link

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
packages/core/src/shader/Shader.ts (1)

Line range hint 337-337: Consider making engine dependency explicit in destroy method.

Regarding the previous discussion about changing the method signature to destroy(engine: Engine, force = false): While making the engine dependency explicit would improve clarity, it would be a breaking change. Consider:

  1. Adding it in the next major version
  2. Documenting the implicit engine dependency in the meantime
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 348-348: packages/core/src/shader/Shader.ts#L348
Added line #L348 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 137110e and c9408d4.

📒 Files selected for processing (2)
  • packages/core/src/shader/Shader.ts (1 hunks)
  • packages/core/src/shader/ShaderPass.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/shader/Shader.ts

[warning] 348-348: packages/core/src/shader/Shader.ts#L348
Added line #L348 was not covered by tests

packages/core/src/shader/ShaderPass.ts

[warning] 152-154: packages/core/src/shader/ShaderPass.ts#L152-L154
Added lines #L152 - L154 were not covered by tests

🔇 Additional comments (5)
packages/core/src/shader/Shader.ts (3)

Line range hint 391-419: LGTM! Well-documented deprecation.

The deprecation notice for getMacroByName is clear and provides a proper migration path to ShaderMacro.getByName.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 348-348: packages/core/src/shader/Shader.ts#L348
Added line #L348 was not covered by tests


Line range hint 421-427: LGTM! Well-documented deprecation.

The deprecation notice for getPropertyByName is clear and provides a proper migration path to ShaderProperty.getByName.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 348-348: packages/core/src/shader/Shader.ts#L348
Added line #L348 was not covered by tests


348-348: Add test coverage for shader program pool cleanup.

The change from _destroy to _clearShaderProgramPool correctly implements the intended functionality. However, this critical change lacks test coverage.

Let's verify the test coverage:

Would you like me to help create test cases that verify:

  1. The shader program pool is properly cleared when destroy is called
  2. No cached shader programs can be retrieved after destruction
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 348-348: packages/core/src/shader/Shader.ts#L348
Added line #L348 was not covered by tests

packages/core/src/shader/ShaderPass.ts (2)

146-146: Enhancement: Added optional 'engine' parameter to '_clearShaderProgramPool'

The inclusion of the optional engine parameter in the _clearShaderProgramPool method allows for explicit control over the engine's shader program pool when clearing cached ShaderPrograms. This change improves resource management by ensuring that the engine's cache can be properly cleared upon destruction of a ShaderPass.


152-154: Verify consistent usage of '_clearShaderProgramPool' with 'engine' parameter

Since _clearShaderProgramPool now accepts an optional engine parameter to clear the engine's shader program pool, it's important to ensure that all calls to this method pass the engine parameter when necessary. This will prevent any residual cached ShaderPrograms from persisting unintentionally.

Run the following script to find all usages of _clearShaderProgramPool and check if the engine parameter is being passed:

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 152-154: packages/core/src/shader/ShaderPass.ts#L152-L154
Added lines #L152 - L154 were not covered by tests

Comment on lines +152 to +154
if (engine) {
delete engine._shaderProgramPools[this._shaderPassId];
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add tests to cover the new logic when 'engine' is provided

The newly added lines that delete the shader program pool from the engine are not currently covered by tests, as indicated by static analysis. To ensure the correctness of this functionality and prevent future regressions, please consider adding unit tests that validate the clearing of the shader program pool from the engine when _clearShaderProgramPool is called with an engine parameter.

Would you like assistance in generating unit tests for this code?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 152-154: packages/core/src/shader/ShaderPass.ts#L152-L154
Added lines #L152 - L154 were not covered by tests

@Sway007
Copy link
Member Author

Sway007 commented Oct 30, 2024

fixed by #2410

@Sway007 Sway007 closed this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium priority Medium priority issue Rendering Rendering related functions shader Shader related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant