concinnity-device 0.18.64

GPU backends (Metal, Vulkan, DirectX) behind a device facade for Concinnity
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
// Single-source engine shader programs for the DirectX backend.
//
// Each program compiles a `.slang` file under `src/shaders/` (the
// backend-neutral single-source directory) to a signed DXIL container at
// renderer init by invoking slangc, cached in the content-addressed shader
// cache exactly like the HLSL programs in `builtins`. slangc resolves dxil.dll
// itself, so the containers it emits are already signed for D3D12.
//
// The bindless main pair compiles the source's `DXIL_ABI` block, whose
// register() annotations reproduce the bindless main root signature in
// `init/pipelines.rs` slot for slot: that layout is a contract, since a world
// Shader asset builds its own PSO against the same root signature (see
// world_shaders.rs). `assert_slang_dxil_abi` in build.rs locks it. The two
// compute kernels need no ABI block: slangc assigns b0/t0/u0 from declaration
// order, which is what their root signatures already bind.
//
// The G-buffer pre-pass and shadow families take the same `DXIL_ABI` block for
// a weaker reason: nothing outside the engine binds them, but their root
// signatures hand the same declarations entirely different slots than the Metal
// and Vulkan hosts do, so the shared source cannot carry one set of registers
// for all three. `assert_slang_dxil_abi` in build.rs locks every one of them,
// which is what a macOS edit to the shared file runs into under
// `dx_crosscheck.sh`.
//
// The fullscreen post passes need no ABI block either, and for a stronger
// reason than the compute kernels: nothing outside the engine binds them at
// all. slangc splits each top-level `Sampler2D` into a `Texture2D` + a
// `SamplerState` and numbers both from declaration order, so a pass with N
// sources lands on t0..tN-1 *and* s0..sN-1 -- where the hand HLSL declared one
// sampler for all of them. The root signatures name the samplers they hand out
// (a pass's static samplers are the same descriptor repeated).
//
// Declaration order is what the root signatures follow, and it is not always
// the order the hand HLSL used: the SSR resolve's probe cube array lands at t4
// (not the hand shader's t7) with its `ProbeSet` at b1 (not b4), and the
// reflection composite reads scene / G-buffer / roughness at t1 / t2 / t3 where
// the HLSL had roughness first.
//
// These are shader model 6.0 rather than the FXC path's 5.1: the bindless pool
// index is non-uniform across a fragment wave, and `NonUniformResourceIndex`
// is an SM 6.0 construct.

use concinnity_slang as slang;

pub(crate) struct SlangProgram {
    // File name under `src/shaders/` for the hot-reload disk-first resolve;
    // also the embedded fallback's origin and the name slangc diagnostics use.
    pub file: &'static str,
    pub embedded: &'static str,
    pub entry: &'static str,
    // Shader-model profile for the DXIL container (stage + feature floor).
    pub profile: &'static str,
    // Diagnostic label (compile errors + cache miss logs + export report).
    pub label: &'static str,
    // Variant defines injected as `#define` lines ahead of the source.
    pub defines: &'static [(&'static str, &'static str)],
}

const MAIN_BINDLESS_SLANG: &str = include_str!("../shaders/main_bindless.slang");
const LIGHT_CULL_SLANG: &str = include_str!("../shaders/light_cull.slang");
const HIZ_BUILD_SLANG: &str = include_str!("../shaders/hiz_build.slang");
const FOG_SLANG: &str = include_str!("../shaders/fog.slang");
const AUTO_EXPOSURE_SLANG: &str = include_str!("../shaders/auto_exposure.slang");
const PARTICLE_SIMULATE_SLANG: &str = include_str!("../shaders/particle_simulate.slang");
const RT_SKIN_SLANG: &str = include_str!("../shaders/rt_skin.slang");
const GBUFFER_PREPASS_SLANG: &str = include_str!("../shaders/gbuffer_prepass.slang");
const SHADOW_SLANG: &str = include_str!("../shaders/shadow.slang");
const FULLSCREEN_SLANG: &str = include_str!("../shaders/fullscreen.slang");
const TAA_SLANG: &str = include_str!("../shaders/taa.slang");
const BLOOM_SLANG: &str = include_str!("../shaders/bloom.slang");
const COMPOSITE_SLANG: &str = include_str!("../shaders/composite.slang");
const SSAO_SLANG: &str = include_str!("../shaders/ssao.slang");
const SSR_SLANG: &str = include_str!("../shaders/ssr.slang");
const SSGI_SLANG: &str = include_str!("../shaders/ssgi.slang");
const REFLECTION_SLANG: &str = include_str!("../shaders/reflection.slang");
const RT_REFLECTIONS_SLANG: &str = include_str!("../shaders/rt_reflections.slang");
const GLASS_SLANG: &str = include_str!("../shaders/glass.slang");
const WATER_SLANG: &str = include_str!("../shaders/water.slang");
const GLASS_MESH_SLANG: &str = include_str!("../shaders/glass_mesh.slang");
const PARTICLE_SLANG: &str = include_str!("../shaders/particle.slang");
const DECAL_SLANG: &str = include_str!("../shaders/decal.slang");
const LINE_SLANG: &str = include_str!("../shaders/line.slang");
const TEXT_SLANG: &str = include_str!("../shaders/text.slang");

// The bindless main pair's variant defines. `MAX_PROBES` sizes the probe cube
// array the root signature's descriptor table covers; `probe_cube_count_matches`
// locks it to the host constant. `POOL_SIZE` is deliberately absent: the DXIL
// pool is an unbounded array, so the shader never over-declares the per-frame
// descriptor region the host actually wrote.
const MAIN_DEFINES: &[(&str, &str)] = &[("DXIL_ABI", "1"), ("MAX_PROBES", "8")];

