From a650054b49c54168bb5a3cec4e26543b172b5a8e Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Tue, 1 Mar 2022 14:40:44 +0800 Subject: [PATCH 1/3] metal: roll metal-rs, fix read_write_texture_tier --- Cargo.lock | 2 +- wgpu-hal/Cargo.toml | 2 +- wgpu-hal/src/metal/adapter.rs | 6 ++++++ wgpu-hal/src/metal/device.rs | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dfed1e113..745c4d5d15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -996,7 +996,7 @@ dependencies = [ [[package]] name = "metal" version = "0.23.1" -source = "git+https://github.com/gfx-rs/metal-rs?rev=44af5cc#44af5cca340617d42d701264f9bf71d1f3e68096" +source = "git+https://github.com/gfx-rs/metal-rs?rev=a357159#a35715916fec38bbc08a510ecf7d115edc500c72" dependencies = [ "bitflags", "block", diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 80405a261c..44d3532ac4 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -77,7 +77,7 @@ winapi = { version = "0.3", features = ["libloaderapi", "windef", "winuser", "dc native = { package = "d3d12", version = "0.4.1", features = ["libloading"], optional = true } [target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] -mtl = { package = "metal", git = "https://github.com/gfx-rs/metal-rs", rev = "44af5cc" } +mtl = { package = "metal", git = "https://github.com/gfx-rs/metal-rs", rev = "a357159" } objc = "0.2.5" core-graphics-types = "0.1" diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 9da58bcebe..dcd8ac7725 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -660,6 +660,12 @@ impl super::PrivateCapabilities { read_write_texture_tier: if os_is_mac { if Self::version_at_least(major, minor, 10, 13) { device.read_write_texture_support() + } else if Self::version_at_least(major, minor, 10, 12) { + if Self::supports_any(device, &[MTLFeatureSet::macOS_ReadWriteTextureTier2]) { + mtl::MTLReadWriteTextureTier::Tier2 + } else { + mtl::MTLReadWriteTextureTier::Tier1 + } } else { mtl::MTLReadWriteTextureTier::TierNone } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index e356cd0b35..b560bd0670 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -644,6 +644,7 @@ impl crate::Device for super::Device { mtl::MTLLanguageVersion::V2_1 => (2, 1), mtl::MTLLanguageVersion::V2_2 => (2, 2), mtl::MTLLanguageVersion::V2_3 => (2, 3), + mtl::MTLLanguageVersion::V2_4 => (2, 4), }, inline_samplers: Default::default(), spirv_cross_compatibility: false, From b0b37c6d1ace661d8787f1124fcb47f6f557f19d Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Tue, 1 Mar 2022 14:44:09 +0800 Subject: [PATCH 2/3] metal: refactor `PrivateCapabilities` creation --- wgpu-hal/src/metal/adapter.rs | 442 ++++++++++------------------------ 1 file changed, 128 insertions(+), 314 deletions(-) diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index dcd8ac7725..83c8809ddd 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1,9 +1,5 @@ -use mtl::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion}; -use objc::{ - class, msg_send, - runtime::{BOOL, YES}, - sel, sel_impl, -}; +use mtl::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion, MTLReadWriteTextureTier}; +use objc::{class, msg_send, sel, sel_impl}; use parking_lot::Mutex; use wgt::{AstcBlock, AstcChannel}; @@ -395,161 +391,95 @@ impl crate::Adapter for super::Adapter { const RESOURCE_HEAP_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily1_v3, - MTLFeatureSet::iOS_GPUFamily2_v3, - MTLFeatureSet::iOS_GPUFamily3_v2, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, - MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v3, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const ARGUMENT_BUFFER_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily1_v4, - MTLFeatureSet::iOS_GPUFamily2_v4, - MTLFeatureSet::iOS_GPUFamily3_v3, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v3, MTLFeatureSet::macOS_GPUFamily1_v3, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const MUTABLE_COMPARISON_SAMPLER_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; -const SAMPLER_CLAMP_TO_BORDER_SUPPORT: &[MTLFeatureSet] = &[ - MTLFeatureSet::macOS_GPUFamily1_v2, - MTLFeatureSet::macOS_GPUFamily2_v1, -]; +const SAMPLER_CLAMP_TO_BORDER_SUPPORT: &[MTLFeatureSet] = &[MTLFeatureSet::macOS_GPUFamily1_v2]; const ASTC_PIXEL_FORMAT_FEATURES: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily2_v1, - MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v1, - MTLFeatureSet::tvOS_GPUFamily2_v1, ]; const ANY8_UNORM_SRGB_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily2_v3, - MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, - MTLFeatureSet::tvOS_GPUFamily2_v1, ]; const ANY8_SNORM_RESOLVE: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily2_v1, - MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v1, - MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const RGBA8_SRGB: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily2_v3, - MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, - MTLFeatureSet::tvOS_GPUFamily2_v1, ]; const RGB10A2UNORM_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const RGB10A2UINT_COLOR_WRITE: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const RG11B10FLOAT_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const RGB9E5FLOAT_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, ]; const BGR10A2_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily1_v4, - MTLFeatureSet::iOS_GPUFamily2_v4, - MTLFeatureSet::iOS_GPUFamily3_v3, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v3, - MTLFeatureSet::tvOS_GPUFamily2_v1, - MTLFeatureSet::macOS_GPUFamily1_v3, MTLFeatureSet::macOS_GPUFamily2_v1, ]; const BASE_INSTANCE_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const BASE_VERTEX_INSTANCE_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const TEXTURE_CUBE_ARRAY_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, - MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const DUAL_SOURCE_BLEND_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily1_v4, - MTLFeatureSet::iOS_GPUFamily2_v4, - MTLFeatureSet::iOS_GPUFamily3_v3, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v3, - MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v2, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const LAYERED_RENDERING_SUPPORT: &[MTLFeatureSet] = &[ @@ -560,28 +490,19 @@ const LAYERED_RENDERING_SUPPORT: &[MTLFeatureSet] = &[ const FUNCTION_SPECIALIZATION_SUPPORT: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily1_v3, - MTLFeatureSet::iOS_GPUFamily2_v3, - MTLFeatureSet::iOS_GPUFamily3_v2, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, MTLFeatureSet::macOS_GPUFamily1_v2, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; const DEPTH_CLIP_MODE: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v3, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ]; -impl super::PrivateCapabilities { - fn version_at_least(major: u32, minor: u32, needed_major: u32, needed_minor: u32) -> bool { - major > needed_major || (major == needed_major && minor >= needed_minor) - } +const OS_NOT_SUPPORT: (usize, usize) = (10000, 0); +impl super::PrivateCapabilities { fn supports_any(raw: &mtl::DeviceRef, features_sets: &[MTLFeatureSet]) -> bool { features_sets .iter() @@ -597,22 +518,30 @@ impl super::PrivateCapabilities { major: usize, minor: usize, patch: usize, + is_mac: bool, + } + + impl NSOperatingSystemVersion { + fn at_least(&self, mac_version: (usize, usize), ios_version: (usize, usize)) -> bool { + if self.is_mac { + self.major > mac_version.0 + || (self.major == mac_version.0 && self.minor >= mac_version.1) + } else { + self.major > ios_version.0 + || (self.major == ios_version.0 && self.minor >= ios_version.1) + } + } } - let version: NSOperatingSystemVersion = unsafe { + let mut version: NSOperatingSystemVersion = unsafe { let process_info: *mut objc::runtime::Object = msg_send![class!(NSProcessInfo), processInfo]; msg_send![process_info, operatingSystemVersion] }; - let major = version.major as u32; - let minor = version.minor as u32; let os_is_mac = device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1); - let family_check = if os_is_mac { - Self::version_at_least(major, minor, 10, 15) - } else { - Self::version_at_least(major, minor, 13, 0) - }; + version.is_mac = os_is_mac; + let family_check = version.at_least((10, 15), (13, 0)); let mut sample_count_mask: u8 = 1 | 4; // 1 and 4 samples are supported on all devices if device.supports_texture_sample_count(2) { @@ -622,60 +551,46 @@ impl super::PrivateCapabilities { sample_count_mask |= 8; } + let rw_texture_tier = if version.at_least((10, 13), (11, 0)) { + device.read_write_texture_support() + } else if version.at_least((10, 12), OS_NOT_SUPPORT) { + if Self::supports_any(device, &[MTLFeatureSet::macOS_ReadWriteTextureTier2]) { + MTLReadWriteTextureTier::Tier2 + } else { + MTLReadWriteTextureTier::Tier1 + } + } else { + MTLReadWriteTextureTier::TierNone + }; + Self { family_check, - msl_version: if os_is_mac { - if Self::version_at_least(major, minor, 11, 0) { - MTLLanguageVersion::V2_3 - } else if Self::version_at_least(major, minor, 10, 15) { - MTLLanguageVersion::V2_2 - } else if Self::version_at_least(major, minor, 10, 14) { - MTLLanguageVersion::V2_1 - } else if Self::version_at_least(major, minor, 10, 13) { - MTLLanguageVersion::V2_0 - } else if Self::version_at_least(major, minor, 10, 12) { - MTLLanguageVersion::V1_2 - } else if Self::version_at_least(major, minor, 10, 11) { - MTLLanguageVersion::V1_1 - } else { - MTLLanguageVersion::V1_0 - } - } else if Self::version_at_least(major, minor, 14, 0) { + msl_version: if version.at_least((12, 0), (15, 0)) { + MTLLanguageVersion::V2_4 + } else if version.at_least((11, 0), (14, 0)) { MTLLanguageVersion::V2_3 - } else if Self::version_at_least(major, minor, 13, 0) { + } else if version.at_least((10, 15), (13, 0)) { MTLLanguageVersion::V2_2 - } else if Self::version_at_least(major, minor, 12, 0) { + } else if version.at_least((10, 14), (12, 0)) { MTLLanguageVersion::V2_1 - } else if Self::version_at_least(major, minor, 11, 0) { + } else if version.at_least((10, 13), (11, 0)) { MTLLanguageVersion::V2_0 - } else if Self::version_at_least(major, minor, 10, 0) { + } else if version.at_least((10, 12), (10, 0)) { MTLLanguageVersion::V1_2 - } else if Self::version_at_least(major, minor, 9, 0) { + } else if version.at_least((10, 11), (9, 0)) { MTLLanguageVersion::V1_1 } else { MTLLanguageVersion::V1_0 }, // macOS 10.11 doesn't support read-write resources - fragment_rw_storage: !os_is_mac || Self::version_at_least(major, minor, 10, 12), - read_write_texture_tier: if os_is_mac { - if Self::version_at_least(major, minor, 10, 13) { - device.read_write_texture_support() - } else if Self::version_at_least(major, minor, 10, 12) { - if Self::supports_any(device, &[MTLFeatureSet::macOS_ReadWriteTextureTier2]) { - mtl::MTLReadWriteTextureTier::Tier2 - } else { - mtl::MTLReadWriteTextureTier::Tier1 - } - } else { - mtl::MTLReadWriteTextureTier::TierNone - } - } else if Self::version_at_least(major, minor, 11, 0) { - device.read_write_texture_support() + fragment_rw_storage: version.at_least((10, 12), (8, 0)), + read_write_texture_tier: rw_texture_tier, + msaa_desktop: os_is_mac, + msaa_apple3: if family_check { + device.supports_family(MTLGPUFamily::Apple3) } else { - mtl::MTLReadWriteTextureTier::TierNone + device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily3_v4) }, - msaa_desktop: os_is_mac, - msaa_apple3: family_check && device.supports_family(MTLGPUFamily::Apple3), msaa_apple7: family_check && device.supports_family(MTLGPUFamily::Apple7), resource_heaps: Self::supports_any(device, RESOURCE_HEAP_SUPPORT), argument_buffers: Self::supports_any(device, ARGUMENT_BUFFER_SUPPORT), @@ -687,8 +602,7 @@ impl super::PrivateCapabilities { sampler_clamp_to_border: Self::supports_any(device, SAMPLER_CLAMP_TO_BORDER_SUPPORT), sampler_lod_average: { // TODO: Clarify minimum macOS version with Apple (43707452) - let need_version = if os_is_mac { (10, 13) } else { (9, 0) }; - Self::version_at_least(major, minor, need_version.0, need_version.1) + version.at_least((10, 13), (9, 0)) }, base_instance: Self::supports_any(device, BASE_INSTANCE_SUPPORT), base_vertex_instance_drawing: Self::supports_any(device, BASE_VERTEX_INSTANCE_SUPPORT), @@ -708,9 +622,9 @@ impl super::PrivateCapabilities { format_eac_etc: !os_is_mac // M1 in macOS supports EAC/ETC2 || (family_check && device.supports_family(MTLGPUFamily::Apple7)), - format_astc: Self::supports_any(device, ASTC_PIXEL_FORMAT_FEATURES) - // A8(Apple2) and later always support ASTC pixel formats - || (family_check && device.supports_family(MTLGPUFamily::Apple2)), + // A8(Apple2) and later always support ASTC pixel formats + format_astc: (family_check && device.supports_family(MTLGPUFamily::Apple2)) + || Self::supports_any(device, ASTC_PIXEL_FORMAT_FEATURES), // A13(Apple6) M1(Apple7) and later always support HDR ASTC pixel formats format_astc_hdr: family_check && device.supports_family(MTLGPUFamily::Apple6), format_any8_unorm_srgb_all: Self::supports_any(device, ANY8_UNORM_SRGB_ALL), @@ -718,34 +632,14 @@ impl super::PrivateCapabilities { && !os_is_mac, format_any8_snorm_all: Self::supports_any(device, ANY8_SNORM_RESOLVE), format_r16_norm_all: os_is_mac, - format_r32_all: !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_r32_no_write: Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_r32float_no_write_no_filter: Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ) && !os_is_mac, - format_r32float_no_filter: !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ) && !os_is_mac, + // No devices support r32's all capabilities + format_r32_all: false, + // All devices support r32's write capability + format_r32_no_write: false, + // iOS support r32float's write capability, macOS support r32float's all capabilities + format_r32float_no_write_no_filter: false, + // Only iOS doesn't support r32float's filter capability + format_r32float_no_filter: !os_is_mac, format_r32float_all: os_is_mac, format_rgba8_srgb_all: Self::supports_any(device, RGBA8_SRGB), format_rgba8_srgb_no_write: !Self::supports_any(device, RGBA8_SRGB), @@ -758,89 +652,59 @@ impl super::PrivateCapabilities { format_rgb9e5_all: Self::supports_any(device, RGB9E5FLOAT_ALL), format_rgb9e5_no_write: !Self::supports_any(device, RGB9E5FLOAT_ALL) && !os_is_mac, format_rgb9e5_filter_only: os_is_mac, - format_rg32_color: Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_rg32_color_write: !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), + format_rg32_color: true, + format_rg32_color_write: true, + // Only macOS support rg32float's all capabilities format_rg32float_all: os_is_mac, - format_rg32float_color_blend: Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_rg32float_no_filter: !os_is_mac - && !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_rgba32int_color: Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_rgba32int_color_write: !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ), - format_rgba32float_color: Self::supports_any( + // All devices support rg32float's color + blend capabilities + format_rg32float_color_blend: true, + // Only iOS doesn't support rg32float's filter + format_rg32float_no_filter: !os_is_mac, + format_rgba32int_color: true, + // All devices support rgba32uint and rgba32sint's color + write capabilities + format_rgba32int_color_write: true, + format_rgba32float_color: true, + // All devices support rgba32float's color + write capabilities + format_rgba32float_color_write: true, + // Only macOS support rgba32float's all capabilities + format_rgba32float_all: os_is_mac, + format_depth16unorm: Self::supports_any( device, &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, + MTLFeatureSet::iOS_GPUFamily3_v3, + MTLFeatureSet::macOS_GPUFamily1_v2, ], ), - format_rgba32float_color_write: !Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v1, - MTLFeatureSet::iOS_GPUFamily2_v1, - ], - ) && !os_is_mac, - format_rgba32float_all: os_is_mac, - format_depth16unorm: device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v2), - format_depth32float_filter: device - .supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1), - format_depth32float_none: !device - .supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1), + format_depth32float_filter: os_is_mac, + format_depth32float_none: !os_is_mac, format_bgr10a2_all: Self::supports_any(device, BGR10A2_ALL), - format_bgr10a2_no_write: !device - .supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v3), + format_bgr10a2_no_write: !Self::supports_any(device, BGR10A2_ALL), max_buffers_per_stage: 31, - max_textures_per_stage: if os_is_mac { 128 } else { 31 }, - max_samplers_per_stage: 16, + max_textures_per_stage: if os_is_mac { + 128 // On macOS, minimun value is 128 + } else if device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1) { + 96 + } else { + 31 + }, + max_samplers_per_stage: if (family_check + && device.supports_family(MTLGPUFamily::Apple6)) + || (os_is_mac && rw_texture_tier == MTLReadWriteTextureTier::Tier2) + { + 1024 + } else { + 16 + }, buffer_alignment: if os_is_mac { 256 } else { 64 }, - max_buffer_size: unsafe { - let sel = sel!(maxBufferLength); - let can_use: BOOL = msg_send![device.as_ref(), respondsToSelector: sel]; - if can_use == YES { - // maxBufferLength available on macOS 10.14+ and iOS 12.0+ - let buffer_size: mtl::NSInteger = msg_send![device.as_ref(), maxBufferLength]; - buffer_size as _ - } else if os_is_mac { - 1 << 30 // 1GB on macOS 10.11 and up - } else { - 1 << 28 // 256MB on iOS 8.0+ - } + max_buffer_size: if version.at_least((10, 14), (12, 0)) { + // maxBufferLength available on macOS 10.14+ and iOS 12.0+ + let buffer_size: mtl::NSInteger = + unsafe { msg_send![device.as_ref(), maxBufferLength] }; + buffer_size as _ + } else if os_is_mac { + 1 << 30 // 1GB on macOS 10.11 and up + } else { + 1 << 28 // 256MB on iOS 8.0+ }, max_texture_size: if Self::supports_any( device, @@ -851,45 +715,33 @@ impl super::PrivateCapabilities { ], ) { 16384 - } else if Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily1_v2, - MTLFeatureSet::iOS_GPUFamily2_v2, - MTLFeatureSet::tvOS_GPUFamily1_v1, - ], - ) { - 8192 } else { - 4096 + 8192 }, max_texture_3d_size: 2048, max_texture_layers: 2048, - max_fragment_input_components: if os_is_mac { 128 } else { 60 }, + max_fragment_input_components: if os_is_mac + || device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1) + { + 124 + } else { + 60 + }, max_color_render_targets: if Self::supports_any( device, &[ MTLFeatureSet::iOS_GPUFamily2_v1, - MTLFeatureSet::iOS_GPUFamily3_v1, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v1, - MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ], ) { 8 } else { 4 }, - max_varying_components: if Self::supports_any( - device, - &[ - MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, - ], - ) { + max_varying_components: if device + .supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1) + { 128 } else { 60 @@ -898,29 +750,22 @@ impl super::PrivateCapabilities { device, &[ MTLFeatureSet::iOS_GPUFamily4_v2, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::macOS_GPUFamily1_v1, - MTLFeatureSet::macOS_GPUFamily2_v1, ], ) { 1024 } else { 512 }, - max_total_threadgroup_memory: if Self::supports_any( - device, - &[ - MTLFeatureSet::iOS_GPUFamily4_v2, - MTLFeatureSet::iOS_GPUFamily5_v1, - ], - ) { + max_total_threadgroup_memory: if device + .supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v2) + { 64 << 10 } else if Self::supports_any( device, &[ MTLFeatureSet::iOS_GPUFamily4_v1, MTLFeatureSet::macOS_GPUFamily1_v2, - MTLFeatureSet::macOS_GPUFamily2_v1, ], ) { 32 << 10 @@ -932,66 +777,35 @@ impl super::PrivateCapabilities { device, &[ MTLFeatureSet::macOS_GPUFamily1_v2, - MTLFeatureSet::macOS_GPUFamily2_v1, MTLFeatureSet::iOS_GPUFamily1_v3, - MTLFeatureSet::iOS_GPUFamily2_v3, - MTLFeatureSet::iOS_GPUFamily3_v2, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily1_v2, - MTLFeatureSet::tvOS_GPUFamily2_v1, ], ), supports_binary_archives: family_check && (device.supports_family(MTLGPUFamily::Apple3) || device.supports_family(MTLGPUFamily::Mac1)), - supports_capture_manager: if os_is_mac { - Self::version_at_least(major, minor, 10, 13) - } else { - Self::version_at_least(major, minor, 11, 0) - }, - can_set_maximum_drawables_count: os_is_mac - || Self::version_at_least(major, minor, 11, 2), - can_set_display_sync: os_is_mac && Self::version_at_least(major, minor, 10, 13), - can_set_next_drawable_timeout: if os_is_mac { - Self::version_at_least(major, minor, 10, 13) - } else { - Self::version_at_least(major, minor, 11, 0) - }, + supports_capture_manager: version.at_least((10, 13), (11, 0)), + can_set_maximum_drawables_count: version.at_least((10, 14), (11, 2)), + can_set_display_sync: version.at_least((10, 13), OS_NOT_SUPPORT), + can_set_next_drawable_timeout: version.at_least((10, 13), (11, 0)), supports_arrays_of_textures: Self::supports_any( device, &[ MTLFeatureSet::iOS_GPUFamily3_v2, - MTLFeatureSet::iOS_GPUFamily4_v1, - MTLFeatureSet::iOS_GPUFamily5_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v3, - MTLFeatureSet::macOS_GPUFamily2_v1, ], ), supports_arrays_of_textures_write: family_check && (device.supports_family(MTLGPUFamily::Apple6) || device.supports_family(MTLGPUFamily::Mac1) - || device.supports_family(MTLGPUFamily::Mac2) - || device.supports_family(MTLGPUFamily::MacCatalyst1) - || device.supports_family(MTLGPUFamily::MacCatalyst2)), - supports_mutability: if os_is_mac { - Self::version_at_least(major, minor, 10, 13) - } else { - Self::version_at_least(major, minor, 11, 0) - }, + || device.supports_family(MTLGPUFamily::MacCatalyst1)), + supports_mutability: version.at_least((10, 13), (11, 0)), //Depth clipping is supported on all macOS GPU families and iOS family 4 and later - supports_depth_clip_control: device - .supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1) - || os_is_mac, - supports_preserve_invariance: if os_is_mac { - Self::version_at_least(major, minor, 11, 0) - } else { - Self::version_at_least(major, minor, 13, 0) - }, - has_unified_memory: if (os_is_mac && Self::version_at_least(major, minor, 10, 15)) - || (!os_is_mac && Self::version_at_least(major, minor, 13, 0)) - { + supports_depth_clip_control: os_is_mac + || device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1), + supports_preserve_invariance: version.at_least((11, 0), (13, 0)), + has_unified_memory: if version.at_least((10, 15), (13, 0)) { Some(device.has_unified_memory()) } else { None From 0526485d94a07f269ddbffbc35998d40be06d61e Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Tue, 1 Mar 2022 15:02:25 +0800 Subject: [PATCH 3/3] gl | metal: updates the upper bounds of the extends of `SurfaceCapabilities` --- wgpu-hal/src/gles/adapter.rs | 5 +++-- wgpu-hal/src/gles/mod.rs | 1 + wgpu-hal/src/metal/adapter.rs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index ae76bce77a..61dcd56b91 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -494,6 +494,7 @@ impl super::Adapter { private_caps, workarounds, shading_language_version, + max_texture_size, }), }, info: Self::make_info(vendor, renderer), @@ -718,8 +719,8 @@ impl crate::Adapter for super::Adapter { height: 4, depth_or_array_layers: 1, }..=wgt::Extent3d { - width: 4096, - height: 4096, + width: self.shared.max_texture_size, + height: self.shared.max_texture_size, depth_or_array_layers: 1, }, usage: crate::TextureUses::COLOR_TARGET, diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index d62799814f..8c7dde0da2 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -182,6 +182,7 @@ struct AdapterShared { private_caps: PrivateCapabilities, workarounds: Workarounds, shading_language_version: naga::back::glsl::Version, + max_texture_size: u32, } pub struct Adapter { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 83c8809ddd..a51686188f 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -380,8 +380,8 @@ impl crate::Adapter for super::Adapter { height: 4, depth_or_array_layers: 1, }..=wgt::Extent3d { - width: 4096, - height: 4096, + width: pc.max_texture_size as u32, + height: pc.max_texture_size as u32, depth_or_array_layers: 1, }, usage: crate::TextureUses::COLOR_TARGET | crate::TextureUses::COPY_DST, //TODO: expose more