crcbl-hal 0.2.1

Crucible graphics HAL: backend seam traits and POD descriptors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
//! Seam behaviours a backend must answer for, and the parity record of which
//! ones actually diverge.
//!
//! # Why this is not [`Features`]
//!
//! The two are different questions, and merging them loses the property this
//! module exists for:
//!
//! | | [`Features`] | [`Capability`] |
//! | --- | --- | --- |
//! | Names | an optional capability a **caller requests** at device creation | a seam behaviour a **backend must answer for** |
//! | Shape | `bitflags` | `enum` + exhaustive `match` |
//! | A backend that says nothing | reports the flag clear, silently | **does not compile** |
//!
//! [`Features`] is a *request* channel: a caller names what it
//! needs in [`DeviceDesc::required_features`](crate::DeviceDesc::required_features),
//! an adapter that lacks it fails loudly, and everything else degrades. That is
//! the right shape for what it does and it is not changing.
//!
//! What a bitflag cannot do is make a *backend* answer. A flag is a bit, and a
//! backend that never sets a new one compiles, links and runs — it simply
//! reports the capability absent, which is indistinguishable from a device that
//! genuinely lacks it. So a behaviour added to one backend costs nothing
//! anywhere else: the others never implement it, their refusal is invisible
//! until something runs, and no test can name what is missing because nothing
//! declares it exists.
//!
//! An `enum` with no wildcard arm inverts that. Adding a variant here is a
//! compile error in **every** backend that has not said what it does about it,
//! and the answer it is forced to give names *whose* answer it is:
//! [`Support::Yes`], [`Support::No`] with a reason a human wrote, or
//! [`Support::NotOnThisDevice`] — which only [`Support::granted`] hands out, and
//! which says the refusal came from the device rather than from the backend.
//!
//! # Prior art, and why this shape
//!
//! Every cross-API engine negotiates capabilities, and the ones that reach for a
//! bitmask reach for it because C has no better closed set:
//!
//! * **wgpu** — `Features` bitflags plus `DownlevelFlags`, validated at call
//!   time. The shape [`Features`] already is, with wgpu's
//!   problem: a backend that omits a flag reports "unsupported" and nothing says
//!   so.
//! * **Dawn** — `wgpu::FeatureName` is an *enum*, and each backend answers it in
//!   a `switch` compiled with `-Werror=switch`. That is this design, in C++.
//! * **bgfx** — a `supported` bitmask plus `caps->formats[]`, an array indexed by
//!   the format enum with a static assertion that its length matches the
//!   enumerator count. The array is C's way of buying the same "there must be an
//!   entry for every variant" property the `match` gives here for free.
//! * **Vulkan itself** — `VkPhysicalDeviceFeatures` is a struct of `VkBool32`, so
//!   a field added to it zero-initialises to `VK_FALSE` in every implementation
//!   that has not heard of it. The same silent-omission failure, one layer down.
//!
//! The consistent lesson is that the anti-rot property comes from a **closed
//! set** plus **an exhaustiveness check**, and from nothing else — not from
//! discipline, and not from a wider bitmask. Rust supplies both natively, so
//! this is the known-good design rather than a new one.
//!
//! # Cost
//!
//! [`Device::supports`](crate::Device::supports) takes a `Copy` enum and returns
//! a `Copy` enum holding at most a `&'static str`. No allocation, no lock, no
//! formatting, no table to walk: a backend's implementation is a `match` the
//! compiler lowers to a jump table or a comparison chain. It is a question asked
//! at set-up rather than in a frame, but it would be cheap enough to ask in one.
//!
//! # What is deliberately **not** a capability here
//!
//! * **Which [`SurfaceTarget`](crate::SurfaceTarget) kinds a backend accepts.**
//!   `crcbl-mtl` refuses a Wayland window and `crcbl-vk` refuses an AppKit one,
//!   but that is a platform axis `crcbl-shell` settles before a surface is
//!   asked for — Metal declining X11 is not a parity gap, and modelling it would
//!   add a variant per window system to describe something no two platforms were
//!   ever going to agree on.
//! * **Numeric ceilings.** [`Limits`](crate::Limits) is the right shape for a
//!   number, and "how big" is not a yes/no question.
//! * **Caller bugs.** A misaligned `fill_buffer` offset, a bind group written
//!   twice at one index, a swapchain retargeted to a different surface: every
//!   backend refuses these and *should*. A capability is something a caller
//!   could legitimately ask for and be told no.
//! * **Anything with no refusal behind it.** Every variant below was derived
//!   from a place some backend actually declines to do the thing.
//!
//! # The parity record
//!
//! [`DIVERGENCES`] is the reviewed list of every (capability, backend) pair that
//! is knowingly absent, and [`parity_verdict`] is the rule that reads it. It is
//! the difference between divergence somebody decided and divergence that
//! happened: a backend that starts refusing something new fails the parity test
//! until the pair is added with a reason, and a backend that starts supporting
//! something on the list fails until the pair is removed.
//!
//! # Why a refusal has to say whose it is
//!
//! The rule needs one more thing to be sound, and it is the reason
//! [`Support::NotOnThisDevice`] exists. "This device reports no `MESH_SHADER`"
//! and "this backend never wrote the mesh path" are both a refusal, and the
//! parity record must excuse the first and demand a row for the second — so the
//! rule used to guess which it was, by asking whether the *device* reported the
//! capability's [`gating_feature`](Capability::gating_feature).
//!
//! That guess made every gated row **unprovable**: on a device reporting the
//! flag clear, a pair was excused whether or not [`DIVERGENCES`] named it, so
//! deleting the row changed nothing anybody could observe and the capability
//! became one nobody claimed and nothing checked. Eight of `crcbl-mtl`'s nine
//! rows were that shape.
//!
//! A refusal now carries whose it is instead of having it inferred, and it costs
//! no backend a line to say so: [`Support::granted`] is the one constructor a
//! device gate is ever expressed through, so every gated arm in every backend
//! already routes through it. What a backend writes by hand is
//! [`Support::No`] — its own refusal, which [`parity_verdict`] demands a row for
//! on **every** device, including one that happens to withhold the flag.
//!
//! A reason alone cannot say **what is left**, though — "Metal's blit fill takes
//! a byte, not a word" and "this backend has not written the code yet" are the
//! same shape as prose. [`DivergenceKind`] is the field that separates them and
//! [`parity_blockers`] is the query over it: every row that somebody could still
//! close, on a backend crcbl is keeping. Parity is reached when that set is
//! empty, and this module's tests snapshot it so it shrinks deliberately.
//!
//! ```
//! use crcbl_hal::{BackendKind, Capability, DIVERGENCES, DivergenceKind, divergence, parity_blockers};
//!
//! // WebGPU has no mesh stage. No work in this repository closes that, so it
//! // is written down and then left alone.
//! let permanent = divergence(Capability::MeshShading, BackendKind::WebGpu)
//!     .expect("WebGPU's missing mesh stage is on the list");
//! assert_eq!(permanent.kind, DivergenceKind::ApiAbsence);
//! assert!(!permanent.kind.blocks_parity());
//!
//! // D3D12's mesh reporting is owed rather than absent, so it is one of the rows
//! // standing between crcbl and its end state.
//! assert!(parity_blockers().any(|entry| {
//!     entry.capability == Capability::MeshShading && entry.backend == BackendKind::Dx12
//! }));
//!
//! // And Metal's GPU-side draw count is not, because that work landed — the
//! // list is a record of what is left, not of what was ever hard.
//! assert!(parity_blockers().all(|entry| {
//!     entry.capability != Capability::DrawIndirectCount || entry.backend != BackendKind::Metal
//! }));
//!
//! // Every entry names a backend that actually drives a GPU.
//! assert!(DIVERGENCES.iter().all(|entry| entry.backend.is_gpu()));
//! ```

