8000 Path in `#include` directive support relative path against to shader's path AND fix code generation error when target language is gles 100 by Sway007 · Pull Request #2241 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Path in #include directive support relative path against to shader's path AND fix code generation error when target language is gles 100 #2241

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

Merged
merged 19 commits into from
Jul 18, 2024

Conversation

Sway007
Copy link
Member
@Sway007 Sway007 commented Jul 18, 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, ...)

In ShaderLab you can import common shader chunk by #include directive, but only with absolute path. now you can import shader chunk with relative path which is aganst to the path of the main shader file.

// relative path
#include "./some_chunk.glsl"

// absolute path aginst to project root
#include "shaders/custom.glsl"
// builtin shader chunk
#include "brdf.glsl"

Complement extension enable directive when target language is gles 100.

Summary by CodeRabbit

  • New Features

    • Enhanced shader path handling, allowing more flexibility in specifying and managing shader source paths.
    • Improved parsing logic for shader passes with new parameters for origin and base paths.
  • Bug Fixes

    • Corrected the #include directive in test shaders to reference the correct relative path.
  • Refactor

    • Consolidated shader version and extension handling in various GLES visitors for better maintainability.

@Sway007 Sway007 added enhancement New feature or request shader Shader related functions high priority High priority issue labels Jul 18, 2024
@Sway007 Sway007 requested review from GuoLei1990 and zhuxudong July 18, 2024 02:47
@Sway007 Sway007 self-assigned this Jul 18, 2024
Copy link
coderabbitai bot commented Jul 18, 2024

Warning

Rate limit exceeded

@Sway007 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 38 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 d7e0ac8 and 00447fb.

Walkthrough

The updates introduce enhanced shader path handling and configurability. Changes span across several files, primarily in shader-related classes, interfaces, and methods. Key modifications include additional parameters for path management in constructors and methods, adjustments to shader compilation processes, and improved path resolution for shader includes.

Changes

Files/Paths Change Summaries
packages/core/src/shader/Shader.ts Introduced a new parameter path in the create method, along with a method _registerPath to manage paths for all shader passes. Adjusted method signatures and logic for handling cases without fragmentSource.
packages/core/src/shader/ShaderPass.ts Added _shaderRootPath and _path properties, updated the constructor with a path parameter, and included logic for paths and macros during shader compilation.
packages/design/src/shader-lab/IShaderLab.ts Added pathOrigin and basePathForIncludeKey parameters to _parseShaderPass for better path resolution.
packages/shader-lab/src/ShaderLab.ts Enhanced constructor with pathOrigin and basePathForIncludeKey parameters, updated Preprocessor.reset call, and modified createPasses to include URL construction.
packages/shader-lab/src/codeGen/... Updated GLES100Visitor, GLES300Visitor, and GLESVisitor classes with _versionText and _extensions properties for better GL version and extension management.
packages/shader-lab/src/preprocessor/... Added pathOrigin and basePathForIncludeKey parameters to PpParser and Preprocessor classes, updated addPredefinedMacro logic for path handling.
tests/src/shader-lab/... Enhanced glslValidate function with shaderPath and fragmentPath parameters, updated shader include directive in the test shader.

Poem

In shaders deep with paths so clear,
We navigate with newfound cheer.
Enhancements made with care and might,
To guide our code through darkest night.
With path in hand, we'll lead the way,
To render worlds where shadows play.
🐇✨


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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

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.

@Sway007 Sway007 changed the title Path in #include directive support relative path against to shader's path Path in #include directive support relative path against to shader's path AND fix code generation error when target language is gles 100 Jul 18, 2024
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, codebase verification and nitpick comments (2)
packages/design/src/shader-lab/IShaderLab.ts (1)

17-18: Ensure all calls to _parseShaderPass include the new parameters.

The addition of pathOrigin and basePathForIncludeKey parameters enhances the functionality of _parseShaderPass. However, the following instances need to be updated to include these new parameters:

  • tests/src/shader-lab/ShaderValidate.ts
  • packages/design/src/shader-lab/IShaderLab.ts
  • packages/core/src/shader/ShaderPass.ts
  • packages/shader-lab/src/ShaderLab.ts

Please update these calls to ensure compatibility with the new parameters.

Analysis chain

LGTM! Ensure compatibility with the new parameters.

The addition of pathOrigin and basePathForIncludeKey parameters to _parseShaderPass enhances the functionality by allowing relative paths in shader includes.

