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

Fix renderQueueType error #2437

Merged
merged 3 commits into from
Nov 18, 2024
Merged

Conversation

zhuxudong
Copy link
Member

@zhuxudong zhuxudong commented Nov 14, 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, ...)

Bug Fix.

What is the current behavior? (You can also link to an open issue here)

ShaderPass's renderQueueType will be override by BasicRenderPipeline.pushRenderElementByType

What is the new behavior (if this is a feature change)?

Should Correct true renderQueueType before render.

Summary by CodeRabbit

  • Improvements
    • Enhanced clarity and control flow in the rendering process, leading to more predictable behavior with shader passes.
    • Streamlined handling of render states for improved performance and maintainability.
    • Updated logic for determining render queue types, potentially improving rendering categorization.
    • Introduced a new ShaderLab rendering state configuration for WebGL, enhancing rendering capabilities.
  • Bug Fixes
    • Simplified logic for applying render states to ensure accurate rendering outcomes.

@zhuxudong zhuxudong added the bug Something isn't working label Nov 14, 2024
@zhuxudong zhuxudong self-assigned this Nov 14, 2024
Copy link

coderabbitai bot commented Nov 14, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request enhance the logic within the RenderQueue, BasicRenderPipeline, and RenderState classes. The render method in RenderQueue.ts has been modified to clarify the handling of render states and queue types. In BasicRenderPipeline.ts, the method for determining render queue types has been updated, affecting how render elements are categorized. Additionally, the RenderState class has seen a method rename and a shift in functionality to return a computed render queue type. Overall, these changes improve code clarity and maintainability without altering the fundamental structure.

Changes

File Path Change Summary
packages/core/src/RenderPipeline/RenderQueue.ts Enhanced render method logic by clarifying renderState and simplifying conditional checks.
packages/core/src/RenderPipeline/BasicRenderPipeline.ts Updated pushRenderElementByType method to use _getRenderQueueByShaderData, refining render queue type determination.
packages/core/src/shader/state/RenderState.ts Renamed _applyRenderQueueByShaderData to _getRenderQueueByShaderData, changing its return type to RenderQueueType and altering its internal logic.
e2e/case/shaderLab-renderState.ts Introduced new file for ShaderLab rendering state configuration with shader setup and entity creation.
e2e/config.ts Added new entry "shaderLab-renderState" to E2E_CONFIG for end-to-end testing configuration.

Possibly related PRs

  • Support post process #2129: The changes in the BasicRenderPipeline class regarding the render queue type determination may relate to the modifications in the RenderQueue class's render method, as both involve handling render queue types and shader data.
  • Refactor sprite mask system #2369: The refactor of the RenderQueue class's rendering logic, particularly in relation to mask interactions, could be relevant to the changes made in the RenderQueue class in the main PR, as both involve rendering logic and queue management.
  • Improve ShaderLab's compatiblity with the RenderState of Material #2378: The improvements in ShaderLab's compatibility with RenderState may connect to the changes in the RenderQueue class, as both involve shader state management and rendering processes.
  • Fix background render error when render to RT #2414: The updates to the BasicRenderPipeline class's rendering methods, particularly regarding shader data and camera integration, may relate to the changes in the RenderQueue class's handling of shader passes and render states.
  • Fix shaderlab loader in NPM mode #2427: The modifications in the MaterialLoader class regarding shader retrieval may connect to the changes in the RenderQueue class, as both involve shader management and rendering processes.

Suggested labels

Rendering, shader, high priority

Suggested reviewers

  • GuoLei1990
  • Sway007

🐇 In the realm of code where the shaders play,
The RenderQueue shines in a clearer way.
With states refined and logic tight,
Our rendering path is now more bright!
So hop along, let the pixels gleam,
In this code garden, we build our dream! 🌟


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

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 70.77%. Comparing base (7da32a5) to head (02b8e40).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/src/RenderPipeline/RenderQueue.ts 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2437      +/-   ##
==========================================
+ Coverage   69.44%   70.77%   +1.33%     
==========================================
  Files         524      524              
  Lines       27484    27487       +3     
  Branches     4112     4111       -1     
==========================================
+ Hits        19085    19453     +368     
+ Misses       6894     6479     -415     
- Partials     1505     1555      +50     
Flag Coverage Δ
unittests 70.77% <91.66%> (+1.33%) ⬆️

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.

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: 0

🧹 Outside diff range and nitpick comments (2)
packages/core/src/RenderPipeline/RenderQueue.ts (2)

108-108: Consider adding type validation for renderState.

While the simplified check is good, consider adding runtime validation to ensure renderState is never undefined at this point, as that could lead to a TypeError.

+        if (!renderState) {
+          continue;
+        }
         if (renderState.renderQueueType !== renderQueueType) {
           continue;
         }

102-108: Add tests to prevent regression.

The changes look good, but according to the PR description, no tests were added. Consider adding tests that verify:

  1. Correct precedence of render states
  2. Proper application of shader-specific render queue types
  3. Edge cases with undefined or null render states

Would you like me to help create test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7da32a5 and 77fefc3.

📒 Files selected for processing (1)
  • packages/core/src/RenderPipeline/RenderQueue.ts (1 hunks)
🔇 Additional comments (2)
packages/core/src/RenderPipeline/RenderQueue.ts (2)

102-103: LGTM! Clear precedence for render state resolution.

The nullish coalescing operator provides a clean way to prioritize shader pass render state while falling back to render states array when needed.


104-106: Verify that this fixes the renderQueueType override issue.

This change ensures that shader-specific render state is properly applied before the render queue type check. Let's verify this resolves the reported issue where renderQueueType was being incorrectly overridden.

✅ Verification successful

Verified: The renderQueueType override fix is correctly implemented

