mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-14 19:27:01 -04:00
Merge origin/main into profile-gain-table-map (RENDER_CACHE_VERSION: main's 21 + 1 = 22)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
95d8aed986
28 files changed
+1539
-154
No files matched your search
@@ -121,6 +121,30 @@ pub fn window_backends() -> Backends {
|
||||
resolve(choice, default, wgpu::Instance::enabled_backend_features()).unwrap_or(default)
|
||||
}
|
||||
|
||||
/// The DX12 shader compiler: FXC (`d3dcompiler_47.dll`, part of Windows) unless
|
||||
/// `WGPU_DX12_COMPILER` (`wgpu`, wgpu's own variable: `fxc`, `dxc`, `auto`…) names another.
|
||||
///
|
||||
/// Issue #471: wgpu's default (`Auto`) loads whichever `dxcompiler.dll` the DLL search path finds
|
||||
/// first — LightCraft ships none, so it is some other program's (an SDK's, a folder on `PATH`). A
|
||||
/// copy without its `dxil.dll` beside it warns that the DXIL is unsigned; wgpu takes the warning for
|
||||
/// a compile error, its own validation pipelines fail, the device is lost and the window never
|
||||
/// opens. FXC is always there and compiles everything LightCraft's shaders need.
|
||||
pub fn dx12_compiler(env: Option<&str>) -> wgpu::Dx12Compiler {
|
||||
let Some(v) = env else { return wgpu::Dx12Compiler::Fxc };
|
||||
v.parse().unwrap_or_else(|e| {
|
||||
log::warn!("gpu: WGPU_DX12_COMPILER={v} ignored: {e}");
|
||||
wgpu::Dx12Compiler::Fxc
|
||||
})
|
||||
}
|
||||
|
||||
/// wgpu's backend options for every instance LightCraft creates — the window's and the compute
|
||||
/// devices': wgpu's environment variables, with the DX12 compiler from [`dx12_compiler`].
|
||||
pub fn backend_options() -> wgpu::BackendOptions {
|
||||
let mut o = wgpu::BackendOptions::from_env_or_default();
|
||||
o.dx12.shader_compiler = dx12_compiler(std::env::var("WGPU_DX12_COMPILER").ok().as_deref());
|
||||
o
|
||||
}
|
||||
|
||||
/// `LIGHTCRAFT_GPU_BACKEND=off`.
|
||||
pub(crate) fn env_off() -> bool {
|
||||
env_choice() == BackendChoice::Off
|
||||
@@ -211,6 +235,20 @@ mod tests {
|
||||
assert!(default_window_backends("linux").contains(Backends::VULKAN | Backends::GL));
|
||||
}
|
||||
|
||||
/// Issue #471: DX12 shaders compile with FXC, never a `dxcompiler.dll` found on the search path,
|
||||
/// unless `WGPU_DX12_COMPILER` asks for it.
|
||||
#[test]
|
||||
fn dx12_compiles_with_fxc_unless_asked() {
|
||||
assert!(matches!(dx12_compiler(None), wgpu::Dx12Compiler::Fxc));
|
||||
assert!(matches!(dx12_compiler(Some("bogus")), wgpu::Dx12Compiler::Fxc));
|
||||
assert!(matches!(dx12_compiler(Some("FXC")), wgpu::Dx12Compiler::Fxc));
|
||||
assert!(matches!(dx12_compiler(Some("dxc")), wgpu::Dx12Compiler::DynamicDxc { .. }));
|
||||
assert!(matches!(dx12_compiler(Some("auto")), wgpu::Dx12Compiler::Auto));
|
||||
if std::env::var_os("WGPU_DX12_COMPILER").is_none() {
|
||||
assert!(matches!(backend_options().dx12.shader_compiler, wgpu::Dx12Compiler::Fxc));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_against_the_build() {
|
||||
let compiled = Backends::DX12 | Backends::VULKAN;
|
||||
|
||||
@@ -282,6 +282,8 @@ impl Gpu {
|
||||
let mut desc = wgpu::InstanceDescriptor::new_without_display_handle();
|
||||
// only these drivers are loaded (`crate::backend`: never Vulkan on Windows unless asked)
|
||||
desc.backends = backends;
|
||||
// DX12 shaders compile with FXC (issue #471)
|
||||
desc.backend_options = crate::backend::backend_options();
|
||||
let instance = wgpu::Instance::new(desc);
|
||||
let adapter = pollster::block_on(
|
||||
instance.request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, ..Default::default() }),
|
||||
|
||||
@@ -76,6 +76,8 @@ fn create_device() -> Result<Dev, String> {
|
||||
fn make_device(backends: wgpu::Backends) -> Result<Dev, String> {
|
||||
let mut desc = wgpu::InstanceDescriptor::new_without_display_handle();
|
||||
desc.backends = backends;
|
||||
// DX12 shaders compile with FXC (issue #471)
|
||||
desc.backend_options = crate::backend::backend_options();
|
||||
let instance = wgpu::Instance::new(desc);
|
||||
let wanted = std::env::var("LIGHTCRAFT_GPU_ADAPTER").ok().map(|s| s.trim().to_lowercase()).filter(|s| !s.is_empty());
|
||||
let adapter = match &wanted {
|
||||
|
||||
Reference in new issue
Block a user