// The SSR resolve reads the probe array but none of the texture pool, so it
// takes the probe count alone. Same lock as `MAIN_DEFINES`.
// `SPLIT_PROBE_SAMPLER` declares that array as a texture array plus one
// sampler: D3D12 binds a shader sampler *array* only through a descriptor
// table, so the combined form Metal and Vulkan use cannot be covered by static
// samplers here (see the declaration in `ssr.slang`).
const SSR_DEFINES: &[(&str, &str)] = &[("MAX_PROBES", "8"), ("SPLIT_PROBE_SAMPLER", "1")];

pub(super) static MAIN_BINDLESS_VERT: SlangProgram = SlangProgram {
    file: "main_bindless.slang",
    embedded: MAIN_BINDLESS_SLANG,
    entry: "vertex_main_bindless",
    profile: "vs_6_0",
    label: "vert_bindless.slang",
    defines: MAIN_DEFINES,
};
pub(super) static MAIN_BINDLESS_FRAG: SlangProgram = SlangProgram {
    file: "main_bindless.slang",
    embedded: MAIN_BINDLESS_SLANG,
    entry: "fragment_main_bindless",
    profile: "ps_6_0",
    label: "frag_bindless.slang",
    defines: MAIN_DEFINES,
};
pub(super) static LIGHT_CULL: SlangProgram = SlangProgram {
    file: "light_cull.slang",
    embedded: LIGHT_CULL_SLANG,
    entry: "light_cull_kernel",
    profile: "cs_6_0",
    label: "light_cull.slang",
    defines: &[],
};
pub(super) static HIZ_INIT_SINGLE: SlangProgram = SlangProgram {
    file: "hiz_build.slang",
    embedded: HIZ_BUILD_SLANG,
    entry: "hiz_init_single",
    profile: "cs_6_0",
    label: "hiz_init_single.slang",
    defines: &[("HIZ_INIT_SINGLE", "1")],
};
pub(super) static HIZ_INIT_MSAA: SlangProgram = SlangProgram {
    file: "hiz_build.slang",
    embedded: HIZ_BUILD_SLANG,
    entry: "hiz_init_msaa",
    profile: "cs_6_0",
    label: "hiz_init_msaa.slang",
    defines: &[("HIZ_INIT_MSAA", "1")],
};
pub(super) static HIZ_DOWNSAMPLE: SlangProgram = SlangProgram {
    file: "hiz_build.slang",
    embedded: HIZ_BUILD_SLANG,
    entry: "hiz_downsample",
    profile: "cs_6_0",
    label: "hiz_downsample.slang",
    defines: &[("HIZ_DOWNSAMPLE", "1")],
};

// The G-buffer pre-pass and shadow families. Every entry is its own program so
// each variant declares exactly the resources its root signature binds; the
// `DXIL_ABI` gate pins those registers to the signatures in `post/gbuffer.rs`,
// `init/pipelines.rs` and `resources.rs`.
const GB_STATIC: &[(&str, &str)] = &[("GB_STATIC", "1"), ("DXIL_ABI", "1")];
const GB_INSTANCED: &[(&str, &str)] = &[("GB_INSTANCED", "1"), ("DXIL_ABI", "1")];
const GB_SKINNED: &[(&str, &str)] = &[("GB_SKINNED", "1"), ("DXIL_ABI", "1")];
const GB_BINDLESS: &[(&str, &str)] = &[("GB_BINDLESS", "1"), ("DXIL_ABI", "1")];
const GB_FRAGMENT: &[(&str, &str)] = &[("GB_FRAGMENT", "1"), ("DXIL_ABI", "1")];
const GB_FRAGMENT_BINDLESS: &[(&str, &str)] = &[("GB_FRAGMENT_BINDLESS", "1"), ("DXIL_ABI", "1")];
const SHADOW_STATIC: &[(&str, &str)] = &[("SHADOW_STATIC", "1"), ("DXIL_ABI", "1")];
const SHADOW_SKINNED: &[(&str, &str)] = &[("SHADOW_SKINNED", "1"), ("DXIL_ABI", "1")];
const SHADOW_BINDLESS: &[(&str, &str)] = &[("SHADOW_BINDLESS", "1"), ("DXIL_ABI", "1")];

