From f712b15e49f533f9b3554a8039a81c57086babf0 Mon Sep 17 00:00:00 2001 From: Ali Milhim Date: Thu, 27 Oct 2022 16:02:04 +0300 Subject: [PATCH] Refactored Metal adapter and updated CHANGELOG.md --- CHANGELOG.md | 2 +- wgpu-hal/src/metal/adapter.rs | 34 +++++++++++++++++++-------------- wgpu-hal/src/metal/mod.rs | 2 +- wgpu/examples/msaa-line/main.rs | 2 -- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 845906c39b5..cc70c07d58e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,7 +71,7 @@ Bottom level categories: #### WebGPU -- Add `TextureFormatSampleCountFlags` to `TextureFormatFeatures` to query supported sample count for the current texture format. By @39ali in [3140](https://github.com/gfx-rs/wgpu/pull/3140) +- Add `MULTISAMPLE_X2`, `MULTISAMPLE_X4` and `MULTISAMPLE_X8` to `TextureFormatFeatureFlags`. By @39ali in [3140](https://github.com/gfx-rs/wgpu/pull/3140) ### Bug Fixes diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index f1a581e249d..e86aa8eb3c2 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -122,11 +122,11 @@ impl crate::Adapter for super::Adapter { | Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND - | Tfc::MULTISAMPLE + | Tfc::MULTISAMPLE_X4 | msaa_resolve_desktop_if } Tf::Rg8Unorm | Tf::Rg16Float | Tf::Bgra8Unorm => all_caps, - Tf::Rg8Uint | Tf::Rg8Sint => Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE, + Tf::Rg8Uint | Tf::Rg8Sint => Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE_X4, Tf::R32Uint | Tf::R32Sint => { read_write_tier1_if | Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | msaa_desktop_if } @@ -137,11 +137,13 @@ impl crate::Adapter for super::Adapter { Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND - | Tfc::MULTISAMPLE + | Tfc::MULTISAMPLE_X4 }; read_write_tier1_if | flags } - Tf::Rg16Uint | Tf::Rg16Sint => Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE, + Tf::Rg16Uint | Tf::Rg16Sint => { + Tfc::STORAGE | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE_X4 + } Tf::Rgba8UnormSrgb | Tf::Bgra8UnormSrgb => { let mut flags = all_caps; flags.set(Tfc::STORAGE, pc.format_rgba8_srgb_all); @@ -176,7 +178,7 @@ impl crate::Adapter for super::Adapter { if pc.format_rgba32float_all { flags |= all_caps } else if pc.msaa_apple7 { - flags |= Tfc::MULTISAMPLE + flags |= Tfc::MULTISAMPLE_X4 }; flags } @@ -189,7 +191,7 @@ impl crate::Adapter for super::Adapter { }*/ Tf::Depth16Unorm => { let mut flags = - Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if; + Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE_X4 | msaa_resolve_apple3x_if; if pc.format_depth16unorm { flags |= Tfc::SAMPLED_LINEAR } @@ -197,14 +199,14 @@ impl crate::Adapter for super::Adapter { } Tf::Depth32Float | Tf::Depth32FloatStencil8 => { let mut flags = - Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if; + Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE_X4 | msaa_resolve_apple3x_if; if pc.format_depth32float_filter { flags |= Tfc::SAMPLED_LINEAR } flags } Tf::Depth24Plus | Tf::Depth24PlusStencil8 => { - let mut flags = Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE; + let mut flags = Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE_X4; if pc.format_depth24_stencil8 { flags |= Tfc::SAMPLED_LINEAR | Tfc::MULTISAMPLE_RESOLVE } else { @@ -224,7 +226,7 @@ impl crate::Adapter for super::Adapter { Tfc::SAMPLED_LINEAR | Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND - | Tfc::MULTISAMPLE + | Tfc::MULTISAMPLE_X4 | Tfc::MULTISAMPLE_RESOLVE } } @@ -275,8 +277,12 @@ impl crate::Adapter for super::Adapter { } } }; - // self.shared.private_caps.sample_count_mask - Tfc::COPY_SRC | Tfc::COPY_DST | Tfc::SAMPLED | extra + + Tfc::COPY_SRC + | Tfc::COPY_DST + | Tfc::SAMPLED + | extra + | self.shared.private_caps.sample_count_mask } unsafe fn surface_capabilities( @@ -489,12 +495,12 @@ impl super::PrivateCapabilities { version.is_mac = os_is_mac; let family_check = version.at_least((10, 15), (13, 0)); - let mut sample_count_mask = wgt::TextureFormatFeatureFlags::MULTISAMPLE_X4; // 1 and 4 samples are supported on all devices + let mut sample_count_mask = crate::TextureFormatCapabilities::MULTISAMPLE_X4; // 1 and 4 samples are supported on all devices if device.supports_texture_sample_count(2) { - sample_count_mask |= wgt::TextureFormatFeatureFlags::MULTISAMPLE_X2; + sample_count_mask |= crate::TextureFormatCapabilities::MULTISAMPLE_X2; } if device.supports_texture_sample_count(8) { - sample_count_mask |= wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8; + sample_count_mask |= crate::TextureFormatCapabilities::MULTISAMPLE_X8; } let rw_texture_tier = if version.at_least((10, 13), (11, 0)) { diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 851868b0236..00a8aa164b2 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -219,7 +219,7 @@ struct PrivateCapabilities { max_varying_components: u32, max_threads_per_group: u32, max_total_threadgroup_memory: u32, - sample_count_mask: wgt::TextureFormatFeatureFlags, + sample_count_mask: crate::TextureFormatCapabilities, supports_debug_markers: bool, supports_binary_archives: bool, supports_capture_manager: bool, diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 8866933c34a..6a5a7660253 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -132,8 +132,6 @@ impl framework::Example for Example { let sample_flags = _adapter.get_texture_format_features(config.format).flags; - log::info!("sample_flags :{:?}", sample_flags); - let max_sample_count = { if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X8) { 8