Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
Fix: fix conflicts
  • Loading branch information
cptbtptpbcptdtptp authored Jan 9, 2025
1 parent 5a43240 commit 406b95a
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 86 deletions.
Binary file modified packages/physics-physx/libs/physx.release.wasm
Binary file not shown.
8 changes: 6 additions & 2 deletions packages/shader-lab/src/common/BaseScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type OnToken = (token: BaseToken, scanner: BaseScanner) => void;
* @internal
*/
export default class BaseScanner {
private static _spaceCharsWithBreak = [" ", "\t", "\n"];
private static _spaceCharsWithBreak = [" ", "\t", "\n", "\r"];
private static _spaceChars = [" ", "\t"];
private static _checkIsIn(checked: string, chars: string[]): boolean {
for (let i = 0; i < chars.length; i++) {
Expand Down Expand Up @@ -117,7 +117,11 @@ export default class BaseScanner {
const start = this.getCurPosition();
this.advance(2);
// single line comments
while (this.getCurChar() !== "\n") this._advance();
let curChar = this.getCurChar();
while (curChar !== "\n" && curChar !== "\r" && !this.isEnd()) {
this._advance();
curChar = this.getCurChar();
}
this.skipCommentsAndSpace();
return ShaderLab.createRange(start, this.getCurPosition());
} else if (this.peek(2) === "/*") {
Expand Down
1 change: 1 addition & 0 deletions packages/shader-lab/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export enum ETokenType {
COLON,
/** = */
EQUAL,
/** ; */
SEMICOLON,
/** ! */
BANG,
Expand Down
21 changes: 17 additions & 4 deletions packages/shader-lab/src/lalr/CFG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,34 @@ const productionAndRules: [GrammarSymbol[], TranslationRule | undefined][] = [

...GrammarUtils.createProductionWithOptions(NoneTerminal.global_declaration, [
[NoneTerminal.precision_specifier],
[NoneTerminal.variable_declaration],
[NoneTerminal.variable_declaration_statement],
[NoneTerminal.struct_specifier],
[NoneTerminal.function_definition]
]),

...GrammarUtils.createProductionWithOptions(
NoneTerminal.variable_declaration,
[
[EKeyword.GS_RenderQueueType, ETokenType.ID, ETokenType.SEMICOLON],
[NoneTerminal.fully_specified_type, ETokenType.ID, ETokenType.SEMICOLON],
[NoneTerminal.fully_specified_type, ETokenType.ID, NoneTerminal.array_specifier, ETokenType.SEMICOLON]
[NoneTerminal.fully_specified_type, ETokenType.ID],
[NoneTerminal.fully_specified_type, ETokenType.ID, NoneTerminal.array_specifier]
],
ASTNode.VariableDeclaration.pool
),

...GrammarUtils.createProductionWithOptions(
NoneTerminal.variable_declaration_list,
[
[NoneTerminal.variable_declaration],
[NoneTerminal.variable_declaration_list, ETokenType.COMMA, ETokenType.ID],
[NoneTerminal.variable_declaration_list, ETokenType.COMMA, ETokenType.ID, NoneTerminal.array_specifier]
],
ASTNode.VariableDeclarationList.pool
),

...GrammarUtils.createProductionWithOptions(NoneTerminal.variable_declaration_statement, [
[NoneTerminal.variable_declaration_list, ETokenType.SEMICOLON]
]),

...GrammarUtils.createProductionWithOptions(
NoneTerminal.ext_builtin_type_specifier_nonarray,
[
Expand Down
3 changes: 2 additions & 1 deletion packages/shader-lab/src/lexer/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default class LexerUtils {
static isSpace(charCode: number) {
return (
charCode === 9 || // Tab
charCode === 10 || // Line break
charCode === 10 || // Line break - /n
charCode === 13 || // Carriage return -/r
charCode === 32 // Space
);
}
Expand Down
80 changes: 64 additions & 16 deletions packages/shader-lab/src/parser/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export abstract class TreeNode implements IPoolElement {
return visitor.defaultCodeGen(this.children);
}

/**
* Do semantic analyze right after the ast node is generated.
*/
semanticAnalyze(sa: SematicAnalyzer) {}
}

Expand Down Expand Up @@ -178,21 +181,31 @@ export namespace ASTNode {
}

override semanticAnalyze(sa: SematicAnalyzer): void {
const fullyType = this.children[0] as FullySpecifiedType;
const id = this.children[1] as Token;
this.typeSpecifier = fullyType.typeSpecifier;
const children = this.children;
const childrenLen = children.length;
const fullyType = children[0] as FullySpecifiedType;
const typeSpecifier = fullyType.typeSpecifier;
this.typeSpecifier = typeSpecifier;
this.arraySpecifier = typeSpecifier.arraySpecifier;

const id = children[1] as Token;

let sm: VarSymbol;
if (this.children.length === 2 || this.children.length === 4) {
const symbolType = new SymbolType(fullyType.type, fullyType.typeSpecifier.lexeme);
const initializer = this.children[3] as Initializer;
if (childrenLen === 2 || childrenLen === 4) {
const symbolType = new SymbolType(fullyType.type, typeSpecifier.lexeme, this.arraySpecifier);
const initializer = children[3] as Initializer;

sm = new VarSymbol(id.lexeme, symbolType, false, initializer);
} else {
const arraySpecifier = this.children[2] as ArraySpecifier;
const arraySpecifier = children[2] as ArraySpecifier;
// #if _VERBOSE
if (arraySpecifier && this.arraySpecifier) {
sa.reportError(arraySpecifier.location, "Array of array is not supported.");
}
// #endif
this.arraySpecifier = arraySpecifier;
const symbolType = new SymbolType(fullyType.type, fullyType.typeSpecifier.lexeme, arraySpecifier);
const initializer = this.children[4] as Initializer;
const symbolType = new SymbolType(fullyType.type, typeSpecifier.lexeme, this.arraySpecifier);
const initializer = children[4] as Initializer;

sm = new VarSymbol(id.lexeme, symbolType, false, initializer);
}
Expand Down Expand Up @@ -288,6 +301,9 @@ export namespace ASTNode {
get arraySize(): number {
return (this.children?.[1] as ArraySpecifier)?.size;
}
get arraySpecifier(): ArraySpecifier {
return this.children[1] as ArraySpecifier;
}

get isCustom() {
return typeof this.type === "string";
Expand Down Expand Up @@ -701,9 +717,9 @@ export namespace ASTNode {
}
}
// #if _VERBOSE
const builtinFn = BuiltinFunction.getFn(fnIdent, ...(paramSig ?? []));
const builtinFn = BuiltinFunction.getFn(fnIdent, paramSig);
if (builtinFn) {
this.type = BuiltinFunction.getReturnType(builtinFn.fun, builtinFn.genType);
this.type = builtinFn.realReturnType;
return;
}
// #endif
Expand Down Expand Up @@ -1110,17 +1126,49 @@ export namespace ASTNode {

@ASTNodeDecorator(NoneTerminal.variable_declaration)
export class VariableDeclaration extends TreeNode {
type: FullySpecifiedType;

override semanticAnalyze(sa: SematicAnalyzer): void {
const type = this.children[0] as FullySpecifiedType;
const ident = this.children[1] as Token;
let sm: VarSymbol;
sm = new VarSymbol(ident.lexeme, new SymbolType(type.type, type.typeSpecifier.lexeme), true, this);
const children = this.children;
const type = children[0] as FullySpecifiedType;
const ident = children[1] as Token;
this.type = type;
const sm = new VarSymbol(ident.lexeme, new SymbolType(type.type, type.typeSpecifier.lexeme), true, this);

sa.symbolTableStack.insert(sm);
}

override codeGen(visitor: CodeGenVisitor): string {
return visitor.visitGlobalVariableDeclaration(this);
return visitor.visitGlobalVariableDeclaration(this) + ";";
}
}

@ASTNodeDecorator(NoneTerminal.variable_declaration_list)
export class VariableDeclarationList extends TreeNode {
type: FullySpecifiedType;

override semanticAnalyze(sa: SematicAnalyzer): void {
const { children } = this;
const length = children.length;
const variableDeclaration = children[0] as VariableDeclaration;
const type = variableDeclaration.type;
this.type = type;

if (length === 1) {
return;
}

const ident = children[2] as Token;

const newVariable = VariableDeclaration.pool.get();
if (length === 3) {
// variable_declaration_list ',' id
newVariable.set(ident.location, [type, ident]);
} else {
// variable_declaration_list ',' id array_specifier
newVariable.set(ident.location, [type, ident, children[3] as ArraySpecifier]);
}
newVariable.semanticAnalyze(sa);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/shader-lab/src/parser/GrammarSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export enum NoneTerminal {
// glsl
global_declaration,
variable_declaration,
variable_declaration_list,
variable_declaration_statement,
array_specifier_list,
array_specifier,
ext_builtin_type_specifier_nonarray,
Expand Down
15 changes: 12 additions & 3 deletions packages/shader-lab/src/parser/TargetParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,25 @@ gs_shader_program:

global_declaration:
precision_specifier
| variable_declaration
| variable_declaration_statement
| struct_specifier
| function_definition
;

variable_declaration:
fully_specified_type id ';'
| fully_specified_type id array_specifier ';'
fully_specified_type id
| fully_specified_type id array_specifier
;

variable_declaration_list:
variable_declaration
| variable_declaration_list ',' id
| variable_declaration_list ',' id array_specifier
;

variable_declaration_statement:
variable_declaration_list ';'

variable_identifier:
id
;
Expand Down
61 changes: 35 additions & 26 deletions packages/shader-lab/src/parser/builtin/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ function isGenericType(t: BuiltinType) {
const BuiltinFunctionTable: Map<string, BuiltinFunction[]> = new Map();

export class BuiltinFunction {
private _returnType: BuiltinType;
ident: string;
readonly args: BuiltinType[];
readonly scope: EShaderStage;

private _returnType: BuiltinType;
private _realReturnType: NonGenericGalaceanType;

get realReturnType(): NonGenericGalaceanType {
return this._realReturnType;
}

private constructor(ident: string, returnType: BuiltinType, scope: EShaderStage, ...args: BuiltinType[]) {
this.ident = ident;
this._returnType = returnType;
Expand All @@ -59,33 +65,33 @@ export class BuiltinFunction {
BuiltinFunctionTable.set(ident, list);
}

static getFn(
ident: string,
...args: BuiltinType[]
): { fun: BuiltinFunction; genType: Exclude<GalaceanDataType, string> } | undefined {
static getFn(ident: string, parameterTypes: NonGenericGalaceanType[]): BuiltinFunction | undefined {
const list = BuiltinFunctionTable.get(ident);
let realType = TypeAny;
if (list?.length) {
const fun = list.find((item) => {
if (item.args.length !== args.length) return false;
let genType = 0;
for (let i = 0; i < args.length; i++) {
if (args[i] === TypeAny) continue;
realType = args[i];
if (isGenericType(item.args[i])) {
if (genType === 0) {
genType = args[i];
continue;
} else {
realType = genType;
if (list) {
for (let length = list.length, i = 0; i < length; i++) {
const fn = list[i];
const fnArgs = fn.args;
const argLength = fnArgs.length;
if (argLength !== parameterTypes.length) continue;
// Try to match generic parameter type.
let returnType = TypeAny;
let found = true;
for (let i = 0; i < argLength; i++) {
const curFnArg = fnArgs[i];
if (isGenericType(curFnArg)) {
if (returnType === TypeAny) returnType = parameterTypes[i];
} else {
if (curFnArg !== parameterTypes[i] && parameterTypes[i] !== TypeAny) {
found = false;
break;
}
}
if (args[i] === TypeAny) continue;
if (args[i] !== realType) return false;
}
return true;
});
if (fun) return { fun, genType: realType };
if (found) {
fn._realReturnType = returnType;
return fn;
}
}
}
}
}
Expand Down Expand Up @@ -249,8 +255,8 @@ BuiltinFunction._create("textureSize", EKeyword.IVEC2, EKeyword.SAMPLER_CUBE_SHA
BuiltinFunction._create("textureSize", EKeyword.IVEC3, EGenType.GSampler2DArray, EKeyword.INT);
BuiltinFunction._create("textureSize", EKeyword.IVEC3, EKeyword.SAMPLER2D_ARRAY_SHADOW, EKeyword.INT);

BuiltinFunction._create("texture2D", EKeyword.SAMPLER2D, EKeyword.VEC2);
BuiltinFunction._create("texture2D", EKeyword.SAMPLER2D, EKeyword.VEC2, EKeyword.FLOAT);
BuiltinFunction._create("texture2D", EKeyword.VEC4, EKeyword.SAMPLER2D, EKeyword.VEC2);
BuiltinFunction._create("texture2D", EKeyword.VEC4, EKeyword.SAMPLER2D, EKeyword.VEC2, EKeyword.FLOAT);

BuiltinFunction._create("texture", EGenType.GVec4, EGenType.GSampler2D, EKeyword.VEC2, EKeyword.FLOAT);
BuiltinFunction._create("texture", EGenType.GVec4, EGenType.GSampler2D, EKeyword.VEC2);
Expand Down Expand Up @@ -286,10 +292,13 @@ BuiltinFunction._create("textureLod", EGenType.GVec4, EGenType.GSampler3D, EKeyw
BuiltinFunction._create("textureLod", EGenType.GVec4, EGenType.GSamplerCube, EKeyword.VEC3, EKeyword.FLOAT);
BuiltinFunction._create("textureLod", EKeyword.FLOAT, EKeyword.SAMPLER2D_SHADOW, EKeyword.VEC3, EKeyword.FLOAT);
BuiltinFunction._create("textureLod", EGenType.GVec4, EGenType.GSampler2DArray, EKeyword.VEC3, EKeyword.FLOAT);
BuiltinFunction._create("texture2DLodEXT", EGenType.GVec4, EGenType.GSampler2D, EKeyword.VEC2, EKeyword.FLOAT);
BuiltinFunction._create("texture2DLodEXT", EGenType.GVec4, EGenType.GSampler3D, EKeyword.VEC3, EKeyword.FLOAT);

BuiltinFunction._create("textureCube", EKeyword.SAMPLER_CUBE, EKeyword.VEC3);
BuiltinFunction._create("textureCube", EKeyword.SAMPLER_CUBE, EKeyword.VEC3, EKeyword.FLOAT);
BuiltinFunction._create("textureCubeLod", EKeyword.SAMPLER_CUBE, EKeyword.VEC3, EKeyword.FLOAT);
BuiltinFunction._create("textureCubeLodEXT", EGenType.GVec4, EGenType.GSamplerCube, EKeyword.VEC3, EKeyword.FLOAT);

BuiltinFunction._create(
"textureOffset",
Expand Down
2 changes: 1 addition & 1 deletion packages/shader-lab/src/preprocessor/PpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export class PpParser {
return !!this._definedMacros.get(macro.lexeme);
} else {
const macro = this._definedMacros.get(id.lexeme);
if (!macro) {
if (!macro || !macro.body) {
return false;
}
if (macro.isFunction) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/component/advanced/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Button extends UIInteractive {
}

override onPointerClick(event: PointerEventData): void {
if (!this.globalInteractive) return;
if (!this._getGlobalInteractive()) return;
const listeners = this._listeners.getLoopArray();
for (let i = 0, n = listeners.length; i < n; i++) {
const listener = listeners[i];
Expand Down
Loading

0 comments on commit 406b95a

Please sign in to comment.