pub(super) static GBUFFER_PREPASS_VERT: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_vertex",
    profile: "vs_6_0",
    label: "gbuffer_prepass_vert.slang",
    defines: GB_STATIC,
};
pub(super) static GBUFFER_PREPASS_VERT_INSTANCED: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_vertex_instanced",
    profile: "vs_6_0",
    label: "gbuffer_prepass_vert_instanced.slang",
    defines: GB_INSTANCED,
};
pub(super) static GBUFFER_PREPASS_VERT_SKINNED: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_vertex_skinned",
    profile: "vs_6_0",
    label: "gbuffer_prepass_vert_skinned.slang",
    defines: GB_SKINNED,
};
pub(super) static GBUFFER_BINDLESS_VERT: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_vertex_bindless",
    profile: "vs_6_0",
    label: "gbuffer_prepass_vert_bindless.slang",
    defines: GB_BINDLESS,
};
pub(super) static GBUFFER_PREPASS_FRAG: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_fragment",
    profile: "ps_6_0",
    label: "gbuffer_prepass_frag.slang",
    defines: GB_FRAGMENT,
};
pub(super) static GBUFFER_BINDLESS_FRAG: SlangProgram = SlangProgram {
    file: "gbuffer_prepass.slang",
    embedded: GBUFFER_PREPASS_SLANG,
    entry: "gbuffer_prepass_fragment_bindless",
    profile: "ps_6_0",
    label: "gbuffer_prepass_frag_bindless.slang",
    defines: GB_FRAGMENT_BINDLESS,
};
pub(super) static SHADOW_VERT: SlangProgram = SlangProgram {
    file: "shadow.slang",
    embedded: SHADOW_SLANG,
    entry: "shadow_vertex_main",
    profile: "vs_6_0",
    label: "shadow_vert.slang",
    defines: SHADOW_STATIC,
};
pub(super) static SKINNED_SHADOW_VERT: SlangProgram = SlangProgram {
    file: "shadow.slang",
    embedded: SHADOW_SLANG,
    entry: "shadow_vertex_main_skinned",
    profile: "vs_6_0",
    label: "shadow_vert_skinned.slang",
    defines: SHADOW_SKINNED,
};
pub(super) static SHADOW_BINDLESS_VERT: SlangProgram = SlangProgram {
    file: "shadow.slang",
    embedded: SHADOW_SLANG,
    entry: "shadow_vertex_bindless",
    profile: "vs_6_0",
    label: "shadow_vert_bindless.slang",
    defines: SHADOW_BINDLESS,
};

// The fog family, auto-exposure and the particle simulation kernel. None takes
// an ABI block: slangc assigns b/t/u/s from declaration order here, which is
// exactly what the root signatures in `fog.rs`, `auto_exposure.rs` and
// `particle.rs` already bind. The fog fragment's vertex half is
// `FULLSCREEN_VERT` below -- the last per-family fullscreen vertex to retire.
//
// Two DirectX-only gates ride these. `DXIL_SPLIT` declares the cascade array as
// a texture plus a comparison sampler rather than the combined
// `Sampler2DArray` the other two backends bind, because `SampleCmp` on a
// combined type mis-lowers on DXIL -- the same split `main_bindless.slang`
// carries for the same reason. `DXIL_STAGE_PACKING` makes the fog fragment
// declare the fullscreen varying it never reads, because D3D links the two
// stages by semantic *and* register and fog is the one post fragment that takes
// no varying; see the declaration in `fog.slang`.
const FOG_FROXEL_DEFINES: &[(&str, &str)] = &[("FOG_FROXEL", "1"), ("DXIL_SPLIT", "1")];

pub(super) static FOG_FROXEL: SlangProgram = SlangProgram {
    file: "fog.slang",
    embedded: FOG_SLANG,
    entry: "fog_froxel_kernel",
    profile: "cs_6_0",
    label: "fog_froxel.slang",
    defines: FOG_FROXEL_DEFINES,
};

// The fog fragment declares its depth source by the main pass's sample count,
// which is a host difference rather than a target one, so it takes two
// programs the way the Hi-Z init pair does: the caller picks by MSAA state and
// the export-time precompile leaves a bundle warm for either.
pub(super) static FOG_FRAG: SlangProgram = SlangProgram {
    file: "fog.slang",
    embedded: FOG_SLANG,
    entry: "fog_fragment",
    profile: "ps_6_0",
    label: "fog_frag.slang",
    defines: &[("USE_MSAA", "0"), ("DXIL_STAGE_PACKING", "1")],
};
pub(super) static FOG_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "fog.slang",
    embedded: FOG_SLANG,
    entry: "fog_fragment",
    profile: "ps_6_0",
    label: "fog_frag_msaa.slang",
    defines: &[("USE_MSAA", "1"), ("DXIL_STAGE_PACKING", "1")],
};

pub(super) static AUTO_EXPOSURE_BUILD: SlangProgram = SlangProgram {
    file: "auto_exposure.slang",
    embedded: AUTO_EXPOSURE_SLANG,
    entry: "histogram_build",
    profile: "cs_6_0",
    label: "auto_exposure_build.slang",
    defines: &[("AE_BUILD", "1")],
};
pub(super) static AUTO_EXPOSURE_AVERAGE: SlangProgram = SlangProgram {
    file: "auto_exposure.slang",
    embedded: AUTO_EXPOSURE_SLANG,
    entry: "histogram_average",
    profile: "cs_6_0",
    label: "auto_exposure_average.slang",
    defines: &[("AE_AVERAGE", "1")],
};

// The RT skinning kernel takes the same shader model as the RT reflection
// resolve it feeds; its own body needs no SM 6.5 feature.
pub(super) static RT_SKIN: SlangProgram = SlangProgram {
    file: "rt_skin.slang",
    embedded: RT_SKIN_SLANG,
    entry: "rt_skin",
    profile: "cs_6_5",
    label: "rt_skin.slang",
    defines: &[],
};

pub(super) static PARTICLE_SIMULATE: SlangProgram = SlangProgram {
    file: "particle_simulate.slang",
    embedded: PARTICLE_SIMULATE_SLANG,
    entry: "particle_simulate",
    profile: "cs_6_0",
    label: "particle_simulate.slang",
    defines: &[],
};

