crcbl_hal/capability.rs
1//! Seam behaviours a backend must answer for, and the parity record of which
2//! ones actually diverge.
3//!
4//! # Why this is not [`Features`]
5//!
6//! The two are different questions, and merging them loses the property this
7//! module exists for:
8//!
9//! | | [`Features`] | [`Capability`] |
10//! | --- | --- | --- |
11//! | Names | an optional capability a **caller requests** at device creation | a seam behaviour a **backend must answer for** |
12//! | Shape | `bitflags` | `enum` + exhaustive `match` |
13//! | A backend that says nothing | reports the flag clear, silently | **does not compile** |
14//!
15//! [`Features`] is a *request* channel: a caller names what it
16//! needs in [`DeviceDesc::required_features`](crate::DeviceDesc::required_features),
17//! an adapter that lacks it fails loudly, and everything else degrades. That is
18//! the right shape for what it does and it is not changing.
19//!
20//! What a bitflag cannot do is make a *backend* answer. A flag is a bit, and a
21//! backend that never sets a new one compiles, links and runs — it simply
22//! reports the capability absent, which is indistinguishable from a device that
23//! genuinely lacks it. So a behaviour added to one backend costs nothing
24//! anywhere else: the others never implement it, their refusal is invisible
25//! until something runs, and no test can name what is missing because nothing
26//! declares it exists.
27//!
28//! An `enum` with no wildcard arm inverts that. Adding a variant here is a
29//! compile error in **every** backend that has not said what it does about it,
30//! and the answer it is forced to give names *whose* answer it is:
31//! [`Support::Yes`], [`Support::No`] with a reason a human wrote, or
32//! [`Support::NotOnThisDevice`] — which only [`Support::granted`] hands out, and
33//! which says the refusal came from the device rather than from the backend.
34//!
35//! # Prior art, and why this shape
36//!
37//! Every cross-API engine negotiates capabilities, and the ones that reach for a
38//! bitmask reach for it because C has no better closed set:
39//!
40//! * **wgpu** — `Features` bitflags plus `DownlevelFlags`, validated at call
41//! time. The shape [`Features`] already is, with wgpu's
42//! problem: a backend that omits a flag reports "unsupported" and nothing says
43//! so.
44//! * **Dawn** — `wgpu::FeatureName` is an *enum*, and each backend answers it in
45//! a `switch` compiled with `-Werror=switch`. That is this design, in C++.
46//! * **bgfx** — a `supported` bitmask plus `caps->formats[]`, an array indexed by
47//! the format enum with a static assertion that its length matches the
48//! enumerator count. The array is C's way of buying the same "there must be an
49//! entry for every variant" property the `match` gives here for free.
50//! * **Vulkan itself** — `VkPhysicalDeviceFeatures` is a struct of `VkBool32`, so
51//! a field added to it zero-initialises to `VK_FALSE` in every implementation
52//! that has not heard of it. The same silent-omission failure, one layer down.
53//!
54//! The consistent lesson is that the anti-rot property comes from a **closed
55//! set** plus **an exhaustiveness check**, and from nothing else — not from
56//! discipline, and not from a wider bitmask. Rust supplies both natively, so
57//! this is the known-good design rather than a new one.
58//!
59//! # Cost
60//!
61//! [`Device::supports`](crate::Device::supports) takes a `Copy` enum and returns
62//! a `Copy` enum holding at most a `&'static str`. No allocation, no lock, no
63//! formatting, no table to walk: a backend's implementation is a `match` the
64//! compiler lowers to a jump table or a comparison chain. It is a question asked
65//! at set-up rather than in a frame, but it would be cheap enough to ask in one.
66//!
67//! # What is deliberately **not** a capability here
68//!
69//! * **Which [`SurfaceTarget`](crate::SurfaceTarget) kinds a backend accepts.**
70//! `crcbl-mtl` refuses a Wayland window and `crcbl-vk` refuses an AppKit one,
71//! but that is a platform axis `crcbl-shell` settles before a surface is
72//! asked for — Metal declining X11 is not a parity gap, and modelling it would
73//! add a variant per window system to describe something no two platforms were
74//! ever going to agree on.
75//! * **Numeric ceilings.** [`Limits`](crate::Limits) is the right shape for a
76//! number, and "how big" is not a yes/no question.
77//! * **Caller bugs.** A misaligned `fill_buffer` offset, a bind group written
78//! twice at one index, a swapchain retargeted to a different surface: every
79//! backend refuses these and *should*. A capability is something a caller
80//! could legitimately ask for and be told no.
81//! * **Anything with no refusal behind it.** Every variant below was derived
82//! from a place some backend actually declines to do the thing.
83//!
84//! # The parity record
85//!
86//! [`DIVERGENCES`] is the reviewed list of every (capability, backend) pair that
87//! is knowingly absent, and [`parity_verdict`] is the rule that reads it. It is
88//! the difference between divergence somebody decided and divergence that
89//! happened: a backend that starts refusing something new fails the parity test
90//! until the pair is added with a reason, and a backend that starts supporting
91//! something on the list fails until the pair is removed.
92//!
93//! # Why a refusal has to say whose it is
94//!
95//! The rule needs one more thing to be sound, and it is the reason
96//! [`Support::NotOnThisDevice`] exists. "This device reports no `MESH_SHADER`"
97//! and "this backend never wrote the mesh path" are both a refusal, and the
98//! parity record must excuse the first and demand a row for the second — so the
99//! rule used to guess which it was, by asking whether the *device* reported the
100//! capability's [`gating_feature`](Capability::gating_feature).
101//!
102//! That guess made every gated row **unprovable**: on a device reporting the
103//! flag clear, a pair was excused whether or not [`DIVERGENCES`] named it, so
104//! deleting the row changed nothing anybody could observe and the capability
105//! became one nobody claimed and nothing checked. Eight of `crcbl-mtl`'s nine
106//! rows were that shape.
107//!
108//! A refusal now carries whose it is instead of having it inferred, and it costs
109//! no backend a line to say so: [`Support::granted`] is the one constructor a
110//! device gate is ever expressed through, so every gated arm in every backend
111//! already routes through it. What a backend writes by hand is
112//! [`Support::No`] — its own refusal, which [`parity_verdict`] demands a row for
113//! on **every** device, including one that happens to withhold the flag.
114//!
115//! A reason alone cannot say **what is left**, though — "Metal's blit fill takes
116//! a byte, not a word" and "this backend has not written the code yet" are the
117//! same shape as prose. [`DivergenceKind`] is the field that separates them and
118//! [`parity_blockers`] is the query over it: every row that somebody could still
119//! close, on a backend crcbl is keeping. Parity is reached when that set is
120//! empty, and this module's tests snapshot it so it shrinks deliberately.
121//!
122//! ```
123//! use crcbl_hal::{BackendKind, Capability, DIVERGENCES, DivergenceKind, divergence, parity_blockers};
124//!
125//! // WebGPU has no mesh stage. No work in this repository closes that, so it
126//! // is written down and then left alone.
127//! let permanent = divergence(Capability::MeshShading, BackendKind::WebGpu)
128//! .expect("WebGPU's missing mesh stage is on the list");
129//! assert_eq!(permanent.kind, DivergenceKind::ApiAbsence);
130//! assert!(!permanent.kind.blocks_parity());
131//!
132//! // D3D12's occlusion query is owed rather than absent, so it is one of the
133//! // rows standing between crcbl and its end state.
134//! assert!(parity_blockers().any(|entry| {
135//! entry.capability == Capability::OcclusionQuery && entry.backend == BackendKind::Dx12
136//! }));
137//!
138//! // And Metal's GPU-side draw count is not, because that work landed — the
139//! // list is a record of what is left, not of what was ever hard.
140//! assert!(parity_blockers().all(|entry| {
141//! entry.capability != Capability::DrawIndirectCount || entry.backend != BackendKind::Metal
142//! }));
143//!
144//! // Every entry names a backend that actually drives a GPU.
145//! assert!(DIVERGENCES.iter().all(|entry| entry.backend.is_gpu()));
146//! ```
147
148use core::fmt;
149
150use crate::{BackendKind, Features};
151
152/// Declares [`Capability`] and everything derived from it from one variant list.
153///
154/// The list appears **once**. [`Capability::ALL`] and [`Capability::name`] are
155/// generated from the same tokens as the enum, so neither can drift from it —
156/// which matters because `ALL` is what the parity report and the agnostic seam
157/// suite iterate, and a hand-written array that silently lost a variant would
158/// make both report a clean sweep over a set with a hole in it.
159macro_rules! capabilities {
160 ($(
161 $(#[$meta:meta])*
162 $variant:ident,
163 )+) => {
164 /// One seam behaviour a backend either performs or refuses.
165 ///
166 /// **Every variant exists because some backend refuses it.** See the
167 /// module docs for what is deliberately not modelled, and
168 /// [`Device::supports`](crate::Device::supports) for how a backend
169 /// answers.
170 ///
171 /// Adding a variant is a compile error in every backend until it says
172 /// what it does — that is the whole point, and it is why this is an
173 /// `enum` and not another [`Features`] bit.
174 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
175 pub enum Capability {
176 $(
177 $(#[$meta])*
178 $variant,
179 )+
180 }
181
182 impl Capability {
183 /// Every capability, in declaration order.
184 ///
185 /// Generated from the same list as the enum, so it cannot be missing
186 /// one. The parity report and the agnostic seam suite both walk it.
187 pub const ALL: &'static [Self] = &[$(Self::$variant),+];
188
189 /// How the variant is spelled in source, e.g. `"BufferFillZero"`.
190 ///
191 /// Taken from the declaration rather than written out beside it, so
192 /// a renamed variant cannot keep an old name in a log line.
193 #[must_use]
194 pub const fn name(self) -> &'static str {
195 match self {
196 $(Self::$variant => stringify!($variant),)+
197 }
198 }
199 }
200 };
201}
202
203capabilities! {
204 // --- copies and fills ---
205
206 /// [`clear_buffer`](crate::CommandEncoder::clear_buffer).
207 ///
208 /// **Every backend answers `Yes`, and it is kept anyway.** This enum covers
209 /// what the seam does rather than only what backends disagree about, so a
210 /// capability with no `DIVERGENCES` row is the shape a settled one takes —
211 /// and the agnostic suite still drives it, which is what would notice a
212 /// backend quietly dropping the call.
213 ///
214 /// It had two valued siblings until 2026-08-19,
215 /// `BufferFillRepeatedByte` and `BufferFillWord`. They described how badly
216 /// each backend could keep a promise the seam should not have made: Metal's
217 /// fill repeats a byte and WebGPU has no valued fill at all, so three of
218 /// five had to refuse most values. The verb lost its `value` instead — see
219 /// [`clear_buffer`](crate::CommandEncoder::clear_buffer) — and both rows
220 /// went with it.
221 BufferFillZero,
222
223
224
225 /// [`copy_image_to_image`](crate::CommandEncoder::copy_image_to_image).
226 ///
227 /// Both sides are texture locations with their own subresource and region,
228 /// which is a different call from the buffer↔image copies and is refused
229 /// separately where it is refused at all.
230 ImageToImageCopy,
231
232 /// A buffer↔image copy —
233 /// [`copy_image_to_buffer`](crate::CommandEncoder::copy_image_to_buffer) or
234 /// [`copy_buffer_to_image`](crate::CommandEncoder::copy_buffer_to_image) —
235 /// whose image carries a **depth or depth-stencil** format and whose
236 /// subresource names [`ImageAspect::DEPTH`](crate::ImageAspect::DEPTH).
237 ///
238 /// Separate from the colour copies every backend performs, because a depth
239 /// image is not one plane of one type. An API that stores a *sampled* depth
240 /// texture typeless needs the plane and a fully typed footprint chosen at
241 /// the copy itself, and [`BufferImageCopy`](crate::BufferImageCopy) carries
242 /// neither — so a backend can copy every colour format and still have no
243 /// expression for this one.
244 ///
245 /// It is what a shadow atlas is read back through, which is why it is worth
246 /// declaring rather than discovering: without it there is no way to show
247 /// that a shadow pass wrote anything, and a shadow pass that wrote nothing
248 /// renders a frame in which every surface is lit and nothing looks wrong.
249 ///
250 /// **WHICH depth format and WHICH direction remains the API's own rule.**
251 /// This asks whether a backend has an expression for the copy at all; a
252 /// backend answering [`Support::Yes`] still refuses the pairs its API's
253 /// format table withholds, by name and at the call. WebGPU is the one that
254 /// withholds any — and `wgpu` enforces the same table, so both backends on
255 /// it agree: the depth plane of [`Format::D32Float`](crate::Format::D32Float),
256 /// [`D32FloatS8Uint`](crate::Format::D32FloatS8Uint) and
257 /// [`D16Unorm`](crate::Format::D16Unorm) copies **out** to a buffer, only
258 /// `D16Unorm`'s copies back **in**, and
259 /// [`D24UnormS8Uint`](crate::Format::D24UnormS8Uint)'s copies neither way,
260 /// because WebGPU's `depth24plus` is whatever the driver chose to store and
261 /// so has no memory layout to lay a buffer out against. The readback a
262 /// shadow atlas needs is inside every one of those.
263 DepthImageCopy,
264
265 // --- render pass ---
266
267 /// A [`ColorAttachment::resolve`](crate::ColorAttachment::resolve) view: the
268 /// pass resolves its multisampled colour target into a single-sampled one as
269 /// it ends.
270 MsaaResolveAttachment,
271
272 /// [`set_stencil_reference`](crate::CommandEncoder::set_stencil_reference) —
273 /// the dynamic stencil reference value subsequent draws compare against.
274 ///
275 /// **The claim is the whole rule, not just that the call is wired.** A
276 /// backend declaring this says the reference is pass state that survives a
277 /// pipeline bind, and that a pass which never calls it draws against
278 /// [`stencil::INITIAL_REFERENCE`](crate::stencil::INITIAL_REFERENCE); see
279 /// [`StencilState`](crate::StencilState) on why there is no pipeline-side
280 /// reference to compete with it.
281 StencilReference,
282
283 // --- draws ---
284
285 /// [`draw_indirect_count`](crate::CommandEncoder::draw_indirect_count) and
286 /// its indexed sibling: the draw **count** is read from a GPU buffer, so the
287 /// CPU never learns how many draws a pass emits.
288 ///
289 /// [`Features::DRAW_INDIRECT_COUNT`](crate::Features::DRAW_INDIRECT_COUNT)
290 /// is the flag a caller requests; this is the backend's answer about the two
291 /// encoder methods, which is not the same claim — a backend can report the
292 /// flag without having wired the calls up, and Metal reports it clear *and*
293 /// refuses the calls for a reason that is not about any one device.
294 DrawIndirectCount,
295
296 /// [`DrawIndirect::stride`](crate::DrawIndirect::stride) larger than the
297 /// argument structure: the arguments are **padded** in the buffer rather
298 /// than tightly packed.
299 ///
300 /// Distinct from drawing indirectly at all. Vulkan's `vkCmdDrawIndirect`
301 /// takes a stride and honours it, D3D12 builds an `ID3D12CommandSignature`
302 /// per stride, `crcbl_mtl::indirect_count` walks the structures itself, and
303 /// `crcbl-webgpu`'s replayer unrolls the draw into one `drawIndirect` per
304 /// structure at `offset + i * stride` — an API with no stride parameter can
305 /// still honour one, and the `Yes` says it does rather than that the
306 /// parameter exists.
307 ///
308 /// **The stride a caller may ask for is every API's stride, not this
309 /// seam's.** All four want a multiple of 4 that is at least the argument
310 /// structure's own width, because all four ultimately address the buffer in
311 /// words: Vulkan says so in `vkCmdDrawIndirect`'s own rule for a
312 /// `drawCount` above one, and WebGPU says so as `indirectOffset` being a
313 /// multiple of 4, which `offset + i * stride` only stays for a stride that
314 /// is one too. Nothing this declaration promises makes a stride of 14 legal
315 /// anywhere.
316 IndirectArgumentPaddedStride,
317
318 /// The mesh-shading path: a [`MeshPipelineDesc`](crate::MeshPipelineDesc)
319 /// can be created and
320 /// [`draw_mesh_tasks`](crate::CommandEncoder::draw_mesh_tasks) and
321 /// [`draw_mesh_tasks_indirect`](crate::CommandEncoder::draw_mesh_tasks_indirect)
322 /// recorded against it.
323 ///
324 /// One capability rather than three, because the seam already states the
325 /// tie: `draw_mesh_tasks_indirect` "requires
326 /// [`Features::MESH_SHADER`](crate::Features::MESH_SHADER) and nothing more
327 /// … a device that can launch this stage at all can launch it from memory",
328 /// and no backend refuses the pipeline while admitting the draw or the
329 /// reverse.
330 MeshShading,
331
332 /// The amplification stage in front of a mesh shader —
333 /// [`MeshPipelineDesc::task`](crate::MeshPipelineDesc::task) is `Some`.
334 ///
335 /// Separately optional from [`MeshShading`](Self::MeshShading) for the same
336 /// reason [`Features::TASK_SHADER`](crate::Features::TASK_SHADER) is a
337 /// separate flag: a mesh shader works with a workgroup count computed
338 /// elsewhere, and this stage is only what moves that decision into the draw.
339 TaskShaderStage,
340
341 // --- bindings and pipeline layout ---
342
343 /// [`update_bind_group`](crate::Device::update_bind_group): rewriting an
344 /// already-created bind group's entries in place.
345 ///
346 /// The update-after-bind model, and what a bindless texture table is
347 /// restreamed through. WebGPU bind groups are immutable once created, so a
348 /// backend on it can only rebuild the group.
349 ///
350 /// A backend answers **whether it has the operation at all**. Vulkan
351 /// additionally requires the individual layout to carry
352 /// [`BindingFlags::UPDATE_AFTER_BIND`](crate::BindingFlags::UPDATE_AFTER_BIND),
353 /// which is a property of the layout the caller built rather than of the
354 /// device, and is refused per call.
355 UpdateBindGroup,
356
357 /// [`push_constants`](crate::CommandEncoder::push_constants) and the
358 /// [`PipelineLayoutDesc::push_constants`](crate::PipelineLayoutDesc::push_constants)
359 /// range they are written through.
360 ///
361 /// The seam requires the refusal at **pipeline-layout creation**, not at the
362 /// write, so a caller finds out once rather than losing writes silently
363 /// every frame.
364 PushConstants,
365
366 /// A runtime-sized descriptor array — a
367 /// [`BindGroupLayoutEntry`](crate::BindGroupLayoutEntry) carrying
368 /// [`BindingFlags`](crate::BindingFlags), and the
369 /// [`BindGroupDesc::variable_count`](crate::BindGroupDesc::variable_count)
370 /// that chooses its length.
371 ///
372 /// What [`BindingModel::Bindless`](crate::BindingModel::Bindless) is built
373 /// on. A backend binding flat argument tables has fixed-size arrays and no
374 /// way to express this, which is a different answer from having no arrays.
375 BindlessDescriptorArray,
376
377 /// A [`BindingKind::StorageImage`](crate::BindingKind::StorageImage) entry
378 /// in a bind group layout.
379 ///
380 /// Its own capability because some implementations need the texel format and
381 /// view dimension in the **layout**, which the seam only carries on the
382 /// image view — so the layout cannot be built at all, rather than the
383 /// binding merely being slower.
384 StorageImageBinding,
385
386 // --- rasteriser state ---
387
388 /// [`PolygonMode::Line`](crate::PolygonMode::Line) — wireframe fill.
389 PolygonModeLine,
390
391 /// Depth **clamping** rather than clipping, for shadow casters behind the
392 /// near plane.
393 DepthClamp,
394
395 /// A [`SamplerDesc`](crate::SamplerDesc) with anisotropy above `1.0`.
396 SamplerAnisotropy,
397
398 // --- queries ---
399
400 /// A [`QueryKind::Timestamp`](crate::QueryKind::Timestamp) query set, the
401 /// [`PassTimestampWrites`](crate::PassTimestampWrites) that fill it
402 /// and the [`query_results`](crate::Device::query_results) that read it.
403 TimestampQuery,
404
405 /// A [`QueryKind::Occlusion`](crate::QueryKind::Occlusion) query set.
406 ///
407 /// **No backend has it**, and the reason is the seam's rather than any
408 /// API's: [`NO_OCCLUSION_QUERY_VERB`]. Every GPU backend carries a
409 /// [`DivergenceKind::Unwritten`] row here, which is what it costs to say so
410 /// honestly.
411 OcclusionQuery,
412
413 /// A [`QueryKind::PipelineStatistics`](crate::QueryKind::PipelineStatistics)
414 /// query set.
415 ///
416 /// Three query variants rather than one, because the three are refused
417 /// separately: a device answers each of
418 /// [`Features::TIMESTAMP_QUERY`](crate::Features::TIMESTAMP_QUERY),
419 /// [`OCCLUSION_QUERY`](crate::Features::OCCLUSION_QUERY) and
420 /// [`PIPELINE_STATISTICS_QUERY`](crate::Features::PIPELINE_STATISTICS_QUERY)
421 /// independently, and folding them would let a backend with only timestamps
422 /// claim the lot.
423 PipelineStatisticsQuery,
424
425 /// [`gpu_clock`](crate::Device::gpu_clock): the GPU's timestamp clock read
426 /// from the CPU, on the same timebase and in the same nanoseconds as a
427 /// [`QueryKind::Timestamp`](crate::QueryKind::Timestamp) set's reads.
428 GpuClock,
429
430 // --- synchronisation ---
431
432 /// [`SemaphoreKind::Timeline`](crate::SemaphoreKind::Timeline): a monotonic
433 /// `u64` counter a submission signals and both GPU and CPU can observe.
434 ///
435 /// The claim is the **observable** one — that
436 /// [`semaphore_value`](crate::Device::semaphore_value) reports the counter
437 /// advancing as submissions complete. A backend that hands out a handle
438 /// whose value never moves has not got this, whatever its return codes say.
439 TimelineSemaphore,
440
441 /// [`SemaphoreKind::Binary`](crate::SemaphoreKind::Binary): the one-shot,
442 /// GPU-only signal WSI acquire/present needs.
443 ///
444 /// Apart from [`TimelineSemaphore`](Self::TimelineSemaphore) deliberately. A
445 /// device may have no timeline and must still hand out a binary one, because
446 /// the swapchain is where they come from — and a backend that refused both
447 /// would pass every test that only checks the timeline half.
448 BinarySemaphore,
449
450 /// [`wait_semaphores`](crate::Device::wait_semaphores): the **CPU** blocking
451 /// until a timeline reaches a value.
452 ///
453 /// Distinct from creating one. A backend can hand out a counter a submission
454 /// signals while having no host-side wait to offer, which is what a
455 /// fence-shaped API looks like before its wait half is wired up.
456 CpuTimelineWait,
457
458 /// [`signal_semaphore`](crate::Device::signal_semaphore): the **CPU**
459 /// advancing a timeline, rather than a submission.
460 ///
461 /// Its own capability for the same reason
462 /// [`CpuTimelineWait`](Self::CpuTimelineWait) is: the two host-side halves
463 /// are separable. A backend that emulates a timeline over per-submission
464 /// completion could move a counter on demand and still have no queue-side
465 /// wait to pair it with, and one with a real semaphore object has both.
466 ///
467 /// The claim is the observable one — that
468 /// [`semaphore_value`](crate::Device::semaphore_value) reports the value the
469 /// host asked for, and that a value which would move the timeline backwards
470 /// is refused rather than accepted.
471 CpuTimelineSignal,
472
473 /// Waiting — from the CPU, or in a [`SubmitInfo`](crate::SubmitInfo) — on a
474 /// timeline value that **nothing submitted so far will signal**, expecting
475 /// a later signal to satisfy it.
476 ///
477 /// A real semaphore object blocks until somebody signals it, and
478 /// [`CpuTimelineSignal`](Self::CpuTimelineSignal) is what lets the host be
479 /// the somebody. A backend that emulates timelines over per-submission
480 /// completion has no object for a future signal to arrive on, so such a wait
481 /// could only ever stop the queue; refusing is the honest answer and it is a
482 /// genuine behavioural divergence rather than a missing call.
483 TimelineWaitBeforeSignal,
484}
485
486impl Capability {
487 /// The [`Features`] bit a caller consults before asking for this, if there
488 /// is one.
489 ///
490 /// **What makes the parity rule fair.** A backend that refuses because the
491 /// device reports this flag clear has not diverged from anything — the
492 /// device is simply lesser, which is exactly what [`Features`] already
493 /// models and logs as a downgrade.
494 ///
495 /// It is the *claim* to be in that position that this flag settles.
496 /// [`Support::granted`] is what puts a backend there, and
497 /// [`parity_verdict`] checks the claim against the device before excusing
498 /// it: a [`Support::NotOnThisDevice`] for a capability with no gate, or on a
499 /// device that reports the gate, is
500 /// [`ParityVerdict::FalseDeviceGate`]. What the flag no longer does is
501 /// excuse a refusal the backend made on its own account, which is how the
502 /// rule used to retire [`DIVERGENCES`] rows without anybody deciding to.
503 ///
504 /// `None` means no flag governs it, so every refusal is the backend's own.
505 /// That is the majority here, and it is the measurement this module was
506 /// built from: most refusal sites answer to no declared capability at all.
507 #[must_use]
508 pub const fn gating_feature(self) -> Option<Features> {
509 match self {
510 // Nothing in `Features` describes a buffer clear, which is why the
511 // fills were the divergence that reached CI — and why the two
512 // valued ones are gone: see `CommandEncoder::clear_buffer`.
513 Self::BufferFillZero
514 | Self::ImageToImageCopy
515 | Self::DepthImageCopy
516 | Self::MsaaResolveAttachment
517 | Self::StencilReference
518 | Self::IndirectArgumentPaddedStride
519 | Self::UpdateBindGroup
520 | Self::StorageImageBinding
521 | Self::BinarySemaphore => None,
522 Self::DrawIndirectCount => Some(Features::DRAW_INDIRECT_COUNT),
523 Self::MeshShading => Some(Features::MESH_SHADER),
524 Self::TaskShaderStage => Some(Features::TASK_SHADER),
525 Self::PushConstants => Some(Features::PUSH_CONSTANTS),
526 Self::BindlessDescriptorArray => Some(Features::DESCRIPTOR_INDEXING),
527 Self::PolygonModeLine => Some(Features::POLYGON_MODE_LINE),
528 Self::DepthClamp => Some(Features::DEPTH_CLAMP),
529 Self::SamplerAnisotropy => Some(Features::SAMPLER_ANISOTROPY),
530 Self::TimestampQuery => Some(Features::TIMESTAMP_QUERY),
531 Self::OcclusionQuery => Some(Features::OCCLUSION_QUERY),
532 Self::PipelineStatisticsQuery => Some(Features::PIPELINE_STATISTICS_QUERY),
533 Self::GpuClock => Some(Features::GPU_CLOCK),
534 // All four are about one object, so one flag governs them.
535 Self::TimelineSemaphore
536 | Self::CpuTimelineWait
537 | Self::CpuTimelineSignal
538 | Self::TimelineWaitBeforeSignal => Some(Features::TIMELINE_SEMAPHORE),
539 }
540 }
541}
542
543impl fmt::Display for Capability {
544 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
545 f.write_str(self.name())
546 }
547}
548
549/// Whether a backend performs a [`Capability`], and why not when it does not.
550///
551/// Three arms, and the third is not a third *degree* of support: "maybe",
552/// "partially" and "not yet" are all [`No`](Self::No) with a reason saying
553/// which, because a caller can do nothing different with a shade of no. What
554/// [`NotOnThisDevice`](Self::NotOnThisDevice) adds is **whose** no it is, which
555/// is a different axis and one a caller can act on — a refusal the device
556/// caused may be answered by opening a better adapter, and a refusal the backend
557/// caused never is.
558///
559/// It is also what makes the parity record checkable; see the module docs.
560#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
561pub enum Support {
562 /// The backend performs it **exactly as the seam documents it**, on this
563 /// device.
564 ///
565 /// Not "the API underneath has it" and not "the code is there": this is the
566 /// claim the agnostic seam suite exercises, so a backend saying it and then
567 /// refusing — or quietly doing something else — at the call site is a test
568 /// failure.
569 Yes,
570
571 /// **The backend** refuses, for the reason given, and would refuse on any
572 /// device.
573 ///
574 /// The reason is written for whoever reads the failure, so it names the
575 /// obstacle — the API call that does not exist, the slice that has not
576 /// landed — rather than restating the capability. `&'static str`, so asking
577 /// costs no allocation.
578 ///
579 /// Every one of these needs a [`DIVERGENCES`] row, on every device. A
580 /// backend reaching for this arm when the device is what withheld the
581 /// capability has not cheated the rule so much as opted into a stricter one.
582 No(&'static str),
583
584 /// **The device** withheld the capability's
585 /// [`gating_feature`](Capability::gating_feature), so the backend never got
586 /// to say whether it has it.
587 ///
588 /// Handed out by [`granted`](Self::granted) and nowhere else in this
589 /// workspace, because that is the one place a device gate is read. The
590 /// distinction is not cosmetic: a lesser device is what [`Features`] already
591 /// models and logs as a downgrade at device creation, and holding a software
592 /// rasteriser to a mesh-shader capability would fail the parity suite for a
593 /// reason nobody can fix.
594 ///
595 /// So this arm is *excused* by [`parity_verdict`] — which is exactly why it
596 /// is checked rather than taken on trust: a backend claiming it for an
597 /// ungated capability, or on a device that did report the flag, is
598 /// [`ParityVerdict::FalseDeviceGate`] and fails.
599 NotOnThisDevice(&'static str),
600}
601
602impl Support {
603 /// [`Yes`](Self::Yes) when `features` holds `feature`, otherwise
604 /// [`NotOnThisDevice`](Self::NotOnThisDevice) with `why`.
605 ///
606 /// The shape most arms of a backend's `match` have, written once here
607 /// because five backends were otherwise going to spell the same `if` five
608 /// ways — and because an arm that reads the *wrong* flag is the one mistake
609 /// in this file a reviewer cannot see, so the flag belongs at the call site
610 /// with nothing else beside it.
611 ///
612 /// **Being the only source of [`NotOnThisDevice`](Self::NotOnThisDevice) is
613 /// what the parity rule rests on.** A backend does not have to know that:
614 /// the arms it already routes through here are precisely the arms whose
615 /// refusal belongs to the device, so the classification costs no backend a
616 /// line and cannot be forgotten by one.
617 ///
618 /// `why` stays the caller's: which flag, and what the device would need to
619 /// report, is the sentence the reader of a parity report needs.
620 #[must_use]
621 pub const fn granted(features: Features, feature: Features, why: &'static str) -> Self {
622 if features.contains(feature) {
623 Self::Yes
624 } else {
625 Self::NotOnThisDevice(why)
626 }
627 }
628
629 /// Whether this is [`Support::Yes`].
630 #[must_use]
631 pub const fn is_yes(self) -> bool {
632 matches!(self, Self::Yes)
633 }
634
635 /// The refusal reason, or `None` when supported.
636 ///
637 /// Both refusals answer, because a caller printing "why not" wants the
638 /// sentence whichever of them it was.
639 #[must_use]
640 pub const fn reason(self) -> Option<&'static str> {
641 match self {
642 Self::Yes => None,
643 Self::No(why) | Self::NotOnThisDevice(why) => Some(why),
644 }
645 }
646}
647
648impl fmt::Display for Support {
649 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
650 match self {
651 Self::Yes => f.write_str("supported"),
652 Self::No(why) => write!(f, "unsupported: {why}"),
653 Self::NotOnThisDevice(why) => write!(f, "unsupported on this device: {why}"),
654 }
655 }
656}
657
658/// Which kind of divergence an entry records — and so whether any amount of
659/// work in this repository could ever close it.
660///
661/// **This is what makes the parity goal checkable.** Without it, "Metal's blit
662/// fill takes a byte, not a word, and no work changes that", "this backend has
663/// not written the code yet" and "it is written and no device here has run it"
664/// are the same shape in the data, and nobody can answer "what is left?"
665/// without re-reading every reason in [`DIVERGENCES`]. With it,
666/// [`parity_blockers`] answers it — and the answer distinguishes work that
667/// needs a programmer from work that needs a machine.
668#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
669pub enum DivergenceKind {
670 /// The backend's API cannot express it. **No work here closes it**, so it
671 /// is not on anybody's list.
672 ///
673 /// The reason must carry the evidence: the selector and the type of the
674 /// argument, the WebIDL member that is absent, the enumeration that has no
675 /// such value. A backend's own comment is a claim rather than evidence — a
676 /// row here is a permanent promise, and the two entries this field was
677 /// introduced to settle were both backend comments contradicting the list.
678 ApiAbsence,
679
680 /// The API allows it and this crate has not written it.
681 ///
682 /// The reason says roughly what the work is, and by convention names the
683 /// slice that owes it.
684 Unwritten,
685
686 /// The code is written and no device available here has executed it.
687 ///
688 /// **Distinct from [`Unwritten`](Self::Unwritten) because the work owed is
689 /// different in kind.** An `Unwritten` row is closed by somebody writing
690 /// code; one of these is closed by somebody *running* what is already
691 /// there, on hardware this project does not have — a Metal 3 Mac, a device
692 /// reporting a counter set, a D3D12 GPU that is not WARP. Collapsing the two
693 /// makes the remaining distance to parity read as programming when it is
694 /// procurement, which is the opposite of what a reader needs.
695 ///
696 /// It blocks parity exactly as `Unwritten` does. The rule that a row leaves
697 /// [`DIVERGENCES`] only when a device has *run* the path is unchanged, and
698 /// this kind is what lets a row say so instead of claiming work is owed that
699 /// is already done.
700 ///
701 /// The reason must name the calls that exist, so the claim is checkable by
702 /// reading them, and say what device would settle it.
703 Unrun,
704}
705
706impl DivergenceKind {
707 /// Whether a row of this kind stands between a backend and parity.
708 ///
709 /// Everything except [`ApiAbsence`](Self::ApiAbsence): an API with no
710 /// expression for something is not a backlog item, while unwritten code is
711 /// work owed.
712 ///
713 /// A `match` rather than a comparison against one variant, so a kind added
714 /// later has to say which side of the goal it falls on.
715 #[must_use]
716 pub const fn blocks_parity(self) -> bool {
717 match self {
718 Self::ApiAbsence => false,
719 Self::Unwritten | Self::Unrun => true,
720 }
721 }
722}
723
724/// One (capability, backend) pair that is knowingly absent.
725///
726/// See [`DIVERGENCES`] for what the list as a whole is for.
727#[derive(Clone, Copy, Debug, PartialEq, Eq)]
728pub struct Divergence {
729 /// The capability the backend does not have.
730 pub capability: Capability,
731 /// The backend that does not have it.
732 pub backend: BackendKind,
733 /// Whether anything in this repository could close it. See
734 /// [`DivergenceKind`], and [`parity_blockers`] for what the field is for.
735 pub kind: DivergenceKind,
736 /// Why, in enough detail to decide whether it should stay that way. This is
737 /// the sentence a reviewer reads when the pair is added.
738 pub why: &'static str,
739}
740
741/// Metal's answer for [`Capability::DrawIndirectCount`] on a device that does
742/// not report the flag — in `crcbl-mtl`'s `Device::supports` and in the error
743/// its encoder refuses with alike.
744///
745/// **One sentence in two places on purpose**, the shape a backend uses when a
746/// refusal has to survive the trip from `Device::supports` to the error a
747/// caller reads.
748///
749/// **It used to be a row in [`DIVERGENCES`], and that row is gone because the
750/// work landed.** For three revisions this constant described an
751/// `MTLIndirectCommandBuffer` written by a compute kernel — the design that was
752/// attempted three times and hung the GPU in a frame every time. What
753/// `crcbl-mtl` ships instead needs no such object: a draw of **zero instances**
754/// renders nothing, so a kernel that packs the argument structures and leaves
755/// every one at or past the GPU-written count with no instances turns a
756/// count-limited draw into `max_draw_count` ordinary indirect draws. The
757/// capability is answered through [`Support::granted`] now, so this is the
758/// sentence a device that withheld
759/// [`Features::DRAW_INDIRECT_COUNT`](crate::Features::DRAW_INDIRECT_COUNT)
760/// would carry — which, the gate being unconditional, is a device somebody
761/// deliberately reverted the slice for.
762pub const METAL_NO_DRAW_INDIRECT_COUNT: &str = "this device reports no DRAW_INDIRECT_COUNT. \
763 crcbl-mtl's count-limited draw is a compute kernel that packs the argument structures and \
764 zeroes the instance count of every one at or past the GPU-written count, followed by \
765 max_draw_count ordinary indirect draws — so the flag is unconditional on Metal and a device \
766 without it is one the slice was switched off for at crcbl_mtl::adapter's features_of";
767
768/// The browser's answer for [`Capability::UpdateBindGroup`], in the parity
769/// record and in `crcbl-webgpu`'s own declaration alike.
770///
771/// The second sentence that had drifted, and the same treatment as
772/// [`METAL_NO_DRAW_INDIRECT_COUNT`]. This list used to say the stream "has no
773/// update_bind_group command **yet**", which reads as schedulable work, while
774/// the backend said a bind group is immutable and the stream "could not carry
775/// one that worked". WebGPU settles it: `GPUBindGroup` exposes a label and
776/// nothing else, so there is no mutation to encode and never will be.
777pub const WEBGPU_BIND_GROUPS_ARE_IMMUTABLE: &str = "WebGPU bind groups are immutable once created \
778 — GPUBindGroup exposes a label and nothing else — so the stream has no update_bind_group \
779 command and could not carry one that worked";
780
781/// Every backend's answer for [`Capability::OcclusionQuery`], in the parity
782/// record, in each `Device::supports`, and in the
783/// [`HalError::Unsupported`](crate::HalError::Unsupported) that
784/// [`QueryKind::check_supported`](crate::QueryKind::check_supported) refuses a
785/// set with.
786///
787/// **One sentence in three places**, the treatment
788/// [`METAL_NO_DRAW_INDIRECT_COUNT`] and [`WEBGPU_BIND_GROUPS_ARE_IMMUTABLE`]
789/// already get, and here it is one sentence for *five* backends because the
790/// thing that is missing is not any of theirs.
791///
792/// **The seam used to hand the set out**, and that is what this replaced. A
793/// caller could create a [`QueryKind::Occlusion`](crate::QueryKind::Occlusion)
794/// set, reset it, resolve it and read it, and what came back — measured through
795/// the seam suite on radv — was zeros. Zero is not a neutral answer to "how many
796/// samples were visible": it is "none of them", so occlusion culling wired to
797/// this seam would have culled the scene with every return value reporting
798/// success. A loud refusal is what this repository does everywhere else with a
799/// promise it cannot keep.
800/// Why a backend's [`Device::pipeline_statistics`](crate::Device::pipeline_statistics)
801/// refuses, and why its encoder refuses a
802/// [`PassStatisticsWrites`](crate::PassStatisticsWrites): it reads no
803/// pipeline-statistics counts from its API yet.
804pub const NO_PIPELINE_STATISTICS: &str = "pipeline statistics: this backend does not count a \
805 pass's work yet";
806
807/// Why a backend's [`Device::gpu_clock`](crate::Device::gpu_clock) refuses: it
808/// does not read the GPU's timestamp clock from the CPU.
809pub const NO_GPU_CLOCK: &str = "gpu_clock: this backend does not read the GPU's timestamp clock \
810 from the CPU";
811
812pub const NO_OCCLUSION_QUERY_VERB: &str = "a QueryKind::Occlusion set. Every API scopes an \
813 occlusion count with a begin/end pair around a draw — vkCmdBeginQuery, D3D12 BeginQuery, \
814 Metal setVisibilityResultMode:offset:, WebGPU beginOcclusionQuery — and crcbl_hal's \
815 CommandEncoder has no such verb: its whole query vocabulary is reset_query_set, \
816 resolve_query_set and the pass descriptor's timestamp_writes. So no work a caller records \
817 could ever count into the pool, and reading one back gives zeros, which says nothing was \
818 visible rather than nothing was asked. Every backend here can do the query and the verb is \
819 what is unwritten, so create_query_set refuses the kind on all of them rather than hand out \
820 a set whose only honest use is impossible";
821
822/// Every capability a backend is knowingly without, **on every device it can
823/// open**.
824///
825/// **This is the parity contract.** A capability every GPU backend has appears
826/// nowhere here; one that some have and some do not appears once per backend
827/// that lacks it, with the reason. The list is checked from both directions
828/// against a running device by the agnostic seam suite, so:
829///
830/// * a backend that starts refusing something new fails until the pair is added,
831/// which is a review of the divergence rather than a silence, and
832/// * a backend that starts *supporting* something listed fails until the pair is
833/// removed, so the list cannot rot into a record of history.
834///
835/// Every row also carries a [`DivergenceKind`], which is what separates the
836/// rows that are somebody's work from the rows no work can touch;
837/// [`parity_blockers`] is the query that reads it.
838///
839/// A refusal that is merely *this device's* — the backend answered
840/// [`Support::NotOnThisDevice`] because the gating [`Features`] flag is clear —
841/// is not listed and is not a gap; see [`parity_verdict`]. A backend's own
842/// refusal needs a row here whatever the device reports, which is what stops a
843/// row being retired by a device that could not have proved anything either way.
844///
845/// Entries are grouped by capability. [`BackendKind::Null`] never appears: it
846/// records rather than executes, so it is not part of the parity model — see
847/// [`BackendKind::is_gpu`].
848pub const DIVERGENCES: &[Divergence] = &[
849 // --- fills: the worked example, and why no row is left ---
850 //
851 // `BufferFillZero` on Dx12 is not here, and its absence is what the list is
852 // for: the row left because the work landed. `crcbl_dx12`'s `fill_buffer`
853 // copies out of a zeroed device-local resource, which is `wgpu-hal`'s dx12
854 // answer to the same call. The valued fills that were the rest of this
855 // section went with the verb's `value` on 2026-08-19 — see `BufferFillZero`
856 // — so the section is a heading over nothing, deliberately.
857 // --- draws ---
858 //
859 // `DrawIndirectCount` on Metal is not here, and its absence is the second
860 // worked example: the row left because the work landed. Metal still has no
861 // count-buffer draw — that never changes — but it does not need one. A draw
862 // of zero instances renders nothing, so `crcbl_mtl::indirect_count` packs
863 // the argument structures with a compute kernel, gives every structure at
864 // or past the GPU-written count no instances, and issues `max_draw_count`
865 // ordinary indirect draws. See [`METAL_NO_DRAW_INDIRECT_COUNT`], which the
866 // backend still shares for the device-gated refusal.
867 Divergence {
868 capability: Capability::DrawIndirectCount,
869 backend: BackendKind::WebGpu,
870 kind: DivergenceKind::ApiAbsence,
871 why: "GPURenderPassEncoder carries drawIndirect and drawIndexedIndirect and no \
872 count-buffer form of either, so the draw count can only come from the CPU; the \
873 stream has no tag for one because there is nothing to encode",
874 },
875 // `IndirectArgumentPaddedStride` on WebGPU is not here either, and it is the
876 // third worked example — the one where the row was never true of the
877 // backend in the first place. It said
878 // `GPURenderPassEncoder.drawIndirect(indirectBuffer, indirectOffset)` reads
879 // one tightly packed structure and has no stride to honour, which is a true
880 // sentence about the WebGPU call and a false one about this backend: the
881 // stride crosses the stream whole and `web/engine/gpu-replay.js` unrolls the
882 // draw into one `drawIndirect` per structure at `offset + i * stride`, so a
883 // padded stride is honoured by walking rather than by a parameter. An
884 // `ApiAbsence` that is only an absence in the API is how a row survives
885 // review: the reason reads as checkable and the thing it describes is not
886 // the thing being declared.
887 // Metal mesh/task rows were retired after native execution qualification;
888 // unsupported Metal devices use the shared hardware/OS capability gate.
889 Divergence {
890 capability: Capability::MeshShading,
891 backend: BackendKind::WebGpu,
892 kind: DivergenceKind::ApiAbsence,
893 why: "WebGPU has no mesh stage: GPUDevice creates render and compute pipelines only and \
894 GPURenderPassEncoder has no draw for one. No proposal for it has reached the \
895 specification, so this is the API rather than the slice",
896 },
897 Divergence {
898 capability: Capability::TaskShaderStage,
899 backend: BackendKind::WebGpu,
900 kind: DivergenceKind::ApiAbsence,
901 why: "WebGPU has no mesh stage to put an amplification stage in front of; see the \
902 MeshShading entry",
903 },
904 // --- bindings ---
905 Divergence {
906 capability: Capability::UpdateBindGroup,
907 backend: BackendKind::WebGpu,
908 kind: DivergenceKind::ApiAbsence,
909 why: WEBGPU_BIND_GROUPS_ARE_IMMUTABLE,
910 },
911 Divergence {
912 capability: Capability::PushConstants,
913 backend: BackendKind::WebGpu,
914 kind: DivergenceKind::ApiAbsence,
915 why: "WebGPU has no push constants — GPUPipelineLayoutDescriptor carries bind group \
916 layouts and nothing beside them. The substitute is a dynamic-offset uniform buffer, \
917 which the seam already carries as bind-group dynamic offsets",
918 },
919 // The Metal row that used to sit here is gone, and it left the way a row is
920 // meant to: `crcbl-mtl` binds a VARIABLE_COUNT slot as one argument buffer
921 // of `MTLBuffer::gpuAddress` values and keeps its contents resident with
922 // `useResource:`, so the backend answers `Support::Yes` wherever the device
923 // reports `DESCRIPTOR_INDEXING`.
924 Divergence {
925 capability: Capability::BindlessDescriptorArray,
926 backend: BackendKind::WebGpu,
927 kind: DivergenceKind::ApiAbsence,
928 why: "GPUBindGroupLayoutEntry carries a binding, a visibility and one resource layout and \
929 no count, so WebGPU has no binding arrays at all, fixed-size or runtime-sized; a \
930 material table is indexed through a storage buffer here rather than through \
931 descriptors",
932 },
933 // The WebGPU row that used to sit here is gone: the gap was the seam's own
934 // descriptor, and `BindingKind::StorageImage` now carries the `view_type`
935 // and `format` `GPUStorageTextureBindingLayout` demands, so `crcbl-webgpu`
936 // answers `Support::Yes`. What is left is the backend nobody is finishing.
937 // --- rasteriser state ---
938 //
939 // Only one entry, and that is the point: `PolygonModeLine`, `DepthClamp` and
940 // `SamplerAnisotropy` are refused by every backend *only* where the device
941 // reports the flag clear, which is `Features` doing its job. WebGPU is the
942 // exception because it has no wireframe on any device it could ever open.
943 Divergence {
944 capability: Capability::PolygonModeLine,
945 backend: BackendKind::WebGpu,
946 kind: DivergenceKind::ApiAbsence,
947 why: "GPUPrimitiveState carries topology, stripIndexFormat, frontFace, cullMode and \
948 unclippedDepth and no fill mode, so WebGPU has no core expression for a wireframe; \
949 unlike the other two rasteriser capabilities this is absent from the API rather than \
950 from a given device",
951 },
952 // --- queries ---
953 //
954 // **The occlusion four are one decision, taken on 2026-09-06**, and they are
955 // the only rows in this list where every backend diverges for the same
956 // reason and that reason is not any backend's: `crcbl_hal::CommandEncoder`
957 // has no verb that scopes a count, so `QueryKind::Occlusion` is refused
958 // everywhere by `QueryKind::check_supported`. See `NO_OCCLUSION_QUERY_VERB`,
959 // which is the sentence all four carry and every `Device::supports`
960 // declares. `Unwritten` rather than `ApiAbsence` on purpose: all four APIs
961 // express occlusion queries, and the missing piece is a seam verb somebody
962 // here would write — the alternative was deleting the capability, and
963 // deleting it would have recorded a decision against occlusion queries that
964 // nobody took. `docs/notes/backends.md` holds the argument and the
965 // measurement the refusal replaced.
966 Divergence {
967 capability: Capability::OcclusionQuery,
968 backend: BackendKind::Vulkan,
969 kind: DivergenceKind::Unwritten,
970 why: NO_OCCLUSION_QUERY_VERB,
971 },
972 Divergence {
973 capability: Capability::OcclusionQuery,
974 backend: BackendKind::WebGpu,
975 kind: DivergenceKind::Unwritten,
976 why: NO_OCCLUSION_QUERY_VERB,
977 },
978 Divergence {
979 capability: Capability::OcclusionQuery,
980 backend: BackendKind::Metal,
981 kind: DivergenceKind::Unwritten,
982 why: NO_OCCLUSION_QUERY_VERB,
983 },
984 Divergence {
985 capability: Capability::OcclusionQuery,
986 backend: BackendKind::Dx12,
987 kind: DivergenceKind::Unwritten,
988 why: NO_OCCLUSION_QUERY_VERB,
989 },
990 // Metal timestamp queries were proved on an M3 Pro on 2026-09-10,
991 // including render/compute boundaries and GPU-side resolves. Clear-only
992 // render passes and empty compute passes needed fixes before that proof;
993 // docs/notes/metal-local-baseline.md records the hardware evidence.
994 // The WebGPU TimestampQuery row that used to sit here is gone, and it left
995 // the way `StorageImageBinding`'s did: the gap was the seam's own verb. It
996 // had a free-standing `write_timestamp` naming an arbitrary point in the
997 // command stream, which WebGPU has no expression for at all, so
998 // `create_query_set` refused a timestamp set rather than hand out a handle a
999 // profiler would fill with zeros. `PassTimestampWrites` is
1000 // `GPURenderPassDescriptor.timestampWrites`' own shape, so the browser
1001 // backend passes it straight through and answers `Support::Yes`. Worth
1002 // reading beside the occlusion rows above, which are the same shape and went
1003 // the other way: a gap in the seam's own vocabulary, refused by
1004 // `create_query_set` rather than papered over — and there, unlike here, the
1005 // verb has not arrived yet.
1006 Divergence {
1007 capability: Capability::PipelineStatisticsQuery,
1008 backend: BackendKind::Metal,
1009 // Reclassified with TimestampQuery on 2026-08-19, from the same probe
1010 // output, and written with it. It stays Unwritten for the same reason —
1011 // no device has run it — plus one this backend cannot fix on its own:
1012 // see the second half of the reason.
1013 kind: DivergenceKind::Unrun,
1014 why: "the calls exist — crcbl_mtl::device's create_query_set builds an \
1015 MTLCounterSampleBuffer over MTLCommonCounterSetStatistic and crcbl_mtl::command's \
1016 resolve_query_set reaches it through the blit encoder's \
1017 resolveCounters:inRange:destinationBuffer:destinationOffset: at the \
1018 MTLCounterResultStatistic width crcbl_mtl::query derives — but no device has ever \
1019 run them, and the seam's way to fill one is not written for Metal yet. **Nothing \
1020 samples one**: the seam names a pass's statistics with PassStatisticsWrites, and \
1021 crcbl_mtl::command refuses that with NO_PIPELINE_STATISTICS, so no work a caller \
1022 records writes into this set; that waits for the Mac work (owner, 2026-10-28). \
1023 **Nor is it read**: crcbl_mtl keeps the trait's refusing Device::pipeline_statistics, \
1024 and query_results refuses the kind because an MTLCounterResultStatistic is eight \
1025 u64s where that call reads one, as crcbl-vk and crcbl-dx12 refuse it. \
1026 crcbl_mtl::adapter reports Features::PIPELINE_STATISTICS_QUERY for a device \
1027 advertising MTLCommonCounterSetStatistic, and gates it on that alone rather than on \
1028 supportsCounterSampling:. The Mac in CI advertises counterSets=0, so it reports the \
1029 flag clear; that is a device fact reported per device, not what leaves the row open. \
1030 Retiring this row takes a Mac that reports the flag counting a pass and reading it \
1031 back",
1032 },
1033 Divergence {
1034 capability: Capability::PipelineStatisticsQuery,
1035 backend: BackendKind::WebGpu,
1036 kind: DivergenceKind::ApiAbsence,
1037 why: "GPUQueryType is exactly 'occlusion' and 'timestamp', so there is no \
1038 pipeline-statistics query set for WebGPU to create",
1039 },
1040 Divergence {
1041 capability: Capability::GpuClock,
1042 backend: BackendKind::Metal,
1043 kind: DivergenceKind::Unwritten,
1044 why: "MTLDevice's sampleTimestamps:gpuTimestamp: reads the CPU's and the GPU's clocks \
1045 together, and crcbl_mtl keeps the trait's refusing Device::gpu_clock: the call is \
1046 not bound, and Metal's GPU timestamps are in its counter-sampling units, which \
1047 crcbl_mtl converts to nanoseconds nowhere yet. Waits for the Mac work (owner, \
1048 2026-10-28)",
1049 },
1050 Divergence {
1051 capability: Capability::GpuClock,
1052 backend: BackendKind::WebGpu,
1053 kind: DivergenceKind::ApiAbsence,
1054 why: "GPUDevice and GPUQueue have no member reading the GPU's clock, and a \
1055 GPUQuerySet's timestamps are only ever resolved into a GPUBuffer by GPU work, so \
1056 no call places one against the CPU's clock",
1057 },
1058 // --- synchronisation ---
1059 Divergence {
1060 capability: Capability::TimelineSemaphore,
1061 backend: BackendKind::WebGpu,
1062 kind: DivergenceKind::ApiAbsence,
1063 why: "WebGPU has no semaphores. It orders submissions implicitly — one queue, executed in \
1064 order, hazards tracked by the browser — and its only completion signal, \
1065 GPUQueue.onSubmittedWorkDone(), resolves for everything submitted so far and carries \
1066 no value, so nothing there could drive a counter. create_semaphore refuses \
1067 SemaphoreKind::Timeline; it used to hand out a handle whose semaphore_value answered \
1068 0 for ever, which is the succeed-while-doing-nothing shape this enum exists to make \
1069 visible",
1070 },
1071 Divergence {
1072 capability: Capability::CpuTimelineWait,
1073 backend: BackendKind::WebGpu,
1074 kind: DivergenceKind::ApiAbsence,
1075 why: "create_semaphore refuses the timeline kind, so there is no counter for a CPU wait to \
1076 read; the binary semaphore this backend does hand out is GPU-waitable only. \
1077 wait_semaphores refuses rather than answering Ok(true) for a wait it never evaluated \
1078 — see the TimelineSemaphore entry",
1079 },
1080 Divergence {
1081 capability: Capability::CpuTimelineSignal,
1082 backend: BackendKind::WebGpu,
1083 kind: DivergenceKind::ApiAbsence,
1084 why: "create_semaphore refuses the timeline kind, so there is no counter for a host signal \
1085 to advance; WebGPU has no signalable object of any kind — see the TimelineSemaphore \
1086 entry",
1087 },
1088 Divergence {
1089 capability: Capability::TimelineWaitBeforeSignal,
1090 backend: BackendKind::WebGpu,
1091 kind: DivergenceKind::ApiAbsence,
1092 why: "a wait of any kind is refused here, so a wait on a value nothing has signalled is \
1093 refused with the rest; see the CpuTimelineWait entry",
1094 },
1095];
1096
1097/// Every divergence that stands between a backend crcbl is **keeping** and
1098/// parity.
1099///
1100/// The answer to "what is left?", derived rather than maintained. A row is here
1101/// when its backend [drives a GPU](BackendKind::is_gpu) and its
1102/// [`kind`](Divergence::kind) [blocks parity](DivergenceKind::blocks_parity) —
1103/// so [`BackendKind::Null`] is excluded by the first half rather than by a
1104/// reader remembering to skip it, and [`DivergenceKind::ApiAbsence`] by the
1105/// second.
1106///
1107/// The set is snapshotted by this module's own tests, so it shrinks only when
1108/// somebody updates the snapshot deliberately. Yields in [`DIVERGENCES`] order.
1109pub fn parity_blockers() -> impl Iterator<Item = &'static Divergence> {
1110 DIVERGENCES
1111 .iter()
1112 .filter(|entry| entry.backend.is_gpu() && entry.kind.blocks_parity())
1113}
1114
1115/// The [`DIVERGENCES`] entry for this pair, if the pair is a known divergence.
1116///
1117/// A linear scan of a `const` slice, which is why the list is kept small enough
1118/// to read: this is asked once per capability in a test, never in a frame.
1119#[must_use]
1120pub fn divergence(capability: Capability, backend: BackendKind) -> Option<&'static Divergence> {
1121 DIVERGENCES
1122 .iter()
1123 .find(|entry| entry.capability == capability && entry.backend == backend)
1124}
1125
1126/// What the parity record has to say about one capability on one running
1127/// device — the outcome [`parity_verdict`] answers with.
1128///
1129/// Five outcomes rather than a `bool`, because "not a gap" used to cover two
1130/// unlike things: a divergence somebody reviewed, and a pair this device could
1131/// not settle either way. Folding them made a retirement free — see
1132/// [`UnprovableHere`](Self::UnprovableHere).
1133#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1134pub enum ParityVerdict {
1135 /// The backend performs it here. Nothing is owed, and a [`DIVERGENCES`] row
1136 /// for the pair would be stale.
1137 Supported,
1138
1139 /// The backend refuses and [`DIVERGENCES`] says why. The reviewed case, and
1140 /// the entry is carried so a report can print the sentence.
1141 Reviewed(&'static Divergence),
1142
1143 /// The device withheld the gating [`Features`] flag, so this run learned
1144 /// **nothing** about the backend — neither that it has the capability nor
1145 /// that it lacks it.
1146 ///
1147 /// Not a failure: the device is lesser, which `Features` already models and
1148 /// logs as a downgrade at creation, and there is no work anybody could do to
1149 /// make a software rasteriser grow a mesh stage.
1150 ///
1151 /// It is reported by name all the same, because "unprovable here" is a
1152 /// coverage gap and used to be indistinguishable from a clean pass. That
1153 /// indistinguishability is the whole defect this enum was split to fix: a
1154 /// gated pair reached it whether or not [`DIVERGENCES`] named the pair, so a
1155 /// row could be deleted and no run anywhere would notice.
1156 UnprovableHere(Features),
1157
1158 /// **The backend's own refusal, with nobody's name on it.** The gap.
1159 ///
1160 /// [`Support::No`] means this backend would refuse on every device, so no
1161 /// device's [`Features`] excuse it: either a row was never written, or one
1162 /// was retired without the backend having learnt to do the thing.
1163 Unreviewed,
1164
1165 /// The backend answered [`Support::NotOnThisDevice`] and the device did not
1166 /// withhold anything — the capability has no
1167 /// [`gating_feature`](Capability::gating_feature), or it has one and this
1168 /// device reports it.
1169 ///
1170 /// A gap, and a louder one than [`Unreviewed`](Self::Unreviewed): the
1171 /// excused arm is the one thing a backend could hide behind, so it is the
1172 /// one arm whose claim is checked against the device rather than believed.
1173 FalseDeviceGate,
1174}
1175
1176impl ParityVerdict {
1177 /// Whether this verdict is a **parity gap** — something nobody has accounted
1178 /// for.
1179 ///
1180 /// The two failing outcomes and no others. [`UnprovableHere`] is deliberately
1181 /// not one: a device that cannot answer is not a defect in the backend.
1182 ///
1183 /// [`UnprovableHere`]: Self::UnprovableHere
1184 #[must_use]
1185 pub const fn is_gap(self) -> bool {
1186 match self {
1187 Self::Supported | Self::Reviewed(_) | Self::UnprovableHere(_) => false,
1188 Self::Unreviewed | Self::FalseDeviceGate => true,
1189 }
1190 }
1191}
1192
1193/// What the parity record says about `capability` on `backend`, given what the
1194/// backend `declared` on a device reporting `features`.
1195///
1196/// The rule the agnostic seam suite applies to every capability of a running
1197/// device, and the whole of what "reviewed divergence" means here:
1198///
1199/// * [`Support::Yes`] is [`Supported`](ParityVerdict::Supported). The backend
1200/// does it, and the suite's other half holds it to that by driving the call.
1201/// * [`Support::NotOnThisDevice`] is
1202/// [`UnprovableHere`](ParityVerdict::UnprovableHere) — **if the device really
1203/// did withhold the gate**, which is checked here rather than assumed.
1204/// Otherwise the backend blamed a device that gave it what it asked for, and
1205/// that is [`FalseDeviceGate`](ParityVerdict::FalseDeviceGate).
1206/// * [`Support::No`] that [`DIVERGENCES`] names is
1207/// [`Reviewed`](ParityVerdict::Reviewed). Somebody decided it and wrote down
1208/// why.
1209/// * [`Support::No`] that it does not name is
1210/// [`Unreviewed`](ParityVerdict::Unreviewed): this backend cannot do something
1211/// its peers can and nobody has said so. **The device's `features` do not
1212/// enter into it** — that is the fix. The old rule waived a refusal whenever
1213/// the device reported the gate clear, which waived it for backends that had
1214/// never looked at the gate, and so retired their rows for them.
1215///
1216/// Deliberately blind to [`DivergenceKind`]: a written reason is what makes a
1217/// refusal reviewed, whatever kind of divergence it turned out to be. "Which of
1218/// them is still somebody's work" is the other question, and
1219/// [`parity_blockers`] is where it is asked.
1220#[must_use]
1221pub fn parity_verdict(
1222 capability: Capability,
1223 backend: BackendKind,
1224 declared: Support,
1225 features: Features,
1226) -> ParityVerdict {
1227 match declared {
1228 Support::Yes => ParityVerdict::Supported,
1229 Support::NotOnThisDevice(_) => match capability.gating_feature() {
1230 Some(gate) if !features.contains(gate) => ParityVerdict::UnprovableHere(gate),
1231 _ => ParityVerdict::FalseDeviceGate,
1232 },
1233 Support::No(_) => match divergence(capability, backend) {
1234 Some(entry) => ParityVerdict::Reviewed(entry),
1235 None => ParityVerdict::Unreviewed,
1236 },
1237 }
1238}
1239
1240#[cfg(test)]
1241mod tests {
1242 use super::*;
1243
1244 /// Every GPU backend, for the tests that must sweep them. Written out rather
1245 /// than derived, so that a new [`BackendKind`] fails
1246 /// [`every_gpu_backend_is_in_this_sweep`] instead of silently escaping the
1247 /// parity model.
1248 const GPU_BACKENDS: [BackendKind; 4] = [
1249 BackendKind::Vulkan,
1250 BackendKind::WebGpu,
1251 BackendKind::Metal,
1252 BackendKind::Dx12,
1253 ];
1254
1255 #[test]
1256 fn every_gpu_backend_is_in_this_sweep() {
1257 for backend in GPU_BACKENDS {
1258 assert!(backend.is_gpu(), "{backend} must be in the parity model");
1259 }
1260 assert!(!BackendKind::Null.is_gpu());
1261 // The count comes from `is_gpu`'s own match rather than from a literal,
1262 // so a fifth backend makes this fail instead of quietly sitting outside
1263 // every sweep below.
1264 let every = [
1265 BackendKind::Vulkan,
1266 BackendKind::WebGpu,
1267 BackendKind::Metal,
1268 BackendKind::Dx12,
1269 BackendKind::Null,
1270 ];
1271 assert_eq!(
1272 every.iter().filter(|kind| kind.is_gpu()).count(),
1273 GPU_BACKENDS.len(),
1274 "a BackendKind drives a GPU and is not swept by these tests"
1275 );
1276 }
1277
1278 /// `ALL` is generated from the enum's own variant list, so it cannot fail by
1279 /// omission — what this catches is the macro being replaced by a
1280 /// hand-written array later, which is the whole reason the macro exists.
1281 #[test]
1282 fn all_holds_every_capability_exactly_once() {
1283 let mut seen: Vec<Capability> = Capability::ALL.to_vec();
1284 let count = seen.len();
1285 seen.sort_unstable();
1286 seen.dedup();
1287 assert_eq!(seen.len(), count, "a capability appears twice in ALL");
1288 assert!(
1289 count >= 20,
1290 "ALL has shrunk to {count}; the capabilities are derived from real refusal sites and \
1291 those have not gone away"
1292 );
1293 }
1294
1295 /// A name is what a failing parity report prints, so two variants sharing
1296 /// one would leave the report unable to say which diverged.
1297 #[test]
1298 fn every_capability_has_its_own_name() {
1299 let mut names: Vec<&'static str> = Capability::ALL.iter().map(|c| c.name()).collect();
1300 let count = names.len();
1301 names.sort_unstable();
1302 names.dedup();
1303 assert_eq!(names.len(), count, "two capabilities share a name");
1304 for capability in Capability::ALL {
1305 assert_eq!(capability.to_string(), capability.name());
1306 assert!(!capability.name().is_empty());
1307 }
1308 }
1309
1310 /// A gate must be a single flag. `Features::GPU_DRIVEN` is a named union,
1311 /// and a capability gated on it would be unsatisfiable on any device missing
1312 /// any one of six unrelated things.
1313 #[test]
1314 fn a_gating_feature_is_always_exactly_one_flag() {
1315 let mut gated = 0;
1316 for capability in Capability::ALL {
1317 let Some(gate) = capability.gating_feature() else {
1318 continue;
1319 };
1320 gated += 1;
1321 assert_eq!(
1322 gate.bits().count_ones(),
1323 1,
1324 "{capability} is gated on {gate:?}, which is not a single flag"
1325 );
1326 }
1327 assert!(
1328 gated > 0 && gated < Capability::ALL.len(),
1329 "both halves must be populated: {gated} of {} capabilities are gated, and a run where \
1330 all or none were would make the parity rule vacuous in one direction",
1331 Capability::ALL.len()
1332 );
1333 }
1334
1335 /// The one constructor a device gate is read through, and the only source of
1336 /// [`Support::NotOnThisDevice`] — so this asserts the *variant*, not merely
1337 /// that it said no. A `granted` that answered [`Support::No`] would put every
1338 /// lesser device back in front of [`ParityVerdict::Unreviewed`].
1339 #[test]
1340 fn granted_reads_the_flag_it_was_given() {
1341 let device = Features::COMPUTE | Features::TIMELINE_SEMAPHORE;
1342 assert_eq!(
1343 Support::granted(device, Features::COMPUTE, "no compute"),
1344 Support::Yes
1345 );
1346 assert_eq!(
1347 Support::granted(device, Features::MESH_SHADER, "no mesh shader"),
1348 Support::NotOnThisDevice("no mesh shader")
1349 );
1350 // And it is `contains`, not `intersects`: a capability gated on a flag
1351 // the device half-has would otherwise report supported.
1352 assert_eq!(
1353 Support::granted(device, Features::GPU_DRIVEN, "not the whole bundle"),
1354 Support::NotOnThisDevice("not the whole bundle")
1355 );
1356 }
1357
1358 #[test]
1359 fn support_carries_the_reason_and_nothing_else() {
1360 assert!(Support::Yes.is_yes());
1361 assert_eq!(Support::Yes.reason(), None);
1362 assert_eq!(Support::Yes.to_string(), "supported");
1363
1364 let refused = Support::No("there is no such call");
1365 assert!(!refused.is_yes());
1366 assert_eq!(refused.reason(), Some("there is no such call"));
1367 assert_eq!(
1368 refused.to_string(),
1369 "unsupported: there is no such call",
1370 "the reason must reach the reader, not merely be stored"
1371 );
1372
1373 // The two refusals read differently, because a reader deciding whether
1374 // to try another adapter needs to know which one this was.
1375 let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
1376 assert!(!withheld.is_yes());
1377 assert_eq!(
1378 withheld.reason(),
1379 Some("this device reports no MESH_SHADER")
1380 );
1381 assert_eq!(
1382 withheld.to_string(),
1383 "unsupported on this device: this device reports no MESH_SHADER"
1384 );
1385 assert_ne!(
1386 withheld,
1387 Support::No("this device reports no MESH_SHADER"),
1388 "the same sentence in the two arms must not compare equal, or the parity rule is \
1389 reading a string rather than a classification"
1390 );
1391 }
1392
1393 /// One pair, one entry. A duplicate would make [`divergence`] return the
1394 /// first and hide whichever reason somebody added second.
1395 #[test]
1396 fn no_pair_is_listed_twice() {
1397 let mut pairs: Vec<(Capability, String)> = DIVERGENCES
1398 .iter()
1399 .map(|entry| (entry.capability, entry.backend.to_string()))
1400 .collect();
1401 let count = pairs.len();
1402 pairs.sort_unstable();
1403 pairs.dedup();
1404 assert_eq!(
1405 pairs.len(),
1406 count,
1407 "a (capability, backend) pair is listed twice"
1408 );
1409 }
1410
1411 /// The list is read by whoever is deciding whether a divergence should stay,
1412 /// so an entry that says nothing is an entry nobody reviewed.
1413 #[test]
1414 fn every_divergence_gives_a_real_reason() {
1415 for entry in DIVERGENCES {
1416 assert!(
1417 entry.why.len() > 40,
1418 "{} on {}: {:?} is too short to be a reason anyone can act on",
1419 entry.capability,
1420 entry.backend,
1421 entry.why
1422 );
1423 }
1424 }
1425
1426 /// [`BackendKind::Null`] records rather than executes, so an entry naming it
1427 /// would be describing a recorder's limitation as a backend divergence.
1428 #[test]
1429 fn divergences_name_only_gpu_backends() {
1430 for entry in DIVERGENCES {
1431 assert!(
1432 entry.backend.is_gpu(),
1433 "{} names {}, which is not a GPU backend",
1434 entry.capability,
1435 entry.backend
1436 );
1437 }
1438 }
1439
1440 /// A capability every GPU backend lacks is a seam behaviour nothing
1441 /// implements, not a *divergence* — so it may only be listed once somebody
1442 /// has decided to leave it that way.
1443 ///
1444 /// **The exception is [`DEFERRED_CAPABILITIES`], and it is a hand-edited
1445 /// list for the same reason [`REVIEWED_BLOCKERS`] is.** A capability the
1446 /// whole seam refuses still belongs in [`DIVERGENCES`] when the refusal was
1447 /// weighed and taken — [`Capability::OcclusionQuery`] is one, and the rows
1448 /// are what makes its cost visible instead of the gap being absorbed into
1449 /// prose. What this catches is the other case: a capability quietly refused
1450 /// everywhere because nobody wrote it, filed as four parity exceptions and
1451 /// read as four separate backend gaps.
1452 ///
1453 /// The other half too: [`divergence`] must find every entry the list holds,
1454 /// and must not invent one.
1455 #[test]
1456 fn a_divergence_is_something_some_backend_actually_has() {
1457 for capability in Capability::ALL {
1458 let lacking = GPU_BACKENDS
1459 .iter()
1460 .filter(|backend| divergence(*capability, **backend).is_some())
1461 .count();
1462 assert!(
1463 lacking < GPU_BACKENDS.len() || DEFERRED_CAPABILITIES.contains(capability),
1464 "{capability} is listed as absent on every GPU backend and nothing parked it, so \
1465 it is not a divergence — it is a seam behaviour nothing implements, and that \
1466 belongs in the seam's own docs rather than in a parity exception list. If it is \
1467 refused everywhere on purpose, say so in DEFERRED_CAPABILITIES"
1468 );
1469 }
1470
1471 for entry in DIVERGENCES {
1472 assert_eq!(
1473 divergence(entry.capability, entry.backend),
1474 Some(entry),
1475 "the lookup must find every entry the list holds"
1476 );
1477 }
1478 assert_eq!(
1479 divergence(
1480 Capability::IndirectArgumentPaddedStride,
1481 BackendKind::Vulkan
1482 ),
1483 None,
1484 "Vulkan takes a padded stride, and the list would be describing it wrongly"
1485 );
1486 assert_eq!(
1487 divergence(Capability::PushConstants, BackendKind::Null),
1488 None
1489 );
1490 }
1491
1492 /// The rule, checked on every case that decides it. Written as a table
1493 /// because the failure mode is an `&&` where an `||` belongs, which reads
1494 /// identically and makes the parity suite either vacuous or unpassable.
1495 #[test]
1496 fn a_parity_gap_is_a_backend_refusal_nobody_wrote_down() {
1497 let all = Features::all();
1498 let no_mesh = all.difference(Features::MESH_SHADER);
1499 let refused = Support::No("this backend has not written it");
1500 let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
1501
1502 // Supported: nothing owed, whatever the list says.
1503 assert_eq!(
1504 parity_verdict(
1505 Capability::MeshShading,
1506 BackendKind::Vulkan,
1507 Support::Yes,
1508 all
1509 ),
1510 ParityVerdict::Supported
1511 );
1512 // A backend refusal the list names: reviewed. An *ungated* pair, so the
1513 // verdict cannot be coming from a flag the device happens to report —
1514 // `IndirectArgumentPaddedStride` stood here until its row left, and the
1515 // replacement was chosen to keep that property rather than only to
1516 // compile.
1517 assert_eq!(
1518 parity_verdict(
1519 Capability::UpdateBindGroup,
1520 BackendKind::WebGpu,
1521 refused,
1522 all
1523 ),
1524 ParityVerdict::Reviewed(
1525 divergence(Capability::UpdateBindGroup, BackendKind::WebGpu)
1526 .expect("WebGPU's immutable bind groups are on the list")
1527 )
1528 );
1529 assert_eq!(Capability::UpdateBindGroup.gating_feature(), None);
1530 // The device withheld the gate: this run proves nothing either way, and
1531 // saying so is not a failure.
1532 assert_eq!(
1533 parity_verdict(
1534 Capability::MeshShading,
1535 BackendKind::Vulkan,
1536 withheld,
1537 no_mesh
1538 ),
1539 ParityVerdict::UnprovableHere(Features::MESH_SHADER)
1540 );
1541 // A backend refusal nobody wrote down: a gap.
1542 assert_eq!(
1543 parity_verdict(Capability::MeshShading, BackendKind::Vulkan, refused, all),
1544 ParityVerdict::Unreviewed
1545 );
1546
1547 // **The hole this rule was rewritten to close.** The same unlisted
1548 // backend refusal on a device that withheld the gate: the old rule
1549 // waived it, so retiring the row cost nothing and no run anywhere
1550 // noticed. It is the same gap it is on a device that reports the flag.
1551 assert_eq!(
1552 parity_verdict(
1553 Capability::MeshShading,
1554 BackendKind::Vulkan,
1555 refused,
1556 no_mesh
1557 ),
1558 ParityVerdict::Unreviewed,
1559 "a backend's own refusal is a gap on every device; a lesser one cannot excuse it"
1560 );
1561
1562 // And the escape hatch is checked rather than believed, in both of its
1563 // failure shapes: an ungated capability has no device to blame, and a
1564 // device that reported the flag did not withhold it.
1565 assert_eq!(Capability::BufferFillZero.gating_feature(), None);
1566 assert_eq!(
1567 parity_verdict(
1568 Capability::BufferFillZero,
1569 BackendKind::Dx12,
1570 withheld,
1571 Features::empty()
1572 ),
1573 ParityVerdict::FalseDeviceGate
1574 );
1575 assert_eq!(
1576 parity_verdict(Capability::MeshShading, BackendKind::Vulkan, withheld, all),
1577 ParityVerdict::FalseDeviceGate
1578 );
1579
1580 // Ungated and unlisted: always a gap, whatever the device reports.
1581 assert!(
1582 parity_verdict(
1583 Capability::BufferFillZero,
1584 BackendKind::Vulkan,
1585 refused,
1586 Features::empty()
1587 )
1588 .is_gap()
1589 );
1590 // Ungated and listed: never a gap. WebGPU's immutable bind groups,
1591 // because nothing in `Features` describes rewriting one.
1592 //
1593 // The indirect stride used to stand here, on the grounds that the row
1594 // was permanent. No row is: that one left when somebody read the
1595 // replayer and found it already walking the stride. A fixture is picked
1596 // for the shape it exercises — ungated, and on the list — and the pair
1597 // that has it is checked rather than assumed.
1598 assert!(
1599 !parity_verdict(
1600 Capability::UpdateBindGroup,
1601 BackendKind::WebGpu,
1602 refused,
1603 Features::empty()
1604 )
1605 .is_gap()
1606 );
1607 }
1608
1609 /// Which verdicts fail, as a table: the failure mode is a variant landing on
1610 /// the wrong side, which would either make the suite unpassable or make the
1611 /// whole report advisory.
1612 #[test]
1613 fn only_an_unaccounted_refusal_is_a_gap() {
1614 let entry = &DIVERGENCES[0];
1615 assert!(!ParityVerdict::Supported.is_gap());
1616 assert!(!ParityVerdict::Reviewed(entry).is_gap());
1617 assert!(!ParityVerdict::UnprovableHere(Features::MESH_SHADER).is_gap());
1618 assert!(ParityVerdict::Unreviewed.is_gap());
1619 assert!(ParityVerdict::FalseDeviceGate.is_gap());
1620 }
1621
1622 /// **Every row in the list is one a running backend can be held to.**
1623 ///
1624 /// The property the rule rewrite buys, asserted over the data rather than
1625 /// argued in a doc comment: a row exists to excuse a [`Support::No`], and
1626 /// [`parity_verdict`] answers [`ParityVerdict::Reviewed`] for that pair on
1627 /// **every** device, including one reporting nothing at all. So deleting any
1628 /// row turns that same pair into [`ParityVerdict::Unreviewed`] on the
1629 /// backend's own CI arm — there is no device on which the deletion passes
1630 /// unnoticed, which is what "a retirement must be earned" means here.
1631 #[test]
1632 fn no_row_can_be_retired_without_a_run_noticing() {
1633 let refused = Support::No("the refusal this row exists to excuse");
1634 for entry in DIVERGENCES {
1635 for features in [Features::empty(), Features::all()] {
1636 assert_eq!(
1637 parity_verdict(entry.capability, entry.backend, refused, features),
1638 ParityVerdict::Reviewed(entry),
1639 "{} on {}: the row must excuse the refusal on every device",
1640 entry.capability,
1641 entry.backend
1642 );
1643 // The counterfactual — that same refusal with no row behind it.
1644 // `divergence` is the only thing the rule reads for a
1645 // `Support::No`, so an unlisted pair *is* what a deleted row
1646 // leaves. `Null` stands in for one because the list can never
1647 // name it — `divergences_name_only_gpu_backends` is what holds
1648 // that — which is why it replaced Vulkan here on 2026-09-06,
1649 // when the occlusion rows gave Vulkan an entry and the
1650 // counterfactual a pair that was no longer unlisted.
1651 assert_eq!(
1652 divergence(entry.capability, BackendKind::Null),
1653 None,
1654 "the list has grown a Null row, which divergences_name_only_gpu_backends \
1655 forbids and this counterfactual depends on"
1656 );
1657 assert_eq!(
1658 parity_verdict(entry.capability, BackendKind::Null, refused, features),
1659 ParityVerdict::Unreviewed,
1660 "{}: an unlisted backend refusal must be a gap on every device, or deleting \
1661 the row above would cost nothing",
1662 entry.capability
1663 );
1664 }
1665 }
1666 }
1667
1668 /// Every divergence standing between crcbl and its stated end state, as
1669 /// reviewed — the whole of what full backend parity still asks for.
1670 /// **Update this deliberately.**
1671 ///
1672 /// A snapshot rather than a rule, and that is the point: a row leaves only
1673 /// when somebody writes the code, overturns the decline, or shows the API
1674 /// cannot express it after all. Each of those is a review, and a test that
1675 /// merely counted the rows — or checked that each had *some* kind — would
1676 /// pass whether the classification were right or wrong.
1677 const REVIEWED_BLOCKERS: &[(Capability, BackendKind, DivergenceKind)] = &[
1678 // **`OcclusionQuery` is the one row every backend has**, and the only
1679 // one here that is nobody's backend work: `crcbl_hal::CommandEncoder`
1680 // has no verb that scopes a count, so every `create_query_set` refuses
1681 // the kind — see `NO_OCCLUSION_QUERY_VERB` and the four `DIVERGENCES`
1682 // rows it is the reason for. Decided 2026-09-06 to refuse rather than
1683 // finish or delete; `docs/notes/backends.md` argues it. These four are
1684 // parked by that decision rather than by a backend's deferral, which is
1685 // what `DEFERRED_CAPABILITIES` says.
1686 (
1687 Capability::OcclusionQuery,
1688 BackendKind::Vulkan,
1689 DivergenceKind::Unwritten,
1690 ),
1691 (
1692 Capability::OcclusionQuery,
1693 BackendKind::WebGpu,
1694 DivergenceKind::Unwritten,
1695 ),
1696 (
1697 Capability::OcclusionQuery,
1698 BackendKind::Metal,
1699 DivergenceKind::Unwritten,
1700 ),
1701 (
1702 Capability::OcclusionQuery,
1703 BackendKind::Dx12,
1704 DivergenceKind::Unwritten,
1705 ),
1706 // `crcbl-dx12`'s mesh shading and task stage rows left on 2026-10-27,
1707 // the way a row is meant to: the backend reports both where the device
1708 // has a mesh tier. `BufferFillZero` left before them, by a copy out of
1709 // a zeroed resource.
1710 // Metal: the byte-wide fill is the API and is not here. The occlusion
1711 // query is, and it arrived from the seam rather than from this backend —
1712 // `crcbl-mtl` builds the visibility buffer and nothing can count into
1713 // it. `DrawIndirectCount` is not here either, and that one left
1714 // the way a row is meant to: `crcbl_mtl::indirect_count` packs the
1715 // argument structures with a compute kernel and draws
1716 // `max_draw_count` times, so the count is honoured with no indirect
1717 // command buffer anywhere.
1718 //
1719 // The two counter-sampled query rows were `Unclassified` until
1720 // 2026-08-19, on the grounds that settling them needed a measurement
1721 // this workspace could not take. `crcbl_mtl::adapter`'s probe has since
1722 // taken it, on CI: `AtStageBoundary=false`, `AtDrawBoundary=true`,
1723 // `counterSets=0`. Metal expresses both features, so neither is an
1724 // `ApiAbsence` and both are `Unwritten`. **The blocker count did not
1725 // move** — an unanswered question and unwritten work both block parity,
1726 // and reclassifying one as the other is honesty about what is owed,
1727 // not progress against it.
1728 (
1729 Capability::PipelineStatisticsQuery,
1730 BackendKind::Metal,
1731 DivergenceKind::Unrun,
1732 ),
1733 // Arrived with the capability on 2026-10-29, parked with the rest of
1734 // Metal: the call exists, nothing here binds it.
1735 (
1736 Capability::GpuClock,
1737 BackendKind::Metal,
1738 DivergenceKind::Unwritten,
1739 ),
1740 // `crcbl-webgpu`'s only row is the occlusion one at the top, and that
1741 // is worth reading twice: everything *WebGPU* refuses is WebGPU itself
1742 // refusing, which is an `ApiAbsence` and not a blocker, so the one row
1743 // the browser backend carries is one this seam owes rather than one the
1744 // platform lacks. It had two rows of its own before and both left the
1745 // way a row is supposed to — the work landed.
1746 // `StorageImageBinding` went when `BindingKind::StorageImage` grew its
1747 // `view_type` and `format`; `TimestampQuery` went when the seam's
1748 // free-standing `write_timestamp` became `PassTimestampWrites` on the
1749 // pass descriptor, which is `timestampWrites`' own shape.
1750 ];
1751
1752 /// The backends whose remaining work is parked rather than owed.
1753 ///
1754 /// `crcbl-mtl` and `crcbl-dx12` were deferred on 2026-08-21 —
1755 /// `docs/plan/09-backends-metal-dx12.md` holds the state and
1756 /// `docs/backlog.md` the two `DEFERRED` entries. The crates and their CI
1757 /// jobs stay so a regression still shows; what stops is feature work on
1758 /// them.
1759 const DEFERRED_BACKENDS: &[BackendKind] = &[BackendKind::Metal, BackendKind::Dx12];
1760
1761 /// The capabilities whose remaining work is parked on every backend at once.
1762 ///
1763 /// A second axis, because [`Capability::OcclusionQuery`] is parked for a
1764 /// reason no backend's deferral covers: the work is a verb on
1765 /// [`crate::CommandEncoder`] plus its five implementations, and it was
1766 /// decided on 2026-09-06 that the verb waits until something wants the
1767 /// counts — `docs/notes/backends.md` and `docs/backlog.md` hold the
1768 /// decision. Folding these rows into [`DEFERRED_BACKENDS`] would have meant
1769 /// calling `crcbl-vk` and `crcbl-webgpu` deferred, which they are not.
1770 const DEFERRED_CAPABILITIES: &[Capability] = &[Capability::OcclusionQuery];
1771 /// **`parity_blockers` cannot reach empty while the deferrals hold, and
1772 /// this is what says so instead of the count quietly redefining done.**
1773 ///
1774 /// Every row [`parity_blockers`] yields is either on a
1775 /// [deferred backend](DEFERRED_BACKENDS) or is a
1776 /// [deferred capability](DEFERRED_CAPABILITIES), so the honest reading of a
1777 /// non-zero blocker count today is "parked", not "outstanding". Nothing
1778 /// about that is expressed by the number itself, and a reader who saw only
1779 /// the number would conclude there was work to pick up.
1780 ///
1781 /// **A failure here is the useful case.** A blocker on `crcbl-vk` or
1782 /// `crcbl-webgpu` that nothing parked is work somebody is meant to do, and
1783 /// it would otherwise join the parked rows and read as more of the same. The
1784 /// second assertion is what stops the first going vacuous: with no blockers
1785 /// at all, "none of them is live" is true and says nothing, and the deferral
1786 /// notes above have become the thing to delete.
1787 #[test]
1788 fn every_parity_blocker_is_deferred_by_its_backend_or_by_its_capability() {
1789 let live: Vec<String> = parity_blockers()
1790 .filter(|entry| {
1791 !DEFERRED_BACKENDS.contains(&entry.backend)
1792 && !DEFERRED_CAPABILITIES.contains(&entry.capability)
1793 })
1794 .map(|entry| format!("{} on {}", entry.capability, entry.backend))
1795 .collect();
1796 assert!(
1797 live.is_empty(),
1798 "these parity blockers are on backends nobody deferred, so they are work that \
1799 is actually owed rather than parked: {live:?}. Say which in the report \
1800 instead of leaving them to be read as more deferred rows"
1801 );
1802 assert!(
1803 parity_blockers().next().is_some(),
1804 "there are no parity blockers left at all, which makes the assertion above \
1805 vacuous. The deferral note on DEFERRED_BACKENDS and this test have \
1806 outlived their subject"
1807 );
1808 }
1809
1810 /// The one that makes the goal checkable: what
1811 /// [`parity_blockers`] answers must be what somebody reviewed, row for row.
1812 ///
1813 /// Fails when a row joins or leaves the blocker set, when a blocking row is
1814 /// reclassified, and when a row is moved to another backend — each of which
1815 /// is a change to "what is left" and none of which should reach `main`
1816 /// without a human editing [`REVIEWED_BLOCKERS`] to match.
1817 #[test]
1818 fn the_parity_blockers_are_exactly_the_reviewed_list() {
1819 let mut actual: Vec<(Capability, String, DivergenceKind)> = parity_blockers()
1820 .map(|entry| (entry.capability, entry.backend.to_string(), entry.kind))
1821 .collect();
1822 actual.sort_unstable();
1823 let mut reviewed: Vec<(Capability, String, DivergenceKind)> = REVIEWED_BLOCKERS
1824 .iter()
1825 .map(|(capability, backend, kind)| (*capability, backend.to_string(), *kind))
1826 .collect();
1827 reviewed.sort_unstable();
1828 assert_eq!(
1829 actual, reviewed,
1830 "the set of divergences between crcbl and parity has changed. That is the goal moving, \
1831 so say so: update REVIEWED_BLOCKERS to match, and if a row left the set, make sure it \
1832 left because the work landed or the API was shown to lack it — not because a kind was \
1833 widened to ApiAbsence to make it disappear"
1834 );
1835 }
1836
1837 /// **Every backend in the model is now a parity target, and the filter that
1838 /// said otherwise is gone.**
1839 ///
1840 /// `parity_blockers` used to filter on `BackendKind::is_parity_target`,
1841 /// whose only `false` arm besides `Null` was `Wgpu` — the bridge backend
1842 /// that was always going to be deleted, and whose divergences were therefore
1843 /// not work anybody would do. `crcbl-wgpu` went on 2026-08-21 and the two
1844 /// predicates became the same function, so the second was deleted rather
1845 /// than kept for a hypothetical successor.
1846 ///
1847 /// What is asserted here is the property that replaced it: the filter is
1848 /// `is_gpu`, every GPU backend passes it, and `Null` does not — so a row on
1849 /// any real backend reaches the blocker set and cannot be excluded by
1850 /// anything except its own kind.
1851 #[test]
1852 fn every_gpu_backend_is_inside_the_goal() {
1853 for backend in GPU_BACKENDS {
1854 assert!(
1855 backend.is_gpu(),
1856 "{backend} is a GPU backend and must reach the blocker set"
1857 );
1858 }
1859 assert!(!BackendKind::Null.is_gpu());
1860 assert!(
1861 parity_blockers().all(|entry| entry.backend.is_gpu()),
1862 "a non-GPU row reached the blocker set"
1863 );
1864 }
1865
1866 /// The rule the query is built on, as a table: the failure mode is a
1867 /// negation dropped or added, which reads identically and would either
1868 /// empty the blocker set or fill it with rows nobody can act on.
1869 #[test]
1870 fn only_an_api_absence_is_off_the_hook() {
1871 assert!(!DivergenceKind::ApiAbsence.blocks_parity());
1872 assert!(DivergenceKind::Unwritten.blocks_parity());
1873 }
1874
1875 /// A kind nothing uses is a distinction nobody made. Each of the four has to
1876 /// describe a real row, or it is vocabulary rather than classification.
1877 #[test]
1878 fn every_kind_describes_at_least_one_real_row() {
1879 for kind in [
1880 DivergenceKind::ApiAbsence,
1881 DivergenceKind::Unwritten,
1882 DivergenceKind::Unrun,
1883 ] {
1884 assert!(
1885 DIVERGENCES.iter().any(|entry| entry.kind == kind),
1886 "no divergence is classified {kind:?}, so the variant is a name with nothing \
1887 behind it"
1888 );
1889 }
1890 }
1891
1892 /// A shared reason is shared with the row it describes.
1893 ///
1894 /// The other half of each pairing is a `Support::No(…)` in the backend
1895 /// crate, which the compiler checks by being a use of the same constant.
1896 /// This end is what stops somebody pasting the text back into the row as a
1897 /// literal and letting the two drift again.
1898 ///
1899 /// [`METAL_NO_DRAW_INDIRECT_COUNT`] is **not** checked here any more, and
1900 /// the assertion below is why: its row left [`DIVERGENCES`] when
1901 /// `crcbl-mtl` learned to honour a GPU-side count, so the constant is now
1902 /// shared between that backend's `Device::supports` gate and the error its
1903 /// encoder refuses with — two places the compiler checks, and neither of
1904 /// them a row. A row reappearing under it would mean the slice was reverted
1905 /// without the entry being restored, which is the state
1906 /// `the_parity_blockers_are_exactly_the_reviewed_list` fails on.
1907 #[test]
1908 fn a_shared_reason_is_the_reason_its_row_carries() {
1909 assert_eq!(
1910 divergence(Capability::DrawIndirectCount, BackendKind::Metal),
1911 None,
1912 "Metal's GPU-side draw count is implemented; the row left when the work landed"
1913 );
1914 assert_eq!(
1915 divergence(Capability::UpdateBindGroup, BackendKind::WebGpu).map(|entry| entry.why),
1916 Some(WEBGPU_BIND_GROUPS_ARE_IMMUTABLE)
1917 );
1918 }
1919}