Skip to content

Commit

Permalink
Add StorageFormat::Bgra8Unorm
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Oct 9, 2023
1 parent 4d6e000 commit 328d047
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl<'a, W: Write> Writer<'a, W> {
write!(self.out, "binding = {binding}")?;
}
if let Some((format, _)) = storage_format_access {
let format_str = glsl_storage_format(format);
let format_str = glsl_storage_format(format)?;
let separator = match layout_binding {
Some(_) => ",",
None => "",
Expand Down Expand Up @@ -1491,7 +1491,7 @@ impl<'a, W: Write> Writer<'a, W> {
..
} = this.module.types[arg.ty].inner
{
write!(this.out, "layout({}) ", glsl_storage_format(format))?;
write!(this.out, "layout({}) ", glsl_storage_format(format)?)?;
}

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

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

match format {
Ok(match format {
Sf::R8Unorm => "r8",
Sf::R8Snorm => "r8_snorm",
Sf::R8Uint => "r8ui",
Expand Down Expand Up @@ -4256,7 +4256,11 @@ const fn glsl_storage_format(format: crate::StorageFormat) -> &'static str {
Sf::Rg16Snorm => "rg16_snorm",
Sf::Rgba16Unorm => "rgba16",
Sf::Rgba16Snorm => "rgba16_snorm",
}

Sf::Bgra8Unorm => {
return Err(Error::Custom("Support format BGRA8 is not implemented".into()))
}
})
}

fn is_value_init_supported(module: &crate::Module, ty: Handle<crate::Type>) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion src/back/hlsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ impl crate::StorageFormat {
Self::Rg11b10Float => "float3",

Self::Rgba16Float | Self::R32Float | Self::Rg32Float | Self::Rgba32Float => "float4",
Self::Rgba8Unorm | Self::Rgba16Unorm | Self::Rgb10a2Unorm => "unorm float4",
Self::Rgba8Unorm | Self::Bgra8Unorm | Self::Rgba16Unorm | Self::Rgb10a2Unorm => {
"unorm float4"
}
Self::Rgba8Snorm | Self::Rgba16Snorm => "snorm float4",

Self::Rgba8Uint
Expand Down
1 change: 1 addition & 0 deletions src/back/spv/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ impl From<crate::StorageFormat> for spirv::ImageFormat {
Sf::Rgba8Snorm => Self::Rgba8Snorm,
Sf::Rgba8Uint => Self::Rgba8ui,
Sf::Rgba8Sint => Self::Rgba8i,
Sf::Bgra8Unorm => Self::Unknown,
Sf::Rgb10a2Uint => Self::Rgb10a2ui,
Sf::Rgb10a2Unorm => Self::Rgb10A2,
Sf::Rg11b10Float => Self::R11fG11fB10f,
Expand Down
5 changes: 4 additions & 1 deletion src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,10 @@ impl Writer {
"64-bit integer storage image format",
&[spirv::Capability::Int64ImageEXT],
),
If::Unknown
If::Unknown => self.require_any(
"Unknown storage image format",
&[spirv::Capability::StorageImageWriteWithoutFormat],
),
| If::Rgba32f
| If::Rgba16f
| If::R32f
Expand Down
1 change: 1 addition & 0 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@ const fn storage_format_str(format: crate::StorageFormat) -> &'static str {
Sf::Rgba8Snorm => "rgba8snorm",
Sf::Rgba8Uint => "rgba8uint",
Sf::Rgba8Sint => "rgba8sint",
Sf::Bgra8Unorm => "bgra8unorm",
Sf::Rgb10a2Uint => "rgb10a2uint",
Sf::Rgb10a2Unorm => "rgb10a2unorm",
Sf::Rg11b10Float => "rg11b10float",
Expand Down
1 change: 1 addition & 0 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl crate::StorageFormat {
Sf::Rgba8Snorm => "rgba8snorm",
Sf::Rgba8Uint => "rgba8uint",
Sf::Rgba8Sint => "rgba8sint",
Sf::Bgra8Unorm => "bgra8unorm",
Sf::Rgb10a2Uint => "rgb10a2uint",
Sf::Rgb10a2Unorm => "rgb10a2unorm",
Sf::Rg11b10Float => "rg11b10float",
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ pub enum StorageFormat {
Rgba8Snorm,
Rgba8Uint,
Rgba8Sint,
Bgra8Unorm,

// Packed 32-bit formats
Rgb10a2Uint,
Expand Down
1 change: 1 addition & 0 deletions src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl From<super::StorageFormat> for super::ScalarKind {
Sf::Rgba8Snorm => Sk::Float,
Sf::Rgba8Uint => Sk::Uint,
Sf::Rgba8Sint => Sk::Sint,
Sf::Bgra8Unorm => Sk::Float,
Sf::Rgb10a2Uint => Sk::Uint,
Sf::Rgb10a2Unorm => Sk::Float,
Sf::Rg11b10Float => Sk::Float,
Expand Down

0 comments on commit 328d047

Please sign in to comment.