// The fullscreen-triangle vertex stage every post pass pairs with; one module
// serves them all, retiring the four per-family `*_vert.hlsl` copies.
pub(super) static FULLSCREEN_VERT: SlangProgram = SlangProgram {
    file: "fullscreen.slang",
    embedded: FULLSCREEN_SLANG,
    entry: "fullscreen_vertex",
    profile: "vs_6_0",
    label: "fullscreen_vert.slang",
    defines: &[],
};
pub(super) static TAA_FRAG: SlangProgram = SlangProgram {
    file: "taa.slang",
    embedded: TAA_SLANG,
    entry: "taa_fragment_main",
    profile: "ps_6_0",
    label: "taa_frag.slang",
    defines: &[],
};
pub(super) static BLOOM_PREFILTER: SlangProgram = SlangProgram {
    file: "bloom.slang",
    embedded: BLOOM_SLANG,
    entry: "bloom_prefilter_fragment",
    profile: "ps_6_0",
    label: "bloom_prefilter.slang",
    defines: &[("BLOOM_PREFILTER", "1")],
};
pub(super) static BLOOM_DOWNSAMPLE: SlangProgram = SlangProgram {
    file: "bloom.slang",
    embedded: BLOOM_SLANG,
    entry: "bloom_downsample_fragment",
    profile: "ps_6_0",
    label: "bloom_downsample.slang",
    defines: &[("BLOOM_DOWNSAMPLE", "1")],
};
pub(super) static BLOOM_UPSAMPLE: SlangProgram = SlangProgram {
    file: "bloom.slang",
    embedded: BLOOM_SLANG,
    entry: "bloom_upsample_fragment",
    profile: "ps_6_0",
    label: "bloom_upsample.slang",
    defines: &[("BLOOM_UPSAMPLE", "1")],
};
pub(super) static COMPOSITE_FRAG: SlangProgram = SlangProgram {
    file: "composite.slang",
    embedded: COMPOSITE_SLANG,
    entry: "composite_fragment",
    profile: "ps_6_0",
    label: "composite_frag.slang",
    defines: &[],
};
pub(super) static SSAO_KERNEL: SlangProgram = SlangProgram {
    file: "ssao.slang",
    embedded: SSAO_SLANG,
    entry: "ssao_kernel_fragment",
    profile: "ps_6_0",
    label: "ssao_kernel.slang",
    defines: &[("SSAO_KERNEL", "1")],
};
pub(super) static SSAO_BLUR: SlangProgram = SlangProgram {
    file: "ssao.slang",
    embedded: SSAO_SLANG,
    entry: "ssao_blur_fragment",
    profile: "ps_6_0",
    label: "ssao_blur.slang",
    defines: &[("SSAO_BLUR", "1")],
};
pub(super) static SSR_RESOLVE: SlangProgram = SlangProgram {
    file: "ssr.slang",
    embedded: SSR_SLANG,
    entry: "ssr_resolve_fragment",
    profile: "ps_6_0",
    label: "ssr_resolve.slang",
    defines: SSR_DEFINES,
};
pub(super) static SSGI_GATHER: SlangProgram = SlangProgram {
    file: "ssgi.slang",
    embedded: SSGI_SLANG,
    entry: "ssgi_gather_fragment",
    profile: "ps_6_0",
    label: "ssgi_gather.slang",
    defines: &[("SSGI_GATHER", "1")],
};
pub(super) static SSGI_COMPOSITE: SlangProgram = SlangProgram {
    file: "ssgi.slang",
    embedded: SSGI_SLANG,
    entry: "ssgi_composite_fragment",
    profile: "ps_6_0",
    label: "ssgi_composite.slang",
    defines: &[("SSGI_COMPOSITE", "1")],
};
pub(super) static REFLECTION_BLUR: SlangProgram = SlangProgram {
    file: "reflection.slang",
    embedded: REFLECTION_SLANG,
    entry: "reflection_blur_fragment",
    profile: "ps_6_0",
    label: "reflection_blur.slang",
    defines: &[("REFLECTION_BLUR", "1")],
};
pub(super) static REFLECTION_COMPOSITE: SlangProgram = SlangProgram {
    file: "reflection.slang",
    embedded: REFLECTION_SLANG,
    entry: "reflection_composite_fragment",
    profile: "ps_6_0",
    label: "reflection_composite.slang",
    defines: &[("REFLECTION_COMPOSITE", "1")],
};

// The ray-traced reflection resolve and the glass family. Both take the
// `DXIL_ABI` block for the reason the pre-pass family does: their root
// signatures in `post/rt_reflections.rs` and `glass.rs` hand the same
// declarations entirely different slots than the Metal and Vulkan hosts do, and
// `assert_slang_dxil_abi` in build.rs locks every one of them. No `POOL_SIZE`:
// the DXIL pool is an unbounded array, as it is for the bindless main pass.
//
// The three ray-query entries are `*_6_5`, above the 6.0 floor the rest of the
// single-source shaders compile at: `RayQuery` is an SM 6.5 construct. Nothing
// else here needs it, so the glass vertex and the base fragment stay at 6.0.
//
// `USE_MSAA` is a host difference rather than a target one -- the glass fragment
// declares its depth source by the main pass's sample count -- so each glass
// fragment comes as a pair the way the fog fragment does, and the caller picks
// by MSAA state. The vertex stage reads no depth and takes neither.
pub(super) static RT_REFLECTIONS_FRAG: SlangProgram = SlangProgram {
    file: "rt_reflections.slang",
    embedded: RT_REFLECTIONS_SLANG,
    entry: "rt_reflections_fragment",
    profile: "ps_6_5",
    label: "rt_reflections.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8")],
};
pub(super) static RT_REFLECTIONS_FRAG_TEXTURED: SlangProgram = SlangProgram {
    file: "rt_reflections.slang",
    embedded: RT_REFLECTIONS_SLANG,
    entry: "rt_reflections_fragment",
    profile: "ps_6_5",
    label: "rt_reflections_textured.slang",
    defines: &[("DXIL_ABI", "1"), ("RT_TEXTURED", "1"), ("MAX_PROBES", "8")],
};