use core::fmt;

use crate::{BackendKind, Features};

/// Declares [`Capability`] and everything derived from it from one variant list.
///
/// The list appears **once**. [`Capability::ALL`] and [`Capability::name`] are
/// generated from the same tokens as the enum, so neither can drift from it —
/// which matters because `ALL` is what the parity report and the agnostic seam
/// suite iterate, and a hand-written array that silently lost a variant would
/// make both report a clean sweep over a set with a hole in it.
macro_rules! capabilities {
    ($(
        $(#[$meta:meta])*
        $variant:ident,
    )+) => {
        /// One seam behaviour a backend either performs or refuses.
        ///
        /// **Every variant exists because some backend refuses it.** See the
        /// module docs for what is deliberately not modelled, and
        /// [`Device::supports`](crate::Device::supports) for how a backend
        /// answers.
        ///
        /// Adding a variant is a compile error in every backend until it says
        /// what it does — that is the whole point, and it is why this is an
        /// `enum` and not another [`Features`] bit.
        #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
        pub enum Capability {
            $(
                $(#[$meta])*
                $variant,
            )+
        }

        impl Capability {
            /// Every capability, in declaration order.
            ///
            /// Generated from the same list as the enum, so it cannot be missing
            /// one. The parity report and the agnostic seam suite both walk it.
            pub const ALL: &'static [Self] = &[$(Self::$variant),+];

            /// How the variant is spelled in source, e.g. `"BufferFillZero"`.
            ///
            /// Taken from the declaration rather than written out beside it, so
            /// a renamed variant cannot keep an old name in a log line.
            #[must_use]
            pub const fn name(self) -> &'static str {
                match self {
                    $(Self::$variant => stringify!($variant),)+
                }
            }
        }
    };
}

capabilities! {
    // --- copies and fills ---

    /// [`clear_buffer`](crate::CommandEncoder::clear_buffer).
    ///
    /// **Every backend answers `Yes`, and it is kept anyway.** This enum covers
    /// what the seam does rather than only what backends disagree about, so a
    /// capability with no `DIVERGENCES` row is the shape a settled one takes —
    /// and the agnostic suite still drives it, which is what would notice a
    /// backend quietly dropping the call.
    ///
    /// It had two valued siblings until 2026-08-19,
    /// `BufferFillRepeatedByte` and `BufferFillWord`. They described how badly
    /// each backend could keep a promise the seam should not have made: Metal's
    /// fill repeats a byte and WebGPU has no valued fill at all, so three of
    /// five had to refuse most values. The verb lost its `value` instead — see
    /// [`clear_buffer`](crate::CommandEncoder::clear_buffer) — and both rows
    /// went with it.
    BufferFillZero,



    /// [`copy_image_to_image`](crate::CommandEncoder::copy_image_to_image).
    ///
    /// Both sides are texture locations with their own subresource and region,
    /// which is a different call from the buffer↔image copies and is refused
    /// separately where it is refused at all.
    ImageToImageCopy,

    /// A buffer↔image copy —
    /// [`copy_image_to_buffer`](crate::CommandEncoder::copy_image_to_buffer) or
    /// [`copy_buffer_to_image`](crate::CommandEncoder::copy_buffer_to_image) —
    /// whose image carries a **depth or depth-stencil** format and whose
    /// subresource names [`ImageAspect::DEPTH`](crate::ImageAspect::DEPTH).
    ///
    /// Separate from the colour copies every backend performs, because a depth
    /// image is not one plane of one type. An API that stores a *sampled* depth
    /// texture typeless needs the plane and a fully typed footprint chosen at
    /// the copy itself, and [`BufferImageCopy`](crate::BufferImageCopy) carries
    /// neither — so a backend can copy every colour format and still have no
    /// expression for this one.
    ///
    /// It is what a shadow atlas is read back through, which is why it is worth
    /// declaring rather than discovering: without it there is no way to show
    /// that a shadow pass wrote anything, and a shadow pass that wrote nothing
    /// renders a frame in which every surface is lit and nothing looks wrong.
    ///
    /// **WHICH depth format and WHICH direction remains the API's own rule.**
    /// This asks whether a backend has an expression for the copy at all; a
    /// backend answering [`Support::Yes`] still refuses the pairs its API's
    /// format table withholds, by name and at the call. WebGPU is the one that
    /// withholds any — and `wgpu` enforces the same table, so both backends on
    /// it agree: the depth plane of [`Format::D32Float`](crate::Format::D32Float),
    /// [`D32FloatS8Uint`](crate::Format::D32FloatS8Uint) and
    /// [`D16Unorm`](crate::Format::D16Unorm) copies **out** to a buffer, only
    /// `D16Unorm`'s copies back **in**, and
    /// [`D24UnormS8Uint`](crate::Format::D24UnormS8Uint)'s copies neither way,
    /// because WebGPU's `depth24plus` is whatever the driver chose to store and
    /// so has no memory layout to lay a buffer out against. The readback a
    /// shadow atlas needs is inside every one of those.
    DepthImageCopy,

    // --- render pass ---

    /// A [`ColorAttachment::resolve`](crate::ColorAttachment::resolve) view: the
    /// pass resolves its multisampled colour target into a single-sampled one as
    /// it ends.
    MsaaResolveAttachment,

    /// [`set_stencil_reference`](crate::CommandEncoder::set_stencil_reference) —
    /// the dynamic stencil reference value subsequent draws compare against.
    ///
    /// **The claim is the whole rule, not just that the call is wired.** A
    /// backend declaring this says the reference is pass state that survives a
    /// pipeline bind, and that a pass which never calls it draws against
    /// [`stencil::INITIAL_REFERENCE`](crate::stencil::INITIAL_REFERENCE); see
    /// [`StencilState`](crate::StencilState) on why there is no pipeline-side
    /// reference to compete with it.
    StencilReference,

    // --- draws ---

    /// [`draw_indirect_count`](crate::CommandEncoder::draw_indirect_count) and
    /// its indexed sibling: the draw **count** is read from a GPU buffer, so the
    /// CPU never learns how many draws a pass emits.
    ///
    /// [`Features::DRAW_INDIRECT_COUNT`](crate::Features::DRAW_INDIRECT_COUNT)
    /// is the flag a caller requests; this is the backend's answer about the two
    /// encoder methods, which is not the same claim — a backend can report the
    /// flag without having wired the calls up, and Metal reports it clear *and*
    /// refuses the calls for a reason that is not about any one device.
    DrawIndirectCount,

    /// [`DrawIndirect::stride`](crate::DrawIndirect::stride) larger than the
    /// argument structure: the arguments are **padded** in the buffer rather
    /// than tightly packed.
    ///
    /// Distinct from drawing indirectly at all. Vulkan's `vkCmdDrawIndirect`
    /// takes a stride and honours it, D3D12 builds an `ID3D12CommandSignature`
    /// per stride, `crcbl_mtl::indirect_count` walks the structures itself, and
    /// `crcbl-webgpu`'s replayer unrolls the draw into one `drawIndirect` per
    /// structure at `offset + i * stride` — an API with no stride parameter can
    /// still honour one, and the `Yes` says it does rather than that the
    /// parameter exists.
    ///
    /// **The stride a caller may ask for is every API's stride, not this
    /// seam's.** All four want a multiple of 4 that is at least the argument
    /// structure's own width, because all four ultimately address the buffer in
    /// words: Vulkan says so in `vkCmdDrawIndirect`'s own rule for a
    /// `drawCount` above one, and WebGPU says so as `indirectOffset` being a
    /// multiple of 4, which `offset + i * stride` only stays for a stride that
    /// is one too. Nothing this declaration promises makes a stride of 14 legal
    /// anywhere.
    IndirectArgumentPaddedStride,

    /// The mesh-shading path: a [`MeshPipelineDesc`](crate::MeshPipelineDesc)
    /// can be created and
    /// [`draw_mesh_tasks`](crate::CommandEncoder::draw_mesh_tasks) and
    /// [`draw_mesh_tasks_indirect`](crate::CommandEncoder::draw_mesh_tasks_indirect)
    /// recorded against it.
    ///
    /// One capability rather than three, because the seam already states the
    /// tie: `draw_mesh_tasks_indirect` "requires
    /// [`Features::MESH_SHADER`](crate::Features::MESH_SHADER) and nothing more
    /// … a device that can launch this stage at all can launch it from memory",
    /// and no backend refuses the pipeline while admitting the draw or the
    /// reverse.
    MeshShading,

    /// The amplification stage in front of a mesh shader —
    /// [`MeshPipelineDesc::task`](crate::MeshPipelineDesc::task) is `Some`.
    ///
    /// Separately optional from [`MeshShading`](Self::MeshShading) for the same
    /// reason [`Features::TASK_SHADER`](crate::Features::TASK_SHADER) is a
    /// separate flag: a mesh shader works with a workgroup count computed
    /// elsewhere, and this stage is only what moves that decision into the draw.
    TaskShaderStage,

    // --- bindings and pipeline layout ---

    /// [`update_bind_group`](crate::Device::update_bind_group): rewriting an
    /// already-created bind group's entries in place.
    ///
    /// The update-after-bind model, and what a bindless texture table is
    /// restreamed through. WebGPU bind groups are immutable once created, so a
    /// backend on it can only rebuild the group.
    ///
    /// A backend answers **whether it has the operation at all**. Vulkan
    /// additionally requires the individual layout to carry
    /// [`BindingFlags::UPDATE_AFTER_BIND`](crate::BindingFlags::UPDATE_AFTER_BIND),
    /// which is a property of the layout the caller built rather than of the
    /// device, and is refused per call.
    UpdateBindGroup,

    /// [`push_constants`](crate::CommandEncoder::push_constants) and the
    /// [`PipelineLayoutDesc::push_constants`](crate::PipelineLayoutDesc::push_constants)
    /// range they are written through.
    ///
    /// The seam requires the refusal at **pipeline-layout creation**, not at the
    /// write, so a caller finds out once rather than losing writes silently
    /// every frame.
    PushConstants,

    /// A runtime-sized descriptor array — a
    /// [`BindGroupLayoutEntry`](crate::BindGroupLayoutEntry) carrying
    /// [`BindingFlags`](crate::BindingFlags), and the
    /// [`BindGroupDesc::variable_count`](crate::BindGroupDesc::variable_count)
    /// that chooses its length.
    ///
    /// What [`BindingModel::Bindless`](crate::BindingModel::Bindless) is built
    /// on. A backend binding flat argument tables has fixed-size arrays and no
    /// way to express this, which is a different answer from having no arrays.
    BindlessDescriptorArray,

    /// A [`BindingKind::StorageImage`](crate::BindingKind::StorageImage) entry
    /// in a bind group layout.
    ///
    /// Its own capability because some implementations need the texel format and
    /// view dimension in the **layout**, which the seam only carries on the
    /// image view — so the layout cannot be built at all, rather than the
    /// binding merely being slower.
    StorageImageBinding,

    // --- rasteriser state ---

    /// [`PolygonMode::Line`](crate::PolygonMode::Line) — wireframe fill.
    PolygonModeLine,

    /// Depth **clamping** rather than clipping, for shadow casters behind the
    /// near plane.
    DepthClamp,

    /// A [`SamplerDesc`](crate::SamplerDesc) with anisotropy above `1.0`.
    SamplerAnisotropy,

    // --- queries ---

    /// A [`QueryKind::Timestamp`](crate::QueryKind::Timestamp) query set, the
    /// [`PassTimestampWrites`](crate::PassTimestampWrites) that fill it
    /// and the [`query_results`](crate::Device::query_results) that read it.
    TimestampQuery,

    /// A [`QueryKind::Occlusion`](crate::QueryKind::Occlusion) query set.
    ///
    /// **No backend has it**, and the reason is the seam's rather than any
    /// API's: [`NO_OCCLUSION_QUERY_VERB`]. Every GPU backend carries a
    /// [`DivergenceKind::Unwritten`] row here, which is what it costs to say so
    /// honestly.
    OcclusionQuery,

    /// A [`QueryKind::PipelineStatistics`](crate::QueryKind::PipelineStatistics)
    /// query set.
    ///
    /// Three query variants rather than one, because the three are refused
    /// separately: a device answers each of
    /// [`Features::TIMESTAMP_QUERY`](crate::Features::TIMESTAMP_QUERY),
    /// [`OCCLUSION_QUERY`](crate::Features::OCCLUSION_QUERY) and
    /// [`PIPELINE_STATISTICS_QUERY`](crate::Features::PIPELINE_STATISTICS_QUERY)
    /// independently, and folding them would let a backend with only timestamps
    /// claim the lot.
    PipelineStatisticsQuery,

    // --- synchronisation ---

    /// [`SemaphoreKind::Timeline`](crate::SemaphoreKind::Timeline): a monotonic
    /// `u64` counter a submission signals and both GPU and CPU can observe.
    ///
    /// The claim is the **observable** one — that
    /// [`semaphore_value`](crate::Device::semaphore_value) reports the counter
    /// advancing as submissions complete. A backend that hands out a handle
    /// whose value never moves has not got this, whatever its return codes say.
    TimelineSemaphore,

    /// [`SemaphoreKind::Binary`](crate::SemaphoreKind::Binary): the one-shot,
    /// GPU-only signal WSI acquire/present needs.
    ///
    /// Apart from [`TimelineSemaphore`](Self::TimelineSemaphore) deliberately. A
    /// device may have no timeline and must still hand out a binary one, because
    /// the swapchain is where they come from — and a backend that refused both
    /// would pass every test that only checks the timeline half.
    BinarySemaphore,

    /// [`wait_semaphores`](crate::Device::wait_semaphores): the **CPU** blocking
    /// until a timeline reaches a value.
    ///
    /// Distinct from creating one. A backend can hand out a counter a submission
    /// signals while having no host-side wait to offer, which is what a
    /// fence-shaped API looks like before its wait half is wired up.
    CpuTimelineWait,

    /// [`signal_semaphore`](crate::Device::signal_semaphore): the **CPU**
    /// advancing a timeline, rather than a submission.
    ///
    /// Its own capability for the same reason
    /// [`CpuTimelineWait`](Self::CpuTimelineWait) is: the two host-side halves
    /// are separable. A backend that emulates a timeline over per-submission
    /// completion could move a counter on demand and still have no queue-side
    /// wait to pair it with, and one with a real semaphore object has both.
    ///
    /// The claim is the observable one — that
    /// [`semaphore_value`](crate::Device::semaphore_value) reports the value the
    /// host asked for, and that a value which would move the timeline backwards
    /// is refused rather than accepted.
    CpuTimelineSignal,

    /// Waiting — from the CPU, or in a [`SubmitInfo`](crate::SubmitInfo) — on a
    /// timeline value that **nothing submitted so far will signal**, expecting
    /// a later signal to satisfy it.
    ///
    /// A real semaphore object blocks until somebody signals it, and
    /// [`CpuTimelineSignal`](Self::CpuTimelineSignal) is what lets the host be
    /// the somebody. A backend that emulates timelines over per-submission
    /// completion has no object for a future signal to arrive on, so such a wait
    /// could only ever stop the queue; refusing is the honest answer and it is a
    /// genuine behavioural divergence rather than a missing call.
    TimelineWaitBeforeSignal,
}

impl Capability {
    /// The [`Features`] bit a caller consults before asking for this, if there
    /// is one.
    ///
    /// **What makes the parity rule fair.** A backend that refuses because the
    /// device reports this flag clear has not diverged from anything — the
    /// device is simply lesser, which is exactly what [`Features`] already
    /// models and logs as a downgrade.
    ///
    /// It is the *claim* to be in that position that this flag settles.
    /// [`Support::granted`] is what puts a backend there, and
    /// [`parity_verdict`] checks the claim against the device before excusing
    /// it: a [`Support::NotOnThisDevice`] for a capability with no gate, or on a
    /// device that reports the gate, is
    /// [`ParityVerdict::FalseDeviceGate`]. What the flag no longer does is
    /// excuse a refusal the backend made on its own account, which is how the
    /// rule used to retire [`DIVERGENCES`] rows without anybody deciding to.
    ///
    /// `None` means no flag governs it, so every refusal is the backend's own.
    /// That is the majority here, and it is the measurement this module was
    /// built from: most refusal sites answer to no declared capability at all.
    #[must_use]
    pub const fn gating_feature(self) -> Option<Features> {
        match self {
            // Nothing in `Features` describes a buffer clear, which is why the
            // fills were the divergence that reached CI — and why the two
            // valued ones are gone: see `CommandEncoder::clear_buffer`.
            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),
            // All four are about one object, so one flag governs them.
            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())
    }
}

