Files
skylar taylor-barrick e944599ef4 Share one GPU device in the thumbnail tests (#4992)
* Share one GPU device in the thumbnail tests

gpu_drawn_fixture created a new wgpu instance, adapter and device for every
test. Its vkEnumeratePhysicalDevices unloads drivers that expose no device,
while another test thread's render calls vkSetDebugUtilsObjectNameEXT on the
process-wide device; Vulkan loaders before 1.4.345 then walk freed loader
state and crash with SIGSEGV (KhronosGroup/Vulkan-Loader#1863). The fixture
now reuses the render device (gpu::shared_device), or one process-wide device
that is never dropped.

render::thumbnail_tests looped 200 times (2 test threads): 31/200 SIGSEGV
before, 0/200 after.

* Keep the thumbnail tests' fallback device from racing the render device

gpu::shared_device returned None while the render device could still be
created later (GPU rendering turned off by another test through app.gpu, the
window's device pending), and gpu_drawn_fixture then created a Vulkan instance
of its own while another thread's render could create and use the render
device: the Vulkan-Loader#1863 race again. shared_device now creates the render
device whatever the preference, and waits while the window's device is being
adopted, so None means no render device can exist in this process any more
(switched off by the environment, creation failed, or the process is ending).
The fixture creates its own device only when the environment switches the GPU
off or creating the device failed: once the process is ending it skips the
test rather than create a device during teardown. The wait for the window's
device has a 60 s deadline and then panics, since returning None would let the
fixture race the window's device.

shared_device overrides the switch that keeps the GPU off (also after a launch
that crashed creating the device, #136), so the app must not have it: it now
exists only in the gpu crate's tests and with a new test-support feature, off
by default, which only dev-dependencies turn on (ui-egui's, and the gpu crate's
own for tests/shared_device.rs). The app's and the workspace's normal builds
don't have it.

The fixture's texture work runs inside error scopes, so an error in it fails
the test instead of stopping GPU rendering for every test in the process.

tests/shared_device.rs: with GPU rendering off and the window's device pending,
shared_device waits for the adoption and settles the render device.
render::thumbnail_tests looped 100 times (2 test threads): 100/100 passed;
with LIGHTCRAFT_GPU=0 (the fixture's own device) 50/50 passed.
2026-12-02 08:34:06 -06:00
..