-
Notifications
You must be signed in to change notification settings - Fork 69
/
vk_physical_device.cpp
7464 lines (6257 loc) · 337 KB
/
vk_physical_device.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) 2014-2020 Advanced Micro Devices, Inc. All Rights Reserved.
*
* 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.
*
**********************************************************************************************************************/
/**
***********************************************************************************************************************
* @file vk_physical_device.cpp
* @brief Contains implementation of Vulkan physical device.
***********************************************************************************************************************
*/
#include "include/khronos/vulkan.h"
#include "include/color_space_helper.h"
#include "include/vk_buffer_view.h"
#include "include/vk_dispatch.h"
#include "include/vk_device.h"
#include "include/vk_physical_device.h"
#include "include/vk_physical_device_manager.h"
#include "include/vk_display.h"
#include "include/vk_display_manager.h"
#include "include/vk_image.h"
#include "include/vk_instance.h"
#include "include/vk_utils.h"
#include "include/vk_conv.h"
#include "include/vk_surface.h"
#include "include/khronos/vk_icd.h"
#include "llpc.h"
#include "res/ver.h"
#include "settings/settings.h"
#include "palDevice.h"
#include "palCmdBuffer.h"
#include "palFormatInfo.h"
#include "palLib.h"
#include "palMath.h"
#include "palMsaaState.h"
#include "palPlatformKey.h"
#include "palScreen.h"
#include "palHashLiteralString.h"
#include "palVectorImpl.h"
#include <string>
#include <vector>
#undef max
#undef min
#include <cstring>
#include <algorithm>
#include <climits>
#include <type_traits>
namespace vk
{
// Vulkan Spec Table 30.11: All features in optimalTilingFeatures
constexpr VkFormatFeatureFlags AllImgFeatures =
VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
VK_FORMAT_FEATURE_BLIT_SRC_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT |
VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT |
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_FORMAT_FEATURE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT |
VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT|
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT|
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT|
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT|
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT|
VK_FORMAT_FEATURE_DISJOINT_BIT|
VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT|
VK_FORMAT_FEATURE_BLIT_DST_BIT;
// Vulkan Spec Table 30.12: All features in bufferFeatures
constexpr VkFormatFeatureFlags AllBufFeatures =
VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT |
VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT |
VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT |
VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
#if PAL_ENABLE_PRINTS_ASSERTS
static void VerifyProperties(const PhysicalDevice& device);
#endif
// =====================================================================================================================
static bool VerifyFormatSupport(
const PhysicalDevice& device,
VkFormat format,
uint32_t sampledImageBit,
uint32_t blitSrcBit,
uint32_t sampledImageFilterLinearBit,
uint32_t storageImageBit,
uint32_t storageImageAtomicBit,
uint32_t colorAttachmentBit,
uint32_t blitDstBit,
uint32_t colorAttachmentBlendBit,
uint32_t depthStencilAttachmentBit,
uint32_t vertexBufferBit,
uint32_t uniformTexelBufferBit,
uint32_t storageTexelBufferBit,
uint32_t storageTexelBufferAtomicBit)
{
bool supported = true;
VkFormatProperties props = {};
VkResult result = device.GetFormatProperties(format, &props);
if (result == VK_SUCCESS)
{
VK_ASSERT((props.optimalTilingFeatures & ~AllImgFeatures) == 0);
VK_ASSERT((props.linearTilingFeatures & ~AllImgFeatures) == 0);
VK_ASSERT((props.bufferFeatures & ~AllBufFeatures) == 0);
if (sampledImageBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0;
// Formats that are required to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT must also support
// VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT.
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT) != 0;
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_TRANSFER_DST_BIT) != 0;
}
if (blitSrcBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) != 0;
}
if (sampledImageFilterLinearBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) != 0;
}
if (storageImageBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0;
}
if (storageImageAtomicBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) != 0;
}
if (colorAttachmentBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0;
}
if (blitDstBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT) != 0;
}
if (colorAttachmentBlendBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) != 0;
}
if (depthStencilAttachmentBit)
{
supported &= (props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0;
}
if (vertexBufferBit)
{
supported &= (props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0;
}
if (uniformTexelBufferBit)
{
supported &= (props.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) != 0;
}
if (storageTexelBufferBit)
{
supported &= (props.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) != 0;
}
if (storageTexelBufferAtomicBit)
{
supported &= (props.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) != 0;
}
}
else
{
supported = false;
}
return supported;
}
// =====================================================================================================================
// Returns true if the given physical device supports the minimum required compressed texture formats to report ETC2
// support
static bool VerifyEtc2FormatSupport(
const PhysicalDevice& dev)
{
// Based on vulkan spec Table 67: Mandatory format support: ETC2 and EAC compressed formats with VkImageType
// VK_IMAGE_TYPE_2D
const bool etc2Support =
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_EAC_R11_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_EAC_R11_SNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return etc2Support;
}
// =====================================================================================================================
// Returns true if the given physical device supports the minimum required compressed texture formats to report ASTC-LDR
// support
static bool VerifyAstcLdrFormatSupport(
const PhysicalDevice& dev)
{
// Based on vulkan spec Table 68: Mandatory format support: ASTC LDR compressed formats with VkImageType
// VK_IMAGE_TYPE_2D
const bool astcLdrSupport =
VerifyFormatSupport(dev, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return astcLdrSupport;
}
// =====================================================================================================================
// Returns true if the given physical device supports the minimum required BC compressed texture format
// requirements
static bool VerifyBCFormatSupport(
const PhysicalDevice& dev)
{
// Based on Vulkan Spec Table 30.20. Mandatory format support: BC compressed formats with VkImageType VK_IMAGE_TYPE_2D and
// VK_IMAGE_TYPE_3D.
const bool bcSupport =
VerifyFormatSupport(dev, VK_FORMAT_BC1_RGB_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC1_RGB_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC2_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC2_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC3_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC3_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC4_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC4_SNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC5_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC5_SNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC6H_UFLOAT_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC6H_SFLOAT_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC7_UNORM_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) &&
VerifyFormatSupport(dev, VK_FORMAT_BC7_SRGB_BLOCK, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return bcSupport;
}
// =====================================================================================================================
PhysicalDevice::PhysicalDevice(
PhysicalDeviceManager* pPhysicalDeviceManager,
Pal::IDevice* pPalDevice,
VulkanSettingsLoader* pSettingsLoader,
AppProfile appProfile
)
:
m_pPhysicalDeviceManager(pPhysicalDeviceManager),
m_pPalDevice(pPalDevice),
m_memoryTypeMask(0),
m_memoryTypeMaskForExternalSharing(0),
m_memoryVkIndexAttachmentImage(0),
m_pSettingsLoader(pSettingsLoader),
m_sampleLocationSampleCounts(0),
m_vrHighPrioritySubEngineIndex(UINT32_MAX),
m_RtCuHighComputeSubEngineIndex(UINT32_MAX),
m_queueFamilyCount(0),
m_appProfile(appProfile),
m_prtOnDmaSupported(true),
m_eqaaSupported(true),
m_supportedExtensions(),
m_allowedExtensions(),
m_compiler(this),
m_memoryUsageTracker {},
m_pPlatformKey(nullptr)
{
memset(&m_limits, 0, sizeof(m_limits));
memset(m_formatFeatureMsaaTarget, 0, sizeof(m_formatFeatureMsaaTarget));
memset(&m_queueFamilies, 0, sizeof(m_queueFamilies));
memset(&m_memoryProperties, 0, sizeof(m_memoryProperties));
memset(&m_gpaProps, 0, sizeof(m_gpaProps));
memset(&m_memoryVkIndexAddRemoteBackupHeap, 0, sizeof(m_memoryVkIndexAddRemoteBackupHeap));
for (uint32_t i = 0; i < Pal::GpuHeapCount; i++)
{
m_memoryPalHeapToVkIndexBits[i] = 0; // invalid bits
m_memoryPalHeapToVkHeap[i] = Pal::GpuHeapCount; // invalid index
}
for (uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; i++)
{
m_memoryVkIndexToPalHeap[i] = Pal::GpuHeapCount; // invalid index
}
memset(&m_pipelineCacheUUID, 0, VK_UUID_SIZE);
for (uint32_t i = 0; i < VkMemoryHeapNum; ++i)
{
m_heapVkToPal[i] = Pal::GpuHeapCount; // invalid index
}
}
// =====================================================================================================================
// Creates a new Vulkan physical device object
VkResult PhysicalDevice::Create(
PhysicalDeviceManager* pPhysicalDeviceManager,
Pal::IDevice* pPalDevice,
VulkanSettingsLoader* pSettingsLoader,
AppProfile appProfile,
VkPhysicalDevice* pPhysicalDevice)
{
VK_ASSERT(pPhysicalDeviceManager != nullptr);
void* pMemory = pPhysicalDeviceManager->VkInstance()->AllocMem(sizeof(ApiPhysicalDevice),
VK_DEFAULT_MEM_ALIGN,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (pMemory == nullptr)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
VK_INIT_DISPATCHABLE(PhysicalDevice, pMemory, (pPhysicalDeviceManager, pPalDevice, pSettingsLoader, appProfile));
VkPhysicalDevice handle = reinterpret_cast<VkPhysicalDevice>(pMemory);
PhysicalDevice* pObject = ApiPhysicalDevice::ObjectFromHandle(handle);
VkResult result = pObject->Initialize();
if (result == VK_SUCCESS)
{
*pPhysicalDevice = handle;
}
else
{
pObject->Destroy();
}
return result;
}
// =====================================================================================================================
// Converts from PAL format feature properties to Vulkan equivalents.
static void GetFormatFeatureFlags(
const Pal::MergedFormatPropertiesTable& formatProperties,
VkFormat format,
VkImageTiling imageTiling,
VkFormatFeatureFlags* pOutFormatFeatureFlags,
const RuntimeSettings& settings)
{
const Pal::SwizzledFormat swizzledFormat = VkToPalFormat(format, settings);
const size_t formatIdx = static_cast<size_t>(swizzledFormat.format);
const size_t tilingIdx = ((imageTiling == VK_IMAGE_TILING_LINEAR) ? Pal::IsLinear : Pal::IsNonLinear);
VkFormatFeatureFlags retFlags = PalToVkFormatFeatureFlags(formatProperties.features[formatIdx][tilingIdx]);
// Only expect vertex buffer support for core formats for now (change this if needed otherwise in the future).
if (VK_ENUM_IN_RANGE(format, VK_FORMAT) && (imageTiling == VK_IMAGE_TILING_LINEAR))
{
bool canSupportVertexFormat = false;
canSupportVertexFormat = Llpc::ICompiler::IsVertexFormatSupported(format);
if (canSupportVertexFormat)
{
retFlags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
}
}
// As in Vulkan we have to return support for VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT based on
// the depth aspect for depth-stencil images we have to handle this case explicitly here.
if (Formats::HasDepth(format) && ((retFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0))
{
Pal::SwizzledFormat depthFormat = VkToPalFormat(
Formats::GetAspectFormat(format, VK_IMAGE_ASPECT_DEPTH_BIT), settings);
const size_t depthFormatIdx = static_cast<size_t>(depthFormat.format);
VkFormatFeatureFlags depthFlags = PalToVkFormatFeatureFlags(
formatProperties.features[depthFormatIdx][tilingIdx]);
if ((depthFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
{
retFlags |= (depthFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
}
// According to the Vulkan Spec (section 32.2.0)
// Re: VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT - If the format is a depth / stencil format,
// this bit only indicates that the depth aspect(not the stencil aspect) of an image of this format
// supports min/max filtering.
if ((depthFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT) != 0)
{
retFlags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT;
}
}
if (Formats::IsDepthStencilFormat(format))
{
if (imageTiling == VK_IMAGE_TILING_LINEAR)
{
retFlags = static_cast<VkFormatFeatureFlags>(0);
}
retFlags &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
retFlags &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
retFlags &= ~VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
}
else
{
retFlags &= ~VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
if (Formats::IsYuvFormat(format))
{
retFlags &= ~VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
retFlags &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
retFlags &= ~VK_FORMAT_FEATURE_BLIT_SRC_BIT;
retFlags &= ~VK_FORMAT_FEATURE_BLIT_DST_BIT;
}
*pOutFormatFeatureFlags = retFlags;
}
// =====================================================================================================================
// Get linear sampler bits for YCbCr plane.
static void GetLinearSampleBits(
const Pal::MergedFormatPropertiesTable& formatProperties,
const Pal::ChNumFormat& palFormat,
Pal::ImageTiling imageTiling,
VkFormatFeatureFlags* formatFeatureFlags)
{
uint32 tilingIdx = static_cast<uint32>(imageTiling);
const size_t formatIdx = static_cast<size_t>(palFormat);
VkFormatFeatureFlags formatRetFlags = PalToVkFormatFeatureFlags(formatProperties.features[formatIdx][tilingIdx]);
if ((formatRetFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) == 0)
{
*formatFeatureFlags &= ~ VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
*formatFeatureFlags &= ~ VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT;
}
}
// =====================================================================================================================
// Checks to see if memory is available for PhysicalDevice local allocations made by the application (externally) and
// reports OOM if necessary
VkResult PhysicalDevice::TryIncreaseAllocatedMemorySize(
Pal::gpusize allocationSize,
uint32_t heapIdx)
{
Util::MutexAuto lock(&m_memoryUsageTracker.trackerMutex);
Pal::gpusize memorySizePostAllocation = m_memoryUsageTracker.allocatedMemorySize[heapIdx] + allocationSize;
return (memorySizePostAllocation > m_memoryUsageTracker.totalMemorySize[heapIdx]) ?
VK_ERROR_OUT_OF_DEVICE_MEMORY : VK_SUCCESS;
}
// =====================================================================================================================
// Increases the allocated memory size for PhysicalDevice local allocations made by the application (externally) and
// reports OOM if necessary
void PhysicalDevice::IncreaseAllocatedMemorySize(
Pal::gpusize allocationSize,
uint32_t heapIdx)
{
Util::MutexAuto lock(&m_memoryUsageTracker.trackerMutex);
m_memoryUsageTracker.allocatedMemorySize[heapIdx] += allocationSize;
}
// =====================================================================================================================
// Decreases the allocated memory size for PhysicalDevice local allocations made by the application (externally)
void PhysicalDevice::DecreaseAllocatedMemorySize(
Pal::gpusize allocationSize,
uint32_t heapIdx)
{
Util::MutexAuto lock(&m_memoryUsageTracker.trackerMutex);
VK_ASSERT(m_memoryUsageTracker.allocatedMemorySize[heapIdx] >= allocationSize);
m_memoryUsageTracker.allocatedMemorySize[heapIdx] -= allocationSize;
}
// =====================================================================================================================
// Determines if the allocation can fit within the allowed budget for the overrideHeapChoiceToLocal setting.
bool PhysicalDevice::IsOverrideHeapChoiceToLocalWithinBudget(
Pal::gpusize size
) const
{
return ((m_memoryUsageTracker.allocatedMemorySize[Pal::GpuHeapLocal] + size) <
m_memoryUsageTracker.totalMemorySize[Pal::GpuHeapLocal] *
(GetRuntimeSettings().overrideHeapChoiceToLocalBudget / 100.0f));
}
// =====================================================================================================================
// Generate our platform key
void PhysicalDevice::InitializePlatformKey(
const RuntimeSettings& settings)
{
static constexpr Util::HashAlgorithm KeyAlgorithm = Util::HashAlgorithm::Sha1;
struct
{
VkPhysicalDeviceProperties properties;
char* timestamp[sizeof(__TIMESTAMP__)];
} initialData;
memset(&initialData, 0, sizeof(initialData));
VkResult result = GetDeviceProperties(&initialData.properties);
if (result == VK_SUCCESS)
{
size_t memSize = Util::GetPlatformKeySize(KeyAlgorithm);
void* pMem = VkInstance()->AllocMem(memSize, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (pMem != nullptr)
{
if (settings.markPipelineCacheWithBuildTimestamp)
{
memcpy(initialData.timestamp, __TIMESTAMP__, sizeof(__TIMESTAMP__));
}
if (Util::CreatePlatformKey(KeyAlgorithm, &initialData, sizeof(initialData), pMem, &m_pPlatformKey) !=
Util::Result::Success)
{
VkInstance()->FreeMem(pMem);
}
}
}
}
// =====================================================================================================================
VkResult PhysicalDevice::Initialize()
{
const bool nullGpu = VkInstance()->IsNullGpuModeEnabled();
// Collect generic device properties
Pal::Result result = m_pPalDevice->GetProperties(&m_properties);
const RuntimeSettings& settings = GetRuntimeSettings();
if (result == Pal::Result::Success)
{
// Finalize the PAL device
Pal::DeviceFinalizeInfo finalizeInfo = {};
// Ask PAL to create the maximum possible number of engines. We ask for maximum support because this has to be
// done before the first Vulkan device is created, and we do not yet know exactly how many engines are needed
// by those devices.
if (nullGpu == false)
{
for (uint32_t idx = 0; idx < Pal::EngineTypeCount; ++idx)
{
const auto& engineProps = m_properties.engineProperties[idx];
finalizeInfo.requestedEngineCounts[idx].engines = ((1 << engineProps.engineCount) - 1);
}
}
if (settings.fullScreenFrameMetadataSupport)
{
finalizeInfo.flags.requireFlipStatus = true;
finalizeInfo.flags.requireFrameMetadata = true;
finalizeInfo.supportedFullScreenFrameMetadata.timerNodeSubmission = true;
finalizeInfo.supportedFullScreenFrameMetadata.frameBeginFlag = true;
finalizeInfo.supportedFullScreenFrameMetadata.frameEndFlag = true;
finalizeInfo.supportedFullScreenFrameMetadata.primaryHandle = true;
finalizeInfo.supportedFullScreenFrameMetadata.p2pCmdFlag = true;
finalizeInfo.supportedFullScreenFrameMetadata.forceSwCfMode = true;
finalizeInfo.supportedFullScreenFrameMetadata.postFrameTimerSubmission = true;
}
finalizeInfo.internalTexOptLevel = VkToPalTexFilterQuality(settings.vulkanTexFilterQuality);
// Finalize the PAL device
result = m_pPalDevice->Finalize(finalizeInfo);
}
Pal::GpuMemoryHeapProperties heapProperties[Pal::GpuHeapCount] = {};
// Collect memory properties
if (result == Pal::Result::Success)
{
result = m_pPalDevice->GetGpuMemoryHeapProperties(heapProperties);
}
if (result == Pal::Result::Success)
{
for (uint32_t heapIdx = 0; heapIdx < Pal::GpuHeapCount; heapIdx++)
{
m_memoryUsageTracker.totalMemorySize[heapIdx] = heapProperties[heapIdx].heapSize;
}
if (m_memoryUsageTracker.totalMemorySize[Pal::GpuHeapInvisible] == 0)
{
// Disable tracking for the local invisible heap and allow it to overallocate when it has size 0
m_memoryUsageTracker.totalMemorySize[Pal::GpuHeapInvisible] = UINT64_MAX;
}
// Pal in some case can give Vulkan a heap with heapSize = 0 or multiple heaps for the same physical memory.
// Make sure we expose only the valid heap that has a heapSize > 0 and only expose each heap once.
// Vulkan uses memory types to communicate memory properties, so the number exposed is based on our
// choosing in order to communicate possible memory requirements as long as they can be associated
// with an available heap that supports a superset of those requirements.
m_memoryProperties.memoryTypeCount = 0;
m_memoryProperties.memoryHeapCount = 0;
uint32_t heapIndices[Pal::GpuHeapCount] =
{
Pal::GpuHeapCount,
Pal::GpuHeapCount,
Pal::GpuHeapCount,
Pal::GpuHeapCount
};
// this order indicate a simple ordering logic we expose to API
constexpr Pal::GpuHeap priority[Pal::GpuHeapCount] =
{
Pal::GpuHeapInvisible,
Pal::GpuHeapGartUswc,
Pal::GpuHeapLocal,
Pal::GpuHeapGartCacheable
};
const Pal::gpusize invisHeapSize = heapProperties[Pal::GpuHeapInvisible].heapSize;
const Pal::gpusize localHeapSize = heapProperties[Pal::GpuHeapLocal].heapSize;
// Initialize memory heaps
for (uint32_t orderedHeapIndex = 0; orderedHeapIndex < Pal::GpuHeapCount; ++orderedHeapIndex)
{
Pal::GpuHeap palGpuHeap = priority[orderedHeapIndex];
const Pal::GpuMemoryHeapProperties& heapProps = heapProperties[palGpuHeap];
// Initialize each heap if it exists other than GartCacheable, which we know will be shared with GartUswc.
if ((heapProps.heapSize > 0) && (palGpuHeap != Pal::GpuHeapGartCacheable))
{
uint32_t heapIndex = m_memoryProperties.memoryHeapCount++;
VkMemoryHeap& memoryHeap = m_memoryProperties.memoryHeaps[heapIndex];
heapIndices[palGpuHeap] = heapIndex;
memoryHeap.flags = PalGpuHeapToVkMemoryHeapFlags(palGpuHeap);
memoryHeap.size = heapProps.heapSize;
m_heapVkToPal[heapIndex] = palGpuHeap;
m_memoryPalHeapToVkHeap[palGpuHeap] = heapIndex;
if (palGpuHeap == Pal::GpuHeapGartUswc)
{
// These two should match because the PAL GPU heaps share the same physical memory.
VK_ASSERT(memoryHeap.size == heapProperties[Pal::GpuHeapGartCacheable].heapSize);
heapIndices[Pal::GpuHeapGartCacheable] = heapIndex;
}
else if ((palGpuHeap == Pal::GpuHeapLocal) &&
(heapIndices[Pal::GpuHeapInvisible] == Pal::GpuHeapCount))
{
// GPU invisible heap isn't present, but its memory properties are a subset of the GPU local heap.
heapIndices[Pal::GpuHeapInvisible] = heapIndex;
}
}
}
VK_ASSERT(m_memoryProperties.memoryHeapCount <= (Pal::GpuHeapCount - 1));
// Spec requires at least one heap to include VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
if (m_memoryProperties.memoryHeapCount == 1)
{
VK_ASSERT(m_properties.gpuType == Pal::GpuType::Integrated);
m_memoryProperties.memoryHeaps[0].flags |= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
}
// Track that we want to add a matching coherent memory type (VK_AMD_device_coherent_memory)
bool memTypeWantsCoherentMemory[VK_MAX_MEMORY_TYPES] = {};
// Initialize memory types
for (uint32_t orderedHeapIndex = 0; orderedHeapIndex < Pal::GpuHeapCount; ++orderedHeapIndex)
{
Pal::GpuHeap palGpuHeap = priority[orderedHeapIndex];
uint32_t heapIndex = heapIndices[palGpuHeap];
// We must have a heap capable of allocating this memory type to expose it.
if (heapIndex < Pal::GpuHeapCount)
{
uint32_t memoryTypeIndex = m_memoryProperties.memoryTypeCount++;
Pal::GpuHeap allocPalGpuHeap = ((palGpuHeap == Pal::GpuHeapInvisible) && (invisHeapSize == 0)) ? Pal::GpuHeapLocal : palGpuHeap;
m_memoryVkIndexToPalHeap[memoryTypeIndex] = allocPalGpuHeap;
m_memoryPalHeapToVkIndexBits[allocPalGpuHeap] |= (1UL << memoryTypeIndex);
VkMemoryType* pMemoryType = &m_memoryProperties.memoryTypes[memoryTypeIndex];
pMemoryType->heapIndex = heapIndex;
m_memoryTypeMask |= 1 << memoryTypeIndex;
const Pal::GpuMemoryHeapProperties& heapProps = heapProperties[palGpuHeap];
if (heapProps.flags.cpuVisible)
{
pMemoryType->propertyFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
}
if (heapProps.flags.cpuGpuCoherent)
{
pMemoryType->propertyFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
if (heapProps.flags.cpuUncached == 0)
{
pMemoryType->propertyFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
}
if (m_memoryProperties.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
{
pMemoryType->propertyFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
if (m_memoryProperties.memoryHeapCount > 1)
{
// Add back-up heap for parts with VRAM smaller than 8GB.
// Note: The back-up heap can also be added if overallocation is allowed via
// VK_AMD_memory_overallocation_behavior.
// Use m_heapVkToPal instead of palGpuHeap here to handle cases where multiple memory types
// share the same heap.
const Pal::gpusize heapSize = heapProperties[m_heapVkToPal[pMemoryType->heapIndex]].heapSize;
m_memoryVkIndexAddRemoteBackupHeap[memoryTypeIndex] =
(heapSize < settings.memoryRemoteBackupHeapMinHeapSize);
}
}
if (m_properties.gfxipProperties.flags.supportGl2Uncached)
{
// Add device coherent memory type based on below type:
// 1. Visible and host coherent
// 2. Invisible
if (((pMemoryType->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) &&
(pMemoryType->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) ||
(palGpuHeap == Pal::GpuHeapInvisible))
{
memTypeWantsCoherentMemory[memoryTypeIndex] = true;
}
}
if (palGpuHeap == Pal::GpuHeapInvisible)
{
if ((invisHeapSize + localHeapSize) >= settings.memoryAttachmentImageMemoryTypeMinHeapSize)
{
// The attachment image memory type (unavailable for parts with VRAM smaller than 4GB)
// reports identical properties as the default invisible. However, it does
// not add a remote back-up heap unless overallocation is allowed via
// VK_AMD_memory_overallocation_behavior.
m_memoryVkIndexAttachmentImage = m_memoryProperties.memoryTypeCount++;
m_memoryProperties.memoryTypes[m_memoryVkIndexAttachmentImage] =
m_memoryProperties.memoryTypes[memoryTypeIndex];
m_memoryVkIndexToPalHeap[m_memoryVkIndexAttachmentImage] =
m_memoryVkIndexToPalHeap[memoryTypeIndex];
}
else
{
m_memoryVkIndexAttachmentImage = memoryTypeIndex;
}
}
// Optional: if we have exposed a memory type that is host visible, add a backup
// memory type that is not host visible. We will use it for optimally tiled images.
if (settings.addHostInvisibleMemoryTypesForOptimalImages &&
((pMemoryType->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) &&
// Skip host visible+coherent+cached as we won't need it
((pMemoryType->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) == 0))
{
memoryTypeIndex = m_memoryProperties.memoryTypeCount++;
m_memoryTypeMask |= 1 << memoryTypeIndex;
m_memoryVkIndexToPalHeap[memoryTypeIndex] = palGpuHeap;
m_memoryPalHeapToVkIndexBits[palGpuHeap] |= (1UL << memoryTypeIndex);
VkMemoryType* pNextMemoryType = &m_memoryProperties.memoryTypes[memoryTypeIndex];
constexpr VkFlags hostMask = (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
pNextMemoryType->heapIndex = pMemoryType->heapIndex;
pNextMemoryType->propertyFlags = pMemoryType->propertyFlags & ~hostMask;
}
}
}
VkBool32 protectedMemorySupported = VK_FALSE;
GetPhysicalDeviceProtectedMemoryFeatures(&protectedMemorySupported);
if (protectedMemorySupported)
{
// The heap order of protected memory.
constexpr Pal::GpuHeap ProtectedPriority[Pal::GpuHeapCount - 1] =
{
Pal::GpuHeapGartUswc,
Pal::GpuHeapInvisible,
Pal::GpuHeapLocal
};
bool protectedMemoryTypeFound = false;
for (uint32_t orderedHeapIndex = 0; orderedHeapIndex < Pal::GpuHeapCount - 1; ++orderedHeapIndex)
{
Pal::GpuHeap palGpuHeap = ProtectedPriority[orderedHeapIndex];
const Pal::gpusize heapSize = heapProperties[palGpuHeap].heapSize;
if ((heapSize > 0) && heapProperties[palGpuHeap].flags.supportsTmz)
{
uint32_t memoryTypeIndex = m_memoryProperties.memoryTypeCount++;
m_memoryTypeMask |= 1 << memoryTypeIndex;
m_memoryVkIndexToPalHeap[memoryTypeIndex] = palGpuHeap;
m_memoryPalHeapToVkIndexBits[palGpuHeap] |= (1UL << memoryTypeIndex);
VkMemoryType* pMemType = &m_memoryProperties.memoryTypes[memoryTypeIndex];
pMemType->heapIndex = heapIndices[palGpuHeap];
if ((palGpuHeap != Pal::GpuHeapGartUswc) || (m_memoryProperties.memoryHeapCount == 1))
{
pMemType->propertyFlags = VK_MEMORY_PROPERTY_PROTECTED_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
else
{
pMemType->propertyFlags = VK_MEMORY_PROPERTY_PROTECTED_BIT;
}
protectedMemoryTypeFound = true;
}
}
if (protectedMemoryTypeFound == false)
{
VK_ALERT_ALWAYS_MSG("No protected memory type.");
VK_NEVER_CALLED();
}
}
// Add device coherent memory type based on memory types which have been added in m_memoryProperties.memoryTypes
// In PAL, uncached device memory, which is always device coherent, will be allocated.
if (m_properties.gfxipProperties.flags.supportGl2Uncached)
{
uint32_t currentTypeCount = m_memoryProperties.memoryTypeCount;
for (uint32_t memoryTypeIndex = 0; memoryTypeIndex < currentTypeCount; ++memoryTypeIndex)
{
VkMemoryType* pCurrentmemoryType = &m_memoryProperties.memoryTypes[memoryTypeIndex];
VkMemoryType* pLastMemoryType = &m_memoryProperties.memoryTypes[m_memoryProperties.memoryTypeCount];
if (memTypeWantsCoherentMemory[memoryTypeIndex])
{
pLastMemoryType->heapIndex = pCurrentmemoryType->heapIndex;
pLastMemoryType->propertyFlags = pCurrentmemoryType->propertyFlags |
VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD |
VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD;
m_memoryVkIndexToPalHeap[m_memoryProperties.memoryTypeCount] =
m_memoryVkIndexToPalHeap[memoryTypeIndex];
m_memoryPalHeapToVkIndexBits[m_memoryVkIndexToPalHeap[m_memoryProperties.memoryTypeCount]] |=
(1UL << memoryTypeIndex);
m_memoryTypeMask |= 1 << m_memoryProperties.memoryTypeCount;
++m_memoryProperties.memoryTypeCount;
}
}
}
VK_ASSERT(m_memoryProperties.memoryTypeCount <= VK_MAX_MEMORY_TYPES);
VK_ASSERT(m_memoryProperties.memoryHeapCount <= Pal::GpuHeapCount);
}
m_memoryTypeMaskForExternalSharing = m_memoryTypeMask;
if (result == Pal::Result::Success)
{
// Determine if EQAA is supported by checking if, for each MSAA fragment count, all sample combos are okay.
const auto& imgProps = PalProperties().imageProperties;
m_eqaaSupported = true;
switch (imgProps.maxMsaaFragments)
{
default:
VK_NEVER_CALLED();
break;
case 8:
m_eqaaSupported &= Util::TestAllFlagsSet(imgProps.msaaSupport, Pal::MsaaFlags::MsaaAllF8);
// fallthrough
case 4:
m_eqaaSupported &= Util::TestAllFlagsSet(imgProps.msaaSupport, Pal::MsaaFlags::MsaaAllF4);
// fallthrough
case 2:
m_eqaaSupported &= Util::TestAllFlagsSet(imgProps.msaaSupport, Pal::MsaaFlags::MsaaAllF2);
// fallthrough
case 1:
m_eqaaSupported &= Util::TestAllFlagsSet(imgProps.msaaSupport, Pal::MsaaFlags::MsaaAllF1);
break;
}
}
if (result == Pal::Result::Success)
{
// Get properties from PAL
const Pal::DeviceProperties& palProps = PalProperties();
// This UUID identifies whether a previously created pipeline cache is compatible with the currently installed
// device/driver.
constexpr uint16_t PalMajorVersion = PAL_INTERFACE_MAJOR_VERSION;
constexpr uint8_t PalMinorVersion = PAL_INTERFACE_MINOR_VERSION;
constexpr char timestamp[] = __DATE__ __TIME__;
const uint32_t timestampHash = Util::HashLiteralString<sizeof(timestamp)>(timestamp);
memset(m_pipelineCacheUUID, 0, VK_UUID_SIZE);
Util::SystemInfo systemInfo = {};
result = Util::QuerySystemInfo(&systemInfo);
if (result == Pal::Result::Success)
{
Util::MetroHash128 hash = {};
hash.Update(timestampHash);
hash.Update(palProps.vendorId);
hash.Update(palProps.deviceId);
hash.Update(PalMajorVersion);
hash.Update(PalMinorVersion);
hash.Update(systemInfo.cpuType);
hash.Update(systemInfo.cpuVendorString[0]);
hash.Update(systemInfo.cpuBrandString[0]);
hash.Update(systemInfo.cpuLogicalCoreCount);
hash.Update(systemInfo.cpuPhysicalCoreCount);
hash.Update(systemInfo.totalSysMemSize);
hash.Finalize(m_pipelineCacheUUID);
}
}
// Collect properties for perf experiments (this call can fail; we just don't report support for
// perf measurement extension then)
if (result == Pal::Result::Success)
{
PopulateGpaProperties();
}