Skip to content

Commit 7741fba

Browse files
committed
fixup! [naga] Generate special type for external texture params buffer
1 parent 2084c01 commit 7741fba

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

naga/src/back/wgsl/writer.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,28 @@ impl<W: Write> Writer<W> {
109109
self.required_polyfills.clear();
110110
}
111111

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 {
113128
module
114129
.special_types
115130
.predeclared_types
116131
.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
119134
}
120135

121136
pub fn write(&mut self, module: &Module, info: &valid::ModuleInfo) -> BackendResult {

naga/src/front/type_gen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ impl crate::Module {
276276
handle
277277
}
278278

279+
/// Generate [`SpecialTypes::external_texture_params`].
280+
///
281+
/// [`SpecialTypes::external_texture_params`]: crate::ir::SpecialTypes::external_texture_params
279282
pub fn generate_external_texture_params_type(&mut self) -> Handle<crate::Type> {
280283
if let Some(handle) = self.special_types.external_texture_params {
281284
return handle;

naga/src/ir/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,18 @@ pub struct SpecialTypes {
23492349
/// Struct containing parameters required by some backends to emit code for
23502350
/// [`ImageClass::External`] textures.
23512351
///
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+
///
23522364
/// Call [`Module::generate_external_texture_params_type`] to populate this
23532365
/// if needed and return the handle.
23542366
pub external_texture_params: Option<Handle<Type>>,

0 commit comments

Comments
 (0)