Skip to content

Commit

Permalink
Add parsing support for PackageRequirements ShaderLab command.
Browse files Browse the repository at this point in the history
  • Loading branch information
mirasrael committed Jun 7, 2023
1 parent 48f13c7 commit 88c5632
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class ParserMessages
public const string IDS_SHADER_BLOCK = "shader block";
public const string IDS_SHADER_LAB_IDENTIFIER = "identifier";
public const string IDS_SIMPLE_PROPERTY_TYPE = "property type";
public const string IDS_STATE_COMMAND_OR_PACKAGE_REQUIREMENTS = "state command or package requirements";
public const string IDS_STATE_COMMAND = "state command";
public const string IDS_STENCIL_CONTENTS = "Stencil command";
public const string IDS_STENCIL_OPERATION = "stencil operation";
Expand All @@ -55,7 +56,7 @@ public static class ParserMessages
public const string IDS_VALUE = "value";
public const string IDS_ZTEST_VALUE = "ZTest value";
public const string IDS_FALLBACK_VALUE = "Fallback value";
public const string IDS_SHADER_LAB_COMMAND = "ShaderLab command";
public const string IDS_SHADER_LAB_COMMAND = "ShaderLab command";

public static string GetString(string id) => id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ PP_DIGITS={DECIMAL_DIGIT}(({WHITESPACE})*{DECIMAL_DIGIT})*
<YYINITIAL> "*" { return ShaderLabTokenType.MULTIPLY; }
<YYINITIAL> "{" { return ShaderLabTokenType.LBRACE; }
<YYINITIAL> "}" { return ShaderLabTokenType.RBRACE; }
<YYINITIAL> ":" { return ShaderLabTokenType.COLON; }