// One vertex stage for both glass pipelines: the base pass and the ray-traced
// one differ only in where the reflection comes from, and both root signatures
// put the transparent view CBV at b0.
pub(super) static GLASS_VERT: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_vertex",
    profile: "vs_6_0",
    label: "glass_vert.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8")],
};
pub(super) static GLASS_FRAG: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_fragment",
    profile: "ps_6_0",
    label: "glass_frag.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "0")],
};
pub(super) static GLASS_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_fragment",
    profile: "ps_6_0",
    label: "glass_frag_msaa.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "1")],
};
pub(super) static GLASS_RT_FRAG: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_rt_fragment",
    profile: "ps_6_5",
    label: "glass_frag_rt.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("GLASS_RT", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "0"),
    ],
};
pub(super) static GLASS_RT_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_rt_fragment",
    profile: "ps_6_5",
    label: "glass_frag_rt_msaa.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("GLASS_RT", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "1"),
    ],
};
pub(super) static GLASS_RT_FRAG_TEXTURED: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_rt_fragment",
    profile: "ps_6_5",
    label: "glass_frag_rt_textured.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("GLASS_RT", "1"),
        ("RT_TEXTURED", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "0"),
    ],
};
pub(super) static GLASS_RT_FRAG_TEXTURED_MSAA: SlangProgram = SlangProgram {
    file: "glass.slang",
    embedded: GLASS_SLANG,
    entry: "glass_rt_fragment",
    profile: "ps_6_5",
    label: "glass_frag_rt_textured_msaa.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("GLASS_RT", "1"),
        ("RT_TEXTURED", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "1"),
    ],
};

const GLASS_MESH_DEFINES: &[(&str, &str)] =
    &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "0")];
const GLASS_MESH_MSAA_DEFINES: &[(&str, &str)] =
    &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "1")];
const GLASS_MESH_TEXTURED_DEFINES: &[(&str, &str)] = &[
    ("DXIL_ABI", "1"),
    ("RT_TEXTURED", "1"),
    ("MAX_PROBES", "8"),
    ("USE_MSAA", "0"),
];
const GLASS_MESH_TEXTURED_MSAA_DEFINES: &[(&str, &str)] = &[
    ("DXIL_ABI", "1"),
    ("RT_TEXTURED", "1"),
    ("MAX_PROBES", "8"),
    ("USE_MSAA", "1"),
];

// The see-through glass MESH family, the transparent pass's third producer.
// Ray-traced only -- the per-pixel trace is what makes the mesh see-through
// rather than the opaque reflective glass the main pass draws -- so there is no
// base pair, only the MSAA x hit-shading matrix at SM 6.5. Its vertex stage is
// its own (it applies the per-draw model matrix) but shares b0/b1 with the rest
// of the pass.
pub(super) static GLASS_MESH_VERT: SlangProgram = SlangProgram {
    file: "glass_mesh.slang",
    embedded: GLASS_MESH_SLANG,
    entry: "glass_mesh_vertex",
    profile: "vs_6_0",
    label: "glass_mesh_vert.slang",
    defines: GLASS_MESH_DEFINES,
};

pub(super) static GLASS_MESH_RT_FRAG: SlangProgram = SlangProgram {
    file: "glass_mesh.slang",
    embedded: GLASS_MESH_SLANG,
    entry: "glass_mesh_rt_fragment",
    profile: "ps_6_5",
    label: "glass_mesh_frag_rt.slang",
    defines: GLASS_MESH_DEFINES,
};

pub(super) static GLASS_MESH_RT_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "glass_mesh.slang",
    embedded: GLASS_MESH_SLANG,
    entry: "glass_mesh_rt_fragment",
    profile: "ps_6_5",
    label: "glass_mesh_frag_rt_msaa.slang",
    defines: GLASS_MESH_MSAA_DEFINES,
};

pub(super) static GLASS_MESH_RT_FRAG_TEXTURED: SlangProgram = SlangProgram {
    file: "glass_mesh.slang",
    embedded: GLASS_MESH_SLANG,
    entry: "glass_mesh_rt_fragment",
    profile: "ps_6_5",
    label: "glass_mesh_frag_rt_textured.slang",
    defines: GLASS_MESH_TEXTURED_DEFINES,
};

pub(super) static GLASS_MESH_RT_FRAG_TEXTURED_MSAA: SlangProgram = SlangProgram {
    file: "glass_mesh.slang",
    embedded: GLASS_MESH_SLANG,
    entry: "glass_mesh_rt_fragment",
    profile: "ps_6_5",
    label: "glass_mesh_frag_rt_textured_msaa.slang",
    defines: GLASS_MESH_TEXTURED_MSAA_DEFINES,
};

