@@ -162,7 +162,7 @@ enum BuiltIn {
162162 ViewIndex ,
163163 BaseInstance ,
164164 BaseVertex ,
165- ClipDistances ,
165+ ClipDistances { array_size : u32 } ,
166166 CullDistance ,
167167 InstanceIndex ,
168168 PointSize ,
@@ -216,7 +216,7 @@ impl BuiltIn {
216216 Self :: ViewIndex => naga:: BuiltIn :: ViewIndex ,
217217 Self :: BaseInstance => naga:: BuiltIn :: BaseInstance ,
218218 Self :: BaseVertex => naga:: BuiltIn :: BaseVertex ,
219- Self :: ClipDistances => naga:: BuiltIn :: ClipDistances ,
219+ Self :: ClipDistances { .. } => naga:: BuiltIn :: ClipDistances ,
220220 Self :: CullDistance => naga:: BuiltIn :: CullDistance ,
221221 Self :: InstanceIndex => naga:: BuiltIn :: InstanceIndex ,
222222 Self :: PointSize => naga:: BuiltIn :: PointSize ,
@@ -1078,6 +1078,33 @@ impl Interface {
10781078 }
10791079 return ;
10801080 }
1081+ naga:: TypeInner :: Array { base, size, stride }
1082+ if matches ! (
1083+ binding,
1084+ Some ( naga:: Binding :: BuiltIn ( naga:: BuiltIn :: ClipDistances ) ) ,
1085+ ) =>
1086+ {
1087+ // NOTE: We should already have validated these in `naga`.
1088+ debug_assert_eq ! (
1089+ & arena[ base] . inner,
1090+ & naga:: TypeInner :: Scalar ( naga:: Scalar :: F32 )
1091+ ) ;
1092+ debug_assert_eq ! ( stride, 4 ) ;
1093+
1094+ let naga:: ArraySize :: Constant ( array_size) = size else {
1095+ // NOTE: Based on the
1096+ // [spec](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types):
1097+ //
1098+ // > The only valid use of a fixed-size array with an element count that is an
1099+ // > override-expression that is not a const-expression is as a memory view in
1100+ // > the workgroup address space.
1101+ unreachable ! ( "non-constant array size for `clip_distances`" )
1102+ } ;
1103+ let array_size = array_size. get ( ) ;
1104+
1105+ list. push ( Varying :: BuiltIn ( BuiltIn :: ClipDistances { array_size } ) ) ;
1106+ return ;
1107+ }
10811108 ref other => {
10821109 //Note: technically this should be at least `log::error`, but
10831110 // the reality is - every shader coming from `glslc` outputs an array
@@ -1110,7 +1137,7 @@ impl Interface {
11101137 naga:: BuiltIn :: ViewIndex => BuiltIn :: ViewIndex ,
11111138 naga:: BuiltIn :: BaseInstance => BuiltIn :: BaseInstance ,
11121139 naga:: BuiltIn :: BaseVertex => BuiltIn :: BaseVertex ,
1113- naga:: BuiltIn :: ClipDistances => BuiltIn :: ClipDistances ,
1140+ naga:: BuiltIn :: ClipDistances => unreachable ! ( ) ,
11141141 naga:: BuiltIn :: CullDistance => BuiltIn :: CullDistance ,
11151142 naga:: BuiltIn :: InstanceIndex => BuiltIn :: InstanceIndex ,
11161143 naga:: BuiltIn :: PointSize => BuiltIn :: PointSize ,
@@ -1598,7 +1625,21 @@ impl Interface {
15981625 None
15991626 } ;
16001627
1601- let deductions = point_list_deduction. into_iter ( ) ;
1628+ let clip_distance_deductions = entry_point. outputs . iter ( ) . filter_map ( |output| {
1629+ if let & Varying :: BuiltIn ( BuiltIn :: ClipDistances { array_size } ) = output {
1630+ Some ( MaxVertexShaderOutputDeduction :: ClipDistances { array_size } )
1631+ } else {
1632+ None
1633+ }
1634+ } ) ;
1635+ debug_assert ! (
1636+ clip_distance_deductions. clone( ) . count( ) <= 1 ,
1637+ "multiple `clip_distances` outputs found"
1638+ ) ;
1639+
1640+ let deductions = point_list_deduction
1641+ . into_iter ( )
1642+ . chain ( clip_distance_deductions) ;
16021643
16031644 for deduction in deductions. clone ( ) {
16041645 // NOTE: Deductions, in the current version of the spec. we implement, do not
0 commit comments