@@ -34,6 +34,7 @@ pub struct ImageType {
34
34
sampled : Sampled ,
35
35
sampled_type : SampledType ,
36
36
components : u32 ,
37
+ access : Option < AccessQualifier > ,
37
38
}
38
39
39
40
impl Parse for ImageType {
@@ -47,6 +48,7 @@ impl Parse for ImageType {
47
48
let mut sampled: Option < Sampled > = None ;
48
49
let mut crate_root = None ;
49
50
let mut components = None ;
51
+ let mut access = None ;
50
52
51
53
let starting_span = input. span ( ) ;
52
54
@@ -122,6 +124,16 @@ impl Parse for ImageType {
122
124
. map( syn:: LitBool :: value)
123
125
. map_or( ImageDepth :: True , From :: from)
124
126
) ;
127
+ } else if ident == "access" {
128
+ let value = peek_and_eat_value ! ( syn:: Ident ) ;
129
+ let value = params:: image_access_from_str (
130
+ value
131
+ . map ( |id| id. to_string ( ) )
132
+ . as_deref ( )
133
+ . unwrap_or ( "unknown" ) ,
134
+ )
135
+ . map_err ( |e| syn:: Error :: new ( ident. span ( ) , e) ) ?;
136
+ access = Some ( value) ;
125
137
} else if ident == "format" {
126
138
let value = peek_and_eat_value ! ( syn:: Ident ) ;
127
139
@@ -377,6 +389,7 @@ impl Parse for ImageType {
377
389
sampled,
378
390
sampled_type,
379
391
components,
392
+ access,
380
393
} )
381
394
}
382
395
}
@@ -400,6 +413,7 @@ impl quote::ToTokens for ImageType {
400
413
let sampled = params:: sampled_to_tokens ( & self . sampled ) ;
401
414
let sampled_type = & self . sampled_type ;
402
415
let components = self . components ;
416
+ let access = params:: image_access_to_tokens ( self . access ) ;
403
417
404
418
tokens. append_all ( quote:: quote! {
405
419
#crate_root:: image:: Image <
@@ -411,6 +425,7 @@ impl quote::ToTokens for ImageType {
411
425
{ #crate_root:: image:: #sampled as u32 } ,
412
426
{ #crate_root:: image:: #format as u32 } ,
413
427
{ #components as u32 } ,
428
+ #crate_root:: image:: __private:: #access
414
429
>
415
430
} ) ;
416
431
}
@@ -420,6 +435,20 @@ mod params {
420
435
use super :: * ;
421
436
use proc_macro2:: TokenStream ;
422
437
438
+ pub fn image_access_from_str ( s : & str ) -> Result < AccessQualifier , & ' static str > {
439
+ Ok ( match s {
440
+ "readonly" => AccessQualifier :: ReadOnly ,
441
+ "writeonly" => AccessQualifier :: WriteOnly ,
442
+ "readwrite" => AccessQualifier :: ReadWrite ,
443
+ _ => {
444
+ return Err (
445
+ "Unknown specified image access. Must be `readonly`, `writeonly`, \
446
+ `readwrite`, or must be omitted.",
447
+ ) ;
448
+ }
449
+ } )
450
+ }
451
+
423
452
pub fn image_format_from_str ( s : & str ) -> Result < ImageFormat , & ' static str > {
424
453
Ok ( match s {
425
454
"rgba32f" => ImageFormat :: Rgba32f ,
@@ -544,6 +573,15 @@ mod params {
544
573
}
545
574
}
546
575
576
+ pub fn image_access_to_tokens ( access : Option < AccessQualifier > ) -> proc_macro2:: TokenStream {
577
+ match access {
578
+ Some ( AccessQualifier :: ReadOnly ) => quote ! ( ImageAccessReadOnly ) ,
579
+ Some ( AccessQualifier :: WriteOnly ) => quote ! ( ImageAccessWriteOnly ) ,
580
+ Some ( AccessQualifier :: ReadWrite ) => quote ! ( ImageAccessReadWrite ) ,
581
+ None => quote ! ( ImageAccessUnknown ) ,
582
+ }
583
+ }
584
+
547
585
pub fn image_format_to_tokens ( format : & ImageFormat ) -> proc_macro2:: TokenStream {
548
586
let variant = {
549
587
let variant = match format {
0 commit comments