Skip to content

Commit 7e2a477

Browse files
committed
[naga] Implement ToWgsl for ImageDimension, and use as needed.
Replace `naga::back::wgsl::writer::image_dimension_str` with a `ToWgsl` implementation for `ImageDimension` in `common::wgsl`. Use this where needed in the WGSL backend.
1 parent 0e53104 commit 7e2a477

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

naga/src/back/wgsl/writer.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<W: Write> Writer<W> {
470470
// More about texture types: https://gpuweb.github.io/gpuweb/wgsl/#sampled-texture-type
471471
use crate::ImageClass as Ic;
472472

473-
let dim_str = image_dimension_str(dim);
473+
let dim_str = dim.to_wgsl_if_implemented()?;
474474
let arrayed_str = if arrayed { "_array" } else { "" };
475475
let (class_str, multisampled_str, format_str, storage_str) = match class {
476476
Ic::Sampled { kind, multi } => (
@@ -1904,17 +1904,6 @@ impl<W: Write> Writer<W> {
19041904
}
19051905
}
19061906

1907-
const fn image_dimension_str(dim: crate::ImageDimension) -> &'static str {
1908-
use crate::ImageDimension as IDim;
1909-
1910-
match dim {
1911-
IDim::D1 => "1d",
1912-
IDim::D2 => "2d",
1913-
IDim::D3 => "3d",
1914-
IDim::Cube => "cube",
1915-
}
1916-
}
1917-
19181907
const fn address_space_str(
19191908
space: crate::AddressSpace,
19201909
) -> (Option<&'static str>, Option<&'static str>) {

naga/src/common/wgsl.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,18 @@ impl ToWgsl for crate::Scalar {
306306
})
307307
}
308308
}
309+
310+
impl ToWgsl for crate::ImageDimension {
311+
const DESCRIPTION: &'static str = "image dimension";
312+
313+
fn to_wgsl(self) -> Option<&'static str> {
314+
use crate::ImageDimension as IDim;
315+
316+
Some(match self {
317+
IDim::D1 => "1d",
318+
IDim::D2 => "2d",
319+
IDim::D3 => "3d",
320+
IDim::Cube => "cube",
321+
})
322+
}
323+
}

0 commit comments

Comments
 (0)