/// Whether a backend performs a [`Capability`], and why not when it does not.
///
/// Three arms, and the third is not a third *degree* of support: "maybe",
/// "partially" and "not yet" are all [`No`](Self::No) with a reason saying
/// which, because a caller can do nothing different with a shade of no. What
/// [`NotOnThisDevice`](Self::NotOnThisDevice) adds is **whose** no it is, which
/// is a different axis and one a caller can act on — a refusal the device
/// caused may be answered by opening a better adapter, and a refusal the backend
/// caused never is.
///
/// It is also what makes the parity record checkable; see the module docs.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Support {
    /// The backend performs it **exactly as the seam documents it**, on this
    /// device.
    ///
    /// Not "the API underneath has it" and not "the code is there": this is the
    /// claim the agnostic seam suite exercises, so a backend saying it and then
    /// refusing — or quietly doing something else — at the call site is a test
    /// failure.
    Yes,

    /// **The backend** refuses, for the reason given, and would refuse on any
    /// device.
    ///
    /// The reason is written for whoever reads the failure, so it names the
    /// obstacle — the API call that does not exist, the slice that has not
    /// landed — rather than restating the capability. `&'static str`, so asking
    /// costs no allocation.
    ///
    /// Every one of these needs a [`DIVERGENCES`] row, on every device. A
    /// backend reaching for this arm when the device is what withheld the
    /// capability has not cheated the rule so much as opted into a stricter one.
    No(&'static str),

    /// **The device** withheld the capability's
    /// [`gating_feature`](Capability::gating_feature), so the backend never got
    /// to say whether it has it.
    ///
    /// Handed out by [`granted`](Self::granted) and nowhere else in this
    /// workspace, because that is the one place a device gate is read. The
    /// distinction is not cosmetic: a lesser device is what [`Features`] already
    /// models and logs as a downgrade at device creation, and holding a software
    /// rasteriser to a mesh-shader capability would fail the parity suite for a
    /// reason nobody can fix.
    ///
    /// So this arm is *excused* by [`parity_verdict`] — which is exactly why it
    /// is checked rather than taken on trust: a backend claiming it for an
    /// ungated capability, or on a device that did report the flag, is
    /// [`ParityVerdict::FalseDeviceGate`] and fails.
    NotOnThisDevice(&'static str),
}

impl Support {
    /// [`Yes`](Self::Yes) when `features` holds `feature`, otherwise
    /// [`NotOnThisDevice`](Self::NotOnThisDevice) with `why`.
    ///
    /// The shape most arms of a backend's `match` have, written once here
    /// because five backends were otherwise going to spell the same `if` five
    /// ways — and because an arm that reads the *wrong* flag is the one mistake
    /// in this file a reviewer cannot see, so the flag belongs at the call site
    /// with nothing else beside it.
    ///
    /// **Being the only source of [`NotOnThisDevice`](Self::NotOnThisDevice) is
    /// what the parity rule rests on.** A backend does not have to know that:
    /// the arms it already routes through here are precisely the arms whose
    /// refusal belongs to the device, so the classification costs no backend a
    /// line and cannot be forgotten by one.
    ///
    /// `why` stays the caller's: which flag, and what the device would need to
    /// report, is the sentence the reader of a parity report needs.
    #[must_use]
    pub const fn granted(features: Features, feature: Features, why: &'static str) -> Self {
        if features.contains(feature) {
            Self::Yes
        } else {
            Self::NotOnThisDevice(why)
        }
    }

    /// Whether this is [`Support::Yes`].
    #[must_use]
    pub const fn is_yes(self) -> bool {
        matches!(self, Self::Yes)
    }

    /// The refusal reason, or `None` when supported.
    ///
    /// Both refusals answer, because a caller printing "why not" wants the
    /// sentence whichever of them it was.
    #[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}"),
        }
    }
}