<YYINITIAL> "(" { return ShaderLabTokenType.LPAREN; }
<YYINITIAL,BRACKETS,PARENS> ")" { return ShaderLabTokenType.RPAREN; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ options {
| FALLBACK_KEYWORD
| CUSTOM_EDITOR_KEYWORD
| DEPENDENCY_KEYWORD
| PACKAGE_REQUIREMENTS_KEYWORD

| COLOR_KEYWORD
| FLOAT_KEYWORD
Expand Down Expand Up @@ -472,6 +473,7 @@ options {
| FALLBACK_KEYWORD
| CUSTOM_EDITOR_KEYWORD
| DEPENDENCY_KEYWORD
| PACKAGE_REQUIREMENTS_KEYWORD

| COLOR_KEYWORD
| FLOAT_KEYWORD
Expand Down Expand Up @@ -680,6 +682,7 @@ options {
| FALLBACK_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>
| CUSTOM_EDITOR_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>
| DEPENDENCY_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>
| PACKAGE_REQUIREMENTS_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>

| COLOR_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>
| FLOAT_KEYWORD<SHADER_LAB_IDENTIFIER, IdentifierToken>
Expand Down Expand Up @@ -1089,6 +1092,7 @@ interface blockCommand
| bindChannelsCommand
| grabPassDef
| texturePassDef
| packageRequirementsCommand
;

interface blockValue
Expand All @@ -1106,6 +1110,7 @@ interface blockValue
| bindChannelsValue
| grabPassValue
| texturePassValue
| packageRequirementsValue
;


Expand Down Expand Up @@ -1482,7 +1487,13 @@ subShaderValue
private errorhandling subShaderValueBody
options { preCheckExpected; }
:
pass<PASS, Passes>*
packageRequirementsForSubShaderValueBody?
pass<PASS, Passes>*
;

private errorhandling packageRequirementsForSubShaderValueBody
:
packageRequirementsCommand
;

pass
Expand All @@ -1506,8 +1517,6 @@ interface stateCommand
| legacyRenderStateCommand
;



// **************************************************************************
//
// Tags
Expand Down Expand Up @@ -2678,10 +2687,16 @@ texturePassValue
private errorhandling texturePassContents
options { preCheckExpected; }
:
packageRequirementsForTexturePassContents?
stateCommandForTexturePass*
setTextureCommand<SET_TEXTURE_COMMAND, SetTextureCommands>*
;

private errorhandling packageRequirementsForTexturePassContents
:
packageRequirementsCommand
;

private errorhandling stateCommandForTexturePass
:
stateCommand<STATE_COMMAND, StateCommands>
Expand Down Expand Up @@ -2758,3 +2773,35 @@ dependencyValue
EQUALS<EQUALS, Equals>
STRING_LITERAL<SHADER_LAB_NAME, Name>
;

// **************************************************************************
//
// PackageRequirements
//
// **************************************************************************
// https://docs.unity3d.com/2021.2/Documentation/Manual/SL-PackageRequirements.html
packageRequirementsCommand
options { stubBase="ShaderLabBlockCommandBase"; }
:
PACKAGE_REQUIREMENTS_KEYWORD<SHADER_LAB_KEYWORD, CommandKeyword>
packageRequirementsValue<SHADER_LAB_VALUE, Value>
;

packageRequirementsValue
:
LBRACE<LBRACE, LBrace>
packageRequirementsValueBody
RBRACE<RBRACE, RBrace>
;

private errorhandling packageRequirementsValueBody
options { preCheckExpected; }
:
packageRequirementEntry<PACKAGE_REQUIREMENT_ENTRY, Entries>*
;

errorhandling packageRequirementEntry
:
STRING_LITERAL<PACKAGE_NAME, PackageName>
(COLON STRING_LITERAL<VERSION_SPEC, PackageVersionSpec>)?
;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static ShaderLabTokenType()
FALLBACK_KEYWORD,
CUSTOM_EDITOR_KEYWORD,
DEPENDENCY_KEYWORD,
PACKAGE_REQUIREMENTS_KEYWORD,

COLOR_KEYWORD,
FLOAT_KEYWORD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Token name="RBRACK" representation="]" />
<Token name="LBRACE" representation="{" />
<Token name="RBRACE" representation="}" />
<Token name="COLON" representation=":" />
<Token name="COMMA" representation="," />
<Token name="DOT" representation="." />
<Token name="EQUALS" representation="=" />
Expand Down Expand Up @@ -103,6 +104,7 @@
<Command name="PASS_KEYWORD" representation="Pass" />
<Command name="USEPASS_KEYWORD" representation="UsePass" />
<Command name="GRABPASS_KEYWORD" representation="GrabPass" />
<Command name="PACKAGE_REQUIREMENTS_KEYWORD" representation="PackageRequirements" />
</SubShaderCommands>

<RenderStateCommands NodeType="CommandKeywordTokenNodeType">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 25 ITEMS #
# 26 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -17,6 +17,7 @@ Lighting
Material
Name
Offset
PackageRequirements
Pass
SeparateSpecular
Stencil
Expand All @@ -26,7 +27,7 @@ ZClip
ZTest
ZWrite
# AUTOMATIC #
# 25 ITEMS #
# 26 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -45,6 +46,7 @@ Lighting
Material
Name
Offset
PackageRequirements
Pass
SeparateSpecular
Stencil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 25 ITEMS #
# 26 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -17,6 +17,7 @@ Lighting
Material
Name
Offset
PackageRequirements
Pass
SeparateSpecular
Stencil
Expand All @@ -26,7 +27,7 @@ ZClip
ZTest
ZWrite
# AUTOMATIC #
# 25 ITEMS #
# 26 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -45,6 +46,7 @@ Lighting
Material
Name
Offset
PackageRequirements
Pass
SeparateSpecular
Stencil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 23 ITEMS #
# 24 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -16,6 +16,7 @@ Lighting
Material
Name
Offset
PackageRequirements
SeparateSpecular
SetTexture
Stencil
Expand All @@ -24,7 +25,7 @@ ZClip
ZTest
ZWrite
# AUTOMATIC #
# 23 ITEMS #
# 24 ITEMS #

+ AlphaTest
AlphaToMask
Expand All @@ -42,6 +43,7 @@ Lighting
Material
Name
Offset
PackageRequirements
SeparateSpecular
SetTexture
Stencil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{caret}Shader "Examples/ExampleShader"
{
SubShader
{
PackageRequirements
{
"com.my.package": "2.2"
"com.package.without.version"
}
Pass
{
PackageRequirements
{
"com.unity.render-pipelines.universal": "[10.2.1,11.0]"
"com.unity.textmeshpro": "3.2"
}
}
Pass
{
PackageRequirements
{
"com.unity.render-pipelines.high-definition": "[8.0,8.5]"
}
}
}
}
Loading

0 comments on commit 88c5632

Please sign in to comment.