@@ -68,6 +68,146 @@ impl StandardFilterableTriggeringRule {
68
68
}
69
69
}
70
70
71
+ impl crate :: MathFunction {
72
+ pub fn to_wgsl ( self ) -> & ' static str {
73
+ use crate :: MathFunction as Mf ;
74
+
75
+ match self {
76
+ Mf :: Abs => "abs" ,
77
+ Mf :: Min => "min" ,
78
+ Mf :: Max => "max" ,
79
+ Mf :: Clamp => "clamp" ,
80
+ Mf :: Saturate => "saturate" ,
81
+ Mf :: Cos => "cos" ,
82
+ Mf :: Cosh => "cosh" ,
83
+ Mf :: Sin => "sin" ,
84
+ Mf :: Sinh => "sinh" ,
85
+ Mf :: Tan => "tan" ,
86
+ Mf :: Tanh => "tanh" ,
87
+ Mf :: Acos => "acos" ,
88
+ Mf :: Asin => "asin" ,
89
+ Mf :: Atan => "atan" ,
90
+ Mf :: Atan2 => "atan2" ,
91
+ Mf :: Asinh => "asinh" ,
92
+ Mf :: Acosh => "acosh" ,
93
+ Mf :: Atanh => "atanh" ,
94
+ Mf :: Radians => "radians" ,
95
+ Mf :: Degrees => "degrees" ,
96
+ Mf :: Ceil => "ceil" ,
97
+ Mf :: Floor => "floor" ,
98
+ Mf :: Round => "round" ,
99
+ Mf :: Fract => "fract" ,
100
+ Mf :: Trunc => "trunc" ,
101
+ Mf :: Modf => "modf" ,
102
+ Mf :: Frexp => "frexp" ,
103
+ Mf :: Ldexp => "ldexp" ,
104
+ Mf :: Exp => "exp" ,
105
+ Mf :: Exp2 => "exp2" ,
106
+ Mf :: Log => "log" ,
107
+ Mf :: Log2 => "log2" ,
108
+ Mf :: Pow => "pow" ,
109
+ Mf :: Dot => "dot" ,
110
+ Mf :: Cross => "cross" ,
111
+ Mf :: Distance => "distance" ,
112
+ Mf :: Length => "length" ,
113
+ Mf :: Normalize => "normalize" ,
114
+ Mf :: FaceForward => "faceForward" ,
115
+ Mf :: Reflect => "reflect" ,
116
+ Mf :: Refract => "refract" ,
117
+ Mf :: Sign => "sign" ,
118
+ Mf :: Fma => "fma" ,
119
+ Mf :: Mix => "mix" ,
120
+ Mf :: Step => "step" ,
121
+ Mf :: SmoothStep => "smoothstep" ,
122
+ Mf :: Sqrt => "sqrt" ,
123
+ Mf :: InverseSqrt => "inverseSqrt" ,
124
+ Mf :: Transpose => "transpose" ,
125
+ Mf :: Determinant => "determinant" ,
126
+ Mf :: QuantizeToF16 => "quantizeToF16" ,
127
+ Mf :: CountTrailingZeros => "countTrailingZeros" ,
128
+ Mf :: CountLeadingZeros => "countLeadingZeros" ,
129
+ Mf :: CountOneBits => "countOneBits" ,
130
+ Mf :: ReverseBits => "reverseBits" ,
131
+ Mf :: ExtractBits => "extractBits" ,
132
+ Mf :: InsertBits => "insertBits" ,
133
+ Mf :: FirstTrailingBit => "firstTrailingBit" ,
134
+ Mf :: FirstLeadingBit => "firstLeadingBit" ,
135
+ Mf :: Pack4x8snorm => "pack4x8snorm" ,
136
+ Mf :: Pack4x8unorm => "pack4x8unorm" ,
137
+ Mf :: Pack2x16snorm => "pack2x16snorm" ,
138
+ Mf :: Pack2x16unorm => "pack2x16unorm" ,
139
+ Mf :: Pack2x16float => "pack2x16float" ,
140
+ Mf :: Pack4xI8 => "pack4xI8" ,
141
+ Mf :: Pack4xU8 => "pack4xU8" ,
142
+ Mf :: Unpack4x8snorm => "unpack4x8snorm" ,
143
+ Mf :: Unpack4x8unorm => "unpack4x8unorm" ,
144
+ Mf :: Unpack2x16snorm => "unpack2x16snorm" ,
145
+ Mf :: Unpack2x16unorm => "unpack2x16unorm" ,
146
+ Mf :: Unpack2x16float => "unpack2x16float" ,
147
+ Mf :: Unpack4xI8 => "unpack4xI8" ,
148
+ Mf :: Unpack4xU8 => "unpack4xU8" ,
149
+ Mf :: Inverse => "{matrix inverse}" ,
150
+ Mf :: Outer => "{vector outer product}" ,
151
+ }
152
+ }
153
+ }
154
+
155
+ impl crate :: BuiltIn {
156
+ pub fn to_wgsl ( self ) -> & ' static str {
157
+ match self {
158
+ crate :: BuiltIn :: Position { invariant : true } => "@position @invariant" ,
159
+ crate :: BuiltIn :: Position { invariant : false } => "@position" ,
160
+ crate :: BuiltIn :: ViewIndex => "view_index" ,
161
+ crate :: BuiltIn :: BaseInstance => "{BaseInstance}" ,
162
+ crate :: BuiltIn :: BaseVertex => "{BaseVertex}" ,
163
+ crate :: BuiltIn :: ClipDistance => "{ClipDistance}" ,
164
+ crate :: BuiltIn :: CullDistance => "{CullDistance}" ,
165
+ crate :: BuiltIn :: InstanceIndex => "instance_index" ,
166
+ crate :: BuiltIn :: PointSize => "{PointSize}" ,
167
+ crate :: BuiltIn :: VertexIndex => "vertex_index" ,
168
+ crate :: BuiltIn :: DrawID => "{DrawId}" ,
169
+ crate :: BuiltIn :: FragDepth => "frag_depth" ,
170
+ crate :: BuiltIn :: PointCoord => "{PointCoord}" ,
171
+ crate :: BuiltIn :: FrontFacing => "front_facing" ,
172
+ crate :: BuiltIn :: PrimitiveIndex => "primitive_index" ,
173
+ crate :: BuiltIn :: SampleIndex => "sample_index" ,
174
+ crate :: BuiltIn :: SampleMask => "sample_mask" ,
175
+ crate :: BuiltIn :: GlobalInvocationId => "global_invocation_id" ,
176
+ crate :: BuiltIn :: LocalInvocationId => "local_invocation_id" ,
177
+ crate :: BuiltIn :: LocalInvocationIndex => "local_invocation_index" ,
178
+ crate :: BuiltIn :: WorkGroupId => "workgroup_id" ,
179
+ crate :: BuiltIn :: WorkGroupSize => "{WorkGroupSize}" ,
180
+ crate :: BuiltIn :: NumWorkGroups => "num_workgroups" ,
181
+ crate :: BuiltIn :: NumSubgroups => "num_subgroups" ,
182
+ crate :: BuiltIn :: SubgroupId => "{SubgroupId}" ,
183
+ crate :: BuiltIn :: SubgroupSize => "subgroup_size" ,
184
+ crate :: BuiltIn :: SubgroupInvocationId => "subgroup_invocation_id" ,
185
+ }
186
+ }
187
+ }
188
+
189
+ impl crate :: Interpolation {
190
+ pub fn to_wgsl ( self ) -> & ' static str {
191
+ match self {
192
+ crate :: Interpolation :: Perspective => "perspective" ,
193
+ crate :: Interpolation :: Linear => "linear" ,
194
+ crate :: Interpolation :: Flat => "flat" ,
195
+ }
196
+ }
197
+ }
198
+
199
+ impl crate :: Sampling {
200
+ pub fn to_wgsl ( self ) -> & ' static str {
201
+ match self {
202
+ crate :: Sampling :: Center => "center" ,
203
+ crate :: Sampling :: Centroid => "centroid" ,
204
+ crate :: Sampling :: Sample => "sample" ,
205
+ crate :: Sampling :: First => "first" ,
206
+ crate :: Sampling :: Either => "either" ,
207
+ }
208
+ }
209
+ }
210
+
71
211
pub struct Wgslish < T > ( pub T ) ;
72
212
73
213
impl Display for Wgslish < & crate :: TypeInner > {
@@ -191,7 +331,7 @@ impl Display for Wgslish<crate::AddressSpace> {
191
331
crate :: AddressSpace :: WorkGroup => "workgroup" ,
192
332
crate :: AddressSpace :: Uniform => "uniform" ,
193
333
crate :: AddressSpace :: Storage { access } => {
194
- return write ! ( f, "{access:?}" ) ;
334
+ return write ! ( f, "storage, {access:?}" ) ;
195
335
}
196
336
crate :: AddressSpace :: Handle => "handle" ,
197
337
crate :: AddressSpace :: PushConstant => "push_constant" ,
@@ -203,7 +343,7 @@ impl Display for Wgslish<crate::AddressSpace> {
203
343
impl Display for Wgslish < & crate :: Binding > {
204
344
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
205
345
match * self . 0 {
206
- crate :: Binding :: BuiltIn ( built_in) => Wgslish ( built_in) . fmt ( f ) ,
346
+ crate :: Binding :: BuiltIn ( built_in) => f . write_str ( built_in. to_wgsl ( ) ) ,
207
347
crate :: Binding :: Location {
208
348
location,
209
349
second_blend_source,
@@ -215,69 +355,13 @@ impl Display for Wgslish<&crate::Binding> {
215
355
f. write_str ( " @second_blend_source" ) ?;
216
356
}
217
357
if let Some ( interpolation) = interpolation {
218
- write ! ( f, " {}" , Wgslish ( interpolation) ) ?;
358
+ write ! ( f, " {}" , interpolation. to_wgsl ( ) ) ?;
219
359
}
220
360
if let Some ( sampling) = sampling {
221
- write ! ( f, " {}" , Wgslish ( sampling) ) ?;
361
+ write ! ( f, " {}" , sampling. to_wgsl ( ) ) ?;
222
362
}
223
363
Ok ( ( ) )
224
364
}
225
365
}
226
366
}
227
367
}
228
-
229
- impl Display for Wgslish < crate :: BuiltIn > {
230
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
231
- f. write_str ( match self . 0 {
232
- crate :: BuiltIn :: Position { invariant : true } => "@position @invariant" ,
233
- crate :: BuiltIn :: Position { invariant : false } => "@position" ,
234
- crate :: BuiltIn :: ViewIndex => "view_index" ,
235
- crate :: BuiltIn :: BaseInstance => "{BaseInstance}" ,
236
- crate :: BuiltIn :: BaseVertex => "{BaseVertex}" ,
237
- crate :: BuiltIn :: ClipDistance => "{ClipDistance}" ,
238
- crate :: BuiltIn :: CullDistance => "{CullDistance}" ,
239
- crate :: BuiltIn :: InstanceIndex => "instance_index" ,
240
- crate :: BuiltIn :: PointSize => "{PointSize}" ,
241
- crate :: BuiltIn :: VertexIndex => "vertex_index" ,
242
- crate :: BuiltIn :: DrawID => "{DrawId}" ,
243
- crate :: BuiltIn :: FragDepth => "frag_depth" ,
244
- crate :: BuiltIn :: PointCoord => "{PointCoord}" ,
245
- crate :: BuiltIn :: FrontFacing => "front_facing" ,
246
- crate :: BuiltIn :: PrimitiveIndex => "primitive_index" ,
247
- crate :: BuiltIn :: SampleIndex => "sample_index" ,
248
- crate :: BuiltIn :: SampleMask => "sample_mask" ,
249
- crate :: BuiltIn :: GlobalInvocationId => "global_invocation_id" ,
250
- crate :: BuiltIn :: LocalInvocationId => "local_invocation_id" ,
251
- crate :: BuiltIn :: LocalInvocationIndex => "local_invocation_index" ,
252
- crate :: BuiltIn :: WorkGroupId => "workgroup_id" ,
253
- crate :: BuiltIn :: WorkGroupSize => "{WorkGroupSize}" ,
254
- crate :: BuiltIn :: NumWorkGroups => "num_workgroups" ,
255
- crate :: BuiltIn :: NumSubgroups => "num_subgroups" ,
256
- crate :: BuiltIn :: SubgroupId => "{SubgroupId}" ,
257
- crate :: BuiltIn :: SubgroupSize => "subgroup_size" ,
258
- crate :: BuiltIn :: SubgroupInvocationId => "subgroup_invocation_id" ,
259
- } )
260
- }
261
- }
262
-
263
- impl Display for Wgslish < crate :: Interpolation > {
264
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
265
- f. write_str ( match self . 0 {
266
- crate :: Interpolation :: Perspective => "perspective" ,
267
- crate :: Interpolation :: Linear => "linear" ,
268
- crate :: Interpolation :: Flat => "flat" ,
269
- } )
270
- }
271
- }
272
-
273
- impl Display for Wgslish < crate :: Sampling > {
274
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
275
- f. write_str ( match self . 0 {
276
- crate :: Sampling :: Center => "center" ,
277
- crate :: Sampling :: Centroid => "centroid" ,
278
- crate :: Sampling :: Sample => "sample" ,
279
- crate :: Sampling :: First => "first" ,
280
- crate :: Sampling :: Either => "either" ,
281
- } )
282
- }
283
- }
0 commit comments