-
Notifications
You must be signed in to change notification settings - Fork 47
/
fossilize.cpp
11601 lines (9934 loc) · 400 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"
#include <time.h>
#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
static inline bool operator==(const VkShaderModuleIdentifierEXT &a, const VkShaderModuleIdentifierEXT &b)
{
return a.identifierSize == b.identifierSize &&
memcmp(a.identifier, b.identifier, a.identifierSize) == 0;
}
static inline bool operator!=(const VkShaderModuleIdentifierEXT &a, const VkShaderModuleIdentifierEXT &b)
{
return !(a == b);
}
namespace std
{
template <> struct hash<VkShaderModuleIdentifierEXT>
{
size_t operator()(const VkShaderModuleIdentifierEXT &i) const
{
Fossilize::Hasher h;
h.u32(i.identifierSize);
h.data(i.identifier, i.identifierSize);
return h.get();
}
};
}
using namespace std;
namespace Fossilize
{
static const void *pnext_chain_skip_ignored_entries(const void *pNext);
static bool pnext_chain_stype_is_hash_invariant(VkStructureType sType);
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;
bool rasterization_state;
bool render_pass_state;
bool layout_state;
bool module_state;
};
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.
// With dynamic state 3 unrestricted the topology is irrelevant, but that's a property.
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 discard_rectangle_mode;
bool fragment_shading_rate;
bool sample_locations;
bool line_stipple;
// Dynamic state 3
bool tessellation_domain_origin;
bool depth_clamp_enable;
bool polygon_mode;
bool rasterization_samples;
bool sample_mask;
bool alpha_to_coverage_enable;
bool alpha_to_one_enable;
bool logic_op_enable;
bool color_blend_enable;
bool color_blend_equation;
bool color_write_mask;
bool rasterization_stream;
bool conservative_rasterization_mode;
bool extra_primitive_overestimation_size;
bool depth_clip_enable;
bool sample_locations_enable;
bool color_blend_advanced;
bool provoking_vertex_mode;
bool line_rasterization_mode;
bool line_stipple_enable;
bool depth_clip_negative_one_to_one;
bool viewport_w_scaling_enable;
bool viewport_swizzle;
bool coverage_to_color_enable;
bool coverage_to_color_location;
bool coverage_modulation_mode;
bool coverage_modulation_table_enable;
bool coverage_modulation_table;
bool shading_rate_image_enable;
bool representative_fragment_test_enable;
bool coverage_reduction_mode;
bool depth_clamp_range;
};
static VkPipelineCreateFlags2KHR normalize_pipeline_creation_flags(VkPipelineCreateFlags2KHR flags)
{
// Remove flags which do not meaningfully contribute to compilation.
flags &= ~VkPipelineCreateFlags2KHR(VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR |
VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR |
VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT |
VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT |
VK_PIPELINE_CREATE_2_CAPTURE_DATA_BIT_KHR);
return flags;
}
static VkGraphicsPipelineLibraryFlagsEXT graphics_pipeline_get_effective_state_flags(
const VkGraphicsPipelineCreateInfo &create_info)
{
VkGraphicsPipelineLibraryFlagsEXT state_flags =
VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT |
VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT |
VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT |
VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT;
auto *graphics_pipeline_library = find_pnext<VkGraphicsPipelineLibraryCreateInfoEXT>(
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
create_info.pNext);
// If we're not creating a library, assume we're defining a complete pipeline.
if ((create_info.flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) != 0 && graphics_pipeline_library)
state_flags = graphics_pipeline_library->flags;
return state_flags;
}
static bool graphics_pipeline_library_state_flags_have_module_state(VkGraphicsPipelineLibraryFlagsEXT flags)
{
return (flags & (VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT |
VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT)) != 0;
}
static bool shader_stage_is_identifier_only(const VkPipelineShaderStageCreateInfo &stage)
{
if (stage.module == VK_NULL_HANDLE)
{
auto *pnext = find_pnext<VkShaderModuleCreateInfo>(VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, stage.pNext);
if (!pnext)
return true;
}
return false;
}
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();
void forget_pipeline_handle_references();
bool parse_samplers(StateCreatorInterface &iface, const Value &samplers) FOSSILIZE_WARN_UNUSED;
bool parse_descriptor_set_layouts(StateCreatorInterface &iface, DatabaseInterface *resolver, 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(StateCreatorInterface &iface, DatabaseInterface *resolver,
const Value &bindings, const VkDescriptorSetLayoutBinding **out_bindings) FOSSILIZE_WARN_UNUSED;
bool parse_immutable_samplers(StateCreatorInterface &iface, DatabaseInterface *resolver,
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,
StateCreatorInterface *iface = nullptr,
DatabaseInterface *resolver = nullptr,
const Value *pipelines = nullptr) 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, VkPipelineVertexInputDivisorStateCreateInfoKHR **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, VkPipelineRasterizationLineStateCreateInfoKHR **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, VkMutableDescriptorTypeCreateInfoEXT **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_fragment_shading_rate_features(const Value &state, VkPhysicalDeviceFragmentShadingRateFeaturesKHR **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_mesh_shader_features(const Value &state, VkPhysicalDeviceMeshShaderFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_mesh_shader_features_nv(const Value &state, VkPhysicalDeviceMeshShaderFeaturesNV **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_descriptor_buffer_features(const Value &state, VkPhysicalDeviceDescriptorBufferFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_shader_object_features(const Value &state, VkPhysicalDeviceShaderObjectFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_primitives_generated_query_features(const Value &state, VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_2d_view_of_3d_features(const Value &state, VkPhysicalDeviceImage2DViewOf3DFeaturesEXT **out_features) FOSSILIZE_WARN_UNUSED;
bool parse_color_write(const Value &state, VkPipelineColorWriteCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sample_locations(const Value &state, VkPipelineSampleLocationsStateCreateInfoEXT **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_graphics_pipeline_library(const Value &state, VkGraphicsPipelineLibraryCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_library(
StateCreatorInterface &iface, DatabaseInterface *resolver,
const Value &pipelines,
const Value &state, ResourceTag tag,
VkPipelineLibraryCreateInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_viewport_depth_clip_control(
const Value &state, VkPipelineViewportDepthClipControlCreateInfoEXT **clip) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_create_flags2(
const Value &state, VkPipelineCreateFlags2CreateInfoKHR **flags2) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_creation_control(const Value &state, VkRenderPassCreationControlEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sampler_border_color_component_mapping(const Value &state, VkSamplerBorderColorComponentMappingCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_multisampled_render_to_single_sampled(const Value &state, VkMultisampledRenderToSingleSampledInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_depth_bias_representation(const Value &state, VkDepthBiasRepresentationInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_render_pass_fragment_density_map(const Value &state, VkRenderPassFragmentDensityMapCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_sample_locations_info(const Value &state, VkSampleLocationsInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_pipeline_robustness(const Value &state, VkPipelineRobustnessCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_depth_clamp_control(const Value &state, VkPipelineViewportDepthClampControlCreateInfoEXT **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rendering_attachment_location_info(const Value &state, VkRenderingAttachmentLocationInfoKHR **out_info) FOSSILIZE_WARN_UNUSED;
bool parse_rendering_input_attachment_index_info(const Value &state, VkRenderingInputAttachmentIndexInfoKHR **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
{
VkStructureType type;
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;
DatabaseInterface *module_identifier_database_iface = nullptr;
DatabaseInterface *on_use_database_iface = nullptr;
ApplicationInfoFilter *application_info_filter = nullptr;
bool should_record_identifier_only = 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);
std::unordered_map<VkShaderModuleIdentifierEXT, VkShaderModule> identifier_to_module;
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,
bool ignore_pnext, 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,
VkDevice device, PFN_vkGetShaderModuleCreateInfoIdentifierEXT gsmcii,
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,
VkDevice device, PFN_vkGetShaderModuleCreateInfoIdentifierEXT gsmcii,
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,
VkDevice device, PFN_vkGetShaderModuleCreateInfoIdentifierEXT gsmcii,
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,
VkDevice device, PFN_vkGetShaderModuleCreateInfoIdentifierEXT gsmcii,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
static bool add_module_identifier(VkPipelineShaderStageCreateInfo *info, ScratchAllocator &alloc,
VkDevice device, PFN_vkGetShaderModuleCreateInfoIdentifierEXT gsmcii);
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,
VkGraphicsPipelineLibraryFlagsEXT state_flags) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineVertexInputDivisorStateCreateInfoKHR *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 VkMutableDescriptorTypeCreateInfoEXT *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,
VkGraphicsPipelineLibraryFlagsEXT state_flags) 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 VkPipelineSampleLocationsStateCreateInfoEXT *create_info,
ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) 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 VkPipelineLibraryCreateInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineShaderStageModuleIdentifierCreateInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkSampleLocationsInfoEXT *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkPipelineViewportDepthClampControlCreateInfoEXT *create_info,
ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkRenderingAttachmentLocationInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
void *copy_pnext_struct(const VkRenderingInputAttachmentIndexInfoKHR *create_info,
ScratchAllocator &alloc) FOSSILIZE_WARN_UNUSED;
template <typename T>
void *copy_pnext_struct_simple(const T *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 remap_shader_module_handle(VkPipelineShaderStageCreateInfo &info) FOSSILIZE_WARN_UNUSED;
void register_module_identifier(VkShaderModule module, const VkPipelineShaderStageModuleIdentifierCreateInfoEXT &ident);
void register_on_use(ResourceTag tag, Hash hash) const;
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 get_hash_for_shader_module(
const VkPipelineShaderStageModuleIdentifierCreateInfoEXT *identifier, Hash *hash) 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;
void push_work_locked(const WorkItem &item);
template <typename T>
void push_unregister_locked(VkStructureType sType, T obj);
bool compression = false;
bool checksum = false;
bool application_feature_links = true;
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,
VkGraphicsPipelineLibraryFlagsEXT state_flags) FOSSILIZE_WARN_UNUSED;
template <typename T>
bool copy_pnext_chains(const T *ts, uint32_t count, ScratchAllocator &alloc,
const DynamicStateInfo *dynamic_state_info,
VkGraphicsPipelineLibraryFlagsEXT state_flags) FOSSILIZE_WARN_UNUSED;
bool copy_pnext_chain_pdf2(const void *pNext, ScratchAllocator &alloc, void **out_pnext) FOSSILIZE_WARN_UNUSED;
Hash record_shader_module(const WorkItem &record_item, bool dependent_record);
struct
{
bool write_database_entries = true;
PayloadWriteFlags payload_flags = 0;
bool need_flush = false;
bool need_prepare = true;
vector<uint8_t> blob;
} record_data;
};
// 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 void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceFragmentShadingRateFeaturesKHR &info)
{
h.u32(info.pipelineFragmentShadingRate);
h.u32(info.primitiveFragmentShadingRate);
h.u32(info.attachmentFragmentShadingRate);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceMeshShaderFeaturesNV &info)
{
h.u32(info.taskShader);
h.u32(info.meshShader);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceMeshShaderFeaturesEXT &info)
{
h.u32(info.taskShader);
h.u32(info.meshShader);
h.u32(info.multiviewMeshShader);
h.u32(info.primitiveFragmentShadingRateMeshShader);
h.u32(info.meshShaderQueries);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceDescriptorBufferFeaturesEXT &info)
{
h.u32(info.descriptorBuffer);
h.u32(info.descriptorBufferCaptureReplay);
h.u32(info.descriptorBufferImageLayoutIgnored);
h.u32(info.descriptorBufferPushDescriptors);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceShaderObjectFeaturesEXT &info)
{
h.u32(info.shaderObject);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT &info)
{
h.u32(info.primitivesGeneratedQuery);
h.u32(info.primitivesGeneratedQueryWithNonZeroStreams);
h.u32(info.primitivesGeneratedQueryWithRasterizerDiscard);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPhysicalDeviceImage2DViewOf3DFeaturesEXT &info)
{
h.u32(info.image2DViewOf3D);
h.u32(info.sampler2DViewOf3D);
}
static void hash_pnext_struct(const StateRecorder *,
Hasher &h,
const VkPipelineCreateFlags2CreateInfoKHR &info)
{
auto flags = normalize_pipeline_creation_flags(info.flags);
h.u64(flags);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkRenderPassCreationControlEXT &info)
{
h.u32(info.disallowMerging);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkSamplerBorderColorComponentMappingCreateInfoEXT &info)
{
h.u32(info.srgb);
h.u32(info.components.r);
h.u32(info.components.g);
h.u32(info.components.b);
h.u32(info.components.a);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkMultisampledRenderToSingleSampledInfoEXT &info)
{
h.u32(info.multisampledRenderToSingleSampledEnable);
h.u32(info.rasterizationSamples);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkDepthBiasRepresentationInfoEXT &info, const DynamicStateInfo *dynamic_state)
{
if (!dynamic_state || !dynamic_state->depth_bias)
{
h.u32(info.depthBiasExact);
h.u32(info.depthBiasRepresentation);
}
else
h.u32(0);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkRenderPassFragmentDensityMapCreateInfoEXT &info)
{
h.u32(info.fragmentDensityMapAttachment.attachment);
h.u32(info.fragmentDensityMapAttachment.layout);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkSampleLocationsInfoEXT &info)
{
h.u32(info.sampleLocationsCount);
h.u32(info.sampleLocationGridSize.width);
h.u32(info.sampleLocationGridSize.height);
h.u32(info.sampleLocationsPerPixel);
for (uint32_t i = 0; i < info.sampleLocationsCount; i++)
{
h.f32(info.pSampleLocations[i].x);
h.f32(info.pSampleLocations[i].y);
}
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkPipelineRobustnessCreateInfoEXT &info)
{
h.u32(info.images);
h.u32(info.vertexInputs);
h.u32(info.uniformBuffers);
h.u32(info.storageBuffers);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkPipelineViewportDepthClampControlCreateInfoEXT &info,
const DynamicStateInfo *dynamic_state)
{
if (dynamic_state && dynamic_state->depth_clamp_range)
return;
h.u32(info.depthClampMode);
if (info.depthClampMode == VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT && info.pDepthClampRange)
{
h.f32(info.pDepthClampRange->minDepthClamp);
h.f32(info.pDepthClampRange->maxDepthClamp);
}
else
h.u32(0);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkRenderingAttachmentLocationInfoKHR &info)
{
h.u32(info.colorAttachmentCount);
if (info.pColorAttachmentLocations)
{
for (uint32_t i = 0; i < info.colorAttachmentCount; i++)
h.u32(info.pColorAttachmentLocations[i]);
}
else
h.u32(0);
}
static void hash_pnext_struct(const StateRecorder *, Hasher &h,
const VkRenderingInputAttachmentIndexInfoKHR &info)
{
h.u32(info.colorAttachmentCount);
if (info.pColorAttachmentInputIndices)
{
for (uint32_t i = 0; i < info.colorAttachmentCount; i++)
h.u32(info.pColorAttachmentInputIndices[i]);
}
else
h.u32(0);
if (info.pDepthInputAttachmentIndex)
h.u32(*info.pDepthInputAttachmentIndex);
else
h.u32(0xffff); // Use an arbitrary invalid attachment value.
if (info.pStencilInputAttachmentIndex)
h.u32(*info.pStencilInputAttachmentIndex);
else
h.u32(0xffff); // Use an arbitrary invalid attachment value.
}
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;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceFragmentShadingRateFeaturesKHR *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceMeshShaderFeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceMeshShaderFeaturesNV *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceDescriptorBufferFeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceShaderObjectFeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVES_GENERATED_QUERY_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT *>(pNext));
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_2D_VIEW_OF_3D_FEATURES_EXT:
hash_pnext_struct(recorder, h, *static_cast<const VkPhysicalDeviceImage2DViewOf3DFeaturesEXT *>(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();
}