Skip to content
Open
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
117 changes: 117 additions & 0 deletions wgpu-types/src/texture/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,123 @@ impl TextureFormat {
}
}

/// Provides texture srgb view formats with static lifetime for `TextureDescriptor.view_formats`.
/// Returns the srgb view formats if the format has an srgb variant, otherwise returns an empty slice.
///
/// The return result covers all the results of [`TextureFormat::add_srgb_suffix`].
pub fn srgb_view_formats(&self) -> &'static [TextureFormat] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just get a test to make sure this matches add_srgb_suffix

match self {
TextureFormat::Rgba8Unorm => &[TextureFormat::Rgba8UnormSrgb],
TextureFormat::Bgra8Unorm => &[TextureFormat::Bgra8UnormSrgb],
TextureFormat::Bc1RgbaUnorm => &[TextureFormat::Bc1RgbaUnormSrgb],
TextureFormat::Bc2RgbaUnorm => &[TextureFormat::Bc2RgbaUnormSrgb],
TextureFormat::Bc3RgbaUnorm => &[TextureFormat::Bc3RgbaUnormSrgb],
TextureFormat::Bc7RgbaUnorm => &[TextureFormat::Bc7RgbaUnormSrgb],
TextureFormat::Etc2Rgb8Unorm => &[TextureFormat::Etc2Rgb8UnormSrgb],
TextureFormat::Etc2Rgb8A1Unorm => &[TextureFormat::Etc2Rgb8A1UnormSrgb],
TextureFormat::Etc2Rgba8Unorm => &[TextureFormat::Etc2Rgba8UnormSrgb],
TextureFormat::Astc {
block: AstcBlock::B4x4,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B4x4,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B5x4,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B5x4,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B5x5,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B5x5,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B6x5,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B6x5,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B6x6,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B6x6,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B8x5,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B8x5,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B8x6,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B8x6,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B8x8,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B8x8,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B10x5,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B10x5,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B10x6,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B10x6,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B10x8,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B10x8,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B10x10,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B10x10,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B12x10,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B12x10,
channel: AstcChannel::UnormSrgb,
}],
TextureFormat::Astc {
block: AstcBlock::B12x12,
channel: AstcChannel::Unorm,
} => &[TextureFormat::Astc {
block: AstcBlock::B12x12,
channel: AstcChannel::UnormSrgb,
}],
_ => &[],
}
}

/// Returns `true` for srgb formats.
#[must_use]
pub fn is_srgb(&self) -> bool {
Expand Down