// The water surface family, the transparent pass's other producer. Same shape as
// the glass table above -- one vertex stage for every pipeline, an MSAA pair of
// base fragments, and the two ray-traced fragments at shader model 6.5 -- and
// deliberately the same registers, so `transparent.rs` builds one root signature
// per path and both producers draw under it.
pub(super) static WATER_VERT: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_vertex",
    profile: "vs_6_0",
    label: "water_vert.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8")],
};
pub(super) static WATER_FRAG: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_fragment",
    profile: "ps_6_0",
    label: "water_frag.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "0")],
};
pub(super) static WATER_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_fragment",
    profile: "ps_6_0",
    label: "water_frag_msaa.slang",
    defines: &[("DXIL_ABI", "1"), ("MAX_PROBES", "8"), ("USE_MSAA", "1")],
};
pub(super) static WATER_RT_FRAG: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_rt_fragment",
    profile: "ps_6_5",
    label: "water_frag_rt.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("WATER_RT", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "0"),
    ],
};
pub(super) static WATER_RT_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_rt_fragment",
    profile: "ps_6_5",
    label: "water_frag_rt_msaa.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("WATER_RT", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "1"),
    ],
};
pub(super) static WATER_RT_FRAG_TEXTURED: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_rt_fragment",
    profile: "ps_6_5",
    label: "water_frag_rt_textured.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("WATER_RT", "1"),
        ("RT_TEXTURED", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "0"),
    ],
};
pub(super) static WATER_RT_FRAG_TEXTURED_MSAA: SlangProgram = SlangProgram {
    file: "water.slang",
    embedded: WATER_SLANG,
    entry: "water_rt_fragment",
    profile: "ps_6_5",
    label: "water_frag_rt_textured_msaa.slang",
    defines: &[
        ("DXIL_ABI", "1"),
        ("WATER_RT", "1"),
        ("RT_TEXTURED", "1"),
        ("MAX_PROBES", "8"),
        ("USE_MSAA", "1"),
    ],
};

// The remaining raster families: the particle billboard pair, the projected
// decal, world-space lines and the text / sprite overlay. Each has real vertex
// geometry, so unlike the post passes they keep their own vertex entry rather
// than pairing with `fullscreen.slang`.
//
// Only the particle pair takes an ABI block, and only to swap two constant
// buffers: its root signature in `particle.rs` binds the view at b0 and the
// per-emitter params at b1, where the Metal buffer indices are 1 and 2. Decal,
// line and text need none -- declaration order already lands each resource on
// the register its root signature declares, which the rows in build.rs's
// `SLANG_DXIL_ENTRY_ABI` pin so a slangc release cannot move one silently.
//
// The two depth-reading fragments come as MSAA pairs the way the fog and glass
// fragments do: the sample count is a host difference, so the caller picks by
// MSAA state and the export-time precompile leaves a bundle warm for either.
// Their vertex stages never name the depth source and take neither.
const PARTICLE_ABI: &[(&str, &str)] = &[("DXIL_ABI", "1")];

pub(super) static PARTICLE_VERT: SlangProgram = SlangProgram {
    file: "particle.slang",
    embedded: PARTICLE_SLANG,
    entry: "particle_vertex",
    profile: "vs_6_0",
    label: "particle_vert.slang",
    defines: PARTICLE_ABI,
};
pub(super) static PARTICLE_FRAG: SlangProgram = SlangProgram {
    file: "particle.slang",
    embedded: PARTICLE_SLANG,
    entry: "particle_fragment",
    profile: "ps_6_0",
    label: "particle_frag.slang",
    defines: PARTICLE_ABI,
};
pub(super) static DECAL_VERT: SlangProgram = SlangProgram {
    file: "decal.slang",
    embedded: DECAL_SLANG,
    entry: "decal_vertex",
    profile: "vs_6_0",
    label: "decal_vert.slang",
    defines: &[],
};
pub(super) static DECAL_FRAG: SlangProgram = SlangProgram {
    file: "decal.slang",
    embedded: DECAL_SLANG,
    entry: "decal_fragment",
    profile: "ps_6_0",
    label: "decal_frag.slang",
    defines: &[("USE_MSAA", "0")],
};
pub(super) static DECAL_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "decal.slang",
    embedded: DECAL_SLANG,
    entry: "decal_fragment",
    profile: "ps_6_0",
    label: "decal_frag_msaa.slang",
    defines: &[("USE_MSAA", "1")],
};
pub(super) static LINE_VERT: SlangProgram = SlangProgram {
    file: "line.slang",
    embedded: LINE_SLANG,
    entry: "line_vertex",
    profile: "vs_6_0",
    label: "line_vert.slang",
    defines: &[],
};
pub(super) static LINE_FRAG: SlangProgram = SlangProgram {
    file: "line.slang",
    embedded: LINE_SLANG,
    entry: "line_fragment",
    profile: "ps_6_0",
    label: "line_frag.slang",
    defines: &[("USE_MSAA", "0")],
};
pub(super) static LINE_FRAG_MSAA: SlangProgram = SlangProgram {
    file: "line.slang",
    embedded: LINE_SLANG,
    entry: "line_fragment",
    profile: "ps_6_0",
    label: "line_frag_msaa.slang",
    defines: &[("USE_MSAA", "1")],
};
pub(super) static TEXT_VERT: SlangProgram = SlangProgram {
    file: "text.slang",
    embedded: TEXT_SLANG,
    entry: "text_vertex_main",
    profile: "vs_6_0",
    label: "text_vert.slang",
    defines: &[],
};
pub(super) static TEXT_FRAG: SlangProgram = SlangProgram {
    file: "text.slang",
    embedded: TEXT_SLANG,
    entry: "text_fragment_main",
    profile: "ps_6_0",
    label: "text_frag.slang",
    defines: &[],
};

