@@ -15,6 +15,40 @@ use crate::{arena::Handle, FastHashMap, FastHashSet};
15
15
pub type EntryPointIndex = u16 ;
16
16
const SEPARATOR : char = '_' ;
17
17
18
+ /// A component of a lowered external texture.
19
+ ///
20
+ /// Whereas the WGSL backend implements [`ImageClass::External`]
21
+ /// images directly, most other Naga backends lower them to a
22
+ /// collection of ordinary textures that represent individual planes
23
+ /// (as received from a video decoder, perhaps), together with a
24
+ /// struct of parameters saying how they should be cropped, sampled,
25
+ /// and color-converted.
26
+ ///
27
+ /// This lowering means that individual globals and function
28
+ /// parameters in Naga IR must be split out by the backends into
29
+ /// collections of globals and parameters of simpler types.
30
+ ///
31
+ /// A value of this enum serves as a name key for one specific
32
+ /// component in the lowered representation of an external texture.
33
+ /// That is, these keys are for variables/parameters that do not exist
34
+ /// in the Naga IR, only in its lowered form.
35
+ ///
36
+ /// [`ImageClass::External`]: crate::ir::ImageClass::External
37
+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
38
+ pub enum ExternalTextureNameKey {
39
+ Plane ( usize ) ,
40
+ Params ,
41
+ }
42
+
43
+ impl ExternalTextureNameKey {
44
+ const ALL : & [ ( & str , ExternalTextureNameKey ) ] = & [
45
+ ( "_plane0" , ExternalTextureNameKey :: Plane ( 0 ) ) ,
46
+ ( "_plane1" , ExternalTextureNameKey :: Plane ( 1 ) ) ,
47
+ ( "_plane2" , ExternalTextureNameKey :: Plane ( 2 ) ) ,
48
+ ( "_params" , ExternalTextureNameKey :: Params ) ,
49
+ ] ;
50
+ }
51
+
18
52
#[ derive( Debug , Eq , Hash , PartialEq ) ]
19
53
pub enum NameKey {
20
54
Constant ( Handle < crate :: Constant > ) ,
@@ -37,6 +71,17 @@ pub enum NameKey {
37
71
38
72
/// Entry point version of `FunctionOobLocal`.
39
73
EntryPointOobLocal ( EntryPointIndex , Handle < crate :: Type > ) ,
74
+
75
+ /// A global variable holding a component of a lowered external texture.
76
+ ///
77
+ /// See [`ExternalTextureNameKey`] for details.
78
+ ExternalTextureGlobalVariable ( Handle < crate :: GlobalVariable > , ExternalTextureNameKey ) ,
79
+
80
+ /// A function argument holding a component of a lowered external
81
+ /// texture.
82
+ ///
83
+ /// See [`ExternalTextureNameKey`] for details.
84
+ ExternalTextureFunctionArgument ( Handle < crate :: Function > , u32 , ExternalTextureNameKey ) ,
40
85
}
41
86
42
87
/// This processor assigns names to all the things in a module
@@ -272,6 +317,27 @@ impl Namer {
272
317
for ( index, arg) in fun. arguments . iter ( ) . enumerate ( ) {
273
318
let name = self . call_or ( & arg. name , "param" ) ;
274
319
output. insert ( NameKey :: FunctionArgument ( fun_handle, index as u32 ) , name) ;
320
+
321
+ if matches ! (
322
+ module. types[ arg. ty] . inner,
323
+ crate :: TypeInner :: Image {
324
+ class: crate :: ImageClass :: External ,
325
+ ..
326
+ }
327
+ ) {
328
+ let base = arg. name . as_deref ( ) . unwrap_or ( "param" ) ;
329
+ for & ( suffix, ext_key) in ExternalTextureNameKey :: ALL {
330
+ let name = self . call ( & format ! ( "{base}_{suffix}" ) ) ;
331
+ output. insert (
332
+ NameKey :: ExternalTextureFunctionArgument (
333
+ fun_handle,
334
+ index as u32 ,
335
+ ext_key,
336
+ ) ,
337
+ name,
338
+ ) ;
339
+ }
340
+ }
275
341
}
276
342
for ( handle, var) in fun. local_variables . iter ( ) {
277
343
let name = self . call_or ( & var. name , "local" ) ;
@@ -282,6 +348,23 @@ impl Namer {
282
348
for ( handle, var) in module. global_variables . iter ( ) {
283
349
let name = self . call_or ( & var. name , "global" ) ;
284
350
output. insert ( NameKey :: GlobalVariable ( handle) , name) ;
351
+
352
+ if matches ! (
353
+ module. types[ var. ty] . inner,
354
+ crate :: TypeInner :: Image {
355
+ class: crate :: ImageClass :: External ,
356
+ ..
357
+ }
358
+ ) {
359
+ let base = var. name . as_deref ( ) . unwrap_or ( "global" ) ;
360
+ for & ( suffix, ext_key) in ExternalTextureNameKey :: ALL {
361
+ let name = self . call ( & format ! ( "{base}_{suffix}" ) ) ;
362
+ output. insert (
363
+ NameKey :: ExternalTextureGlobalVariable ( handle, ext_key) ,
364
+ name,
365
+ ) ;
366
+ }
367
+ }
285
368
}
286
369
287
370
for ( handle, constant) in module. constants . iter ( ) {
0 commit comments