@@ -34,6 +34,7 @@ pub struct ImageType {
3434 sampled : Sampled ,
3535 sampled_type : SampledType ,
3636 components : u32 ,
37+ access : Option < AccessQualifier > ,
3738}
3839
3940impl Parse for ImageType {
@@ -47,6 +48,7 @@ impl Parse for ImageType {
4748 let mut sampled: Option < Sampled > = None ;
4849 let mut crate_root = None ;
4950 let mut components = None ;
51+ let mut access = None ;
5052
5153 let starting_span = input. span ( ) ;
5254
@@ -122,6 +124,16 @@ impl Parse for ImageType {
122124 . map( syn:: LitBool :: value)
123125 . map_or( ImageDepth :: True , From :: from)
124126 ) ;
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) ;
125137 } else if ident == "format" {
126138 let value = peek_and_eat_value ! ( syn:: Ident ) ;
127139
@@ -377,6 +389,7 @@ impl Parse for ImageType {
377389 sampled,
378390 sampled_type,
379391 components,
392+ access,
380393 } )
381394 }
382395}
@@ -400,6 +413,7 @@ impl quote::ToTokens for ImageType {
400413 let sampled = params:: sampled_to_tokens ( & self . sampled ) ;
401414 let sampled_type = & self . sampled_type ;
402415 let components = self . components ;
416+ let access = params:: image_access_to_tokens ( self . access ) ;
403417
404418 tokens. append_all ( quote:: quote! {
405419 #crate_root:: image:: Image <
@@ -411,6 +425,7 @@ impl quote::ToTokens for ImageType {
411425 { #crate_root:: image:: #sampled as u32 } ,
412426 { #crate_root:: image:: #format as u32 } ,
413427 { #components as u32 } ,
428+ #crate_root:: image:: __private:: #access
414429 >
415430 } ) ;
416431 }
@@ -420,6 +435,20 @@ mod params {
420435 use super :: * ;
421436 use proc_macro2:: TokenStream ;
422437
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+
423452 pub fn image_format_from_str ( s : & str ) -> Result < ImageFormat , & ' static str > {
424453 Ok ( match s {
425454 "rgba32f" => ImageFormat :: Rgba32f ,
@@ -544,6 +573,15 @@ mod params {
544573 }
545574 }
546575
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+
547585 pub fn image_format_to_tokens ( format : & ImageFormat ) -> proc_macro2:: TokenStream {
548586 let variant = {
549587 let variant = match format {
0 commit comments