/// Which kind of divergence an entry records — and so whether any amount of
/// work in this repository could ever close it.
///
/// **This is what makes the parity goal checkable.** Without it, "Metal's blit
/// fill takes a byte, not a word, and no work changes that", "this backend has
/// not written the code yet" and "it is written and no device here has run it"
/// are the same shape in the data, and nobody can answer "what is left?"
/// without re-reading every reason in [`DIVERGENCES`]. With it,
/// [`parity_blockers`] answers it — and the answer distinguishes work that
/// needs a programmer from work that needs a machine.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum DivergenceKind {
    /// The backend's API cannot express it. **No work here closes it**, so it
    /// is not on anybody's list.
    ///
    /// The reason must carry the evidence: the selector and the type of the
    /// argument, the WebIDL member that is absent, the enumeration that has no
    /// such value. A backend's own comment is a claim rather than evidence — a
    /// row here is a permanent promise, and the two entries this field was
    /// introduced to settle were both backend comments contradicting the list.
    ApiAbsence,

    /// The API allows it and this crate has not written it.
    ///
    /// The reason says roughly what the work is, and by convention names the
    /// slice that owes it.
    Unwritten,

    /// The code is written and no device available here has executed it.
    ///
    /// **Distinct from [`Unwritten`](Self::Unwritten) because the work owed is
    /// different in kind.** An `Unwritten` row is closed by somebody writing
    /// code; one of these is closed by somebody *running* what is already
    /// there, on hardware this project does not have — a Metal 3 Mac, a device
    /// reporting a counter set, a D3D12 GPU that is not WARP. Collapsing the two
    /// makes the remaining distance to parity read as programming when it is
    /// procurement, which is the opposite of what a reader needs.
    ///
    /// It blocks parity exactly as `Unwritten` does. The rule that a row leaves
    /// [`DIVERGENCES`] only when a device has *run* the path is unchanged, and
    /// this kind is what lets a row say so instead of claiming work is owed that
    /// is already done.
    ///
    /// The reason must name the calls that exist, so the claim is checkable by
    /// reading them, and say what device would settle it.
    Unrun,
}

impl DivergenceKind {
    /// Whether a row of this kind stands between a backend and parity.
    ///
    /// Everything except [`ApiAbsence`](Self::ApiAbsence): an API with no
    /// expression for something is not a backlog item, while unwritten code is
    /// work owed.
    ///
    /// A `match` rather than a comparison against one variant, so a kind added
    /// later has to say which side of the goal it falls on.
    #[must_use]
    pub const fn blocks_parity(self) -> bool {
        match self {
            Self::ApiAbsence => false,
            Self::Unwritten | Self::Unrun => true,
        }
    }
}

