Add env vars to set wgpu backend and wgpu api trace save dir (api trace still needs feature to be set ofc)

This commit is contained in:
Imbris 2021-04-07 21:28:39 -04:00 committed by Avi Weinstock
parent 349ff53c3c
commit 91b6cd7106
2 changed files with 40 additions and 18 deletions

View File

@ -108,7 +108,16 @@ key = "veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc="
winit = { git = "https://gitlab.com/veloren/winit.git", branch = "macos-test-spiffed" } winit = { git = "https://gitlab.com/veloren/winit.git", branch = "macos-test-spiffed" }
vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" } vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" }
# patch wgpu so we can use wgpu-profiler crate # patch wgpu so we can use wgpu-profiler crate
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "c5ee9cd98310aee66fb49bc98f4f65590304e4aa" } wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "d44fc6ff855faf37b63fd711a9f9a916256cedc2" }
# patch gfx-hal for the dx12 backend patch for cube sampling
[patch."https://github.com/gfx-rs/gfx"]
gfx-hal = { path = "../gfx/src/hal" }
gfx-backend-empty = { path = "../gfx/src/backend/empty" }
gfx-backend-vulkan = { path = "../gfx/src/backend/vulkan" }
gfx-backend-gl = { path = "../gfx/src/backend/gl" }
gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" }
gfx-backend-dx11 = { path = "../gfx/src/backend/dx11" }
gfx-backend-metal = { path = "../gfx/src/backend/metal" }
# # Uncomment this to use a local fork of wgpu (for testing purposes) # # Uncomment this to use a local fork of wgpu (for testing purposes)
# [patch.'https://github.com/gfx-rs/wgpu'] # [patch.'https://github.com/gfx-rs/wgpu']

View File

@ -141,15 +141,23 @@ impl Renderer {
// TODO: fix panic on wayland with opengl? // TODO: fix panic on wayland with opengl?
// TODO: fix backend defaulting to opengl on wayland. // TODO: fix backend defaulting to opengl on wayland.
let only_vulkan = std::env::var("ONLY_VULKAN") let backend_bit = std::env::var("WGPU_BACKEND")
.ok() .ok()
.map_or(false, |s| &s == "1" || &s == "true"); .and_then(|backend| match backend.to_lowercase().as_str() {
let backend_bit = if only_vulkan { "vulkan" => Some(wgpu::BackendBit::VULKAN),
info!("Only requesting Vulkan backend due to ONLY_VULKAN env var being set"); "metal" => Some(wgpu::BackendBit::METAL),
wgpu::BackendBit::VULKAN "dx12" => Some(wgpu::BackendBit::DX12),
} else { "primary" => Some(wgpu::BackendBit::PRIMARY),
wgpu::BackendBit::PRIMARY /* | wgpu::BackendBit::SECONDARY */ "opengl" | "gl" => Some(wgpu::BackendBit::GL),
}; "dx11" => Some(wgpu::BackendBit::DX11),
"secondary" => Some(wgpu::BackendBit::SECONDARY),
"all" => Some(wgpu::BackendBit::all()),
_ => None,
})
.unwrap_or(
wgpu::BackendBit::PRIMARY, /* | wgpu::BackendBit::SECONDARY */
);
let instance = wgpu::Instance::new(backend_bit); let instance = wgpu::Instance::new(backend_bit);
let dims = window.inner_size(); let dims = window.inner_size();
@ -172,21 +180,26 @@ impl Renderer {
..Default::default() ..Default::default()
}; };
let (device, queue) = futures::executor::block_on(adapter.request_device( let (device, queue) = futures::executor::block_on(
&wgpu::DeviceDescriptor { adapter.request_device(
// TODO &wgpu::DeviceDescriptor {
label: None, // TODO
features: wgpu::Features::DEPTH_CLAMPING label: None,
features: wgpu::Features::DEPTH_CLAMPING
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER | wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgpu::Features::PUSH_CONSTANTS | wgpu::Features::PUSH_CONSTANTS
// TODO: make optional based on enabling profiling // TODO: make optional based on enabling profiling
// NOTE: requires recreating the device/queue is this setting changes // NOTE: requires recreating the device/queue is this setting changes
// alternatively it could be a compile time feature toggle // alternatively it could be a compile time feature toggle
| (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES), | (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES),
limits, limits,
}, },
None, std::env::var_os("WGPU_TRACE_DIR")
))?; .as_ref()
.map(|v| std::path::Path::new(v))
.or(Some("./wgpu-trace".as_ref())),
),
)?;
let profiler_features_enabled = device let profiler_features_enabled = device
.features() .features()