Verify that all calls to _parseShaderPass in the codebase are updated to include these new parameters.

Also applies to: 27-28

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `_parseShaderPass` include the new parameters.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'_parseShaderPass'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all calls to `_parseShaderPass` include the new parameters.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 _parseShaderPass

Length of output: 2633

packages/core/src/shader/Shader.ts (1)

47-47: Some usages of Shader.create do not provide the new path parameter.

The following instances of Shader.create need to be updated to include the path parameter:

  • examples/buffer-mesh-particle-shader-effect.ts
  • examples/outline-multi-pass.ts
  • examples/sprite-material-dissolve.ts
  • examples/video-transparent.ts
  • examples/video-background.ts
  • examples/transparent-shadow.ts
  • examples/shader-water.ts
  • examples/shader-lab.ts
  • examples/text-ktv-subtitle.ts
  • examples/shader-lab-multi-pass.ts
  • examples/shader-replacement.ts
  • examples/sprite-material-blur.ts
  • examples/mrt.ts
  • examples/model-mesh.ts
  • examples/sprite-material-glitch-rgbSplit.ts
  • examples/shader-lab-simple.ts
  • examples/material-head-distort.ts
  • examples/ibl-baker.ts
  • examples/camera-depth-texture.ts
  • examples/cascaded-shadow.ts
  • examples/buffer-mesh-instance.ts
  • tests/src/core/Shader.test.ts
  • tests/src/core/Camera.test.ts
  • packages/core/src/postProcess/index.ts
  • packages/core/src/postProcess/effects/BloomEffect.ts
  • packages/core/src/trail/TrailMaterial.ts
  • packages/core/src/shader/ShaderPool.ts
  • tests/src/shader-lab/ShaderLab.test.ts
  • e2e/case/material-shaderLab.ts
  • e2e/case/material-shaderReplacement.ts
  • e2e/case/camera-opaque-texture.ts

Please update these instances to ensure the path parameter is provided where necessary.

Analysis chain

Verify the usage of the new path parameter.

Ensure that all usages of the Shader.create method provide the new path parameter when needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `Shader.create` method provide the new `path` parameter when needed.

# Test: Search for the method usage. Expect: Only occurrences with the new parameter.
rg --type ts -A 5 $'Shader.create'

Length of output: 15969

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5dc3bd and 964b846.

Files selected for processing (11)
  • packages/core/src/shader/Shader.ts (4 hunks)
  • packages/core/src/shader/ShaderPass.ts (7 hunks)
  • packages/design/src/shader-lab/IShaderLab.ts (1 hunks)
  • packages/shader-lab/src/ShaderLab.ts (2 hunks)
  • packages/shader-lab/src/codeGen/GLES100.ts (1 hunks)
  • packages/shader-lab/src/codeGen/GLES300.ts (1 hunks)
  • packages/shader-lab/src/codeGen/GLESVisitor.ts (3 hunks)
  • packages/shader-lab/src/preprocessor/PpParser.ts (2 hunks)
  • packages/shader-lab/src/preprocessor/Preprocessor.ts (1 hunks)
  • tests/src/shader-lab/ShaderValidate.ts (1 hunks)
  • tests/src/shader-lab/shaders/unlit.shader (1 hunks)
Additional context used
Biome
packages/shader-lab/src/preprocessor/PpParser.ts

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 42-42: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (19)
packages/shader-lab/src/preprocessor/Preprocessor.ts (1)

10-12: LGTM! Ensure compatibility with the new parameters.

The addition of pathOrigin and basePathForIncludeKey parameters to reset enhances the functionality by allowing relative paths in shader includes.

Verify that all calls to reset in the codebase are updated to include these new parameters.

Also applies to: 13-14

packages/shader-lab/src/codeGen/GLES100.ts (1)

7-15: LGTM!

The addition of _versionText and _extensions properties to GLES100Visitor enhances the functionality by defining the GLSL version and enabling specific GL extensions. The implementation is clear and follows best practices.

tests/src/shader-lab/ShaderValidate.ts (1)

89-91: LGTM!

The addition of shaderPath and fragmentPath parameters to glslValidate enhances the functionality by allowing the specification of paths for the shader and fragment files. The implementation is clear and follows best practices.

packages/shader-lab/src/codeGen/GLES300.ts (1)

14-14: LGTM! Encapsulation of version text.

