@@ -119,15 +119,31 @@ pub enum Version {
119
119
/// `core` GLSL.
120
120
Desktop ( u16 ) ,
121
121
/// `es` GLSL.
122
- Embedded ( u16 ) ,
122
+ Embedded { version : u16 , is_webgl : bool } ,
123
123
}
124
124
125
125
impl Version {
126
+ /// Create a new gles version
127
+ pub const fn new_gles ( version : u16 ) -> Self {
128
+ Self :: Embedded {
129
+ version,
130
+ is_webgl : false ,
131
+ }
132
+ }
133
+
126
134
/// Returns true if self is `Version::Embedded` (i.e. is a es version)
127
135
const fn is_es ( & self ) -> bool {
128
136
match * self {
129
137
Version :: Desktop ( _) => false ,
130
- Version :: Embedded ( _) => true ,
138
+ Version :: Embedded { .. } => true ,
139
+ }
140
+ }
141
+
142
+ /// Returns true if targetting WebGL
143
+ const fn is_webgl ( & self ) -> bool {
144
+ match * self {
145
+ Version :: Desktop ( _) => false ,
146
+ Version :: Embedded { is_webgl, .. } => is_webgl,
131
147
}
132
148
}
133
149
@@ -140,7 +156,7 @@ impl Version {
140
156
fn is_supported ( & self ) -> bool {
141
157
match * self {
142
158
Version :: Desktop ( v) => SUPPORTED_CORE_VERSIONS . contains ( & v) ,
143
- Version :: Embedded ( v ) => SUPPORTED_ES_VERSIONS . contains ( & v) ,
159
+ Version :: Embedded { version : v , .. } => SUPPORTED_ES_VERSIONS . contains ( & v) ,
144
160
}
145
161
}
146
162
@@ -151,27 +167,29 @@ impl Version {
151
167
/// Note: `location=` for vertex inputs and fragment outputs is supported
152
168
/// unconditionally for GLES 300.
153
169
fn supports_explicit_locations ( & self ) -> bool {
154
- * self >= Version :: Embedded ( 310 ) || * self >= Version :: Desktop ( 410 )
170
+ * self >= Version :: Desktop ( 410 ) || * self >= Version :: new_gles ( 310 )
155
171
}
156
172
157
173
fn supports_early_depth_test ( & self ) -> bool {
158
- * self >= Version :: Desktop ( 130 ) || * self >= Version :: Embedded ( 310 )
174
+ * self >= Version :: Desktop ( 130 ) || * self >= Version :: new_gles ( 310 )
159
175
}
160
176
161
177
fn supports_std430_layout ( & self ) -> bool {
162
- * self >= Version :: Desktop ( 430 ) || * self >= Version :: Embedded ( 310 )
178
+ * self >= Version :: Desktop ( 430 ) || * self >= Version :: new_gles ( 310 )
163
179
}
164
180
165
181
fn supports_fma_function ( & self ) -> bool {
166
- * self >= Version :: Desktop ( 400 ) || * self >= Version :: Embedded ( 310 )
182
+ * self >= Version :: Desktop ( 400 ) || * self >= Version :: new_gles ( 310 )
167
183
}
168
184
}
169
185
170
186
impl PartialOrd for Version {
171
187
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
172
188
match ( * self , * other) {
173
189
( Version :: Desktop ( x) , Version :: Desktop ( y) ) => Some ( x. cmp ( & y) ) ,
174
- ( Version :: Embedded ( x) , Version :: Embedded ( y) ) => Some ( x. cmp ( & y) ) ,
190
+ ( Version :: Embedded { version : x, .. } , Version :: Embedded { version : y, .. } ) => {
191
+ Some ( x. cmp ( & y) )
192
+ }
175
193
_ => None ,
176
194
}
177
195
}
@@ -181,7 +199,7 @@ impl fmt::Display for Version {
181
199
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
182
200
match * self {
183
201
Version :: Desktop ( v) => write ! ( f, "{} core" , v) ,
184
- Version :: Embedded ( v ) => write ! ( f, "{} es" , v) ,
202
+ Version :: Embedded { version : v , .. } => write ! ( f, "{} es" , v) ,
185
203
}
186
204
}
187
205
}
@@ -215,7 +233,7 @@ pub struct Options {
215
233
impl Default for Options {
216
234
fn default ( ) -> Self {
217
235
Options {
218
- version : Version :: Embedded ( 310 ) ,
236
+ version : Version :: new_gles ( 310 ) ,
219
237
writer_flags : WriterFlags :: ADJUST_COORDINATE_SPACE ,
220
238
binding_map : BindingMap :: default ( ) ,
221
239
}
@@ -233,6 +251,8 @@ pub struct PipelineOptions {
233
251
///
234
252
/// If no entry point that matches is found while creating a [`Writer`], a error will be thrown.
235
253
pub entry_point : String ,
254
+ /// How many views to render to, if doing multiview rendering.
255
+ pub multiview : Option < std:: num:: NonZeroU32 > ,
236
256
}
237
257
238
258
/// Reflection info for texture mappings and uniforms.
@@ -285,6 +305,7 @@ struct VaryingName<'a> {
285
305
binding : & ' a crate :: Binding ,
286
306
stage : ShaderStage ,
287
307
output : bool ,
308
+ targetting_webgl : bool ,
288
309
}
289
310
impl fmt:: Display for VaryingName < ' _ > {
290
311
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -302,7 +323,11 @@ impl fmt::Display for VaryingName<'_> {
302
323
write ! ( f, "_{}_location{}" , prefix, location, )
303
324
}
304
325
crate :: Binding :: BuiltIn ( built_in) => {
305
- write ! ( f, "{}" , glsl_built_in( built_in, self . output) )
326
+ write ! (
327
+ f,
328
+ "{}" ,
329
+ glsl_built_in( built_in, self . output, self . targetting_webgl)
330
+ )
306
331
}
307
332
}
308
333
}
@@ -400,6 +425,8 @@ pub struct Writer<'a, W> {
400
425
named_expressions : crate :: NamedExpressions ,
401
426
/// Set of expressions that need to be baked to avoid unnecessary repetition in output
402
427
need_bake_expressions : back:: NeedBakeExpressions ,
428
+ /// How many views to render to, if doing multiview rendering.
429
+ multiview : Option < std:: num:: NonZeroU32 > ,
403
430
}
404
431
405
432
impl < ' a , W : Write > Writer < ' a , W > {
@@ -451,7 +478,7 @@ impl<'a, W: Write> Writer<'a, W> {
451
478
reflection_names_globals : crate :: FastHashMap :: default ( ) ,
452
479
entry_point : & module. entry_points [ ep_idx] ,
453
480
entry_point_idx : ep_idx as u16 ,
454
-
481
+ multiview : pipeline_options . multiview ,
455
482
block_id : IdGenerator :: default ( ) ,
456
483
named_expressions : Default :: default ( ) ,
457
484
need_bake_expressions : Default :: default ( ) ,
@@ -540,6 +567,13 @@ impl<'a, W: Write> Writer<'a, W> {
540
567
}
541
568
}
542
569
570
+ if self . entry_point . stage == ShaderStage :: Vertex && self . options . version . is_webgl ( ) {
571
+ if let Some ( multiview) = self . multiview . as_ref ( ) {
572
+ writeln ! ( self . out, "layout(num_views = {}) in;" , multiview) ?;
573
+ writeln ! ( self . out) ?;
574
+ }
575
+ }
576
+
543
577
let ep_info = self . info . get_entry_point ( self . entry_point_idx as usize ) ;
544
578
545
579
// Write struct types.
@@ -1180,7 +1214,11 @@ impl<'a, W: Write> Writer<'a, W> {
1180
1214
} => ( location, interpolation, sampling) ,
1181
1215
crate :: Binding :: BuiltIn ( built_in) => {
1182
1216
if let crate :: BuiltIn :: Position { invariant : true } = built_in {
1183
- writeln ! ( self . out, "invariant {};" , glsl_built_in( built_in, output) ) ?;
1217
+ writeln ! (
1218
+ self . out,
1219
+ "invariant {};" ,
1220
+ glsl_built_in( built_in, output, self . options. version. is_webgl( ) )
1221
+ ) ?;
1184
1222
}
1185
1223
return Ok ( ( ) ) ;
1186
1224
}
@@ -1238,6 +1276,7 @@ impl<'a, W: Write> Writer<'a, W> {
1238
1276
} ,
1239
1277
stage : self . entry_point . stage ,
1240
1278
output,
1279
+ targetting_webgl : self . options . version . is_webgl ( ) ,
1241
1280
} ;
1242
1281
writeln ! ( self . out, " {};" , vname) ?;
1243
1282
@@ -1378,6 +1417,7 @@ impl<'a, W: Write> Writer<'a, W> {
1378
1417
binding : member. binding . as_ref ( ) . unwrap ( ) ,
1379
1418
stage,
1380
1419
output : false ,
1420
+ targetting_webgl : self . options . version . is_webgl ( ) ,
1381
1421
} ;
1382
1422
if index != 0 {
1383
1423
write ! ( self . out, ", " ) ?;
@@ -1391,6 +1431,7 @@ impl<'a, W: Write> Writer<'a, W> {
1391
1431
binding : arg. binding . as_ref ( ) . unwrap ( ) ,
1392
1432
stage,
1393
1433
output : false ,
1434
+ targetting_webgl : self . options . version . is_webgl ( ) ,
1394
1435
} ;
1395
1436
writeln ! ( self . out, "{};" , varying_name) ?;
1396
1437
}
@@ -1897,6 +1938,7 @@ impl<'a, W: Write> Writer<'a, W> {
1897
1938
binding : member. binding . as_ref ( ) . unwrap ( ) ,
1898
1939
stage : ep. stage ,
1899
1940
output : true ,
1941
+ targetting_webgl : self . options . version . is_webgl ( ) ,
1900
1942
} ;
1901
1943
write ! ( self . out, "{} = " , varying_name) ?;
1902
1944
@@ -1921,6 +1963,7 @@ impl<'a, W: Write> Writer<'a, W> {
1921
1963
binding : result. binding . as_ref ( ) . unwrap ( ) ,
1922
1964
stage : ep. stage ,
1923
1965
output : true ,
1966
+ targetting_webgl : self . options . version . is_webgl ( ) ,
1924
1967
} ;
1925
1968
write ! ( self . out, "{} = " , name) ?;
1926
1969
self . write_expr ( value, ctx) ?;
@@ -3629,7 +3672,11 @@ const fn glsl_scalar(
3629
3672
}
3630
3673
3631
3674
/// Helper function that returns the glsl variable name for a builtin
3632
- const fn glsl_built_in ( built_in : crate :: BuiltIn , output : bool ) -> & ' static str {
3675
+ const fn glsl_built_in (
3676
+ built_in : crate :: BuiltIn ,
3677
+ output : bool ,
3678
+ targetting_webgl : bool ,
3679
+ ) -> & ' static str {
3633
3680
use crate :: BuiltIn as Bi ;
3634
3681
3635
3682
match built_in {
@@ -3640,6 +3687,7 @@ const fn glsl_built_in(built_in: crate::BuiltIn, output: bool) -> &'static str {
3640
3687
"gl_FragCoord"
3641
3688
}
3642
3689
}
3690
+ Bi :: ViewIndex if targetting_webgl => "int(gl_ViewID_OVR)" ,
3643
3691
Bi :: ViewIndex => "gl_ViewIndex" ,
3644
3692
// vertex
3645
3693
Bi :: BaseInstance => "uint(gl_BaseInstance)" ,
0 commit comments