/// One (capability, backend) pair that is knowingly absent.
///
/// See [`DIVERGENCES`] for what the list as a whole is for.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Divergence {
    /// The capability the backend does not have.
    pub capability: Capability,
    /// The backend that does not have it.
    pub backend: BackendKind,
    /// Whether anything in this repository could close it. See
    /// [`DivergenceKind`], and [`parity_blockers`] for what the field is for.
    pub kind: DivergenceKind,
    /// Why, in enough detail to decide whether it should stay that way. This is
    /// the sentence a reviewer reads when the pair is added.
    pub why: &'static str,
}

/// Metal's answer for [`Capability::DrawIndirectCount`] on a device that does
/// not report the flag — in `crcbl-mtl`'s `Device::supports` and in the error
/// its encoder refuses with alike.
///
/// **One sentence in two places on purpose**, the shape a backend uses when a
/// refusal has to survive the trip from `Device::supports` to the error a
/// caller reads.
///
/// **It used to be a row in [`DIVERGENCES`], and that row is gone because the
/// work landed.** For three revisions this constant described an
/// `MTLIndirectCommandBuffer` written by a compute kernel — the design that was
/// attempted three times and hung the GPU in a frame every time. What
/// `crcbl-mtl` ships instead needs no such object: a draw of **zero instances**
/// renders nothing, so a kernel that packs the argument structures and leaves
/// every one at or past the GPU-written count with no instances turns a
/// count-limited draw into `max_draw_count` ordinary indirect draws. The
/// capability is answered through [`Support::granted`] now, so this is the
/// sentence a device that withheld
/// [`Features::DRAW_INDIRECT_COUNT`](crate::Features::DRAW_INDIRECT_COUNT)
/// would carry — which, the gate being unconditional, is a device somebody
/// deliberately reverted the slice for.
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";

/// The browser's answer for [`Capability::UpdateBindGroup`], in the parity
/// record and in `crcbl-webgpu`'s own declaration alike.
///
/// The second sentence that had drifted, and the same treatment as
/// [`METAL_NO_DRAW_INDIRECT_COUNT`]. This list used to say the stream "has no
/// update_bind_group command **yet**", which reads as schedulable work, while
/// the backend said a bind group is immutable and the stream "could not carry
/// one that worked". WebGPU settles it: `GPUBindGroup` exposes a label and
/// nothing else, so there is no mutation to encode and never will be.
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";

/// Every backend's answer for [`Capability::OcclusionQuery`], in the parity
/// record, in each `Device::supports`, and in the
/// [`HalError::Unsupported`](crate::HalError::Unsupported) that
/// [`QueryKind::check_supported`](crate::QueryKind::check_supported) refuses a
/// set with.
///
/// **One sentence in three places**, the treatment
/// [`METAL_NO_DRAW_INDIRECT_COUNT`] and [`WEBGPU_BIND_GROUPS_ARE_IMMUTABLE`]
/// already get, and here it is one sentence for *five* backends because the
/// thing that is missing is not any of theirs.
///
/// **The seam used to hand the set out**, and that is what this replaced. A
/// caller could create a [`QueryKind::Occlusion`](crate::QueryKind::Occlusion)
/// set, reset it, resolve it and read it, and what came back — measured through
/// the seam suite on radv — was zeros. Zero is not a neutral answer to "how many
/// samples were visible": it is "none of them", so occlusion culling wired to
/// this seam would have culled the scene with every return value reporting
/// success. A loud refusal is what this repository does everywhere else with a
/// promise it cannot keep.
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";

/// Every capability a backend is knowingly without, **on every device it can
/// open**.
///
/// **This is the parity contract.** A capability every GPU backend has appears
/// nowhere here; one that some have and some do not appears once per backend
/// that lacks it, with the reason. The list is checked from both directions
/// against a running device by the agnostic seam suite, so:
///
/// * a backend that starts refusing something new fails until the pair is added,
///   which is a review of the divergence rather than a silence, and
/// * a backend that starts *supporting* something listed fails until the pair is
///   removed, so the list cannot rot into a record of history.
///
/// Every row also carries a [`DivergenceKind`], which is what separates the
/// rows that are somebody's work from the rows no work can touch;
/// [`parity_blockers`] is the query that reads it.
///
/// A refusal that is merely *this device's* — the backend answered
/// [`Support::NotOnThisDevice`] because the gating [`Features`] flag is clear —
/// is not listed and is not a gap; see [`parity_verdict`]. A backend's own
/// refusal needs a row here whatever the device reports, which is what stops a
/// row being retired by a device that could not have proved anything either way.
///
/// Entries are grouped by capability. [`BackendKind::Null`] never appears: it
/// records rather than executes, so it is not part of the parity model — see
/// [`BackendKind::is_gpu`].
pub const DIVERGENCES: &[Divergence] = &[
    // --- fills: the worked example, and why no row is left ---
    //
    // `BufferFillZero` on Dx12 is not here, and its absence is what the list is
    // for: the row left because the work landed. `crcbl_dx12`'s `fill_buffer`
    // copies out of a zeroed device-local resource, which is `wgpu-hal`'s dx12
    // answer to the same call. The valued fills that were the rest of this
    // section went with the verb's `value` on 2026-08-19 — see `BufferFillZero`
    // — so the section is a heading over nothing, deliberately.
    // --- draws ---
    //
    // `DrawIndirectCount` on Metal is not here, and its absence is the second
    // worked example: the row left because the work landed. Metal still has no
    // count-buffer draw — that never changes — but it does not need one. A draw
    // of zero instances renders nothing, so `crcbl_mtl::indirect_count` packs
    // the argument structures with a compute kernel, gives every structure at
    // or past the GPU-written count no instances, and issues `max_draw_count`
    // ordinary indirect draws. See [`METAL_NO_DRAW_INDIRECT_COUNT`], which the
    // backend still shares for the device-gated refusal.
    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",
    },
    // `IndirectArgumentPaddedStride` on WebGPU is not here either, and it is the
    // third worked example — the one where the row was never true of the
    // backend in the first place. It said
    // `GPURenderPassEncoder.drawIndirect(indirectBuffer, indirectOffset)` reads
    // one tightly packed structure and has no stride to honour, which is a true
    // sentence about the WebGPU call and a false one about this backend: the
    // stride crosses the stream whole and `web/engine/gpu-replay.js` unrolls the
    // draw into one `drawIndirect` per structure at `offset + i * stride`, so a
    // padded stride is honoured by walking rather than by a parameter. An
    // `ApiAbsence` that is only an absence in the API is how a row survives
    // review: the reason reads as checkable and the thing it describes is not
    // the thing being declared.
    // Metal mesh/task rows were retired after native execution qualification;
    // unsupported Metal devices use the shared hardware/OS capability gate.
    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",
    },
    // --- bindings ---
    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",
    },
    // The Metal row that used to sit here is gone, and it left the way a row is
    // meant to: `crcbl-mtl` binds a VARIABLE_COUNT slot as one argument buffer
    // of `MTLBuffer::gpuAddress` values and keeps its contents resident with
    // `useResource:`, so the backend answers `Support::Yes` wherever the device
    // reports `DESCRIPTOR_INDEXING`.
    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",
    },
    // The WebGPU row that used to sit here is gone: the gap was the seam's own
    // descriptor, and `BindingKind::StorageImage` now carries the `view_type`
    // and `format` `GPUStorageTextureBindingLayout` demands, so `crcbl-webgpu`
    // answers `Support::Yes`. What is left is the backend nobody is finishing.
    // --- rasteriser state ---
    //
    // Only one entry, and that is the point: `PolygonModeLine`, `DepthClamp` and
    // `SamplerAnisotropy` are refused by every backend *only* where the device
    // reports the flag clear, which is `Features` doing its job. WebGPU is the
    // exception because it has no wireframe on any device it could ever open.
    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",
    },
    // --- queries ---
    //
    // **The occlusion four are one decision, taken on 2026-09-06**, and they are
    // the only rows in this list where every backend diverges for the same
    // reason and that reason is not any backend's: `crcbl_hal::CommandEncoder`
    // has no verb that scopes a count, so `QueryKind::Occlusion` is refused
    // everywhere by `QueryKind::check_supported`. See `NO_OCCLUSION_QUERY_VERB`,
    // which is the sentence all four carry and every `Device::supports`
    // declares. `Unwritten` rather than `ApiAbsence` on purpose: all four APIs
    // express occlusion queries, and the missing piece is a seam verb somebody
    // here would write — the alternative was deleting the capability, and
    // deleting it would have recorded a decision against occlusion queries that
    // nobody took. `docs/notes/backends.md` holds the argument and the
    // measurement the refusal replaced.
    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,
    },
    // Metal timestamp queries were proved on an M3 Pro on 2026-09-10,
    // including render/compute boundaries and GPU-side resolves. Clear-only
    // render passes and empty compute passes needed fixes before that proof;
    // docs/notes/metal-local-baseline.md records the hardware evidence.
    // The WebGPU TimestampQuery row that used to sit here is gone, and it left
    // the way `StorageImageBinding`'s did: the gap was the seam's own verb. It
    // had a free-standing `write_timestamp` naming an arbitrary point in the
    // command stream, which WebGPU has no expression for at all, so
    // `create_query_set` refused a timestamp set rather than hand out a handle a
    // profiler would fill with zeros. `PassTimestampWrites` is
    // `GPURenderPassDescriptor.timestampWrites`' own shape, so the browser
    // backend passes it straight through and answers `Support::Yes`. Worth
    // reading beside the occlusion rows above, which are the same shape and went
    // the other way: a gap in the seam's own vocabulary, refused by
    // `create_query_set` rather than papered over — and there, unlike here, the
    // verb has not arrived yet.
    Divergence {
        capability: Capability::PipelineStatisticsQuery,
        backend: BackendKind::Metal,
        // Reclassified with TimestampQuery on 2026-08-19, from the same probe
        // output, and written with it. It stays Unwritten for the same reason —
        // no device has run it — plus one this backend cannot fix on its own:
        // see the second half of the reason.
        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",
    },
    // --- synchronisation ---
    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",
    },
];

