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

Updating TextureFormat matching specs #2954

Merged
merged 15 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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
7 changes: 4 additions & 3 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ pub(crate) fn validate_texture_copy_range(
let extent = extent_virtual.physical_size(desc.format);

match desc.format {
wgt::TextureFormat::Depth32Float
//wgt::TextureFormat::Stencil8 |
wgt::TextureFormat::Depth16Unorm
| wgt::TextureFormat::Depth32Float
| wgt::TextureFormat::Depth32FloatStencil8
| wgt::TextureFormat::Depth24Plus
| wgt::TextureFormat::Depth24PlusStencil8
| wgt::TextureFormat::Depth24UnormStencil8 => {
| wgt::TextureFormat::Depth24PlusStencil8 => {
if *copy_size != extent {
return Err(TransferError::InvalidDepthTextureExtent);
}
Expand Down
7 changes: 4 additions & 3 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
use wgt::TextureFormat as Tf;
match format {
Tf::Depth32Float
//Tf::Stencil8 |
Tf::Depth16Unorm
| Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8
| Tf::Depth24UnormStencil8 => false,
| Tf::Depth24PlusStencil8 => false,
_ => true,
}
}
Expand Down
7 changes: 4 additions & 3 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,12 @@ impl NumericType {
(NumericDimension::Vector(Vs::Quad), Sk::Sint)
}
Tf::Rg11b10Float => (NumericDimension::Vector(Vs::Tri), Sk::Float),
Tf::Depth32Float
//Tf::Stencil8 |
Tf::Depth16Unorm
| Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8
| Tf::Depth24UnormStencil8 => {
| Tf::Depth24PlusStencil8 => {
panic!("Unexpected depth format")
}
Tf::Rgb9e5Ufloat => (NumericDimension::Vector(Vs::Tri), Sk::Float),
Expand Down
24 changes: 15 additions & 9 deletions wgpu-hal/src/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
Tf::Bgra8Unorm => DXGI_FORMAT_B8G8R8A8_UNORM,
Tf::Rgba8Uint => DXGI_FORMAT_R8G8B8A8_UINT,
Tf::Rgba8Sint => DXGI_FORMAT_R8G8B8A8_SINT,
Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
Tf::Rgb10a2Unorm => DXGI_FORMAT_R10G10B10A2_UNORM,
Tf::Rg11b10Float => DXGI_FORMAT_R11G11B10_FLOAT,
Tf::Rg32Uint => DXGI_FORMAT_R32G32_UINT,
Expand All @@ -46,11 +47,12 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
Tf::Rgba32Uint => DXGI_FORMAT_R32G32B32A32_UINT,
Tf::Rgba32Sint => DXGI_FORMAT_R32G32B32A32_SINT,
Tf::Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT,
//Tf::Stencil8 => DXGI_FORMAT_R8_UNORM,
Tf::Depth16Unorm => DXGI_FORMAT_D16_UNORM,
Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Depth24PlusStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Depth32Float => DXGI_FORMAT_D32_FLOAT,
Tf::Depth32FloatStencil8 => DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
Tf::Bc1RgbaUnorm => DXGI_FORMAT_BC1_UNORM,
Tf::Bc1RgbaUnormSrgb => DXGI_FORMAT_BC1_UNORM_SRGB,
Tf::Bc2RgbaUnorm => DXGI_FORMAT_BC2_UNORM,
Expand Down Expand Up @@ -103,13 +105,15 @@ pub fn map_texture_format_nosrgb(format: wgt::TextureFormat) -> dxgiformat::DXGI
//TODO: stencil views?
pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
match format {
//wgt::TextureFormat::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM,
wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM,
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_FLOAT,
wgt::TextureFormat::Depth32FloatStencil8 => {
dxgiformat::DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS
}
wgt::TextureFormat::Depth24Plus
| wgt::TextureFormat::Depth24PlusStencil8
| wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS
}
_ => {
assert_eq!(
crate::FormatAspects::from(format),
Expand All @@ -122,11 +126,13 @@ pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXG

pub fn map_texture_format_depth_typeless(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
match format {
//wgt::TextureFormat::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM,
wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM,
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS,
wgt::TextureFormat::Depth32FloatStencil8 => dxgiformat::DXGI_FORMAT_R32G8X24_TYPELESS,
wgt::TextureFormat::Depth24Plus
| wgt::TextureFormat::Depth24PlusStencil8
| wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24G8_TYPELESS,
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
dxgiformat::DXGI_FORMAT_R24G8_TYPELESS
}
_ => unreachable!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl super::Adapter {

let mut features = wgt::Features::empty()
| wgt::Features::DEPTH_CLIP_CONTROL
| wgt::Features::DEPTH24UNORM_STENCIL8
| wgt::Features::DEPTH24PLUS_STENCIL8
| wgt::Features::DEPTH32FLOAT_STENCIL8
| wgt::Features::INDIRECT_FIRST_INSTANCE
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS
Expand Down
7 changes: 4 additions & 3 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,12 @@ impl crate::Adapter<super::Api> for super::Adapter {
Tf::Rgba32Uint => renderable | storage,
Tf::Rgba32Sint => renderable | storage,
Tf::Rgba32Float => unfilterable | storage | float_renderable,
Tf::Depth32Float
//Tf::Stencil8 |
Tf::Depth16Unorm
| Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8
| Tf::Depth24UnormStencil8 => depth,
| Tf::Depth24PlusStencil8 => depth,
Tf::Rgb9e5Ufloat => filterable,
Tf::Bc1RgbaUnorm
| Tf::Bc1RgbaUnormSrgb
Expand Down
8 changes: 7 additions & 1 deletion wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ impl super::AdapterShared {
Tf::Rgba32Uint => (glow::RGBA32UI, glow::RGBA_INTEGER, glow::UNSIGNED_INT),
Tf::Rgba32Sint => (glow::RGBA32I, glow::RGBA_INTEGER, glow::INT),
Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT),
//Tf::Stencil8 => (glow::R8UI, glow::STENCIL_COMPONENTS, glow::UNSIGNED_BYTE),
Tf::Depth16Unorm => (
glow::DEPTH_COMPONENT16,
glow::DEPTH_COMPONENT,
glow::UNSIGNED_SHORT,
),
Tf::Depth32Float => (glow::DEPTH_COMPONENT32F, glow::DEPTH_COMPONENT, glow::FLOAT),
Tf::Depth32FloatStencil8 => {
(glow::DEPTH32F_STENCIL8, glow::DEPTH_COMPONENT, glow::FLOAT)
Expand All @@ -65,7 +71,7 @@ impl super::AdapterShared {
glow::DEPTH_COMPONENT,
glow::UNSIGNED_NORMALIZED,
),
Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => (
Tf::Depth24PlusStencil8 => (
glow::DEPTH24_STENCIL8,
glow::DEPTH_COMPONENT,
glow::UNSIGNED_INT,
Expand Down
8 changes: 5 additions & 3 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,12 @@ impl From<wgt::TextureAspect> for FormatAspects {
impl From<wgt::TextureFormat> for FormatAspects {
fn from(format: wgt::TextureFormat) -> Self {
match format {
//wgt::TextureFormat::Stencil8 => Self::STENCIL,
wgt::TextureFormat::Depth16Unorm => Self::DEPTH,
wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth24Plus => Self::DEPTH,
wgt::TextureFormat::Depth32FloatStencil8
| wgt::TextureFormat::Depth24PlusStencil8
| wgt::TextureFormat::Depth24UnormStencil8 => Self::DEPTH | Self::STENCIL,
wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24PlusStencil8 => {
Self::DEPTH | Self::STENCIL
}
_ => Self::COLOR,
}
}
Expand Down
26 changes: 18 additions & 8 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ impl crate::Adapter<super::Api> for super::Adapter {
};
flags
}
/*Tf::Stencil8 => {
let mut flags = all_caps
| Tfc::DEPTH_STENCIL_ATTACHMENT
| Tfc::MULTISAMPLE
| msaa_resolve_apple3x_if;
flags
}*/
Tf::Depth16Unorm => {
let mut flags =
Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if;
if pc.format_depth16unorm {
flags |= Tfc::SAMPLED_LINEAR
}
flags
}
Tf::Depth32Float | Tf::Depth32FloatStencil8 => {
let mut flags =
Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if;
Expand All @@ -200,12 +215,6 @@ impl crate::Adapter<super::Api> for super::Adapter {
}
flags
}
Tf::Depth24UnormStencil8 => {
Tfc::DEPTH_STENCIL_ATTACHMENT
| Tfc::SAMPLED_LINEAR
| Tfc::MULTISAMPLE
| Tfc::MULTISAMPLE_RESOLVE
}
Tf::Rgb9e5Ufloat => {
if pc.msaa_apple3 {
all_caps
Expand Down Expand Up @@ -770,7 +779,7 @@ impl super::PrivateCapabilities {
features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc);

features.set(F::DEPTH_CLIP_CONTROL, self.supports_depth_clip_control);
features.set(F::DEPTH24UNORM_STENCIL8, self.format_depth24_stencil8);
features.set(F::DEPTH24PLUS_STENCIL8, self.format_depth24_stencil8);

features.set(
F::TEXTURE_BINDING_ARRAY
Expand Down Expand Up @@ -903,6 +912,8 @@ impl super::PrivateCapabilities {
Tf::Rgba32Uint => RGBA32Uint,
Tf::Rgba32Sint => RGBA32Sint,
Tf::Rgba32Float => RGBA32Float,
//Tf::Stencil8 => R8Unorm,
Tf::Depth16Unorm => Depth16Unorm,
Tf::Depth32Float => Depth32Float,
Tf::Depth32FloatStencil8 => Depth32Float_Stencil8,
Tf::Depth24Plus => {
Expand All @@ -919,7 +930,6 @@ impl super::PrivateCapabilities {
Depth32Float_Stencil8
}
}
Tf::Depth24UnormStencil8 => Depth24Unorm_Stencil8,
Tf::Rgb9e5Ufloat => RGB9E5Float,
Tf::Bc1RgbaUnorm => BC1_RGBA,
Tf::Bc1RgbaUnormSrgb => BC1_RGBA_sRGB,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl PhysicalDeviceFeatures {
);

features.set(
F::DEPTH24UNORM_STENCIL8,
F::DEPTH24PLUS_STENCIL8,
supports_format(
instance,
phd,
Expand Down
3 changes: 2 additions & 1 deletion wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl super::PrivateCapabilities {
F::D32_SFLOAT_S8_UINT
}
}
Tf::Depth24UnormStencil8 => F::D24_UNORM_S8_UINT,
//Tf::Stencil8 => F::R8_UNORM,
Tf::Depth16Unorm => F::D16_UNORM,
Tf::Rgb9e5Ufloat => F::E5B9G9R9_UFLOAT_PACK32,
Tf::Bc1RgbaUnorm => F::BC1_RGBA_UNORM_BLOCK,
Tf::Bc1RgbaUnormSrgb => F::BC1_RGBA_SRGB_BLOCK,
Expand Down
3 changes: 2 additions & 1 deletion wgpu-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ mod inner {
wgpu::TextureFormat::Rgba32Uint,
wgpu::TextureFormat::Rgba32Sint,
wgpu::TextureFormat::Rgba32Float,
//wgpu::TextureFormat::Stencil8,
wgpu::TextureFormat::Depth16Unorm,
wgpu::TextureFormat::Depth32Float,
wgpu::TextureFormat::Depth32FloatStencil8,
wgpu::TextureFormat::Depth24Plus,
wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureFormat::Depth24UnormStencil8,
wgpu::TextureFormat::Rgb9e5Ufloat,
wgpu::TextureFormat::Bc1RgbaUnorm,
wgpu::TextureFormat::Bc1RgbaUnormSrgb,
Expand Down
Loading