The change encapsulates the versionText property by overriding it with _versionText, which is a good practice.

packages/shader-lab/src/ShaderLab.ts (3)

56-58: Addition of new parameters to _parseShaderPass.

The new parameters pathOrigin and basePathForIncludeKey have been added to the _parseShaderPass method. Ensure these parameters are correctly passed and used in the method.


61-61: Update to Preprocessor.reset method call.

The Preprocessor.reset method call has been updated to include the new parameters pathOrigin and basePathForIncludeKey. Ensure that the Preprocessor class handles these parameters correctly.


123-125: Addition of new parameters to _parse method.

The new parameters pathOrigin and basePathForIncludeKey have been added to the _parse method. Ensure these parameters are correctly passed and used in the method.

tests/src/shader-lab/shaders/unlit.shader (1)

57-57: LGTM! Support for relative paths in #include directive.

The change updates the #include directive to use a relative path, enhancing flexibility.

packages/shader-lab/src/codeGen/GLESVisitor.ts (3)

14-15: Addition of _versionText and _extensions properties.

The new protected properties _versionText and _extensions have been added to the GLESVisitor class. These properties encapsulate the version text and extensions, respectively.


85-85: Update to return statement in vertexMain method.

The return statement in the vertexMain method now includes _versionText, encapsulating the version text.


105-105: Update to return statement in _fragmentMain method.

The return statement in the _fragmentMain method now includes _versionText and _extensions, encapsulating the version text and extensions.

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

Line range hint 164-192: Ensure platform macros are correctly handled.

The platform macros are being reset and set based on hardware capabilities. This looks good, but ensure that the macros are correctly handled in all cases.


Line range hint 108-123: LGTM!

The _getShaderProgram method handles shader program retrieval and compilation correctly.


Line range hint 164-192: LGTM!

The _compileShaderProgram method handles shader program compilation correctly.


43-43: Verify the usage of the new path parameter.

Ensure that all usages of the ShaderPass constructor provide the new path parameter.

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

88-92: Ensure all cases for shader creation are correctly handled.

The updated logic handles cases where fragmentSource is not provided. Ensure that all cases for shader creation are correctly handled.


152-162: Ensure all cases for shader creation are correctly handled.

The updated logic handles cases where vertexSourceOrShaderPassesOrSubShadersOrPath is a string. Ensure that all cases for shader creation are correctly handled.

packages/shader-lab/src/preprocessor/PpParser.ts (2)

34-42: Ensure the new parameters are correctly handled.

The reset method has been updated to include new parameters pathOrigin and basePathForIncludeKey. Ensure that these parameters are correctly handled in all cases.

Tools
Biome

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 42-42: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


101-108: Ensure the new parameters are correctly handled.

The _parseInclude method has been updated to handle the new basePathForIncludeKey and pathOrigin parameters. Ensure that these parameters are correctly handled in all cases.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 964b846 and f6fed8b.

Files selected for processing (1)
  • packages/shader-lab/src/preprocessor/PpParser.ts (2 hunks)
Additional context used
Biome
packages/shader-lab/src/preprocessor/PpParser.ts

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 42-42: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (2)
packages/shader-lab/src/preprocessor/PpParser.ts (2)

31-32: New static variables added for path handling.

The static variables _basePathForIncludeKey and _pathOrigin have been added to handle the base path and origin for include directives.


101-108: Updated _parseInclude method to handle relative paths.

The _parseInclude method now correctly handles relative paths using the _basePathForIncludeKey and _pathOrigin variables. Ensure that the path handling logic is thoroughly tested.

Comment on lines +112 to +114
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${id.lexeme}" not founded.`);
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
Copy link

Choose a reason for hiding this comment

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

Fix grammatical issue in error message.

The error message has a minor grammatical issue. Change "not founded" to "not found".

