From cbddf50a41720f85e5a2828d1ce147042e141924 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 20 Mar 2021 14:31:39 -0400 Subject: [PATCH] Allow setting env var to only use the vulkan backend, deactivate profiling if the feature is not available --- voxygen/src/render/renderer.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index af8e31e921..473640823a 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -125,12 +125,13 @@ pub struct Renderer { profiler: wgpu_profiler::GpuProfiler, profile_times: Vec, + profiler_features_enabled: bool, } impl Renderer { /// Create a new `Renderer` from a variety of backend-specific components /// and the window targets. - pub fn new(window: &winit::window::Window, mode: RenderMode) -> Result { + pub fn new(window: &winit::window::Window, mut mode: RenderMode) -> Result { // Enable seamless cubemaps globally, where available--they are essentially a // strict improvement on regular cube maps. // @@ -140,9 +141,16 @@ impl Renderer { // TODO: fix panic on wayland with opengl? // TODO: fix backend defaulting to opengl on wayland. - let instance = wgpu::Instance::new( - wgpu::BackendBit::PRIMARY, /* | wgpu::BackendBit::SECONDARY */ - ); + let only_vulkan = std::env::var("ONLY_VULKAN") + .ok() + .map_or(false, |s| &s == "1" || &s == "true"); + let backend_bit = if only_vulkan { + info!("Only requesting Vulkan backend due to ONLY_VULKAN env var being set"); + wgpu::BackendBit::VULKAN + } else { + wgpu::BackendBit::PRIMARY /* | wgpu::BackendBit::SECONDARY */ + }; + let instance = wgpu::Instance::new(backend_bit); let dims = window.inner_size(); @@ -174,12 +182,22 @@ impl Renderer { // TODO: make optional based on enabling profiling // NOTE: requires recreating the device/queue is this setting changes // alternatively it could be a compile time feature toggle - | wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES, + | (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES), limits, }, None, ))?; + let profiler_features_enabled = device + .features() + .contains(wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES); + if !profiler_features_enabled { + info!( + "The features for GPU profiling (timestamp queries) are not available on this \ + adapter" + ); + } + let info = adapter.get_info(); info!( ?info.name, @@ -351,6 +369,7 @@ impl Renderer { let quad_index_buffer_u32 = create_quad_index_buffer_u32(&device, QUAD_INDEX_BUFFER_U32_START_VERT_LEN as usize); let mut profiler = wgpu_profiler::GpuProfiler::new(4, queue.get_timestamp_period()); + mode.profiler_enabled &= profiler_features_enabled; profiler.enable_timer = mode.profiler_enabled; profiler.enable_debug_marker = mode.profiler_enabled; @@ -383,6 +402,7 @@ impl Renderer { profiler, profile_times: Vec::new(), + profiler_features_enabled, }) } @@ -391,6 +411,8 @@ impl Renderer { self.mode = mode; self.sc_desc.present_mode = self.mode.present_mode.into(); + // Only enable profiling if the wgpu features are enabled + self.mode.profiler_enabled &= self.profiler_features_enabled; // Enable/disable profiler if !self.mode.profiler_enabled { // Clear the times if disabled