forked from ValveSoftware/Fossilize
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fossilize.cpp
9028 lines (7707 loc) · 302 KB
/
fossilize.cpp
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
/* Copyright (c) 2018-2019 Hans-Kristian Arntzen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <stddef.h>
#include "fossilize_inttypes.h"
#include "fossilize.hpp"
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <string.h>
#include <stdarg.h>
#include "varint.hpp"
#include "path.hpp"
#include "fossilize_db.hpp"
#include "layer/utils.hpp"
#include "fossilize_errors.hpp"
#include "fossilize_application_filter.hpp"
#include "fossilize_hasher.hpp"
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/writer.h"
using namespace rapidjson;
#ifdef PRETTY_WRITER
using CustomWriter = PrettyWriter<StringBuffer>;
#else
using CustomWriter = Writer<StringBuffer>;
#endif
using namespace std;
namespace Fossilize
{
static const void *pnext_chain_skip_ignored_entries(const void *pNext);
static const void *pnext_chain_pdf2_skip_ignored_entries(const void *pNext);
template <typename T>
static const T *find_pnext(VkStructureType sType, const void *pNext)
{
while (pNext)
{
auto *base_in = static_cast<const VkBaseInStructure *>(pNext);
if (base_in->sType == sType)
return static_cast<const T *>(pNext);
pNext = base_in->pNext;
}
return nullptr;
}
template <typename T>
struct HashedInfo
{
Hash hash;
T info;
};
template <typename Allocator>
static Value uint64_string(uint64_t value, Allocator &alloc)
{
char str[17]; // 16 digits + null
sprintf(str, "%016" PRIx64, value);
return Value(str, alloc);
}
struct GlobalStateInfo
{
bool input_assembly;
bool tessellation_state;
bool viewport_state;
bool multisample_state;
bool depth_stencil_state;
bool color_blend_state;
bool vertex_input;
};
struct DynamicStateInfo
{
bool stencil_compare;
bool stencil_reference;
bool stencil_write_mask;
bool depth_bounds;
bool depth_bias;
bool line_width;
bool blend_constants;
bool scissor;
bool viewport;
bool scissor_count;
bool viewport_count;
bool cull_mode;
bool front_face;
// Primitive topology isn't fully dynamic, so we need to hash it.
bool depth_test_enable;
bool depth_write_enable;
bool depth_compare_op;
bool depth_bounds_test_enable;
bool stencil_test_enable;
bool stencil_op;
bool vertex_input;
bool vertex_input_binding_stride;
bool patch_control_points;
bool rasterizer_discard_enable;
bool primitive_restart_enable;
bool logic_op;
bool color_write_enable;
bool depth_bias_enable;
bool discard_rectangle;
bool fragment_shading_rate;
};
struct StateReplayer::Impl
{
bool parse(StateCreatorInterface &iface, DatabaseInterface *resolver, const void *buffer, size_t size) FOSSILIZE_WARN_UNUSED;
ScratchAllocator allocator;
std::unordered_map<Hash, VkSampler> replayed_samplers;
std::unordered_map<Hash, VkDescriptorSetLayout> replayed_descriptor_set_layouts;
std::unordered_map<Hash, VkPipelineLayout> replayed_pipeline_layouts;
std::unordered_map<Hash, VkShaderModule> replayed_shader_modules;
std::unordered_map<Hash, VkRenderPass> replayed_render_passes;
std::unordered_map<Hash, VkPipeline> replayed_compute_pipelines;
std::unordered_map<Hash, VkPipeline> replayed_graphics_pipelines;
std::unordered_map<Hash, VkPipeline> replayed_raytracing_pipelines;
void copy_handle_references(const Impl &impl);
void forget_handle_references();
bool parse_samplers(StateCreatorInterface &iface, const Value &samplers) FOSSILIZE_WARN_UNUSED;
bool parse_descriptor_set_layouts(StateCreatorInterface &iface, const Value &layouts) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_layouts(StateCreatorInterface &iface, const Value &layouts) FOSSILIZE_WARN_UNUSED;
bool parse_shader_modules(StateCreatorInterface &iface, const Value &modules, const uint8_t *varint, size_t varint_size) FOSSILIZE_WARN_UNUSED;
bool parse_render_passes(StateCreatorInterface &iface, const Value &passes) FOSSILIZE_WARN_UNUSED;
bool parse_render_passes2(StateCreatorInterface &iface, const Value &passes) FOSSILIZE_WARN_UNUSED;
bool parse_compute_pipelines(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines) FOSSILIZE_WARN_UNUSED;
bool parse_graphics_pipelines(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines) FOSSILIZE_WARN_UNUSED;
bool parse_raytracing_pipelines(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines) FOSSILIZE_WARN_UNUSED;
bool parse_compute_pipeline(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines, const Value &member) FOSSILIZE_WARN_UNUSED;
bool parse_graphics_pipeline(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines, const Value &member) FOSSILIZE_WARN_UNUSED;
bool parse_raytracing_pipeline(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &pipelines, const Value &member) FOSSILIZE_WARN_UNUSED;
bool parse_application_info(StateCreatorInterface &iface, const Value &app_info, const Value &pdf_info) FOSSILIZE_WARN_UNUSED;
bool parse_application_info_link(StateCreatorInterface &iface, const Value &link) FOSSILIZE_WARN_UNUSED;
bool parse_push_constant_ranges(const Value &ranges, const VkPushConstantRange **out_ranges) FOSSILIZE_WARN_UNUSED;
bool parse_set_layouts(const Value &layouts, const VkDescriptorSetLayout **out_layouts) FOSSILIZE_WARN_UNUSED;
bool parse_descriptor_set_bindings(const Value &bindings, const VkDescriptorSetLayoutBinding **out_bindings) FOSSILIZE_WARN_UNUSED;
bool parse_immutable_samplers(const Value &samplers, const VkSampler **out_sampler) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_attachments(const Value &attachments, const VkAttachmentDescription **out_attachments) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_dependencies(const Value &dependencies, const VkSubpassDependency **out_dependencies) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_subpasses(const Value &subpass, const VkSubpassDescription **out_descriptions) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_attachments2(const Value &attachments, const VkAttachmentDescription2 **out_attachments) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_dependencies2(const Value &dependencies, const VkSubpassDependency2 **out_dependencies) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_subpasses2(const Value &subpass, const VkSubpassDescription2 **out_descriptions) FOSSILIZE_WARN_UNUSED;
bool parse_attachment(const Value &value, const VkAttachmentReference **out_references) FOSSILIZE_WARN_UNUSED;
bool parse_attachments(const Value &attachments, const VkAttachmentReference **out_references) FOSSILIZE_WARN_UNUSED;
bool parse_attachment2(const Value &value, const VkAttachmentReference2 **out_references) FOSSILIZE_WARN_UNUSED;
bool parse_attachments2(const Value &attachments, const VkAttachmentReference2 **out_references) FOSSILIZE_WARN_UNUSED;
bool parse_specialization_info(const Value &spec_info, const VkSpecializationInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_map_entries(const Value &map_entries, const VkSpecializationMapEntry **out_entries) FOSSILIZE_WARN_UNUSED;
bool parse_viewports(const Value &viewports, const VkViewport **out_viewports) FOSSILIZE_WARN_UNUSED;
bool parse_scissors(const Value &scissors, const VkRect2D **out_rects) FOSSILIZE_WARN_UNUSED;
bool parse_pnext_chain(const Value &pnext, const void **out_pnext) FOSSILIZE_WARN_UNUSED;
bool parse_vertex_input_state(const Value &state, const VkPipelineVertexInputStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_color_blend_state(const Value &state, const VkPipelineColorBlendStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_depth_stencil_state(const Value &state, const VkPipelineDepthStencilStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rasterization_state(const Value &state, const VkPipelineRasterizationStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_input_assembly_state(const Value &state, const VkPipelineInputAssemblyStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_multisample_state(const Value &state, const VkPipelineMultisampleStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_viewport_state(const Value &state, const VkPipelineViewportStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_dynamic_state(const Value &state, const VkPipelineDynamicStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_layout_handle(const Value &state, VkPipelineLayout *out_layout) FOSSILIZE_WARN_UNUSED;
bool parse_derived_pipeline_handle(StateCreatorInterface &iface, DatabaseInterface *resolver,
const Value &state, const Value &pipelines,
ResourceTag tag, VkPipeline *pipeline) FOSSILIZE_WARN_UNUSED;
bool parse_raytracing_groups(const Value &state, const VkRayTracingShaderGroupCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_library_interface(const Value &state, const VkRayTracingPipelineInterfaceCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_tessellation_state(const Value &state, const VkPipelineTessellationStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_stages(StateCreatorInterface &iface, DatabaseInterface *resolver, const Value &stages, const VkPipelineShaderStageCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_vertex_attributes(const Value &attributes, const VkVertexInputAttributeDescription **out_desc) FOSSILIZE_WARN_UNUSED;
bool parse_vertex_bindings(const Value &bindings, const VkVertexInputBindingDescription **out_desc) FOSSILIZE_WARN_UNUSED;
bool parse_blend_attachments(const Value &attachments, const VkPipelineColorBlendAttachmentState **out_state) FOSSILIZE_WARN_UNUSED;
bool parse_tessellation_domain_origin_state(const Value &state, VkPipelineTessellationDomainOriginStateCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_vertex_input_divisor_state(const Value &state, VkPipelineVertexInputDivisorStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rasterization_depth_clip_state(const Value &state, VkPipelineRasterizationDepthClipStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rasterization_stream_state(const Value &state, VkPipelineRasterizationStateStreamCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_multiview_state(const Value &state, VkRenderPassMultiviewCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_descriptor_set_binding_flags(const Value &state, VkDescriptorSetLayoutBindingFlagsCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_color_blend_advanced_state(const Value &state, VkPipelineColorBlendAdvancedStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rasterization_conservative_state(const Value &state, VkPipelineRasterizationConservativeStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rasterization_line_state(const Value &state, VkPipelineRasterizationLineStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_shader_stage_required_subgroup_size(const Value &state, VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_mutable_descriptor_type(const Value &state, VkMutableDescriptorTypeCreateInfoVALVE **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_attachment_description_stencil_layout(const Value &state, VkAttachmentDescriptionStencilLayout **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_attachment_reference_stencil_layout(const Value &state, VkAttachmentReferenceStencilLayout **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_subpass_description_depth_stencil_resolve(const Value &state, VkSubpassDescriptionDepthStencilResolve **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_fragment_shading_rate_attachment_info(const Value &state, VkFragmentShadingRateAttachmentInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_rendering_info(const Value &state, VkPipelineRenderingCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_pnext_chain_pdf2(const Value &pnext, void **out_pnext) FOSSILIZE_WARN_UNUSED;
bool parse_robustness2_features(const Value &state, VkPhysicalDeviceRobustness2FeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_image_robustness_features(const Value &state, VkPhysicalDeviceImageRobustnessFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_fragment_shading_rate_enums_features(const Value &state, VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_color_write(const Value &state, VkPipelineColorWriteCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_provoking_vertex(const Value &state, VkPipelineRasterizationProvokingVertexStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sampler_custom_border_color(const Value &state, VkSamplerCustomBorderColorCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sampler_reduction_mode(const Value &state, VkSamplerReductionModeCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_input_attachment_aspect(const Value &state, VkRenderPassInputAttachmentAspectCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_discard_rectangles(const Value &state, VkPipelineDiscardRectangleStateCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_memory_barrier2(const Value &state, VkMemoryBarrier2KHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_fragment_shading_rate(const Value &state, VkPipelineFragmentShadingRateStateCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sampler_ycbcr_conversion(const Value &state,
VkSamplerYcbcrConversionCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_uints(const Value &attachments, const uint32_t **out_uints) FOSSILIZE_WARN_UNUSED;
bool parse_sints(const Value &attachments, const int32_t **out_uints) FOSSILIZE_WARN_UNUSED;
const char *duplicate_string(const char *str, size_t len);
bool resolve_derivative_pipelines = true;
bool resolve_shader_modules = true;
template <typename T>
T *copy(const T *src, size_t count);
};
struct WorkItem
{
uint64_t handle;
void *create_info;
Hash custom_hash;
};
struct StateRecorder::Impl
{
~Impl();
void sync_thread();
void record_end();
ScratchAllocator allocator;
ScratchAllocator temp_allocator;
ScratchAllocator ycbcr_temp_allocator;
DatabaseInterface *database_iface = nullptr;
ApplicationInfoFilter *application_info_filter = nullptr;
bool need_prepare = false;
std::unordered_map<Hash, VkDescriptorSetLayoutCreateInfo *> descriptor_sets;
std::unordered_map<Hash, VkPipelineLayoutCreateInfo *> pipeline_layouts;
std::unordered_map<Hash, VkShaderModuleCreateInfo *> shader_modules;
std::unordered_map<Hash, VkGraphicsPipelineCreateInfo *> graphics_pipelines;
std::unordered_map<Hash, VkComputePipelineCreateInfo *> compute_pipelines;
std::unordered_map<Hash, VkRayTracingPipelineCreateInfoKHR *> raytracing_pipelines;
std::unordered_map<Hash, void *> render_passes;
std::unordered_map<Hash, VkSamplerCreateInfo *> samplers;
std::unordered_map<VkSamplerYcbcrConversion, const VkSamplerYcbcrConversionCreateInfo *> ycbcr_conversions;
std::unordered_map<VkDescriptorSetLayout, Hash> descriptor_set_layout_to_hash;
std::unordered_map<VkPipelineLayout, Hash> pipeline_layout_to_hash;
std::unordered_map<VkShaderModule, Hash> shader_module_to_hash;
std::unordered_map<VkPipeline, Hash> graphics_pipeline_to_hash;
std::unordered_map<VkPipeline, Hash> compute_pipeline_to_hash;
std::unordered_map<VkPipeline, Hash> raytracing_pipeline_to_hash;
std::unordered_map<VkRenderPass, Hash> render_pass_to_hash;
std::unordered_map<VkSampler, Hash> sampler_to_hash;
struct SubpassMetaStorage
{
// Holds 16 subpasses' worth of state. Hits ~100% of the time.
uint32_t embedded;
uint32_t subpass_count;
// Spillage
std::vector<uint32_t> fallback;
};
std::unordered_map<Hash, SubpassMetaStorage> render_pass_hash_to_subpass_meta;
template <typename CreateInfo>
static SubpassMetaStorage analyze_subpass_meta_storage(const CreateInfo &render_pass_create_info);
VkApplicationInfo *application_info = nullptr;
VkPhysicalDeviceFeatures2 *physical_device_features = nullptr;
StateRecorderApplicationFeatureHash application_feature_hash = {};
bool copy_descriptor_set_layout(const VkDescriptorSetLayoutCreateInfo *create_info, ScratchAllocator &alloc, VkDescriptorSetLayoutCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_pipeline_layout(const VkPipelineLayoutCreateInfo *create_info, ScratchAllocator &alloc, VkPipelineLayoutCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_shader_module(const VkShaderModuleCreateInfo *create_info, ScratchAllocator &alloc, VkShaderModuleCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_graphics_pipeline(const VkGraphicsPipelineCreateInfo *create_info, ScratchAllocator &alloc,
const VkPipeline *base_pipelines, uint32_t base_pipeline_count,
VkGraphicsPipelineCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_compute_pipeline(const VkComputePipelineCreateInfo *create_info, ScratchAllocator &alloc,
const VkPipeline *base_pipelines, uint32_t base_pipeline_count,
VkComputePipelineCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_raytracing_pipeline(const VkRayTracingPipelineCreateInfoKHR *create_info, ScratchAllocator &alloc,
const VkPipeline *base_pipelines, uint32_t base_pipeline_count,
VkRayTracingPipelineCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_sampler(const VkSamplerCreateInfo *create_info, ScratchAllocator &alloc,
VkSamplerCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_ycbcr_conversion(const VkSamplerYcbcrConversionCreateInfo *create_info, ScratchAllocator &alloc,
VkSamplerYcbcrConversionCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_render_pass(const VkRenderPassCreateInfo *create_info, ScratchAllocator &alloc,
VkRenderPassCreateInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_render_pass2(const VkRenderPassCreateInfo2 *create_info, ScratchAllocator &alloc,
VkRenderPassCreateInfo2 **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_application_info(const VkApplicationInfo *app_info, ScratchAllocator &alloc, VkApplicationInfo **out_info) FOSSILIZE_WARN_UNUSED;
bool copy_physical_device_features(const void *device_pnext, ScratchAllocator &alloc, VkPhysicalDeviceFeatures2 **out_features) FOSSILIZE_WARN_UNUSED;
bool copy_specialization_info(const VkSpecializationInfo *info, ScratchAllocator &alloc, const VkSpecializationInfo **out_info) FOSSILIZE_WARN_UNUSED;
template <typename CreateInfo>
bool copy_stages(CreateInfo *info, ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
template <typename CreateInfo>
bool copy_dynamic_state(CreateInfo *info, ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
template <typename SubCreateInfo>
bool copy_sub_create_info(const SubCreateInfo *&info, ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineTessellationDomainOriginStateCreateInfo *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineVertexInputDivisorStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRasterizationDepthClipStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRasterizationStateStreamCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkRenderPassMultiviewCreateInfo *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineColorBlendAdvancedStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRasterizationConservativeStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRasterizationLineStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkMutableDescriptorTypeCreateInfoVALVE *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkAttachmentDescriptionStencilLayout *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkAttachmentReferenceStencilLayout *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkSubpassDescriptionDepthStencilResolve *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkFragmentShadingRateAttachmentInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRenderingCreateInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPhysicalDeviceRobustness2FeaturesEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPhysicalDeviceImageRobustnessFeaturesEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineColorWriteCreateInfoEXT *create_info,
ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkSamplerCustomBorderColorCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkSamplerReductionModeCreateInfo *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkRenderPassInputAttachmentAspectCreateInfo *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineDiscardRectangleStateCreateInfoEXT *create_info,
ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkMemoryBarrier2KHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineFragmentShadingRateStateCreateInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkSamplerYcbcrConversionCreateInfo *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
bool remap_sampler_handle(VkSampler sampler, VkSampler *out_sampler) const FOSSILIZE_WARN_UNUSED;
bool remap_descriptor_set_layout_handle(VkDescriptorSetLayout layout, VkDescriptorSetLayout *out_layout) const FOSSILIZE_WARN_UNUSED;
bool remap_pipeline_layout_handle(VkPipelineLayout layout, VkPipelineLayout *out_layout) const FOSSILIZE_WARN_UNUSED;
bool remap_render_pass_handle(VkRenderPass render_pass, VkRenderPass *out_render_pass) const FOSSILIZE_WARN_UNUSED;
bool remap_shader_module_handle(VkShaderModule shader_module, VkShaderModule *out_shader_module) const FOSSILIZE_WARN_UNUSED;
bool remap_compute_pipeline_handle(VkPipeline pipeline, VkPipeline *out_pipeline) const FOSSILIZE_WARN_UNUSED;
bool remap_graphics_pipeline_handle(VkPipeline pipeline, VkPipeline *out_pipeline) const FOSSILIZE_WARN_UNUSED;
bool remap_raytracing_pipeline_handle(VkPipeline pipeline, VkPipeline *out_pipeline) const FOSSILIZE_WARN_UNUSED;
bool remap_descriptor_set_layout_ci(VkDescriptorSetLayoutCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_pipeline_layout_ci(VkPipelineLayoutCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_shader_module_ci(VkShaderModuleCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_graphics_pipeline_ci(VkGraphicsPipelineCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_compute_pipeline_ci(VkComputePipelineCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_raytracing_pipeline_ci(VkRayTracingPipelineCreateInfoKHR *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_sampler_ci(VkSamplerCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
bool remap_render_pass_ci(VkRenderPassCreateInfo *create_info) FOSSILIZE_WARN_UNUSED;
template <typename CreateInfo>
bool remap_shader_module_handles(CreateInfo *info) FOSSILIZE_WARN_UNUSED;
bool get_subpass_meta_for_render_pass_hash(Hash render_pass_hash,
uint32_t subpass,
SubpassMeta *meta) const FOSSILIZE_WARN_UNUSED;
bool get_subpass_meta_for_pipeline(const VkGraphicsPipelineCreateInfo &create_info,
Hash render_pass_hash,
SubpassMeta *meta) const FOSSILIZE_WARN_UNUSED;
bool serialize_application_info(std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_application_blob_link(Hash hash, ResourceTag tag, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
Hash get_application_link_hash(ResourceTag tag, Hash hash) const;
bool register_application_link_hash(ResourceTag tag, Hash hash, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_sampler(Hash hash, const VkSamplerCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_descriptor_set_layout(Hash hash, const VkDescriptorSetLayoutCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_pipeline_layout(Hash hash, const VkPipelineLayoutCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_render_pass(Hash hash, const VkRenderPassCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_render_pass2(Hash hash, const VkRenderPassCreateInfo2 &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_shader_module(Hash hash, const VkShaderModuleCreateInfo &create_info, std::vector<uint8_t> &blob, ScratchAllocator &allocator) const FOSSILIZE_WARN_UNUSED;
bool serialize_graphics_pipeline(Hash hash, const VkGraphicsPipelineCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_compute_pipeline(Hash hash, const VkComputePipelineCreateInfo &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
bool serialize_raytracing_pipeline(Hash hash, const VkRayTracingPipelineCreateInfoKHR &create_info, std::vector<uint8_t> &blob) const FOSSILIZE_WARN_UNUSED;
std::mutex record_lock;
std::mutex synchronized_record_lock;
std::condition_variable record_cv;
std::queue<WorkItem> record_queue;
std::thread worker_thread;
bool compression = false;
bool checksum = false;
void record_task(StateRecorder *recorder, bool looping);
void pump_synchronized_recording(StateRecorder *recorder);
template <typename T>
T *copy(const T *src, size_t count, ScratchAllocator &alloc);
bool copy_pnext_chain(const void *pNext, ScratchAllocator &alloc, const void **out_pnext,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
template <typename T>
bool copy_pnext_chains(const T *ts, uint32_t count, ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
bool copy_pnext_chain_pdf2(const void *pNext, ScratchAllocator &alloc, void **out_pnext) FOSSILIZE_WARN_UNUSED;
};
// reinterpret_cast does not work reliably on MSVC 2013 for Vulkan objects.
template <typename T, typename U>
static inline T api_object_cast(U obj)
{
static_assert(sizeof(T) == sizeof(U), "Objects are not of same size.");
return (T)obj;
}
namespace Hashing
{
static Hash compute_hash_application_info(const VkApplicationInfo &info)
{
Hasher h;
h.u32(info.applicationVersion);
h.u32(info.apiVersion);
h.u32(info.engineVersion);
if (info.pApplicationName)
h.string(info.pApplicationName);
else
h.u32(0);
if (info.pEngineName)
h.string(info.pEngineName);
else
h.u32(0);
return h.get();
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceRobustness2FeaturesEXT &info)
{
h.u32(info.robustBufferAccess2);
h.u32(info.robustImageAccess2);
h.u32(info.nullDescriptor);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceImageRobustnessFeaturesEXT &info)
{
h.u32(info.robustImageAccess);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV &info)
{
h.u32(info.noInvocationFragmentShadingRates);
h.u32(info.fragmentShadingRateEnums);
// Specifically known to affect shader compilation on NV.
// Just hash the entire struct while we're at it though ...
h.u32(info.supersampleFragmentShadingRates);
}
static bool hash_pnext_chain_pdf2(const StateRecorder *recorder, Hasher &h, const void *pNext)
{
while ((pNext = pnext_chain_pdf2_skip_ignored_entries(pNext)) != nullptr)
{
auto *pin = static_cast<const VkBaseInStructure *>(pNext);
h.s32(pin->sType);
// Pull in any robustness-like feature and other types which are known to affect shader compilation.
switch (pin->sType)
{
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceRobustness2FeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceImageRobustnessFeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_ENUMS_FEATURES_NV:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV *>(pNext));
break;
default:
log_error_pnext_chain("Unsupported pNext found, cannot hash.", pNext);
return false;
}
pNext = pin->pNext;
}
return true;
}
static Hash compute_hash_physical_device_features(const void *device_pnext)
{
Hasher h;
// For hash invariance, make sure we hash PDF2 first, since when we serialize and unserialize,
// PDF2 will always come first in the chain.
auto *pdf2 = find_pnext<VkPhysicalDeviceFeatures2>(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, device_pnext);
if (pdf2)
h.u32(pdf2->features.robustBufferAccess);
else
h.u32(0);
hash_pnext_chain_pdf2(nullptr, h, device_pnext);
return h.get();
}
StateRecorderApplicationFeatureHash compute_application_feature_hash(const VkApplicationInfo *info,
const void *device_pnext)
{
StateRecorderApplicationFeatureHash hash = {};
if (info)
hash.application_info_hash = compute_hash_application_info(*info);
if (device_pnext)
hash.physical_device_features_hash = compute_hash_physical_device_features(device_pnext);
return hash;
}
static void hash_application_feature_info(Hasher &hasher, const StateRecorderApplicationFeatureHash &base_hash)
{
// This makes it so two different applications won't conflict if they use the same pipelines.
hasher.u64(base_hash.application_info_hash);
hasher.u64(base_hash.physical_device_features_hash);
}
Hash compute_combined_application_feature_hash(const StateRecorderApplicationFeatureHash &base_hash)
{
Hasher h;
hash_application_feature_info(h, base_hash);
return h.get();
}
static Hash compute_hash_application_info_link(const StateRecorderApplicationFeatureHash &app, ResourceTag tag, Hash hash)
{
Hasher h;
h.u64(compute_combined_application_feature_hash(app));
h.s32(tag);
h.u64(hash);
return h.get();
}
static Hash compute_hash_application_info_link(Hash app_hash, ResourceTag tag, Hash hash)
{
Hasher h;
h.u64(app_hash);
h.s32(tag);
h.u64(hash);
return h.get();
}
static bool hash_pnext_chain(const StateRecorder *recorder, Hasher &h, const void *pNext,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
bool compute_hash_sampler(const VkSamplerCreateInfo &sampler, Hash *out_hash)
{
Hasher h;
h.u32(sampler.flags);
h.f32(sampler.maxAnisotropy);
h.f32(sampler.mipLodBias);
h.f32(sampler.minLod);
h.f32(sampler.maxLod);
h.u32(sampler.minFilter);
h.u32(sampler.magFilter);
h.u32(sampler.mipmapMode);
h.u32(sampler.compareEnable);
h.u32(sampler.compareOp);
h.u32(sampler.anisotropyEnable);
h.u32(sampler.addressModeU);
h.u32(sampler.addressModeV);
h.u32(sampler.addressModeW);
h.u32(sampler.borderColor);
h.u32(sampler.unnormalizedCoordinates);
if (!hash_pnext_chain(nullptr, h, sampler.pNext, nullptr))
return false;
*out_hash = h.get();
return true;
}
static bool validate_pnext_chain(const void *pNext, const VkStructureType *expected, uint32_t count)
{
while ((pNext = pnext_chain_skip_ignored_entries(pNext)) != nullptr)
{
auto *pin = static_cast<const VkBaseInStructure *>(pNext);
auto sType = pin->sType;
if (std::find(expected, expected + count, sType) == expected + count)
return false;
pNext = pin->pNext;
}
return true;
}
bool compute_hash_descriptor_set_layout(const StateRecorder &recorder, const VkDescriptorSetLayoutCreateInfo &layout, Hash *out_hash)
{
Hasher h;
h.u32(layout.bindingCount);
h.u32(layout.flags);
for (uint32_t i = 0; i < layout.bindingCount; i++)
{
auto &binding = layout.pBindings[i];
h.u32(binding.binding);
h.u32(binding.descriptorCount);
h.u32(binding.descriptorType);
h.u32(binding.stageFlags);
if (binding.pImmutableSamplers &&
(binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER))
{
for (uint32_t j = 0; j < binding.descriptorCount; j++)
{
Hash hash;
if (!recorder.get_hash_for_sampler(binding.pImmutableSamplers[j], &hash))
return false;
h.u64(hash);
}
}
}
if (!hash_pnext_chain(&recorder, h, layout.pNext, nullptr))
return false;
*out_hash = h.get();
return true;
}
bool compute_hash_pipeline_layout(const StateRecorder &recorder, const VkPipelineLayoutCreateInfo &layout, Hash *out_hash)
{
Hasher h;
h.u32(layout.setLayoutCount);
for (uint32_t i = 0; i < layout.setLayoutCount; i++)
{
if (layout.pSetLayouts[i])
{
Hash hash;
if (!recorder.get_hash_for_descriptor_set_layout(layout.pSetLayouts[i], &hash))
return false;
h.u64(hash);
}
else
h.u32(0);
}
h.u32(layout.pushConstantRangeCount);
for (uint32_t i = 0; i < layout.pushConstantRangeCount; i++)
{
auto &push = layout.pPushConstantRanges[i];
h.u32(push.stageFlags);
h.u32(push.size);
h.u32(push.offset);
}
h.u32(layout.flags);
*out_hash = h.get();
return true;
}
bool compute_hash_shader_module(const VkShaderModuleCreateInfo &create_info, Hash *out_hash)
{
Hasher h;
h.data(create_info.pCode, create_info.codeSize);
h.u32(create_info.flags);
*out_hash = h.get();
return true;
}
static void hash_specialization_info(Hasher &h, const VkSpecializationInfo &spec)
{
h.data(static_cast<const uint8_t *>(spec.pData), spec.dataSize);
h.u64(spec.dataSize);
h.u32(spec.mapEntryCount);
for (uint32_t i = 0; i < spec.mapEntryCount; i++)
{
h.u32(spec.pMapEntries[i].offset);
h.u64(spec.pMapEntries[i].size);
h.u32(spec.pMapEntries[i].constantID);
}
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineTessellationDomainOriginStateCreateInfo &create_info)
{
h.u32(create_info.domainOrigin);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineVertexInputDivisorStateCreateInfoEXT &create_info)
{
h.u32(create_info.vertexBindingDivisorCount);
for (uint32_t i = 0; i < create_info.vertexBindingDivisorCount; i++)
{
h.u32(create_info.pVertexBindingDivisors[i].binding);
h.u32(create_info.pVertexBindingDivisors[i].divisor);
}
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRasterizationDepthClipStateCreateInfoEXT &create_info)
{
h.u32(create_info.flags);
h.u32(create_info.depthClipEnable);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRasterizationStateStreamCreateInfoEXT &create_info)
{
h.u32(create_info.flags);
h.u32(create_info.rasterizationStream);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkRenderPassMultiviewCreateInfo &create_info)
{
h.u32(create_info.subpassCount);
for (uint32_t i = 0; i < create_info.subpassCount; i++)
h.u32(create_info.pViewMasks[i]);
h.u32(create_info.dependencyCount);
for (uint32_t i = 0; i < create_info.dependencyCount; i++)
h.s32(create_info.pViewOffsets[i]);
h.u32(create_info.correlationMaskCount);
for (uint32_t i = 0; i < create_info.correlationMaskCount; i++)
h.u32(create_info.pCorrelationMasks[i]);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT &create_info)
{
h.u32(create_info.bindingCount);
for (uint32_t i = 0; i < create_info.bindingCount; i++)
h.u32(create_info.pBindingFlags[i]);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineColorBlendAdvancedStateCreateInfoEXT &create_info)
{
h.u32(create_info.srcPremultiplied);
h.u32(create_info.dstPremultiplied);
h.u32(create_info.blendOverlap);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRasterizationConservativeStateCreateInfoEXT &create_info)
{
h.u32(create_info.flags);
h.u32(create_info.conservativeRasterizationMode);
h.f32(create_info.extraPrimitiveOverestimationSize);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRasterizationLineStateCreateInfoEXT &create_info)
{
h.u32(create_info.lineRasterizationMode);
h.u32(create_info.stippledLineEnable);
h.u32(create_info.lineStippleFactor);
h.u32(create_info.lineStipplePattern);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT &create_info)
{
h.u32(create_info.requiredSubgroupSize);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkMutableDescriptorTypeCreateInfoVALVE &mutable_info)
{
h.u32(mutable_info.mutableDescriptorTypeListCount);
for (uint32_t i = 0; i < mutable_info.mutableDescriptorTypeListCount; i++)
{
auto &l = mutable_info.pMutableDescriptorTypeLists[i];
h.u32(l.descriptorTypeCount);
for (uint32_t j = 0; j < l.descriptorTypeCount; j++)
h.s32(l.pDescriptorTypes[j]);
}
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkAttachmentDescriptionStencilLayoutKHR &info)
{
h.u32(info.stencilInitialLayout);
h.u32(info.stencilFinalLayout);
}
static bool hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkFragmentShadingRateAttachmentInfoKHR &info)
{
if (info.pFragmentShadingRateAttachment)
{
h.u32(info.pFragmentShadingRateAttachment->attachment);
h.u32(info.pFragmentShadingRateAttachment->layout);
h.u32(info.pFragmentShadingRateAttachment->aspectMask);
h.u32(info.shadingRateAttachmentTexelSize.width);
h.u32(info.shadingRateAttachmentTexelSize.height);
// Avoid potential stack overflow on intentionally broken input.
// It is also meaningless, since the only pNext we can consider here
// is stencil layout.
if (info.pFragmentShadingRateAttachment->pNext)
return false;
}
else
h.u32(0);
return true;
}
static bool hash_pnext_struct(const StateRecorder *recorder,
Hasher &h,
const VkSubpassDescriptionDepthStencilResolve &info)
{
if (info.pDepthStencilResolveAttachment)
{
h.u32(info.depthResolveMode);
h.u32(info.stencilResolveMode);
h.u32(info.pDepthStencilResolveAttachment->attachment);
h.u32(info.pDepthStencilResolveAttachment->layout);
h.u32(info.pDepthStencilResolveAttachment->aspectMask);
// Ensures we cannot get a recursive cycle.
const VkStructureType expected = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT;
if (!validate_pnext_chain(info.pDepthStencilResolveAttachment->pNext, &expected, 1))
return false;
if (!hash_pnext_chain(recorder, h, info.pDepthStencilResolveAttachment->pNext, nullptr))
return false;
}
else
h.u32(0);
return true;
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkAttachmentReferenceStencilLayoutKHR &info)
{
h.u32(info.stencilLayout);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRenderingCreateInfoKHR &info)
{
h.u32(info.colorAttachmentCount);
h.u32(info.viewMask);
for (uint32_t i = 0; i < info.colorAttachmentCount; i++)
h.u32(info.pColorAttachmentFormats[i]);
h.u32(info.depthAttachmentFormat);
h.u32(info.stencilAttachmentFormat);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineColorWriteCreateInfoEXT &info,
const DynamicStateInfo *dynamic_state_info)
{
h.u32(info.attachmentCount);
if (dynamic_state_info && !dynamic_state_info->color_write_enable)
for (uint32_t i = 0; i < info.attachmentCount; i++)
h.u32(info.pColorWriteEnables[i]);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT &info)
{
h.u32(info.provokingVertexMode);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkSamplerCustomBorderColorCreateInfoEXT &info)
{
h.u32(info.customBorderColor.uint32[0]);
h.u32(info.customBorderColor.uint32[1]);
h.u32(info.customBorderColor.uint32[2]);
h.u32(info.customBorderColor.uint32[3]);
h.u32(info.format);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkSamplerReductionModeCreateInfo &info)
{
h.u32(info.reductionMode);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkRenderPassInputAttachmentAspectCreateInfo &info)
{
h.u32(info.aspectReferenceCount);
for (uint32_t i = 0; i < info.aspectReferenceCount; i++)
{
h.u32(info.pAspectReferences[i].subpass);
h.u32(info.pAspectReferences[i].inputAttachmentIndex);
h.u32(info.pAspectReferences[i].aspectMask);
}
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineDiscardRectangleStateCreateInfoEXT &info,
const DynamicStateInfo *dynamic_state_info)
{
h.u32(info.flags);
h.u32(info.discardRectangleMode);
h.u32(info.discardRectangleCount);
if (dynamic_state_info && !dynamic_state_info->discard_rectangle)
{
for (uint32_t i = 0; i < info.discardRectangleCount; i++)
{
h.s32(info.pDiscardRectangles[i].offset.x);
h.s32(info.pDiscardRectangles[i].offset.y);
h.u32(info.pDiscardRectangles[i].extent.width);
h.u32(info.pDiscardRectangles[i].extent.height);
}
}
}
static void hash_pnext_struct(const StateRecorder *,