-
Notifications
You must be signed in to change notification settings - Fork 1
/
RendererVk.cpp
5605 lines (4848 loc) · 235 KB
/
RendererVk.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 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RendererVk.cpp:
// Implements the class methods for RendererVk.
//
#include "libANGLE/renderer/vulkan/RendererVk.h"
// Placing this first seems to solve an intellisense bug.
#include "libANGLE/renderer/vulkan/vk_utils.h"
#include <EGL/eglext.h>
#include "common/debug.h"
#include "common/platform.h"
#include "common/system_utils.h"
#include "common/vulkan/libvulkan_loader.h"
#include "common/vulkan/vk_google_filtering_precision.h"
#include "common/vulkan/vulkan_icd.h"
#include "gpu_info_util/SystemInfo.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/driver_utils.h"
#include "libANGLE/renderer/vulkan/CompilerVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/ProgramVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/trace.h"
#include "platform/PlatformMethods.h"
// Consts
namespace
{
constexpr VkFormatFeatureFlags kInvalidFormatFeatureFlags = static_cast<VkFormatFeatureFlags>(-1);
#if defined(ANGLE_EXPOSE_NON_CONFORMANT_EXTENSIONS_AND_VERSIONS)
constexpr bool kExposeNonConformantExtensionsAndVersions = true;
#else
constexpr bool kExposeNonConformantExtensionsAndVersions = false;
#endif
#if defined(ANGLE_ENABLE_CRC_FOR_PIPELINE_CACHE)
constexpr bool kEnableCRCForPipelineCache = true;
#else
constexpr bool kEnableCRCForPipelineCache = false;
#endif
} // anonymous namespace
namespace rx
{
namespace
{
constexpr uint32_t kMinDefaultUniformBufferSize = 16 * 1024u;
// This size is picked based on experience. Majority of devices support 64K
// maxUniformBufferSize. Since this is per context buffer, a bigger buffer size reduces the
// number of descriptor set allocations, so we picked the maxUniformBufferSize that most
// devices supports. It may needs further tuning based on specific device needs and balance
// between performance and memory usage.
constexpr uint32_t kPreferredDefaultUniformBufferSize = 64 * 1024u;
// Update the pipeline cache every this many swaps.
constexpr uint32_t kPipelineCacheVkUpdatePeriod = 60;
// Per the Vulkan specification, ANGLE must indicate the highest version of Vulkan functionality
// that it uses. The Vulkan validation layers will issue messages for any core functionality that
// requires a higher version.
//
// ANGLE specifically limits its core version to Vulkan 1.1 and relies on availability of
// extensions. While implementations are not required to expose an extension that is promoted to
// later versions, they always do so in practice. Avoiding later core versions helps keep the
// initialization logic simpler.
constexpr uint32_t kPreferredVulkanAPIVersion = VK_API_VERSION_1_1;
// For pipeline cache, the values stored in key data has the following format: {originalCacheSize,
// compressedDataCRC, numChunks, chunkIndex; chunkCompressedData}. The header values are used to
// validate the data. For example, if the original and compressed sizes are 70000 bytes (68k) and
// 68841 bytes (67k), the compressed data will be divided into two chunks: {70000,crc0,2,0;34421
// bytes} and {70000,crc1,2,1;34420 bytes}.
constexpr size_t kBlobHeaderSize = 8 * sizeof(uint8_t);
bool IsVulkan11(uint32_t apiVersion)
{
return apiVersion >= VK_API_VERSION_1_1;
}
bool IsVenus(uint32_t driverId, const char *deviceName)
{
// Where driver id is available, check against Venus driver id:
if (driverId != 0)
{
return driverId == VK_DRIVER_ID_MESA_VENUS;
}
// Otherwise, look for Venus in the device name.
return strstr(deviceName, "Venus") != nullptr;
}
bool IsQualcommOpenSource(uint32_t vendorId, uint32_t driverId, const char *deviceName)
{
if (!IsQualcomm(vendorId))
{
return false;
}
// Where driver id is available, distinguish by driver id:
if (driverId != 0)
{
return driverId != VK_DRIVER_ID_QUALCOMM_PROPRIETARY;
}
// Otherwise, look for Venus or Turnip in the device name.
return strstr(deviceName, "Venus") != nullptr || strstr(deviceName, "Turnip") != nullptr;
}
angle::vk::ICD ChooseICDFromAttribs(const egl::AttributeMap &attribs)
{
#if !defined(ANGLE_PLATFORM_ANDROID)
// Mock ICD does not currently run on Android
EGLAttrib deviceType = attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE);
switch (deviceType)
{
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE:
break;
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE:
return angle::vk::ICD::Mock;
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_SWIFTSHADER_ANGLE:
return angle::vk::ICD::SwiftShader;
default:
UNREACHABLE();
break;
}
#endif // !defined(ANGLE_PLATFORM_ANDROID)
return angle::vk::ICD::Default;
}
bool StrLess(const char *a, const char *b)
{
return strcmp(a, b) < 0;
}
bool ExtensionFound(const char *needle, const vk::ExtensionNameList &haystack)
{
// NOTE: The list must be sorted.
return std::binary_search(haystack.begin(), haystack.end(), needle, StrLess);
}
VkResult VerifyExtensionsPresent(const vk::ExtensionNameList &haystack,
const vk::ExtensionNameList &needles)
{
// NOTE: The lists must be sorted.
if (std::includes(haystack.begin(), haystack.end(), needles.begin(), needles.end(), StrLess))
{
return VK_SUCCESS;
}
for (const char *needle : needles)
{
if (!ExtensionFound(needle, haystack))
{
ERR() << "Extension not supported: " << needle;
}
}
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
// Array of Validation error/warning messages that will be ignored, should include bugID
constexpr const char *kSkippedMessages[] = {
// http://anglebug.com/2866
"UNASSIGNED-CoreValidation-Shader-OutputNotConsumed",
// http://anglebug.com/4883
"UNASSIGNED-CoreValidation-Shader-InputNotProduced",
// http://anglebug.com/4928
"VUID-vkMapMemory-memory-00683",
// http://anglebug.com/5027
"UNASSIGNED-CoreValidation-Shader-PushConstantOutOfRange",
// http://anglebug.com/5304
"VUID-vkCmdDraw-magFilter-04553",
"VUID-vkCmdDrawIndexed-magFilter-04553",
// http://anglebug.com/5309
"VUID-VkImageViewCreateInfo-usage-02652",
// http://issuetracker.google.com/175584609
"VUID-vkCmdDraw-None-04584",
"VUID-vkCmdDrawIndexed-None-04584",
"VUID-vkCmdDrawIndirect-None-04584",
"VUID-vkCmdDrawIndirectCount-None-04584",
"VUID-vkCmdDrawIndexedIndirect-None-04584",
"VUID-vkCmdDrawIndexedIndirectCount-None-04584",
// http://anglebug.com/5912
"VUID-VkImageViewCreateInfo-pNext-01585",
// http://anglebug.com/6442
"UNASSIGNED-CoreValidation-Shader-InterfaceTypeMismatch",
// http://anglebug.com/6514
"vkEnumeratePhysicalDevices: One or more layers modified physical devices",
// When using Vulkan secondary command buffers, the command buffer is begun with the current
// framebuffer specified in pInheritanceInfo::framebuffer. If the framebuffer is multisampled
// and is resolved, an optimization would change the framebuffer to add the resolve target and
// use a subpass resolve operation instead. The following error complains that the framebuffer
// used to start the render pass and the one specified in pInheritanceInfo::framebuffer must be
// equal, which is not true in that case. In practice, this is benign, as the part of the
// framebuffer that's accessed by the command buffer is identically laid out.
// http://anglebug.com/6811
"VUID-vkCmdExecuteCommands-pCommandBuffers-00099",
// http://anglebug.com/7105
"VUID-vkCmdDraw-None-06538",
"VUID-vkCmdDrawIndexed-None-06538",
// http://anglebug.com/7325
"VUID-vkCmdBindVertexBuffers2-pStrides-06209",
// http://anglebug.com/7729
"VUID-vkDestroySemaphore-semaphore-01137",
// http://anglebug.com/7843
"VUID-VkGraphicsPipelineCreateInfo-Vertex-07722",
// http://anglebug.com/7861
"VUID-vkCmdDraw-None-06887",
"VUID-vkCmdDrawIndexed-None-06887",
// http://anglebug.com/7865
"VUID-VkDescriptorImageInfo-imageView-06711",
// http://crbug.com/1412096
"VUID-VkImageCreateInfo-pNext-00990",
// http://crbug.com/1420265
"VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912",
// http://anglebug.com/8076
"VUID-VkGraphicsPipelineCreateInfo-None-06573",
// http://anglebug.com/8119
"VUID-VkGraphicsPipelineCreateInfo-Input-07905",
"UNASSIGNED-CoreValidation-Shader-VertexInputMismatch",
"VUID-vkCmdDraw-None-02859",
"VUID-vkCmdDrawIndexed-None-02859",
"VUID-vkCmdDrawIndexed-None-07835",
"VUID-vkCmdDrawIndexedIndirect-None-02859",
"VUID-vkCmdDrawIndirect-None-02859",
"VUID-VkGraphicsPipelineCreateInfo-Input-08733",
};
// Validation messages that should be ignored only when VK_EXT_primitive_topology_list_restart is
// not present.
constexpr const char *kNoListRestartSkippedMessages[] = {
// http://anglebug.com/3832
"VUID-VkPipelineInputAssemblyStateCreateInfo-topology-00428",
};
// Some syncval errors are resolved in the presence of the NONE load or store render pass ops. For
// those, ANGLE makes no further attempt to resolve them and expects vendor support for the
// extensions instead. The list of skipped messages is split based on this support.
constexpr vk::SkippedSyncvalMessage kSkippedSyncvalMessages[] = {
// http://anglebug.com/6416
// http://anglebug.com/6421
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION, "
"write_barriers: 0, command: vkCmdEndRenderPass",
},
// These errors are caused by a feedback loop tests that don't produce correct Vulkan to begin
// with.
// http://anglebug.com/6417
// http://anglebug.com/7070
//
// Occassionally, this is due to VVL's lack of support for some extensions. For example,
// syncval doesn't properly account for VK_EXT_fragment_shader_interlock, which gives
// synchronization guarantees without the need for an image barrier.
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/4387
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"imageLayout: VK_IMAGE_LAYOUT_GENERAL",
"usage: SYNC_FRAGMENT_SHADER_SHADER_",
},
// http://anglebug.com/6551
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, write_barriers: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_"
"STENCIL_ATTACHMENT_WRITE|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_LATE_"
"FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_"
"ATTACHMENT_"
"READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, command: vkCmdEndRenderPass",
},
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, write_barriers: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_"
"ATTACHMENT_WRITE, command: vkCmdEndRenderPass",
},
// From: TraceTest.manhattan_31 with SwiftShader and
// VulkanPerformanceCounterTest.NewTextureDoesNotBreakRenderPass for both depth and stencil
// aspect. http://anglebug.com/6701
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"Hazard WRITE_AFTER_WRITE in subpass 0 for attachment 1 aspect ",
"during load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info (usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION",
},
// From various tests. The validation layer does not calculate the exact vertexCounts that's
// being accessed. http://anglebug.com/6725
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDrawIndexed: Hazard READ_AFTER_WRITE for vertex",
"usage: SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDrawIndexedIndirect: Hazard READ_AFTER_WRITE for vertex",
"usage: SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDrawIndirect: Hazard READ_AFTER_WRITE for vertex",
"usage: SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDrawIndexedIndirect: Hazard READ_AFTER_WRITE for index",
"usage: SYNC_INDEX_INPUT_INDEX_READ",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"vkCmdDraw: Hazard WRITE_AFTER_READ for",
"Access info (usage: SYNC_VERTEX_SHADER_SHADER_STORAGE_WRITE, prior_usage: "
"SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"vkCmdCopyImageToBuffer: Hazard WRITE_AFTER_READ for dstBuffer VkBuffer",
"Access info (usage: SYNC_COPY_TRANSFER_WRITE, prior_usage: "
"SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"vkCmdCopyBuffer: Hazard WRITE_AFTER_READ for dstBuffer VkBuffer",
"Access info (usage: SYNC_COPY_TRANSFER_WRITE, prior_usage: "
"SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"vkCmdDispatch: Hazard WRITE_AFTER_READ for VkBuffer",
"Access info (usage: SYNC_COMPUTE_SHADER_SHADER_STORAGE_WRITE, prior_usage: "
"SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ",
},
// From: MultisampledRenderToTextureES3Test.TransformFeedbackTest. http://anglebug.com/6725
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"vkCmdBeginRenderPass: Hazard WRITE_AFTER_WRITE in subpass",
"write_barriers: "
"SYNC_TRANSFORM_FEEDBACK_EXT_TRANSFORM_FEEDBACK_COUNTER_READ_EXT|SYNC_TRANSFORM_FEEDBACK_"
"EXT_"
"TRANSFORM_FEEDBACK_COUNTER_WRITE_EXT",
},
// http://anglebug.com/8054 (VkNonDispatchableHandle on x86 bots)
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDraw: Hazard READ_AFTER_WRITE for VkBuffer",
"usage: SYNC_VERTEX_SHADER_SHADER_STORAGE_READ",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdDraw: Hazard READ_AFTER_WRITE for VkNonDispatchableHandle",
"usage: SYNC_VERTEX_SHADER_SHADER_STORAGE_READ",
},
// From: TraceTest.manhattan_31 with SwiftShader. These failures appears related to
// dynamic uniform buffers. The failures are gone if I force mUniformBufferDescriptorType to
// VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER. My guess is that syncval is not doing a fine grain enough
// range tracking with dynamic uniform buffers. http://anglebug.com/6725
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"usage: SYNC_VERTEX_SHADER_UNIFORM_READ",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"usage: SYNC_VERTEX_SHADER_UNIFORM_READ",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"type: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"type: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC",
},
// Coherent framebuffer fetch is enabled on some platforms that are known a priori to have the
// needed behavior, even though this is not specified in the Vulkan spec. These generate
// syncval errors that are benign on those platforms.
// http://anglebug.com/6870
// From: TraceTest.dead_by_daylight
// From: TraceTest.genshin_impact
{"SYNC-HAZARD-READ-AFTER-WRITE",
"vkCmdBeginRenderPass: Hazard READ_AFTER_WRITE in subpass 0 for attachment ",
"aspect color during load with loadOp VK_ATTACHMENT_LOAD_OP_LOAD. Access info (usage: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: 0, command: vkCmdEndRenderPass",
true},
{"SYNC-HAZARD-WRITE-AFTER-WRITE",
"vkCmdBeginRenderPass: Hazard WRITE_AFTER_WRITE in subpass 0 for attachment ",
"image layout transition (old_layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, new_layout: "
"VK_IMAGE_LAYOUT_GENERAL). Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, write_barriers:",
true},
// From: TraceTest.car_chase http://anglebug.com/7125
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"type: VK_DESCRIPTOR_TYPE_STORAGE_BUFFER",
},
// From: TraceTest.car_chase http://anglebug.com/7125#c6
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"Access info (usage: SYNC_COPY_TRANSFER_WRITE, "
"prior_usage: SYNC_FRAGMENT_SHADER_UNIFORM_READ, "
"read_barriers: VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, command: vkCmdDrawIndexed",
},
// From: TraceTest.special_forces_group_2 http://anglebug.com/5592
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_FRAGMENT_SHADER_SHADER_",
},
// http://anglebug.com/7031
{"SYNC-HAZARD-READ-AFTER-WRITE",
"type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, imageLayout: "
"VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, binding #0, index 0. Access info (usage: "
"SYNC_COMPUTE_SHADER_SHADER_",
"", false},
// http://anglebug.com/7456
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
"imageLayout: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL",
"Access info (usage: SYNC_FRAGMENT_SHADER_SHADER_",
},
// From: TraceTest.life_is_strange http://anglebug.com/7711
{"SYNC-HAZARD-WRITE-AFTER-READ",
"vkCmdEndRenderPass: Hazard WRITE_AFTER_READ in subpass 0 for attachment 1 "
"depth aspect during store with storeOp VK_ATTACHMENT_STORE_OP_DONT_CARE. "
"Access info (usage: SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, "
"prior_usage: SYNC_FRAGMENT_SHADER_SHADER_"},
// From: TraceTest.life_is_strange http://anglebug.com/7711
{"SYNC-HAZARD-READ-AFTER-WRITE",
"type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
"imageLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL",
"usage: SYNC_FRAGMENT_SHADER_SHADER_"},
// From: TraceTest.diablo_immortal http://anglebug.com/7837
{"SYNC-HAZARD-WRITE-AFTER-WRITE", "vkCmdDrawIndexed: Hazard WRITE_AFTER_WRITE for VkImageView ",
"Subpass #0, and pColorAttachments #0. Access info (usage: "
"SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: 0, command: vkCmdEndRenderPass"},
// From: TraceTest.diablo_immortal http://anglebug.com/7837
{"SYNC-HAZARD-WRITE-AFTER-READ",
"load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info (usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_FRAGMENT_SHADER_SHADER_"},
// From: TraceTest.catalyst_black http://anglebug.com/7924
{"SYNC-HAZARD-WRITE-AFTER-READ",
"store with storeOp VK_ATTACHMENT_STORE_OP_STORE. Access info (usage: "
"SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_FRAGMENT_SHADER_SHADER_"},
};
// Messages that shouldn't be generated if storeOp=NONE is supported, otherwise they are expected.
constexpr vk::SkippedSyncvalMessage kSkippedSyncvalMessagesWithoutStoreOpNone[] = {
// These errors are generated when simultaneously using a read-only depth/stencil attachment as
// sampler. This is valid Vulkan.
//
// When storeOp=NONE is not present, ANGLE uses storeOp=STORE, but considers the image read-only
// and produces a hazard. ANGLE relies on storeOp=NONE and so this is not expected to be worked
// around.
//
// With storeOp=NONE, there is another bug where a depth/stencil attachment may use storeOp=NONE
// for depth while storeOp=DONT_CARE for stencil, and the latter causes a synchronization error
// (similarly to the previous case as DONT_CARE is also a write operation).
// http://anglebug.com/5962
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"depth aspect during store with storeOp VK_ATTACHMENT_STORE_OP_STORE. Access info (usage: "
"SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE",
"usage: SYNC_FRAGMENT_SHADER_SHADER_",
},
{
"SYNC-HAZARD-WRITE-AFTER-READ",
"stencil aspect during store with stencilStoreOp VK_ATTACHMENT_STORE_OP_STORE. Access info "
"(usage: SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE",
"usage: SYNC_FRAGMENT_SHADER_SHADER_",
},
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"imageLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL",
"usage: SYNC_FRAGMENT_SHADER_SHADER_",
},
// From: TraceTest.antutu_refinery http://anglebug.com/6663
{
"SYNC-HAZARD-READ-AFTER-WRITE",
"imageLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL",
"usage: SYNC_COMPUTE_SHADER_SHADER_SAMPLED_READ",
},
};
// Messages that shouldn't be generated if both loadOp=NONE and storeOp=NONE are supported,
// otherwise they are expected.
constexpr vk::SkippedSyncvalMessage kSkippedSyncvalMessagesWithoutLoadStoreOpNone[] = {
// This error is generated for multiple reasons:
//
// - http://anglebug.com/6411
// - http://anglebug.com/5371: This is resolved with storeOp=NONE
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: "
"SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, write_barriers: 0, command: "
"vkCmdEndRenderPass",
},
// http://anglebug.com/6411
// http://anglebug.com/6584
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"aspect depth during load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info (usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION",
},
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"aspect stencil during load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info "
"(usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE",
},
// http://anglebug.com/5962
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"aspect stencil during load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info "
"(usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION",
},
{
"SYNC-HAZARD-WRITE-AFTER-WRITE",
"aspect stencil during load with loadOp VK_ATTACHMENT_LOAD_OP_DONT_CARE. Access info "
"(usage: "
"SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, prior_usage: "
"SYNC_IMAGE_LAYOUT_TRANSITION",
},
};
enum class DebugMessageReport
{
Ignore,
Print,
};
bool IsMessageInSkipList(const char *message,
const char *const skippedList[],
size_t skippedListSize)
{
for (size_t index = 0; index < skippedListSize; ++index)
{
if (strstr(message, skippedList[index]) != nullptr)
{
return true;
}
}
return false;
}
// Suppress validation errors that are known. Returns DebugMessageReport::Ignore in that case.
DebugMessageReport ShouldReportDebugMessage(RendererVk *renderer,
const char *messageId,
const char *message)
{
if (message == nullptr)
{
return DebugMessageReport::Print;
}
// Check with non-syncval messages:
const std::vector<const char *> &skippedMessages = renderer->getSkippedValidationMessages();
if (IsMessageInSkipList(message, skippedMessages.data(), skippedMessages.size()))
{
return DebugMessageReport::Ignore;
}
// Then check with syncval messages:
const bool isFramebufferFetchUsed = renderer->isFramebufferFetchUsed();
for (const vk::SkippedSyncvalMessage &msg : renderer->getSkippedSyncvalMessages())
{
if (strstr(messageId, msg.messageId) == nullptr ||
strstr(message, msg.messageContents1) == nullptr ||
strstr(message, msg.messageContents2) == nullptr)
{
continue;
}
// If the error is due to exposing coherent framebuffer fetch (without
// VK_EXT_rasterization_order_attachment_access), but framebuffer fetch has not been used by
// the application, report it.
//
// Note that currently syncval doesn't support the
// VK_EXT_rasterization_order_attachment_access extension, so the syncval messages would
// continue to be produced despite the extension.
constexpr bool kSyncValSupportsRasterizationOrderExtension = false;
const bool hasRasterizationOrderExtension =
renderer->getFeatures().supportsRasterizationOrderAttachmentAccess.enabled &&
kSyncValSupportsRasterizationOrderExtension;
if (msg.isDueToNonConformantCoherentFramebufferFetch &&
(!isFramebufferFetchUsed || hasRasterizationOrderExtension))
{
return DebugMessageReport::Print;
}
// Otherwise ignore the message
return DebugMessageReport::Ignore;
}
return DebugMessageReport::Print;
}
const char *GetVkObjectTypeName(VkObjectType type)
{
switch (type)
{
case VK_OBJECT_TYPE_UNKNOWN:
return "Unknown";
case VK_OBJECT_TYPE_INSTANCE:
return "Instance";
case VK_OBJECT_TYPE_PHYSICAL_DEVICE:
return "Physical Device";
case VK_OBJECT_TYPE_DEVICE:
return "Device";
case VK_OBJECT_TYPE_QUEUE:
return "Queue";
case VK_OBJECT_TYPE_SEMAPHORE:
return "Semaphore";
case VK_OBJECT_TYPE_COMMAND_BUFFER:
return "Command Buffer";
case VK_OBJECT_TYPE_FENCE:
return "Fence";
case VK_OBJECT_TYPE_DEVICE_MEMORY:
return "Device Memory";
case VK_OBJECT_TYPE_BUFFER:
return "Buffer";
case VK_OBJECT_TYPE_IMAGE:
return "Image";
case VK_OBJECT_TYPE_EVENT:
return "Event";
case VK_OBJECT_TYPE_QUERY_POOL:
return "Query Pool";
case VK_OBJECT_TYPE_BUFFER_VIEW:
return "Buffer View";
case VK_OBJECT_TYPE_IMAGE_VIEW:
return "Image View";
case VK_OBJECT_TYPE_SHADER_MODULE:
return "Shader Module";
case VK_OBJECT_TYPE_PIPELINE_CACHE:
return "Pipeline Cache";
case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
return "Pipeline Layout";
case VK_OBJECT_TYPE_RENDER_PASS:
return "Render Pass";
case VK_OBJECT_TYPE_PIPELINE:
return "Pipeline";
case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
return "Descriptor Set Layout";
case VK_OBJECT_TYPE_SAMPLER:
return "Sampler";
case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
return "Descriptor Pool";
case VK_OBJECT_TYPE_DESCRIPTOR_SET:
return "Descriptor Set";
case VK_OBJECT_TYPE_FRAMEBUFFER:
return "Framebuffer";
case VK_OBJECT_TYPE_COMMAND_POOL:
return "Command Pool";
case VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION:
return "Sampler YCbCr Conversion";
case VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE:
return "Descriptor Update Template";
case VK_OBJECT_TYPE_SURFACE_KHR:
return "Surface";
case VK_OBJECT_TYPE_SWAPCHAIN_KHR:
return "Swapchain";
case VK_OBJECT_TYPE_DISPLAY_KHR:
return "Display";
case VK_OBJECT_TYPE_DISPLAY_MODE_KHR:
return "Display Mode";
case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV:
return "Indirect Commands Layout";
case VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT:
return "Debug Utils Messenger";
case VK_OBJECT_TYPE_VALIDATION_CACHE_EXT:
return "Validation Cache";
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV:
return "Acceleration Structure";
default:
return "<Unrecognized>";
}
}
VKAPI_ATTR VkBool32 VKAPI_CALL
DebugUtilsMessenger(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
const VkDebugUtilsMessengerCallbackDataEXT *callbackData,
void *userData)
{
RendererVk *rendererVk = static_cast<RendererVk *>(userData);
// See if it's an issue we are aware of and don't want to be spammed about.
if (ShouldReportDebugMessage(rendererVk, callbackData->pMessageIdName,
callbackData->pMessage) == DebugMessageReport::Ignore)
{
return VK_FALSE;
}
std::ostringstream log;
if (callbackData->pMessageIdName)
{
log << "[ " << callbackData->pMessageIdName << " ] ";
}
log << callbackData->pMessage << std::endl;
// Aesthetic value based on length of the function name, line number, etc.
constexpr size_t kStartIndent = 28;
// Output the debug marker hierarchy under which this error has occured.
size_t indent = kStartIndent;
if (callbackData->queueLabelCount > 0)
{
log << std::string(indent++, ' ') << "<Queue Label Hierarchy:>" << std::endl;
for (uint32_t i = 0; i < callbackData->queueLabelCount; ++i)
{
log << std::string(indent++, ' ') << callbackData->pQueueLabels[i].pLabelName
<< std::endl;
}
}
if (callbackData->cmdBufLabelCount > 0)
{
log << std::string(indent++, ' ') << "<Command Buffer Label Hierarchy:>" << std::endl;
for (uint32_t i = 0; i < callbackData->cmdBufLabelCount; ++i)
{
log << std::string(indent++, ' ') << callbackData->pCmdBufLabels[i].pLabelName
<< std::endl;
}
}
// Output the objects involved in this error message.
if (callbackData->objectCount > 0)
{
for (uint32_t i = 0; i < callbackData->objectCount; ++i)
{
const char *objectName = callbackData->pObjects[i].pObjectName;
const char *objectType = GetVkObjectTypeName(callbackData->pObjects[i].objectType);
uint64_t objectHandle = callbackData->pObjects[i].objectHandle;
log << std::string(indent, ' ') << "Object: ";
if (objectHandle == 0)
{
log << "VK_NULL_HANDLE";
}
else
{
log << "0x" << std::hex << objectHandle << std::dec;
}
log << " (type = " << objectType << "(" << callbackData->pObjects[i].objectType << "))";
if (objectName)
{
log << " [" << objectName << "]";
}
log << std::endl;
}
}
bool isError = (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) != 0;
std::string msg = log.str();
rendererVk->onNewValidationMessage(msg);
if (isError)
{
ERR() << msg;
}
else
{
WARN() << msg;
}
return VK_FALSE;
}
VKAPI_ATTR void VKAPI_CALL
MemoryReportCallback(const VkDeviceMemoryReportCallbackDataEXT *callbackData, void *userData)
{
RendererVk *rendererVk = static_cast<RendererVk *>(userData);
rendererVk->processMemoryReportCallback(*callbackData);
}
bool ShouldUseValidationLayers(const egl::AttributeMap &attribs)
{
#if defined(ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS_BY_DEFAULT)
return ShouldUseDebugLayers(attribs);
#else
EGLAttrib debugSetting =
attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE);
return debugSetting == EGL_TRUE;
#endif // defined(ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS_BY_DEFAULT)
}
gl::Version LimitVersionTo(const gl::Version ¤t, const gl::Version &lower)
{
return std::min(current, lower);
}
[[maybe_unused]] bool FencePropertiesCompatibleWithAndroid(
const VkExternalFenceProperties &externalFenceProperties)
{
// handleType here is the external fence type -
// we want type compatible with creating and export/dup() Android FD
// Imported handleType that can be exported - need for vkGetFenceFdKHR()
if ((externalFenceProperties.exportFromImportedHandleTypes &
VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR) == 0)
{
return false;
}
// HandleTypes which can be specified at creating a fence
if ((externalFenceProperties.compatibleHandleTypes &
VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR) == 0)
{
return false;
}
constexpr VkExternalFenceFeatureFlags kFeatureFlags =
(VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR |
VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR);
if ((externalFenceProperties.externalFenceFeatures & kFeatureFlags) != kFeatureFlags)
{
return false;
}
return true;
}
[[maybe_unused]] bool SemaphorePropertiesCompatibleWithAndroid(
const VkExternalSemaphoreProperties &externalSemaphoreProperties)
{
// handleType here is the external semaphore type -
// we want type compatible with importing an Android FD
constexpr VkExternalSemaphoreFeatureFlags kFeatureFlags =
(VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR);
if ((externalSemaphoreProperties.externalSemaphoreFeatures & kFeatureFlags) != kFeatureFlags)
{
return false;
}
return true;
}
// CRC16-CCITT is used for header before the pipeline cache key data.
uint16_t ComputeCRC16(const uint8_t *data, const size_t size)
{
constexpr uint16_t kPolynomialCRC16 = 0x8408;
uint16_t rem = 0;
for (size_t i = 0; i < size; i++)
{
rem ^= data[i];
for (int j = 0; j < 8; j++)
{
rem = (rem & 1) ? kPolynomialCRC16 ^ (rem >> 1) : rem >> 1;
}
}
return rem;
}
// Pack header data for the pipeline cache key data.
void PackHeaderDataForPipelineCache(uint32_t cacheDataSize,
uint16_t compressedDataCRC,
uint8_t numChunks,
uint8_t chunkIndex,
uint64_t *dataOut)
{
uint64_t concatenatedData = cacheDataSize;
concatenatedData = (concatenatedData << 16) | compressedDataCRC;
concatenatedData = (concatenatedData << 8) | numChunks;
concatenatedData = (concatenatedData << 8) | chunkIndex;
*dataOut = concatenatedData;
}
// Unpack header data from the pipeline cache key data.
void UnpackHeaderDataForPipelineCache(uint64_t data,
uint32_t *cacheDataSizeOut,
uint16_t *compressedDataCRCOut,
size_t *numChunksOut,
size_t *chunkIndexOut)
{
*chunkIndexOut = data & 0xFF;
data >>= 8;
*numChunksOut = data & 0xFF;
data >>= 8;
*compressedDataCRCOut = data & 0xFFFF;
data >>= 16;
*cacheDataSizeOut = static_cast<uint32_t>(data);
}
void ComputePipelineCacheVkChunkKey(VkPhysicalDeviceProperties physicalDeviceProperties,
const uint8_t chunkIndex,
egl::BlobCache::Key *hashOut)
{
std::ostringstream hashStream("ANGLE Pipeline Cache: ", std::ios_base::ate);
// Add the pipeline cache UUID to make sure the blob cache always gives a compatible pipeline
// cache. It's not particularly necessary to write it as a hex number as done here, so long as
// there is no '\0' in the result.
for (const uint32_t c : physicalDeviceProperties.pipelineCacheUUID)
{
hashStream << std::hex << c;
}
// Add the vendor and device id too for good measure.
hashStream << std::hex << physicalDeviceProperties.vendorID;
hashStream << std::hex << physicalDeviceProperties.deviceID;
// Add chunkIndex to generate unique key for chunks.
hashStream << std::hex << chunkIndex;
const std::string &hashString = hashStream.str();
angle::base::SHA1HashBytes(reinterpret_cast<const unsigned char *>(hashString.c_str()),
hashString.length(), hashOut->data());
}
void CompressAndStorePipelineCacheVk(VkPhysicalDeviceProperties physicalDeviceProperties,
DisplayVk *displayVk,
ContextVk *contextVk,
const std::vector<uint8_t> &cacheData,
const size_t maxTotalSize)
{
// Though the pipeline cache will be compressed and divided into several chunks to store in blob
// cache, the largest total size of blob cache is only 2M in android now, so there is no use to
// handle big pipeline cache when android will reject it finally.
if (cacheData.size() >= maxTotalSize)
{
// TODO: handle the big pipeline cache. http://anglebug.com/4722
ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_LOW,
"Skip syncing pipeline cache data when it's larger than maxTotalSize.");
return;
}
// To make it possible to store more pipeline cache data, compress the whole pipelineCache.
angle::MemoryBuffer compressedData;
if (!egl::CompressBlobCacheData(cacheData.size(), cacheData.data(), &compressedData))
{
ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_LOW,
"Skip syncing pipeline cache data as it failed compression.");
return;
}
// If the size of compressedData is larger than (kMaxBlobCacheSize - sizeof(numChunks)),
// the pipelineCache still can't be stored in blob cache. Divide the large compressed
// pipelineCache into several parts to store seperately. There is no function to
// query the limit size in android.
constexpr size_t kMaxBlobCacheSize = 64 * 1024;
size_t compressedOffset = 0;
const size_t numChunks = UnsignedCeilDivide(static_cast<unsigned int>(compressedData.size()),
kMaxBlobCacheSize - kBlobHeaderSize);
size_t chunkSize = UnsignedCeilDivide(static_cast<unsigned int>(compressedData.size()),
static_cast<unsigned int>(numChunks));
uint16_t compressedDataCRC = 0;
if (kEnableCRCForPipelineCache)
{
compressedDataCRC = ComputeCRC16(compressedData.data(), compressedData.size());
}
for (size_t chunkIndex = 0; chunkIndex < numChunks; ++chunkIndex)
{
if (chunkIndex == numChunks - 1)
{
chunkSize = compressedData.size() - compressedOffset;
}
angle::MemoryBuffer keyData;
if (!keyData.resize(kBlobHeaderSize + chunkSize))
{
ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_LOW,
"Skip syncing pipeline cache data due to out of memory.");
return;
}
// Add the header data, followed by the compressed data.
ASSERT(numChunks <= UINT8_MAX && chunkIndex <= UINT8_MAX && cacheData.size() <= UINT32_MAX);
uint64_t headerData;
PackHeaderDataForPipelineCache(static_cast<uint32_t>(cacheData.size()), compressedDataCRC,
static_cast<uint8_t>(numChunks),
static_cast<uint8_t>(chunkIndex), &headerData);
*reinterpret_cast<uint64_t *>(keyData.data()) = headerData;