-      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
+      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not found.`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${id.lexeme}" not founded.`);
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not found.`);

Comment on lines 34 to 42
static reset(includeMap: Record<string, string>, pathOrigin: string, basePathForIncludeKey: string) {
this._definedMacros.clear();
this._expandSegmentsStack.length = 0;
this._expandSegmentsStack.push([]);
this._branchMacros.clear();
this.addPredefinedMacro("GL_ES");
this._includeMap = includeMap;
this._basePathForIncludeKey = basePathForIncludeKey;
this._pathOrigin = pathOrigin;
Copy link

Choose a reason for hiding this comment

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

Replace this with the class name in static context.

Using this in a static context can be confusing. Replace this with the class name PpParser.

-    this._definedMacros.clear();
-    this._expandSegmentsStack.length = 0;
-    this._expandSegmentsStack.push([]);
-    this._branchMacros.clear();
-    this.addPredefinedMacro("GL_ES");
-    this._includeMap = includeMap;
-    this._basePathForIncludeKey = basePathForIncludeKey;
-    this._pathOrigin = pathOrigin;
+    PpParser._definedMacros.clear();
+    PpParser._expandSegmentsStack.length = 0;
+    PpParser._expandSegmentsStack.push([]);
+    PpParser._branchMacros.clear();
+    PpParser.addPredefinedMacro("GL_ES");
+    PpParser._includeMap = includeMap;
+    PpParser._basePathForIncludeKey = basePathForIncludeKey;
+    PpParser._pathOrigin = pathOrigin;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static reset(includeMap: Record<string, string>, pathOrigin: string, basePathForIncludeKey: string) {
this._definedMacros.clear();
this._expandSegmentsStack.length = 0;
this._expandSegmentsStack.push([]);
this._branchMacros.clear();
this.addPredefinedMacro("GL_ES");
this._includeMap = includeMap;
this._basePathForIncludeKey = basePathForIncludeKey;
this._pathOrigin = pathOrigin;
static reset(includeMap: Record<string, string>, pathOrigin: string, basePathForIncludeKey: string) {
PpParser._definedMacros.clear();
PpParser._expandSegmentsStack.length = 0;
PpParser._expandSegmentsStack.push([]);
PpParser._branchMacros.clear();
PpParser.addPredefinedMacro("GL_ES");
PpParser._includeMap = includeMap;
PpParser._basePathForIncludeKey = basePathForIncludeKey;
PpParser._pathOrigin = pathOrigin;
Tools
Biome

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 42-42: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

[]
[],
"shaders://root/",
new URL(pass.name, "shaders://root/").href
Copy link
Member

Choose a reason for hiding this comment

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

Why use path name?

const compiledPass = shaderLab._parseShaderPass(
pass.contents,
pass.vertexEntry,
pass.fragmentEntry,
[],
ShaderPlatformTarget.GLES300,
[]
[],
"shaders://root/",
Copy link
Member

Choose a reason for hiding this comment

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

Why not defeine a static

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f6fed8b and 519ab40.

Files selected for processing (6)
  • packages/core/src/shader/ShaderPass.ts (7 hunks)
  • packages/design/src/shader-lab/IShaderLab.ts (1 hunks)
  • packages/shader-lab/src/ShaderLab.ts (3 hunks)
  • packages/shader-lab/src/preprocessor/PpParser.ts (3 hunks)
  • packages/shader-lab/src/preprocessor/Preprocessor.ts (1 hunks)
  • tests/src/shader-lab/ShaderValidate.ts (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/core/src/shader/ShaderPass.ts
  • packages/design/src/shader-lab/IShaderLab.ts
  • packages/shader-lab/src/ShaderLab.ts
  • packages/shader-lab/src/preprocessor/Preprocessor.ts
  • tests/src/shader-lab/ShaderValidate.ts
Additional context used
Biome
packages/shader-lab/src/preprocessor/PpParser.ts

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (3)
packages/shader-lab/src/preprocessor/PpParser.ts (3)

13-13: Import addition looks good.

The import statement for ShaderPass is necessary for the new relative path handling logic.


32-32: Static variable addition looks good.

The static variable _basePathForIncludeKey is necessary for handling the base path for relative includes.


100-114: Fix grammatical issue in error message.

The error message has a minor grammatical issue. Change "not founded" to "not found".

-      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
+      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not found.`);

Likely invalid or redundant comment.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 519ab40 and ee6a813.

