|
1 | 1 | use anyhow::{anyhow, Context as _}; |
| 2 | +use naga::front::wgsl::TreatMissingCapabiltiesAsUnknown; |
2 | 3 | use std::fs; |
3 | 4 | use std::{error::Error, fmt, io::Read, path::Path, str::FromStr}; |
4 | 5 |
|
@@ -144,6 +145,19 @@ struct Args { |
144 | 145 | /// defines to be passed to the parser (only glsl is supported) |
145 | 146 | #[argh(option, short = 'D')] |
146 | 147 | defines: Vec<Defines>, |
| 148 | + |
| 149 | + /// capabilities for parsing and validation. |
| 150 | + /// |
| 151 | + /// Can be a comma-separated list of capability names (e.g., |
| 152 | + /// "shader_float16,dual_source_blending"), a numeric bitflags value (e.g., |
| 153 | + /// "67108864"), the string "none", or the string "all". |
| 154 | + #[argh(option, default = "CapabilitiesArg(naga::valid::Capabilities::all())")] |
| 155 | + capabilities: CapabilitiesArg, |
| 156 | + |
| 157 | + /// whether diagnostics should recognize enable-extensions whose capabilities are missing, or |
| 158 | + /// pretend that such an extension is unknown. |
| 159 | + #[argh(switch)] |
| 160 | + treat_missing_capabilities_as_unknown: bool, |
147 | 161 | } |
148 | 162 |
|
149 | 163 | /// Newtype so we can implement [`FromStr`] for `BoundsCheckPolicy`. |
@@ -350,7 +364,7 @@ struct Parameters<'a> { |
350 | 364 | input_kind: Option<InputKind>, |
351 | 365 | shader_stage: Option<ShaderStage>, |
352 | 366 | defines: FastHashMap<String, String>, |
353 | | - |
| 367 | + treat_missing_capabilities_as_unknown: bool, |
354 | 368 | /// We use this copy of `args.compact` to know whether we should pass the |
355 | 369 | /// entrypoint to `process_overrides`, which will result in removal from |
356 | 370 | /// the module of anything not reachable from that entry point. |
@@ -503,6 +517,7 @@ fn run() -> anyhow::Result<()> { |
503 | 517 | ); |
504 | 518 |
|
505 | 519 | params.compact = args.compact; |
| 520 | + params.treat_missing_capabilities_as_unknown = args.treat_missing_capabilities_as_unknown; |
506 | 521 |
|
507 | 522 | if args.bulk_validate { |
508 | 523 | return bulk_validate(&args, ¶ms); |
@@ -680,7 +695,12 @@ fn parse_input(input_path: &Path, input: Vec<u8>, params: &Parameters) -> anyhow |
680 | 695 | }, |
681 | 696 | InputKind::Wgsl => { |
682 | 697 | let input = String::from_utf8(input)?; |
683 | | - let result = naga::front::wgsl::parse_str(&input); |
| 698 | +(??) let options = naga::front::wgsl::Options { |
| 699 | +(??) parse_doc_comments: false, |
| 700 | +(??) capabilities: params.capabilities, |
| 701 | +(??) }; |
| 702 | +(??) let mut frontend = naga::front::wgsl::Frontend::new_with_options(options); |
| 703 | +(??) let result = frontend.parse(&input); |
684 | 704 | match result { |
685 | 705 | Ok(v) => Parsed { |
686 | 706 | module: v, |
|
0 commit comments