Skip to content

Commit

Permalink
bevy_render: Only auto-disable mappable primary buffers for discrete …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
superdump committed Jan 31, 2022
1 parent ca029ef commit 33ef5b5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions crates/bevy_render/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ pub type RenderQueue = Arc<Queue>;
/// 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(
Expand All @@ -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 = {
Expand All @@ -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();
}

Expand Down

0 comments on commit 33ef5b5

Please sign in to comment.