@@ -20,8 +20,8 @@ public class Parameter
2020 public class ShaderPiece
2121 {
2222 public string content ;
23- public List < string > inputs = new ( ) ;
24- public List < string > outputs = new ( ) ;
23+ public List < string > inputs = [ ] ;
24+ public List < string > outputs = [ ] ;
2525 }
2626
2727 private static Regex typeRegex = TypeRegex ( ) ;
@@ -34,10 +34,14 @@ public class ShaderPiece
3434 private static Regex outputRegex = OutputRegex ( ) ;
3535 private static Regex blendRegex = BlendRegex ( ) ;
3636 private static Regex variantsRegex = VariantsRegex ( ) ;
37+ private static Regex bufferRegex = BufferRegex ( ) ;
3738
3839 [ GeneratedRegex ( "(varying|uniform) (\\ w+) (\\ w+)(([ ]*)\\ :([ ]*)(\\ w+))?(([ ]*)\\ =([ ]*)(.*))?" ) ]
3940 private static partial Regex ParameterRegex ( ) ;
4041
42+ [ GeneratedRegex ( "(ROBuffer|RWBuffer|WOBuffer)\\ <(\\ w+)\\ >([ ]*)(\\ w+)([ ]*)\\ :([ ]*)([0-9]+)" ) ]
43+ private static partial Regex BufferRegex ( ) ;
44+
4145 [ GeneratedRegex ( "Begin Vertex((.|\\ n)*)End Vertex" ) ]
4246 private static partial Regex VertexRegex ( ) ;
4347
@@ -84,28 +88,36 @@ public static bool Parse(string source, out ShaderType type, out (BlendMode, Ble
8488 return false ;
8589 }
8690
87- var variantsMatch = variantsRegex . Match ( source ) ;
88-
89- if ( variantsMatch != null && variantsMatch . Length > 0 )
90- {
91- variants = variantsMatch . Groups [ 1 ] . Value . Split ( "," ) . Select ( x => x . Trim ( ) ) . ToList ( ) ;
92- }
93- else
91+ if ( type == ShaderType . VertexFragment )
9492 {
95- variants = [ ] ;
96- }
93+ var variantsMatch = variantsRegex . Match ( source ) ;
9794
98- var blendMatch = blendRegex . Match ( source ) ;
95+ if ( variantsMatch != null && variantsMatch . Length > 0 )
96+ {
97+ variants = variantsMatch . Groups [ 1 ] . Value . Split ( "," ) . Select ( x => x . Trim ( ) ) . ToList ( ) ;
98+ }
99+ else
100+ {
101+ variants = [ ] ;
102+ }
99103
100- if ( blendMatch == null ||
101- Enum . TryParse < BlendMode > ( blendMatch . Groups [ 1 ] . Value , true , out var from ) == false ||
102- Enum . TryParse < BlendMode > ( blendMatch . Groups [ 2 ] . Value , true , out var to ) == false )
103- {
104- blendMode = default ;
104+ var blendMatch = blendRegex . Match ( source ) ;
105+
106+ if ( blendMatch == null ||
107+ Enum . TryParse < BlendMode > ( blendMatch . Groups [ 1 ] . Value , true , out var from ) == false ||
108+ Enum . TryParse < BlendMode > ( blendMatch . Groups [ 2 ] . Value , true , out var to ) == false )
109+ {
110+ blendMode = default ;
111+ }
112+ else
113+ {
114+ blendMode = ( from , to ) ;
115+ }
105116 }
106117 else
107118 {
108- blendMode = ( from , to ) ;
119+ variants = [ ] ;
120+ blendMode = default ;
109121 }
110122
111123 var parametersMatch = parametersRegex . Match ( source ) ;
@@ -115,6 +127,7 @@ public static bool Parse(string source, out ShaderType type, out (BlendMode, Ble
115127 var content = parametersMatch . Groups [ 1 ] . Value ;
116128
117129 var parameterMatches = parameterRegex . Matches ( content ) ;
130+ var bufferMatches = bufferRegex . Matches ( content ) ;
118131
119132 var parameterList = new List < Parameter > ( ) ;
120133
@@ -142,6 +155,32 @@ public static bool Parse(string source, out ShaderType type, out (BlendMode, Ble
142155 parameterList . Add ( parameter ) ;
143156 }
144157
158+ foreach ( Match match in bufferMatches )
159+ {
160+ if ( int . TryParse ( match . Groups [ 7 ] . Value . Trim ( ) , out var bufferIndex ) == false )
161+ {
162+ type = default ;
163+ parameters = default ;
164+ variants = [ ] ;
165+ vertex = default ;
166+ fragment = default ;
167+ compute = default ;
168+ blendMode = default ;
169+
170+ return false ;
171+ }
172+
173+ var parameter = new Parameter
174+ {
175+ type = match . Groups [ 1 ] . Value . Trim ( ) ,
176+ dataType = match . Groups [ 2 ] . Value . Trim ( ) ,
177+ name = match . Groups [ 4 ] . Value . Trim ( ) ,
178+ initializer = bufferIndex . ToString ( ) ,
179+ } ;
180+
181+ parameterList . Add ( parameter ) ;
182+ }
183+
145184 parameters = parameterList . ToArray ( ) ;
146185 }
147186 else
@@ -195,9 +234,20 @@ void HandleContent(Regex regex, out ShaderPiece piece)
195234 }
196235 }
197236
198- HandleContent ( vertexRegex , out vertex ) ;
199- HandleContent ( fragmentRegex , out fragment ) ;
200- HandleContent ( computeRegex , out compute ) ;
237+ if ( type == ShaderType . VertexFragment )
238+ {
239+ HandleContent ( vertexRegex , out vertex ) ;
240+ HandleContent ( fragmentRegex , out fragment ) ;
241+
242+ compute = default ;
243+ }
244+ else
245+ {
246+ HandleContent ( computeRegex , out compute ) ;
247+
248+ vertex = default ;
249+ fragment = default ;
250+ }
201251
202252 return true ;
203253 }
0 commit comments