-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofflineshadercompiler.cpp
More file actions
801 lines (735 loc) · 33.4 KB
/
Copy pathofflineshadercompiler.cpp
File metadata and controls
801 lines (735 loc) · 33.4 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
#define SDL_MAIN_HANDLED
#include "Simtary.h"
#include <iostream>
#include <iomanip>
#include <mutex>
#include <string>
#include <cstdlib>
class nullbuf_t : public std::streambuf
{
protected:
virtual int_type overflow(int_type ch) override
{
return traits_type::not_eof(ch);
}
} nullbuf;
std::mutex locker;
struct ShaderEntry
{
std::string name;
wi::graphics::ShaderStage stage = wi::graphics::ShaderStage::Count;
wi::graphics::ShaderModel minshadermodel = wi::graphics::ShaderModel::SM_5_0;
struct Permutation
{
wi::vector<std::string> defines;
Permutation() = default;
Permutation(std::initializer_list<std::string> init)
{
for (auto& x : init)
{
defines.push_back(x);
}
}
};
wi::vector<Permutation> permutations;
std::string entrypoint = "main";
};
wi::vector<ShaderEntry> shaders = {
{"hairparticle_simulateCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_simulateCS", wi::graphics::ShaderStage::CS},
{"generateMIPChainCubeCS_float4", wi::graphics::ShaderStage::CS},
{"generateMIPChainCubeArrayCS_float4", wi::graphics::ShaderStage::CS},
{"generateMIPChain3DCS_float4", wi::graphics::ShaderStage::CS},
{"generateMIPChain2DCS_float4", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC1", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC3", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC4", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC5", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC6H", wi::graphics::ShaderStage::CS},
{"blockcompressCS_BC6H_cubemap", wi::graphics::ShaderStage::CS},
{"blur_gaussian_float4CS", wi::graphics::ShaderStage::CS},
{"bloomseparateCS", wi::graphics::ShaderStage::CS},
{"depthoffield_mainCS", wi::graphics::ShaderStage::CS},
{"depthoffield_neighborhoodMaxCOCCS", wi::graphics::ShaderStage::CS},
{"depthoffield_prepassCS", wi::graphics::ShaderStage::CS},
{"depthoffield_upsampleCS", wi::graphics::ShaderStage::CS},
{"depthoffield_tileMaxCOC_verticalCS", wi::graphics::ShaderStage::CS},
{"depthoffield_tileMaxCOC_horizontalCS", wi::graphics::ShaderStage::CS},
{"vxgi_offsetprevCS", wi::graphics::ShaderStage::CS},
{"vxgi_temporalCS", wi::graphics::ShaderStage::CS},
{"vxgi_sdf_jumpfloodCS", wi::graphics::ShaderStage::CS},
{"vxgi_resolve_diffuseCS", wi::graphics::ShaderStage::CS},
{"vxgi_resolve_specularCS", wi::graphics::ShaderStage::CS},
{"upsample_bilateral_float1CS", wi::graphics::ShaderStage::CS},
{"upsample_bilateral_float4CS", wi::graphics::ShaderStage::CS},
{"temporalaaCS", wi::graphics::ShaderStage::CS},
{"tonemapCS", wi::graphics::ShaderStage::CS},
{"underwaterCS", wi::graphics::ShaderStage::CS},
{"mesh_blend_prepareCS", wi::graphics::ShaderStage::CS},
{"mesh_blend_expandCS", wi::graphics::ShaderStage::CS},
{"mesh_blendPS", wi::graphics::ShaderStage::PS},
{"fsr_upscalingCS", wi::graphics::ShaderStage::CS},
{"fsr_sharpenCS", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_autogen_reactive_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_compute_luminance_pyramid_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_prepare_input_color_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_reconstruct_previous_depth_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_depth_clip_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_lock_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_accumulate_pass", wi::graphics::ShaderStage::CS},
{"ffx-fsr2/ffx_fsr2_rcas_pass", wi::graphics::ShaderStage::CS},
{"ssaoCS", wi::graphics::ShaderStage::CS},
{"ssgi_deinterleaveCS", wi::graphics::ShaderStage::CS},
{"ssgiCS", wi::graphics::ShaderStage::CS},
{"ssgi_upsampleCS", wi::graphics::ShaderStage::CS},
{"rtdiffuseCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5},
{"rtdiffuse_spatialCS", wi::graphics::ShaderStage::CS},
{"rtdiffuse_temporalCS", wi::graphics::ShaderStage::CS},
{"rtdiffuse_upsampleCS", wi::graphics::ShaderStage::CS},
{"rtreflectionCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5},
{"ssr_tileMaxRoughness_horizontalCS", wi::graphics::ShaderStage::CS},
{"ssr_tileMaxRoughness_verticalCS", wi::graphics::ShaderStage::CS},
{"ssr_depthHierarchyCS", wi::graphics::ShaderStage::CS},
{"ssr_resolveCS", wi::graphics::ShaderStage::CS},
{"ssr_temporalCS", wi::graphics::ShaderStage::CS},
{"ssr_upsampleCS", wi::graphics::ShaderStage::CS},
{"ssr_raytraceCS", wi::graphics::ShaderStage::CS},
{"ssr_raytraceCS_cheap", wi::graphics::ShaderStage::CS},
{"ssr_raytraceCS_earlyexit", wi::graphics::ShaderStage::CS},
{"sharpenCS", wi::graphics::ShaderStage::CS},
{"crt_screenCS", wi::graphics::ShaderStage::CS},
{"skinningCS", wi::graphics::ShaderStage::CS},
{"resolveMSAADepthStencilCS", wi::graphics::ShaderStage::CS},
{"raytraceCS", wi::graphics::ShaderStage::CS},
{"raytraceCS_rtapi", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5},
{"paint_textureCS", wi::graphics::ShaderStage::CS},
{"oceanUpdateDisplacementMapCS", wi::graphics::ShaderStage::CS},
{"oceanUpdateGradientFoldingCS", wi::graphics::ShaderStage::CS},
{"oceanSimulatorCS", wi::graphics::ShaderStage::CS},
{"msao_interleaveCS", wi::graphics::ShaderStage::CS},
{"msao_preparedepthbuffers1CS", wi::graphics::ShaderStage::CS},
{"msao_preparedepthbuffers2CS", wi::graphics::ShaderStage::CS},
{"msao_blurupsampleCS", wi::graphics::ShaderStage::CS},
{"msao_blurupsampleCS_blendout", wi::graphics::ShaderStage::CS},
{"msao_blurupsampleCS_premin", wi::graphics::ShaderStage::CS},
{"msao_blurupsampleCS_premin_blendout", wi::graphics::ShaderStage::CS},
{"msaoCS", wi::graphics::ShaderStage::CS},
{"motionblur_neighborhoodMaxVelocityCS", wi::graphics::ShaderStage::CS},
{"motionblur_tileMaxVelocity_horizontalCS", wi::graphics::ShaderStage::CS},
{"motionblur_tileMaxVelocity_verticalCS", wi::graphics::ShaderStage::CS},
{"luminancePass2CS", wi::graphics::ShaderStage::CS},
{"motionblurCS", wi::graphics::ShaderStage::CS},
{"motionblurCS_cheap", wi::graphics::ShaderStage::CS},
{"motionblurCS_earlyexit", wi::graphics::ShaderStage::CS},
{"luminancePass1CS", wi::graphics::ShaderStage::CS},
{"lightShaftsCS", wi::graphics::ShaderStage::CS},
{"hbaoCS", wi::graphics::ShaderStage::CS},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_COUNT"}}, "FPS_Count"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_COUNT_REDUCE"}}, "FPS_CountReduce"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_SCAN"}}, "FPS_Scan"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_SCAN_ADD"}}, "FPS_ScanAdd"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_SCATTER"}}, "FPS_Scatter"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_SCATTER", "kRS_ValueCopy"}}, "FPS_Scatter"},
{"radix_sortCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_0, {{"FPS_INDIRECT"}}, "FPS_SetupIndirectParameters"},
{"fxaaCS", wi::graphics::ShaderStage::CS},
{"filterEnvMapCS", wi::graphics::ShaderStage::CS},
{"fft_512x512_c2c_CS", wi::graphics::ShaderStage::CS},
{"fft_512x512_c2c_v2_CS", wi::graphics::ShaderStage::CS},
{"emittedparticle_sphpartitionCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_sphcellallocationCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_sphbinningCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_simulateCS_SORTING", wi::graphics::ShaderStage::CS},
{"emittedparticle_simulateCS_SORTING_DEPTHCOLLISIONS", wi::graphics::ShaderStage::CS},
{"emittedparticle_sphdensityCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_sphforceCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_kickoffUpdateCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_simulateCS_DEPTHCOLLISIONS", wi::graphics::ShaderStage::CS},
{"emittedparticle_emitCS", wi::graphics::ShaderStage::CS},
{"emittedparticle_emitCS_FROMMESH", wi::graphics::ShaderStage::CS},
{"emittedparticle_emitCS_volume", wi::graphics::ShaderStage::CS},
{"emittedparticle_finishUpdateCS", wi::graphics::ShaderStage::CS},
{"downsample4xCS", wi::graphics::ShaderStage::CS},
{"lineardepthCS", wi::graphics::ShaderStage::CS},
{"depthoffield_prepassCS_earlyexit", wi::graphics::ShaderStage::CS},
{"depthoffield_mainCS_cheap", wi::graphics::ShaderStage::CS},
{"depthoffield_mainCS_earlyexit", wi::graphics::ShaderStage::CS },
{"depthoffield_postfilterCS", wi::graphics::ShaderStage::CS },
{"copytexture2D_float4_borderexpandCS", wi::graphics::ShaderStage::CS },
{"copytexture2D_float4CS", wi::graphics::ShaderStage::CS },
{"chromatic_aberrationCS", wi::graphics::ShaderStage::CS },
{"bvh_hierarchyCS", wi::graphics::ShaderStage::CS },
{"bvh_primitivesCS", wi::graphics::ShaderStage::CS },
{"bvh_propagateaabbCS", wi::graphics::ShaderStage::CS },
{"blur_gaussian_wide_float1CS", wi::graphics::ShaderStage::CS },
{"blur_gaussian_wide_float4CS", wi::graphics::ShaderStage::CS },
{"blur_gaussian_float1CS", wi::graphics::ShaderStage::CS },
{"blur_bilateral_wide_float1CS", wi::graphics::ShaderStage::CS },
{"blur_bilateral_wide_float4CS", wi::graphics::ShaderStage::CS },
{"blur_bilateral_float1CS", wi::graphics::ShaderStage::CS },
{"blur_bilateral_float4CS", wi::graphics::ShaderStage::CS },
{"normalsfromdepthCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_curlnoiseCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_detailnoiseCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_renderCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_renderCS_capture", wi::graphics::ShaderStage::CS },
{"volumetricCloud_reprojectCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_shadow_renderCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_shapenoiseCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_upsamplePS", wi::graphics::ShaderStage::PS },
{"volumetricCloud_weathermapCS", wi::graphics::ShaderStage::CS },
{"shadingRateClassificationCS", wi::graphics::ShaderStage::CS },
{"shadingRateClassificationCS_DEBUG", wi::graphics::ShaderStage::CS },
{"aerialPerspectiveCS", wi::graphics::ShaderStage::CS },
{"skyAtmosphere_cameraVolumeLutCS", wi::graphics::ShaderStage::CS },
{"skyAtmosphere_transmittanceLutCS", wi::graphics::ShaderStage::CS },
{"skyAtmosphere_skyViewLutCS", wi::graphics::ShaderStage::CS },
{"skyAtmosphere_multiScatteredLuminanceLutCS", wi::graphics::ShaderStage::CS },
{"skyAtmosphere_skyLuminanceLutCS", wi::graphics::ShaderStage::CS },
{"screenspaceshadowCS", wi::graphics::ShaderStage::CS },
{"rtshadowCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5 },
{"rtshadow_denoise_tileclassificationCS", wi::graphics::ShaderStage::CS },
{"rtshadow_denoise_filterCS", wi::graphics::ShaderStage::CS },
{"rtshadow_denoise_temporalCS", wi::graphics::ShaderStage::CS },
{"rtshadow_upsampleCS", wi::graphics::ShaderStage::CS },
{"rtaoCS", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5 },
{"rtao_denoise_tileclassificationCS", wi::graphics::ShaderStage::CS },
{"rtao_denoise_filterCS", wi::graphics::ShaderStage::CS },
{"visibility_resolveCS", wi::graphics::ShaderStage::CS },
{"visibility_resolveCS_MSAA", wi::graphics::ShaderStage::CS },
{"visibility_velocityCS", wi::graphics::ShaderStage::CS },
{"visibility_skyCS", wi::graphics::ShaderStage::CS },
{"surfel_coverageCS", wi::graphics::ShaderStage::CS },
{"surfel_indirectprepareCS", wi::graphics::ShaderStage::CS },
{"surfel_updateCS", wi::graphics::ShaderStage::CS },
{"surfel_gridoffsetsCS", wi::graphics::ShaderStage::CS },
{"surfel_binningCS", wi::graphics::ShaderStage::CS },
{"surfel_raytraceCS_rtapi", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5 },
{"surfel_raytraceCS", wi::graphics::ShaderStage::CS },
{"surfel_integrateCS", wi::graphics::ShaderStage::CS },
{"ddgi_rayallocationCS", wi::graphics::ShaderStage::CS },
{"ddgi_indirectprepareCS", wi::graphics::ShaderStage::CS },
{"ddgi_raytraceCS", wi::graphics::ShaderStage::CS },
{"ddgi_raytraceCS_rtapi", wi::graphics::ShaderStage::CS, wi::graphics::ShaderModel::SM_6_5 },
{"ddgi_updateCS", wi::graphics::ShaderStage::CS },
{"ddgi_updateCS_depth", wi::graphics::ShaderStage::CS },
{"terrainVirtualTextureUpdateCS", wi::graphics::ShaderStage::CS },
{"terrainVirtualTextureUpdateCS_normalmap", wi::graphics::ShaderStage::CS },
{"terrainVirtualTextureUpdateCS_surfacemap", wi::graphics::ShaderStage::CS },
{"terrainVirtualTextureUpdateCS_emissivemap", wi::graphics::ShaderStage::CS },
{"meshlet_prepareCS", wi::graphics::ShaderStage::CS },
{"impostor_prepareCS", wi::graphics::ShaderStage::CS },
{"virtualTextureTileRequestsCS", wi::graphics::ShaderStage::CS },
{"virtualTextureTileAllocateCS", wi::graphics::ShaderStage::CS },
{"virtualTextureResidencyUpdateCS", wi::graphics::ShaderStage::CS },
{"windCS", wi::graphics::ShaderStage::CS },
{"yuv_to_rgbCS", wi::graphics::ShaderStage::CS },
{"wetmap_updateCS", wi::graphics::ShaderStage::CS },
{"causticsCS", wi::graphics::ShaderStage::CS },
{"depth_reprojectCS", wi::graphics::ShaderStage::CS },
{"depth_pyramidCS", wi::graphics::ShaderStage::CS },
{"lightmap_expandCS", wi::graphics::ShaderStage::CS },
{"gaussian_splatCS", wi::graphics::ShaderStage::CS },
{"gaussian_splat_indirectCS", wi::graphics::ShaderStage::CS },
{"imagePS", wi::graphics::ShaderStage::PS },
{"emittedparticlePS_soft", wi::graphics::ShaderStage::PS },
{"emittedparticlePS_shadow", wi::graphics::ShaderStage::PS },
{"emittedparticlePS_soft_lighting", wi::graphics::ShaderStage::PS },
{"oceanSurfacePS", wi::graphics::ShaderStage::PS },
{"oceanSurfacePS_envmap", wi::graphics::ShaderStage::PS },
{"hairparticlePS", wi::graphics::ShaderStage::PS },
{"hairparticlePS_simple", wi::graphics::ShaderStage::PS },
{"hairparticlePS_prepass", wi::graphics::ShaderStage::PS },
{"hairparticlePS_prepass_depthonly", wi::graphics::ShaderStage::PS },
{"hairparticlePS_shadow", wi::graphics::ShaderStage::PS },
{"volumetricLight_SpotPS", wi::graphics::ShaderStage::PS },
{"volumetricLight_PointPS", wi::graphics::ShaderStage::PS },
{"volumetricLight_DirectionalPS", wi::graphics::ShaderStage::PS },
{"volumetriclight_rectanglePS", wi::graphics::ShaderStage::PS },
{"voxelPS", wi::graphics::ShaderStage::PS },
{"vertexcolorPS", wi::graphics::ShaderStage::PS },
{"upsample_bilateralPS", wi::graphics::ShaderStage::PS },
{"sunPS", wi::graphics::ShaderStage::PS },
{"skyPS_dynamic", wi::graphics::ShaderStage::PS },
{"skyPS_static", wi::graphics::ShaderStage::PS },
{"shadowPS_transparent", wi::graphics::ShaderStage::PS },
{"shadowPS_water", wi::graphics::ShaderStage::PS },
{"shadowPS_alphatest", wi::graphics::ShaderStage::PS },
{"paintdecalPS", wi::graphics::ShaderStage::PS },
{"renderlightmapPS", wi::graphics::ShaderStage::PS },
{"renderlightmapPS_rtapi", wi::graphics::ShaderStage::PS, wi::graphics::ShaderModel::SM_6_5 },
{"raytrace_debugbvhPS", wi::graphics::ShaderStage::PS },
{"outlinePS", wi::graphics::ShaderStage::PS },
{"oceanSurfaceSimplePS", wi::graphics::ShaderStage::PS },
{"objectPS_voxelizer", wi::graphics::ShaderStage::PS },
{"objectPS_hologram", wi::graphics::ShaderStage::PS },
{"objectPS_paintradius", wi::graphics::ShaderStage::PS },
{"objectPS_simple", wi::graphics::ShaderStage::PS },
{"objectPS_debug", wi::graphics::ShaderStage::PS },
{"objectPS_prepass", wi::graphics::ShaderStage::PS },
{"objectPS_prepass_alphatest", wi::graphics::ShaderStage::PS },
{"objectPS_prepass_depthonly_alphatest", wi::graphics::ShaderStage::PS },
{"lightVisualizerPS", wi::graphics::ShaderStage::PS },
{"vRectLightPS", wi::graphics::ShaderStage::PS },
{"lensFlarePS", wi::graphics::ShaderStage::PS },
{"impostorPS", wi::graphics::ShaderStage::PS },
{"impostorPS_simple", wi::graphics::ShaderStage::PS },
{"impostorPS_prepass", wi::graphics::ShaderStage::PS },
{"impostorPS_prepass_depthonly", wi::graphics::ShaderStage::PS },
{"forceFieldVisualizerPS", wi::graphics::ShaderStage::PS },
{"fontPS", wi::graphics::ShaderStage::PS },
{"envMap_skyPS_static", wi::graphics::ShaderStage::PS },
{"envMap_skyPS_dynamic", wi::graphics::ShaderStage::PS },
{"envMapPS", wi::graphics::ShaderStage::PS },
{"emittedparticlePS_soft_distortion", wi::graphics::ShaderStage::PS },
{"downsampleDepthBuffer4xPS", wi::graphics::ShaderStage::PS },
{"emittedparticlePS_simple", wi::graphics::ShaderStage::PS },
{"cubeMapPS", wi::graphics::ShaderStage::PS },
{"circlePS", wi::graphics::ShaderStage::PS },
{"captureImpostorPS", wi::graphics::ShaderStage::PS },
{"ddgi_debugPS", wi::graphics::ShaderStage::PS },
{"copyDepthPS", wi::graphics::ShaderStage::PS },
{"copyStencilBitPS", wi::graphics::ShaderStage::PS },
{"extractStencilBitPS", wi::graphics::ShaderStage::PS },
{"trailPS", wi::graphics::ShaderStage::PS },
{"waveeffectPS", wi::graphics::ShaderStage::PS },
{"gaussian_splatPS", wi::graphics::ShaderStage::PS },
{"hairparticleVS", wi::graphics::ShaderStage::VS },
{"emittedparticleVS", wi::graphics::ShaderStage::VS },
{"emittedparticleVS_shadow", wi::graphics::ShaderStage::VS },
{"imageVS", wi::graphics::ShaderStage::VS },
{"fontVS", wi::graphics::ShaderStage::VS },
{"voxelVS", wi::graphics::ShaderStage::VS },
{"vertexcolorVS", wi::graphics::ShaderStage::VS },
{"volumetriclight_directionalVS", wi::graphics::ShaderStage::VS },
{"volumetriclight_pointVS", wi::graphics::ShaderStage::VS },
{"volumetriclight_spotVS", wi::graphics::ShaderStage::VS },
{"volumetriclight_rectangleVS", wi::graphics::ShaderStage::VS },
{"vSpotLightVS", wi::graphics::ShaderStage::VS },
{"vPointLightVS", wi::graphics::ShaderStage::VS },
{"vRectLightVS", wi::graphics::ShaderStage::VS },
{"sphereVS", wi::graphics::ShaderStage::VS },
{"skyVS", wi::graphics::ShaderStage::VS },
{"postprocessVS", wi::graphics::ShaderStage::VS },
{"paintdecalVS", wi::graphics::ShaderStage::VS },
{"renderlightmapVS", wi::graphics::ShaderStage::VS },
{"raytrace_screenVS", wi::graphics::ShaderStage::VS },
{"oceanSurfaceVS", wi::graphics::ShaderStage::VS },
{"objectVS_debug", wi::graphics::ShaderStage::VS },
{"objectVS_voxelizer", wi::graphics::ShaderStage::VS },
{"lensFlareVS", wi::graphics::ShaderStage::VS },
{"impostorVS", wi::graphics::ShaderStage::VS },
{"forceFieldPointVisualizerVS", wi::graphics::ShaderStage::VS },
{"forceFieldPlaneVisualizerVS", wi::graphics::ShaderStage::VS },
{"envMap_skyVS", wi::graphics::ShaderStage::VS },
{"envMapVS", wi::graphics::ShaderStage::VS },
{"occludeeVS", wi::graphics::ShaderStage::VS },
{"ddgi_debugVS", wi::graphics::ShaderStage::VS },
{"voxelGS", wi::graphics::ShaderStage::GS },
{"objectGS_voxelizer", wi::graphics::ShaderStage::GS },
{"objectVS_simple", wi::graphics::ShaderStage::VS },
{"objectVS_common", wi::graphics::ShaderStage::VS },
{"objectVS_common_tessellation", wi::graphics::ShaderStage::VS },
{"objectVS_prepass", wi::graphics::ShaderStage::VS },
{"objectVS_prepass_alphatest", wi::graphics::ShaderStage::VS },
{"objectVS_prepass_tessellation", wi::graphics::ShaderStage::VS },
{"objectVS_simple_tessellation", wi::graphics::ShaderStage::VS },
{"shadowVS", wi::graphics::ShaderStage::VS },
{"shadowVS_alphatest", wi::graphics::ShaderStage::VS },
{"shadowVS_transparent", wi::graphics::ShaderStage::VS },
{"screenVS", wi::graphics::ShaderStage::VS },
{"voxelgridVS", wi::graphics::ShaderStage::VS },
{"trailVS", wi::graphics::ShaderStage::VS },
{"gaussian_splatVS", wi::graphics::ShaderStage::VS },
{"objectDS", wi::graphics::ShaderStage::DS },
{"objectDS_prepass", wi::graphics::ShaderStage::DS },
{"objectDS_simple", wi::graphics::ShaderStage::DS },
{"objectHS", wi::graphics::ShaderStage::HS },
{"objectHS_prepass", wi::graphics::ShaderStage::HS },
{"objectHS_simple", wi::graphics::ShaderStage::HS },
{"emittedparticleMS", wi::graphics::ShaderStage::MS },
{"objectMS", wi::graphics::ShaderStage::MS },
{"objectMS_prepass", wi::graphics::ShaderStage::MS },
{"objectMS_prepass_alphatest", wi::graphics::ShaderStage::MS },
{"objectMS_simple", wi::graphics::ShaderStage::MS },
{"shadowMS", wi::graphics::ShaderStage::MS },
{"shadowMS_alphatest", wi::graphics::ShaderStage::MS },
{"shadowMS_transparent", wi::graphics::ShaderStage::MS },
{"objectAS", wi::graphics::ShaderStage::AS },
//{"rtreflectionLIB", wi::graphics::ShaderStage::LIB },
};
struct Target
{
wi::graphics::ShaderFormat format;
std::string dir;
};
wi::vector<Target> targets;
wi::unordered_map<std::string, wi::shadercompiler::CompilerOutput> results;
bool rebuild = false;
bool shaderdump_enabled = false;
using namespace wi::graphics;
std::ostream nullout(&nullbuf);
int main(int argc, char* argv[])
{
wi::shadercompiler::Flags compile_flags = wi::shadercompiler::Flags::NONE;
wi::arguments::Parse(argc, argv);
std::ostream* out;
if (wi::arguments::HasArgument("quiet"))
{
wi::backlog::SetLogLevel(wi::backlog::LogLevel::Error);
out = &nullout;
}
else
{
out = &std::cout;
}
*out << "[HMMWV4 Offline Shader Compiler]\n";
*out << "Available command arguments:\n";
*out << "\thlsl5 : \t\tCompile shaders to hlsl5 (dx11) format (using d3dcompiler)\n";
*out << "\thlsl6 : \t\tCompile shaders to hlsl6 (dx12) format (using dxcompiler)\n";
*out << "\tspirv : \t\tCompile shaders to spirv (vulkan) format (using dxcompiler)\n";
*out << "\tmetal : \t\tCompile shaders to Apple Metal format (using dxcompiler and metal shader converter)\n";
*out << "\thlsl6_xs : \t\tCompile shaders to hlsl6 Xbox Series native (dx12) format (requires Xbox SDK)\n";
*out << "\tps5 : \t\t\tCompile shaders to PlayStation 5 native format (requires PlayStation 5 SDK)\n";
*out << "\trebuild : \t\tAll shaders will be rebuilt, regardless if they are outdated or not\n";
*out << "\tdisable_optimization : \tShaders will be compiled without optimizations\n";
*out << "\tstrip_reflection : \tReflection will be stripped from shader binary to reduce file size\n";
*out << "\tshaderdump : \t\tShaders will be saved to wiShaderDump.h C++ header file (can be combined with \"rebuild\")\n";
*out << "\tdebuginfo : \t\tKeep symbol data for shader debugging\n";
*out << "\tquiet : \t\tOnly print errors\n";
*out << "\tsm6.1 : \t\tIncrease all compilations to shader model 6.1\n";
*out << "\tsm6.2 : \t\tIncrease all compilations to shader model 6.2\n";
*out << "\tsm6.3 : \t\tIncrease all compilations to shader model 6.3\n";
*out << "\tsm6.4 : \t\tIncrease all compilations to shader model 6.4\n";
*out << "\tsm6.5 : \t\tIncrease all compilations to shader model 6.5\n";
*out << "\tsm6.6 : \t\tIncrease all compilations to shader model 6.6\n";
*out << "Command arguments used: ";
if (wi::arguments::HasArgument("hlsl5"))
{
targets.push_back({ ShaderFormat::HLSL5, "shaders/hlsl5/" });
*out << "hlsl5 ";
}
if (wi::arguments::HasArgument("hlsl6"))
{
targets.push_back({ ShaderFormat::HLSL6, "shaders/hlsl6/" });
*out << "hlsl6 ";
}
if (wi::arguments::HasArgument("spirv"))
{
targets.push_back({ ShaderFormat::SPIRV, "shaders/spirv/" });
*out << "spirv ";
}
if (wi::arguments::HasArgument("metal"))
{
targets.push_back({ ShaderFormat::METAL, "shaders/metal/" });
*out << "metal ";
}
if (wi::arguments::HasArgument("hlsl6_xs"))
{
targets.push_back({ ShaderFormat::HLSL6_XS, "shaders/hlsl6_xs/" });
*out << "hlsl6_xs ";
}
if (wi::arguments::HasArgument("ps5"))
{
targets.push_back({ ShaderFormat::PS5, "shaders/ps5/" });
*out << "ps5 ";
}
if (wi::arguments::HasArgument("shaderdump"))
{
shaderdump_enabled = true;
*out << "shaderdump ";
}
if (wi::arguments::HasArgument("rebuild"))
{
rebuild = true;
*out << "rebuild ";
}
if (wi::arguments::HasArgument("disable_optimization"))
{
compile_flags |= wi::shadercompiler::Flags::DISABLE_OPTIMIZATION;
*out << "disable_optimization ";
}
if (wi::arguments::HasArgument("debuginfo"))
{
compile_flags |= wi::shadercompiler::Flags::KEEP_DEBUG_INFORMATION;
*out << "debuginfo ";
}
if (wi::arguments::HasArgument("strip_reflection"))
{
compile_flags |= wi::shadercompiler::Flags::STRIP_REFLECTION;
*out << "strip_reflection ";
}
ShaderModel minshadermodel_override = ShaderModel::SM_5_0;
if (wi::arguments::HasArgument("sm6.1"))
{
minshadermodel_override = ShaderModel::SM_6_1;
*out << "sm6.1 ";
}
if (wi::arguments::HasArgument("sm6.2"))
{
minshadermodel_override = ShaderModel::SM_6_2;
*out << "sm6.2 ";
}
if (wi::arguments::HasArgument("sm6.3"))
{
minshadermodel_override = ShaderModel::SM_6_3;
*out << "sm6.3 ";
}
if (wi::arguments::HasArgument("sm6.4"))
{
minshadermodel_override = ShaderModel::SM_6_4;
*out << "sm6.4 ";
}
if (wi::arguments::HasArgument("sm6.5"))
{
minshadermodel_override = ShaderModel::SM_6_5;
*out << "sm6.5 ";
}
if (wi::arguments::HasArgument("sm6.6"))
{
minshadermodel_override = ShaderModel::SM_6_6;
*out << "sm6.6 ";
}
if (wi::arguments::HasArgument("sm6.7"))
{
minshadermodel_override = ShaderModel::SM_6_7;
*out << "sm6.7 ";
}
*out << "\n";
if (targets.empty())
{
targets = {
#ifdef __APPLE__
{ ShaderFormat::METAL, "shaders/metal/" },
#else
//{ ShaderFormat::HLSL5, "shaders/hlsl5/" },
{ ShaderFormat::HLSL6, "shaders/hlsl6/" },
{ ShaderFormat::SPIRV, "shaders/spirv/" },
#endif // __APPLE__
};
*out << "No shader formats were specified, assuming command arguments: spirv hlsl6\n";
}
// permutations for objectPS:
shaders.push_back({ "objectPS", wi::graphics::ShaderStage::PS });
for (auto& x : wi::scene::MaterialComponent::shaderTypeDefines)
{
shaders.back().permutations.emplace_back().defines = x;
// same but with TRANSPARENT:
shaders.back().permutations.emplace_back().defines = x;
shaders.back().permutations.back().defines.push_back("TRANSPARENT");
}
// permutations for visibility_surfaceCS:
shaders.push_back({ "visibility_surfaceCS", wi::graphics::ShaderStage::CS });
for (auto& x : wi::scene::MaterialComponent::shaderTypeDefines)
{
shaders.back().permutations.emplace_back().defines = x;
}
// permutations for visibility_surfaceCS REDUCED:
shaders.push_back({ "visibility_surfaceCS", wi::graphics::ShaderStage::CS });
for (auto& x : wi::scene::MaterialComponent::shaderTypeDefines)
{
auto defines = x;
defines.push_back("REDUCED");
shaders.back().permutations.emplace_back().defines = defines;
}
// permutations for visibility_shadeCS:
shaders.push_back({ "visibility_shadeCS", wi::graphics::ShaderStage::CS });
for (auto& x : wi::scene::MaterialComponent::shaderTypeDefines)
{
shaders.back().permutations.emplace_back().defines = x;
}
// permutations for ssgiCS:
shaders.push_back({ "ssgiCS", wi::graphics::ShaderStage::CS });
shaders.back().permutations.emplace_back().defines = { "WIDE" };
// permutations for ssgi_upsampleCS:
shaders.push_back({ "ssgi_upsampleCS", wi::graphics::ShaderStage::CS });
shaders.back().permutations.emplace_back().defines = { "WIDE" };
// permutations for copyStencilBitPS:
shaders.push_back({ "copyStencilBitPS", wi::graphics::ShaderStage::PS });
shaders.back().permutations.emplace_back().defines = { "MSAA" };
// permutations for yuv_to_rgbCS:
shaders.push_back({ "yuv_to_rgbCS", wi::graphics::ShaderStage::CS });
shaders.back().permutations.emplace_back().defines = { "ARRAY" };
// permutations for lightCullingCS:
shaders.push_back({ "lightCullingCS", wi::graphics::ShaderStage::CS });
shaders.back().permutations.emplace_back().defines = {};
shaders.back().permutations.emplace_back().defines = { "DEBUG" };
shaders.back().permutations.emplace_back().defines = { "ADVANCED" };
shaders.back().permutations.emplace_back().defines = { "ADVANCED", "DEBUG" };
// Simplify permutation iteration:
for (auto& shader : shaders)
{
if (shader.permutations.empty())
{
shader.permutations.emplace_back();
}
}
wi::jobsystem::Initialize();
wi::jobsystem::context ctx;
static std::string SHADERSOURCEPATH = wi::renderer::GetShaderSourcePath();
wi::helper::MakePathAbsolute(SHADERSOURCEPATH);
*out << "[HMMWV4 Offline Shader Compiler] Searching for outdated shaders...\n";
wi::Timer timer;
static int errors = 0;
for (auto& target : targets)
{
std::string SHADERPATH = target.dir;
wi::helper::DirectoryCreate(SHADERPATH);
for (auto& shader : shaders)
{
if (target.format == ShaderFormat::HLSL5)
{
if (
shader.stage == ShaderStage::MS ||
shader.stage == ShaderStage::AS ||
shader.stage == ShaderStage::LIB
)
{
// shader stage not applicable to HLSL5
continue;
}
}
for (auto& permutation : shader.permutations)
{
wi::jobsystem::Execute(ctx, [&target, &permutation, &shader, &out, SHADERPATH, compile_flags, minshadermodel_override](wi::jobsystem::JobArgs args) {
std::string shaderbinaryfilename = SHADERPATH + shader.name;
for (auto& def : permutation.defines)
{
shaderbinaryfilename += "_" + def;
}
shaderbinaryfilename += ".cso";
wi::shadercompiler::CompilerOutput output;
if (!wi::shadercompiler::IsShaderOutdated(shaderbinaryfilename))
{
if (!rebuild)
{
if (shaderdump_enabled)
{
auto vec = wi::allocator::make_shared<std::vector<uint8_t>>();
if (wi::helper::FileRead(shaderbinaryfilename, *vec))
{
output.internal_state = vec;
output.shaderdata = vec->data();
output.shadersize = vec->size();
locker.lock();
results[shaderbinaryfilename] = output;
*out << "up-to-date: " << shaderbinaryfilename << std::endl;
locker.unlock();
}
else
{
locker.lock();
std::cerr << "ERROR reading binary shader: " << shaderbinaryfilename << std::endl;
locker.unlock();
}
}
return;
}
}
wi::shadercompiler::CompilerInput input;
input.entrypoint = shader.entrypoint;
input.flags = compile_flags;
input.format = target.format;
input.stage = shader.stage;
input.shadersourcefilename = SHADERSOURCEPATH + shader.name + ".hlsl";
input.include_directories.push_back(SHADERSOURCEPATH);
input.include_directories.push_back(SHADERSOURCEPATH + wi::helper::GetDirectoryFromPath(shader.name));
input.minshadermodel = std::max(shader.minshadermodel, minshadermodel_override);
input.defines = permutation.defines;
if (input.minshadermodel > ShaderModel::SM_5_0 && target.format == ShaderFormat::HLSL5)
{
// if shader format cannot support shader model, then we cancel the task without returning error
return;
}
if (target.format == ShaderFormat::PS5 && (input.minshadermodel >= ShaderModel::SM_6_5 || input.stage == ShaderStage::MS || input.stage == ShaderStage::AS))
{
// TODO PS5 raytracing, mesh shader
return;
}
if (target.format == ShaderFormat::HLSL6_XS && (input.stage == ShaderStage::MS || input.stage == ShaderStage::AS))
{
// TODO Xbox mesh shader
return;
}
wi::shadercompiler::Compile(input, output);
if (output.IsValid())
{
wi::shadercompiler::SaveShaderAndMetadata(shaderbinaryfilename, output);
locker.lock();
if (!output.error_message.empty())
{
std::cerr << output.error_message << "\n";
}
*out << "shader compiled: " << shaderbinaryfilename << "\n";
if (shaderdump_enabled)
{
results[shaderbinaryfilename] = output;
}
locker.unlock();
}
else
{
locker.lock();
std::cerr << "shader compile FAILED: " << shaderbinaryfilename << "\n" << output.error_message;
errors++;
locker.unlock();
}
});
}
}
}
wi::jobsystem::Wait(ctx);
*out << "[HMMWV4 Offline Shader Compiler] Finished in " << std::setprecision(4) << timer.elapsed_seconds() << " seconds with " << errors << " errors\n";
if (shaderdump_enabled)
{
*out << "[HMMWV4 Offline Shader Compiler] Creating ShaderDump...\n";
timer.record();
size_t total_raw = 0;
size_t total_compressed = 0;
std::string ss;
ss += "namespace wiShaderDump {\n";
for (auto& x : results)
{
auto& name = x.first;
auto& output = x.second;
wi::vector<uint8_t> compressed;
bool success = wi::helper::Compress(output.shaderdata, output.shadersize, compressed, 9);
if (success) {
total_raw += output.shadersize;
total_compressed += compressed.size();
}
else
{
wi::helper::DebugOut("Compression failed while creating shader dump!", wi::helper::DebugLevel::Error);
continue;
}
std::string name_repl = name;
std::replace(name_repl.begin(), name_repl.end(), '/', '_');
std::replace(name_repl.begin(), name_repl.end(), '.', '_');
std::replace(name_repl.begin(), name_repl.end(), '-', '_');
ss += "static const uint8_t " + name_repl + "[] = {";
for (size_t i = 0; i < compressed.size(); ++i)
{
ss += std::to_string((uint32_t)compressed[i]) + ",";
}
ss += "};\n";
}
*out << "[HMMWV4 Offline Shader Compiler] Compressed shaders: " << total_raw << " -> " << total_compressed << " (" << std::setprecision(3) << (100. * total_compressed / total_raw) << "%)" << std::endl;
ss += "struct ShaderDumpEntry{const uint8_t* data; size_t size;};\n";
ss += "static const wi::unordered_map<std::string, ShaderDumpEntry> shaderdump = {\n";
for (auto& x : results)
{
auto& name = x.first;
std::string name_repl = name;
std::replace(name_repl.begin(), name_repl.end(), '/', '_');
std::replace(name_repl.begin(), name_repl.end(), '.', '_');
std::replace(name_repl.begin(), name_repl.end(), '-', '_');
ss += "{\"" + name + "\", {" + name_repl + ",sizeof(" + name_repl + ")}},\n";
}
ss += "};\n"; // map end
ss += "}\n"; // namespace end
wi::helper::FileWrite("wiShaderDump.h", (uint8_t*)ss.c_str(), ss.length());
*out << "[HMMWV4 Offline Shader Compiler] ShaderDump written to wiShaderDump.h in " << std::setprecision(4) << timer.elapsed_seconds() << " seconds\n";
}
wi::jobsystem::ShutDown();
return errors;
}