Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 7a0bc25

Browse files
committed
Add StorageFormat::Bgra8Unorm
1 parent 4d6e000 commit 7a0bc25

File tree

8 files changed

+34
-6
lines changed

8 files changed

+34
-6
lines changed

src/back/glsl/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl<'a, W: Write> Writer<'a, W> {
766766
write!(self.out, "binding = {binding}")?;
767767
}
768768
if let Some((format, _)) = storage_format_access {
769-
let format_str = glsl_storage_format(format);
769+
let format_str = glsl_storage_format(format)?;
770770
let separator = match layout_binding {
771771
Some(_) => ",",
772772
None => "",
@@ -1491,7 +1491,7 @@ impl<'a, W: Write> Writer<'a, W> {
14911491
..
14921492
} = this.module.types[arg.ty].inner
14931493
{
1494-
write!(this.out, "layout({}) ", glsl_storage_format(format))?;
1494+
write!(this.out, "layout({}) ", glsl_storage_format(format)?)?;
14951495
}
14961496

14971497
// write the type
@@ -4213,10 +4213,10 @@ const fn glsl_dimension(dim: crate::ImageDimension) -> &'static str {
42134213
}
42144214

42154215
/// Helper function that returns the glsl storage format string of [`StorageFormat`](crate::StorageFormat)
4216-
const fn glsl_storage_format(format: crate::StorageFormat) -> &'static str {
4216+
fn glsl_storage_format(format: crate::StorageFormat) -> Result<&'static str, Error> {
42174217
use crate::StorageFormat as Sf;
42184218

4219-
match format {
4219+
Ok(match format {
42204220
Sf::R8Unorm => "r8",
42214221
Sf::R8Snorm => "r8_snorm",
42224222
Sf::R8Uint => "r8ui",
@@ -4256,7 +4256,13 @@ const fn glsl_storage_format(format: crate::StorageFormat) -> &'static str {
42564256
Sf::Rg16Snorm => "rg16_snorm",
42574257
Sf::Rgba16Unorm => "rgba16",
42584258
Sf::Rgba16Snorm => "rgba16_snorm",
4259-
}
4259+
4260+
Sf::Bgra8Unorm => {
4261+
return Err(Error::Custom(
4262+
"Support format BGRA8 is not implemented".into(),
4263+
))
4264+
}
4265+
})
42604266
}
42614267

42624268
fn is_value_init_supported(module: &crate::Module, ty: Handle<crate::Type>) -> bool {

src/back/hlsl/conv.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ impl crate::StorageFormat {
122122
Self::Rg11b10Float => "float3",
123123

124124
Self::Rgba16Float | Self::R32Float | Self::Rg32Float | Self::Rgba32Float => "float4",
125-
Self::Rgba8Unorm | Self::Rgba16Unorm | Self::Rgb10a2Unorm => "unorm float4",
125+
Self::Rgba8Unorm | Self::Bgra8Unorm | Self::Rgba16Unorm | Self::Rgb10a2Unorm => {
126+
"unorm float4"
127+
}
126128
Self::Rgba8Snorm | Self::Rgba16Snorm => "snorm float4",
127129

128130
Self::Rgba8Uint

src/back/spv/image.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,21 @@ impl<'w> BlockContext<'w> {
11701170

11711171
let write = Store { image_id, value_id };
11721172

1173+
match *self.fun_info[image].ty.inner_with(&self.ir_module.types) {
1174+
crate::TypeInner::Image {
1175+
class:
1176+
crate::ImageClass::Storage {
1177+
format: crate::StorageFormat::Bgra8Unorm,
1178+
..
1179+
},
1180+
..
1181+
} => self.writer.require_any(
1182+
"Bgra8Unorm storage write",
1183+
&[spirv::Capability::StorageImageWriteWithoutFormat],
1184+
)?,
1185+
_ => {}
1186+
}
1187+
11731188
match self.writer.bounds_check_policies.image_store {
11741189
crate::proc::BoundsCheckPolicy::Restrict => {
11751190
let (coords, _, _) =

src/back/spv/instructions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ impl From<crate::StorageFormat> for spirv::ImageFormat {
10641064
Sf::Rgba8Snorm => Self::Rgba8Snorm,
10651065
Sf::Rgba8Uint => Self::Rgba8ui,
10661066
Sf::Rgba8Sint => Self::Rgba8i,
1067+
Sf::Bgra8Unorm => Self::Unknown,
10671068
Sf::Rgb10a2Uint => Self::Rgb10a2ui,
10681069
Sf::Rgb10a2Unorm => Self::Rgb10A2,
10691070
Sf::Rg11b10Float => Self::R11fG11fB10f,

src/back/wgsl/writer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ const fn storage_format_str(format: crate::StorageFormat) -> &'static str {
18291829
Sf::Rgba8Snorm => "rgba8snorm",
18301830
Sf::Rgba8Uint => "rgba8uint",
18311831
Sf::Rgba8Sint => "rgba8sint",
1832+
Sf::Bgra8Unorm => "bgra8unorm",
18321833
Sf::Rgb10a2Uint => "rgb10a2uint",
18331834
Sf::Rgb10a2Unorm => "rgb10a2unorm",
18341835
Sf::Rg11b10Float => "rg11b10float",

src/front/wgsl/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl crate::StorageFormat {
7171
Sf::Rgba8Snorm => "rgba8snorm",
7272
Sf::Rgba8Uint => "rgba8uint",
7373
Sf::Rgba8Sint => "rgba8sint",
74+
Sf::Bgra8Unorm => "bgra8unorm",
7475
Sf::Rgb10a2Uint => "rgb10a2uint",
7576
Sf::Rgb10a2Unorm => "rgb10a2unorm",
7677
Sf::Rg11b10Float => "rg11b10float",

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ pub enum StorageFormat {
599599
Rgba8Snorm,
600600
Rgba8Uint,
601601
Rgba8Sint,
602+
Bgra8Unorm,
602603

603604
// Packed 32-bit formats
604605
Rgb10a2Uint,

src/proc/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl From<super::StorageFormat> for super::ScalarKind {
3939
Sf::Rgba8Snorm => Sk::Float,
4040
Sf::Rgba8Uint => Sk::Uint,
4141
Sf::Rgba8Sint => Sk::Sint,
42+
Sf::Bgra8Unorm => Sk::Float,
4243
Sf::Rgb10a2Uint => Sk::Uint,
4344
Sf::Rgb10a2Unorm => Sk::Float,
4445
Sf::Rg11b10Float => Sk::Float,

0 commit comments

Comments
 (0)