When a map error first appeared on poll_reads' second pass and its
device-loss probe recorded a validation error, the call returned the map
error and left the other reads pending. A third pass now runs only when
a polling fault is recorded, and fails those reads in the same call.
The salvage path also reads the non-out-of-memory error flag again after
it sees a loss, before it copies mapped bytes.
docs/gpu-backends.md states when a mapped read returns its bytes after
the call detects a loss.
poll_reads skipped the rescan after a map error when the callback counter
had not changed since the scan. A callback stores its result before it
increments the counter, so a read that mapped during the scan was skipped
and then failed with DeviceLost. The counter is removed, and poll_reads
always collects mapped reads after a map error probe unless an error
disqualifies them.
submit_read_copy now checks health.fault() after a validity probe that
returned Ok, so an out-of-memory error recorded during that probe fails
the read instead of registering it. Device loss is still reported first.
poll_reads counts map callbacks and rescans pending reads after a map
error only when a callback ran since the last scan.
poll_reads copies reads whose map succeeded when the loss is first recorded by its own polls, on either pass; a loss recorded before the call still fails every pending read. The wait validity check copies every read whose map succeeded, including reads mapped before the check. poll_reads reads the non-out-of-memory error flag before the polling fault. upload_buffer and the read copy submission report an out-of-memory error recorded by their validity probe before a validation error recorded in the same poll.
Reads already mapped before the check, reads whose mapped range can no longer be read, and reads after a non-out-of-memory error stay pending, so poll_reads fails them with the device loss.
The blocking read wait collects reads that mapped during its blocking
poll, and collects mapped reads only when no error other than out of
memory was recorded, even when a device loss was recorded in the same
poll. The poll_reads drain copies successful maps before it probes a
sibling's map error, collects reads that map during each probe, stops
probing after the first device loss, and does not copy a read after a
validation fault disqualified it. DeviceHealth::has_non_oom_error
reports a recorded non-out-of-memory error regardless of loss
precedence.
read_buffer's wait now moves reads whose map has completed to the ready
outcomes after each validity check, while the device is still valid, so a
queue callback that destroys the device on the next poll no longer turns a
mapped read into GpuFault::DeviceLost.
poll_reads now returns the bytes of a read whose map completed during the
validity check's poll before it fails the reads still waiting with
GpuFault::DeviceLost. The map-error fan-out test now has an unresolved read
before the failed map and a mapped read after it, and checks that each read
gets exactly one loss outcome.
When a queue callback destroys the device while one read has mapped and
another is still waiting, poll_reads now returns the mapped bytes and
fails only the waiting read with DeviceLost.
poll_reads now runs the device validity check when no read is pending, so
device_status reports a destroyed device found by an idle poll. It polls
before checking whether reads are ready, so a read whose map completes in
the same poll returns its bytes. upload_buffer checks the device health
again after its validity probe and returns an out-of-memory error recorded
during that probe instead of a handle.
A poll callback can destroy a shared device, and wgpu delivers the loss
only on a later poll, so check_device_valid now polls first and then runs
its validation probe. The map-error fan-out test now makes every map
ready, so it exercises the fan-out rather than the pending-read check.
A destroyed shared device can defer its loss callback until the queue
drains, so poll_reads and the blocking wait in read_buffer now run the
device validity check while a read's map has not completed, and fail the
pending reads with GpuFault::DeviceLost. request_read also returns the
recorded work fault before a non-loss error from its validity probe, so
out of memory keeps its precedence.
request_read checks the recorded work fault again after its device check, so
an out-of-memory error that a callback records during that check stops the
read before it allocates a staging buffer. with_device documents that the
queue must be the one opened with the device.
- An allocation error, a failed read wait, an oversized upload and a bad read
handle check the device and return GpuFault::DeviceLost when it was
destroyed while wgpu still defers its device-lost callback.
- poll_reads checks the device before failing pending reads with a recorded
error, and when a mapped read's error turns out to be a loss, every
outstanding read fails with that loss in the same call.
- upload_buffer and request_read check the device before returning a
recorded error other than a loss, so a device destroyed while its loss
callback is deferred reports GpuFault::DeviceLost. An out-of-memory error
still takes precedence over a validation error on a valid device.
- craft_gpu_device::native_descriptor includes OpenGL on Windows when it is
the only compiled native backend, and craft-gpu-wgpu uses that descriptor.
- An allocation error whose handling finds the device lost returns
GpuFault::DeviceLost instead of an allocation error, in upload_buffer and
request_read.
- request_read checks the device after submitting its copy, so a copy that a
destroyed device rejected does not become a pending read.
- On Windows, the context's instance includes OpenGL when it is the only
compiled native backend.
- craft_gpu_device::native_instance returns OpenError::NoAdapter when no wgpu
backend is compiled, instead of wgpu panicking.
- docs/gpu-backends.md says read_buffer waits for the read's own copy
submission.
request_read checks the device for every read, not only empty ones, so a
nonempty read on a device destroyed while earlier work is pending returns
DeviceLost instead of a request for a copy that was never submitted.
- read_buffer waits on the copy submission of the read it was asked for
instead of an empty submission, so it does not also wait for work other
users of the shared queue submitted later.
- An empty read checks that the device is still valid before it queues its
empty result, so a destroyed device fails the read with DeviceLost.
- When no wgpu backend is compiled for the target, the context uses the
staging path and probe_caps reports no adapter, instead of wgpu panicking
while creating the instance.
wgpu 30.0.1 runs a destroyed device's lost callback only once its queue is
empty, and a device loss bypasses error scopes, so the single poll after the
upload could leave device_status() at Ok and register a handle for a buffer
that was never created.
upload_buffer now checks the device with a scoped zero-size buffer creation:
wgpu-core checks device validity before usage validation, so a valid device
reports a validation error into the scope and a destroyed one reports nothing.
The check does not wait for queue work or enter a backend fence wait. The loss
is recorded with DeviceHealth::confirm_device_lost, which sets device_lost()
while probe keeps polling until wgpu's own callback runs.
A caller that passes its device to `from_opened` or `with_device` can
destroy it. wgpu records the loss only on a later poll, and the upload's
out-of-memory scopes do not catch it, so `upload_buffer` returned a
handle for a buffer that was never created. The upload now polls once
before it keeps the buffer and returns `GpuFault::DeviceLost` when the
device is gone.
`wait_between_reads` checked `DeviceHealth::fault()`, which reports an
out-of-memory error ahead of a recorded validation error. With both
recorded, it skipped the early stop, submitted empty work, and failed the
read with "Out of Memory". It now uses `polling_fault()` for the check and
for the returned error, as `poll_reads` does. An out-of-memory error alone
still waits normally, and a loss is still left to `poll_reads`.
docs/gpu-backends.md no longer says that `adapter-probe` turns on wgpu's
default native backends: the workspace sets wgpu to
`default-features = false`, and native backends come only from the
`native-*` features.
WgpuContext::new and probe_caps each made their own wgpu instance, so every
context loaded and unloaded every installed Vulkan driver. On Ubuntu with
mesa-vulkan-drivers installed, contexts opened from several threads at once
crashed with SIGSEGV while a lavapipe device was in use: cargo test of
craft-gpu-wgpu with adapter-probe,native-vulkan crashed in 3 of 10 runs.
native::instance() now makes the instance once and returns a clone of it on
every later call. WGPU_BACKEND is read on the first call.
read_buffer checks the recorded fault before it submits the empty work it waits on, so a device with an error other than out of memory gets no new submission.
read_buffer waits on the index of an empty submission, through
DeviceHealth::wait, which now polls in 100 ms slices. A validation error
that another user of the device records while the read waits ends the
wait after the current slice, and the read fails with that error.
With `adapter-probe`, `WgpuContext::new` opens its device with
`craft_gpu_device::open` for `Preference::Auto`, so it takes the same adapter,
driver corrections and fallback order as other callers of that crate, and
`probe_caps()` reports the adapter `craft_gpu_device::pick` chooses. The
instance uses `craft_gpu_device::native_descriptor`'s backends (no OpenGL on
Windows) unless `WGPU_BACKEND` names others.
- `WgpuContext::from_opened` takes a `craft_gpu_device::Opened`, and
`WgpuContext::with_device` takes a device, its queue and its `DeviceHealth`
(for example egui's device). The caps are the device's own.
- The context no longer sets a device-lost callback. A loss is read from the
device's `DeviceHealth`, including one another user of that health records,
and `health()` returns it.
- `upload_buffer` and `request_read` also stop on any other fault the health
records, as `GpuFault::Operation`, and allocation errors the context's error
scopes catch are recorded in the health. `device_status()` still reports a
loss only.
- When the device reports such an error while `read_buffer` waits, or the
wait fails, the read is dropped and returns that error instead of polling
until a map that may not complete.
- `adapter-probe` now depends on `craft-gpu-device`, which turns on wgpu's
default native backends.
- craft-gpu's DeviceCaps gains `vendor_id` and `software` (serde
default 0 and false) and `has_feature`. craft-gpu-wgpu fills both.
- `Capabilities` holds a DeviceCaps and reads NV12, P010, 16-bit norm,
f16 and timestamps from its feature names and the vendor from its
vendor id. It derefs to DeviceCaps and converts both ways.
- `list_async` and `open_async` are `list` and `open` as futures, for a
wasm32 web worker. In a browser they request the adapter for the
preference's power; wgpu 30 does not pass the fallback-adapter option
to the browser, so `Software` there opens the browser's adapter.
- The README lists what a caller rebuilds after a device loss.
next documents the whole workspace with -D warnings; main does not, so these come in with the
sync:
- craft-gpu: the crate docs link GpuJob::provider_id; ProviderId is not exported.
- craft-gpu-null, craft-gpu-wgpu: GpuContext is in scope, so its links need no explicit target.
- craft-video: TrackDecoder exists only with a decoder feature, so the error docs name it in code.
- craft-plotter: outer's docs name the grid in words; Grid is private.
- craft-develop: best_offset and synthesize are PhotoCraft's and were not ported, so the
inpaint docs name them in code.
* craft-gpu: add the GPU job traits and the shared providers.
This carries over crates/gpu, crates/gpu-wgpu, crates/gpu-null, and crates/gpu-providers from the cut-down #160 branch, with minimal workspace wiring.
None of these crates names a vendor or any app. craft-gpu defines GpuJob and ProviderRegistry. craft-gpu-null is an in-memory context for tests. craft-gpu-providers holds the shared craft.* WGSL providers. craft-gpu-wgpu is the wgpu backend, native and WebGPU.
* craft-gpu: real device wiring, device loss and async readback (RFC-0022)
Addresses skylartaylor's review gate on #663 at 138f7b2. RFC-0022 has merged
since that review. This follows its acceptance requirements.
WgpuContext now requests a real device. DeviceCaps comes from that device,
reflecting the limits and features actually enabled on it. Buffers are real
wgpu::Buffer values when a device exists. The no-adapter case still degrades
to the same staging behavior as craft-gpu-null. The RFC defines that case
explicitly as the no-adapter path. Device loss is registered via
set_device_lost_callback. It surfaces as GpuFault::DeviceLost. It never
surfaces as a panic. The recovery is stated on GpuContext's trait docs.
GpuContext::read_buffer is no longer a required method. The primitives are
request_read and poll_reads. That mirrors craft-worker-host's own
HostMessage::GpuJobs to WorkerMessage::GpuBatchDone split one level down.
read_buffer stays as a default blocking convenience. It resolves immediately
on the null and staging paths. Native wgpu blocks on
Device::poll(wait_indefinitely). On wasm32 it returns GpuFault::Operation,
since a blocking wait there would freeze the one thread map_async's own
callback needs to run on.
crates/gpu-wgpu/src/tests.rs adds a real-backend suite, gated on
adapter-probe plus non-wasm32. It runs upload, readback and device-loss
tests against a real WgpuContext. It also runs three craft-gpu-providers
CPU-stand-in providers against that same real WgpuContext. It skips with a clear message when no adapter is present.
Verified against lavapipe with mesa-vulkan-drivers, using
--features adapter-probe,native-vulkan: every test passes. That run first
caught a real wgpu panic on buffer lengths that are not a multiple of 4,
COPY_BUFFER_ALIGNMENT. The fix pads real buffers transparently. Every caller
still sees exact, unpadded bytes.
docs/gpu-backends.md and docs/gpu-providers.md are updated to match,
including named consumers (the runtime slice first, then EffectCraft and
FilmCraft) and a device-ownership note for when egui's wgpu renderer is also
running.
* craft-gpu: buffer-size guards, empty-buffer parity, read_buffer keeps other completions
Answers the six findings in CodeRabbit review 5852678306 on PR #663.
upload_buffer on the device path refuses a padded size past the device's
max_buffer_size with GpuFault::InvalidJob before creating the buffer.
request_read guards its staging copy the same way. An oversized request
used to reach wgpu as a validation error on the device's error scope.
Empty buffers are accepted everywhere, matching craft-gpu-null and the
documented staging parity. The device path resolves an empty readback
immediately (wgpu refuses an empty map range). The blanket InvalidJob on
empty upload bytes is gone.
read_buffer no longer eats completions that belong to another
outstanding request. The wgpu override re-queues them for the next
poll_reads. The null context gains an override that takes only its own
completion. The trait's default-body contract is documented: with the
default body, do not interleave read_buffer with an outstanding
request_read.
ReadbackProvider validates the storage-binding cap directly. The old
chunk_buffer call allocated a Vec of slices only to drop it.
parse_u32 and params_contain refuse an empty prefix or needle.
windows(0) panics and the crate's rule is never to crash.
The manifest guard test now also rejects *-engine dependency lines, per
docs/gpu-providers.md.
* craft-gpu: per-job batch results, wasm staging reads resolve
Two findings CodeRabbit raised against the carried copy on PR 662, fixed here where the crates live. dispatch_batch now answers per job in input order. The old first-failure abort discarded outcomes earlier providers had already produced, leaving the caller nothing to reply with and no way to name the jobs worth retrying. A job fed by a failed predecessor fails honestly on its own bad handles. On wasm32 read_buffer now serves the staging backing, whose reads resolve synchronously. The backing on that target is always staging today. The refusal remains for a read that did not resolve synchronously, guarding the future wasm device backing where blocking would hang the tab.
* Add free_buffer and device_status to GpuContext.
Two CodeRabbit findings against crates/gpu-wgpu, both answered at the
trait level since craft-gpu-null has the exact same gap.
free_buffer (lib.rs:313). Every upload_buffer call added an entry to a
backend's buffer table. So did every output buffer a provider's job
created. Nothing ever removed one. Repeated jobs retained memory for
the whole lifetime of a context. The new required method releases a
buffer's resources. A freed handle behaves as invalid afterward, the
same fault an unknown handle already produces.
device_status (lib.rs:401). poll_reads can only attach a device-lost
fault to a read it has something to attach it to. A caller whose event
loop only polls, with nothing pending when loss happens, could never
observe it. The new method, default Ok(()), covers that gap directly;
a backend with no concept of device loss needs no override.
MemContext in this crate's own tests gets the same free_buffer shape as
craft-gpu-null, to keep it compiling under the new required method.
* Implement free_buffer for NullContext.
buffers moves from Vec<Vec<u8>> to Vec<Option<Vec<u8>>>. A handle is a
stable index. Freeing a slot replaces it with None. Removing it
instead would shift every later handle's index out from under its
caller. buffer_len and request_read now reject a freed index the same
way they already reject one that never existed.
Two new tests. One frees a handle and checks another's index and bytes
stay untouched. One frees a handle twice, and a handle that never
existed, and confirms both are a harmless no-op.
* Fix the no-device caps fallback, capture allocation failures, free buffers.
Four CodeRabbit findings against this crate.
The no-device fallback in WgpuContext::new called probe_caps() again
on request_device failure (lib.rs:228). A second, successful adapter
query would then report the adapter's advertised limits as if they
came from a granted device, for a context that holds none. It now
falls back to the plain, fixed caps probe_caps's own doc comment
already promises for that case.
Allocation failures during buffer creation used to reach wgpu's
default uncaptured-error handler (lib.rs:299). That handler panics.
The size check already in place only catches a request past the
device's advertised maximum. It says nothing about whether the device
can actually allocate that many bytes right now. An error scope around
both the output-buffer and the read-staging-buffer creation converts a
failure into a GpuFault instead.
free_buffer for WgpuContext (lib.rs:313) matches the Option-wrapped
shape just added to craft-gpu-null. Both backings, staging and real
device, release a buffer's resources and make the handle behave as
invalid afterward, without shifting any other handle's index.
device_status for WgpuContext (lib.rs:401) reports device loss through
the trait method just added to GpuContext. A caller that only polls
can now observe loss even with nothing pending.
New tests cover the fixed fallback value and a regression check that
the new allocation error scope does not misfire on an ordinary
allocation. They also cover free_buffer on both the staging and the
real-device path. One more covers device_status observing a destroyed
device with nothing outstanding. A genuine out-of-memory condition is not reliably
reproducible in CI; the allocation-failure test is the honest half of
that fix this can run.
* Fix the error-scope API call and run cargo fmt.
wgpu 30.0.1's Device has no pop_error_scope method. push_error_scope
returns an ErrorScopeGuard. pop() lives on that guard. Keep the guard
from push_error_scope and call pop() on it.
Also drops an unneeded mut on a test binding that never mutates its
context. Also runs cargo fmt on the lines the Option-wrapped buffer
changes touched.
* Drop a needless return clippy flagged in the adapter-probe lane.
The fallback branch in WgpuContext::new is the function's own tail
expression once the real-device branch above it has already returned
early. The explicit return on it was redundant.
* Run cargo fmt on the no-device fallback branch.
* Pop the OOM scope before the call that would misuse a failed buffer.
upload_buffer popped its scope only after write_buffer. request_read
popped its scope only after the copy and its submission. A buffer that
failed to create is invalid. Using an invalid buffer raises a VALIDATION
error that an OutOfMemory-only scope never catches. The default
uncaptured-error handler still panicked on a failed create even with the
scope in place. Pop right after create_buffer in both paths and return
before the buffer is used again, with a separate scope around the later
write or copy.
write_buffer only queues its copy into wgpu's PendingWrites. An upload
with no following submission kept the destination and staging buffers
alive inside wgpu-core until some other submit happened. upload_buffer now
flushes with an empty queue.submit right after its own write_buffer call.
A free_buffer right after an upload can now actually release the
allocation.
* Run cargo fmt on the new ordering test.
* craft-gpu-wgpu: correct the crate docs on wasm32 read_buffer
The staging backing serves wasm32 reads synchronously since the staging-reads fix. Only a read that did not complete synchronously faults. The crate-level summary still described the old unconditional fault.
* craft-gpu: sync the docs with the implemented readback behavior
Review asked for three corrections. The backends doc, the providers doc and the trait docs now state that both bundled backends override read_buffer's default body and that wasm32 serves the staging read, with a fault only for a read that did not resolve synchronously. The runtime follow-up paragraph now records that #662 consumed it. The software Vulkan container run is described as local testing. Hosted CI coverage and the pilot consumers' browser and hardware validation remain their own requirements. Em dashes swept from both docs per the house writing rules.
* has_device: say the answer once, in this file's own shape
Clippy 1.100.0 refuses the old body under `needless_bool`. The `if` returned a
bool literal with a bare `false` after it. The cfg attribute sat on the `if`
itself. The whole statement therefore vanished without the adapter-probe
feature.
Two cfg blocks replace it, one per configuration. `probe_caps` in the same
file already has that shape. `Backing::Device` exists only under that feature.
The clippy suggestion on its own would not compile.
The plain clippy leg never saw this. The line compiles only with adapter-probe
on. The all-features leg catches it, as does any workspace build that unifies
the feature in.