@@ -17,23 +17,23 @@ pub struct EnableExtensions {
1717 /// Whether `enable clip_distances;` was written earlier in the shader module.
1818 clip_distances : bool ,
1919 /// Native-only extensions.
20- wgpu : NativeOnly < WgpuEnableExtensions > ,
20+ native_only : NativeOnly < NativeOnlyEnableExtensions > ,
2121}
2222
2323impl EnableExtensions {
2424 pub ( crate ) const fn empty ( native_only : NativeOnly < ( ) > ) -> Self {
2525 // TODO: It'd be nice to use a `const` `map` helper here, once
2626 // <https://github.com/rust-lang/rust/issues/73255> has landed.
27- let wgpu = match native_only {
27+ let native_only = match native_only {
2828 NativeOnly :: NotAllowed {
2929 can_suggest_in_diagnostics,
3030 } => NativeOnly :: NotAllowed {
3131 can_suggest_in_diagnostics,
3232 } ,
33- NativeOnly :: Allowed ( ( ) ) => NativeOnly :: Allowed ( WgpuEnableExtensions :: empty ( ) ) ,
33+ NativeOnly :: Allowed ( ( ) ) => NativeOnly :: Allowed ( NativeOnlyEnableExtensions :: empty ( ) ) ,
3434 } ;
3535 Self {
36- wgpu ,
36+ native_only ,
3737 f16 : false ,
3838 dual_source_blending : false ,
3939 clip_distances : false ,
@@ -45,18 +45,18 @@ impl EnableExtensions {
4545 & mut self ,
4646 span : Span ,
4747 ext : ImplementedEnableExtension ,
48- ) -> core:: result:: Result < ( ) , EnableExtensionNotAvailableError > {
48+ ) -> core:: result:: Result < ( ) , NativeOnlyEnableExtensionError > {
4949 macro_rules! check_wgpu {
5050 ( $f: expr) => { {
51- let f: fn ( & mut WgpuEnableExtensions ) -> & mut bool = $f;
52- match & mut self . wgpu {
51+ let f: fn ( & mut NativeOnlyEnableExtensions ) -> & mut bool = $f;
52+ match & mut self . native_only {
5353 & mut NativeOnly :: Allowed ( ref mut wgpu) => Ok ( f( wgpu) ) ,
5454 & mut NativeOnly :: NotAllowed {
5555 can_suggest_in_diagnostics,
56- } => Err ( EnableExtensionNotAvailableError {
56+ } => Err ( NativeOnlyEnableExtensionError {
5757 span,
5858 extension: ext,
59- reason: EnableExtensionNotAvailableErrorReason :: NotAllowed {
59+ reason: NativeOnlyEnableExtensionErrorReason :: NotAllowed {
6060 can_suggest_in_diagnostics,
6161 } ,
6262 } ) ,
@@ -65,17 +65,17 @@ impl EnableExtensions {
6565 }
6666 let field = match ext {
6767 ImplementedEnableExtension :: WgpuMeshShader => {
68- check_wgpu ! ( |wgpu | & mut wgpu . mesh_shader ) ?
68+ check_wgpu ! ( |no | & mut no . wgpu_mesh_shader ) ?
6969 }
70- ImplementedEnableExtension :: WgpuRayQuery => check_wgpu ! ( |wgpu | & mut wgpu . ray_query ) ?,
70+ ImplementedEnableExtension :: WgpuRayQuery => check_wgpu ! ( |no | & mut no . wgpu_ray_query ) ?,
7171 ImplementedEnableExtension :: WgpuRayQueryVertexReturn => {
72- check_wgpu ! ( |wgpu | & mut wgpu . ray_query_vertex_return ) ?
72+ check_wgpu ! ( |no | & mut no . wgpu_ray_query_vertex_return ) ?
7373 }
7474 ImplementedEnableExtension :: DualSourceBlending => & mut self . dual_source_blending ,
7575 ImplementedEnableExtension :: F16 => & mut self . f16 ,
7676 ImplementedEnableExtension :: ClipDistances => & mut self . clip_distances ,
7777 ImplementedEnableExtension :: WgpuCooperativeMatrix => {
78- check_wgpu ! ( |wgpu | & mut wgpu . cooperative_matrix ) ?
78+ check_wgpu ! ( |no | & mut no . wgpu_cooperative_matrix ) ?
7979 }
8080 } ;
8181 * field = true ;
@@ -88,41 +88,41 @@ impl EnableExtensions {
8888 & self ,
8989 span : Span ,
9090 extension : ImplementedEnableExtension ,
91- ) -> core:: result:: Result < ( ) , EnableExtensionNotAvailableError > {
92- let check_wgpu = |f : fn ( & WgpuEnableExtensions ) -> bool | match & self . wgpu {
91+ ) -> core:: result:: Result < ( ) , NativeOnlyEnableExtensionError > {
92+ let check_wgpu = |f : fn ( & NativeOnlyEnableExtensions ) -> bool | match & self . native_only {
9393 & NativeOnly :: Allowed ( ref wgpu) => Ok ( f ( wgpu) ) ,
9494 & NativeOnly :: NotAllowed {
9595 can_suggest_in_diagnostics,
96- } => Err ( EnableExtensionNotAvailableError {
96+ } => Err ( NativeOnlyEnableExtensionError {
9797 span,
9898 extension,
99- reason : EnableExtensionNotAvailableErrorReason :: NotAllowed {
99+ reason : NativeOnlyEnableExtensionErrorReason :: NotAllowed {
100100 can_suggest_in_diagnostics,
101101 } ,
102102 } ) ,
103103 } ;
104104
105105 let is_enabled = match extension {
106- ImplementedEnableExtension :: WgpuMeshShader => check_wgpu ( |wgpu| wgpu . mesh_shader ) ?,
107- ImplementedEnableExtension :: WgpuRayQuery => check_wgpu ( |wgpu| wgpu . ray_query ) ?,
106+ ImplementedEnableExtension :: WgpuMeshShader => check_wgpu ( |no| no . wgpu_mesh_shader ) ?,
107+ ImplementedEnableExtension :: WgpuRayQuery => check_wgpu ( |no| no . wgpu_ray_query ) ?,
108108 ImplementedEnableExtension :: WgpuRayQueryVertexReturn => {
109- check_wgpu ( |wgpu| wgpu . ray_query_vertex_return ) ?
109+ check_wgpu ( |no| no . wgpu_ray_query_vertex_return ) ?
110110 }
111111 ImplementedEnableExtension :: DualSourceBlending => self . dual_source_blending ,
112112 ImplementedEnableExtension :: F16 => self . f16 ,
113113 ImplementedEnableExtension :: ClipDistances => self . clip_distances ,
114114 ImplementedEnableExtension :: WgpuCooperativeMatrix => {
115- check_wgpu ( |wgpu| wgpu . cooperative_matrix ) ?
115+ check_wgpu ( |no| no . wgpu_cooperative_matrix ) ?
116116 }
117117 } ;
118118
119119 if is_enabled {
120120 Ok ( ( ) )
121121 } else {
122- Err ( EnableExtensionNotAvailableError {
122+ Err ( NativeOnlyEnableExtensionError {
123123 span,
124124 extension,
125- reason : EnableExtensionNotAvailableErrorReason :: NotEnabled ,
125+ reason : NativeOnlyEnableExtensionErrorReason :: NotEnabled ,
126126 } )
127127 }
128128 }
@@ -174,46 +174,50 @@ impl<T> Default for NativeOnly<T> {
174174
175175/// Native-only extensions under [`EnableExtensions::wgpu`].
176176#[ derive( Clone , Debug , Eq , PartialEq ) ]
177- pub struct WgpuEnableExtensions {
177+ pub struct NativeOnlyEnableExtensions {
178178 /// Whether `enable wgpu_mesh_shader;` was written earlier in the shader module.
179- mesh_shader : bool ,
179+ wgpu_mesh_shader : bool ,
180180 /// Whether `enable wgpu_ray_query;` was written earlier in the shader module.
181- ray_query : bool ,
181+ wgpu_ray_query : bool ,
182182 /// Whether `enable wgpu_ray_query_vertex_return;` was written earlier in the shader module.
183- ray_query_vertex_return : bool ,
183+ wgpu_ray_query_vertex_return : bool ,
184184 /// Whether `enable wgpu_cooperative_matrix;` was written earlier in the shader module.
185- cooperative_matrix : bool ,
185+ wgpu_cooperative_matrix : bool ,
186186}
187187
188- impl WgpuEnableExtensions {
188+ impl NativeOnlyEnableExtensions {
189189 pub ( crate ) const fn empty ( ) -> Self {
190190 Self {
191- mesh_shader : false ,
192- ray_query : false ,
193- ray_query_vertex_return : false ,
194- cooperative_matrix : false ,
191+ wgpu_mesh_shader : false ,
192+ wgpu_ray_query : false ,
193+ wgpu_ray_query_vertex_return : false ,
194+ wgpu_cooperative_matrix : false ,
195195 }
196196 }
197197}
198198
199- impl Default for WgpuEnableExtensions {
199+ impl Default for NativeOnlyEnableExtensions {
200200 fn default ( ) -> Self {
201201 Self :: empty ( )
202202 }
203203}
204204
205205/// An error returned by [`EnableExtensions::contains`].
206206#[ derive( Clone , Debug ) ]
207- pub struct EnableExtensionNotAvailableError {
208- span : Span ,
209- extension : ImplementedEnableExtension ,
210- reason : EnableExtensionNotAvailableErrorReason ,
207+ pub struct NativeOnlyEnableExtensionError {
208+ pub span : Span ,
209+ pub extension : ImplementedEnableExtension ,
210+ pub reason : NativeOnlyEnableExtensionErrorReason ,
211211}
212212
213213/// An [`EnableExtensionNotAvailableError::reason`].
214214#[ derive( Clone , Debug , Eq , PartialEq ) ]
215- pub enum EnableExtensionNotAvailableErrorReason {
215+ pub enum NativeOnlyEnableExtensionErrorReason {
216+ /// [`EnableExtensions::check`] was called, and only failed because the user didn't write
217+ /// `enable <extension>;`.
216218 NotEnabled ,
219+ /// [`EnableExtensions::check`] or `[EnableExtensions::enable]` was called for an extension
220+ /// not allowed in the current environment.
217221 NotAllowed { can_suggest_in_diagnostics : bool } ,
218222}
219223
0 commit comments