Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ jobs:
packages=$(sed -n 's/^packages=//p' "$RUNNER_TEMP/ci-affected")
}
# Whether the NUL-separated paths in $1 (the diff $2) reach what the Windows D3D12 jobs
# exercise: the GPU crate and its shaders, the app and its startup, the viewport's wgpu
# glue, the vendored egui-wgpu and kernel, their scripts, the control server (its refusals,
# #10967), or a lockfile change that moves the graphics stack (wgpu, naga, egui, winit,
# windows). Pull requests and merge groups share it.
# exercise: the GPU crate and its shaders, the shared viewport GPU crate, the app and its
# startup, the viewport's wgpu glue, the vendored egui-wgpu, wgpu-hal and kernel, their
# scripts, the control server (its refusals, #10967), or a lockfile change that moves the
# graphics stack (wgpu, naga, egui, winit, windows). Pull requests and merge groups share it.
windows_paths() {
while IFS= read -r -d '' path; do
case "$path" in
crates/gpu/*|apps/solidcraft/*|crates/ui-egui/src/gpu.rs|vendor/egui-wgpu/*|solidcore/*|crates/control/src/server.rs) windows=true ;;
crates/gpu/*|crates/viewport-gpu/*|apps/solidcraft/*|crates/ui-egui/src/gpu.rs|vendor/egui-wgpu/*|vendor/wgpu-hal/*|solidcore/*|crates/control/src/server.rs) windows=true ;;
tools/windows-*.ps1|.github/workflows/ci.yml|rust-toolchain*|.cargo/*) windows=true ;;
esac
done < "$1"
Expand Down Expand Up @@ -1074,7 +1074,8 @@ jobs:
# DXC, Vulkan and Metal: a shader it cannot compile once crashed the app at startup. Build the
# GPU tessellation pipeline with FXC on the runner's WARP software adapter and compare its
# results with the CPU, and draw headless pictures with the viewport's pipelines there
# (crates/gpu/tests/capture.rs).
# (crates/gpu/tests/capture.rs), and build the viewport's pipelines on several threads again
# and again (crates/viewport-gpu/src/concurrent.rs).
windows-fxc:
name: Windows D3D12 FXC shaders
needs: changes
Expand Down Expand Up @@ -1102,6 +1103,9 @@ jobs:
# pipelines at once, which the parallel tests do. Minidumps showed it in WARP itself, not
# in SolidCraft or FXC; serial runs never hit it.
- run: cargo test -p solidcraft-gpu --profile ci --locked -- --test-threads=1
# The viewport's pipelines built on several threads, where FXC's shared blobs crashed the
# app at startup (#8530).
- run: cargo test -p solidcraft-viewport-gpu --profile ci --locked --lib -- the_viewports_pipelines

# The Windows app starts D3D12 first and only the backend it uses (a Vulkan driver crashed the
# app at startup on Intel). Start the real app on the runner (its D3D12 adapter is WARP) with
Expand Down
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ copied into SolidCraft.

| Directory | Source | Licence | Changes |
|---|---|---|---|
| vendor/wgpu-hal | wgpu-hal 30.0.1, https://github.com/gfx-rs/wgpu (gfx-rs developers) | MIT OR Apache-2.0 | Direct3D 12's shader cache keeps copies of the compiled bytecode, not the compiler's objects: a backport of gfx-rs/wgpu#10805 (vendor/README.md) |

## Vendored renderer compatibility fix

Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ debug = "line-tables-only"
# Keep OpenGL pipelines, resolve textures and CAD callbacks at the same safe sample count.
egui-wgpu = { path = "vendor/egui-wgpu" }

# Direct3D 12's shader cache holds copies of the compiled bytecode, not FXC's blobs, whose
# reference count is not thread-safe: pipelines built on several threads crashed at start (#8530).
wgpu-hal = { path = "vendor/wgpu-hal" }

# Deliver trackpad pinch and rotation gestures on Wayland (zwp_pointer_gestures_v1), which
# winit 0.30 never binds and eframe 0.37 still requires winit 0.30.
winit = { path = "vendor/winit" }
Expand Down
37 changes: 37 additions & 0 deletions crates/viewport-gpu/src/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
//! thread. wgpu hands every thread one DXC compiler, which is not documented as safe to share,
//! and OpenGL works through one context. There, and in the browser, which has no threads, each
//! job runs when it is joined, one after another, as before.
//! - On Direct3D 12, the threads need `vendor/wgpu-hal` (#8530): wgpu-hal 30's shader cache
//! handed the jobs that share a shader one FXC blob, whose reference count is not thread-safe,
//! and a lost reference freed it while the cache still held it (a crash at start). The vendored
//! copy keeps the compiled bytes instead (gfx-rs/wgpu#10805).

#[cfg(target_arch = "wasm32")]
use std::marker::PhantomData;
Expand Down Expand Up @@ -269,4 +273,37 @@ mod tests {
});
assert_eq!(built, 7);
}

/// The viewport's pipelines, built on several threads again and again on one device (#8530).
/// On Direct3D 12 with FXC, every build after the first takes its shaders from wgpu-hal's
/// cache, and the jobs that share a shader take it at the same time. Before the vendored fix
/// (vendor/wgpu-hal), they shared one FXC blob whose reference count is not thread-safe, and
/// the test process died of heap corruption or an access violation: in 6 of 9 runs of 5,000
/// builds on an NVIDIA GPU, and in 2 of 4 runs of 2,000 builds on WARP. 300 builds catch that
/// in only some runs; for a longer run, in PowerShell on Windows (FXC named, since DXC builds
/// on one thread):
/// `$env:WGPU_BACKEND='dx12'; $env:WGPU_DX12_COMPILER='fxc'; $env:VIEWPORT_TEST_PIPELINE_BUILDS='5000'`,
/// then `cargo test -p solidcraft-viewport-gpu the_viewports_pipelines`.
/// Other backends have no such cache and compile every build, so they build twice. Only a
/// missing adapter skips the test, and not with `VIEWPORT_TEST_REQUIRE_GPU` (the Windows CI job).
#[test]
fn the_viewports_pipelines_build_again_and_again_on_several_threads() {
let (adapter, device, _) = match crate::open_headless(crate::test_env::policy()) {
Ok(d) => d,
Err(e @ crate::GpuError::NoAdapter(_)) if crate::test_env::skip_unless_required(crate::test_env::required(), &e) => return,
Err(e) => panic!("the pipeline builds need a GPU: {e}"),
};
let d3d12 = adapter.get_info().backend == wgpu::Backend::Dx12;
let builds = std::env::var("VIEWPORT_TEST_PIPELINE_BUILDS").ok().and_then(|n| n.parse().ok()).unwrap_or(if d3d12 { 300 } else { 2 });
let target = crate::view::GpuTarget {
format: wgpu::TextureFormat::Rgba8Unorm,
depth: Some(crate::depth_format(&device, true)),
samples: 4,
tess: false,
oit: false,
};
for _ in 0..builds {
drop(crate::view::Renderer::new(&device, target, None));
}
}
}
19 changes: 19 additions & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ SolidCraft changes:
`egui_pipeline` shader compilation, #6648) returns `WgpuError::CreateRendererError` through
eframe so startup can retry another backend instead of invoking wgpu's panic handler.

## wgpu-hal 30.0.1 (MIT OR Apache-2.0, gfx-rs developers, https://github.com/gfx-rs/wgpu)

The published package, with both original licence texts. Not copied: `README.md`, `examples/`
and the package's `Cargo.lock`. Drop this copy when SolidCraft moves to a wgpu release that has
gfx-rs/wgpu#10805, or another fix for gfx-rs/wgpu#10547.

SolidCraft changes:
- `src/dx12/mod.rs`, `src/dx12/shader_compilation.rs`, `src/dx12/device.rs`: gfx-rs/wgpu#10805,
backported. Direct3D 12's shader cache keeps an `Arc<[u8]>` copy of each compiled shader, not
the compiler's COM object. With FXC (SolidCraft's compiler on Windows unless `dxcompiler.dll`
is beside the app), the threads that build pipelines from the same shader got clones of one
`ID3DBlob`. FXC counts that object's references without atomic operations, so a lost
reference freed it while the cache still held it, and the next cache hit crashed. SolidCraft
has built the viewport's pipelines on several threads since 0.25.0
(`crates/gpu/src/concurrent.rs`), so the app could crash during start (#8530, #9065, #11743).
DXC's output is copied the same way.
- `Cargo.toml`: drop the example targets and the dev-dependencies (their sources are not
vendored).

## winit 0.30.13 (Apache-2.0, © The winit contributors, https://github.com/rust-windowing/winit)

Original package sources from the 0.30.13 release, with the upstream licence retained. Example
Expand Down
Loading
Loading