The implementation in RenderState._applyRenderQueueByShaderData shows that the renderQueueType is properly handled:

  1. It first checks if renderQueueType exists in the shader pass's renderStateDataMap
  2. If present, it sets the renderQueueType from shader data with a fallback to Opaque
  3. This happens before the render queue type check in the render pipeline, ensuring correct queue type application
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related tests or usage patterns
rg -A 5 "_renderStateDataMap" 

# Look for any other places where renderQueueType might be modified
ast-grep --pattern 'renderQueueType = $_'

# Check for related bug reports or issues
rg -l "renderQueueType.*override"

Length of output: 4558


Script:

#!/bin/bash
# Check the implementation of _applyRenderQueueByShaderData to understand the fix
ast-grep --pattern '_applyRenderQueueByShaderData($_,$_) {
  $$$
}'

# Look for RenderState class definition and renderQueueType property
ast-grep --pattern 'class RenderState {
  $$$
}'

# Search for any tests related to render queue type
rg -l "renderQueueType.*test"

Length of output: 5238

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: 0

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

64-67: Consider adding type safety for renderStateDataMap values.

The implementation looks good and handles undefined cases correctly. However, there's room for improvement in type safety.

Consider adding a type guard or assertion to ensure renderStateDataMap[RenderStateElementKey.RenderQueueType] is of type ShaderProperty:

  _getRenderQueueByShaderData(
    renderStateDataMap: Record<number, ShaderProperty>,
    shaderData: ShaderData
  ): RenderQueueType {
    const renderQueueType = renderStateDataMap[RenderStateElementKey.RenderQueueType];
-   if (renderQueueType === undefined) {
+   if (!renderQueueType || !(renderQueueType instanceof ShaderProperty)) {
      return this.renderQueueType;
    } else {
      return shaderData.getFloat(renderQueueType) ?? RenderQueueType.Opaque;
    }
  }
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

272-275: Consider adding test coverage for render queue assignment

Since this fixes a critical rendering issue, it would be valuable to add test cases that verify:

  1. Correct queue type determination for different shader configurations
  2. Proper handling of render states
  3. Queue assignment for each type (Opaque, AlphaTest, Transparent)

Would you like me to help create test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 77fefc3 and 0225664.

📒 Files selected for processing (3)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1 hunks)
  • packages/core/src/RenderPipeline/RenderQueue.ts (1 hunks)
  • packages/core/src/shader/state/RenderState.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/RenderPipeline/RenderQueue.ts
🔇 Additional comments (3)
packages/core/src/shader/state/RenderState.ts (2)

59-62: LGTM! Method signature change improves code design.

The change from void to returning RenderQueueType makes the code more functional and gives better control to callers for determining the final queue type.


59-67: Verify all callers are updated to handle the return value.

Let's ensure all callers are properly updated to handle the return value instead of expecting the previous void behavior.

✅ Verification successful

Let me analyze the call sites of _getRenderQueueByShaderData to verify how the return value is being used.


Based on the analysis of the call sites, I can now generate the final response:

The return value is properly handled by all callers

The method _getRenderQueueByShaderData is called in two places:

  • BasicRenderPipeline.ts: assigns the return value to renderQueueType
  • RenderQueue.ts: assigns the return value to passQueueType

Both callers correctly handle the return value of type RenderQueueType, and there are no instances of the old method name in the codebase, indicating a complete migration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to both old and new method names to ensure complete migration
echo "Searching for old method calls (_applyRenderQueueByShaderData):"
rg "_applyRenderQueueByShaderData" --type ts

echo -e "\nSearching for new method calls (_getRenderQueueByShaderData):"
rg "_getRenderQueueByShaderData" --type ts

echo -e "\nSearching for RenderState usage patterns:"
ast-grep --pattern 'new RenderState()' 

Length of output: 1392


Script:

#!/bin/bash
# Check how the return value is used in BasicRenderPipeline
echo "BasicRenderPipeline usage:"
rg -B 2 -A 2 "_getRenderQueueByShaderData" packages/core/src/RenderPipeline/BasicRenderPipeline.ts

echo -e "\nRenderQueue usage:"
rg -B 2 -A 2 "_getRenderQueueByShaderData" packages/core/src/RenderPipeline/RenderQueue.ts

# Check the method implementation
echo -e "\nRenderState implementation:"
rg -B 5 -A 5 "_getRenderQueueByShaderData" packages/core/src/shader/state/RenderState.ts

Length of output: 1297

packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

272-275: LGTM! Fix for renderQueueType determination

The change from _applyRenderQueueByShaderData to _getRenderQueueByShaderData correctly addresses the issue where renderQueueType was being overridden. The new method properly determines the queue type based on shader data without modifying it.

Let's verify the impact of this change on render queue assignments:

✅ Verification successful

Based on the search results, I can now generate the final response:

Verified: renderQueueType determination change is safe and consistent

The change to use _getRenderQueueByShaderData is correct and aligns with existing usage patterns in the codebase:

  • The method is already being used in RenderQueue.ts for queue type determination
  • No other instances of the old _applyRenderQueueByShaderData method exist, confirming complete migration
  • All other renderQueueType modifications happen through proper state management in RenderState and material classes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other potential renderQueue type modifications
# Look for any other places that might be modifying renderQueueType

# Search for methods that might modify renderQueueType
rg -g '*.ts' '(set|apply|modify|override).*[Rr]enderQueue'

# Search for direct assignments to renderQueueType
rg -g '*.ts' 'renderQueueType\s*='

# Search for related RenderState usage
rg -g '*.ts' '_getRenderQueueByShaderData|_applyRenderQueueByShaderData'

Length of output: 3487

@GuoLei1990 GuoLei1990 merged commit f9fc2c6 into galacean:main Nov 18, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants