Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StorageFormat::Bgra8Unorm #2542

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 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,13 @@ 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
15 changes: 15 additions & 0 deletions src/back/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,21 @@ impl<'w> BlockContext<'w> {

let write = Store { image_id, value_id };

match *self.fun_info[image].ty.inner_with(&self.ir_module.types) {
crate::TypeInner::Image {
class:
crate::ImageClass::Storage {
format: crate::StorageFormat::Bgra8Unorm,
..
},
..
} => self.writer.require_any(
"Bgra8Unorm storage write",
&[spirv::Capability::StorageImageWriteWithoutFormat],
)?,
_ => {}
}

match self.writer.bounds_check_policies.image_store {
crate::proc::BoundsCheckPolicy::Restrict => {
let (coords, _, _) =
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,
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
Sf::Rgb10a2Uint => Self::Rgb10a2ui,
Sf::Rgb10a2Unorm => Self::Rgb10A2,
Sf::Rg11b10Float => Self::R11fG11fB10f,
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