Skip to content

Commit ec88fca

Browse files
superdumpcart
authored andcommitted
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.
1 parent d114090 commit ec88fca

File tree

1 file changed

+12
-9
lines changed
  • crates/bevy_render/src/renderer

1 file changed

+12
-9
lines changed

crates/bevy_render/src/renderer/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ pub type RenderQueue = Arc<Queue>;
6161
/// aswell as to create [`WindowSurfaces`](crate::view::window::WindowSurfaces).
6262
pub type RenderInstance = Instance;
6363

64-
/// `wgpu::Features` that are not automatically enabled due to having possibly-negative side effects.
65-
/// `MAPPABLE_PRIMARY_BUFFERS` can have a significant, negative performance impact so should not be
66-
/// automatically enabled.
67-
pub const DEFAULT_DISABLED_WGPU_FEATURES: wgpu::Features = wgpu::Features::MAPPABLE_PRIMARY_BUFFERS;
68-
6964
/// Initializes the renderer by retrieving and preparing the GPU instance, device and queue
7065
/// for the specified backend.
7166
pub async fn initialize_renderer(
@@ -78,7 +73,8 @@ pub async fn initialize_renderer(
7873
.await
7974
.expect("Unable to find a GPU! Make sure you have installed required drivers!");
8075

81-
info!("{:?}", adapter.get_info());
76+
let adapter_info = adapter.get_info();
77+
info!("{:?}", adapter_info);
8278

8379
#[cfg(feature = "wgpu_trace")]
8480
let trace_path = {
@@ -91,9 +87,16 @@ pub async fn initialize_renderer(
9187
let trace_path = None;
9288

9389
if matches!(options.priority, WgpuOptionsPriority::Functionality) {
94-
options.features = (adapter.features()
95-
| wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES)
96-
- DEFAULT_DISABLED_WGPU_FEATURES;
90+
let mut features =
91+
adapter.features() | wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
92+
if adapter_info.device_type == wgpu::DeviceType::DiscreteGpu {
93+
// `MAPPABLE_PRIMARY_BUFFERS` can have a significant, negative performance impact for
94+
// discrete GPUs due to having to transfer data across the PCI-E bus and so it
95+
// should not be automatically enabled in this case. It is however beneficial for
96+
// integrated GPUs.
97+
features -= wgpu::Features::MAPPABLE_PRIMARY_BUFFERS;
98+
}
99+
options.features = features;
97100
options.limits = adapter.limits();
98101
}
99102

0 commit comments

Comments
 (0)