/// Every divergence that stands between a backend crcbl is **keeping** and
/// parity.
///
/// The answer to "what is left?", derived rather than maintained. A row is here
/// when its backend [drives a GPU](BackendKind::is_gpu) and its
/// [`kind`](Divergence::kind) [blocks parity](DivergenceKind::blocks_parity) —
/// so [`BackendKind::Null`] is excluded by the first half rather than by a
/// reader remembering to skip it, and [`DivergenceKind::ApiAbsence`] by the
/// second.
///
/// The set is snapshotted by this module's own tests, so it shrinks only when
/// somebody updates the snapshot deliberately. Yields in [`DIVERGENCES`] order.
pub fn parity_blockers() -> impl Iterator<Item = &'static Divergence> {
    DIVERGENCES
        .iter()
        .filter(|entry| entry.backend.is_gpu() && entry.kind.blocks_parity())
}

/// The [`DIVERGENCES`] entry for this pair, if the pair is a known divergence.
///
/// A linear scan of a `const` slice, which is why the list is kept small enough
/// to read: this is asked once per capability in a test, never in a frame.
#[must_use]
pub fn divergence(capability: Capability, backend: BackendKind) -> Option<&'static Divergence> {
    DIVERGENCES
        .iter()
        .find(|entry| entry.capability == capability && entry.backend == backend)
}

/// What the parity record has to say about one capability on one running
/// device — the outcome [`parity_verdict`] answers with.
///
/// Five outcomes rather than a `bool`, because "not a gap" used to cover two
/// unlike things: a divergence somebody reviewed, and a pair this device could
/// not settle either way. Folding them made a retirement free — see
/// [`UnprovableHere`](Self::UnprovableHere).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ParityVerdict {
    /// The backend performs it here. Nothing is owed, and a [`DIVERGENCES`] row
    /// for the pair would be stale.
    Supported,

    /// The backend refuses and [`DIVERGENCES`] says why. The reviewed case, and
    /// the entry is carried so a report can print the sentence.
    Reviewed(&'static Divergence),

    /// The device withheld the gating [`Features`] flag, so this run learned
    /// **nothing** about the backend — neither that it has the capability nor
    /// that it lacks it.
    ///
    /// Not a failure: the device is lesser, which `Features` already models and
    /// logs as a downgrade at creation, and there is no work anybody could do to
    /// make a software rasteriser grow a mesh stage.
    ///
    /// It is reported by name all the same, because "unprovable here" is a
    /// coverage gap and used to be indistinguishable from a clean pass. That
    /// indistinguishability is the whole defect this enum was split to fix: a
    /// gated pair reached it whether or not [`DIVERGENCES`] named the pair, so a
    /// row could be deleted and no run anywhere would notice.
    UnprovableHere(Features),

    /// **The backend's own refusal, with nobody's name on it.** The gap.
    ///
    /// [`Support::No`] means this backend would refuse on every device, so no
    /// device's [`Features`] excuse it: either a row was never written, or one
    /// was retired without the backend having learnt to do the thing.
    Unreviewed,

    /// The backend answered [`Support::NotOnThisDevice`] and the device did not
    /// withhold anything — the capability has no
    /// [`gating_feature`](Capability::gating_feature), or it has one and this
    /// device reports it.
    ///
    /// A gap, and a louder one than [`Unreviewed`](Self::Unreviewed): the
    /// excused arm is the one thing a backend could hide behind, so it is the
    /// one arm whose claim is checked against the device rather than believed.
    FalseDeviceGate,
}

impl ParityVerdict {
    /// Whether this verdict is a **parity gap** — something nobody has accounted
    /// for.
    ///
    /// The two failing outcomes and no others. [`UnprovableHere`] is deliberately
    /// not one: a device that cannot answer is not a defect in the backend.
    ///
    /// [`UnprovableHere`]: Self::UnprovableHere
    #[must_use]
    pub const fn is_gap(self) -> bool {
        match self {
            Self::Supported | Self::Reviewed(_) | Self::UnprovableHere(_) => false,
            Self::Unreviewed | Self::FalseDeviceGate => true,
        }
    }
}

