File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -109,13 +109,28 @@ impl<W: Write> Writer<W> {
109
109
self . required_polyfills . clear ( ) ;
110
110
}
111
111
112
- fn is_builtin_wgsl_struct ( & self , module : & Module , handle : Handle < crate :: Type > ) -> bool {
112
+ /// Determine if `ty` is the Naga IR presentation of a WGSL builtin type.
113
+ ///
114
+ /// Return true if `ty` refers to the Naga IR form of a WGSL builtin type
115
+ /// like `__atomic_compare_exchange_result`.
116
+ ///
117
+ /// Even though the module may use the type, the WGSL backend should avoid
118
+ /// emitting a definition for it, since it is [predeclared] in WGSL.
119
+ ///
120
+ /// This also covers types like [`NagaExternalTextureParams`], which other
121
+ /// backends use to lower WGSL constructs like external textures to their
122
+ /// implementations. WGSL can express these directly, so the types need not
123
+ /// be emitted.
124
+ ///
125
+ /// [predeclared]: https://www.w3.org/TR/WGSL/#predeclared
126
+ /// [`NagaExternalTextureParams`]: crate::ir::SpecialTypes::external_texture_params
127
+ fn is_builtin_wgsl_struct ( & self , module : & Module , ty : Handle < crate :: Type > ) -> bool {
113
128
module
114
129
. special_types
115
130
. predeclared_types
116
131
. values ( )
117
- . any ( |t| * t == handle )
118
- || Some ( handle ) == module. special_types . external_texture_params
132
+ . any ( |t| * t == ty )
133
+ || Some ( ty ) == module. special_types . external_texture_params
119
134
}
120
135
121
136
pub fn write ( & mut self , module : & Module , info : & valid:: ModuleInfo ) -> BackendResult {
Original file line number Diff line number Diff line change @@ -276,6 +276,9 @@ impl crate::Module {
276
276
handle
277
277
}
278
278
279
+ /// Generate [`SpecialTypes::external_texture_params`].
280
+ ///
281
+ /// [`SpecialTypes::external_texture_params`]: crate::ir::SpecialTypes::external_texture_params
279
282
pub fn generate_external_texture_params_type ( & mut self ) -> Handle < crate :: Type > {
280
283
if let Some ( handle) = self . special_types . external_texture_params {
281
284
return handle;
Original file line number Diff line number Diff line change @@ -2349,6 +2349,18 @@ pub struct SpecialTypes {
2349
2349
/// Struct containing parameters required by some backends to emit code for
2350
2350
/// [`ImageClass::External`] textures.
2351
2351
///
2352
+ /// In WGSL, this type would be:
2353
+ ///
2354
+ /// ```ignore
2355
+ /// struct NagaExternalTextureParams { // align size offset
2356
+ /// yuv_conversion_matrix: mat4x4<f32>, // 16 64 0
2357
+ /// sample_transform: mat3x2<f32>, // 8 24 64
2358
+ /// load_transform: mat3x2<f32>, // 8 24 88
2359
+ /// size: vec2<u32>, // 8 8 112
2360
+ /// num_planes: u32, // 4 4 120
2361
+ /// } // whole struct: 16 128
2362
+ /// ```
2363
+ ///
2352
2364
/// Call [`Module::generate_external_texture_params_type`] to populate this
2353
2365
/// if needed and return the handle.
2354
2366
pub external_texture_params : Option < Handle < Type > > ,
You can’t perform that action at this time.
0 commit comments