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

Commit

Permalink
Support 16-bit unorm/snorm formats
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia committed Jan 17, 2023
1 parent 5b4e946 commit 811d2a7
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,12 @@ const fn glsl_storage_format(format: crate::StorageFormat) -> &'static str {
Sf::Rgba32Uint => "rgba32ui",
Sf::Rgba32Sint => "rgba32i",
Sf::Rgba32Float => "rgba32f",
Sf::R16Unorm => "r16",
Sf::R16Snorm => "r16_snorm",
Sf::Rg16Unorm => "rg16",
Sf::Rg16Snorm => "rg16_snorm",
Sf::Rgba16Unorm => "rgba16",
Sf::Rgba16Snorm => "rgba16_snorm",
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/back/hlsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ impl crate::StorageFormat {
pub(super) const fn to_hlsl_str(self) -> &'static str {
match self {
Self::R16Float => "float",
Self::R8Unorm => "unorm float",
Self::R8Snorm => "snorm float",
Self::R8Unorm | Self::R16Unorm => "unorm float",
Self::R8Snorm | Self::R16Snorm => "snorm float",
Self::R8Uint | Self::R16Uint => "uint",
Self::R8Sint | Self::R16Sint => "int",

Self::Rg16Float => "float2",
Self::Rg8Unorm => "unorm float2",
Self::Rg8Snorm => "snorm float2",
Self::Rg8Unorm | Self::Rg16Unorm => "unorm float2",
Self::Rg8Snorm | Self::Rg16Snorm => "snorm float2",

Self::Rg8Sint | Self::Rg16Sint => "int2",
Self::Rg8Uint | Self::Rg16Uint => "uint2",

Self::Rg11b10Float => "float3",

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

Self::Rgba8Uint
| Self::Rgba16Uint
Expand Down
6 changes: 6 additions & 0 deletions src/back/spv/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,12 @@ impl From<crate::StorageFormat> for spirv::ImageFormat {
Sf::Rgba32Uint => Self::Rgba32ui,
Sf::Rgba32Sint => Self::Rgba32i,
Sf::Rgba32Float => Self::Rgba32f,
Sf::R16Unorm => Self::R16,
Sf::R16Snorm => Self::R16Snorm,
Sf::Rg16Unorm => Self::Rg16,
Sf::Rg16Snorm => Self::Rg16Snorm,
Sf::Rgba16Unorm => Self::Rgba16,
Sf::Rgba16Snorm => Self::Rgba16Snorm,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,12 @@ const fn storage_format_str(format: crate::StorageFormat) -> &'static str {
Sf::Rgba32Uint => "rgba32uint",
Sf::Rgba32Sint => "rgba32sint",
Sf::Rgba32Float => "rgba32float",
Sf::R16Unorm => "r16unorm",
Sf::R16Snorm => "r16snorm",
Sf::Rg16Unorm => "rg16unorm",
Sf::Rg16Snorm => "rg16snorm",
Sf::Rgba16Unorm => "rgba16unorm",
Sf::Rgba16Snorm => "rgba16snorm",
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/front/glsl/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,18 @@ fn map_image_format(word: &str) -> Option<crate::StorageFormat> {
"r11f_g11f_b10f" => Sf::Rg11b10Float,
"r32f" => Sf::R32Float,
"r16f" => Sf::R16Float,
"rgba16" => Sf::Rgba16Float,
"rgba16" => Sf::Rgba16Unorm,
"rgb10_a2" => Sf::Rgb10a2Unorm,
"rgba8" => Sf::Rgba8Unorm,
"rg16" => Sf::Rg16Float,
"rg16" => Sf::Rg16Unorm,
"rg8" => Sf::Rg8Unorm,
"r16" => Sf::R16Float,
"r16" => Sf::R16Unorm,
"r8" => Sf::R8Unorm,
"rgba16_snorm" => Sf::Rgba16Snorm,
"rgba8_snorm" => Sf::Rgba8Snorm,
"rg16_snorm" => Sf::Rg16Snorm,
"rg8_snorm" => Sf::Rg8Snorm,
"r16_snorm" => Sf::R16Snorm,
"r8_snorm" => Sf::R8Snorm,
// int-image-format-qualifier:
"rgba32i" => Sf::Rgba32Sint,
Expand All @@ -416,9 +419,6 @@ fn map_image_format(word: &str) -> Option<crate::StorageFormat> {
"r16ui" => Sf::R16Uint,
"r8ui" => Sf::R8Uint,
// TODO: These next ones seem incorrect to me
// "rgba16_snorm" => Sf::Rgba16Float,
// "rg16_snorm" => Sf::Rg16Float,
// "r16_snorm" => Sf::R16Float,
// "rgb10_a2ui" => Sf::Rgb10a2Unorm,
_ => return None,
};
Expand Down
6 changes: 6 additions & 0 deletions src/front/wgsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub fn map_storage_format(word: &str, span: Span) -> Result<crate::StorageFormat
"r8snorm" => Sf::R8Snorm,
"r8uint" => Sf::R8Uint,
"r8sint" => Sf::R8Sint,
"r16unorm" => Sf::R16Unorm,
"r16snorm" => Sf::R16Snorm,
"r16uint" => Sf::R16Uint,
"r16sint" => Sf::R16Sint,
"r16float" => Sf::R16Float,
Expand All @@ -72,6 +74,8 @@ pub fn map_storage_format(word: &str, span: Span) -> Result<crate::StorageFormat
"r32uint" => Sf::R32Uint,
"r32sint" => Sf::R32Sint,
"r32float" => Sf::R32Float,
"rg16unorm" => Sf::Rg16Unorm,
"rg16snorm" => Sf::Rg16Snorm,
"rg16uint" => Sf::Rg16Uint,
"rg16sint" => Sf::Rg16Sint,
"rg16float" => Sf::Rg16Float,
Expand All @@ -84,6 +88,8 @@ pub fn map_storage_format(word: &str, span: Span) -> Result<crate::StorageFormat
"rg32uint" => Sf::Rg32Uint,
"rg32sint" => Sf::Rg32Sint,
"rg32float" => Sf::Rg32Float,
"rgba16unorm" => Sf::Rgba16Unorm,
"rgba16snorm" => Sf::Rgba16Snorm,
"rgba16uint" => Sf::Rgba16Uint,
"rgba16sint" => Sf::Rgba16Sint,
"rgba16float" => Sf::Rgba16Float,
Expand Down
6 changes: 6 additions & 0 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ impl crate::StorageFormat {
Sf::Rgba32Uint => "rgba32uint",
Sf::Rgba32Sint => "rgba32sint",
Sf::Rgba32Float => "rgba32float",
Sf::R16Unorm => "r16unorm",
Sf::R16Snorm => "r16snorm",
Sf::Rg16Unorm => "rg16unorm",
Sf::Rg16Snorm => "rg16snorm",
Sf::Rgba16Unorm => "rgba16unorm",
Sf::Rgba16Snorm => "rgba16snorm",
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ pub enum StorageFormat {
Rgba32Uint,
Rgba32Sint,
Rgba32Float,

// Normalized 16-bit per channel formats
R16Unorm,
R16Snorm,
Rg16Unorm,
Rg16Snorm,
Rgba16Unorm,
Rgba16Snorm,
}

/// Sub-class of the image type.
Expand Down
6 changes: 6 additions & 0 deletions src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl From<super::StorageFormat> for super::ScalarKind {
Sf::Rgba32Uint => Sk::Uint,
Sf::Rgba32Sint => Sk::Sint,
Sf::Rgba32Float => Sk::Float,
Sf::R16Unorm => Sk::Float,
Sf::R16Snorm => Sk::Float,
Sf::Rg16Unorm => Sk::Float,
Sf::Rg16Snorm => Sk::Float,
Sf::Rgba16Unorm => Sk::Float,
Sf::Rgba16Snorm => Sk::Float,
}
}
}
Expand Down

0 comments on commit 811d2a7

Please sign in to comment.