use core::fmt;
use crate::{BackendKind, Features};
macro_rules! capabilities {
($(
$(#[$meta:meta])*
$variant:ident,
)+) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Capability {
$(
$(#[$meta])*
$variant,
)+
}
impl Capability {
pub const ALL: &'static [Self] = &[$(Self::$variant),+];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
$(Self::$variant => stringify!($variant),)+
}
}
}
};
}
capabilities! {
BufferFillZero,
ImageToImageCopy,
DepthImageCopy,
MsaaResolveAttachment,
StencilReference,
DrawIndirectCount,
IndirectArgumentPaddedStride,
MeshShading,
TaskShaderStage,
UpdateBindGroup,
PushConstants,
BindlessDescriptorArray,
StorageImageBinding,
PolygonModeLine,
DepthClamp,
SamplerAnisotropy,
TimestampQuery,
OcclusionQuery,
PipelineStatisticsQuery,
TimelineSemaphore,
BinarySemaphore,
CpuTimelineWait,
CpuTimelineSignal,
TimelineWaitBeforeSignal,
}
impl Capability {
#[must_use]
pub const fn gating_feature(self) -> Option<Features> {
match self {
Self::BufferFillZero
| Self::ImageToImageCopy
| Self::DepthImageCopy
| Self::MsaaResolveAttachment
| Self::StencilReference
| Self::IndirectArgumentPaddedStride
| Self::UpdateBindGroup
| Self::StorageImageBinding
| Self::BinarySemaphore => None,
Self::DrawIndirectCount => Some(Features::DRAW_INDIRECT_COUNT),
Self::MeshShading => Some(Features::MESH_SHADER),
Self::TaskShaderStage => Some(Features::TASK_SHADER),
Self::PushConstants => Some(Features::PUSH_CONSTANTS),
Self::BindlessDescriptorArray => Some(Features::DESCRIPTOR_INDEXING),
Self::PolygonModeLine => Some(Features::POLYGON_MODE_LINE),
Self::DepthClamp => Some(Features::DEPTH_CLAMP),
Self::SamplerAnisotropy => Some(Features::SAMPLER_ANISOTROPY),
Self::TimestampQuery => Some(Features::TIMESTAMP_QUERY),
Self::OcclusionQuery => Some(Features::OCCLUSION_QUERY),
Self::PipelineStatisticsQuery => Some(Features::PIPELINE_STATISTICS_QUERY),
Self::TimelineSemaphore
| Self::CpuTimelineWait
| Self::CpuTimelineSignal
| Self::TimelineWaitBeforeSignal => Some(Features::TIMELINE_SEMAPHORE),
}
}
}
impl fmt::Display for Capability {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Support {
Yes,
No(&'static str),
NotOnThisDevice(&'static str),
}
impl Support {
#[must_use]
pub const fn granted(features: Features, feature: Features, why: &'static str) -> Self {
if features.contains(feature) {
Self::Yes
} else {
Self::NotOnThisDevice(why)
}
}
#[must_use]
pub const fn is_yes(self) -> bool {
matches!(self, Self::Yes)
}
#[must_use]
pub const fn reason(self) -> Option<&'static str> {
match self {
Self::Yes => None,
Self::No(why) | Self::NotOnThisDevice(why) => Some(why),
}
}
}
impl fmt::Display for Support {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Yes => f.write_str("supported"),
Self::No(why) => write!(f, "unsupported: {why}"),
Self::NotOnThisDevice(why) => write!(f, "unsupported on this device: {why}"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum DivergenceKind {
ApiAbsence,
Unwritten,
Unrun,
}
impl DivergenceKind {
#[must_use]
pub const fn blocks_parity(self) -> bool {
match self {
Self::ApiAbsence => false,
Self::Unwritten | Self::Unrun => true,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Divergence {
pub capability: Capability,
pub backend: BackendKind,
pub kind: DivergenceKind,
pub why: &'static str,
}
pub const METAL_NO_DRAW_INDIRECT_COUNT: &str = "this device reports no DRAW_INDIRECT_COUNT. \
crcbl-mtl's count-limited draw is a compute kernel that packs the argument structures and \
zeroes the instance count of every one at or past the GPU-written count, followed by \
max_draw_count ordinary indirect draws — so the flag is unconditional on Metal and a device \
without it is one the slice was switched off for at crcbl_mtl::adapter's features_of";
pub const WEBGPU_BIND_GROUPS_ARE_IMMUTABLE: &str = "WebGPU bind groups are immutable once created \
— GPUBindGroup exposes a label and nothing else — so the stream has no update_bind_group \
command and could not carry one that worked";
pub const NO_OCCLUSION_QUERY_VERB: &str = "a QueryKind::Occlusion set. Every API scopes an \
occlusion count with a begin/end pair around a draw — vkCmdBeginQuery, D3D12 BeginQuery, \
Metal setVisibilityResultMode:offset:, WebGPU beginOcclusionQuery — and crcbl_hal's \
CommandEncoder has no such verb: its whole query vocabulary is reset_query_set, \
resolve_query_set and the pass descriptor's timestamp_writes. So no work a caller records \
could ever count into the pool, and reading one back gives zeros, which says nothing was \
visible rather than nothing was asked. Every backend here can do the query and the verb is \
what is unwritten, so create_query_set refuses the kind on all of them rather than hand out \
a set whose only honest use is impossible";
pub const DIVERGENCES: &[Divergence] = &[
Divergence {
capability: Capability::DrawIndirectCount,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "GPURenderPassEncoder carries drawIndirect and drawIndexedIndirect and no \
count-buffer form of either, so the draw count can only come from the CPU; the \
stream has no tag for one because there is nothing to encode",
},
Divergence {
capability: Capability::MeshShading,
backend: BackendKind::Dx12,
kind: DivergenceKind::Unwritten,
why: "the calls exist — crcbl_dx12::pipeline packs the D3D12_PIPELINE_STATE_STREAM_DESC an \
amplification and mesh stage need, and the encoder records DispatchMesh and an \
ExecuteIndirect of DISPATCH_MESH — but crcbl_dx12::adapter does not report \
Features::MESH_SHADER, so the capability cannot answer Yes. Reporting it moves every \
D3D12 adapter onto GeometryPath::MeshShader and re-keys every golden image, which is \
its own change (the DX12 mesh reporting slice)",
},
Divergence {
capability: Capability::MeshShading,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "WebGPU has no mesh stage: GPUDevice creates render and compute pipelines only and \
GPURenderPassEncoder has no draw for one. No proposal for it has reached the \
specification, so this is the API rather than the slice",
},
Divergence {
capability: Capability::TaskShaderStage,
backend: BackendKind::Dx12,
kind: DivergenceKind::Unwritten,
why: "MeshPipelineDesc::task reaches D3D12's amplification stage through the same \
subobject stream the mesh one does, and it is behind the same unreported flag; see \
the MeshShading entry",
},
Divergence {
capability: Capability::TaskShaderStage,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "WebGPU has no mesh stage to put an amplification stage in front of; see the \
MeshShading entry",
},
Divergence {
capability: Capability::UpdateBindGroup,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: WEBGPU_BIND_GROUPS_ARE_IMMUTABLE,
},
Divergence {
capability: Capability::PushConstants,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "WebGPU has no push constants — GPUPipelineLayoutDescriptor carries bind group \
layouts and nothing beside them. The substitute is a dynamic-offset uniform buffer, \
which the seam already carries as bind-group dynamic offsets",
},
Divergence {
capability: Capability::BindlessDescriptorArray,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "GPUBindGroupLayoutEntry carries a binding, a visibility and one resource layout and \
no count, so WebGPU has no binding arrays at all, fixed-size or runtime-sized; a \
material table is indexed through a storage buffer here rather than through \
descriptors",
},
Divergence {
capability: Capability::PolygonModeLine,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "GPUPrimitiveState carries topology, stripIndexFormat, frontFace, cullMode and \
unclippedDepth and no fill mode, so WebGPU has no core expression for a wireframe; \
unlike the other two rasteriser capabilities this is absent from the API rather than \
from a given device",
},
Divergence {
capability: Capability::OcclusionQuery,
backend: BackendKind::Vulkan,
kind: DivergenceKind::Unwritten,
why: NO_OCCLUSION_QUERY_VERB,
},
Divergence {
capability: Capability::OcclusionQuery,
backend: BackendKind::WebGpu,
kind: DivergenceKind::Unwritten,
why: NO_OCCLUSION_QUERY_VERB,
},
Divergence {
capability: Capability::OcclusionQuery,
backend: BackendKind::Metal,
kind: DivergenceKind::Unwritten,
why: NO_OCCLUSION_QUERY_VERB,
},
Divergence {
capability: Capability::OcclusionQuery,
backend: BackendKind::Dx12,
kind: DivergenceKind::Unwritten,
why: NO_OCCLUSION_QUERY_VERB,
},
Divergence {
capability: Capability::PipelineStatisticsQuery,
backend: BackendKind::Metal,
kind: DivergenceKind::Unrun,
why: "the calls exist — crcbl_mtl::device's create_query_set builds an \
MTLCounterSampleBuffer over MTLCommonCounterSetStatistic and crcbl_mtl::command's \
resolve_query_set reaches it through the blit encoder's \
resolveCounters:inRange:destinationBuffer:destinationOffset: at the \
MTLCounterResultStatistic width crcbl_mtl::query derives — but no device has ever \
run them, and two of the seam's read paths cannot be written at all. **Nothing can \
sample one**: PassTimestampWrites names timestamps and crcbl_hal::CommandEncoder has \
no other query verb, so no work a caller records will ever write into this set — \
which is exactly what Capability::OcclusionQuery means on every backend, and why \
crcbl_mtl::device's supports claims the create, the resolve and the destroy and \
nothing more. **And query_results refuses it**: an MTLCounterResultStatistic is \
eight u64s while that call reads one u64 per query, so there is nowhere for the \
other seven to go, and returning the first would answer a different question in the \
shape of this one; crcbl-dx12 refuses the identical read of an eleven-field \
D3D12_QUERY_DATA_PIPELINE_STATISTICS in the same words, and the fix is a seam that \
carries a result width. crcbl_mtl::adapter reports \
Features::PIPELINE_STATISTICS_QUERY for a device advertising \
MTLCommonCounterSetStatistic, and gates it on that alone rather than on \
supportsCounterSampling:, because nothing samples this kind and a gate on an answer \
no line reads decides nothing. The Mac in CI advertises counterSets=0, so it reports \
the flag clear; that is a device fact reported per device, not what leaves the row \
open. Retiring this row takes a Mac that reports the flag creating and resolving a \
set, as the occlusion kind's absence from this list took",
},
Divergence {
capability: Capability::PipelineStatisticsQuery,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "GPUQueryType is exactly 'occlusion' and 'timestamp', so there is no \
pipeline-statistics query set for WebGPU to create",
},
Divergence {
capability: Capability::TimelineSemaphore,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "WebGPU has no semaphores. It orders submissions implicitly — one queue, executed in \
order, hazards tracked by the browser — and its only completion signal, \
GPUQueue.onSubmittedWorkDone(), resolves for everything submitted so far and carries \
no value, so nothing there could drive a counter. create_semaphore refuses \
SemaphoreKind::Timeline; it used to hand out a handle whose semaphore_value answered \
0 for ever, which is the succeed-while-doing-nothing shape this enum exists to make \
visible",
},
Divergence {
capability: Capability::CpuTimelineWait,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "create_semaphore refuses the timeline kind, so there is no counter for a CPU wait to \
read; the binary semaphore this backend does hand out is GPU-waitable only. \
wait_semaphores refuses rather than answering Ok(true) for a wait it never evaluated \
— see the TimelineSemaphore entry",
},
Divergence {
capability: Capability::CpuTimelineSignal,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "create_semaphore refuses the timeline kind, so there is no counter for a host signal \
to advance; WebGPU has no signalable object of any kind — see the TimelineSemaphore \
entry",
},
Divergence {
capability: Capability::TimelineWaitBeforeSignal,
backend: BackendKind::WebGpu,
kind: DivergenceKind::ApiAbsence,
why: "a wait of any kind is refused here, so a wait on a value nothing has signalled is \
refused with the rest; see the CpuTimelineWait entry",
},
];
pub fn parity_blockers() -> impl Iterator<Item = &'static Divergence> {
DIVERGENCES
.iter()
.filter(|entry| entry.backend.is_gpu() && entry.kind.blocks_parity())
}
#[must_use]
pub fn divergence(capability: Capability, backend: BackendKind) -> Option<&'static Divergence> {
DIVERGENCES
.iter()
.find(|entry| entry.capability == capability && entry.backend == backend)
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ParityVerdict {
Supported,
Reviewed(&'static Divergence),
UnprovableHere(Features),
Unreviewed,
FalseDeviceGate,
}
impl ParityVerdict {
#[must_use]
pub const fn is_gap(self) -> bool {
match self {
Self::Supported | Self::Reviewed(_) | Self::UnprovableHere(_) => false,
Self::Unreviewed | Self::FalseDeviceGate => true,
}
}
}
#[must_use]
pub fn parity_verdict(
capability: Capability,
backend: BackendKind,
declared: Support,
features: Features,
) -> ParityVerdict {
match declared {
Support::Yes => ParityVerdict::Supported,
Support::NotOnThisDevice(_) => match capability.gating_feature() {
Some(gate) if !features.contains(gate) => ParityVerdict::UnprovableHere(gate),
_ => ParityVerdict::FalseDeviceGate,
},
Support::No(_) => match divergence(capability, backend) {
Some(entry) => ParityVerdict::Reviewed(entry),
None => ParityVerdict::Unreviewed,
},
}
}
#[cfg(test)]
mod tests {
use super::*;
const GPU_BACKENDS: [BackendKind; 4] = [
BackendKind::Vulkan,
BackendKind::WebGpu,
BackendKind::Metal,
BackendKind::Dx12,
];
#[test]
fn every_gpu_backend_is_in_this_sweep() {
for backend in GPU_BACKENDS {
assert!(backend.is_gpu(), "{backend} must be in the parity model");
}
assert!(!BackendKind::Null.is_gpu());
let every = [
BackendKind::Vulkan,
BackendKind::WebGpu,
BackendKind::Metal,
BackendKind::Dx12,
BackendKind::Null,
];
assert_eq!(
every.iter().filter(|kind| kind.is_gpu()).count(),
GPU_BACKENDS.len(),
"a BackendKind drives a GPU and is not swept by these tests"
);
}
#[test]
fn all_holds_every_capability_exactly_once() {
let mut seen: Vec<Capability> = Capability::ALL.to_vec();
let count = seen.len();
seen.sort_unstable();
seen.dedup();
assert_eq!(seen.len(), count, "a capability appears twice in ALL");
assert!(
count >= 20,
"ALL has shrunk to {count}; the capabilities are derived from real refusal sites and \
those have not gone away"
);
}
#[test]
fn every_capability_has_its_own_name() {
let mut names: Vec<&'static str> = Capability::ALL.iter().map(|c| c.name()).collect();
let count = names.len();
names.sort_unstable();
names.dedup();
assert_eq!(names.len(), count, "two capabilities share a name");
for capability in Capability::ALL {
assert_eq!(capability.to_string(), capability.name());
assert!(!capability.name().is_empty());
}
}
#[test]
fn a_gating_feature_is_always_exactly_one_flag() {
let mut gated = 0;
for capability in Capability::ALL {
let Some(gate) = capability.gating_feature() else {
continue;
};
gated += 1;
assert_eq!(
gate.bits().count_ones(),
1,
"{capability} is gated on {gate:?}, which is not a single flag"
);
}
assert!(
gated > 0 && gated < Capability::ALL.len(),
"both halves must be populated: {gated} of {} capabilities are gated, and a run where \
all or none were would make the parity rule vacuous in one direction",
Capability::ALL.len()
);
}
#[test]
fn granted_reads_the_flag_it_was_given() {
let device = Features::COMPUTE | Features::TIMELINE_SEMAPHORE;
assert_eq!(
Support::granted(device, Features::COMPUTE, "no compute"),
Support::Yes
);
assert_eq!(
Support::granted(device, Features::MESH_SHADER, "no mesh shader"),
Support::NotOnThisDevice("no mesh shader")
);
assert_eq!(
Support::granted(device, Features::GPU_DRIVEN, "not the whole bundle"),
Support::NotOnThisDevice("not the whole bundle")
);
}
#[test]
fn support_carries_the_reason_and_nothing_else() {
assert!(Support::Yes.is_yes());
assert_eq!(Support::Yes.reason(), None);
assert_eq!(Support::Yes.to_string(), "supported");
let refused = Support::No("there is no such call");
assert!(!refused.is_yes());
assert_eq!(refused.reason(), Some("there is no such call"));
assert_eq!(
refused.to_string(),
"unsupported: there is no such call",
"the reason must reach the reader, not merely be stored"
);
let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
assert!(!withheld.is_yes());
assert_eq!(
withheld.reason(),
Some("this device reports no MESH_SHADER")
);
assert_eq!(
withheld.to_string(),
"unsupported on this device: this device reports no MESH_SHADER"
);
assert_ne!(
withheld,
Support::No("this device reports no MESH_SHADER"),
"the same sentence in the two arms must not compare equal, or the parity rule is \
reading a string rather than a classification"
);
}
#[test]
fn no_pair_is_listed_twice() {
let mut pairs: Vec<(Capability, String)> = DIVERGENCES
.iter()
.map(|entry| (entry.capability, entry.backend.to_string()))
.collect();
let count = pairs.len();
pairs.sort_unstable();
pairs.dedup();
assert_eq!(
pairs.len(),
count,
"a (capability, backend) pair is listed twice"
);
}
#[test]
fn every_divergence_gives_a_real_reason() {
for entry in DIVERGENCES {
assert!(
entry.why.len() > 40,
"{} on {}: {:?} is too short to be a reason anyone can act on",
entry.capability,
entry.backend,
entry.why
);
}
}
#[test]
fn divergences_name_only_gpu_backends() {
for entry in DIVERGENCES {
assert!(
entry.backend.is_gpu(),
"{} names {}, which is not a GPU backend",
entry.capability,
entry.backend
);
}
}
#[test]
fn a_divergence_is_something_some_backend_actually_has() {
for capability in Capability::ALL {
let lacking = GPU_BACKENDS
.iter()
.filter(|backend| divergence(*capability, **backend).is_some())
.count();
assert!(
lacking < GPU_BACKENDS.len() || DEFERRED_CAPABILITIES.contains(capability),
"{capability} is listed as absent on every GPU backend and nothing parked it, so \
it is not a divergence — it is a seam behaviour nothing implements, and that \
belongs in the seam's own docs rather than in a parity exception list. If it is \
refused everywhere on purpose, say so in DEFERRED_CAPABILITIES"
);
}
for entry in DIVERGENCES {
assert_eq!(
divergence(entry.capability, entry.backend),
Some(entry),
"the lookup must find every entry the list holds"
);
}
assert_eq!(
divergence(
Capability::IndirectArgumentPaddedStride,
BackendKind::Vulkan
),
None,
"Vulkan takes a padded stride, and the list would be describing it wrongly"
);
assert_eq!(
divergence(Capability::PushConstants, BackendKind::Null),
None
);
}
#[test]
fn a_parity_gap_is_a_backend_refusal_nobody_wrote_down() {
let all = Features::all();
let no_mesh = all.difference(Features::MESH_SHADER);
let refused = Support::No("this backend has not written it");
let withheld = Support::NotOnThisDevice("this device reports no MESH_SHADER");
assert_eq!(
parity_verdict(
Capability::MeshShading,
BackendKind::Vulkan,
Support::Yes,
all
),
ParityVerdict::Supported
);
assert_eq!(
parity_verdict(
Capability::UpdateBindGroup,
BackendKind::WebGpu,
refused,
all
),
ParityVerdict::Reviewed(
divergence(Capability::UpdateBindGroup, BackendKind::WebGpu)
.expect("WebGPU's immutable bind groups are on the list")
)
);
assert_eq!(Capability::UpdateBindGroup.gating_feature(), None);
assert_eq!(
parity_verdict(
Capability::MeshShading,
BackendKind::Vulkan,
withheld,
no_mesh
),
ParityVerdict::UnprovableHere(Features::MESH_SHADER)
);
assert_eq!(
parity_verdict(Capability::MeshShading, BackendKind::Vulkan, refused, all),
ParityVerdict::Unreviewed
);
assert_eq!(
parity_verdict(
Capability::MeshShading,
BackendKind::Vulkan,
refused,
no_mesh
),
ParityVerdict::Unreviewed,
"a backend's own refusal is a gap on every device; a lesser one cannot excuse it"
);
assert_eq!(Capability::BufferFillZero.gating_feature(), None);
assert_eq!(
parity_verdict(
Capability::BufferFillZero,
BackendKind::Dx12,
withheld,
Features::empty()
),
ParityVerdict::FalseDeviceGate
);
assert_eq!(
parity_verdict(Capability::MeshShading, BackendKind::Vulkan, withheld, all),
ParityVerdict::FalseDeviceGate
);
assert!(
parity_verdict(
Capability::BufferFillZero,
BackendKind::Vulkan,
refused,
Features::empty()
)
.is_gap()
);
assert!(
!parity_verdict(
Capability::UpdateBindGroup,
BackendKind::WebGpu,
refused,
Features::empty()
)
.is_gap()
);
}
#[test]
fn only_an_unaccounted_refusal_is_a_gap() {
let entry = &DIVERGENCES[0];
assert!(!ParityVerdict::Supported.is_gap());
assert!(!ParityVerdict::Reviewed(entry).is_gap());
assert!(!ParityVerdict::UnprovableHere(Features::MESH_SHADER).is_gap());
assert!(ParityVerdict::Unreviewed.is_gap());
assert!(ParityVerdict::FalseDeviceGate.is_gap());
}
#[test]
fn no_row_can_be_retired_without_a_run_noticing() {
let refused = Support::No("the refusal this row exists to excuse");
for entry in DIVERGENCES {
for features in [Features::empty(), Features::all()] {
assert_eq!(
parity_verdict(entry.capability, entry.backend, refused, features),
ParityVerdict::Reviewed(entry),
"{} on {}: the row must excuse the refusal on every device",
entry.capability,
entry.backend
);
assert_eq!(
divergence(entry.capability, BackendKind::Null),
None,
"the list has grown a Null row, which divergences_name_only_gpu_backends \
forbids and this counterfactual depends on"
);
assert_eq!(
parity_verdict(entry.capability, BackendKind::Null, refused, features),
ParityVerdict::Unreviewed,
"{}: an unlisted backend refusal must be a gap on every device, or deleting \
the row above would cost nothing",
entry.capability
);
}
}
}
const REVIEWED_BLOCKERS: &[(Capability, BackendKind, DivergenceKind)] = &[
(
Capability::OcclusionQuery,
BackendKind::Vulkan,
DivergenceKind::Unwritten,
),
(
Capability::OcclusionQuery,
BackendKind::WebGpu,
DivergenceKind::Unwritten,
),
(
Capability::OcclusionQuery,
BackendKind::Metal,
DivergenceKind::Unwritten,
),
(
Capability::OcclusionQuery,
BackendKind::Dx12,
DivergenceKind::Unwritten,
),
(
Capability::MeshShading,
BackendKind::Dx12,
DivergenceKind::Unwritten,
),
(
Capability::TaskShaderStage,
BackendKind::Dx12,
DivergenceKind::Unwritten,
),
(
Capability::PipelineStatisticsQuery,
BackendKind::Metal,
DivergenceKind::Unrun,
),
];
const DEFERRED_BACKENDS: &[BackendKind] = &[BackendKind::Metal, BackendKind::Dx12];
const DEFERRED_CAPABILITIES: &[Capability] = &[Capability::OcclusionQuery];
#[test]
fn every_parity_blocker_is_deferred_by_its_backend_or_by_its_capability() {
let live: Vec<String> = parity_blockers()
.filter(|entry| {
!DEFERRED_BACKENDS.contains(&entry.backend)
&& !DEFERRED_CAPABILITIES.contains(&entry.capability)
})
.map(|entry| format!("{} on {}", entry.capability, entry.backend))
.collect();
assert!(
live.is_empty(),
"these parity blockers are on backends nobody deferred, so they are work that \
is actually owed rather than parked: {live:?}. Say which in the report \
instead of leaving them to be read as more deferred rows"
);
assert!(
parity_blockers().next().is_some(),
"there are no parity blockers left at all, which makes the assertion above \
vacuous. The deferral note on DEFERRED_BACKENDS and this test have \
outlived their subject"
);
}
#[test]
fn the_parity_blockers_are_exactly_the_reviewed_list() {
let mut actual: Vec<(Capability, String, DivergenceKind)> = parity_blockers()
.map(|entry| (entry.capability, entry.backend.to_string(), entry.kind))
.collect();
actual.sort_unstable();
let mut reviewed: Vec<(Capability, String, DivergenceKind)> = REVIEWED_BLOCKERS
.iter()
.map(|(capability, backend, kind)| (*capability, backend.to_string(), *kind))
.collect();
reviewed.sort_unstable();
assert_eq!(
actual, reviewed,
"the set of divergences between crcbl and parity has changed. That is the goal moving, \
so say so: update REVIEWED_BLOCKERS to match, and if a row left the set, make sure it \
left because the work landed or the API was shown to lack it — not because a kind was \
widened to ApiAbsence to make it disappear"
);
}
#[test]
fn every_gpu_backend_is_inside_the_goal() {
for backend in GPU_BACKENDS {
assert!(
backend.is_gpu(),
"{backend} is a GPU backend and must reach the blocker set"
);
}
assert!(!BackendKind::Null.is_gpu());
assert!(
parity_blockers().all(|entry| entry.backend.is_gpu()),
"a non-GPU row reached the blocker set"
);
}
#[test]
fn only_an_api_absence_is_off_the_hook() {
assert!(!DivergenceKind::ApiAbsence.blocks_parity());
assert!(DivergenceKind::Unwritten.blocks_parity());
}
#[test]
fn every_kind_describes_at_least_one_real_row() {
for kind in [
DivergenceKind::ApiAbsence,
DivergenceKind::Unwritten,
DivergenceKind::Unrun,
] {
assert!(
DIVERGENCES.iter().any(|entry| entry.kind == kind),
"no divergence is classified {kind:?}, so the variant is a name with nothing \
behind it"
);
}
}
#[test]
fn a_shared_reason_is_the_reason_its_row_carries() {
assert_eq!(
divergence(Capability::DrawIndirectCount, BackendKind::Metal),
None,
"Metal's GPU-side draw count is implemented; the row left when the work landed"
);
assert_eq!(
divergence(Capability::UpdateBindGroup, BackendKind::WebGpu).map(|entry| entry.why),
Some(WEBGPU_BIND_GROUPS_ARE_IMMUTABLE)
);
}
}