From ab8dfd9086cec07acb16685ef5851f13f7982673 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Sat, 29 Jan 2022 00:23:46 +0100 Subject: [PATCH] bevy_render: Only auto-disable mappable primary buffers for discrete GPUs --- crates/bevy_render/src/renderer/mod.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 1e5486f90b1eb..9908cfd476126 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -61,11 +61,6 @@ pub type RenderQueue = Arc; /// aswell as to create [`WindowSurfaces`](crate::view::window::WindowSurfaces). pub type RenderInstance = Instance; -/// `wgpu::Features` that are not automatically enabled due to having possibly-negative side effects. -/// `MAPPABLE_PRIMARY_BUFFERS` can have a significant, negative performance impact so should not be -/// automatically enabled. -pub const DEFAULT_DISABLED_WGPU_FEATURES: wgpu::Features = wgpu::Features::MAPPABLE_PRIMARY_BUFFERS; - /// Initializes the renderer by retrieving and preparing the GPU instance, device and queue /// for the specified backend. pub async fn initialize_renderer( @@ -78,7 +73,8 @@ pub async fn initialize_renderer( .await .expect("Unable to find a GPU! Make sure you have installed required drivers!"); - info!("{:?}", adapter.get_info()); + let adapter_info = adapter.get_info(); + info!("{:?}", adapter_info); #[cfg(feature = "wgpu_trace")] let trace_path = { @@ -91,9 +87,16 @@ pub async fn initialize_renderer( let trace_path = None; if matches!(options.priority, WgpuOptionsPriority::Functionality) { - options.features = (adapter.features() - | wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES) - - DEFAULT_DISABLED_WGPU_FEATURES; + let mut features = + adapter.features() | wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES; + if adapter_info.device_type == wgpu::DeviceType::DiscreteGpu { + // `MAPPABLE_PRIMARY_BUFFERS` can have a significant, negative performance impact for + // discrete GPUs due to having to transfer data across the PCI-E bus and so it + // should not be automatically enabled in this case. It is however beneficial for + // integrated GPUs. + features -= wgpu::Features::MAPPABLE_PRIMARY_BUFFERS; + } + options.features = features; options.limits = adapter.limits(); }