ptx_parser/parser/instruction/
tex.rs

1//! Original PTX specification:
2//!
3//! tex.geom.v4.dtype.ctype  d{|p}, [a, c] {, e} {, f};
4//! tex.geom.v4.dtype.ctype  d{|p}, [a, b, c] {, e} {, f};  // explicit sampler
5//! tex.geom.v2.f16x2.ctype  d{|p}, [a, c] {, e} {, f};
6//! tex.geom.v2.f16x2.ctype  d{|p}, [a, b, c] {, e} {, f};  // explicit sampler
7//! // mipmaps
8//! tex.base.geom.v4.dtype.ctype   d{|p}, [a, {b,} c] {, e} {, f};
9//! tex.level.geom.v4.dtype.ctype  d{|p}, [a, {b,} c], lod {, e} {, f};
10//! tex.grad.geom.v4.dtype.ctype   d{|p}, [a, {b,} c], dPdx, dPdy {, e} {, f};
11//! tex.base.geom.v2.f16x2.ctype   d{|p}, [a, {b,} c] {, e} {, f};
12//! tex.level.geom.v2.f16x2.ctype  d{|p}, [a, {b,} c], lod {, e} {, f};
13//! tex.grad.geom.v2.f16x2.ctype   d{|p}, [a, {b,} c], dPdx, dPdy {, e} {, f};
14//! .geom  = { .1d, .2d, .3d, .a1d, .a2d, .cube, .acube, .2dms, .a2dms };
15//! .dtype = { .u32, .s32, .f16,  .f32 };
16//! .ctype = {       .s32, .f32 };          // .cube, .acube require .f32
17//! // .2dms, .a2dms require .s32
18
19#![allow(unused)]
20
21use crate::parser::{
22    PtxParseError, PtxParser, PtxTokenStream, Span,
23    util::{
24        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
25        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
26    },
27};
28use crate::r#type::common::*;
29use crate::{alt, ok, seq_n};
30
31pub mod section_0 {
32    use super::*;
33    use crate::r#type::instruction::tex::section_0::*;
34
35    // ============================================================================
36    // Generated enum parsers
37    // ============================================================================
38
39    impl PtxParser for Ctype {
40        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
41            alt!(
42                map(string_p(".s32"), |_, _span| Ctype::S32),
43                map(string_p(".f32"), |_, _span| Ctype::F32)
44            )
45        }
46    }
47
48    impl PtxParser for Dtype {
49        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
50            alt!(
51                map(string_p(".u32"), |_, _span| Dtype::U32),
52                map(string_p(".s32"), |_, _span| Dtype::S32),
53                map(string_p(".f16"), |_, _span| Dtype::F16),
54                map(string_p(".f32"), |_, _span| Dtype::F32)
55            )
56        }
57    }
58
59    impl PtxParser for Geom {
60        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
61            alt!(
62                map(string_p(".acube"), |_, _span| Geom::Acube),
63                map(string_p(".a2dms"), |_, _span| Geom::A2dms),
64                map(string_p(".cube"), |_, _span| Geom::Cube),
65                map(string_p(".2dms"), |_, _span| Geom::_2dms),
66                map(string_p(".a1d"), |_, _span| Geom::A1d),
67                map(string_p(".a2d"), |_, _span| Geom::A2d),
68                map(string_p(".1d"), |_, _span| Geom::_1d),
69                map(string_p(".2d"), |_, _span| Geom::_2d),
70                map(string_p(".3d"), |_, _span| Geom::_3d)
71            )
72        }
73    }
74
75    impl PtxParser for TexGeomV4DtypeCtype {
76        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
77            try_map(
78                seq_n!(
79                    string_p("tex"),
80                    Geom::parse(),
81                    string_p(".v4"),
82                    Dtype::parse(),
83                    Ctype::parse(),
84                    GeneralOperand::parse(),
85                    map(
86                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
87                        |value, _| value.map(|(_, operand)| operand)
88                    ),
89                    comma_p(),
90                    TexHandler2::parse(),
91                    map(
92                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
93                        |value, _| value.map(|(_, operand)| operand)
94                    ),
95                    map(
96                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
97                        |value, _| value.map(|(_, operand)| operand)
98                    ),
99                    semicolon_p()
100                ),
101                |(_, geom, v4, dtype, ctype, d, p, _, a, e, f, _), span| {
102                    ok!(TexGeomV4DtypeCtype {
103                        geom = geom,
104                        v4 = v4,
105                        dtype = dtype,
106                        ctype = ctype,
107                        d = d,
108                        p = p,
109                        a = a,
110                        e = e,
111                        f = f,
112
113                    })
114                },
115            )
116        }
117    }
118
119    impl PtxParser for TexGeomV4DtypeCtype1 {
120        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
121            try_map(
122                seq_n!(
123                    string_p("tex"),
124                    Geom::parse(),
125                    string_p(".v4"),
126                    Dtype::parse(),
127                    Ctype::parse(),
128                    GeneralOperand::parse(),
129                    map(
130                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
131                        |value, _| value.map(|(_, operand)| operand)
132                    ),
133                    comma_p(),
134                    TexHandler3::parse(),
135                    map(
136                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
137                        |value, _| value.map(|(_, operand)| operand)
138                    ),
139                    map(
140                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
141                        |value, _| value.map(|(_, operand)| operand)
142                    ),
143                    semicolon_p()
144                ),
145                |(_, geom, v4, dtype, ctype, d, p, _, a, e, f, _), span| {
146                    ok!(TexGeomV4DtypeCtype1 {
147                        geom = geom,
148                        v4 = v4,
149                        dtype = dtype,
150                        ctype = ctype,
151                        d = d,
152                        p = p,
153                        a = a,
154                        e = e,
155                        f = f,
156
157                    })
158                },
159            )
160        }
161    }
162
163    impl PtxParser for TexGeomV2F16x2Ctype {
164        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
165            try_map(
166                seq_n!(
167                    string_p("tex"),
168                    Geom::parse(),
169                    string_p(".v2"),
170                    string_p(".f16x2"),
171                    Ctype::parse(),
172                    GeneralOperand::parse(),
173                    map(
174                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
175                        |value, _| value.map(|(_, operand)| operand)
176                    ),
177                    comma_p(),
178                    TexHandler2::parse(),
179                    map(
180                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
181                        |value, _| value.map(|(_, operand)| operand)
182                    ),
183                    map(
184                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
185                        |value, _| value.map(|(_, operand)| operand)
186                    ),
187                    semicolon_p()
188                ),
189                |(_, geom, v2, f16x2, ctype, d, p, _, a, e, f, _), span| {
190                    ok!(TexGeomV2F16x2Ctype {
191                        geom = geom,
192                        v2 = v2,
193                        f16x2 = f16x2,
194                        ctype = ctype,
195                        d = d,
196                        p = p,
197                        a = a,
198                        e = e,
199                        f = f,
200
201                    })
202                },
203            )
204        }
205    }
206
207    impl PtxParser for TexGeomV2F16x2Ctype1 {
208        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
209            try_map(
210                seq_n!(
211                    string_p("tex"),
212                    Geom::parse(),
213                    string_p(".v2"),
214                    string_p(".f16x2"),
215                    Ctype::parse(),
216                    GeneralOperand::parse(),
217                    map(
218                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
219                        |value, _| value.map(|(_, operand)| operand)
220                    ),
221                    comma_p(),
222                    TexHandler3::parse(),
223                    map(
224                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
225                        |value, _| value.map(|(_, operand)| operand)
226                    ),
227                    map(
228                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
229                        |value, _| value.map(|(_, operand)| operand)
230                    ),
231                    semicolon_p()
232                ),
233                |(_, geom, v2, f16x2, ctype, d, p, _, a, e, f, _), span| {
234                    ok!(TexGeomV2F16x2Ctype1 {
235                        geom = geom,
236                        v2 = v2,
237                        f16x2 = f16x2,
238                        ctype = ctype,
239                        d = d,
240                        p = p,
241                        a = a,
242                        e = e,
243                        f = f,
244
245                    })
246                },
247            )
248        }
249    }
250
251    impl PtxParser for TexBaseGeomV4DtypeCtype {
252        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
253            try_map(
254                seq_n!(
255                    string_p("tex"),
256                    string_p(".base"),
257                    Geom::parse(),
258                    string_p(".v4"),
259                    Dtype::parse(),
260                    Ctype::parse(),
261                    GeneralOperand::parse(),
262                    map(
263                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
264                        |value, _| value.map(|(_, operand)| operand)
265                    ),
266                    comma_p(),
267                    TexHandler3Optional::parse(),
268                    map(
269                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
270                        |value, _| value.map(|(_, operand)| operand)
271                    ),
272                    map(
273                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
274                        |value, _| value.map(|(_, operand)| operand)
275                    ),
276                    semicolon_p()
277                ),
278                |(_, base, geom, v4, dtype, ctype, d, p, _, a, e, f, _), span| {
279                    ok!(TexBaseGeomV4DtypeCtype {
280                        base = base,
281                        geom = geom,
282                        v4 = v4,
283                        dtype = dtype,
284                        ctype = ctype,
285                        d = d,
286                        p = p,
287                        a = a,
288                        e = e,
289                        f = f,
290
291                    })
292                },
293            )
294        }
295    }
296
297    impl PtxParser for TexLevelGeomV4DtypeCtype {
298        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
299            try_map(
300                seq_n!(
301                    string_p("tex"),
302                    string_p(".level"),
303                    Geom::parse(),
304                    string_p(".v4"),
305                    Dtype::parse(),
306                    Ctype::parse(),
307                    GeneralOperand::parse(),
308                    map(
309                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
310                        |value, _| value.map(|(_, operand)| operand)
311                    ),
312                    comma_p(),
313                    TexHandler3Optional::parse(),
314                    comma_p(),
315                    GeneralOperand::parse(),
316                    map(
317                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
318                        |value, _| value.map(|(_, operand)| operand)
319                    ),
320                    map(
321                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
322                        |value, _| value.map(|(_, operand)| operand)
323                    ),
324                    semicolon_p()
325                ),
326                |(_, level, geom, v4, dtype, ctype, d, p, _, a, _, lod, e, f, _), span| {
327                    ok!(TexLevelGeomV4DtypeCtype {
328                        level = level,
329                        geom = geom,
330                        v4 = v4,
331                        dtype = dtype,
332                        ctype = ctype,
333                        d = d,
334                        p = p,
335                        a = a,
336                        lod = lod,
337                        e = e,
338                        f = f,
339
340                    })
341                },
342            )
343        }
344    }
345
346    impl PtxParser for TexGradGeomV4DtypeCtype {
347        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
348            try_map(
349                seq_n!(
350                    string_p("tex"),
351                    string_p(".grad"),
352                    Geom::parse(),
353                    string_p(".v4"),
354                    Dtype::parse(),
355                    Ctype::parse(),
356                    GeneralOperand::parse(),
357                    map(
358                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
359                        |value, _| value.map(|(_, operand)| operand)
360                    ),
361                    comma_p(),
362                    TexHandler3Optional::parse(),
363                    comma_p(),
364                    GeneralOperand::parse(),
365                    comma_p(),
366                    GeneralOperand::parse(),
367                    map(
368                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
369                        |value, _| value.map(|(_, operand)| operand)
370                    ),
371                    map(
372                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
373                        |value, _| value.map(|(_, operand)| operand)
374                    ),
375                    semicolon_p()
376                ),
377                |(_, grad, geom, v4, dtype, ctype, d, p, _, a, _, dpdx, _, dpdy, e, f, _), span| {
378                    ok!(TexGradGeomV4DtypeCtype {
379                        grad = grad,
380                        geom = geom,
381                        v4 = v4,
382                        dtype = dtype,
383                        ctype = ctype,
384                        d = d,
385                        p = p,
386                        a = a,
387                        dpdx = dpdx,
388                        dpdy = dpdy,
389                        e = e,
390                        f = f,
391
392                    })
393                },
394            )
395        }
396    }
397
398    impl PtxParser for TexBaseGeomV2F16x2Ctype {
399        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
400            try_map(
401                seq_n!(
402                    string_p("tex"),
403                    string_p(".base"),
404                    Geom::parse(),
405                    string_p(".v2"),
406                    string_p(".f16x2"),
407                    Ctype::parse(),
408                    GeneralOperand::parse(),
409                    map(
410                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
411                        |value, _| value.map(|(_, operand)| operand)
412                    ),
413                    comma_p(),
414                    TexHandler3Optional::parse(),
415                    map(
416                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
417                        |value, _| value.map(|(_, operand)| operand)
418                    ),
419                    map(
420                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
421                        |value, _| value.map(|(_, operand)| operand)
422                    ),
423                    semicolon_p()
424                ),
425                |(_, base, geom, v2, f16x2, ctype, d, p, _, a, e, f, _), span| {
426                    ok!(TexBaseGeomV2F16x2Ctype {
427                        base = base,
428                        geom = geom,
429                        v2 = v2,
430                        f16x2 = f16x2,
431                        ctype = ctype,
432                        d = d,
433                        p = p,
434                        a = a,
435                        e = e,
436                        f = f,
437
438                    })
439                },
440            )
441        }
442    }
443
444    impl PtxParser for TexLevelGeomV2F16x2Ctype {
445        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
446            try_map(
447                seq_n!(
448                    string_p("tex"),
449                    string_p(".level"),
450                    Geom::parse(),
451                    string_p(".v2"),
452                    string_p(".f16x2"),
453                    Ctype::parse(),
454                    GeneralOperand::parse(),
455                    map(
456                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
457                        |value, _| value.map(|(_, operand)| operand)
458                    ),
459                    comma_p(),
460                    TexHandler3Optional::parse(),
461                    comma_p(),
462                    GeneralOperand::parse(),
463                    map(
464                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
465                        |value, _| value.map(|(_, operand)| operand)
466                    ),
467                    map(
468                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
469                        |value, _| value.map(|(_, operand)| operand)
470                    ),
471                    semicolon_p()
472                ),
473                |(_, level, geom, v2, f16x2, ctype, d, p, _, a, _, lod, e, f, _), span| {
474                    ok!(TexLevelGeomV2F16x2Ctype {
475                        level = level,
476                        geom = geom,
477                        v2 = v2,
478                        f16x2 = f16x2,
479                        ctype = ctype,
480                        d = d,
481                        p = p,
482                        a = a,
483                        lod = lod,
484                        e = e,
485                        f = f,
486
487                    })
488                },
489            )
490        }
491    }
492
493    impl PtxParser for TexGradGeomV2F16x2Ctype {
494        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
495            try_map(
496                seq_n!(
497                    string_p("tex"),
498                    string_p(".grad"),
499                    Geom::parse(),
500                    string_p(".v2"),
501                    string_p(".f16x2"),
502                    Ctype::parse(),
503                    GeneralOperand::parse(),
504                    map(
505                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
506                        |value, _| value.map(|(_, operand)| operand)
507                    ),
508                    comma_p(),
509                    TexHandler3Optional::parse(),
510                    comma_p(),
511                    GeneralOperand::parse(),
512                    comma_p(),
513                    GeneralOperand::parse(),
514                    map(
515                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
516                        |value, _| value.map(|(_, operand)| operand)
517                    ),
518                    map(
519                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
520                        |value, _| value.map(|(_, operand)| operand)
521                    ),
522                    semicolon_p()
523                ),
524                |(_, grad, geom, v2, f16x2, ctype, d, p, _, a, _, dpdx, _, dpdy, e, f, _), span| {
525                    ok!(TexGradGeomV2F16x2Ctype {
526                        grad = grad,
527                        geom = geom,
528                        v2 = v2,
529                        f16x2 = f16x2,
530                        ctype = ctype,
531                        d = d,
532                        p = p,
533                        a = a,
534                        dpdx = dpdx,
535                        dpdy = dpdy,
536                        e = e,
537                        f = f,
538
539                    })
540                },
541            )
542        }
543    }
544}