Skip to content

Commit cdf6ee0

Browse files
gents83Mauro Gentile
andauthored
Updating TextureFormat matching specs (#2954)
Co-authored-by: Mauro Gentile <Mauro.Gentile@ubisoft.com>
1 parent f8ff5a8 commit cdf6ee0

File tree

16 files changed

+155
-121
lines changed

16 files changed

+155
-121
lines changed

wgpu-core/src/command/transfer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,12 @@ pub(crate) fn validate_texture_copy_range(
314314
let extent = extent_virtual.physical_size(desc.format);
315315

316316
match desc.format {
317-
wgt::TextureFormat::Depth32Float
317+
//wgt::TextureFormat::Stencil8 |
318+
wgt::TextureFormat::Depth16Unorm
319+
| wgt::TextureFormat::Depth32Float
318320
| wgt::TextureFormat::Depth32FloatStencil8
319321
| wgt::TextureFormat::Depth24Plus
320-
| wgt::TextureFormat::Depth24PlusStencil8
321-
| wgt::TextureFormat::Depth24UnormStencil8 => {
322+
| wgt::TextureFormat::Depth24PlusStencil8 => {
322323
if *copy_size != extent {
323324
return Err(TransferError::InvalidDepthTextureExtent);
324325
}

wgpu-core/src/conv.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
1919
pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
2020
use wgt::TextureFormat as Tf;
2121
match format {
22-
Tf::Depth32Float
22+
//Tf::Stencil8 |
23+
Tf::Depth16Unorm
24+
| Tf::Depth32Float
2325
| Tf::Depth32FloatStencil8
2426
| Tf::Depth24Plus
25-
| Tf::Depth24PlusStencil8
26-
| Tf::Depth24UnormStencil8 => false,
27+
| Tf::Depth24PlusStencil8 => false,
2728
_ => true,
2829
}
2930
}

wgpu-core/src/validation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,12 @@ impl NumericType {
704704
(NumericDimension::Vector(Vs::Quad), Sk::Sint)
705705
}
706706
Tf::Rg11b10Float => (NumericDimension::Vector(Vs::Tri), Sk::Float),
707-
Tf::Depth32Float
707+
//Tf::Stencil8 |
708+
Tf::Depth16Unorm
709+
| Tf::Depth32Float
708710
| Tf::Depth32FloatStencil8
709711
| Tf::Depth24Plus
710-
| Tf::Depth24PlusStencil8
711-
| Tf::Depth24UnormStencil8 => {
712+
| Tf::Depth24PlusStencil8 => {
712713
panic!("Unexpected depth format")
713714
}
714715
Tf::Rgb9e5Ufloat => (NumericDimension::Vector(Vs::Tri), Sk::Float),

wgpu-hal/src/auxil/dxgi/conv.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
3333
Tf::Bgra8Unorm => DXGI_FORMAT_B8G8R8A8_UNORM,
3434
Tf::Rgba8Uint => DXGI_FORMAT_R8G8B8A8_UINT,
3535
Tf::Rgba8Sint => DXGI_FORMAT_R8G8B8A8_SINT,
36+
Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
3637
Tf::Rgb10a2Unorm => DXGI_FORMAT_R10G10B10A2_UNORM,
3738
Tf::Rg11b10Float => DXGI_FORMAT_R11G11B10_FLOAT,
3839
Tf::Rg32Uint => DXGI_FORMAT_R32G32_UINT,
@@ -46,11 +47,12 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
4647
Tf::Rgba32Uint => DXGI_FORMAT_R32G32B32A32_UINT,
4748
Tf::Rgba32Sint => DXGI_FORMAT_R32G32B32A32_SINT,
4849
Tf::Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT,
50+
//Tf::Stencil8 => DXGI_FORMAT_R8_UNORM,
51+
Tf::Depth16Unorm => DXGI_FORMAT_D16_UNORM,
52+
Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT,
53+
Tf::Depth24PlusStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT,
4954
Tf::Depth32Float => DXGI_FORMAT_D32_FLOAT,
5055
Tf::Depth32FloatStencil8 => DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
51-
Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT,
52-
Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT,
53-
Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
5456
Tf::Bc1RgbaUnorm => DXGI_FORMAT_BC1_UNORM,
5557
Tf::Bc1RgbaUnormSrgb => DXGI_FORMAT_BC1_UNORM_SRGB,
5658
Tf::Bc2RgbaUnorm => DXGI_FORMAT_BC2_UNORM,
@@ -103,13 +105,15 @@ pub fn map_texture_format_nosrgb(format: wgt::TextureFormat) -> dxgiformat::DXGI
103105
//TODO: stencil views?
104106
pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
105107
match format {
108+
//wgt::TextureFormat::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM,
109+
wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM,
106110
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_FLOAT,
107111
wgt::TextureFormat::Depth32FloatStencil8 => {
108112
dxgiformat::DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS
109113
}
110-
wgt::TextureFormat::Depth24Plus
111-
| wgt::TextureFormat::Depth24PlusStencil8
112-
| wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
114+
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
115+
dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS
116+
}
113117
_ => {
114118
assert_eq!(
115119
crate::FormatAspects::from(format),
@@ -122,11 +126,13 @@ pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXG
122126

123127
pub fn map_texture_format_depth_typeless(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
124128
match format {
129+
//wgt::TextureFormat::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM,
130+
wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM,
125131
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS,
126132
wgt::TextureFormat::Depth32FloatStencil8 => dxgiformat::DXGI_FORMAT_R32G8X24_TYPELESS,
127-
wgt::TextureFormat::Depth24Plus
128-
| wgt::TextureFormat::Depth24PlusStencil8
129-
| wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24G8_TYPELESS,
133+
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
134+
dxgiformat::DXGI_FORMAT_R24G8_TYPELESS
135+
}
130136
_ => unreachable!(),
131137
}
132138
}

wgpu-hal/src/dx12/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl super::Adapter {
189189

190190
let mut features = wgt::Features::empty()
191191
| wgt::Features::DEPTH_CLIP_CONTROL
192-
| wgt::Features::DEPTH24UNORM_STENCIL8
192+
| wgt::Features::DEPTH24PLUS_STENCIL8
193193
| wgt::Features::DEPTH32FLOAT_STENCIL8
194194
| wgt::Features::INDIRECT_FIRST_INSTANCE
195195
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS

wgpu-hal/src/gles/adapter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,12 @@ impl crate::Adapter<super::Api> for super::Adapter {
725725
Tf::Rgba32Uint => renderable | storage,
726726
Tf::Rgba32Sint => renderable | storage,
727727
Tf::Rgba32Float => unfilterable | storage | float_renderable,
728-
Tf::Depth32Float
728+
//Tf::Stencil8 |
729+
Tf::Depth16Unorm
730+
| Tf::Depth32Float
729731
| Tf::Depth32FloatStencil8
730732
| Tf::Depth24Plus
731-
| Tf::Depth24PlusStencil8
732-
| Tf::Depth24UnormStencil8 => depth,
733+
| Tf::Depth24PlusStencil8 => depth,
733734
Tf::Rgb9e5Ufloat => filterable,
734735
Tf::Bc1RgbaUnorm
735736
| Tf::Bc1RgbaUnormSrgb

wgpu-hal/src/gles/conv.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl super::AdapterShared {
5656
Tf::Rgba32Uint => (glow::RGBA32UI, glow::RGBA_INTEGER, glow::UNSIGNED_INT),
5757
Tf::Rgba32Sint => (glow::RGBA32I, glow::RGBA_INTEGER, glow::INT),
5858
Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT),
59+
//Tf::Stencil8 => (glow::R8UI, glow::STENCIL_COMPONENTS, glow::UNSIGNED_BYTE),
60+
Tf::Depth16Unorm => (
61+
glow::DEPTH_COMPONENT16,
62+
glow::DEPTH_COMPONENT,
63+
glow::UNSIGNED_SHORT,
64+
),
5965
Tf::Depth32Float => (glow::DEPTH_COMPONENT32F, glow::DEPTH_COMPONENT, glow::FLOAT),
6066
Tf::Depth32FloatStencil8 => {
6167
(glow::DEPTH32F_STENCIL8, glow::DEPTH_COMPONENT, glow::FLOAT)
@@ -65,7 +71,7 @@ impl super::AdapterShared {
6571
glow::DEPTH_COMPONENT,
6672
glow::UNSIGNED_NORMALIZED,
6773
),
68-
Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => (
74+
Tf::Depth24PlusStencil8 => (
6975
glow::DEPTH24_STENCIL8,
7076
glow::DEPTH_COMPONENT,
7177
glow::UNSIGNED_INT,

wgpu-hal/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,12 @@ impl From<wgt::TextureAspect> for FormatAspects {
612612
impl From<wgt::TextureFormat> for FormatAspects {
613613
fn from(format: wgt::TextureFormat) -> Self {
614614
match format {
615+
//wgt::TextureFormat::Stencil8 => Self::STENCIL,
616+
wgt::TextureFormat::Depth16Unorm => Self::DEPTH,
615617
wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth24Plus => Self::DEPTH,
616-
wgt::TextureFormat::Depth32FloatStencil8
617-
| wgt::TextureFormat::Depth24PlusStencil8
618-
| wgt::TextureFormat::Depth24UnormStencil8 => Self::DEPTH | Self::STENCIL,
618+
wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24PlusStencil8 => {
619+
Self::DEPTH | Self::STENCIL
620+
}
619621
_ => Self::COLOR,
620622
}
621623
}

wgpu-hal/src/metal/adapter.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ impl crate::Adapter<super::Api> for super::Adapter {
180180
};
181181
flags
182182
}
183+
/*Tf::Stencil8 => {
184+
let mut flags = all_caps
185+
| Tfc::DEPTH_STENCIL_ATTACHMENT
186+
| Tfc::MULTISAMPLE
187+
| msaa_resolve_apple3x_if;
188+
flags
189+
}*/
190+
Tf::Depth16Unorm => {
191+
let mut flags =
192+
Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if;
193+
if pc.format_depth16unorm {
194+
flags |= Tfc::SAMPLED_LINEAR
195+
}
196+
flags
197+
}
183198
Tf::Depth32Float | Tf::Depth32FloatStencil8 => {
184199
let mut flags =
185200
Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if;
@@ -200,12 +215,6 @@ impl crate::Adapter<super::Api> for super::Adapter {
200215
}
201216
flags
202217
}
203-
Tf::Depth24UnormStencil8 => {
204-
Tfc::DEPTH_STENCIL_ATTACHMENT
205-
| Tfc::SAMPLED_LINEAR
206-
| Tfc::MULTISAMPLE
207-
| Tfc::MULTISAMPLE_RESOLVE
208-
}
209218
Tf::Rgb9e5Ufloat => {
210219
if pc.msaa_apple3 {
211220
all_caps
@@ -769,7 +778,7 @@ impl super::PrivateCapabilities {
769778
features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc);
770779

771780
features.set(F::DEPTH_CLIP_CONTROL, self.supports_depth_clip_control);
772-
features.set(F::DEPTH24UNORM_STENCIL8, self.format_depth24_stencil8);
781+
features.set(F::DEPTH24PLUS_STENCIL8, self.format_depth24_stencil8);
773782

774783
features.set(
775784
F::TEXTURE_BINDING_ARRAY
@@ -902,6 +911,8 @@ impl super::PrivateCapabilities {
902911
Tf::Rgba32Uint => RGBA32Uint,
903912
Tf::Rgba32Sint => RGBA32Sint,
904913
Tf::Rgba32Float => RGBA32Float,
914+
//Tf::Stencil8 => R8Unorm,
915+
Tf::Depth16Unorm => Depth16Unorm,
905916
Tf::Depth32Float => Depth32Float,
906917
Tf::Depth32FloatStencil8 => Depth32Float_Stencil8,
907918
Tf::Depth24Plus => {
@@ -918,7 +929,6 @@ impl super::PrivateCapabilities {
918929
Depth32Float_Stencil8
919930
}
920931
}
921-
Tf::Depth24UnormStencil8 => Depth24Unorm_Stencil8,
922932
Tf::Rgb9e5Ufloat => RGB9E5Float,
923933
Tf::Bc1RgbaUnorm => BC1_RGBA,
924934
Tf::Bc1RgbaUnormSrgb => BC1_RGBA_sRGB,

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl PhysicalDeviceFeatures {
482482
);
483483

484484
features.set(
485-
F::DEPTH24UNORM_STENCIL8,
485+
F::DEPTH24PLUS_STENCIL8,
486486
supports_format(
487487
instance,
488488
phd,

0 commit comments

Comments
 (0)