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 mesh reporting is owed rather than absent, so it is one of the rows
133//! // standing between crcbl and its end state.
134//! assert!(parity_blockers().any(|entry| {
135//! entry.capability == Capability::MeshShading && 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 // --- synchronisation ---
426
427 /// [`SemaphoreKind::Timeline`](crate::SemaphoreKind::Timeline): a monotonic
428 /// `u64` counter a submission signals and both GPU and CPU can observe.
429 ///
430 /// The claim is the **observable** one — that
431 /// [`semaphore_value`](crate::Device::semaphore_value) reports the counter
432 /// advancing as submissions complete. A backend that hands out a handle
433 /// whose value never moves has not got this, whatever its return codes say.
434 TimelineSemaphore,
435
436 /// [`SemaphoreKind::Binary`](crate::SemaphoreKind::Binary): the one-shot,
437 /// GPU-only signal WSI acquire/present needs.
438 ///
439 /// Apart from [`TimelineSemaphore`](Self::TimelineSemaphore) deliberately. A
440 /// device may have no timeline and must still hand out a binary one, because
441 /// the swapchain is where they come from — and a backend that refused both
442 /// would pass every test that only checks the timeline half.
443 BinarySemaphore,
444
445 /// [`wait_semaphores`](crate::Device::wait_semaphores): the **CPU** blocking
446 /// until a timeline reaches a value.
447 ///
448 /// Distinct from creating one. A backend can hand out a counter a submission
449 /// signals while having no host-side wait to offer, which is what a
450 /// fence-shaped API looks like before its wait half is wired up.
451 CpuTimelineWait,
452
453 /// [`signal_semaphore`](crate::Device::signal_semaphore): the **CPU**
454 /// advancing a timeline, rather than a submission.
455 ///
456 /// Its own capability for the same reason
457 /// [`CpuTimelineWait`](Self::CpuTimelineWait) is: the two host-side halves
458 /// are separable. A backend that emulates a timeline over per-submission
459 /// completion could move a counter on demand and still have no queue-side
460 /// wait to pair it with, and one with a real semaphore object has both.
461 ///
462 /// The claim is the observable one — that
463 /// [`semaphore_value`](crate::Device::semaphore_value) reports the value the
464 /// host asked for, and that a value which would move the timeline backwards
465 /// is refused rather than accepted.
466 CpuTimelineSignal,
467
468 /// Waiting — from the CPU, or in a [`SubmitInfo`](crate::SubmitInfo) — on a
469 /// timeline value that **nothing submitted so far will signal**, expecting
470 /// a later signal to satisfy it.
471 ///
472 /// A real semaphore object blocks until somebody signals it, and
473 /// [`CpuTimelineSignal`](Self::CpuTimelineSignal) is what lets the host be
474 /// the somebody. A backend that emulates timelines over per-submission
475 /// completion has no object for a future signal to arrive on, so such a wait
476 /// could only ever stop the queue; refusing is the honest answer and it is a
477 /// genuine behavioural divergence rather than a missing call.
478 TimelineWaitBeforeSignal,
479}
480
481impl Capability {
482 /// The [`Features`] bit a caller consults before asking for this, if there
483 /// is one.
484 ///
485 /// **What makes the parity rule fair.** A backend that refuses because the
486 /// device reports this flag clear has not diverged from anything — the
487 /// device is simply lesser, which is exactly what [`Features`] already
488 /// models and logs as a downgrade.
489 ///
490 /// It is the *claim* to be in that position that this flag settles.
491 /// [`Support::granted`] is what puts a backend there, and
492 /// [`parity_verdict`] checks the claim against the device before excusing
493 /// it: a [`Support::NotOnThisDevice`] for a capability with no gate, or on a
494 /// device that reports the gate, is
495 /// [`ParityVerdict::FalseDeviceGate`]. What the flag no longer does is
496 /// excuse a refusal the backend made on its own account, which is how the
497 /// rule used to retire [`DIVERGENCES`] rows without anybody deciding to.
498 ///
499 /// `None` means no flag governs it, so every refusal is the backend's own.
500 /// That is the majority here, and it is the measurement this module was
501 /// built from: most refusal sites answer to no declared capability at all.
502 #[must_use]
503 pub const fn gating_feature(self) -> Option<Features> {
504 match self {
505 // Nothing in `Features` describes a buffer clear, which is why the
506 // fills were the divergence that reached CI — and why the two
507 // valued ones are gone: see `CommandEncoder::clear_buffer`.
508 Self::BufferFillZero
509 | Self::ImageToImageCopy
510 | Self::DepthImageCopy
511 | Self::MsaaResolveAttachment
512 | Self::StencilReference
513 | Self::IndirectArgumentPaddedStride
514 | Self::UpdateBindGroup
515 | Self::StorageImageBinding
516 | Self::BinarySemaphore => None,
517 Self::DrawIndirectCount => Some(Features::DRAW_INDIRECT_COUNT),
518 Self::MeshShading => Some(Features::MESH_SHADER),
519 Self::TaskShaderStage => Some(Features::TASK_SHADER),
520 Self::PushConstants => Some(Features::PUSH_CONSTANTS),
521 Self::BindlessDescriptorArray => Some(Features::DESCRIPTOR_INDEXING),
522 Self::PolygonModeLine => Some(Features::POLYGON_MODE_LINE),
523 Self::DepthClamp => Some(Features::DEPTH_CLAMP),
524 Self::SamplerAnisotropy => Some(Features::SAMPLER_ANISOTROPY),
525 Self::TimestampQuery => Some(Features::TIMESTAMP_QUERY),
526 Self::OcclusionQuery => Some(Features::OCCLUSION_QUERY),
527 Self::PipelineStatisticsQuery => Some(Features::PIPELINE_STATISTICS_QUERY),
528 // All four are about one object, so one flag governs them.
529 Self::TimelineSemaphore
530 | Self::CpuTimelineWait
531 | Self::CpuTimelineSignal
532 | Self::TimelineWaitBeforeSignal => Some(Features::TIMELINE_SEMAPHORE),
533 }
534 }
535}
536
537impl fmt::Display for Capability {
538 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
539 f.write_str(self.name())
540 }
541}
542
543/// Whether a backend performs a [`Capability`], and why not when it does not.
544///
545/// Three arms, and the third is not a third *degree* of support: "maybe",
546/// "partially" and "not yet" are all [`No`](Self::No) with a reason saying
547/// which, because a caller can do nothing different with a shade of no. What
548/// [`NotOnThisDevice`](Self::NotOnThisDevice) adds is **whose** no it is, which
549/// is a different axis and one a caller can act on — a refusal the device
550/// caused may be answered by opening a better adapter, and a refusal the backend
551/// caused never is.
552///
553/// It is also what makes the parity record checkable; see the module docs.
554#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
555pub enum Support {
556 /// The backend performs it **exactly as the seam documents it**, on this
557 /// device.
558 ///
559 /// Not "the API underneath has it" and not "the code is there": this is the
560 /// claim the agnostic seam suite exercises, so a backend saying it and then
561 /// refusing — or quietly doing something else — at the call site is a test
562 /// failure.
563 Yes,
564
565 /// **The backend** refuses, for the reason given, and would refuse on any
566 /// device.
567 ///
568 /// The reason is written for whoever reads the failure, so it names the
569 /// obstacle — the API call that does not exist, the slice that has not
570 /// landed — rather than restating the capability. `&'static str`, so asking
571 /// costs no allocation.
572 ///
573 /// Every one of these needs a [`DIVERGENCES`] row, on every device. A
574 /// backend reaching for this arm when the device is what withheld the
575 /// capability has not cheated the rule so much as opted into a stricter one.
576 No(&'static str),
577
578 /// **The device** withheld the capability's
579 /// [`gating_feature`](Capability::gating_feature), so the backend never got
580 /// to say whether it has it.
581 ///
582 /// Handed out by [`granted`](Self::granted) and nowhere else in this
583 /// workspace, because that is the one place a device gate is read. The
584 /// distinction is not cosmetic: a lesser device is what [`Features`] already
585 /// models and logs as a downgrade at device creation, and holding a software
586 /// rasteriser to a mesh-shader capability would fail the parity suite for a
587 /// reason nobody can fix.
588 ///
589 /// So this arm is *excused* by [`parity_verdict`] — which is exactly why it
590 /// is checked rather than taken on trust: a backend claiming it for an
591 /// ungated capability, or on a device that did report the flag, is
592 /// [`ParityVerdict::FalseDeviceGate`] and fails.
593 NotOnThisDevice(&'static str),
594}
595
596impl Support {
597 /// [`Yes`](Self::Yes) when `features` holds `feature`, otherwise
598 /// [`NotOnThisDevice`](Self::NotOnThisDevice) with `why`.
599 ///
600 /// The shape most arms of a backend's `match` have, written once here
601 /// because five backends were otherwise going to spell the same `if` five
602 /// ways — and because an arm that reads the *wrong* flag is the one mistake
603 /// in this file a reviewer cannot see, so the flag belongs at the call site
604 /// with nothing else beside it.
605 ///
606 /// **Being the only source of [`NotOnThisDevice`](Self::NotOnThisDevice) is
607 /// what the parity rule rests on.** A backend does not have to know that:
608 /// the arms it already routes through here are precisely the arms whose
609 /// refusal belongs to the device, so the classification costs no backend a
610 /// line and cannot be forgotten by one.
611 ///
612 /// `why` stays the caller's: which flag, and what the device would need to
613 /// report, is the sentence the reader of a parity report needs.
614 #[must_use]
615 pub const fn granted(features: Features, feature: Features, why: &'static str) -> Self {
616 if features.contains(feature) {
617 Self::Yes
618 } else {
619 Self::NotOnThisDevice(why)
620 }
621 }
622
623 /// Whether this is [`Support::Yes`].
624 #[must_use]
625 pub const fn is_yes(self) -> bool {
626 matches!(self, Self::Yes)
627 }
628
629 /// The refusal reason, or `None` when supported.
630 ///
631 /// Both refusals answer, because a caller printing "why not" wants the
632 /// sentence whichever of them it was.
633 #[must_use]
634 pub const fn reason(self) -> Option<&'static str> {
635 match self {
636 Self::Yes => None,
637 Self::No(why) | Self::NotOnThisDevice(why) => Some(why),
638 }
639 }
640}
641
642impl fmt::Display for Support {
643 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
644 match self {
645 Self::Yes => f.write_str("supported"),
646 Self::No(why) => write!(f, "unsupported: {why}"),
647 Self::NotOnThisDevice(why) => write!(f, "unsupported on this device: {why}"),
648 }
649 }
650}
651
652/// Which kind of divergence an entry records — and so whether any amount of
653/// work in this repository could ever close it.
654///
655/// **This is what makes the parity goal checkable.** Without it, "Metal's blit
656/// fill takes a byte, not a word, and no work changes that", "this backend has
657/// not written the code yet" and "it is written and no device here has run it"
658/// are the same shape in the data, and nobody can answer "what is left?"
659/// without re-reading every reason in [`DIVERGENCES`]. With it,
660/// [`parity_blockers`] answers it — and the answer distinguishes work that
661/// needs a programmer from work that needs a machine.
662#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
663pub enum DivergenceKind {
664 /// The backend's API cannot express it. **No work here closes it**, so it
665 /// is not on anybody's list.
666 ///
667 /// The reason must carry the evidence: the selector and the type of the
668 /// argument, the WebIDL member that is absent, the enumeration that has no
669 /// such value. A backend's own comment is a claim rather than evidence — a
670 /// row here is a permanent promise, and the two entries this field was
671 /// introduced to settle were both backend comments contradicting the list.
672 ApiAbsence,
673
674 /// The API allows it and this crate has not written it.
675 ///
676 /// The reason says roughly what the work is, and by convention names the
677 /// slice that owes it.
678 Unwritten,
679
680 /// The code is written and no device available here has executed it.
681 ///
682 /// **Distinct from [`Unwritten`](Self::Unwritten) because the work owed is
683 /// different in kind.** An `Unwritten` row is closed by somebody writing
684 /// code; one of these is closed by somebody *running* what is already
685 /// there, on hardware this project does not have — a Metal 3 Mac, a device
686 /// reporting a counter set, a D3D12 GPU that is not WARP. Collapsing the two
687 /// makes the remaining distance to parity read as programming when it is
688 /// procurement, which is the opposite of what a reader needs.
689 ///
690 /// It blocks parity exactly as `Unwritten` does. The rule that a row leaves
691 /// [`DIVERGENCES`] only when a device has *run* the path is unchanged, and
692 /// this kind is what lets a row say so instead of claiming work is owed that
693 /// is already done.
694 ///
695 /// The reason must name the calls that exist, so the claim is checkable by
696 /// reading them, and say what device would settle it.
697 Unrun,
698}
699
700impl DivergenceKind {
701 /// Whether a row of this kind stands between a backend and parity.
702 ///
703 /// Everything except [`ApiAbsence`](Self::ApiAbsence): an API with no
704 /// expression for something is not a backlog item, while unwritten code is
705 /// work owed.
706 ///
707 /// A `match` rather than a comparison against one variant, so a kind added
708 /// later has to say which side of the goal it falls on.
709 #[must_use]
710 pub const fn blocks_parity(self) -> bool {
711 match self {
712 Self::ApiAbsence => false,
713 Self::Unwritten | Self::Unrun => true,
714 }
715 }
716}
717
718/// One (capability, backend) pair that is knowingly absent.
719///
720/// See [`DIVERGENCES`] for what the list as a whole is for.
721#[derive(Clone, Copy, Debug, PartialEq, Eq)]
722pub struct Divergence {
723 /// The capability the backend does not have.
724 pub capability: Capability,
725 /// The backend that does not have it.
726 pub backend: BackendKind,
727 /// Whether anything in this repository could close it. See
728 /// [`DivergenceKind`], and [`parity_blockers`] for what the field is for.
729 pub kind: DivergenceKind,
730 /// Why, in enough detail to decide whether it should stay that way. This is
731 /// the sentence a reviewer reads when the pair is added.
732 pub why: &'static str,
733}
734
735/// Metal's answer for [`Capability::DrawIndirectCount`] on a device that does
736/// not report the flag — in `crcbl-mtl`'s `Device::supports` and in the error
737/// its encoder refuses with alike.
738///
739/// **One sentence in two places on purpose**, the shape a backend uses when a
740/// refusal has to survive the trip from `Device::supports` to the error a
741/// caller reads.
742///
743/// **It used to be a row in [`DIVERGENCES`], and that row is gone because the
744/// work landed.** For three revisions this constant described an
745/// `MTLIndirectCommandBuffer` written by a compute kernel — the design that was
746/// attempted three times and hung the GPU in a frame every time. What
747/// `crcbl-mtl` ships instead needs no such object: a draw of **zero instances**
748/// renders nothing, so a kernel that packs the argument structures and leaves
749/// every one at or past the GPU-written count with no instances turns a
750/// count-limited draw into `max_draw_count` ordinary indirect draws. The
751/// capability is answered through [`Support::granted`] now, so this is the
752/// sentence a device that withheld
753/// [`Features::DRAW_INDIRECT_COUNT`](crate::Features::DRAW_INDIRECT_COUNT)
754/// would carry — which, the gate being unconditional, is a device somebody
755/// deliberately reverted the slice for.
756pub const METAL_NO_DRAW_INDIRECT_COUNT: &str = "this device reports no DRAW_INDIRECT_COUNT. \
757 crcbl-mtl's count-limited draw is a compute kernel that packs the argument structures and \
758 zeroes the instance count of every one at or past the GPU-written count, followed by \
759 max_draw_count ordinary indirect draws — so the flag is unconditional on Metal and a device \
760 without it is one the slice was switched off for at crcbl_mtl::adapter's features_of";
761
762/// The browser's answer for [`Capability::UpdateBindGroup`], in the parity
763/// record and in `crcbl-webgpu`'s own declaration alike.
764///
765/// The second sentence that had drifted, and the same treatment as
766/// [`METAL_NO_DRAW_INDIRECT_COUNT`]. This list used to say the stream "has no
767/// update_bind_group command **yet**", which reads as schedulable work, while
768/// the backend said a bind group is immutable and the stream "could not carry
769/// one that worked". WebGPU settles it: `GPUBindGroup` exposes a label and
770/// nothing else, so there is no mutation to encode and never will be.
771pub const WEBGPU_BIND_GROUPS_ARE_IMMUTABLE: &str = "WebGPU bind groups are immutable once created \
772 — GPUBindGroup exposes a label and nothing else — so the stream has no update_bind_group \
773 command and could not carry one that worked";
774
775/// Every backend's answer for [`Capability::OcclusionQuery`], in the parity
776/// record, in each `Device::supports`, and in the
777/// [`HalError::Unsupported`](crate::HalError::Unsupported) that
778/// [`QueryKind::check_supported`](crate::QueryKind::check_supported) refuses a
779/// set with.
780///
781/// **One sentence in three places**, the treatment
782/// [`METAL_NO_DRAW_INDIRECT_COUNT`] and [`WEBGPU_BIND_GROUPS_ARE_IMMUTABLE`]
783/// already get, and here it is one sentence for *five* backends because the
784/// thing that is missing is not any of theirs.
785///
786/// **The seam used to hand the set out**, and that is what this replaced. A
787/// caller could create a [`QueryKind::Occlusion`](crate::QueryKind::Occlusion)
788/// set, reset it, resolve it and read it, and what came back — measured through
789/// the seam suite on radv — was zeros. Zero is not a neutral answer to "how many
790/// samples were visible": it is "none of them", so occlusion culling wired to
791/// this seam would have culled the scene with every return value reporting
792/// success. A loud refusal is what this repository does everywhere else with a
793/// promise it cannot keep.
794pub const NO_OCCLUSION_QUERY_VERB: &str = "a QueryKind::Occlusion set. Every API scopes an \
795 occlusion count with a begin/end pair around a draw — vkCmdBeginQuery, D3D12 BeginQuery, \
796 Metal setVisibilityResultMode:offset:, WebGPU beginOcclusionQuery — and crcbl_hal's \
797 CommandEncoder has no such verb: its whole query vocabulary is reset_query_set, \
798 resolve_query_set and the pass descriptor's timestamp_writes. So no work a caller records \
799 could ever count into the pool, and reading one back gives zeros, which says nothing was \
800 visible rather than nothing was asked. Every backend here can do the query and the verb is \
801 what is unwritten, so create_query_set refuses the kind on all of them rather than hand out \
802 a set whose only honest use is impossible";
803
804/// Every capability a backend is knowingly without, **on every device it can
805/// open**.
806///
807/// **This is the parity contract.** A capability every GPU backend has appears
808/// nowhere here; one that some have and some do not appears once per backend
809/// that lacks it, with the reason. The list is checked from both directions
810/// against a running device by the agnostic seam suite, so:
811///
812/// * a backend that starts refusing something new fails until the pair is added,
813/// which is a review of the divergence rather than a silence, and
814/// * a backend that starts *supporting* something listed fails until the pair is
815/// removed, so the list cannot rot into a record of history.
816///
817/// Every row also carries a [`DivergenceKind`], which is what separates the
818/// rows that are somebody's work from the rows no work can touch;
819/// [`parity_blockers`] is the query that reads it.
820///
821/// A refusal that is merely *this device's* — the backend answered
822/// [`Support::NotOnThisDevice`] because the gating [`Features`] flag is clear —
823/// is not listed and is not a gap; see [`parity_verdict`]. A backend's own
824/// refusal needs a row here whatever the device reports, which is what stops a
825/// row being retired by a device that could not have proved anything either way.
826///
827/// Entries are grouped by capability. [`BackendKind::Null`] never appears: it
828/// records rather than executes, so it is not part of the parity model — see
829/// [`BackendKind::is_gpu`].
830pub const DIVERGENCES: &[Divergence] = &[
831 // --- fills: the worked example, and why no row is left ---
832 //
833 // `BufferFillZero` on Dx12 is not here, and its absence is what the list is
834 // for: the row left because the work landed. `crcbl_dx12`'s `fill_buffer`
835 // copies out of a zeroed device-local resource, which is `wgpu-hal`'s dx12
836 // answer to the same call. The valued fills that were the rest of this
837 // section went with the verb's `value` on 2026-08-19 — see `BufferFillZero`
838 // — so the section is a heading over nothing, deliberately.
839 // --- draws ---
840 //
841 // `DrawIndirectCount` on Metal is not here, and its absence is the second
842 // worked example: the row left because the work landed. Metal still has no
843 // count-buffer draw — that never changes — but it does not need one. A draw
844 // of zero instances renders nothing, so `crcbl_mtl::indirect_count` packs
845 // the argument structures with a compute kernel, gives every structure at
846 // or past the GPU-written count no instances, and issues `max_draw_count`
847 // ordinary indirect draws. See [`METAL_NO_DRAW_INDIRECT_COUNT`], which the
848 // backend still shares for the device-gated refusal.
849 Divergence {
850 capability: Capability::DrawIndirectCount,
851 backend: BackendKind::WebGpu,
852 kind: DivergenceKind::ApiAbsence,
853 why: "GPURenderPassEncoder carries drawIndirect and drawIndexedIndirect and no \
854 count-buffer form of either, so the draw count can only come from the CPU; the \
855 stream has no tag for one because there is nothing to encode",
856 },
857 // `IndirectArgumentPaddedStride` on WebGPU is not here either, and it is the
858 // third worked example — the one where the row was never true of the
859 // backend in the first place. It said
860 // `GPURenderPassEncoder.drawIndirect(indirectBuffer, indirectOffset)` reads
861 // one tightly packed structure and has no stride to honour, which is a true
862 // sentence about the WebGPU call and a false one about this backend: the
863 // stride crosses the stream whole and `web/engine/gpu-replay.js` unrolls the
864 // draw into one `drawIndirect` per structure at `offset + i * stride`, so a
865 // padded stride is honoured by walking rather than by a parameter. An
866 // `ApiAbsence` that is only an absence in the API is how a row survives
867 // review: the reason reads as checkable and the thing it describes is not
868 // the thing being declared.
869 // Metal mesh/task rows were retired after native execution qualification;
870 // unsupported Metal devices use the shared hardware/OS capability gate.
871 Divergence {
872 capability: Capability::MeshShading,
873 backend: BackendKind::Dx12,
874 kind: DivergenceKind::Unwritten,
875 why: "the calls exist — crcbl_dx12::pipeline packs the D3D12_PIPELINE_STATE_STREAM_DESC an \
876 amplification and mesh stage need, and the encoder records DispatchMesh and an \
877 ExecuteIndirect of DISPATCH_MESH — but crcbl_dx12::adapter does not report \
878 Features::MESH_SHADER, so the capability cannot answer Yes. Reporting it moves every \
879 D3D12 adapter onto GeometryPath::MeshShader and re-keys every golden image, which is \
880 its own change (the DX12 mesh reporting slice)",
881 },
882 Divergence {
883 capability: Capability::MeshShading,
884 backend: BackendKind::WebGpu,
885 kind: DivergenceKind::ApiAbsence,
886 why: "WebGPU has no mesh stage: GPUDevice creates render and compute pipelines only and \
887 GPURenderPassEncoder has no draw for one. No proposal for it has reached the \
888 specification, so this is the API rather than the slice",
889 },
890 Divergence {
891 capability: Capability::TaskShaderStage,
892 backend: BackendKind::Dx12,
893 kind: DivergenceKind::Unwritten,
894 why: "MeshPipelineDesc::task reaches D3D12's amplification stage through the same \
895 subobject stream the mesh one does, and it is behind the same unreported flag; see \
896 the MeshShading entry",
897 },
898 Divergence {
899 capability: Capability::TaskShaderStage,
900 backend: BackendKind::WebGpu,
901 kind: DivergenceKind::ApiAbsence,
902 why: "WebGPU has no mesh stage to put an amplification stage in front of; see the \
903 MeshShading entry",
904 },
905 // --- bindings ---
906 Divergence {
907 capability: Capability::UpdateBindGroup,
908 backend: BackendKind::WebGpu,
909 kind: DivergenceKind::ApiAbsence,
910 why: WEBGPU_BIND_GROUPS_ARE_IMMUTABLE,
911 },
912 Divergence {
913 capability: Capability::PushConstants,
914 backend: BackendKind::WebGpu,
915 kind: DivergenceKind::ApiAbsence,
916 why: "WebGPU has no push constants — GPUPipelineLayoutDescriptor carries bind group \
917 layouts and nothing beside them. The substitute is a dynamic-offset uniform buffer, \
918 which the seam already carries as bind-group dynamic offsets",
919 },
920 // The Metal row that used to sit here is gone, and it left the way a row is
921 // meant to: `crcbl-mtl` binds a VARIABLE_COUNT slot as one argument buffer
922 // of `MTLBuffer::gpuAddress` values and keeps its contents resident with
923 // `useResource:`, so the backend answers `Support::Yes` wherever the device
924 // reports `DESCRIPTOR_INDEXING`.
925 Divergence {
926 capability: Capability::BindlessDescriptorArray,
927 backend: BackendKind::WebGpu,
928 kind: DivergenceKind::ApiAbsence,
929 why: "GPUBindGroupLayoutEntry carries a binding, a visibility and one resource layout and \
930 no count, so WebGPU has no binding arrays at all, fixed-size or runtime-sized; a \
931 material table is indexed through a storage buffer here rather than through \
932 descriptors",
933 },
934 // The WebGPU row that used to sit here is gone: the gap was the seam's own
935 // descriptor, and `BindingKind::StorageImage` now carries the `view_type`
936 // and `format` `GPUStorageTextureBindingLayout` demands, so `crcbl-webgpu`
937 // answers `Support::Yes`. What is left is the backend nobody is finishing.
938 // --- rasteriser state ---
939 //
940 // Only one entry, and that is the point: `PolygonModeLine`, `DepthClamp` and
941 // `SamplerAnisotropy` are refused by every backend *only* where the device
942 // reports the flag clear, which is `Features` doing its job. WebGPU is the
943 // exception because it has no wireframe on any device it could ever open.
944 Divergence {
945 capability: Capability::PolygonModeLine,
946 backend: BackendKind::WebGpu,
947 kind: DivergenceKind::ApiAbsence,
948 why: "GPUPrimitiveState carries topology, stripIndexFormat, frontFace, cullMode and \
949 unclippedDepth and no fill mode, so WebGPU has no core expression for a wireframe; \
950 unlike the other two rasteriser capabilities this is absent from the API rather than \
951 from a given device",
952 },
953 // --- queries ---
954 //
955 // **The occlusion four are one decision, taken on 2026-09-06**, and they are
956 // the only rows in this list where every backend diverges for the same
957 // reason and that reason is not any backend's: `crcbl_hal::CommandEncoder`
958 // has no verb that scopes a count, so `QueryKind::Occlusion` is refused
959 // everywhere by `QueryKind::check_supported`. See `NO_OCCLUSION_QUERY_VERB`,
960 // which is the sentence all four carry and every `Device::supports`
961 // declares. `Unwritten` rather than `ApiAbsence` on purpose: all four APIs
962 // express occlusion queries, and the missing piece is a seam verb somebody
963 // here would write — the alternative was deleting the capability, and
964 // deleting it would have recorded a decision against occlusion queries that
965 // nobody took. `docs/notes/backends.md` holds the argument and the
966 // measurement the refusal replaced.
967 Divergence {
968 capability: Capability::OcclusionQuery,
969 backend: BackendKind::Vulkan,
970 kind: DivergenceKind::Unwritten,
971 why: NO_OCCLUSION_QUERY_VERB,
972 },
973 Divergence {
974 capability: Capability::OcclusionQuery,
975 backend: BackendKind::WebGpu,
976 kind: DivergenceKind::Unwritten,
977 why: NO_OCCLUSION_QUERY_VERB,
978 },
979 Divergence {
980 capability: Capability::OcclusionQuery,
981 backend: BackendKind::Metal,
982 kind: DivergenceKind::Unwritten,
983 why: NO_OCCLUSION_QUERY_VERB,
984 },
985 Divergence {
986 capability: Capability::OcclusionQuery,
987 backend: BackendKind::Dx12,
988 kind: DivergenceKind::Unwritten,
989 why: NO_OCCLUSION_QUERY_VERB,
990 },
991 // Metal timestamp queries were proved on an M3 Pro on 2026-09-10,
992 // including render/compute boundaries and GPU-side resolves. Clear-only
993 // render passes and empty compute passes needed fixes before that proof;
994 // docs/notes/metal-local-baseline.md records the hardware evidence.
995 // The WebGPU TimestampQuery row that used to sit here is gone, and it left
996 // the way `StorageImageBinding`'s did: the gap was the seam's own verb. It
997 // had a free-standing `write_timestamp` naming an arbitrary point in the
998 // command stream, which WebGPU has no expression for at all, so
999 // `create_query_set` refused a timestamp set rather than hand out a handle a
1000 // profiler would fill with zeros. `PassTimestampWrites` is
1001 // `GPURenderPassDescriptor.timestampWrites`' own shape, so the browser
1002 // backend passes it straight through and answers `Support::Yes`. Worth
1003 // reading beside the occlusion rows above, which are the same shape and went
1004 // the other way: a gap in the seam's own vocabulary, refused by
1005 // `create_query_set` rather than papered over — and there, unlike here, the
1006 // verb has not arrived yet.
1007 Divergence {
1008 capability: Capability::PipelineStatisticsQuery,
1009 backend: BackendKind::Metal,
1010 // Reclassified with TimestampQuery on 2026-08-19, from the same probe
1011 // output, and written with it. It stays Unwritten for the same reason —
1012 // no device has run it — plus one this backend cannot fix on its own:
1013 // see the second half of the reason.
1014 kind: DivergenceKind::Unrun,
1015 why: "the calls exist — crcbl_mtl::device's create_query_set builds an \
1016 MTLCounterSampleBuffer over MTLCommonCounterSetStatistic and crcbl_mtl::command's \
1017 resolve_query_set reaches it through the blit encoder's \
1018 resolveCounters:inRange:destinationBuffer:destinationOffset: at the \
1019 MTLCounterResultStatistic width crcbl_mtl::query derives — but no device has ever \
1020 run them, and two of the seam's read paths cannot be written at all. **Nothing can \
1021 sample one**: PassTimestampWrites names timestamps and crcbl_hal::CommandEncoder has \
1022 no other query verb, so no work a caller records will ever write into this set — \
1023 which is exactly what Capability::OcclusionQuery means on every backend, and why \
1024 crcbl_mtl::device's supports claims the create, the resolve and the destroy and \
1025 nothing more. **And query_results refuses it**: an MTLCounterResultStatistic is \
1026 eight u64s while that call reads one u64 per query, so there is nowhere for the \
1027 other seven to go, and returning the first would answer a different question in the \
1028 shape of this one; crcbl-dx12 refuses the identical read of an eleven-field \
1029 D3D12_QUERY_DATA_PIPELINE_STATISTICS in the same words, and the fix is a seam that \
1030 carries a result width. crcbl_mtl::adapter reports \
1031 Features::PIPELINE_STATISTICS_QUERY for a device advertising \
1032 MTLCommonCounterSetStatistic, and gates it on that alone rather than on \
1033 supportsCounterSampling:, because nothing samples this kind and a gate on an answer \
1034 no line reads decides nothing. The Mac in CI advertises counterSets=0, so it reports \
1035 the flag clear; that is a device fact reported per device, not what leaves the row \
1036 open. Retiring this row takes a Mac that reports the flag creating and resolving a \
1037 set, as the occlusion kind's absence from this list took",
1038 },
1039 Divergence {
1040 capability: Capability::PipelineStatisticsQuery,
1041 backend: BackendKind::WebGpu,
1042 kind: DivergenceKind::ApiAbsence,
1043 why: "GPUQueryType is exactly 'occlusion' and 'timestamp', so there is no \
1044 pipeline-statistics query set for WebGPU to create",
1045 },
1046 // --- synchronisation ---
1047 Divergence {
1048 capability: Capability::TimelineSemaphore,
1049 backend: BackendKind::WebGpu,
1050 kind: DivergenceKind::ApiAbsence,
1051 why: "WebGPU has no semaphores. It orders submissions implicitly — one queue, executed in \
1052 order, hazards tracked by the browser — and its only completion signal, \
1053 GPUQueue.onSubmittedWorkDone(), resolves for everything submitted so far and carries \
1054 no value, so nothing there could drive a counter. create_semaphore refuses \
1055 SemaphoreKind::Timeline; it used to hand out a handle whose semaphore_value answered \
1056 0 for ever, which is the succeed-while-doing-nothing shape this enum exists to make \
1057 visible",
1058 },
1059 Divergence {
1060 capability: Capability::CpuTimelineWait,
1061 backend: BackendKind::WebGpu,
1062 kind: DivergenceKind::ApiAbsence,
1063 why: "create_semaphore refuses the timeline kind, so there is no counter for a CPU wait to \
1064 read; the binary semaphore this backend does hand out is GPU-waitable only. \
1065 wait_semaphores refuses rather than answering Ok(true) for a wait it never evaluated \
1066 — see the TimelineSemaphore entry",
1067 },
1068 Divergence {
1069 capability: Capability::CpuTimelineSignal,
1070 backend: BackendKind::WebGpu,
1071 kind: DivergenceKind::ApiAbsence,
1072 why: "create_semaphore refuses the timeline kind, so there is no counter for a host signal \
1073 to advance; WebGPU has no signalable object of any kind — see the TimelineSemaphore \
1074 entry",
1075 },
1076 Divergence {
1077 capability: Capability::TimelineWaitBeforeSignal,
1078 backend: BackendKind::WebGpu,
1079 kind: DivergenceKind::ApiAbsence,
1080 why: "a wait of any kind is refused here, so a wait on a value nothing has signalled is \
1081 refused with the rest; see the CpuTimelineWait entry",
1082 },
1083];
1084
1085/// Every divergence that stands between a backend crcbl is **keeping** and
1086/// parity.
1087///
1088/// The answer to "what is left?", derived rather than maintained. A row is here
1089/// when its backend [drives a GPU](BackendKind::is_gpu) and its
1090/// [`kind`](Divergence::kind) [blocks parity](DivergenceKind::blocks_parity) —
1091/// so [`BackendKind::Null`] is excluded by the first half rather than by a
1092/// reader remembering to skip it, and [`DivergenceKind::ApiAbsence`] by the
1093/// second.
1094///
1095/// The set is snapshotted by this module's own tests, so it shrinks only when
1096/// somebody updates the snapshot deliberately. Yields in [`DIVERGENCES`] order.
1097pub fn parity_blockers() -> impl Iterator<Item = &'static Divergence> {
1098 DIVERGENCES
1099 .iter()
1100 .filter(|entry| entry.backend.is_gpu() && entry.kind.blocks_parity())
1101}
1102
1103/// The [`DIVERGENCES`] entry for this pair, if the pair is a known divergence.
1104///
1105/// A linear scan of a `const` slice, which is why the list is kept small enough
1106/// to read: this is asked once per capability in a test, never in a frame.
1107#[must_use]
1108pub fn divergence(capability: Capability, backend: BackendKind) -> Option<&'static Divergence> {
1109 DIVERGENCES
1110 .iter()
1111 .find(|entry| entry.capability == capability && entry.backend == backend)
1112}
1113
1114/// What the parity record has to say about one capability on one running
1115/// device — the outcome [`parity_verdict`] answers with.
1116///
1117/// Five outcomes rather than a `bool`, because "not a gap" used to cover two
1118/// unlike things: a divergence somebody reviewed, and a pair this device could
1119/// not settle either way. Folding them made a retirement free — see
1120/// [`UnprovableHere`](Self::UnprovableHere).
1121#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1122pub enum ParityVerdict {
1123 /// The backend performs it here. Nothing is owed, and a [`DIVERGENCES`] row
1124 /// for the pair would be stale.
1125 Supported,
1126
1127 /// The backend refuses and [`DIVERGENCES`] says why. The reviewed case, and
1128 /// the entry is carried so a report can print the sentence.
1129 Reviewed(&'static Divergence),
1130
1131 /// The device withheld the gating [`Features`] flag, so this run learned
1132 /// **nothing** about the backend — neither that it has the capability nor
1133 /// that it lacks it.
1134 ///
1135 /// Not a failure: the device is lesser, which `Features` already models and
1136 /// logs as a downgrade at creation, and there is no work anybody could do to
1137 /// make a software rasteriser grow a mesh stage.
1138 ///
1139 /// It is reported by name all the same, because "unprovable here" is a
1140 /// coverage gap and used to be indistinguishable from a clean pass. That
1141 /// indistinguishability is the whole defect this enum was split to fix: a
1142 /// gated pair reached it whether or not [`DIVERGENCES`] named the pair, so a
1143 /// row could be deleted and no run anywhere would notice.
1144 UnprovableHere(Features),
1145
1146 /// **The backend's own refusal, with nobody's name on it.** The gap.
1147 ///
1148 /// [`Support::No`] means this backend would refuse on every device, so no
1149 /// device's [`Features`] excuse it: either a row was never written, or one
1150 /// was retired without the backend having learnt to do the thing.
1151 Unreviewed,
1152
1153 /// The backend answered [`Support::NotOnThisDevice`] and the device did not
1154 /// withhold anything — the capability has no
1155 /// [`gating_feature`](Capability::gating_feature), or it has one and this
1156 /// device reports it.
1157 ///
1158 /// A gap, and a louder one than [`Unreviewed`](Self::Unreviewed): the
1159 /// excused arm is the one thing a backend could hide behind, so it is the
1160 /// one arm whose claim is checked against the device rather than believed.
1161 FalseDeviceGate,
1162}
1163
1164impl ParityVerdict {
1165 /// Whether this verdict is a **parity gap** — something nobody has accounted
1166 /// for.
1167 ///
1168 /// The two failing outcomes and no others. [`UnprovableHere`] is deliberately
1169 /// not one: a device that cannot answer is not a defect in the backend.
1170 ///
1171 /// [`UnprovableHere`]: Self::UnprovableHere
1172 #[must_use]
1173 pub const fn is_gap(self) -> bool {
1174 match self {
1175 Self::Supported | Self::Reviewed(_) | Self::UnprovableHere(_) => false,
1176 Self::Unreviewed | Self::FalseDeviceGate => true,
1177 }
1178 }
1179}
1180
1181/// What the parity record says about `capability` on `backend`, given what the
1182/// backend `declared` on a device reporting `features`.
1183///
1184/// The rule the agnostic seam suite applies to every capability of a running
1185/// device, and the whole of what "reviewed divergence" means here:
1186///
1187/// * [`Support::Yes`] is [`Supported`](ParityVerdict::Supported). The backend
1188/// does it, and the suite's other half holds it to that by driving the call.
1189/// * [`Support::NotOnThisDevice`] is
1190/// [`UnprovableHere`](ParityVerdict::UnprovableHere) — **if the device really
1191/// did withhold the gate**, which is checked here rather than assumed.
1192/// Otherwise the backend blamed a device that gave it what it asked for, and
1193/// that is [`FalseDeviceGate`](ParityVerdict::FalseDeviceGate).
1194/// * [`Support::No`] that [`DIVERGENCES`] names is
1195/// [`Reviewed`](ParityVerdict::Reviewed). Somebody decided it and wrote down
1196/// why.
1197/// * [`Support::No`] that it does not name is
1198/// [`Unreviewed`](ParityVerdict::Unreviewed): this backend cannot do something
1199/// its peers can and nobody has said so. **The device's `features` do not
1200/// enter into it** — that is the fix. The old rule waived a refusal whenever
1201/// the device reported the gate clear, which waived it for backends that had
1202/// never looked at the gate, and so retired their rows for them.
1203///
1204/// Deliberately blind to [`DivergenceKind`]: a written reason is what makes a
1205/// refusal reviewed, whatever kind of divergence it turned out to be. "Which of
1206/// them is still somebody's work" is the other question, and
1207/// [`parity_blockers`] is where it is asked.
1208#[must_use]
1209pub fn parity_verdict(
1210 capability: Capability,
1211 backend: BackendKind,
1212 declared: Support,
1213 features: Features,
1214) -> ParityVerdict {
1215 match declared {
1216 Support::Yes => ParityVerdict::Supported,
1217 Support::NotOnThisDevice(_) => match capability.gating_feature() {
1218 Some(gate) if !features.contains(gate) => ParityVerdict::UnprovableHere(gate),
1219 _ => ParityVerdict::FalseDeviceGate,
1220 },
1221 Support::No(_) => match divergence(capability, backend) {
1222 Some(entry) => ParityVerdict::Reviewed(entry),
1223 None => ParityVerdict::Unreviewed,
1224 },
1225 }
1226}
1227
1228#[cfg(test)]
1229mod tests {
1230 use super::*;
1231
1232 /// Every GPU backend, for the tests that must sweep them. Written out rather
1233 /// than derived, so that a new [`BackendKind`] fails
1234 /// [`every_gpu_backend_is_in_this_sweep`] instead of silently escaping the
1235 /// parity model.
1236 const GPU_BACKENDS: [BackendKind; 4] = [
1237 BackendKind::Vulkan,
1238 BackendKind::WebGpu,
1239 BackendKind::Metal,
1240 BackendKind::Dx12,
1241 ];
1242
1243 #[test]
1244 fn every_gpu_backend_is_in_this_sweep() {
1245 for backend in GPU_BACKENDS {
1246 assert!(backend.is_gpu(), "{backend} must be in the parity model");
1247 }
1248 assert!(!BackendKind::Null.is_gpu());
1249 // The count comes from `is_gpu`'s own match rather than from a literal,
1250 // so a fifth backend makes this fail instead of quietly sitting outside
1251 // every sweep below.
1252 let every = [
1253 BackendKind::Vulkan,
1254 BackendKind::WebGpu,
1255 BackendKind::Metal,
1256 BackendKind::Dx12,
1257 BackendKind::Null,
1258 ];
1259 assert_eq!(
1260 every.iter().filter(|kind| kind.is_gpu()).count(),
1261 GPU_BACKENDS.len(),
1262 "a BackendKind drives a GPU and is not swept by these tests"
1263 );
1264 }
1265
1266 /// `ALL` is generated from the enum's own variant list, so it cannot fail by
1267 /// omission — what this catches is the macro being replaced by a
1268 /// hand-written array later, which is the whole reason the macro exists.
1269 #[test]
1270 fn all_holds_every_capability_exactly_once() {
1271 let mut seen: Vec<Capability> = Capability::ALL.to_vec();
1272 let count = seen.len();
1273 seen.sort_unstable();
1274 seen.dedup();
1275 assert_eq!(seen.len(), count, "a capability appears twice in ALL");
1276 assert!(
1277 count >= 20,
1278 "ALL has shrunk to {count}; the capabilities are derived from real refusal sites and \
1279 those have not gone away"
1280 );
1281 }
1282
1283 /// A name is what a failing parity report prints, so two variants sharing
1284 /// one would leave the report unable to say which diverged.
1285 #[test]
1286 fn every_capability_has_its_own_name() {
1287 let mut names: Vec<&'static str> = Capability::ALL.iter().map(|c| c.name()).collect();
1288 let count = names.len();
1289 names.sort_unstable();
1290 names.dedup();
1291 assert_eq!(names.len(), count, "two capabilities share a name");
1292 for capability in Capability::ALL {
1293 assert_eq!(capability.to_string(), capability.name());
1294 assert!(!capability.name().is_empty());
1295 }
1296 }
1297
1298 /// A gate must be a single flag. `Features::GPU_DRIVEN` is a named union,
1299 /// and a capability gated on it would be unsatisfiable on any device missing
1300 /// any one of six unrelated things.
1301 #[test]
1302 fn a_gating_feature_is_always_exactly_one_flag() {
1303 let mut gated = 0;
1304 for capability in Capability::ALL {
1305 let Some(gate) = capability.gating_feature() else {
1306 continue;
1307 };
1308 gated += 1;
1309 assert_eq!(
1310 gate.bits().count_ones(),
1311 1,
1312 "{capability} is gated on {gate:?}, which is not a single flag"
1313 );
1314 }
1315 assert!(
1316 gated > 0 && gated < Capability::ALL.len(),
1317 "both halves must be populated: {gated} of {} capabilities are gated, and a run where \
1318 all or none were would make the parity rule vacuous in one direction",
1319 Capability::ALL.len()
1320 );
1321 }
1322
1323 /// The one constructor a device gate is read through, and the only source of
1324 /// [`Support::NotOnThisDevice`] — so this asserts the *variant*, not merely
1325 /// that it said no. A `granted` that answered [`Support::No`] would put every
1326 /// lesser device back in front of [`ParityVerdict::Unreviewed`].
1327 #[test]
1328 fn granted_reads_the_flag_it_was_given() {
1329 let device = Features::COMPUTE | Features::TIMELINE_SEMAPHORE;
1330 assert_eq!(
1331 Support::granted(device, Features::COMPUTE, "no compute"),
1332 Support::Yes
1333 );
1334 assert_eq!(
1335 Support::granted(device, Features::MESH_SHADER, "no mesh shader"),
1336 Support::NotOnThisDevice("no mesh shader")
1337 );
1338 // And it is `contains`, not `intersects`: a capability gated on a flag
1339 // the device half-has would otherwise report supported.
1340 assert_eq!(
1341 Support::granted(device, Features::GPU_DRIVEN, "not the whole bundle"),
1342 Support::NotOnThisDevice("not the whole bundle")
1343 );
1344 }
1345
1346 #[test]
1347 fn support_carries_the_reason_and_nothing_else() {
1348 assert!(Support::Yes.is_yes());
1349 assert_eq!(Support::Yes.reason(), None);
1350 assert_eq!(Support::Yes.to_string(), "supported");
1351
1352 let refused = Support::No("there is no such call");
1353 assert!(!refused.is_yes());
1354 assert_eq!(refused.reason(), Some("there is no such call"));
1355 assert_eq!(
1356 refused.to_string(),
1357 "unsupported: there is no such call",
1358 "the reason must reach the reader, not merely be stored"
1359 );
1360
1361 // The two refusals read differently, because a reader deciding whether
1362 // to try another adapter needs to know which one this was.
1363 let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
1364 assert!(!withheld.is_yes());
1365 assert_eq!(
1366 withheld.reason(),
1367 Some("this device reports no MESH_SHADER")
1368 );
1369 assert_eq!(
1370 withheld.to_string(),
1371 "unsupported on this device: this device reports no MESH_SHADER"
1372 );
1373 assert_ne!(
1374 withheld,
1375 Support::No("this device reports no MESH_SHADER"),
1376 "the same sentence in the two arms must not compare equal, or the parity rule is \
1377 reading a string rather than a classification"
1378 );
1379 }
1380
1381 /// One pair, one entry. A duplicate would make [`divergence`] return the
1382 /// first and hide whichever reason somebody added second.
1383 #[test]
1384 fn no_pair_is_listed_twice() {
1385 let mut pairs: Vec<(Capability, String)> = DIVERGENCES
1386 .iter()
1387 .map(|entry| (entry.capability, entry.backend.to_string()))
1388 .collect();
1389 let count = pairs.len();
1390 pairs.sort_unstable();
1391 pairs.dedup();
1392 assert_eq!(
1393 pairs.len(),
1394 count,
1395 "a (capability, backend) pair is listed twice"
1396 );
1397 }
1398
1399 /// The list is read by whoever is deciding whether a divergence should stay,
1400 /// so an entry that says nothing is an entry nobody reviewed.
1401 #[test]
1402 fn every_divergence_gives_a_real_reason() {
1403 for entry in DIVERGENCES {
1404 assert!(
1405 entry.why.len() > 40,
1406 "{} on {}: {:?} is too short to be a reason anyone can act on",
1407 entry.capability,
1408 entry.backend,
1409 entry.why
1410 );
1411 }
1412 }
1413
1414 /// [`BackendKind::Null`] records rather than executes, so an entry naming it
1415 /// would be describing a recorder's limitation as a backend divergence.
1416 #[test]
1417 fn divergences_name_only_gpu_backends() {
1418 for entry in DIVERGENCES {
1419 assert!(
1420 entry.backend.is_gpu(),
1421 "{} names {}, which is not a GPU backend",
1422 entry.capability,
1423 entry.backend
1424 );
1425 }
1426 }
1427
1428 /// A capability every GPU backend lacks is a seam behaviour nothing
1429 /// implements, not a *divergence* — so it may only be listed once somebody
1430 /// has decided to leave it that way.
1431 ///
1432 /// **The exception is [`DEFERRED_CAPABILITIES`], and it is a hand-edited
1433 /// list for the same reason [`REVIEWED_BLOCKERS`] is.** A capability the
1434 /// whole seam refuses still belongs in [`DIVERGENCES`] when the refusal was
1435 /// weighed and taken — [`Capability::OcclusionQuery`] is one, and the rows
1436 /// are what makes its cost visible instead of the gap being absorbed into
1437 /// prose. What this catches is the other case: a capability quietly refused
1438 /// everywhere because nobody wrote it, filed as four parity exceptions and
1439 /// read as four separate backend gaps.
1440 ///
1441 /// The other half too: [`divergence`] must find every entry the list holds,
1442 /// and must not invent one.
1443 #[test]
1444 fn a_divergence_is_something_some_backend_actually_has() {
1445 for capability in Capability::ALL {
1446 let lacking = GPU_BACKENDS
1447 .iter()
1448 .filter(|backend| divergence(*capability, **backend).is_some())
1449 .count();
1450 assert!(
1451 lacking < GPU_BACKENDS.len() || DEFERRED_CAPABILITIES.contains(capability),
1452 "{capability} is listed as absent on every GPU backend and nothing parked it, so \
1453 it is not a divergence — it is a seam behaviour nothing implements, and that \
1454 belongs in the seam's own docs rather than in a parity exception list. If it is \
1455 refused everywhere on purpose, say so in DEFERRED_CAPABILITIES"
1456 );
1457 }
1458
1459 for entry in DIVERGENCES {
1460 assert_eq!(
1461 divergence(entry.capability, entry.backend),
1462 Some(entry),
1463 "the lookup must find every entry the list holds"
1464 );
1465 }
1466 assert_eq!(
1467 divergence(
1468 Capability::IndirectArgumentPaddedStride,
1469 BackendKind::Vulkan
1470 ),
1471 None,
1472 "Vulkan takes a padded stride, and the list would be describing it wrongly"
1473 );
1474 assert_eq!(
1475 divergence(Capability::PushConstants, BackendKind::Null),
1476 None
1477 );
1478 }
1479
1480 /// The rule, checked on every case that decides it. Written as a table
1481 /// because the failure mode is an `&&` where an `||` belongs, which reads
1482 /// identically and makes the parity suite either vacuous or unpassable.
1483 #[test]
1484 fn a_parity_gap_is_a_backend_refusal_nobody_wrote_down() {
1485 let all = Features::all();
1486 let no_mesh = all.difference(Features::MESH_SHADER);
1487 let refused = Support::No("this backend has not written it");
1488 let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
1489
1490 // Supported: nothing owed, whatever the list says.
1491 assert_eq!(
1492 parity_verdict(
1493 Capability::MeshShading,
1494 BackendKind::Vulkan,
1495 Support::Yes,
1496 all
1497 ),
1498 ParityVerdict::Supported
1499 );
1500 // A backend refusal the list names: reviewed. An *ungated* pair, so the
1501 // verdict cannot be coming from a flag the device happens to report —
1502 // `IndirectArgumentPaddedStride` stood here until its row left, and the
1503 // replacement was chosen to keep that property rather than only to
1504 // compile.
1505 assert_eq!(
1506 parity_verdict(
1507 Capability::UpdateBindGroup,
1508 BackendKind::WebGpu,
1509 refused,
1510 all
1511 ),
1512 ParityVerdict::Reviewed(
1513 divergence(Capability::UpdateBindGroup, BackendKind::WebGpu)
1514 .expect("WebGPU's immutable bind groups are on the list")
1515 )
1516 );
1517 assert_eq!(Capability::UpdateBindGroup.gating_feature(), None);
1518 // The device withheld the gate: this run proves nothing either way, and
1519 // saying so is not a failure.
1520 assert_eq!(
1521 parity_verdict(
1522 Capability::MeshShading,
1523 BackendKind::Vulkan,
1524 withheld,
1525 no_mesh
1526 ),
1527 ParityVerdict::UnprovableHere(Features::MESH_SHADER)
1528 );
1529 // A backend refusal nobody wrote down: a gap.
1530 assert_eq!(
1531 parity_verdict(Capability::MeshShading, BackendKind::Vulkan, refused, all),
1532 ParityVerdict::Unreviewed
1533 );
1534
1535 // **The hole this rule was rewritten to close.** The same unlisted
1536 // backend refusal on a device that withheld the gate: the old rule
1537 // waived it, so retiring the row cost nothing and no run anywhere
1538 // noticed. It is the same gap it is on a device that reports the flag.
1539 assert_eq!(
1540 parity_verdict(
1541 Capability::MeshShading,
1542 BackendKind::Vulkan,
1543 refused,
1544 no_mesh
1545 ),
1546 ParityVerdict::Unreviewed,
1547 "a backend's own refusal is a gap on every device; a lesser one cannot excuse it"
1548 );
1549
1550 // And the escape hatch is checked rather than believed, in both of its
1551 // failure shapes: an ungated capability has no device to blame, and a
1552 // device that reported the flag did not withhold it.
1553 assert_eq!(Capability::BufferFillZero.gating_feature(), None);
1554 assert_eq!(
1555 parity_verdict(
1556 Capability::BufferFillZero,
1557 BackendKind::Dx12,
1558 withheld,
1559 Features::empty()
1560 ),
1561 ParityVerdict::FalseDeviceGate
1562 );
1563 assert_eq!(
1564 parity_verdict(Capability::MeshShading, BackendKind::Vulkan, withheld, all),
1565 ParityVerdict::FalseDeviceGate
1566 );
1567
1568 // Ungated and unlisted: always a gap, whatever the device reports.
1569 assert!(
1570 parity_verdict(
1571 Capability::BufferFillZero,
1572 BackendKind::Vulkan,
1573 refused,
1574 Features::empty()
1575 )
1576 .is_gap()
1577 );
1578 // Ungated and listed: never a gap. WebGPU's immutable bind groups,
1579 // because nothing in `Features` describes rewriting one.
1580 //
1581 // The indirect stride used to stand here, on the grounds that the row
1582 // was permanent. No row is: that one left when somebody read the
1583 // replayer and found it already walking the stride. A fixture is picked
1584 // for the shape it exercises — ungated, and on the list — and the pair
1585 // that has it is checked rather than assumed.
1586 assert!(
1587 !parity_verdict(
1588 Capability::UpdateBindGroup,
1589 BackendKind::WebGpu,
1590 refused,
1591 Features::empty()
1592 )
1593 .is_gap()
1594 );
1595 }
1596
1597 /// Which verdicts fail, as a table: the failure mode is a variant landing on
1598 /// the wrong side, which would either make the suite unpassable or make the
1599 /// whole report advisory.
1600 #[test]
1601 fn only_an_unaccounted_refusal_is_a_gap() {
1602 let entry = &DIVERGENCES[0];
1603 assert!(!ParityVerdict::Supported.is_gap());
1604 assert!(!ParityVerdict::Reviewed(entry).is_gap());
1605 assert!(!ParityVerdict::UnprovableHere(Features::MESH_SHADER).is_gap());
1606 assert!(ParityVerdict::Unreviewed.is_gap());
1607 assert!(ParityVerdict::FalseDeviceGate.is_gap());
1608 }
1609
1610 /// **Every row in the list is one a running backend can be held to.**
1611 ///
1612 /// The property the rule rewrite buys, asserted over the data rather than
1613 /// argued in a doc comment: a row exists to excuse a [`Support::No`], and
1614 /// [`parity_verdict`] answers [`ParityVerdict::Reviewed`] for that pair on
1615 /// **every** device, including one reporting nothing at all. So deleting any
1616 /// row turns that same pair into [`ParityVerdict::Unreviewed`] on the
1617 /// backend's own CI arm — there is no device on which the deletion passes
1618 /// unnoticed, which is what "a retirement must be earned" means here.
1619 #[test]
1620 fn no_row_can_be_retired_without_a_run_noticing() {
1621 let refused = Support::No("the refusal this row exists to excuse");
1622 for entry in DIVERGENCES {
1623 for features in [Features::empty(), Features::all()] {
1624 assert_eq!(
1625 parity_verdict(entry.capability, entry.backend, refused, features),
1626 ParityVerdict::Reviewed(entry),
1627 "{} on {}: the row must excuse the refusal on every device",
1628 entry.capability,
1629 entry.backend
1630 );
1631 // The counterfactual — that same refusal with no row behind it.
1632 // `divergence` is the only thing the rule reads for a
1633 // `Support::No`, so an unlisted pair *is* what a deleted row
1634 // leaves. `Null` stands in for one because the list can never
1635 // name it — `divergences_name_only_gpu_backends` is what holds
1636 // that — which is why it replaced Vulkan here on 2026-09-06,
1637 // when the occlusion rows gave Vulkan an entry and the
1638 // counterfactual a pair that was no longer unlisted.
1639 assert_eq!(
1640 divergence(entry.capability, BackendKind::Null),
1641 None,
1642 "the list has grown a Null row, which divergences_name_only_gpu_backends \
1643 forbids and this counterfactual depends on"
1644 );
1645 assert_eq!(
1646 parity_verdict(entry.capability, BackendKind::Null, refused, features),
1647 ParityVerdict::Unreviewed,
1648 "{}: an unlisted backend refusal must be a gap on every device, or deleting \
1649 the row above would cost nothing",
1650 entry.capability
1651 );
1652 }
1653 }
1654 }
1655
1656 /// Every divergence standing between crcbl and its stated end state, as
1657 /// reviewed — the whole of what full backend parity still asks for.
1658 /// **Update this deliberately.**
1659 ///
1660 /// A snapshot rather than a rule, and that is the point: a row leaves only
1661 /// when somebody writes the code, overturns the decline, or shows the API
1662 /// cannot express it after all. Each of those is a review, and a test that
1663 /// merely counted the rows — or checked that each had *some* kind — would
1664 /// pass whether the classification were right or wrong.
1665 const REVIEWED_BLOCKERS: &[(Capability, BackendKind, DivergenceKind)] = &[
1666 // **`OcclusionQuery` is the one row every backend has**, and the only
1667 // one here that is nobody's backend work: `crcbl_hal::CommandEncoder`
1668 // has no verb that scopes a count, so every `create_query_set` refuses
1669 // the kind — see `NO_OCCLUSION_QUERY_VERB` and the four `DIVERGENCES`
1670 // rows it is the reason for. Decided 2026-09-06 to refuse rather than
1671 // finish or delete; `docs/notes/backends.md` argues it. These four are
1672 // parked by that decision rather than by a backend's deferral, which is
1673 // what `DEFERRED_CAPABILITIES` says.
1674 (
1675 Capability::OcclusionQuery,
1676 BackendKind::Vulkan,
1677 DivergenceKind::Unwritten,
1678 ),
1679 (
1680 Capability::OcclusionQuery,
1681 BackendKind::WebGpu,
1682 DivergenceKind::Unwritten,
1683 ),
1684 (
1685 Capability::OcclusionQuery,
1686 BackendKind::Metal,
1687 DivergenceKind::Unwritten,
1688 ),
1689 (
1690 Capability::OcclusionQuery,
1691 BackendKind::Dx12,
1692 DivergenceKind::Unwritten,
1693 ),
1694 // `crcbl-dx12`'s own rows are the two below: D3D12 expresses every
1695 // capability here, so every row of its below is `Unwritten` rather than
1696 // an `ApiAbsence` — mesh shading and the task stage are shader-model
1697 // features nobody has written against, not ones the API lacks.
1698 // `BufferFillZero` was another and left the way a row is meant to: the
1699 // backend fills to zero now, by copying out of a zeroed resource.
1700 (
1701 Capability::MeshShading,
1702 BackendKind::Dx12,
1703 DivergenceKind::Unwritten,
1704 ),
1705 (
1706 Capability::TaskShaderStage,
1707 BackendKind::Dx12,
1708 DivergenceKind::Unwritten,
1709 ),
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 // `crcbl-webgpu`'s only row is the occlusion one at the top, and that
1734 // is worth reading twice: everything *WebGPU* refuses is WebGPU itself
1735 // refusing, which is an `ApiAbsence` and not a blocker, so the one row
1736 // the browser backend carries is one this seam owes rather than one the
1737 // platform lacks. It had two rows of its own before and both left the
1738 // way a row is supposed to — the work landed.
1739 // `StorageImageBinding` went when `BindingKind::StorageImage` grew its
1740 // `view_type` and `format`; `TimestampQuery` went when the seam's
1741 // free-standing `write_timestamp` became `PassTimestampWrites` on the
1742 // pass descriptor, which is `timestampWrites`' own shape.
1743 ];
1744
1745 /// The backends whose remaining work is parked rather than owed.
1746 ///
1747 /// `crcbl-mtl` and `crcbl-dx12` were deferred on 2026-08-21 —
1748 /// `docs/plan/09-backends-metal-dx12.md` holds the state and
1749 /// `docs/backlog.md` the two `DEFERRED` entries. The crates and their CI
1750 /// jobs stay so a regression still shows; what stops is feature work on
1751 /// them.
1752 const DEFERRED_BACKENDS: &[BackendKind] = &[BackendKind::Metal, BackendKind::Dx12];
1753
1754 /// The capabilities whose remaining work is parked on every backend at once.
1755 ///
1756 /// A second axis, because [`Capability::OcclusionQuery`] is parked for a
1757 /// reason no backend's deferral covers: the work is a verb on
1758 /// [`crate::CommandEncoder`] plus its five implementations, and it was
1759 /// decided on 2026-09-06 that the verb waits until something wants the
1760 /// counts — `docs/notes/backends.md` and `docs/backlog.md` hold the
1761 /// decision. Folding these rows into [`DEFERRED_BACKENDS`] would have meant
1762 /// calling `crcbl-vk` and `crcbl-webgpu` deferred, which they are not.
1763 const DEFERRED_CAPABILITIES: &[Capability] = &[Capability::OcclusionQuery];
1764 /// **`parity_blockers` cannot reach empty while the deferrals hold, and
1765 /// this is what says so instead of the count quietly redefining done.**
1766 ///
1767 /// Every row [`parity_blockers`] yields is either on a
1768 /// [deferred backend](DEFERRED_BACKENDS) or is a
1769 /// [deferred capability](DEFERRED_CAPABILITIES), so the honest reading of a
1770 /// non-zero blocker count today is "parked", not "outstanding". Nothing
1771 /// about that is expressed by the number itself, and a reader who saw only
1772 /// the number would conclude there was work to pick up.
1773 ///
1774 /// **A failure here is the useful case.** A blocker on `crcbl-vk` or
1775 /// `crcbl-webgpu` that nothing parked is work somebody is meant to do, and
1776 /// it would otherwise join the parked rows and read as more of the same. The
1777 /// second assertion is what stops the first going vacuous: with no blockers
1778 /// at all, "none of them is live" is true and says nothing, and the deferral
1779 /// notes above have become the thing to delete.
1780 #[test]
1781 fn every_parity_blocker_is_deferred_by_its_backend_or_by_its_capability() {
1782 let live: Vec<String> = parity_blockers()
1783 .filter(|entry| {
1784 !DEFERRED_BACKENDS.contains(&entry.backend)
1785 && !DEFERRED_CAPABILITIES.contains(&entry.capability)
1786 })
1787 .map(|entry| format!("{} on {}", entry.capability, entry.backend))
1788 .collect();
1789 assert!(
1790 live.is_empty(),
1791 "these parity blockers are on backends nobody deferred, so they are work that \
1792 is actually owed rather than parked: {live:?}. Say which in the report \
1793 instead of leaving them to be read as more deferred rows"
1794 );
1795 assert!(
1796 parity_blockers().next().is_some(),
1797 "there are no parity blockers left at all, which makes the assertion above \
1798 vacuous. The deferral note on DEFERRED_BACKENDS and this test have \
1799 outlived their subject"
1800 );
1801 }
1802
1803 /// The one that makes the goal checkable: what
1804 /// [`parity_blockers`] answers must be what somebody reviewed, row for row.
1805 ///
1806 /// Fails when a row joins or leaves the blocker set, when a blocking row is
1807 /// reclassified, and when a row is moved to another backend — each of which
1808 /// is a change to "what is left" and none of which should reach `main`
1809 /// without a human editing [`REVIEWED_BLOCKERS`] to match.
1810 #[test]
1811 fn the_parity_blockers_are_exactly_the_reviewed_list() {
1812 let mut actual: Vec<(Capability, String, DivergenceKind)> = parity_blockers()
1813 .map(|entry| (entry.capability, entry.backend.to_string(), entry.kind))
1814 .collect();
1815 actual.sort_unstable();
1816 let mut reviewed: Vec<(Capability, String, DivergenceKind)> = REVIEWED_BLOCKERS
1817 .iter()
1818 .map(|(capability, backend, kind)| (*capability, backend.to_string(), *kind))
1819 .collect();
1820 reviewed.sort_unstable();
1821 assert_eq!(
1822 actual, reviewed,
1823 "the set of divergences between crcbl and parity has changed. That is the goal moving, \
1824 so say so: update REVIEWED_BLOCKERS to match, and if a row left the set, make sure it \
1825 left because the work landed or the API was shown to lack it — not because a kind was \
1826 widened to ApiAbsence to make it disappear"
1827 );
1828 }
1829
1830 /// **Every backend in the model is now a parity target, and the filter that
1831 /// said otherwise is gone.**
1832 ///
1833 /// `parity_blockers` used to filter on `BackendKind::is_parity_target`,
1834 /// whose only `false` arm besides `Null` was `Wgpu` — the bridge backend
1835 /// that was always going to be deleted, and whose divergences were therefore
1836 /// not work anybody would do. `crcbl-wgpu` went on 2026-08-21 and the two
1837 /// predicates became the same function, so the second was deleted rather
1838 /// than kept for a hypothetical successor.
1839 ///
1840 /// What is asserted here is the property that replaced it: the filter is
1841 /// `is_gpu`, every GPU backend passes it, and `Null` does not — so a row on
1842 /// any real backend reaches the blocker set and cannot be excluded by
1843 /// anything except its own kind.
1844 #[test]
1845 fn every_gpu_backend_is_inside_the_goal() {
1846 for backend in GPU_BACKENDS {
1847 assert!(
1848 backend.is_gpu(),
1849 "{backend} is a GPU backend and must reach the blocker set"
1850 );
1851 }
1852 assert!(!BackendKind::Null.is_gpu());
1853 assert!(
1854 parity_blockers().all(|entry| entry.backend.is_gpu()),
1855 "a non-GPU row reached the blocker set"
1856 );
1857 }
1858
1859 /// The rule the query is built on, as a table: the failure mode is a
1860 /// negation dropped or added, which reads identically and would either
1861 /// empty the blocker set or fill it with rows nobody can act on.
1862 #[test]
1863 fn only_an_api_absence_is_off_the_hook() {
1864 assert!(!DivergenceKind::ApiAbsence.blocks_parity());
1865 assert!(DivergenceKind::Unwritten.blocks_parity());
1866 }
1867
1868 /// A kind nothing uses is a distinction nobody made. Each of the four has to
1869 /// describe a real row, or it is vocabulary rather than classification.
1870 #[test]
1871 fn every_kind_describes_at_least_one_real_row() {
1872 for kind in [
1873 DivergenceKind::ApiAbsence,
1874 DivergenceKind::Unwritten,
1875 DivergenceKind::Unrun,
1876 ] {
1877 assert!(
1878 DIVERGENCES.iter().any(|entry| entry.kind == kind),
1879 "no divergence is classified {kind:?}, so the variant is a name with nothing \
1880 behind it"
1881 );
1882 }
1883 }
1884
1885 /// A shared reason is shared with the row it describes.
1886 ///
1887 /// The other half of each pairing is a `Support::No(…)` in the backend
1888 /// crate, which the compiler checks by being a use of the same constant.
1889 /// This end is what stops somebody pasting the text back into the row as a
1890 /// literal and letting the two drift again.
1891 ///
1892 /// [`METAL_NO_DRAW_INDIRECT_COUNT`] is **not** checked here any more, and
1893 /// the assertion below is why: its row left [`DIVERGENCES`] when
1894 /// `crcbl-mtl` learned to honour a GPU-side count, so the constant is now
1895 /// shared between that backend's `Device::supports` gate and the error its
1896 /// encoder refuses with — two places the compiler checks, and neither of
1897 /// them a row. A row reappearing under it would mean the slice was reverted
1898 /// without the entry being restored, which is the state
1899 /// `the_parity_blockers_are_exactly_the_reviewed_list` fails on.
1900 #[test]
1901 fn a_shared_reason_is_the_reason_its_row_carries() {
1902 assert_eq!(
1903 divergence(Capability::DrawIndirectCount, BackendKind::Metal),
1904 None,
1905 "Metal's GPU-side draw count is implemented; the row left when the work landed"
1906 );
1907 assert_eq!(
1908 divergence(Capability::UpdateBindGroup, BackendKind::WebGpu).map(|entry| entry.why),
1909 Some(WEBGPU_BIND_GROUPS_ARE_IMMUTABLE)
1910 );
1911 }
1912}