forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvklayertests_ycbcr.cpp
1321 lines (1131 loc) · 66.6 KB
/
vklayertests_ycbcr.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) 2015-2023 The Khronos Group Inc.
* Copyright (c) 2015-2023 Valve Corporation
* Copyright (c) 2015-2023 LunarG, Inc.
* Copyright (c) 2015-2023 Google, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
#include "cast_utils.h"
#include "enum_flag_bits.h"
#include "layer_validation_tests.h"
#include "vk_layer_utils.h"
TEST_F(VkLayerTest, CreateYCbCrSampler) {
TEST_DESCRIPTION("Verify YCbCr sampler creation.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto ycbcr_features = LvlInitStruct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>();
GetPhysicalDeviceFeatures2(ycbcr_features);
if (ycbcr_features.samplerYcbcrConversion != VK_TRUE) {
GTEST_SKIP() << "samplerYcbcrConversion feature not supported";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required.";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &ycbcr_features));
PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT = nullptr;
PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = nullptr;
if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceFormatPropertiesEXT, fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
GTEST_SKIP() << "Failed to load device profile layer.";
}
PFN_vkCreateSamplerYcbcrConversionKHR vkCreateSamplerYcbcrConversionFunction = nullptr;
PFN_vkDestroySamplerYcbcrConversionKHR vkDestroySamplerYcbcrConversionFunction = nullptr;
if (DeviceValidationVersion() >= VK_API_VERSION_1_1) {
vkCreateSamplerYcbcrConversionFunction = vk::CreateSamplerYcbcrConversion;
vkDestroySamplerYcbcrConversionFunction = vk::DestroySamplerYcbcrConversion;
} else {
vkCreateSamplerYcbcrConversionFunction =
(PFN_vkCreateSamplerYcbcrConversionKHR)vk::GetDeviceProcAddr(m_device->handle(), "vkCreateSamplerYcbcrConversionKHR");
vkDestroySamplerYcbcrConversionFunction =
(PFN_vkDestroySamplerYcbcrConversionKHR)vk::GetDeviceProcAddr(m_device->handle(), "vkDestroySamplerYcbcrConversionKHR");
}
if (!vkCreateSamplerYcbcrConversionFunction || !vkDestroySamplerYcbcrConversionFunction) {
GTEST_SKIP() << "Did not find required device support for YcbcrSamplerConversion";
}
VkSamplerYcbcrConversion ycbcr_conv = VK_NULL_HANDLE;
VkSamplerYcbcrConversionCreateInfo sycci = LvlInitStruct<VkSamplerYcbcrConversionCreateInfo>();
sycci.format = VK_FORMAT_UNDEFINED;
sycci.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
sycci.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
sycci.forceExplicitReconstruction = VK_FALSE;
sycci.chromaFilter = VK_FILTER_NEAREST;
sycci.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
sycci.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
// test non external conversion with a VK_FORMAT_UNDEFINED
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-format-04060");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// test for non unorm
sycci.format = VK_FORMAT_R8G8B8A8_SNORM;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-format-04060");
m_errorMonitor->SetUnexpectedError("VUID-VkSamplerYcbcrConversionCreateInfo-format-01650");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Force the multi-planar format support desired format features
VkFormat mp_format = VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM;
VkFormatProperties formatProps;
fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, &formatProps);
formatProps.linearTilingFeatures = 0;
formatProps.optimalTilingFeatures = 0;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, formatProps);
// Check that errors are caught when format feature don't exist
sycci.format = mp_format;
// No Chroma Sampler Bit set
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-format-01650");
// 01651 set off twice for both xChromaOffset and yChromaOffset
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01651");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01651");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Cosited feature supported, but midpoint samples set
formatProps.linearTilingFeatures = 0;
formatProps.optimalTilingFeatures = VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, formatProps);
sycci.xChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
sycci.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01652");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Moving support to Linear to test that it checks either linear or optimal
formatProps.linearTilingFeatures = VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
formatProps.optimalTilingFeatures = 0;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, formatProps);
sycci.xChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
sycci.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01652");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Using forceExplicitReconstruction without feature bit
sycci.forceExplicitReconstruction = VK_TRUE;
sycci.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
sycci.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-forceExplicitReconstruction-01656");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Linear chroma filtering without feature bit
sycci.forceExplicitReconstruction = VK_FALSE;
sycci.chromaFilter = VK_FILTER_LINEAR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-chromaFilter-01657");
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Add linear feature bit so can create valid SamplerYcbcrConversion
formatProps.linearTilingFeatures = VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
formatProps.optimalTilingFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, formatProps);
vkCreateSamplerYcbcrConversionFunction(device(), &sycci, NULL, &ycbcr_conv);
// Try to create a Sampler with non-matching filters without feature bit set
VkSamplerYcbcrConversionInfo sampler_ycbcr_info = LvlInitStruct<VkSamplerYcbcrConversionInfo>();
sampler_ycbcr_info.conversion = ycbcr_conv;
VkSampler sampler;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
sampler_info.minFilter = VK_FILTER_NEAREST; // Different than chromaFilter
sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.pNext = (void *)&sampler_ycbcr_info;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-minFilter-01645");
vk::CreateSampler(device(), &sampler_info, nullptr, &sampler);
m_errorMonitor->VerifyFound();
sampler_info.magFilter = VK_FILTER_NEAREST;
sampler_info.minFilter = VK_FILTER_LINEAR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-minFilter-01645");
vk::CreateSampler(device(), &sampler_info, nullptr, &sampler);
m_errorMonitor->VerifyFound();
vkDestroySamplerYcbcrConversionFunction(device(), ycbcr_conv, nullptr);
}
TEST_F(VkLayerTest, InvalidSwizzleYCbCr) {
TEST_DESCRIPTION("Verify Invalid use of siwizzle components when dealing with YCbCr.");
// Use 1.1 to get VK_KHR_sampler_ycbcr_conversion easier
SetTargetApiVersion(VK_API_VERSION_1_2);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
auto features11 = LvlInitStruct<VkPhysicalDeviceVulkan11Features>();
auto features2 = GetPhysicalDeviceFeatures2(features11);
if (features11.samplerYcbcrConversion != VK_TRUE) {
GTEST_SKIP() << "samplerYcbcrConversion not supported, skipping test";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const VkFormat mp_format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
// Make sure components doesn't affect _444 formats
VkFormatProperties format_props;
vk::GetPhysicalDeviceFormatProperties(gpu(), mp_format, &format_props);
if ((format_props.optimalTilingFeatures &
(VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT | VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT)) == 0) {
GTEST_SKIP() << "Device does not support chroma sampling of 3plane 420 format";
}
const VkComponentMapping identity = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
VkSamplerYcbcrConversion ycbcr_conv = VK_NULL_HANDLE;
VkSamplerYcbcrConversionCreateInfo sycci = LvlInitStruct<VkSamplerYcbcrConversionCreateInfo>();
sycci.format = mp_format;
sycci.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
sycci.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
sycci.forceExplicitReconstruction = VK_FALSE;
sycci.chromaFilter = VK_FILTER_NEAREST;
sycci.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
sycci.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
// test components.g
// This test is also serves as positive form of VU 01655 since SWIZZLE_A is considered only valid with this format because
// ycbcrModel RGB_IDENTITY
sycci.components = identity;
sycci.components.g = VK_COMPONENT_SWIZZLE_A;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02581");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// test components.a
sycci.components = identity;
sycci.components.a = VK_COMPONENT_SWIZZLE_R;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02582");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// make sure zero and one are allowed for components.a
sycci.components.a = VK_COMPONENT_SWIZZLE_ONE;
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
vk::DestroySamplerYcbcrConversion(device(), ycbcr_conv, nullptr);
sycci.components.a = VK_COMPONENT_SWIZZLE_ZERO;
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
vk::DestroySamplerYcbcrConversion(device(), ycbcr_conv, nullptr);
// test components.r
sycci.components = identity;
sycci.components.r = VK_COMPONENT_SWIZZLE_G;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02583");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02585");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// test components.b
sycci.components = identity;
sycci.components.b = VK_COMPONENT_SWIZZLE_G;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02584");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02585");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// test components.r and components.b together
sycci.components = identity;
sycci.components.r = VK_COMPONENT_SWIZZLE_B;
sycci.components.b = VK_COMPONENT_SWIZZLE_B;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02585");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// make sure components.r and components.b can be swapped
sycci.components = identity;
sycci.components.r = VK_COMPONENT_SWIZZLE_B;
sycci.components.b = VK_COMPONENT_SWIZZLE_R;
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
vk::DestroySamplerYcbcrConversion(device(), ycbcr_conv, nullptr);
// Non RGB Identity model
sycci.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY;
{
// Non RGB Identity can't have a explicit zero swizzle
sycci.components = identity;
sycci.components.g = VK_COMPONENT_SWIZZLE_ZERO;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrModel-01655");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02581");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// Non RGB Identity can't have a explicit one swizzle
sycci.components = identity;
sycci.components.g = VK_COMPONENT_SWIZZLE_ONE;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrModel-01655");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02581");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
// VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM has 3 component so RGBA conversion has implicit A as one
sycci.components = identity;
sycci.components.g = VK_COMPONENT_SWIZZLE_A;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrModel-01655");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02581");
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
m_errorMonitor->VerifyFound();
}
sycci.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY; // reset
// Make sure components doesn't affect _444 formats
vk::GetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM, &format_props);
if ((format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT) != 0) {
sycci.format = VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM;
sycci.components = identity;
sycci.components.g = VK_COMPONENT_SWIZZLE_R;
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
vk::DestroySamplerYcbcrConversion(device(), ycbcr_conv, nullptr);
}
// Create a valid conversion with guaranteed support
sycci.format = mp_format;
sycci.components = identity;
vk::CreateSamplerYcbcrConversion(device(), &sycci, NULL, &ycbcr_conv);
VkImageObj image(m_device);
image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
ASSERT_TRUE(image.initialized());
VkSamplerYcbcrConversionInfo conversion_info = LvlInitStruct<VkSamplerYcbcrConversionInfo>();
conversion_info.conversion = ycbcr_conv;
VkImageView image_view;
VkImageViewCreateInfo image_view_create_info = LvlInitStruct<VkImageViewCreateInfo>(&conversion_info);
image_view_create_info.image = image.handle();
image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
image_view_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_view_create_info.subresourceRange.layerCount = 1;
image_view_create_info.subresourceRange.baseMipLevel = 0;
image_view_create_info.subresourceRange.levelCount = 1;
image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
image_view_create_info.components = identity;
image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_B;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImageViewCreateInfo-pNext-01970");
vk::CreateImageView(m_device->device(), &image_view_create_info, nullptr, &image_view);
m_errorMonitor->VerifyFound();
vk::DestroySamplerYcbcrConversion(device(), ycbcr_conv, nullptr);
}
TEST_F(VkLayerTest, CreateImageYcbcrFormats) {
TEST_DESCRIPTION("Creating images with Ycbcr Formats.");
// Enable KHR multiplane req'd extensions
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT = nullptr;
PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = nullptr;
if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceFormatPropertiesEXT, fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
GTEST_SKIP() << "Failed to load device profile layer.";
}
if (!ImageFormatIsSupported(gpu(), VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM)) {
GTEST_SKIP() << "VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM is unsupported";
}
// Set format features as needed for tests
VkFormatProperties formatProps;
const VkFormat mp_format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, &formatProps);
formatProps.optimalTilingFeatures |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT;
formatProps.optimalTilingFeatures = formatProps.optimalTilingFeatures & ~VK_FORMAT_FEATURE_DISJOINT_BIT;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), mp_format, formatProps);
// Create ycbcr image with all valid values
// Each test changes needed values and returns them back after
VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = mp_format;
image_create_info.extent.width = 32;
image_create_info.extent.height = 32;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
image_create_info.arrayLayers = 1;
VkImageCreateInfo reset_create_info = image_create_info;
VkImageFormatProperties img_limits;
ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &image_create_info, &img_limits));
// invalid mipLevels
if (img_limits.maxMipLevels == 1) {
printf("Multiplane image maxMipLevels is already 1. Skipping test.\n");
} else {
// needs to be 2
// if more then 2 the VU since its larger the (depth^2 + 1)
// if up the depth the VU for IMAGE_TYPE_2D and depth != 1 hits
image_create_info.mipLevels = 2;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-06410");
image_create_info = reset_create_info;
}
// invalid samples count
image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
// Might need to add extra validation because implementation probably doesn't support YUV
VkImageFormatProperties image_format_props;
vk::GetPhysicalDeviceImageFormatProperties(gpu(), mp_format, image_create_info.imageType, image_create_info.tiling,
image_create_info.usage, image_create_info.flags, &image_format_props);
if ((image_format_props.sampleCounts & VK_SAMPLE_COUNT_4_BIT) == 0) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImageCreateInfo-samples-02258");
}
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-06411");
image_create_info = reset_create_info;
// invalid width
image_create_info.extent.width = 31;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-04712");
image_create_info = reset_create_info;
// invalid height (since 420 format)
image_create_info.extent.height = 31;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-04713");
image_create_info = reset_create_info;
// invalid imageType
image_create_info.imageType = VK_IMAGE_TYPE_1D;
// Check that image format is valid
if (vk::GetPhysicalDeviceImageFormatProperties(gpu(), mp_format, image_create_info.imageType, image_create_info.tiling,
image_create_info.usage, image_create_info.flags,
&image_format_props) == VK_SUCCESS) {
// Can't just set height to 1 as stateless validation will hit 04713 first
m_errorMonitor->SetUnexpectedError("VUID-VkImageCreateInfo-imageType-00956");
m_errorMonitor->SetUnexpectedError("VUID-VkImageCreateInfo-extent-02253");
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-06412");
}
image_create_info = reset_create_info;
// Test using a format that doesn't support disjoint
image_create_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageCreateFormatFeatures-02260");
image_create_info = reset_create_info;
}
TEST_F(VkLayerTest, CopyImageSinglePlane422Alignment) {
// Image copy tests on single-plane _422 formats with block alignment errors
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Select a _422 format and verify support
VkImageCreateInfo ci = LvlInitStruct<VkImageCreateInfo>();
ci.flags = 0;
ci.imageType = VK_IMAGE_TYPE_2D;
ci.format = VK_FORMAT_G8B8G8R8_422_UNORM_KHR;
ci.tiling = VK_IMAGE_TILING_OPTIMAL;
ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
ci.mipLevels = 1;
ci.arrayLayers = 1;
ci.samples = VK_SAMPLE_COUNT_1_BIT;
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
ci.queueFamilyIndexCount = 0;
ci.pQueueFamilyIndices = NULL;
ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
// Verify formats
VkFormatFeatureFlags features = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, features);
if (!supported) {
// Assume there's low ROI on searching for different mp formats
GTEST_SKIP() << "Single-plane _422 image format not supported";
}
// Create images
ci.extent = {64, 64, 1};
VkImageObj image_422(m_device);
image_422.init(&ci);
ASSERT_TRUE(image_422.initialized());
ci.extent = {64, 64, 1};
ci.format = VK_FORMAT_R8G8B8A8_UNORM;
VkImageObj image_ucmp(m_device);
image_ucmp.init(&ci);
ASSERT_TRUE(image_ucmp.initialized());
m_commandBuffer->begin();
VkImageCopy copy_region;
copy_region.extent = {48, 48, 1};
copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.srcSubresource.mipLevel = 0;
copy_region.dstSubresource.mipLevel = 0;
copy_region.srcSubresource.baseArrayLayer = 0;
copy_region.dstSubresource.baseArrayLayer = 0;
copy_region.srcSubresource.layerCount = 1;
copy_region.dstSubresource.layerCount = 1;
copy_region.srcOffset = {0, 0, 0};
copy_region.dstOffset = {0, 0, 0};
// Src offsets must be multiples of compressed block sizes
copy_region.srcOffset = {3, 4, 0}; // source offset x
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-pRegions-07278");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcOffset-01783");
m_commandBuffer->CopyImage(image_422.image(), VK_IMAGE_LAYOUT_GENERAL, image_ucmp.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.srcOffset = {0, 0, 0};
// Dst offsets must be multiples of compressed block sizes
copy_region.dstOffset = {1, 0, 0};
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-pRegions-07281");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-dstOffset-01784");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-dstOffset-00150");
m_commandBuffer->CopyImage(image_ucmp.image(), VK_IMAGE_LAYOUT_GENERAL, image_422.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.dstOffset = {0, 0, 0};
// Copy extent must be multiples of compressed block sizes if not full width/height
copy_region.extent = {31, 60, 1}; // 422 source, extent.x
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcImage-01728");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcOffset-01783");
m_commandBuffer->CopyImage(image_422.image(), VK_IMAGE_LAYOUT_GENERAL, image_ucmp.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
// 422 dest
m_commandBuffer->CopyImage(image_ucmp.image(), VK_IMAGE_LAYOUT_GENERAL, image_422.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
copy_region.dstOffset = {0, 0, 0};
m_commandBuffer->end();
}
TEST_F(VkLayerTest, CopyImageMultiplaneAspectBits) {
// Image copy tests on multiplane images with aspect errors
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Select multi-plane formats and verify support
VkFormat mp3_format = VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR;
VkFormat mp2_format = VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR;
VkImageCreateInfo ci = LvlInitStruct<VkImageCreateInfo>();
ci.flags = 0;
ci.imageType = VK_IMAGE_TYPE_2D;
ci.format = mp2_format;
ci.extent = {256, 256, 1};
ci.tiling = VK_IMAGE_TILING_OPTIMAL;
ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
ci.mipLevels = 1;
ci.arrayLayers = 1;
ci.samples = VK_SAMPLE_COUNT_1_BIT;
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
ci.queueFamilyIndexCount = 0;
ci.pQueueFamilyIndices = NULL;
ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
// Verify formats
VkFormatFeatureFlags features = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, features);
ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
supported = supported && ImageFormatAndFeaturesSupported(instance(), gpu(), ci, features);
ci.format = mp3_format;
supported = supported && ImageFormatAndFeaturesSupported(instance(), gpu(), ci, features);
if (!supported) {
// Assume there's low ROI on searching for different mp formats
GTEST_SKIP() << "Multiplane image formats or optimally tiled depth-stencil buffers not supported";
}
// Create images
VkImageObj mp3_image(m_device);
mp3_image.init(&ci);
ASSERT_TRUE(mp3_image.initialized());
ci.format = mp2_format;
VkImageObj mp2_image(m_device);
mp2_image.init(&ci);
ASSERT_TRUE(mp2_image.initialized());
ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
VkImageObj sp_image(m_device);
sp_image.init(&ci);
ASSERT_TRUE(sp_image.initialized());
m_commandBuffer->begin();
VkImageCopy copy_region;
copy_region.extent = {128, 128, 1};
copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
copy_region.srcSubresource.mipLevel = 0;
copy_region.dstSubresource.mipLevel = 0;
copy_region.srcSubresource.baseArrayLayer = 0;
copy_region.dstSubresource.baseArrayLayer = 0;
copy_region.srcSubresource.layerCount = 1;
copy_region.dstSubresource.layerCount = 1;
copy_region.srcOffset = {0, 0, 0};
copy_region.dstOffset = {0, 0, 0};
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcImage-01552");
m_commandBuffer->CopyImage(mp2_image.image(), VK_IMAGE_LAYOUT_GENERAL, mp3_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcImage-01553");
m_commandBuffer->CopyImage(mp3_image.image(), VK_IMAGE_LAYOUT_GENERAL, mp2_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_1_BIT_KHR;
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-dstImage-01554");
m_commandBuffer->CopyImage(mp3_image.image(), VK_IMAGE_LAYOUT_GENERAL, mp2_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-dstImage-01555");
m_commandBuffer->CopyImage(mp2_image.image(), VK_IMAGE_LAYOUT_GENERAL, mp3_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-srcImage-01556");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-None-01549"); // since also non-compatiable
m_commandBuffer->CopyImage(mp2_image.image(), VK_IMAGE_LAYOUT_GENERAL, sp_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-dstImage-01557");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyImage-None-01549"); // since also non-compatiable
m_commandBuffer->CopyImage(sp_image.image(), VK_IMAGE_LAYOUT_GENERAL, mp3_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
©_region);
m_errorMonitor->VerifyFound();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, CreateSamplerYcbcrConversionEnable) {
TEST_DESCRIPTION("Checks samplerYcbcrConversion is enabled before calling vkCreateSamplerYcbcrConversion");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Explictly not enable Ycbcr Conversion Features
VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcr_features = LvlInitStruct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>();
ycbcr_features.samplerYcbcrConversion = VK_FALSE;
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &ycbcr_features));
PFN_vkCreateSamplerYcbcrConversionKHR vkCreateSamplerYcbcrConversionFunction =
(PFN_vkCreateSamplerYcbcrConversionKHR)vk::GetDeviceProcAddr(m_device->handle(), "vkCreateSamplerYcbcrConversionKHR");
// Create Ycbcr conversion
VkSamplerYcbcrConversion conversions;
VkSamplerYcbcrConversionCreateInfo ycbcr_create_info = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
NULL,
VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
VK_SAMPLER_YCBCR_RANGE_ITU_FULL,
{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
VK_CHROMA_LOCATION_COSITED_EVEN,
VK_CHROMA_LOCATION_COSITED_EVEN,
VK_FILTER_NEAREST,
false};
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCreateSamplerYcbcrConversion-None-01648");
vkCreateSamplerYcbcrConversionFunction(m_device->handle(), &ycbcr_create_info, nullptr, &conversions);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, ClearColorImageWithInvalidFormat) {
TEST_DESCRIPTION("Record clear color with an invalid image formats");
// Enable KHR multiplane req'd extensions
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkImageObj mp_image(m_device);
VkFormat mp_format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = mp_format;
image_create_info.extent.width = 32;
image_create_info.extent.height = 32;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
image_create_info.arrayLayers = 1;
bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), image_create_info, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
if (supported == false) {
GTEST_SKIP() << "Multiplane image format not supported";
}
mp_image.init(&image_create_info);
m_commandBuffer->begin();
VkClearColorValue color_clear_value = {};
VkImageSubresourceRange clear_range;
clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
clear_range.baseMipLevel = 0;
clear_range.baseArrayLayer = 0;
clear_range.layerCount = 1;
clear_range.levelCount = 1;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearColorImage-image-01545");
m_commandBuffer->ClearColorImage(mp_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, WriteDescriptorSetYcbcr) {
TEST_DESCRIPTION("Attempt to use VkSamplerYcbcrConversion ImageView to update descriptors that are not allowed.");
// Enable KHR multiplane req'd extensions
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
}
// Enable Sampler YCbCr Conversion
auto ycbcr_features = LvlInitStruct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>();
auto features2 = GetPhysicalDeviceFeatures2(ycbcr_features);
if (ycbcr_features.samplerYcbcrConversion == VK_FALSE) {
GTEST_SKIP() << "samplerYcbcrConversion feature not supported. Skipped.";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
if (!ImageFormatAndFeaturesSupported(gpu(), VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, VK_IMAGE_TILING_OPTIMAL,
VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT)) {
GTEST_SKIP() << "Required formats/features not supported";
}
// Create Ycbcr conversion
VkFormat mp_format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; // guaranteed sampling support
auto ycbcr_create_info = LvlInitStruct<VkSamplerYcbcrConversionCreateInfo>(
nullptr, mp_format, VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY, VK_SAMPLER_YCBCR_RANGE_ITU_FULL,
VkComponentMapping{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY},
VK_CHROMA_LOCATION_COSITED_EVEN, VK_CHROMA_LOCATION_COSITED_EVEN, VK_FILTER_NEAREST, VK_FALSE);
vk_testing::SamplerYcbcrConversion conversion(*m_device, ycbcr_create_info, true);
OneOffDescriptorSet descriptor_set(m_device, {
{0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_ALL, nullptr},
});
VkImageObj image_obj(m_device);
auto image_ci = LvlInitStruct<VkImageCreateInfo>(
nullptr, VkImageCreateFlags{VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT}, // need for multi-planar
VK_IMAGE_TYPE_2D, mp_format, VkExtent3D{64, 64u, 1u}, 1u, 1u, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_TILING_OPTIMAL,
VkImageUsageFlags{VK_IMAGE_USAGE_SAMPLED_BIT}, VK_SHARING_MODE_EXCLUSIVE, 0u, nullptr, VK_IMAGE_LAYOUT_UNDEFINED);
image_obj.init(&image_ci);
ASSERT_TRUE(image_obj.initialized());
auto ycbcr_info = LvlInitStruct<VkSamplerYcbcrConversionInfo>();
ycbcr_info.conversion = conversion.handle();
auto image_view_create_info = LvlInitStruct<VkImageViewCreateInfo>(&ycbcr_info);
image_view_create_info.image = image_obj.handle();
image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
image_view_create_info.format = mp_format;
image_view_create_info.subresourceRange.layerCount = 1;
image_view_create_info.subresourceRange.baseMipLevel = 0;
image_view_create_info.subresourceRange.levelCount = 1;
image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
vk_testing::ImageView image_view(*m_device, image_view_create_info);
descriptor_set.WriteDescriptorImageInfo(0, image_view.handle(), VK_NULL_HANDLE, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkWriteDescriptorSet-descriptorType-01946");
descriptor_set.UpdateDescriptorSets();
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, MultiplaneImageLayoutBadAspectFlags) {
TEST_DESCRIPTION("Query layout of a multiplane image using illegal aspect flag masks");
// Enable KHR multiplane req'd extensions
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
VkImageCreateInfo ci = LvlInitStruct<VkImageCreateInfo>();
ci.flags = 0;
ci.imageType = VK_IMAGE_TYPE_2D;
ci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
ci.extent = {128, 128, 1};
ci.mipLevels = 1;
ci.arrayLayers = 1;
ci.samples = VK_SAMPLE_COUNT_1_BIT;
ci.tiling = VK_IMAGE_TILING_LINEAR;
ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
// Verify formats
bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
ci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR;
supported = supported && ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
if (!supported) {
// Assume there's low ROI on searching for different mp formats
GTEST_SKIP() << "Multiplane image format not supported";
}
VkImage image_2plane, image_3plane;
ci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
VkResult err = vk::CreateImage(device(), &ci, NULL, &image_2plane);
ASSERT_VK_SUCCESS(err);
ci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR;
err = vk::CreateImage(device(), &ci, NULL, &image_3plane);
ASSERT_VK_SUCCESS(err);
// Query layout of 3rd plane, for a 2-plane image
VkImageSubresource subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
subres.mipLevel = 0;
subres.arrayLayer = 0;
VkSubresourceLayout layout = {};
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetImageSubresourceLayout-format-01581");
vk::GetImageSubresourceLayout(device(), image_2plane, &subres, &layout);
m_errorMonitor->VerifyFound();
// Query layout using color aspect, for a 3-plane image
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetImageSubresourceLayout-format-01582");
vk::GetImageSubresourceLayout(device(), image_3plane, &subres, &layout);
m_errorMonitor->VerifyFound();
// Clean up
vk::DestroyImage(device(), image_2plane, NULL);
vk::DestroyImage(device(), image_3plane, NULL);
}
TEST_F(VkLayerTest, BindInvalidMemoryYcbcr) {
// Enable KHR YCbCr req'd extensions for Disjoint Bit
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Create aliased function pointers for 1.0 and 1.1 contexts
PFN_vkBindImageMemory2KHR vkBindImageMemory2Function = nullptr;
PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2Function = nullptr;
if (DeviceValidationVersion() >= VK_API_VERSION_1_1) {
vkBindImageMemory2Function = vk::BindImageMemory2;
vkGetImageMemoryRequirements2Function = vk::GetImageMemoryRequirements2;
} else {
vkBindImageMemory2Function = (PFN_vkBindImageMemory2KHR)vk::GetDeviceProcAddr(m_device->handle(), "vkBindImageMemory2KHR");
vkGetImageMemoryRequirements2Function =
(PFN_vkGetImageMemoryRequirements2KHR)vk::GetDeviceProcAddr(m_device->handle(), "vkGetImageMemoryRequirements2KHR");
}
// Try to bind an image created with Disjoint bit
VkFormatProperties format_properties;
VkFormat mp_format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
vk::GetPhysicalDeviceFormatProperties(m_device->phy().handle(), mp_format, &format_properties);
// Need to make sure disjoint is supported for format
// Also need to support an arbitrary image usage feature
constexpr VkFormatFeatureFlags disjoint_sampled = VK_FORMAT_FEATURE_DISJOINT_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
if (disjoint_sampled != (format_properties.optimalTilingFeatures & disjoint_sampled)) {
printf("test requires disjoint and sampled feature bit on format. Skipping.\n");
} else {
VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = mp_format;
image_create_info.extent.width = 64;
image_create_info.extent.height = 64;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.arrayLayers = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
image_create_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT;
VkImage image;
ASSERT_VK_SUCCESS(vk::CreateImage(device(), &image_create_info, NULL, &image));
VkImagePlaneMemoryRequirementsInfo image_plane_req = LvlInitStruct<VkImagePlaneMemoryRequirementsInfo>();
image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT;
VkImageMemoryRequirementsInfo2 mem_req_info2 = LvlInitStruct<VkImageMemoryRequirementsInfo2>(&image_plane_req);
mem_req_info2.image = image;
VkMemoryRequirements2 mem_req2 = LvlInitStruct<VkMemoryRequirements2>();
vkGetImageMemoryRequirements2Function(device(), &mem_req_info2, &mem_req2);
// Find a valid memory type index to memory to be allocated from
VkMemoryAllocateInfo alloc_info = LvlInitStruct<VkMemoryAllocateInfo>();
alloc_info.allocationSize = mem_req2.memoryRequirements.size;
ASSERT_TRUE(m_device->phy().set_memory_type(mem_req2.memoryRequirements.memoryTypeBits, &alloc_info, 0));
VkDeviceMemory image_memory;
ASSERT_VK_SUCCESS(vk::AllocateMemory(device(), &alloc_info, NULL, &image_memory));
// Bind disjoint with BindImageMemory instead of BindImageMemory2
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBindImageMemory-image-01608");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-image-07736");
vk::BindImageMemory(device(), image, image_memory, 0);
m_errorMonitor->VerifyFound();
VkBindImagePlaneMemoryInfo plane_memory_info = LvlInitStruct<VkBindImagePlaneMemoryInfo>();
ASSERT_TRUE(FormatPlaneCount(mp_format) == 2);
plane_memory_info.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT;
VkBindImageMemoryInfo bind_image_info = LvlInitStruct<VkBindImageMemoryInfo>(&plane_memory_info);
bind_image_info.image = image;
bind_image_info.memory = image_memory;
bind_image_info.memoryOffset = 0;
// Set invalid planeAspect
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImagePlaneMemoryInfo-planeAspect-02283");
// Error is thrown from not having both planes bound
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBindImageMemory2-pBindInfos-02858");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBindImageMemory2-pBindInfos-02858");
// Might happen as plane2 wasn't queried for its memroy type
m_errorMonitor->SetUnexpectedError("VUID-VkBindImageMemoryInfo-pNext-01619");
m_errorMonitor->SetUnexpectedError("VUID-VkBindImageMemoryInfo-pNext-01621");
vkBindImageMemory2Function(device(), 1, &bind_image_info);
m_errorMonitor->VerifyFound();
vk::FreeMemory(device(), image_memory, NULL);
vk::DestroyImage(device(), image, nullptr);
}
// Bind image with VkBindImagePlaneMemoryInfo without disjoint bit in image
// Need to support an arbitrary image usage feature for multi-planar format
if (0 == (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
printf("test requires sampled feature bit on multi-planar format. Skipping.\n");
} else {
VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = mp_format;
image_create_info.extent.width = 64;
image_create_info.extent.height = 64;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.arrayLayers = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
image_create_info.flags = 0; // no disjoint bit set
VkImage image;
ASSERT_VK_SUCCESS(vk::CreateImage(device(), &image_create_info, NULL, &image));
VkImageMemoryRequirementsInfo2 mem_req_info2 = LvlInitStruct<VkImageMemoryRequirementsInfo2>();
mem_req_info2.image = image;
VkMemoryRequirements2 mem_req2 = LvlInitStruct<VkMemoryRequirements2>();
vkGetImageMemoryRequirements2Function(device(), &mem_req_info2, &mem_req2);
// Find a valid memory type index to memory to be allocated from
VkMemoryAllocateInfo alloc_info = LvlInitStruct<VkMemoryAllocateInfo>();
alloc_info.allocationSize = mem_req2.memoryRequirements.size;
ASSERT_TRUE(m_device->phy().set_memory_type(mem_req2.memoryRequirements.memoryTypeBits, &alloc_info, 0));
VkDeviceMemory image_memory;
ASSERT_VK_SUCCESS(vk::AllocateMemory(device(), &alloc_info, NULL, &image_memory));
VkBindImagePlaneMemoryInfo plane_memory_info = LvlInitStruct<VkBindImagePlaneMemoryInfo>();
plane_memory_info.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT;
VkBindImageMemoryInfo bind_image_info = LvlInitStruct<VkBindImageMemoryInfo>(&plane_memory_info);
bind_image_info.image = image;
bind_image_info.memory = image_memory;
bind_image_info.memoryOffset = 0;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-pNext-01618");
vkBindImageMemory2Function(device(), 1, &bind_image_info);
m_errorMonitor->VerifyFound();
vk::FreeMemory(device(), image_memory, NULL);
vk::DestroyImage(device(), image, nullptr);
}
}
TEST_F(VkLayerTest, BindInvalidMemory2Disjoint) {