Files selected for processing (2)
  • packages/core/src/shader/Shader.ts (1 hunks)
  • packages/core/src/shader/ShaderPass.ts (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/shader/Shader.ts
  • packages/core/src/shader/ShaderPass.ts

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ee6a813 and d7e0ac8.

Files selected for processing (1)
  • packages/shader-lab/src/preprocessor/PpParser.ts (3 hunks)
Additional context used
Biome
packages/shader-lab/src/preprocessor/PpParser.ts

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (2)
packages/shader-lab/src/preprocessor/PpParser.ts (2)

13-13: LGTM! Import statement is correct.

The import statement for ShaderPass from "@galacean/engine" aligns with the changes described in the PR summary.


32-32: LGTM! Static variable addition is correct.

The addition of the static variable _basePathForIncludeKey is necessary for supporting relative paths in the #include directive.

Comment on lines +100 to +114
let includedPath: string;
// builtin path
if (id.lexeme[0] !== ".") {
includedPath = id.lexeme;
} else {
// relative path
// @ts-ignore
includedPath = new URL(id.lexeme, this._basePathForIncludeKey).href.substring(ShaderPass._shaderRootPath.length);
}

scanner.scanToChar("\n");
const end = scanner.getShaderPosition();

const chunk = this._includeMap[id.lexeme];
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${id.lexeme}" not founded.`);
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
Copy link

Choose a reason for hiding this comment

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

Fix grammatical issue in error message.

The error message has a minor grammatical issue. Change "not founded" to "not found".

-      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
+      ParserUtils.throw(id.location, `Shader slice "${includedPath}" not found.`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let includedPath: string;
// builtin path
if (id.lexeme[0] !== ".") {
includedPath = id.lexeme;
} else {
// relative path
// @ts-ignore
includedPath = new URL(id.lexeme, this._basePathForIncludeKey).href.substring(ShaderPass._shaderRootPath.length);
}
scanner.scanToChar("\n");
const end = scanner.getShaderPosition();
const chunk = this._includeMap[id.lexeme];
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${id.lexeme}" not founded.`);
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not founded.`);
let includedPath: string;
// builtin path
if (id.lexeme[0] !== ".") {
includedPath = id.lexeme;
} else {
// relative path
// @ts-ignore
includedPath = new URL(id.lexeme, this._basePathForIncludeKey).href.substring(ShaderPass._shaderRootPath.length);
}
scanner.scanToChar("\n");
const end = scanner.getShaderPosition();
const chunk = this._includeMap[includedPath];
if (!chunk) {
ParserUtils.throw(id.location, `Shader slice "${includedPath}" not found.`);

Comment on lines +34 to +41
static reset(includeMap: Record<string, string>, basePathForIncludeKey: string) {
this._definedMacros.clear();
this._expandSegmentsStack.length = 0;
this._expandSegmentsStack.push([]);
this._branchMacros.clear();
this.addPredefinedMacro("GL_ES");
this._includeMap = includeMap;
this._basePathForIncludeKey = basePathForIncludeKey;
Copy link

Choose a reason for hiding this comment

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

Fix the use of this in a static context.

Using this in a static context can be confusing. Replace this with the class name PpParser.

-    this._definedMacros.clear();
-    this._expandSegmentsStack.length = 0;
-    this._expandSegmentsStack.push([]);
-    this._branchMacros.clear();
-    this.addPredefinedMacro("GL_ES");
-    this._includeMap = includeMap;
-    this._basePathForIncludeKey = basePathForIncludeKey;
+    PpParser._definedMacros.clear();
+    PpParser._expandSegmentsStack.length = 0;
+    PpParser._expandSegmentsStack.push([]);
+    PpParser._branchMacros.clear();
+    PpParser.addPredefinedMacro("GL_ES");
+    PpParser._includeMap = includeMap;
+    PpParser._basePathForIncludeKey = basePathForIncludeKey;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static reset(includeMap: Record<string, string>, basePathForIncludeKey: string) {
this._definedMacros.clear();
this._expandSegmentsStack.length = 0;
this._expandSegmentsStack.push([]);
this._branchMacros.clear();
this.addPredefinedMacro("GL_ES");
this._includeMap = includeMap;
this._basePathForIncludeKey = basePathForIncludeKey;
static reset(includeMap: Record<string, string>, basePathForIncludeKey: string) {
PpParser._definedMacros.clear();
PpParser._expandSegmentsStack.length = 0;
PpParser._expandSegmentsStack.push([]);
PpParser._branchMacros.clear();
PpParser.addPredefinedMacro("GL_ES");
PpParser._includeMap = includeMap;
PpParser._basePathForIncludeKey = basePathForIncludeKey;
Tools
Biome

[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 36-36: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 37-37: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 38-38: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 39-39: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 40-40: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 41-41: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

@GuoLei1990 GuoLei1990 merged commit cb9ea62 into galacean:dev/1.3 Jul 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority High priority issue shader Shader related functions
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants
0