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

ShaderLab should expose an extra api for syntax error detection #2405

Open
Sway007 opened this issue Oct 25, 2024 · 0 comments
Open

ShaderLab should expose an extra api for syntax error detection #2405

Sway007 opened this issue Oct 25, 2024 · 0 comments
Assignees
Labels
medium priority Medium priority issue Rendering Rendering related functions shader Shader related functions

Comments

@Sway007
Copy link
Member

Sway007 commented Oct 25, 2024

Is your feature request related to a problem? Please describe.

EN

Due to the presence of macros, a single Shader code may contain multiple branches of code. During runtime, the compiler only needs to compile one specific branch of code when all macros are known. However, for syntax error detection tools, it is preferable for the compiler to compile all branches of code and report all detected errors. Currently, the compilation of ShaderLab requires providing all macros related to the code. If one wants to perform syntax checks on all branch codes, it is necessary to explore all combinations of macros, which leads to an exponential explosion problem. Therefore, a separate API needs to be designed specifically for syntax error detection tools, employing a specific compilation algorithm to address the exponential explosion issue.

CN

因为宏的存在,一份Shader代码可能包含多份分支代码,运行时阶段编译器只需要在所有宏都确定的情况下对唯一的一份分支代码进行编译。但对于语法错误检测工具而言,则希望编译器能够对所有分支代码进行编译,并提示所有检测到的错误。当前ShaderLab的编译需要提供代码关联的所有宏,如果想要对所有分支代码都进行语法检查则需要遍历所有宏组合情况,存在指数爆炸问题,需要针对语法错误检测工具单独设计一个API,走特定的编译算法,并解决指数爆炸问题

Describe the solution you'd like

  1. A sperate parse api should be exposed by ShaderLab for VERBOSE package (used by editor and VSCode extension).
  2. In the compilation of VERBOSE version, all branch-macro-statements, like #if, #ifdef, #else, are transpiled into normal if-else branch statements, then the same compilation process are performed by compiler.

There are still several different grammar rule after all macro-branch are transpiled into if-else branch. For instance, use undeclared variable should be allowed under below situation

 ...
 #ifdef XXX_MACRO
 float ior = 1.0;
 #else 
 float ior = 0.0;
 #endif
 float v = ior * factor ...;
 ...

the snippets above will be transpiled into

 if (exist(XXX_MACRO)) {
   float ior = 1.0;
 } else {
   float ior = 0.0;
 }
  float v = ior * factor ...;
@Sway007 Sway007 added Rendering Rendering related functions shader Shader related functions medium priority Medium priority issue labels Oct 25, 2024
@Sway007 Sway007 self-assigned this Oct 25, 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

No branches or pull requests

1 participant