// Every declared program, iterated by the export-time precompile. Both Hi-Z
// init variants are enumerated, and both MSAA halves of every fragment that has
// them: which one a device runs depends on its MSAA mode, and a bundle should
// be warm for either.
pub(crate) static ALL: &[&SlangProgram] = &[
    &MAIN_BINDLESS_VERT,
    &MAIN_BINDLESS_FRAG,
    &LIGHT_CULL,
    &RT_SKIN,
    &HIZ_INIT_SINGLE,
    &HIZ_INIT_MSAA,
    &HIZ_DOWNSAMPLE,
    &GBUFFER_PREPASS_VERT,
    &GBUFFER_PREPASS_VERT_INSTANCED,
    &GBUFFER_PREPASS_VERT_SKINNED,
    &GBUFFER_BINDLESS_VERT,
    &GBUFFER_PREPASS_FRAG,
    &GBUFFER_BINDLESS_FRAG,
    &SHADOW_VERT,
    &SKINNED_SHADOW_VERT,
    &SHADOW_BINDLESS_VERT,
    &FOG_FROXEL,
    &FOG_FRAG,
    &FOG_FRAG_MSAA,
    &AUTO_EXPOSURE_BUILD,
    &AUTO_EXPOSURE_AVERAGE,
    &PARTICLE_SIMULATE,
    &FULLSCREEN_VERT,
    &TAA_FRAG,
    &BLOOM_PREFILTER,
    &BLOOM_DOWNSAMPLE,
    &BLOOM_UPSAMPLE,
    &COMPOSITE_FRAG,
    &SSAO_KERNEL,
    &SSAO_BLUR,
    &SSR_RESOLVE,
    &SSGI_GATHER,
    &SSGI_COMPOSITE,
    &REFLECTION_BLUR,
    &REFLECTION_COMPOSITE,
    &RT_REFLECTIONS_FRAG,
    &RT_REFLECTIONS_FRAG_TEXTURED,
    &GLASS_VERT,
    &GLASS_FRAG,
    &GLASS_FRAG_MSAA,
    &GLASS_RT_FRAG,
    &GLASS_RT_FRAG_MSAA,
    &GLASS_RT_FRAG_TEXTURED,
    &GLASS_RT_FRAG_TEXTURED_MSAA,
    &GLASS_MESH_VERT,
    &GLASS_MESH_RT_FRAG,
    &GLASS_MESH_RT_FRAG_MSAA,
    &GLASS_MESH_RT_FRAG_TEXTURED,
    &GLASS_MESH_RT_FRAG_TEXTURED_MSAA,
    &WATER_VERT,
    &WATER_FRAG,
    &WATER_FRAG_MSAA,
    &WATER_RT_FRAG,
    &WATER_RT_FRAG_MSAA,
    &WATER_RT_FRAG_TEXTURED,
    &WATER_RT_FRAG_TEXTURED_MSAA,
    &PARTICLE_VERT,
    &PARTICLE_FRAG,
    &DECAL_VERT,
    &DECAL_FRAG,
    &DECAL_FRAG_MSAA,
    &LINE_VERT,
    &LINE_FRAG,
    &LINE_FRAG_MSAA,
    &TEXT_VERT,
    &TEXT_FRAG,
];

impl SlangProgram {
    // Assemble the exact source text this program compiles.
    pub(crate) fn source(&self, hot_reload: bool) -> String {
        crate::slang_source::assemble(hot_reload, self.file, self.embedded, self.defines)
    }

    fn target(&self) -> slang::SlangTarget {
        slang::SlangTarget::Dxil(self.profile)
    }

    // The shader-cache key for `source`. Shared by the runtime compile path
    // and the export-time precompile so the two can never key differently.
    pub(crate) fn cache_key<'a>(&self, source: &'a str) -> crate::shader_cache::Key<'a> {
        crate::shader_cache::Key {
            compiler: "slang",
            source,
            entry: self.entry,
            target: self.profile,
            options: 0,
        }
    }

    // Compile to DXIL, reusing a cached artifact when this exact assembled
    // source has been compiled before.
    pub(crate) fn compile(&self, hot_reload: bool) -> Result<Vec<u8>, String> {
        let source = self.source(hot_reload);
        let key = self.cache_key(&source);
        crate::shader_cache::cached(&key, self.label, || compile_uncached(self, &source))
    }
}

pub(super) fn compile_uncached(program: &SlangProgram, source: &str) -> Result<Vec<u8>, String> {
    let job = slang::SlangJob {
        source,
        file_name: program.file,
        entries: &[program.entry],
        target: program.target(),
    };
    slang::compile(&job, &crate::shader_cache::slang_work_dir())
}

