Skip to content

Commit bde7091

Browse files
authored
add Metal support for MULTISAMPLE_ARRAY (gfx-rs#9300)
1 parent 2ac1fae commit bde7091

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

wgpu-hal/src/metal/adapter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,14 @@ impl super::CapabilitiesQuery {
11071107
false
11081108
},
11091109
shader_per_vertex: family_check && device.supportsFamily(MTLGPUFamily::Apple10),
1110+
1111+
//https://developer.apple.com/documentation/metal/mtltexturetype/type2dmultisamplearray
1112+
supports_multisample_array: available!(
1113+
macos = 10.14,
1114+
ios = 14.0,
1115+
tvos = 16.0,
1116+
visionos = 1.0
1117+
),
11101118
}
11111119
}
11121120

@@ -1242,6 +1250,8 @@ impl super::CapabilitiesQuery {
12421250

12431251
features.set(F::EXPERIMENTAL_RAY_QUERY, self.supports_raytracing);
12441252

1253+
features.set(F::MULTISAMPLE_ARRAY, self.supports_multisample_array);
1254+
12451255
features
12461256
}
12471257

wgpu-hal/src/metal/device.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,15 @@ impl crate::Device for super::Device {
493493
wgt::TextureDimension::D2 => {
494494
if desc.sample_count > 1 {
495495
unsafe { descriptor.setSampleCount(desc.sample_count as usize) };
496-
MTLTextureType::Type2DMultisample
496+
497+
if desc.size.depth_or_array_layers > 1 {
498+
unsafe {
499+
descriptor.setArrayLength(desc.size.depth_or_array_layers as usize)
500+
};
501+
MTLTextureType::Type2DMultisampleArray
502+
} else {
503+
MTLTextureType::Type2DMultisample
504+
}
497505
} else if desc.size.depth_or_array_layers > 1 {
498506
unsafe {
499507
descriptor.setArrayLength(desc.size.depth_or_array_layers as usize)
@@ -560,7 +568,9 @@ impl crate::Device for super::Device {
560568
texture: &super::Texture,
561569
desc: &crate::TextureViewDescriptor,
562570
) -> DeviceResult<super::TextureView> {
563-
let raw_type = if texture.raw_type == MTLTextureType::Type2DMultisample {
571+
let raw_type = if texture.raw_type == MTLTextureType::Type2DMultisample
572+
|| texture.raw_type == MTLTextureType::Type2DMultisampleArray
573+
{
564574
texture.raw_type
565575
} else {
566576
conv::map_texture_view_dimension(desc.dimension)

wgpu-hal/src/metal/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ struct CapabilitiesQuery {
322322
supports_memoryless_storage: bool,
323323
supports_raytracing: bool,
324324
shader_per_vertex: bool,
325+
supports_multisample_array: bool,
325326
}
326327

327328
#[derive(Debug)]

wgpu-types/src/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ bitflags_array! {
13871387
///
13881388
/// Supported platforms:
13891389
/// - Vulkan (except VK_KHR_portability_subset if multisampleArrayImage is not available)
1390+
/// - Metal (with macos 10.14+, ios 14.0+, tvos 16.0+, visionos 1.0+)
13901391
#[name("wgpu-multisample-array")]
13911392
const MULTISAMPLE_ARRAY = 1 << 56;
13921393

0 commit comments

Comments
 (0)