Skip to content

Commit 8ff93cd

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 f652a3c commit 8ff93cd

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

naga/src/back/wgsl/writer.rs

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

442-
let dim_str = image_dimension_str(dim);
442+
let dim_str = dim.to_wgsl();
443443
let arrayed_str = if arrayed { "_array" } else { "" };
444444
let (class_str, multisampled_str, format_str, storage_str) = match class {
445445
Ic::Sampled { kind, multi } => (
@@ -1877,17 +1877,6 @@ impl<W: Write> Writer<W> {
18771877
}
18781878
}
18791879

1880-
const fn image_dimension_str(dim: crate::ImageDimension) -> &'static str {
1881-
use crate::ImageDimension as IDim;
1882-
1883-
match dim {
1884-
IDim::D1 => "1d",
1885-
IDim::D2 => "2d",
1886-
IDim::D3 => "3d",
1887-
IDim::Cube => "cube",
1888-
}
1889-
}
1890-
18911880
const fn address_space_str(
18921881
space: crate::AddressSpace,
18931882
) -> (Option<&'static str>, Option<&'static str>) {

naga/src/common/wgsl.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,16 @@ impl TryToWgsl for crate::Scalar {
324324
})
325325
}
326326
}
327+
328+
impl ToWgsl for crate::ImageDimension {
329+
fn to_wgsl(self) -> &'static str {
330+
use crate::ImageDimension as IDim;
331+
332+
match self {
333+
IDim::D1 => "1d",
334+
IDim::D2 => "2d",
335+
IDim::D3 => "3d",
336+
IDim::Cube => "cube",
337+
}
338+
}
339+
}

0 commit comments

Comments
 (0)