|
| 1 | +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] |
| 2 | +pub enum DirectiveKind { |
| 3 | + Unimplemented(UnimplementedDirectiveKind), |
| 4 | +} |
| 5 | + |
| 6 | +impl DirectiveKind { |
| 7 | + const DIAGNOSTIC: &'static str = "diagnostic"; |
| 8 | + const ENABLE: &'static str = "enable"; |
| 9 | + const REQUIRES: &'static str = "requires"; |
| 10 | + |
| 11 | + pub fn from_ident(s: &str) -> Option<Self> { |
| 12 | + Some(match s { |
| 13 | + Self::DIAGNOSTIC => Self::Unimplemented(UnimplementedDirectiveKind::Diagnostic), |
| 14 | + Self::ENABLE => Self::Unimplemented(UnimplementedDirectiveKind::Enable), |
| 15 | + Self::REQUIRES => Self::Unimplemented(UnimplementedDirectiveKind::Requires), |
| 16 | + _ => return None, |
| 17 | + }) |
| 18 | + } |
| 19 | + |
| 20 | + pub const fn to_ident(self) -> &'static str { |
| 21 | + match self { |
| 22 | + Self::Unimplemented(kind) => match kind { |
| 23 | + UnimplementedDirectiveKind::Diagnostic => Self::DIAGNOSTIC, |
| 24 | + UnimplementedDirectiveKind::Enable => Self::ENABLE, |
| 25 | + UnimplementedDirectiveKind::Requires => Self::REQUIRES, |
| 26 | + }, |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + #[cfg(test)] |
| 31 | + fn iter() -> impl Iterator<Item = Self> { |
| 32 | + use strum::IntoEnumIterator; |
| 33 | + |
| 34 | + UnimplementedDirectiveKind::iter().map(Self::Unimplemented) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] |
| 39 | +#[cfg_attr(test, derive(strum::EnumIter))] |
| 40 | +pub enum UnimplementedDirectiveKind { |
| 41 | + Diagnostic, |
| 42 | + Enable, |
| 43 | + Requires, |
| 44 | +} |
| 45 | + |
| 46 | +impl UnimplementedDirectiveKind { |
| 47 | + pub const fn tracking_issue_num(self) -> u16 { |
| 48 | + match self { |
| 49 | + Self::Diagnostic => 5320, |
| 50 | + Self::Requires => 6350, |
| 51 | + Self::Enable => 5476, |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +#[cfg(test)] |
| 57 | +mod test { |
| 58 | + use strum::IntoEnumIterator; |
| 59 | + |
| 60 | + use crate::front::wgsl::assert_parse_err; |
| 61 | + |
| 62 | + use super::{DirectiveKind, UnimplementedDirectiveKind}; |
| 63 | + |
| 64 | + #[test] |
| 65 | + fn unimplemented_directives() { |
| 66 | + for unsupported_shader in UnimplementedDirectiveKind::iter() { |
| 67 | + let shader; |
| 68 | + let expected_msg; |
| 69 | + match unsupported_shader { |
| 70 | + UnimplementedDirectiveKind::Diagnostic => { |
| 71 | + shader = "diagnostic(off,derivative_uniformity);"; |
| 72 | + expected_msg = "\ |
| 73 | +error: `diagnostic` is not yet implemented |
| 74 | + ┌─ wgsl:1:1 |
| 75 | + │ |
| 76 | +1 │ diagnostic(off,derivative_uniformity); |
| 77 | + │ ^^^^^^^^^^ this global directive is standard, but not yet implemented |
| 78 | + │ |
| 79 | + = note: Let Naga maintainers know that you ran into this at <https://github.com/gfx-rs/wgpu/issues/5320>, so they can prioritize it! |
| 80 | +
|
| 81 | +"; |
| 82 | + } |
| 83 | + UnimplementedDirectiveKind::Enable => { |
| 84 | + shader = "enable f16;"; |
| 85 | + expected_msg = "\ |
| 86 | +error: `enable` is not yet implemented |
| 87 | + ┌─ wgsl:1:1 |
| 88 | + │ |
| 89 | +1 │ enable f16; |
| 90 | + │ ^^^^^^ this global directive is standard, but not yet implemented |
| 91 | + │ |
| 92 | + = note: Let Naga maintainers know that you ran into this at <https://github.com/gfx-rs/wgpu/issues/5476>, so they can prioritize it! |
| 93 | +
|
| 94 | +"; |
| 95 | + } |
| 96 | + UnimplementedDirectiveKind::Requires => { |
| 97 | + shader = "requires readonly_and_readwrite_storage_textures"; |
| 98 | + expected_msg = "\ |
| 99 | +error: `requires` is not yet implemented |
| 100 | + ┌─ wgsl:1:1 |
| 101 | + │ |
| 102 | +1 │ requires readonly_and_readwrite_storage_textures |
| 103 | + │ ^^^^^^^^ this global directive is standard, but not yet implemented |
| 104 | + │ |
| 105 | + = note: Let Naga maintainers know that you ran into this at <https://github.com/gfx-rs/wgpu/issues/6350>, so they can prioritize it! |
| 106 | +
|
| 107 | +"; |
| 108 | + } |
| 109 | + }; |
| 110 | + |
| 111 | + assert_parse_err(shader, expected_msg); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + #[test] |
| 116 | + fn directive_after_global_decl() { |
| 117 | + for unsupported_shader in DirectiveKind::iter() { |
| 118 | + let directive; |
| 119 | + let expected_msg; |
| 120 | + match unsupported_shader { |
| 121 | + DirectiveKind::Unimplemented(UnimplementedDirectiveKind::Diagnostic) => { |
| 122 | + directive = "diagnostic(off,derivative_uniformity)"; |
| 123 | + expected_msg = "\ |
| 124 | +error: expected global declaration, but found a global directive |
| 125 | + ┌─ wgsl:2:1 |
| 126 | + │ |
| 127 | +2 │ diagnostic(off,derivative_uniformity); |
| 128 | + │ ^^^^^^^^^^ written after first global declaration |
| 129 | + │ |
| 130 | + = note: global directives are only allowed before global declarations; maybe hoist this closer to the top of the shader module? |
| 131 | +
|
| 132 | +"; |
| 133 | + } |
| 134 | + DirectiveKind::Unimplemented(UnimplementedDirectiveKind::Enable) => { |
| 135 | + directive = "enable f16"; |
| 136 | + expected_msg = "\ |
| 137 | +error: expected global declaration, but found a global directive |
| 138 | + ┌─ wgsl:2:1 |
| 139 | + │ |
| 140 | +2 │ enable f16; |
| 141 | + │ ^^^^^^ written after first global declaration |
| 142 | + │ |
| 143 | + = note: global directives are only allowed before global declarations; maybe hoist this closer to the top of the shader module? |
| 144 | +
|
| 145 | +"; |
| 146 | + } |
| 147 | + DirectiveKind::Unimplemented(UnimplementedDirectiveKind::Requires) => { |
| 148 | + directive = "requires readonly_and_readwrite_storage_textures"; |
| 149 | + expected_msg = "\ |
| 150 | +error: expected global declaration, but found a global directive |
| 151 | + ┌─ wgsl:2:1 |
| 152 | + │ |
| 153 | +2 │ requires readonly_and_readwrite_storage_textures; |
| 154 | + │ ^^^^^^^^ written after first global declaration |
| 155 | + │ |
| 156 | + = note: global directives are only allowed before global declarations; maybe hoist this closer to the top of the shader module? |
| 157 | +
|
| 158 | +"; |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + let shader = format!( |
| 163 | + "\ |
| 164 | +@group(0) @binding(0) var<storage> thing: i32; |
| 165 | +{directive}; |
| 166 | +" |
| 167 | + ); |
| 168 | + assert_parse_err(&shader, expected_msg); |
| 169 | + } |
| 170 | + } |
| 171 | +} |
0 commit comments