From 33ef5b5039ce4bea9b33199c1e5649dc858a6d4c Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Mon, 31 Jan 2022 01:22:17 +0000 Subject: [PATCH] bevy_render: Only auto-disable mappable primary buffers for discrete GPUs (#3803) # Objective - While it is not safe to enable mappable primary buffers for all GPUs, it should be preferred for integrated GPUs where an integrated GPU is one that is sharing system memory. ## Solution - Auto-disable mappable primary buffers only for discrete GPUs. If the GPU is integrated and mappable primary buffers are supported, use them. --- 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(); }