/// What the parity record says about `capability` on `backend`, given what the
/// backend `declared` on a device reporting `features`.
///
/// The rule the agnostic seam suite applies to every capability of a running
/// device, and the whole of what "reviewed divergence" means here:
///
/// * [`Support::Yes`] is [`Supported`](ParityVerdict::Supported). The backend
///   does it, and the suite's other half holds it to that by driving the call.
/// * [`Support::NotOnThisDevice`] is
///   [`UnprovableHere`](ParityVerdict::UnprovableHere) — **if the device really
///   did withhold the gate**, which is checked here rather than assumed.
///   Otherwise the backend blamed a device that gave it what it asked for, and
///   that is [`FalseDeviceGate`](ParityVerdict::FalseDeviceGate).
/// * [`Support::No`] that [`DIVERGENCES`] names is
///   [`Reviewed`](ParityVerdict::Reviewed). Somebody decided it and wrote down
///   why.
/// * [`Support::No`] that it does not name is
///   [`Unreviewed`](ParityVerdict::Unreviewed): this backend cannot do something
///   its peers can and nobody has said so. **The device's `features` do not
///   enter into it** — that is the fix. The old rule waived a refusal whenever
///   the device reported the gate clear, which waived it for backends that had
///   never looked at the gate, and so retired their rows for them.
///
/// Deliberately blind to [`DivergenceKind`]: a written reason is what makes a
/// refusal reviewed, whatever kind of divergence it turned out to be. "Which of
/// them is still somebody's work" is the other question, and
/// [`parity_blockers`] is where it is asked.
#[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::*;

    /// Every GPU backend, for the tests that must sweep them. Written out rather
    /// than derived, so that a new [`BackendKind`] fails
    /// [`every_gpu_backend_is_in_this_sweep`] instead of silently escaping the
    /// parity model.
    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());
        // The count comes from `is_gpu`'s own match rather than from a literal,
        // so a fifth backend makes this fail instead of quietly sitting outside
        // every sweep below.
        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"
        );
    }

    /// `ALL` is generated from the enum's own variant list, so it cannot fail by
    /// omission — what this catches is the macro being replaced by a
    /// hand-written array later, which is the whole reason the macro exists.
    #[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"
        );
    }

    /// A name is what a failing parity report prints, so two variants sharing
    /// one would leave the report unable to say which diverged.
    #[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());
        }
    }

    /// A gate must be a single flag. `Features::GPU_DRIVEN` is a named union,
    /// and a capability gated on it would be unsatisfiable on any device missing
    /// any one of six unrelated things.
    #[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()
        );
    }

    /// The one constructor a device gate is read through, and the only source of
    /// [`Support::NotOnThisDevice`] — so this asserts the *variant*, not merely
    /// that it said no. A `granted` that answered [`Support::No`] would put every
    /// lesser device back in front of [`ParityVerdict::Unreviewed`].
    #[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")
        );
        // And it is `contains`, not `intersects`: a capability gated on a flag
        // the device half-has would otherwise report supported.
        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"
        );

        // The two refusals read differently, because a reader deciding whether
        // to try another adapter needs to know which one this was.
        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"
        );
    }

    /// One pair, one entry. A duplicate would make [`divergence`] return the
    /// first and hide whichever reason somebody added second.
    #[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"
        );
    }

    /// The list is read by whoever is deciding whether a divergence should stay,
    /// so an entry that says nothing is an entry nobody reviewed.
    #[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
            );
        }
    }

    /// [`BackendKind::Null`] records rather than executes, so an entry naming it
    /// would be describing a recorder's limitation as a backend divergence.
    #[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
            );
        }
    }

    /// A capability every GPU backend lacks is a seam behaviour nothing
    /// implements, not a *divergence* — so it may only be listed once somebody
    /// has decided to leave it that way.
    ///
    /// **The exception is [`DEFERRED_CAPABILITIES`], and it is a hand-edited
    /// list for the same reason [`REVIEWED_BLOCKERS`] is.** A capability the
    /// whole seam refuses still belongs in [`DIVERGENCES`] when the refusal was
    /// weighed and taken — [`Capability::OcclusionQuery`] is one, and the rows
    /// are what makes its cost visible instead of the gap being absorbed into
    /// prose. What this catches is the other case: a capability quietly refused
    /// everywhere because nobody wrote it, filed as four parity exceptions and
    /// read as four separate backend gaps.
    ///
    /// The other half too: [`divergence`] must find every entry the list holds,
    /// and must not invent one.
    #[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
        );
    }

    /// The rule, checked on every case that decides it. Written as a table
    /// because the failure mode is an `&&` where an `||` belongs, which reads
    /// identically and makes the parity suite either vacuous or unpassable.
    #[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");

        // Supported: nothing owed, whatever the list says.
        assert_eq!(
            parity_verdict(
                Capability::MeshShading,
                BackendKind::Vulkan,
                Support::Yes,
                all
            ),
            ParityVerdict::Supported
        );
        // A backend refusal the list names: reviewed. An *ungated* pair, so the
        // verdict cannot be coming from a flag the device happens to report —
        // `IndirectArgumentPaddedStride` stood here until its row left, and the
        // replacement was chosen to keep that property rather than only to
        // compile.
        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);
        // The device withheld the gate: this run proves nothing either way, and
        // saying so is not a failure.
        assert_eq!(
            parity_verdict(
                Capability::MeshShading,
                BackendKind::Vulkan,
                withheld,
                no_mesh
            ),
            ParityVerdict::UnprovableHere(Features::MESH_SHADER)
        );
        // A backend refusal nobody wrote down: a gap.
        assert_eq!(
            parity_verdict(Capability::MeshShading, BackendKind::Vulkan, refused, all),
            ParityVerdict::Unreviewed
        );

        // **The hole this rule was rewritten to close.** The same unlisted
        // backend refusal on a device that withheld the gate: the old rule
        // waived it, so retiring the row cost nothing and no run anywhere
        // noticed. It is the same gap it is on a device that reports the flag.
        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"
        );

        // And the escape hatch is checked rather than believed, in both of its
        // failure shapes: an ungated capability has no device to blame, and a
        // device that reported the flag did not withhold 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
        );

        // Ungated and unlisted: always a gap, whatever the device reports.
        assert!(
            parity_verdict(
                Capability::BufferFillZero,
                BackendKind::Vulkan,
                refused,
                Features::empty()
            )
            .is_gap()
        );
        // Ungated and listed: never a gap. WebGPU's immutable bind groups,
        // because nothing in `Features` describes rewriting one.
        //
        // The indirect stride used to stand here, on the grounds that the row
        // was permanent. No row is: that one left when somebody read the
        // replayer and found it already walking the stride. A fixture is picked
        // for the shape it exercises — ungated, and on the list — and the pair
        // that has it is checked rather than assumed.
        assert!(
            !parity_verdict(
                Capability::UpdateBindGroup,
                BackendKind::WebGpu,
                refused,
                Features::empty()
            )
            .is_gap()
        );
    }

    /// Which verdicts fail, as a table: the failure mode is a variant landing on
    /// the wrong side, which would either make the suite unpassable or make the
    /// whole report advisory.
    #[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());
    }

    /// **Every row in the list is one a running backend can be held to.**
    ///
    /// The property the rule rewrite buys, asserted over the data rather than
    /// argued in a doc comment: a row exists to excuse a [`Support::No`], and
    /// [`parity_verdict`] answers [`ParityVerdict::Reviewed`] for that pair on
    /// **every** device, including one reporting nothing at all. So deleting any
    /// row turns that same pair into [`ParityVerdict::Unreviewed`] on the
    /// backend's own CI arm — there is no device on which the deletion passes
    /// unnoticed, which is what "a retirement must be earned" means here.
    #[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
                );
                // The counterfactual — that same refusal with no row behind it.
                // `divergence` is the only thing the rule reads for a
                // `Support::No`, so an unlisted pair *is* what a deleted row
                // leaves. `Null` stands in for one because the list can never
                // name it — `divergences_name_only_gpu_backends` is what holds
                // that — which is why it replaced Vulkan here on 2026-09-06,
                // when the occlusion rows gave Vulkan an entry and the
                // counterfactual a pair that was no longer unlisted.
                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
                );
            }
        }
    }

    /// Every divergence standing between crcbl and its stated end state, as
    /// reviewed — the whole of what full backend parity still asks for.
    /// **Update this deliberately.**
    ///
    /// A snapshot rather than a rule, and that is the point: a row leaves only
    /// when somebody writes the code, overturns the decline, or shows the API
    /// cannot express it after all. Each of those is a review, and a test that
    /// merely counted the rows — or checked that each had *some* kind — would
    /// pass whether the classification were right or wrong.
    const REVIEWED_BLOCKERS: &[(Capability, BackendKind, DivergenceKind)] = &[
        // **`OcclusionQuery` is the one row every backend has**, and the only
        // one here that is nobody's backend work: `crcbl_hal::CommandEncoder`
        // has no verb that scopes a count, so every `create_query_set` refuses
        // the kind — see `NO_OCCLUSION_QUERY_VERB` and the four `DIVERGENCES`
        // rows it is the reason for. Decided 2026-09-06 to refuse rather than
        // finish or delete; `docs/notes/backends.md` argues it. These four are
        // parked by that decision rather than by a backend's deferral, which is
        // what `DEFERRED_CAPABILITIES` says.
        (
            Capability::OcclusionQuery,
            BackendKind::Vulkan,
            DivergenceKind::Unwritten,
        ),
        (
            Capability::OcclusionQuery,
            BackendKind::WebGpu,
            DivergenceKind::Unwritten,
        ),
        (
            Capability::OcclusionQuery,
            BackendKind::Metal,
            DivergenceKind::Unwritten,
        ),
        (
            Capability::OcclusionQuery,
            BackendKind::Dx12,
            DivergenceKind::Unwritten,
        ),
        // `crcbl-dx12`'s own rows are the two below: D3D12 expresses every
        // capability here, so every row of its below is `Unwritten` rather than
        // an `ApiAbsence` — mesh shading and the task stage are shader-model
        // features nobody has written against, not ones the API lacks.
        // `BufferFillZero` was another and left the way a row is meant to: the
        // backend fills to zero now, by copying out of a zeroed resource.
        (
            Capability::MeshShading,
            BackendKind::Dx12,
            DivergenceKind::Unwritten,
        ),
        (
            Capability::TaskShaderStage,
            BackendKind::Dx12,
            DivergenceKind::Unwritten,
        ),
        // Metal: the byte-wide fill is the API and is not here. The occlusion
        // query is, and it arrived from the seam rather than from this backend —
        // `crcbl-mtl` builds the visibility buffer and nothing can count into
        // it. `DrawIndirectCount` is not here either, and that one left
        // the way a row is meant to: `crcbl_mtl::indirect_count` packs the
        // argument structures with a compute kernel and draws
        // `max_draw_count` times, so the count is honoured with no indirect
        // command buffer anywhere.
        //
        // The two counter-sampled query rows were `Unclassified` until
        // 2026-08-19, on the grounds that settling them needed a measurement
        // this workspace could not take. `crcbl_mtl::adapter`'s probe has since
        // taken it, on CI: `AtStageBoundary=false`, `AtDrawBoundary=true`,
        // `counterSets=0`. Metal expresses both features, so neither is an
        // `ApiAbsence` and both are `Unwritten`. **The blocker count did not
        // move** — an unanswered question and unwritten work both block parity,
        // and reclassifying one as the other is honesty about what is owed,
        // not progress against it.
        (
            Capability::PipelineStatisticsQuery,
            BackendKind::Metal,
            DivergenceKind::Unrun,
        ),
        // `crcbl-webgpu`'s only row is the occlusion one at the top, and that
        // is worth reading twice: everything *WebGPU* refuses is WebGPU itself
        // refusing, which is an `ApiAbsence` and not a blocker, so the one row
        // the browser backend carries is one this seam owes rather than one the
        // platform lacks. It had two rows of its own before and both left the
        // way a row is supposed to — the work landed.
        // `StorageImageBinding` went when `BindingKind::StorageImage` grew its
        // `view_type` and `format`; `TimestampQuery` went when the seam's
        // free-standing `write_timestamp` became `PassTimestampWrites` on the
        // pass descriptor, which is `timestampWrites`' own shape.
    ];

    /// The backends whose remaining work is parked rather than owed.
    ///
    /// `crcbl-mtl` and `crcbl-dx12` were deferred on 2026-08-21 —
    /// `docs/plan/09-backends-metal-dx12.md` holds the state and
    /// `docs/backlog.md` the two `DEFERRED` entries. The crates and their CI
    /// jobs stay so a regression still shows; what stops is feature work on
    /// them.
    const DEFERRED_BACKENDS: &[BackendKind] = &[BackendKind::Metal, BackendKind::Dx12];

    /// The capabilities whose remaining work is parked on every backend at once.
    ///
    /// A second axis, because [`Capability::OcclusionQuery`] is parked for a
    /// reason no backend's deferral covers: the work is a verb on
    /// [`crate::CommandEncoder`] plus its five implementations, and it was
    /// decided on 2026-09-06 that the verb waits until something wants the
    /// counts — `docs/notes/backends.md` and `docs/backlog.md` hold the
    /// decision. Folding these rows into [`DEFERRED_BACKENDS`] would have meant
    /// calling `crcbl-vk` and `crcbl-webgpu` deferred, which they are not.
    const DEFERRED_CAPABILITIES: &[Capability] = &[Capability::OcclusionQuery];
    /// **`parity_blockers` cannot reach empty while the deferrals hold, and
    /// this is what says so instead of the count quietly redefining done.**
    ///
    /// Every row [`parity_blockers`] yields is either on a
    /// [deferred backend](DEFERRED_BACKENDS) or is a
    /// [deferred capability](DEFERRED_CAPABILITIES), so the honest reading of a
    /// non-zero blocker count today is "parked", not "outstanding". Nothing
    /// about that is expressed by the number itself, and a reader who saw only
    /// the number would conclude there was work to pick up.
    ///
    /// **A failure here is the useful case.** A blocker on `crcbl-vk` or
    /// `crcbl-webgpu` that nothing parked is work somebody is meant to do, and
    /// it would otherwise join the parked rows and read as more of the same. The
    /// second assertion is what stops the first going vacuous: with no blockers
    /// at all, "none of them is live" is true and says nothing, and the deferral
    /// notes above have become the thing to delete.
    #[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"
        );
    }

    /// The one that makes the goal checkable: what
    /// [`parity_blockers`] answers must be what somebody reviewed, row for row.
    ///
    /// Fails when a row joins or leaves the blocker set, when a blocking row is
    /// reclassified, and when a row is moved to another backend — each of which
    /// is a change to "what is left" and none of which should reach `main`
    /// without a human editing [`REVIEWED_BLOCKERS`] to match.
    #[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"
        );
    }

    /// **Every backend in the model is now a parity target, and the filter that
    /// said otherwise is gone.**
    ///
    /// `parity_blockers` used to filter on `BackendKind::is_parity_target`,
    /// whose only `false` arm besides `Null` was `Wgpu` — the bridge backend
    /// that was always going to be deleted, and whose divergences were therefore
    /// not work anybody would do. `crcbl-wgpu` went on 2026-08-21 and the two
    /// predicates became the same function, so the second was deleted rather
    /// than kept for a hypothetical successor.
    ///
    /// What is asserted here is the property that replaced it: the filter is
    /// `is_gpu`, every GPU backend passes it, and `Null` does not — so a row on
    /// any real backend reaches the blocker set and cannot be excluded by
    /// anything except its own kind.
    #[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"
        );
    }

    /// The rule the query is built on, as a table: the failure mode is a
    /// negation dropped or added, which reads identically and would either
    /// empty the blocker set or fill it with rows nobody can act on.
    #[test]
    fn only_an_api_absence_is_off_the_hook() {
        assert!(!DivergenceKind::ApiAbsence.blocks_parity());
        assert!(DivergenceKind::Unwritten.blocks_parity());
    }

    /// A kind nothing uses is a distinction nobody made. Each of the four has to
    /// describe a real row, or it is vocabulary rather than classification.
    #[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"
            );
        }
    }

    /// A shared reason is shared with the row it describes.
    ///
    /// The other half of each pairing is a `Support::No(…)` in the backend
    /// crate, which the compiler checks by being a use of the same constant.
    /// This end is what stops somebody pasting the text back into the row as a
    /// literal and letting the two drift again.
    ///
    /// [`METAL_NO_DRAW_INDIRECT_COUNT`] is **not** checked here any more, and
    /// the assertion below is why: its row left [`DIVERGENCES`] when
    /// `crcbl-mtl` learned to honour a GPU-side count, so the constant is now
    /// shared between that backend's `Device::supports` gate and the error its
    /// encoder refuses with — two places the compiler checks, and neither of
    /// them a row. A row reappearing under it would mean the slice was reverted
    /// without the entry being restored, which is the state
    /// `the_parity_blockers_are_exactly_the_reviewed_list` fails on.
    #[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)
        );
    }
}