-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
2638 lines (2480 loc) · 131 KB
/
Copy pathCMakeLists.txt
File metadata and controls
2638 lines (2480 loc) · 131 KB
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
# ============================================================================
# WhiteoutFlakes — standalone renderer + basic_viewer tool.
# ============================================================================
cmake_minimum_required(VERSION 3.20)
project(WhiteoutFlakes LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ---- Emscripten / WebAssembly target ----
# Configured via `emcmake cmake ...`. The web build is a lean subset:
# WebGPU only, no desktop windowing/audio/UI, no native game archives.
# Every gating decision below keys off EMSCRIPTEN; the desktop build is
# unaffected.
if(EMSCRIPTEN)
set(WDX_ENABLE_TRACY OFF CACHE BOOL "" FORCE) # no web transport
set(WDX_ENABLE_IMGUI OFF CACHE BOOL "" FORCE) # JS owns all UI chrome
set(WDX_ENABLE_WEBGPU ON CACHE BOOL "" FORCE) # only web backend
set(WDX_ENABLE_WEBP OFF CACHE BOOL "" FORCE) # viewer-only export
# Exceptions: -fno-exceptions everywhere. The renderer doesn't throw
# and WhiteoutLib has been adjusted to compile without `throw` under
# Emscripten — so there's no reason to ship EH machinery. This is
# what avoids the Chrome wasm-compile freeze we hit with both
# -fexceptions (JS-trampolined invoke_*) and -fwasm-exceptions
# (native try_table) — both emit code Chrome's wasm compiler stalls
# on for >60 s, while the equivalent EH-free wasm compiles in ms.
add_compile_options(-fno-exceptions)
add_link_options(-fno-exceptions)
# Compile-time: -O2 for better per-function codegen quality (register
# allocation, CSE, loop opts, constant propagation). Link-time: -Oz
# to keep the wasm binary small via wasm-opt. The Chrome V8 freeze we
# used to hit was caused by *huge inlined functions* (50k+ wasm
# instructions per func, e.g. PIMPL ctors absorbing their whole
# subsystem graph) tipping V8 into synchronous TurboFan — that's
# already blocked by `-fno-inline-functions` + `-fno-lto`, which we
# keep. With those guards in place, -O2 produces faster code without
# creating the giant functions V8 chokes on.
#
# Was -Oz globally; the Firefox profile showed 73% of frame time in
# our WASM (Firefox WGPU/SpiderMonkey is more sensitive to AOT code
# quality than Chrome/V8, which JIT-optimizes hot paths at run time).
# Lifting compile -O to O2 closes a meaningful chunk of the gap.
#
# Flags retained:
# -fno-lto : no cross-TU inlining at link time
# -fno-inline-functions: no intra-TU inlining of large funcs
# Combined with `-O2`, individual function sizes stay manageable.
add_compile_options(-O2 -fno-lto -fno-inline-functions)
add_link_options(-Oz -fno-lto)
message(STATUS "WhiteoutFlakes: Emscripten/WebAssembly build "
"(no exceptions, compile -O2 / link -Oz, no inlining/LTO)")
endif()
# Disable vcpkg's user-wide MSBuild integration (`vcpkg integrate install`)
# for every generated .vcxproj. WhiteoutFlakes pulls all its dependencies via
# FetchContent / add_subdirectory and uses no vcpkg toolchain or manifest, but
# a machine-wide vcpkg integration would otherwise auto-link every installed
# vcpkg package into our binaries — e.g. silently importing vcpkg's shared
# libwebp.dll alongside our own statically-built libwebp. Emitted into the
# Globals PropertyGroup, which vcpkg.user.targets honours. (VS generator only;
# harmless elsewhere, where the integration does not apply anyway.)
set(CMAKE_VS_GLOBALS "VcpkgEnabled=false")
# Pull in WhiteoutLib (provides whiteout_lib; optionally whiteout_casc, whiteout_mpq).
# CASC/MPQ are native file-I/O + threading — disabled under Emscripten; the web
# build receives bytes from JS via FetchContentProvider instead.
if(EMSCRIPTEN)
set(WHITEOUT_ENABLE_CASC OFF CACHE BOOL "Enable CASC archive support" FORCE)
set(WHITEOUT_ENABLE_MPQ OFF CACHE BOOL "Enable MPQ archive support" FORCE)
# WhiteoutLib auto-enables embind bindings under EMSCRIPTEN. Those
# bindings register every public C++ class/method into JS via a
# massive static-init constructor — easily 40k+ wasm instructions in
# a single function, which trips V8's synchronous-compile fallback
# and freezes the page. We have our own `wf_*` C facade and never
# call into JS-bound WhiteoutLib symbols, so the bindings are pure
# dead weight here.
set(WHITEOUT_BUILD_WASM_BINDINGS OFF CACHE BOOL "" FORCE)
else()
set(WHITEOUT_ENABLE_CASC ON CACHE BOOL "Enable CASC archive support" FORCE)
set(WHITEOUT_ENABLE_MPQ ON CACHE BOOL "Enable MPQ archive support" FORCE)
endif()
# DBC / DB2. Pure parsing over bytes the content provider hands it, so unlike
# CASC/MPQ it costs the web build nothing to keep on. World of Warcraft's
# replaceable textures are read out of these; see WowReplaceableTextures.
set(WHITEOUT_ENABLE_DATABASE ON CACHE BOOL "Enable WoW client database support" FORCE)
# Skip adding the bundled WhiteoutLib if the parent project has already
# provided the `whiteout_lib` target (e.g. the WhiteoutDex monorepo pins
# its own WhiteoutLib submodule and pulls it in before this subdir, so
# every plugin shares one copy). When standalone, pull in the bundled
# nested submodule as usual.
if(NOT TARGET whiteout_lib)
add_subdirectory(externals/WhiteoutLib)
endif()
# Tracy — opt-in CPU + GPU profiler. When WDX_ENABLE_TRACY is ON, the
# Tracy::TracyClient target is built and TRACY_ENABLE is defined for
# everyone linking it; otherwise every TracyVk*/ZoneScoped macro expands
# to nothing and there's zero runtime cost. TRACY_ON_DEMAND keeps the
# client buffering minimal until Tracy.exe connects.
# World of Warcraft `.m2` and StarCraft II / Heroes `.m3`.
#
# ON so the standalone viewer can open them from File > Open — which is the
# only reason the default changed; REFACTOR_PLAN.md P9/P10 landed them OFF on
# the grounds that a release viewer shouldn't carry a half-implemented format.
# That caveat still holds and is worth repeating: **both load geometry only**.
# No bones, no textures, no materials, no animation — a model draws as a flat
# untextured silhouette. Turn them off for a build that should not offer that.
#
# Warcraft III rendering is byte-identical either way (G1/G2 gated in both
# configurations), so this costs compile time and nothing else. CI has no `.m2`
# or `.m3` assets, so the tests that use them skip rather than fail.
option(WDX_ENABLE_M2 "Enable World of Warcraft .m2 loading (geometry only)" ON)
option(WDX_ENABLE_M3 "Enable StarCraft II / Heroes .m3 loading (geometry only)" ON)
# Diablo III actors. Unlike the two above, nothing extra has to be enabled
# upstream: WhiteoutLib builds sno/d3/native and textures/tex into its core
# target unconditionally, so this option only gates our own sources.
option(WDX_ENABLE_D3 "Enable Diablo III actor loading" ON)
# Rigid-body physics, driven by Snowball — the re-implementation of Blizzard's
# Domino engine, vendored under src/renderer/physics/snowball. Both games that
# ship Domino data are covered: WoW's `.m2` cloth and tassels (`.phys`/PFDC) and
# StarCraft II's `.m3` rigid bodies and death ragdolls (PHRB/PHYJ). Needs at
# least one of WDX_ENABLE_M2 / WDX_ENABLE_M3, since physics reaches us only
# through a model format.
option(WDX_ENABLE_PHYSICS "Enable rigid-body simulation (needs Snowball)" ON)
option(WDX_ENABLE_TRACY "Enable Tracy profiler (CPU + Vulkan GPU)" ON)
if(WDX_ENABLE_TRACY AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/externals/tracy/CMakeLists.txt")
set(TRACY_ENABLE ON CACHE BOOL "" FORCE)
set(TRACY_ON_DEMAND ON CACHE BOOL "" FORCE)
set(TRACY_NO_FRAME_IMAGE ON CACHE BOOL "" FORCE)
add_subdirectory(externals/tracy)
set(WDX_TRACY_LIB Tracy::TracyClient)
message(STATUS "Tracy: enabled (TRACY_ENABLE + TRACY_ON_DEMAND)")
else()
set(WDX_TRACY_LIB "")
if(WDX_ENABLE_TRACY)
message(WARNING "WDX_ENABLE_TRACY=ON but externals/tracy is missing. "
"Run: git submodule update --init externals/tracy")
endif()
endif()
# cornflakes is folded directly into WhiteoutFlakesLib as a renderer module
# the cornflakes determinism + warnings INTERFACE targets the upstream project
# defines are replaced by inline compile flags on WhiteoutFlakesLib.
set(CORNFLAKES_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/renderer/corn_effects/cornflakes")
set(CORNFLAKES_SOURCES
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/version.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/core/arena.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/diagnostics/issue.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/diagnostics/frame_trace.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/scheduler/serial_worker_pool.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/service/cornflakes_service.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/asset_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/pkb_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/pkmm_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/pkvf_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/file_mesh_provider.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/text_pkfx_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/war3_compatibility_validator.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/object_accessors.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/asset/field_defs_generated.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/effect_binder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/program_binder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/renderer_binder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/sampler_binder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/external_binding.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/ir_to_cbem_lowerer.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/sampler_resource.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/binding/spatial_layer_resource.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/bytecode_trace.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/cbem/cbem_interpreter.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/cbem/cbem_ir_ops.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/cbem/cbem_dispatchers.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/math_functions.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/vm/bytecode_decoder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/mesh.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/shape_geometry.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/shape.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/curve.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/curve_cdf.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/texture.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/turbulence.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sampler/vector_field.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/particle_page.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/spawn_processor.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/spawn_evaluator_driver.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/evolve_page_task.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/simulation_runtime.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/layer_tick_harness.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/particle_pool.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/effect_runtime.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/state_digest.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/state_compare.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/sim/lod.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/layer_stream_store.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/scratch_validator.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/register_census.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/packet_register_file.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/stream_extract.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/simt/simt_interpreter.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/events/payload_cache_store.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/events/payload_builder.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/events/event_generator.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/events/event_router.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/events/kick_processor.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/semantic_slot_reader.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/renderer_class_bucket.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/render_extractor.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/pool_extractor.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/ribbon_geometry.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/shader_perm.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/render/instance_stream.cpp"
"${CORNFLAKES_MODULE_DIR}/internal/cornflakes/validation/batch_resource_tracker.cpp"
)
# ============================================================================
# Slang shader compilation (compile-time: .slang → DXBC → embedded C++ header)
# ============================================================================
set(SHADER_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/renderer/shaders")
set(SHADER_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders")
file(MAKE_DIRECTORY "${SHADER_OUT_DIR}")
find_program(SLANGC slangc
HINTS "${SLANG_DIR}/bin" "$ENV{SLANG_DIR}/bin"
DOC "Path to Slang compiler (slangc)")
if(NOT SLANGC)
message(FATAL_ERROR
"slangc not found. Install the Slang SDK from https://github.com/shader-slang/slang/releases "
"and set -DSLANG_DIR=<path-to-slang-sdk> or add slangc to PATH.")
endif()
message(STATUS "Using slangc (default): ${SLANGC}")
# Optional override for the Vulkan-target slangc. Some upstream slang
# bugs (e.g. `Conditional<>` + SPIR-V specialise emit) are fixed in
# tip-of-tree slang but not in the Vulkan SDK build, while the SDK
# slangc still emits cleaner DXIL than tip — pass
# -DSLANGC_VULKAN=<path-to-newer-slangc.exe> to use the newer build
# for SPIR-V only, and keep the SDK slangc for d3d11 / d3d12.
if(NOT DEFINED SLANGC_VULKAN OR SLANGC_VULKAN STREQUAL "")
set(SLANGC_VULKAN "${SLANGC}"
CACHE FILEPATH "slangc used for the Vulkan (SPIR-V) target. Defaults to SLANGC.")
endif()
message(STATUS "Using slangc (vulkan): ${SLANGC_VULKAN}")
# Common Slang flags: column-major matrices (matches C++ transpose-before-upload convention)
# Use DXC as the downstream compiler instead of FXC for DXBC output
set(SLANG_COMMON_FLAGS -matrix-layout-column-major -I "${SHADER_SRC_DIR}"
-default-downstream-compiler hlsl dxc)
# Shader entry points: <slang_file> <entry> <stage> <output_name>
# Only line.slang (debug wires), blit.slang and framebuffer_capture.slang
# remain as Slang sources; every MDX-material draw goes through BLS, and the
# tonemap pass uses the engine's sprite.bls VS directly.
set(SHADER_ENTRIES
"line.slang|vsLine|vertex|kLineVS"
"line.slang|psLine|fragment|kLinePS"
"blit.slang|vsBlit|vertex|kBlitVS"
"blit.slang|psBlit|fragment|kBlitPS"
"framebuffer_capture.slang|csCapture|compute|kCaptureCS"
# UnlitShading — position-only, flat white. An IShadingModel of its own
# (not a BLS program), so it lives here rather than in a .bls bundle.
"unlit.slang|vsUnlit|vertex|kUnlitVS"
"unlit.slang|psUnlit|fragment|kUnlitPS"
# Lit permutations: POSITION+NORMAL, selected by the profile's
# UnlitLighting(). They exist to make a MeshBuffer's layout description
# checkable — flat white cannot tell a right normal from a missing one.
"unlit.slang|vsUnlitLit|vertex|kUnlitLitVS"
"unlit.slang|psUnlitLambert|fragment|kUnlitLambertPS"
"unlit.slang|psUnlitBlinnPhong|fragment|kUnlitBlinnPhongPS"
# Skinned permutations. Same pixel shaders; the vertex side poses the
# geometry from a bone palette, reading BLENDWEIGHT/BLENDINDICES out of the
# same interleaved buffer that carries position — which is how `.m3` ships
# them, so nothing is decoded or duplicated to get here.
"unlit.slang|vsUnlitSkinned|vertex|kUnlitSkinnedVS"
"unlit.slang|vsUnlitSkinnedLit|vertex|kUnlitSkinnedLitVS"
# GTAO ambient-occlusion pass — read by GtaoService. The same
# vsGtao fullscreen-triangle VS feeds both the main pass (writes
# the AO buffer) and the apply pass (modulates the HDR scene
# colour in place via loadOp=Load + DST*SRC blend).
"gtao.slang|vsGtao|vertex|kGtaoVS"
"gtao.slang|gtao_main_low_ps|fragment|kGtaoMainLowPS"
"gtao.slang|gtao_main_ps|fragment|kGtaoMainPS"
"gtao.slang|gtao_main_high_ps|fragment|kGtaoMainHighPS"
"gtao.slang|gtao_denoise_ps|fragment|kGtaoDenoisePS"
"gtao.slang|gtao_temporal_ps|fragment|kGtaoTemporalPS"
"gtao.slang|gtao_depth_copy_ps|fragment|kGtaoDepthCopyPS"
"gtao.slang|gtao_ibl_boost_ps|fragment|kGtaoIblBoostPS"
"gtao.slang|gtao_apply_ps|fragment|kGtaoApplyPS"
# Bloom Gaussian blur (post-process). PostProcessService runs this
# twice per frame (horizontal, then vertical) between BloomExtract
# and BloomCombine. Renderer-internal — Wc3Shaders doesn't author a
# blur source, so we ship our own embedded copy rather than relying
# on the engine's shipped gaussianblur.bls being staged.
"gaussian_blur.slang|vsBlur|vertex|kGaussianBlurVS"
"gaussian_blur.slang|psBlur|fragment|kGaussianBlurPS"
# ImGui colour-space-converting image draws. The retail imgui.bls permute
# set is fixed (differentially tested against the shipped game), so the
# mismatched-texture half of the colour-space matrix — a UNORM thumbnail
# on an sRGB RTV, an sRGB texture on a UNORM RTV — ships as engine
# entries that ImGuiRenderer swaps to per draw.
"imgui_convert.slang|vsImGuiConvert|vertex|kImGuiConvertVS"
"imgui_convert.slang|psImGuiToLinear|fragment|kImGuiToLinearPS"
"imgui_convert.slang|psImGuiToDisplay|fragment|kImGuiToDisplayPS"
# WoW refraction particles (RefractionService). Two passes: the emitters'
# quads into a scalar distortion mask, then a full-screen pass that bends
# the finished scene through it. Transcribed from the retail `refraction`
# and `refractionapply` shaders — see M2_REFRACTION_DESIGN.md.
"refraction_mask.slang|vsRefractParticle|vertex|kRefractParticleVS"
"refraction_mask.slang|psRefractParticle|fragment|kRefractParticlePS"
"refraction_apply.slang|vsRefractApply|vertex|kRefractApplyVS"
"refraction_apply.slang|psRefractApply|fragment|kRefractApplyPS"
# Diablo III screen-space distortion (DistortionService). Only the RESOLVE
# is a shader of its own — the buffer is written by the ordinary D3 programs
# into a different target. Transcribed from the shipped `v14 PostFX
# Distortion` orphan; see D3_MATERIAL_DESIGN.md.
"d3_distortion_apply.slang|vsD3DistortionApply|vertex|kD3DistortionApplyVS"
"d3_distortion_apply.slang|psD3DistortionApply|fragment|kD3DistortionApplyPS"
# WoW multi-texture particles (MultiTexParticleService). Three textures
# through three UV sets, drawn in the transparent pass like any other
# particle. Transcribed from the retail `particle_3colortex_3alphatex`
# shader — see M2_MULTITEX_DESIGN.md.
"particle_multitex.slang|vsMultiTexParticle|vertex|kMultiTexParticleVS"
"particle_multitex.slang|psMultiTexParticle|fragment|kMultiTexParticlePS"
# M2CombinerShading — WoW `.m2`. 16 vertex + 36 pixel entry points, indexed
# directly by M2GetVertexShaderID / M2GetPixelShaderID (m2_shader_select.h).
# Any VS pairs with any PS, so all 52 share one interstage signature.
# Names keep Blizzard's underscores: Mod_AddAlpha and Mod_Add_Alpha are
# two different combiners that collide the moment you camel-case them.
"m2_combiners.slang|vsM2Diffuse_T1|vertex|kM2Vs_Diffuse_T1"
"m2_combiners.slang|vsM2Diffuse_Env|vertex|kM2Vs_Diffuse_Env"
"m2_combiners.slang|vsM2Diffuse_T1_T2|vertex|kM2Vs_Diffuse_T1_T2"
"m2_combiners.slang|vsM2Diffuse_T1_Env|vertex|kM2Vs_Diffuse_T1_Env"
"m2_combiners.slang|vsM2Diffuse_Env_T1|vertex|kM2Vs_Diffuse_Env_T1"
"m2_combiners.slang|vsM2Diffuse_Env_Env|vertex|kM2Vs_Diffuse_Env_Env"
"m2_combiners.slang|vsM2Diffuse_T1_Env_T1|vertex|kM2Vs_Diffuse_T1_Env_T1"
"m2_combiners.slang|vsM2Diffuse_T1_T1|vertex|kM2Vs_Diffuse_T1_T1"
"m2_combiners.slang|vsM2Diffuse_T1_T1_T1|vertex|kM2Vs_Diffuse_T1_T1_T1"
"m2_combiners.slang|vsM2Diffuse_EdgeFade_T1|vertex|kM2Vs_Diffuse_EdgeFade_T1"
"m2_combiners.slang|vsM2Diffuse_T2|vertex|kM2Vs_Diffuse_T2"
"m2_combiners.slang|vsM2Diffuse_T1_Env_T2|vertex|kM2Vs_Diffuse_T1_Env_T2"
"m2_combiners.slang|vsM2Diffuse_EdgeFade_T1_T2|vertex|kM2Vs_Diffuse_EdgeFade_T1_T2"
"m2_combiners.slang|vsM2Diffuse_T1_T1_T1_T2|vertex|kM2Vs_Diffuse_T1_T1_T1_T2"
"m2_combiners.slang|vsM2Diffuse_EdgeFade_Env|vertex|kM2Vs_Diffuse_EdgeFade_Env"
"m2_combiners.slang|vsM2Diffuse_T1_T2_T1|vertex|kM2Vs_Diffuse_T1_T2_T1"
"m2_combiners.slang|psM2Combiners_Opaque|fragment|kM2Ps_Combiners_Opaque"
"m2_combiners.slang|psM2Combiners_Mod|fragment|kM2Ps_Combiners_Mod"
"m2_combiners.slang|psM2Combiners_Opaque_Mod|fragment|kM2Ps_Combiners_Opaque_Mod"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2x|fragment|kM2Ps_Combiners_Opaque_Mod2x"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA|fragment|kM2Ps_Combiners_Opaque_Mod2xNA"
"m2_combiners.slang|psM2Combiners_Opaque_Opaque|fragment|kM2Ps_Combiners_Opaque_Opaque"
"m2_combiners.slang|psM2Combiners_Mod_Mod|fragment|kM2Ps_Combiners_Mod_Mod"
"m2_combiners.slang|psM2Combiners_Mod_Mod2x|fragment|kM2Ps_Combiners_Mod_Mod2x"
"m2_combiners.slang|psM2Combiners_Mod_Add|fragment|kM2Ps_Combiners_Mod_Add"
"m2_combiners.slang|psM2Combiners_Mod_Mod2xNA|fragment|kM2Ps_Combiners_Mod_Mod2xNA"
"m2_combiners.slang|psM2Combiners_Mod_AddNA|fragment|kM2Ps_Combiners_Mod_AddNA"
"m2_combiners.slang|psM2Combiners_Mod_Opaque|fragment|kM2Ps_Combiners_Mod_Opaque"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA_Alpha|fragment|kM2Ps_Combiners_Opaque_Mod2xNA_Alpha"
"m2_combiners.slang|psM2Combiners_Opaque_AddAlpha|fragment|kM2Ps_Combiners_Opaque_AddAlpha"
"m2_combiners.slang|psM2Combiners_Opaque_AddAlpha_Alpha|fragment|kM2Ps_Combiners_Opaque_AddAlpha_Alpha"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA_Alpha_Add|fragment|kM2Ps_Combiners_Opaque_Mod2xNA_Alpha_Add"
"m2_combiners.slang|psM2Combiners_Mod_AddAlpha|fragment|kM2Ps_Combiners_Mod_AddAlpha"
"m2_combiners.slang|psM2Combiners_Mod_AddAlpha_Alpha|fragment|kM2Ps_Combiners_Mod_AddAlpha_Alpha"
"m2_combiners.slang|psM2Combiners_Opaque_Alpha_Alpha|fragment|kM2Ps_Combiners_Opaque_Alpha_Alpha"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA_Alpha_3s|fragment|kM2Ps_Combiners_Opaque_Mod2xNA_Alpha_3s"
"m2_combiners.slang|psM2Combiners_Opaque_AddAlpha_Wgt|fragment|kM2Ps_Combiners_Opaque_AddAlpha_Wgt"
"m2_combiners.slang|psM2Combiners_Mod_Add_Alpha|fragment|kM2Ps_Combiners_Mod_Add_Alpha"
"m2_combiners.slang|psM2Combiners_Opaque_ModNA_Alpha|fragment|kM2Ps_Combiners_Opaque_ModNA_Alpha"
"m2_combiners.slang|psM2Combiners_Mod_AddAlpha_Wgt|fragment|kM2Ps_Combiners_Mod_AddAlpha_Wgt"
"m2_combiners.slang|psM2Combiners_Opaque_Mod_Add_Wgt|fragment|kM2Ps_Combiners_Opaque_Mod_Add_Wgt"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA_Alpha_UnshAlpha|fragment|kM2Ps_Combiners_Opaque_Mod2xNA_Alpha_UnshAlpha"
"m2_combiners.slang|psM2Combiners_Mod_Dual_Crossfade|fragment|kM2Ps_Combiners_Mod_Dual_Crossfade"
"m2_combiners.slang|psM2Combiners_Opaque_Mod2xNA_Alpha_Alpha|fragment|kM2Ps_Combiners_Opaque_Mod2xNA_Alpha_Alpha"
"m2_combiners.slang|psM2Combiners_Mod_Masked_Dual_Crossfade|fragment|kM2Ps_Combiners_Mod_Masked_Dual_Crossfade"
"m2_combiners.slang|psM2Combiners_Opaque_Alpha|fragment|kM2Ps_Combiners_Opaque_Alpha"
"m2_combiners.slang|psM2Guild|fragment|kM2Ps_Guild"
"m2_combiners.slang|psM2Guild_NoBorder|fragment|kM2Ps_Guild_NoBorder"
"m2_combiners.slang|psM2Guild_Opaque|fragment|kM2Ps_Guild_Opaque"
"m2_combiners.slang|psM2Combiners_Mod_Depth|fragment|kM2Ps_Combiners_Mod_Depth"
"m2_combiners.slang|psM2Combiners_Mod_Mod_Depth|fragment|kM2Ps_Combiners_Mod_Mod_Depth"
"m2_combiners.slang|psM2Illum|fragment|kM2Ps_Illum"
# Debug views: every combiner, by pixel-shader id, at fixed light.
"m2_combiners.slang|psM2Debug|fragment|kM2Ps_Debug"
# M3 simple material (M3_SIMPLE_MATERIAL_DESIGN.md): forward and MRT pixel
# entries share one shading function; the split exists because Vulkan
# rejects a PS declaring outputs the pass never binds.
"m3_standard.slang|vsM3Standard|vertex|kM3StandardVS"
"m3_standard.slang|vsM3StandardSkinned|vertex|kM3StandardSkinnedVS"
"m3_standard.slang|psM3Standard|fragment|kM3StandardPS"
"m3_standard.slang|psM3StandardMrt|fragment|kM3StandardMrtPS"
# Debug views: ShadeM3's terms through debug_view.slang. The MRT twin writes
# the overridden albedo so the deferred lights agree in the lighting views.
"m3_standard.slang|psM3StandardDebug|fragment|kM3StandardDebugPS"
"m3_standard.slang|psM3StandardDebugMrt|fragment|kM3StandardDebugMrtPS"
# The ribbon strip VS: world-space CPU strip into the shared full material
# PS (psM3Standard). No PS of its own — the ribbon runs the geoset shader.
"m3_standard.slang|vsM3Ribbon|vertex|kM3RibbonVS"
# D3 standard material (Diablo III actors). One PS: the frame is gamma-LDR
# with no G-buffer, so there is no MRT twin to split off.
"d3_standard.slang|vsD3Standard|vertex|kD3StandardVS"
"d3_standard.slang|vsD3StandardSkinned|vertex|kD3StandardSkinnedVS"
"d3_standard.slang|psD3Standard|fragment|kD3StandardPS"
# Debug views: both material shapes' terms through debug_view.slang.
"d3_standard.slang|psD3StandardDebug|fragment|kD3StandardDebugPS"
# D3 particles. `Billboard.fx` / `ps_legacy` is a four-stage fixed-function
# chain with a UV transform per stage; the SD program has one texture and no
# chain at all. See D3_PARTICLE_DESIGN.md §8.
"d3_particle.slang|vsD3Particle|vertex|kD3ParticleVS"
"d3_particle.slang|psD3Particle|fragment|kD3ParticlePS"
"m3_deferred_light.slang|vsM3DeferredLight|vertex|kM3DeferredLightVS"
"m3_deferred_light.slang|psM3DeferredLight|fragment|kM3DeferredLightPS"
# Debug views (DEBUG_VIEW_DESIGN.md). The WC3 programs pair with the retail
# HD / SD vertex permutations and import Wc3Shaders for every decode, so they
# take the `wc3` flag set: its include path and the DX constant-buffer layout
# the BLS build compiles the programs they stand in for with. The lighting
# variants exist per shadow map a frame may or may not have bound.
"wc3_debug.slang|psWc3HdDebug|fragment|kWc3HdDebugPS|wc3"
"wc3_debug.slang|psWc3HdDebugCsm|fragment|kWc3HdDebugCsmPS|wc3"
"wc3_debug.slang|psWc3HdDebugCube|fragment|kWc3HdDebugCubePS|wc3"
"wc3_debug.slang|psWc3HdDebugCsmCube|fragment|kWc3HdDebugCsmCubePS|wc3"
"wc3_debug.slang|psWc3SdDebug|fragment|kWc3SdDebugPS|wc3"
"wc3_debug.slang|vsWc3SdDebug|vertex|kWc3SdDebugVS|wc3"
"wc3_debug.slang|vsWc3SdDebugSkinned|vertex|kWc3SdDebugSkinnedVS|wc3"
"wc3_debug.slang|psWc3SdDebugNormal|fragment|kWc3SdDebugNormalPS|wc3"
# Mesh overlay (DEBUG_VIEW_DESIGN.md §9): one pixel entry, and per product a
# vertex entry per skinning path that imports the product's own vertex code.
# The `overlay` set silences the constant-buffer overlap the entries take on
# purpose (the debug view's b3) and tracks the imported product files.
"mesh_overlay.slang|psMeshOverlay|fragment|kMeshOverlayPS|overlay"
"m2_overlay.slang|vsM2Overlay|vertex|kM2OverlayVS|overlay"
"m3_overlay.slang|vsM3Overlay|vertex|kM3OverlayVS|overlay"
"m3_overlay.slang|vsM3OverlaySkinned|vertex|kM3OverlaySkinnedVS|overlay"
"d3_overlay.slang|vsD3Overlay|vertex|kD3OverlayVS|overlay"
"d3_overlay.slang|vsD3OverlaySkinned|vertex|kD3OverlaySkinnedVS|overlay"
"unlit_overlay.slang|vsUnlitOverlay|vertex|kUnlitOverlayVS|overlay"
"unlit_overlay.slang|vsUnlitOverlaySkinned|vertex|kUnlitOverlaySkinnedVS|overlay"
"wc3_overlay.slang|vsWc3HdOverlay|vertex|kWc3HdOverlayVS|wc3"
"wc3_overlay.slang|vsWc3HdOverlayPalette|vertex|kWc3HdOverlayPaletteVS|wc3"
"wc3_overlay.slang|vsWc3HdOverlayBoneBuffer|vertex|kWc3HdOverlayBoneBufferVS|wc3"
"wc3_overlay.slang|vsWc3SdOverlay|vertex|kWc3SdOverlayVS|wc3"
"wc3_overlay.slang|vsWc3SdOverlaySkinned|vertex|kWc3SdOverlaySkinnedVS|wc3"
# NOTE: depth of field has no custom shader entry — DofService runs the
# shipped WC3 depthoffield.bls (GxShaderID DepthOfField) through the BLS
# shader cache, and reuses the embedded blit (kBlit*) for the round-trip.
)
# The WC3 debug pixel programs that pair with a RETAIL vertex program. On D3D12
# that program is DXIL (shaders/d3d12/), and the runtime will not link SM 6
# with SM 5, so these also build as DXIL. Through the same slangc that builds
# the d3d12 bundles, so both stages spell their semantics the same way.
set(WC3_DXIL_ENTRIES kWc3HdDebugPS kWc3HdDebugCsmPS kWc3HdDebugCubePS kWc3HdDebugCsmCubePS
kWc3SdDebugPS)
set(SHADER_DXBC_FILES "")
set(SHADER_DXIL_FILES "")
set(SHADER_SPV_FILES "")
set(SHADER_WGSL_FILES "")
set(SHADER_MTL_FILES "")
foreach(entry IN LISTS SHADER_ENTRIES)
string(REPLACE "|" ";" parts "${entry}")
list(GET parts 0 src_file)
list(GET parts 1 entry_name)
list(GET parts 2 stage)
list(GET parts 3 var_name)
# Optional fifth column: a named flag set.
set(entry_flags "")
set(entry_spv_flags "")
set(entry_deps "${SHADER_SRC_DIR}/common.slang" "${SHADER_SRC_DIR}/debug_view.slang")
list(LENGTH parts part_count)
if(part_count GREATER 4)
list(GET parts 4 flag_set)
if(flag_set STREQUAL "wc3")
set(entry_flags -I "${CMAKE_CURRENT_SOURCE_DIR}/externals/Wc3Shaders/wc3_shaders"
-warnings-disable 39001,15205,30056,41016)
set(entry_spv_flags -fvk-use-dx-layout)
list(APPEND entry_deps
"${CMAKE_CURRENT_SOURCE_DIR}/externals/Wc3Shaders/wc3_shaders/wc3_shaders.slang"
"${SHADER_SRC_DIR}/mesh_overlay.slang")
elseif(flag_set STREQUAL "overlay")
set(entry_flags -warnings-disable 39001)
list(APPEND entry_deps "${SHADER_SRC_DIR}/mesh_overlay.slang"
"${SHADER_SRC_DIR}/m2_combiners.slang" "${SHADER_SRC_DIR}/m3_standard.slang"
"${SHADER_SRC_DIR}/d3_standard.slang" "${SHADER_SRC_DIR}/unlit.slang")
endif()
endif()
set(dxbc_path "${SHADER_OUT_DIR}/${var_name}.dxbc")
set(spv_path "${SHADER_OUT_DIR}/${var_name}.spv")
# DXBC is Windows-only: slangc's DXBC backend invokes fxc internally,
# and fxc.exe ships with the Windows SDK / d3dcompiler — there's no
# Linux/macOS equivalent. On non-Windows hosts we skip the DXBC step
# entirely and let embed_shaders.cmake stub the DXBC C++ symbols so
# the consumer call sites still compile (they're never reached at
# runtime on platforms without D3D).
if(WIN32)
add_custom_command(
OUTPUT "${dxbc_path}"
COMMAND "${SLANGC}" "${SHADER_SRC_DIR}/${src_file}"
${SLANG_COMMON_FLAGS} ${entry_flags}
-entry ${entry_name} -stage ${stage}
-target dxbc -profile sm_5_0
-o "${dxbc_path}"
DEPENDS "${SHADER_SRC_DIR}/${src_file}"
${entry_deps}
COMMENT "Slang: ${src_file} [${entry_name}] → ${var_name}.dxbc"
VERBATIM
)
list(APPEND SHADER_DXBC_FILES "${dxbc_path}")
if(var_name IN_LIST WC3_DXIL_ENTRIES)
set(dxil_path "${SHADER_OUT_DIR}/${var_name}.dxil")
add_custom_command(
OUTPUT "${dxil_path}"
COMMAND "${SLANGC}" "${SHADER_SRC_DIR}/${src_file}"
${SLANG_COMMON_FLAGS} ${entry_flags}
-entry ${entry_name} -stage ${stage}
-target dxil -profile sm_6_0
-o "${dxil_path}"
DEPENDS "${SHADER_SRC_DIR}/${src_file}"
${entry_deps}
COMMENT "Slang: ${src_file} [${entry_name}] → ${var_name}.dxil"
VERBATIM
)
list(APPEND SHADER_DXIL_FILES "${dxil_path}")
endif()
endif()
# SPIR-V variant for the Vulkan backend. The embed script picks these
# up alongside the .dxbc blobs and emits a parallel `<var>Spv[]` array
# in compiled_shaders.h. Compiled here unconditionally — the resulting
# bytes are unused (and harmless) when WDX_HAS_VULKAN is off.
add_custom_command(
OUTPUT "${spv_path}"
COMMAND "${SLANGC}" "${SHADER_SRC_DIR}/${src_file}"
${SLANG_COMMON_FLAGS} ${entry_flags} ${entry_spv_flags}
-entry ${entry_name} -stage ${stage}
-target spirv -profile glsl_450
-o "${spv_path}"
DEPENDS "${SHADER_SRC_DIR}/${src_file}"
${entry_deps}
COMMENT "Slang: ${src_file} [${entry_name}] → ${var_name}.spv"
VERBATIM
)
list(APPEND SHADER_SPV_FILES "${spv_path}")
# WGSL variant for the WebGPU backend. Only emitted when WDX_ENABLE_WEBGPU
# is on — otherwise the embed script's stub keeps the consumer code
# type-checking without dragging the slangc invocation into every build.
if(WDX_ENABLE_WEBGPU)
set(wgsl_path "${SHADER_OUT_DIR}/${var_name}.wgsl")
set(wgsl_post "")
if(entry_spv_flags)
# The wc3 set: slangc types comparison-sampled textures as colour.
set(wgsl_post COMMAND "${CMAKE_COMMAND}" "-DWGSL=${wgsl_path}"
-P "${SHADER_SRC_DIR}/wgsl_depth_textures.cmake")
endif()
add_custom_command(
OUTPUT "${wgsl_path}"
COMMAND "${SLANGC}" "${SHADER_SRC_DIR}/${src_file}"
${SLANG_COMMON_FLAGS} ${entry_flags}
-DWGSL_TARGET=1
-entry ${entry_name} -stage ${stage}
-target wgsl
-o "${wgsl_path}"
${wgsl_post}
DEPENDS "${SHADER_SRC_DIR}/${src_file}"
${entry_deps}
COMMENT "Slang: ${src_file} [${entry_name}] → ${var_name}.wgsl"
VERBATIM
)
list(APPEND SHADER_WGSL_FILES "${wgsl_path}")
endif()
# Metal library bytecode for the Metal backend. macOS-only — needs
# Apple's metal compiler (Xcode's Metal Toolchain). slangc's metallib
# backend invokes xcrun metal internally and pins the container at
# version 1.2.7 (Metal 4.x); fine for the debug line / blit /
# framebuffer-capture shaders here — the renderer just loads them as
# opaque bytes. The Wc3Shaders pipeline targets metallib 1.2.5 by
# post-processing slangc's .metal emit, but that machinery isn't
# needed for this small set of shaders.
if(WDX_ENABLE_METAL AND APPLE)
set(mtl_path "${SHADER_OUT_DIR}/${var_name}.metallib")
add_custom_command(
OUTPUT "${mtl_path}"
COMMAND "${SLANGC}" "${SHADER_SRC_DIR}/${src_file}"
${SLANG_COMMON_FLAGS} ${entry_flags}
-DMETAL_TARGET=1
-entry ${entry_name} -stage ${stage}
-target metallib -profile sm_6_0
-o "${mtl_path}"
DEPENDS "${SHADER_SRC_DIR}/${src_file}"
${entry_deps}
COMMENT "Slang: ${src_file} [${entry_name}] → ${var_name}.metallib"
VERBATIM
)
list(APPEND SHADER_MTL_FILES "${mtl_path}")
endif()
endforeach()
# Embed all DXBC blobs into a single C++ header
set(COMPILED_SHADERS_H "${SHADER_OUT_DIR}/compiled_shaders.h")
# Emscripten has no Vulkan backend, and the SPIR-V twin of every shader is
# ~780 KB the browser can never reach — a quarter of the wasm. Stub the bytes
# there; the symbols still exist, so the per-backend selectors compile.
if(EMSCRIPTEN)
set(_wf_embed_spv OFF)
else()
set(_wf_embed_spv ON)
endif()
add_custom_command(
OUTPUT "${COMPILED_SHADERS_H}"
COMMAND "${CMAKE_COMMAND}"
"-DSHADER_DIR=${SHADER_OUT_DIR}"
"-DOUTPUT=${COMPILED_SHADERS_H}"
"-DEMBED_SPV=${_wf_embed_spv}"
-P "${SHADER_SRC_DIR}/embed_shaders.cmake"
DEPENDS ${SHADER_DXBC_FILES} ${SHADER_DXIL_FILES} ${SHADER_SPV_FILES} ${SHADER_WGSL_FILES}
${SHADER_MTL_FILES}
"${SHADER_SRC_DIR}/embed_shaders.cmake"
COMMENT "Embedding compiled shaders into compiled_shaders.h"
VERBATIM
)
add_custom_target(WhiteoutFlakesShaders DEPENDS "${COMPILED_SHADERS_H}")
# ============================================================================
# Embedded resources (build-time: binary file → C++ header with byte array)
# ============================================================================
set(EMBED_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/embedded")
file(MAKE_DIRECTORY "${EMBED_OUT_DIR}")
set(TEAM_GLOW_TGA "${CMAKE_CURRENT_SOURCE_DIR}/resources/teamglow.tga")
set(TEAM_GLOW_H "${EMBED_OUT_DIR}/team_glow_embedded.h")
add_custom_command(
OUTPUT "${TEAM_GLOW_H}"
COMMAND "${CMAKE_COMMAND}"
"-DINPUT=${TEAM_GLOW_TGA}"
"-DOUTPUT=${TEAM_GLOW_H}"
"-DVAR_NAME=kTeamGlowTGA"
"-DNAMESPACE=whiteout::flakes::io"
-P "${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
DEPENDS "${TEAM_GLOW_TGA}"
"${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
COMMENT "Embedding teamglow.tga into team_glow_embedded.h"
VERBATIM
)
# Roboto-Medium for the ImGui host theme — hinted TTF (vs. ProggyClean bitmap)
# so DPI-scaled UIs stay crisp instead of bilinear-upscaled.
set(ROBOTO_TTF "${CMAKE_CURRENT_SOURCE_DIR}/externals/imgui/misc/fonts/Roboto-Medium.ttf")
set(ROBOTO_H "${EMBED_OUT_DIR}/roboto_medium_embedded.h")
add_custom_command(
OUTPUT "${ROBOTO_H}"
COMMAND "${CMAKE_COMMAND}"
"-DINPUT=${ROBOTO_TTF}"
"-DOUTPUT=${ROBOTO_H}"
"-DVAR_NAME=kRobotoMediumTTF"
"-DNAMESPACE=whiteout::flakes::ui"
-P "${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
DEPENDS "${ROBOTO_TTF}"
"${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
COMMENT "Embedding Roboto-Medium.ttf into roboto_medium_embedded.h"
VERBATIM
)
# The application's own icon, for the ribbon's application tile. Embedded
# rather than staged beside the exe because a host that is not the standalone
# viewer — the Max plugin ships as one .dlu — has no asset directory to look in.
set(FLAKES_ICON_PNG "${CMAKE_CURRENT_SOURCE_DIR}/resources/flakes_icon_linux.png")
set(FLAKES_ICON_H "${EMBED_OUT_DIR}/flakes_icon_embedded.h")
add_custom_command(
OUTPUT "${FLAKES_ICON_H}"
COMMAND "${CMAKE_COMMAND}"
"-DINPUT=${FLAKES_ICON_PNG}"
"-DOUTPUT=${FLAKES_ICON_H}"
"-DVAR_NAME=kFlakesIconPNG"
"-DNAMESPACE=whiteout::flakes::ui"
-P "${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
DEPENDS "${FLAKES_ICON_PNG}"
"${CMAKE_CURRENT_SOURCE_DIR}/resources/embed_binary.cmake"
COMMENT "Embedding flakes_icon_linux.png into flakes_icon_embedded.h"
VERBATIM
)
add_custom_target(WhiteoutFlakesEmbedded DEPENDS "${TEAM_GLOW_H}" "${ROBOTO_H}" "${FLAKES_ICON_H}")
# ============================================================================
# Wc3Shaders — opt-in build of the externals/Wc3Shaders Slang reconstruction.
#
# When WDX_BUILD_WC3_SHADERS=ON, drives the submodule's two-step Python
# pipeline (compile_all_slang.py → DXBC + DXIL, then build_bls.py → .bls)
# and copies the resulting BLS bundles next to the standalone exe under
# Shaders/{ps,vs}/. Packing requires the shipped war3.w3mod/shaders/ tree
# (binding-metadata templates), supplied via -DWDX_SHADER_TEMPLATES=<path>.
# Both DXBC (sm 5.0, primary — what the BLS loader reads) and DXIL (sm 6.0,
# kept as raw .dxil under wc3_shaders/slang_out/ for future use) targets
# are produced.
# ============================================================================
option(WDX_BUILD_WC3_SHADERS
"Compile the externals/Wc3Shaders Slang sources and pack BLS bundles"
OFF)
# When ON (and WDX_BUILD_WC3_SHADERS is too), a second pass builds a
# parallel set of BLS bundles with full debug symbols (slangc -g2 -O0,
# +emit-spirv-directly) and stages them into standalone/debug_shaders/.
# The renderer loads those instead of standalone/shaders/ when graphics
# debug is on. Roughly doubles the Wc3Shaders compile time and the
# emitted bundles weigh ~865 MB — opt in only when actively debugging
# shaders. Not committed under prebuilt/ for the same size reason.
option(WDX_BUILD_WC3_DEBUG_SHADERS
"Also build debug-symbol BLS bundles into debug_shaders/"
OFF)
# Use the pre-baked .bls bundles committed under prebuilt/shaders/ instead of
# re-running slangc. Mutually exclusive with WDX_BUILD_WC3_SHADERS — the
# auto-detect at the bottom of this option block flips it on by default
# whenever the prebuilt dir exists *and* shader compilation is off, which
# covers both the GitHub CI case (slangc isn't installed) and a fresh clone
# without the Vulkan SDK.
option(WDX_USE_PREBUILT_SHADERS
"Stage the prebuilt/shaders pack instead of running the Slang toolchain"
OFF)
if(NOT WDX_USE_PREBUILT_SHADERS AND NOT WDX_BUILD_WC3_SHADERS
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/shaders")
set(WDX_USE_PREBUILT_SHADERS ON CACHE BOOL
"Stage the prebuilt/shaders pack instead of running the Slang toolchain"
FORCE)
message(STATUS "Wc3Shaders: WDX_USE_PREBUILT_SHADERS auto-enabled (prebuilt/shaders found)")
endif()
if(WDX_BUILD_WC3_SHADERS AND WDX_USE_PREBUILT_SHADERS)
message(FATAL_ERROR
"WDX_BUILD_WC3_SHADERS and WDX_USE_PREBUILT_SHADERS are mutually exclusive — "
"one runs slangc, the other copies pre-baked bundles. Pick one.")
endif()
# Where the viewer exe lands, spelled without naming the target (a generator
# expression on WhiteoutFlakesStandalone would make Wc3Shaders depend on the
# viewer, which depends on Wc3Shaders). The viewer pins Debug and Release to
# standalone/; multi-config generators put every other config one level below.
if(CMAKE_CONFIGURATION_TYPES)
set(WDX_VIEWER_EXE_DIR
"${CMAKE_BINARY_DIR}/standalone/$<$<NOT:$<CONFIG:Debug,Release>>:$<CONFIG>>")
else()
set(WDX_VIEWER_EXE_DIR "${CMAKE_BINARY_DIR}/standalone")
endif()
if(WDX_USE_PREBUILT_SHADERS)
set(WDX_PREBUILT_SHADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/shaders"
CACHE PATH "Pre-baked .bls staging tree (mirrors standalone/shaders/ layout)")
if(NOT EXISTS "${WDX_PREBUILT_SHADERS_DIR}")
message(FATAL_ERROR
"WDX_USE_PREBUILT_SHADERS=ON but ${WDX_PREBUILT_SHADERS_DIR} is missing. "
"Run cmake --build build --target update-prebuilt-shaders against a "
"tree where WDX_BUILD_WC3_SHADERS=ON to populate it.")
endif()
# Stage prebuilt → standalone/shaders so the runtime exe-dir lookup
# finds them with no extra path config (matches the WDX_BUILD_WC3_SHADERS
# codegen layout exactly).
set(_prebuilt_stage "${CMAKE_BINARY_DIR}/standalone/shaders")
set(_prebuilt_stamp "${CMAKE_CURRENT_BINARY_DIR}/wc3_prebuilt.stamp")
add_custom_command(
OUTPUT "${_prebuilt_stamp}"
COMMAND "${CMAKE_COMMAND}" -E rm -rf "${_prebuilt_stage}"
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${WDX_PREBUILT_SHADERS_DIR}" "${_prebuilt_stage}"
COMMAND "${CMAKE_COMMAND}" -E touch "${_prebuilt_stamp}"
# Re-stage when any prebuilt file changes (developer pulled new
# prebuilt/ from git).
DEPENDS "${WDX_PREBUILT_SHADERS_DIR}"
COMMENT "Wc3Shaders[prebuilt]: staging ${WDX_PREBUILT_SHADERS_DIR} -> ${_prebuilt_stage}"
VERBATIM)
# Beside the exe too, for the configs whose exe is not in standalone/
# (the same reason as the compiled pack's exe stage below).
set(_prebuilt_exe_stamp "${CMAKE_CURRENT_BINARY_DIR}/wc3_prebuilt_exe_$<CONFIG>.stamp")
add_custom_command(
OUTPUT "${_prebuilt_exe_stamp}"
COMMAND "${CMAKE_COMMAND}"
"-DSRC=${_prebuilt_stage}"
"-DDST=${WDX_VIEWER_EXE_DIR}/shaders"
"-DSTAMP=${_prebuilt_exe_stamp}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/resources/copy_dir_unless_same.cmake"
DEPENDS "${_prebuilt_stamp}" "${CMAKE_CURRENT_SOURCE_DIR}/resources/copy_dir_unless_same.cmake"
COMMENT "Wc3Shaders[prebuilt]: staging the pack beside the viewer exe"
VERBATIM)
add_custom_target(Wc3Shaders ALL DEPENDS "${_prebuilt_exe_stamp}")
# debug_shaders/ is intentionally not prebuilt — the .bls bundles
# weigh ~865 MB and bloat the repo. Developers who need them flip
# WDX_BUILD_WC3_SHADERS=ON locally (which also honors
# WDX_BUILD_WC3_DEBUG_SHADERS=ON to produce standalone/debug_shaders/).
endif()
if(WDX_BUILD_WC3_SHADERS)
set(WC3_SHADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals/Wc3Shaders")
if(NOT EXISTS "${WC3_SHADERS_DIR}/compile_all_slang.py")
message(FATAL_ERROR
"WDX_BUILD_WC3_SHADERS=ON but externals/Wc3Shaders/ is empty. "
"Initialize the submodule with: git submodule update --init externals/Wc3Shaders")
endif()
# Default to the locally-vendored war3.w3mod/shaders/ tree at the
# project root (gitignored). Users can still override with
# -DWDX_SHADER_TEMPLATES=<path> when their templates live elsewhere.
if(NOT DEFINED WDX_SHADER_TEMPLATES OR WDX_SHADER_TEMPLATES STREQUAL "")
set(WDX_SHADER_TEMPLATES "${CMAKE_CURRENT_SOURCE_DIR}/war3.w3mod/shaders"
CACHE PATH "Path to extracted war3.w3mod/shaders/ BLS templates")
endif()
if(NOT EXISTS "${WDX_SHADER_TEMPLATES}")
message(FATAL_ERROR
"WDX_SHADER_TEMPLATES does not exist: ${WDX_SHADER_TEMPLATES}\n"
"Point at an extracted war3.w3mod/shaders/ directory containing "
"the shipped {ps,vs}/*.bls templates, or place the tree at "
"${CMAKE_CURRENT_SOURCE_DIR}/war3.w3mod/shaders/ to use the default.")
endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
message(STATUS "Wc3Shaders: Python = ${Python3_EXECUTABLE}")
message(STATUS "Wc3Shaders: BLS templates = ${WDX_SHADER_TEMPLATES}")
# The Python scripts hardcode their output under <repo>/slang_out and
# <repo>/bls_out (both gitignored inside the submodule). We use a stamp
# file pattern for dependency tracking — globs catch source / config
# changes; the slangc the renderer's debug shaders found is forwarded
# so we don't need to re-resolve.
file(GLOB_RECURSE WC3_SLANG_SOURCES
"${WC3_SHADERS_DIR}/wc3_shaders/*.slang"
"${WC3_SHADERS_DIR}/custom_shaders/*.slang")
set(WC3_BUILD_SCRIPTS
"${WC3_SHADERS_DIR}/compile_all_slang.py"
"${WC3_SHADERS_DIR}/build_bls.py"
"${WC3_SHADERS_DIR}/shader_config.py"
"${WC3_SHADERS_DIR}/wc3_shaders.json"
"${WC3_SHADERS_DIR}/custom_shaders.json")
# Optional cache var: semicolon-separated list of shader families to
# compile. Defaults to empty → compile every family. The compile
# script's --family flag accepts the same names; only the listed
# families get re-slang'd, every other family reuses the previous
# slang_out/<target>/<family>/ output (and BLS bundles).
set(WDX_WC3_FAMILIES "" CACHE STRING "Wc3Shaders families to re-compile (empty = all)")
set(WC3_FAMILY_ARGS "")
if(WDX_WC3_FAMILIES)
foreach(fam IN LISTS WDX_WC3_FAMILIES)
list(APPEND WC3_FAMILY_ARGS --family "${fam}")
endforeach()
message(STATUS "Wc3Shaders: limiting compile to families: ${WDX_WC3_FAMILIES}")
endif()
# Build one variant of the Wc3Shaders pipeline end to end:
# compile Slang -> {DXBC, DXIL, SPIR-V} (compile_all_slang.py)
# pack .bls bundles (build_bls.py)
# stage into the standalone exe's <stage_subdir>/ tree
#
# The release variant compiles optimised bytecode into slang_out/ and
# packs it (with --strip) into shaders/. The debug variant passes
# --debug to compile_all_slang.py (slangc -g2 -O0, +emit-spirv-directly;
# output diverted to slang_out_debug/), then packs *without* --strip —
# stripping would trim the input-signature/debug data we want kept —
# into debug_shaders/. Both reuse the same .slang sources, the same
# WC3_FAMILY_ARGS filter, and the same v1.8/v1.14 → flat layout
# flattening so the renderer's BLS cache only knows two roots:
# shaders/ and debug_shaders/.
#
# Sets ${out_stamp_var} in the caller's scope to the final stage stamp.
function(wc3_shader_pipeline variant is_debug stage_subdir out_stamp_var)
if(is_debug)
set(_compile_extra --debug)
set(_slang_out "${WC3_SHADERS_DIR}/slang_out_debug")
set(_bls_out "${WC3_SHADERS_DIR}/bls_out_debug")
set(_bls_slang_out_arg --slang-out "${_slang_out}")
set(_bls_strip_arg) # debug: keep signatures/debug info
else()
set(_compile_extra) # release: no extra flag
set(_slang_out "${WC3_SHADERS_DIR}/slang_out")
set(_bls_out "${WC3_SHADERS_DIR}/bls_out")
set(_bls_slang_out_arg) # build_bls.py defaults to slang_out
set(_bls_strip_arg --strip)
endif()
set(_dxbc "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_dxbc.stamp")
set(_dxil "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_dxil.stamp")
set(_spirv "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_spirv.stamp")
set(_wgsl "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_wgsl.stamp")
set(_bls "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_bls.stamp")
set(_stage "${CMAKE_CURRENT_BINARY_DIR}/wc3_${variant}_stage.stamp")
add_custom_command(
OUTPUT "${_dxbc}"
COMMAND "${Python3_EXECUTABLE}" "${WC3_SHADERS_DIR}/compile_all_slang.py"
--target d3d11 --slangc "${SLANGC}" ${_compile_extra} ${WC3_FAMILY_ARGS}
COMMAND "${CMAKE_COMMAND}" -E touch "${_dxbc}"
WORKING_DIRECTORY "${WC3_SHADERS_DIR}"
DEPENDS ${WC3_SLANG_SOURCES} ${WC3_BUILD_SCRIPTS}
COMMENT "Wc3Shaders[${variant}]: compiling Slang -> DXBC (d3d11)"
VERBATIM)
add_custom_command(
OUTPUT "${_dxil}"
COMMAND "${Python3_EXECUTABLE}" "${WC3_SHADERS_DIR}/compile_all_slang.py"
--target d3d12 --slangc "${SLANGC}" ${_compile_extra} ${WC3_FAMILY_ARGS}
COMMAND "${CMAKE_COMMAND}" -E touch "${_dxil}"
WORKING_DIRECTORY "${WC3_SHADERS_DIR}"
DEPENDS ${WC3_SLANG_SOURCES} ${WC3_BUILD_SCRIPTS}
COMMENT "Wc3Shaders[${variant}]: compiling Slang -> DXIL (d3d12)"
VERBATIM)
add_custom_command(
OUTPUT "${_spirv}"
COMMAND "${Python3_EXECUTABLE}" "${WC3_SHADERS_DIR}/compile_all_slang.py"
--target vulkan --slangc "${SLANGC_VULKAN}" ${_compile_extra} ${WC3_FAMILY_ARGS}
COMMAND "${CMAKE_COMMAND}" -E touch "${_spirv}"
WORKING_DIRECTORY "${WC3_SHADERS_DIR}"
DEPENDS ${WC3_SLANG_SOURCES} ${WC3_BUILD_SCRIPTS}
COMMENT "Wc3Shaders[${variant}]: compiling Slang -> SPIR-V (vulkan)"
VERBATIM)
# WGSL for the WebGPU backend — only emitted when WDX_ENABLE_WEBGPU
# is on (the consumer side). compile_all_slang.py writes
# slang_out/webgpu/<family>/*.wgsl; build_bls.py picks them up
# automatically and packs them into bls_out_1_14/shaders/{pixel,
# vertex}/wgsl_1_0/.
add_custom_command(
OUTPUT "${_wgsl}"
COMMAND "${Python3_EXECUTABLE}" "${WC3_SHADERS_DIR}/compile_all_slang.py"
--target webgpu --slangc "${SLANGC_VULKAN}" ${_compile_extra} ${WC3_FAMILY_ARGS}
COMMAND "${CMAKE_COMMAND}" -E touch "${_wgsl}"
WORKING_DIRECTORY "${WC3_SHADERS_DIR}"
DEPENDS ${WC3_SLANG_SOURCES} ${WC3_BUILD_SCRIPTS}
COMMENT "Wc3Shaders[${variant}]: compiling Slang -> WGSL (webgpu)"
VERBATIM)
# Upstream build_bls.py writes two trees:
# <output>_1_8/{ps,vs,mtlfs,mtlvs}/*.bls (Wc3 v1.8 layout)
# <output>_1_14/shaders/{pixel,vertex}/<api>/*.bls (v1.14, WoW-style)
# where <api> ∈ {dx_5_0, dx_6_0, spv_1_3, …}. The SPIR-V subdir name
# encodes the slangc-emitted SPIR-V version (1.3 for glsl_450 →
# Vulkan 1.3).
set(_bls_out_18 "${_bls_out}_1_8")
set(_bls_out_14 "${_bls_out}_1_14")
add_custom_command(
OUTPUT "${_bls}"
COMMAND "${Python3_EXECUTABLE}" "${WC3_SHADERS_DIR}/build_bls.py"
--templates "${WDX_SHADER_TEMPLATES}"
--output "${_bls_out}"
${_bls_slang_out_arg}
${_bls_strip_arg}
COMMAND "${CMAKE_COMMAND}" -E touch "${_bls}"
WORKING_DIRECTORY "${WC3_SHADERS_DIR}"
DEPENDS "${_dxbc}" "${_dxil}" "${_spirv}" "${_wgsl}" ${WC3_BUILD_SCRIPTS}
COMMENT "Wc3Shaders[${variant}]: packing .bls (v1.8 DX + v1.14 DX/SPIR-V/WGSL)"
VERBATIM)
# Stage the freshly packed bundles into the standalone exe's output
# directory the moment Wc3Shaders rebuilds — independently of
# whether the exe relinks (POST_BUILD on the exe wouldn't fire on a
# BLS-only change). The standalone exe lands at
# ${CMAKE_BINARY_DIR}/standalone, so the path is known up front. We
# flatten the upstream layout into the renderer's path scheme
# (<root>/{ps,vs,d3d12/ps,d3d12/vs,vulkan/ps,vulkan/vs,metal/ps,metal/vs}/)
# so the BLS cache only needs to know the two roots shaders/ and
# debug_shaders/.
set(_stage_dir "${CMAKE_BINARY_DIR}/standalone/${stage_subdir}")
# Metal v1.8 bundles — only emitted on macOS where Apple's Metal
# toolchain is available. compile_all_slang.py auto-adds the
# metal target on darwin, so the dxbc command above also
# populates slang_out/metal and build_bls.py packs
# bls_out_1_8/{mtlfs,mtlvs} in the same run. bls_shader_cache
# routes GfxApi::Metal → metal/{ps,vs}/.
set(_extra_stage_cmds "")
if(APPLE)
list(APPEND _extra_stage_cmds
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${_bls_out_18}/mtlfs" "${_stage_dir}/metal/ps"
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${_bls_out_18}/mtlvs" "${_stage_dir}/metal/vs"
)
endif()
add_custom_command(
OUTPUT "${_stage}"
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${_bls_out_18}/ps" "${_stage_dir}/ps"
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${_bls_out_18}/vs" "${_stage_dir}/vs"
COMMAND "${CMAKE_COMMAND}" -E copy_directory