// Compile every declared program into `out_dir`, reusing local cache artifacts
// where present. Called by the export-time precompile alongside the HLSL table.
pub(crate) fn precompile(out_dir: &std::path::Path, report: &mut crate::precompile::Report) {
    for program in ALL {
        let source = program.source(false);
        let key = program.cache_key(&source);
        report.record(
            &format!("{} {}", program.entry, program.profile),
            crate::shader_cache::ensure_in(out_dir, &key, || compile_uncached(program, &source)),
        );
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn variant_gates_and_abi_define_lead_the_source() {
        assert!(
            MAIN_BINDLESS_FRAG
                .source(false)
                .starts_with("#define DXIL_ABI 1\n#define MAX_PROBES 8\n")
        );
        assert!(
            HIZ_INIT_MSAA
                .source(false)
                .starts_with("#define HIZ_INIT_MSAA 1\n")
        );
        // The SSR resolve reads the probe array but none of the texture pool.
        assert!(
            SSR_RESOLVE
                .source(false)
                .starts_with("#define MAX_PROBES 8\n")
        );
        assert!(!LIGHT_CULL.source(false).starts_with("#define"));
    }

    // An unreplaced `{...}` fragment marker would reach slangc as a syntax
    // error at renderer init; catch a missing splice here instead.
    #[test]
    fn every_program_assembles_with_its_fragments_spliced() {
        for p in ALL {
            let src = p.source(false);
            for marker in [
                "{POST_COMMON}",
                "{OBJECT_COMMON}",
                "{PROBE_TYPES}",
                "{PROBE_COMMON}",
                "{RT_TYPES}",
                "{RT_TRACE}",
                "{PARTICLE_TYPES}",
            ] {
                assert!(
                    !src.contains(marker),
                    "{}: unspliced fragment marker {marker}",
                    p.label
                );
            }
        }
    }

    // The pre-pass rasterises the same visible set the main pass does, sky
    // shell included, and the shell's corners fall outside the far plane, so
    // an unpinned sky vert clips and the G-buffer loses coverage the main pass
    // has. Two entries can carry skybox geometry -- the per-draw static one and
    // the GPU-driven one -- and both must call the pin. The instanced and
    // skinned entries are excluded: neither ever carries skybox geometry.
    #[test]
    fn the_prepass_pins_sky_to_the_far_plane() {
        assert!(GBUFFER_PREPASS_SLANG.contains("color.b > 1.5"));
        assert!(GBUFFER_PREPASS_SLANG.contains("position.z = position.w"));
        assert_eq!(GBUFFER_PREPASS_SLANG.matches("gb_sky_pin(").count(), 3);
    }

    // Two programs collide when they would compile identical source with the
    // same entry and profile; the table must not declare the same artifact twice.
    #[test]
    fn table_has_no_duplicate_programs() {
        let mut seen = std::collections::HashSet::new();
        for p in ALL {
            assert!(
                seen.insert((p.source(false), p.entry, p.profile)),
                "duplicate program: {}",
                p.label
            );
        }
    }

    // The key must carry the fields that separate one program's artifact from
    // another's: the slang toolchain, the entry, and the stage profile.
    #[test]
    fn the_cache_key_tracks_the_program() {
        let src = MAIN_BINDLESS_VERT.source(false);
        let key = MAIN_BINDLESS_VERT.cache_key(&src);
        assert_eq!(key.compiler, "slang");
        assert_eq!(key.entry, "vertex_main_bindless");
        assert_eq!(key.target, "vs_6_0");
        assert_eq!(MAIN_BINDLESS_FRAG.cache_key(&src).target, "ps_6_0");
    }

    // Every probe cube array must be exactly as long as the descriptor table
    // its root signature binds, or a probe sample reads past it. Scanned over
    // the whole table rather than a listed few, so a new program that bakes the
    // count in cannot bake in the wrong one.
    #[test]
    fn probe_cube_count_matches_the_host_constant() {
        let want = concinnity_render::uniforms::MAX_PROBES.to_string();
        let mut sized = 0usize;
        for p in ALL {
            for (key, value) in p.defines {
                if *key == "MAX_PROBES" {
                    assert_eq!(*value, want.as_str(), "{}", p.label);
                    sized += 1;
                }
            }
        }
        assert!(sized > 0, "no program bakes MAX_PROBES in");
    }

    // The reflection-cut constant in every single-source fragment that gates on
    // it must track the canonical Rust value: the SSR resolve, the composite
    // blur, and the forward pass all decide "does this surface reflect" from it
    // and cannot disagree. The Metal table asserts the same thing, but that
    // module does not build on a DirectX host.
    #[test]
    fn reflection_roughness_cut_matches_canonical() {
        let expected = format!(
            "static const float REFLECTION_ROUGHNESS_CUT = {:?};",
            crate::gfx::ssr::REFLECTION_ROUGHNESS_CUT
        );
        for (name, src) in [
            ("main_bindless.slang", MAIN_BINDLESS_SLANG),
            ("ssr.slang", SSR_SLANG),
            ("reflection.slang", REFLECTION_SLANG),
            ("rt_reflections.slang", RT_REFLECTIONS_SLANG),
        ] {
            assert!(
                src.contains(&expected),
                "{name} REFLECTION_ROUGHNESS_CUT drifted from \
                 concinnity_core::gfx::ssr::REFLECTION_ROUGHNESS_CUT"
            );
        }
    }

    // The single-source files carry cluster constants that must track the Rust
    // values the CPU sizes buffers with.
    #[test]
    fn cluster_constants_match_render_types() {
        use crate::gfx::render_types::{CLUSTER_LIGHT_LIST_STRIDE, MAX_LIGHTS_PER_CLUSTER};
        for src in [LIGHT_CULL_SLANG, MAIN_BINDLESS_SLANG] {
            assert!(src.contains(&format!(
                "CLUSTER_LIGHT_LIST_STRIDE = {CLUSTER_LIGHT_LIST_STRIDE}u"
            )));
        }
        assert!(LIGHT_CULL_SLANG.contains(&format!(
            "MAX_LIGHTS_PER_CLUSTER = {MAX_LIGHTS_PER_CLUSTER}u"
        )));
    }

    // The sky shell's half-extent tracks the camera far plane, so its corners
    // always fall outside it: the bindless vertex path must pin sky verts to the
    // far plane or those corners clip and the clear colour shows through.
    #[test]
    fn the_bindless_vertex_path_pins_sky_to_the_far_plane() {
        assert!(MAIN_BINDLESS_SLANG.contains("v.color.b > 1.5"));
        assert!(MAIN_BINDLESS_SLANG.contains("o.position.z = o.position.w"));
    }
}