forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vklayertests_sampler.cpp
1329 lines (1128 loc) · 67.2 KB
/
vklayertests_sampler.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, MirrorClampToEdgeNotEnabled) {
TEST_DESCRIPTION("Validation should catch using CLAMP_TO_EDGE addressing mode if the extension is not enabled.");
SetTargetApiVersion(VK_API_VERSION_1_0);
ASSERT_NO_FATAL_FAILURE(Init());
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-addressModeU-01079");
VkSampler sampler = VK_NULL_HANDLE;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
// Set the modes to cause the error
sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, MirrorClampToEdgeNotEnabled12) {
TEST_DESCRIPTION("Validation using CLAMP_TO_EDGE for Vulkan 1.2 without the samplerMirrorClampToEdge feature enabled.");
SetTargetApiVersion(VK_API_VERSION_1_2);
ASSERT_NO_FATAL_FAILURE(Init());
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-addressModeU-01079");
VkSampler sampler = VK_NULL_HANDLE;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, AnisotropyFeatureDisabled) {
TEST_DESCRIPTION("Validation should check anisotropy parameters are correct with samplerAnisotropy disabled.");
// Determine if required device features are available
VkPhysicalDeviceFeatures device_features = {};
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
device_features.samplerAnisotropy = VK_FALSE; // force anisotropy off
ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-anisotropyEnable-01070");
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
// With the samplerAnisotropy disable, the sampler must not enable it.
sampler_info.anisotropyEnable = VK_TRUE;
VkSampler sampler = VK_NULL_HANDLE;
VkResult err;
err = vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
if (VK_SUCCESS == err) {
vk::DestroySampler(m_device->device(), sampler, NULL);
}
sampler = VK_NULL_HANDLE;
}
TEST_F(VkLayerTest, AnisotropyFeatureEnabled) {
TEST_DESCRIPTION("Validation must check several conditions that apply only when Anisotropy is enabled.");
AddOptionalExtensions(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
VkPhysicalDeviceFeatures device_features = {};
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
const bool cubic_support = IsExtensionsEnabled(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
// These tests require that the device support anisotropic filtering
if (VK_TRUE != device_features.samplerAnisotropy) {
GTEST_SKIP() << "Test requires unsupported samplerAnisotropy feature";
}
VkSamplerCreateInfo sampler_info_ref = SafeSaneSamplerCreateInfo();
sampler_info_ref.anisotropyEnable = VK_TRUE;
VkSamplerCreateInfo sampler_info = sampler_info_ref;
ASSERT_NO_FATAL_FAILURE(InitState());
// maxAnisotropy out-of-bounds low.
sampler_info.maxAnisotropy = NearestSmaller(1.0F);
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-anisotropyEnable-01071");
sampler_info.maxAnisotropy = sampler_info_ref.maxAnisotropy;
// maxAnisotropy out-of-bounds high.
sampler_info.maxAnisotropy = NearestGreater(m_device->phy().properties().limits.maxSamplerAnisotropy);
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-anisotropyEnable-01071");
sampler_info.maxAnisotropy = sampler_info_ref.maxAnisotropy;
// Both anisotropy and unnormalized coords enabled
sampler_info.unnormalizedCoordinates = VK_TRUE;
// If unnormalizedCoordinates is VK_TRUE, minLod and maxLod must be zero
sampler_info.minLod = 0;
sampler_info.maxLod = 0;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076");
sampler_info.unnormalizedCoordinates = sampler_info_ref.unnormalizedCoordinates;
// Both anisotropy and cubic filtering enabled
if (cubic_support) {
sampler_info.minFilter = VK_FILTER_CUBIC_IMG;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-magFilter-01081");
sampler_info.minFilter = sampler_info_ref.minFilter;
sampler_info.magFilter = VK_FILTER_CUBIC_IMG;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-magFilter-01081");
sampler_info.magFilter = sampler_info_ref.magFilter;
} else {
printf("Test requires unsupported extension \"VK_IMG_filter_cubic\". Skipped.\n");
}
}
TEST_F(VkLayerTest, UnnormalizedCoordinatesEnabled) {
TEST_DESCRIPTION("Validate restrictions on sampler parameters when unnormalizedCoordinates is true.");
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
VkSamplerCreateInfo sampler_info_ref = SafeSaneSamplerCreateInfo();
sampler_info_ref.unnormalizedCoordinates = VK_TRUE;
sampler_info_ref.minLod = 0.0f;
sampler_info_ref.maxLod = 0.0f;
VkSamplerCreateInfo sampler_info = sampler_info_ref;
ASSERT_NO_FATAL_FAILURE(InitState());
// min and mag filters must be the same
sampler_info.minFilter = VK_FILTER_NEAREST;
sampler_info.magFilter = VK_FILTER_LINEAR;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072");
std::swap(sampler_info.minFilter, sampler_info.magFilter);
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072");
sampler_info = sampler_info_ref;
// mipmapMode must be NEAREST
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01073");
sampler_info = sampler_info_ref;
// minlod and maxlod must be zero
sampler_info.maxLod = 3.14159f;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074");
sampler_info.minLod = 2.71828f;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074");
sampler_info = sampler_info_ref;
// addressModeU and addressModeV must both be CLAMP_TO_EDGE or CLAMP_TO_BORDER
// checks all 12 invalid combinations out of 16 total combinations
const std::array<VkSamplerAddressMode, 4> kAddressModes = {{
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
}};
for (const auto umode : kAddressModes) {
for (const auto vmode : kAddressModes) {
if ((umode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && umode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
(vmode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && vmode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
sampler_info.addressModeU = umode;
sampler_info.addressModeV = vmode;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075");
}
}
}
sampler_info = sampler_info_ref;
// VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076 is tested in AnisotropyFeatureEnabled above
// Since it requires checking/enabling the anisotropic filtering feature, it's easier to do it
// with the other anisotropic tests.
// compareEnable must be VK_FALSE
sampler_info.compareEnable = VK_TRUE;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01077");
sampler_info = sampler_info_ref;
}
TEST_F(VkLayerTest, InvalidSamplerCreateInfo) {
TEST_DESCRIPTION("Checks various cases where VkSamplerCreateInfo is invalid");
ASSERT_NO_FATAL_FAILURE(Init());
// reference to reset values between test cases
VkSamplerCreateInfo const sampler_info_ref = SafeSaneSamplerCreateInfo();
VkSamplerCreateInfo sampler_info = sampler_info_ref;
// Mix up Lod values
sampler_info.minLod = 4.0f;
sampler_info.maxLod = 1.0f;
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-maxLod-01973");
sampler_info.minLod = sampler_info_ref.minLod;
sampler_info.maxLod = sampler_info_ref.maxLod;
// Larger mipLodBias than max limit
sampler_info.mipLodBias = NearestGreater(m_device->phy().properties().limits.maxSamplerLodBias);
CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-mipLodBias-01069");
sampler_info.mipLodBias = sampler_info_ref.mipLodBias;
}
TEST_F(VkLayerTest, ExceedSamplerAllocationCount) {
VkResult err = VK_SUCCESS;
const int max_samplers = 32;
VkSampler samplers[max_samplers + 1];
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
PFN_vkSetPhysicalDeviceLimitsEXT fpvkSetPhysicalDeviceLimitsEXT = nullptr;
PFN_vkGetOriginalPhysicalDeviceLimitsEXT fpvkGetOriginalPhysicalDeviceLimitsEXT = nullptr;
if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceLimitsEXT, fpvkGetOriginalPhysicalDeviceLimitsEXT)) {
GTEST_SKIP() << "Failed to load device profile layer.";
}
VkPhysicalDeviceProperties props;
fpvkGetOriginalPhysicalDeviceLimitsEXT(gpu(), &props.limits);
if (props.limits.maxSamplerAllocationCount > max_samplers) {
props.limits.maxSamplerAllocationCount = max_samplers;
fpvkSetPhysicalDeviceLimitsEXT(gpu(), &props.limits);
}
ASSERT_NO_FATAL_FAILURE(InitState());
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCreateSampler-maxSamplerAllocationCount-04110");
VkSamplerCreateInfo sampler_create_info = SafeSaneSamplerCreateInfo();
int i;
for (i = 0; i <= max_samplers; i++) {
err = vk::CreateSampler(m_device->device(), &sampler_create_info, NULL, &samplers[i]);
if (err != VK_SUCCESS) {
break;
}
}
m_errorMonitor->VerifyFound();
for (int j = 0; j < i; j++) {
vk::DestroySampler(m_device->device(), samplers[j], NULL);
}
}
TEST_F(VkLayerTest, SamplerImageViewFormatUnsupportedFilter) {
TEST_DESCRIPTION(
"Create sampler with a filter and use with image view using a format that does not support the sampler filter.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddOptionalExtensions(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
const bool cubic_support = IsExtensionsEnabled(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
enum FormatTypes { FLOAT, SINT, UINT };
struct TestFilterType {
VkFilter filter = VK_FILTER_LINEAR;
VkFormatFeatureFlagBits required_format_feature = VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
VkImageTiling tiling = VK_IMAGE_TILING_LINEAR;
VkFormat format = VK_FORMAT_UNDEFINED;
FormatTypes format_type;
std::string err_msg;
};
std::vector<std::pair<VkFormat, FormatTypes>> formats_to_check({{VK_FORMAT_R8_UNORM, FLOAT},
{VK_FORMAT_R8_SNORM, FLOAT},
{VK_FORMAT_R8_SRGB, FLOAT},
{VK_FORMAT_R8G8_UNORM, FLOAT},
{VK_FORMAT_R8G8_SNORM, FLOAT},
{VK_FORMAT_R8G8_SRGB, FLOAT},
{VK_FORMAT_R8G8B8_UNORM, FLOAT},
{VK_FORMAT_R8G8B8_SNORM, FLOAT},
{VK_FORMAT_R8G8B8_SRGB, FLOAT},
{VK_FORMAT_R8G8B8A8_UNORM, FLOAT},
{VK_FORMAT_R8G8B8A8_SNORM, FLOAT},
{VK_FORMAT_R8G8B8A8_SRGB, FLOAT},
{VK_FORMAT_B8G8R8A8_UNORM, FLOAT},
{VK_FORMAT_B8G8R8A8_SNORM, FLOAT},
{VK_FORMAT_B8G8R8A8_SRGB, FLOAT},
{VK_FORMAT_R16_UNORM, FLOAT},
{VK_FORMAT_R16_SNORM, FLOAT},
{VK_FORMAT_R16_SFLOAT, FLOAT},
{VK_FORMAT_R16G16_UNORM, FLOAT},
{VK_FORMAT_R16G16_SNORM, FLOAT},
{VK_FORMAT_R16G16_SFLOAT, FLOAT},
{VK_FORMAT_R16G16B16_UNORM, FLOAT},
{VK_FORMAT_R16G16B16_SNORM, FLOAT},
{VK_FORMAT_R16G16B16_SFLOAT, FLOAT},
{VK_FORMAT_R16G16B16A16_UNORM, FLOAT},
{VK_FORMAT_R16G16B16A16_SNORM, FLOAT},
{VK_FORMAT_R16G16B16A16_SFLOAT, FLOAT},
{VK_FORMAT_R32_SFLOAT, FLOAT},
{VK_FORMAT_R32G32_SFLOAT, FLOAT},
{VK_FORMAT_R32G32B32_SFLOAT, FLOAT},
{VK_FORMAT_R32G32B32A32_SFLOAT, FLOAT},
{VK_FORMAT_R64_SFLOAT, FLOAT},
{VK_FORMAT_R64G64_SFLOAT, FLOAT},
{VK_FORMAT_R64G64B64_SFLOAT, FLOAT},
{VK_FORMAT_R64G64B64A64_SFLOAT, FLOAT},
{VK_FORMAT_R8_SINT, SINT},
{VK_FORMAT_R8G8_SINT, SINT},
{VK_FORMAT_R8G8B8_SINT, SINT},
{VK_FORMAT_R8G8B8A8_SINT, SINT},
{VK_FORMAT_B8G8R8A8_SINT, SINT},
{VK_FORMAT_R16_SINT, SINT},
{VK_FORMAT_R16G16_SINT, SINT},
{VK_FORMAT_R16G16B16_SINT, SINT},
{VK_FORMAT_R16G16B16A16_SINT, SINT},
{VK_FORMAT_R32_SINT, SINT},
{VK_FORMAT_R32G32_SINT, SINT},
{VK_FORMAT_R32G32B32_SINT, SINT},
{VK_FORMAT_R32G32B32A32_SINT, SINT},
{VK_FORMAT_R64_SINT, SINT},
{VK_FORMAT_R64G64_SINT, SINT},
{VK_FORMAT_R64G64B64_SINT, SINT},
{VK_FORMAT_R64G64B64A64_SINT, SINT},
{VK_FORMAT_R8_UINT, UINT},
{VK_FORMAT_R8G8_UINT, UINT},
{VK_FORMAT_R8G8B8_UINT, UINT},
{VK_FORMAT_R8G8B8A8_UINT, UINT},
{VK_FORMAT_B8G8R8A8_UINT, UINT},
{VK_FORMAT_R16_UINT, UINT},
{VK_FORMAT_R16G16_UINT, UINT},
{VK_FORMAT_R16G16B16_UINT, UINT},
{VK_FORMAT_R16G16B16A16_UINT, UINT},
{VK_FORMAT_R32_UINT, UINT},
{VK_FORMAT_R32G32_UINT, UINT},
{VK_FORMAT_R32G32B32_UINT, UINT},
{VK_FORMAT_R32G32B32A32_UINT, UINT},
{VK_FORMAT_R64_UINT, UINT},
{VK_FORMAT_R64G64_UINT, UINT},
{VK_FORMAT_R64G64B64_UINT, UINT},
{VK_FORMAT_R64G64B64A64_UINT, UINT}});
std::vector<struct TestFilterType> tests(2);
tests[0].err_msg = "VUID-vkCmdDraw-magFilter-04553";
tests[1].filter = VK_FILTER_CUBIC_IMG;
tests[1].required_format_feature = VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG;
tests[1].err_msg = "VUID-vkCmdDraw-None-02692";
for (auto &test_struct : tests) {
for (std::pair<VkFormat, FormatTypes> cur_format_pair : formats_to_check) {
VkFormatProperties props = {};
vk::GetPhysicalDeviceFormatProperties(gpu(), cur_format_pair.first, &props);
if (test_struct.format == VK_FORMAT_UNDEFINED && props.linearTilingFeatures != 0 &&
(props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) &&
!(props.linearTilingFeatures & test_struct.required_format_feature)) {
test_struct.format = cur_format_pair.first;
test_struct.format_type = cur_format_pair.second;
} else if (test_struct.format == VK_FORMAT_UNDEFINED && props.optimalTilingFeatures != 0 &&
(props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) &&
!(props.optimalTilingFeatures & test_struct.required_format_feature)) {
test_struct.format = cur_format_pair.first;
test_struct.format_type = cur_format_pair.second;
test_struct.tiling = VK_IMAGE_TILING_OPTIMAL;
}
if (test_struct.format != VK_FORMAT_UNDEFINED) {
break;
}
}
}
const char bindStateFragiSamplerShaderText[] = R"glsl(
#version 450
layout(set=0, binding=0) uniform isampler2D s;
layout(location=0) out vec4 x;
void main(){
x = texture(s, vec2(1));
}
)glsl";
const char bindStateFraguSamplerShaderText[] = R"glsl(
#version 450
layout(set=0, binding=0) uniform usampler2D s;
layout(location=0) out vec4 x;
void main(){
x = texture(s, vec2(1));
}
)glsl";
ASSERT_NO_FATAL_FAILURE(InitViewport());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
for (const auto &test_struct : tests) {
if (test_struct.format == VK_FORMAT_UNDEFINED) {
printf("Could not find a testable format for filter %d. Skipping test for said filter.\n", test_struct.filter);
continue;
}
VkSamplerCreateInfo sci = SafeSaneSamplerCreateInfo();
sci.magFilter = test_struct.filter;
sci.minFilter = test_struct.filter;
sci.compareEnable = VK_FALSE;
if (test_struct.filter == VK_FILTER_CUBIC_IMG) {
if (cubic_support) {
sci.anisotropyEnable = VK_FALSE;
} else {
printf("VK_FILTER_CUBIC_IMG not supported. Skipping use of VK_FILTER_CUBIC_IMG this test.\n");
continue;
}
}
VkSampler sampler;
VkResult err = vk::CreateSampler(m_device->device(), &sci, nullptr, &sampler);
ASSERT_VK_SUCCESS(err);
VkImageObj mpimage(m_device);
mpimage.Init(128, 128, 1, test_struct.format, VK_IMAGE_USAGE_SAMPLED_BIT, test_struct.tiling);
ASSERT_TRUE(mpimage.initialized());
VkImageView view = mpimage.targetView(test_struct.format);
CreatePipelineHelper pipe(*this);
VkShaderObj *fs = nullptr;
pipe.InitInfo();
if (test_struct.format_type == FLOAT) {
fs = new VkShaderObj(this, bindStateFragSamplerShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
} else if (test_struct.format_type == SINT) {
fs = new VkShaderObj(this, bindStateFragiSamplerShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
} else if (test_struct.format_type == UINT) {
fs = new VkShaderObj(this, bindStateFraguSamplerShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
}
pipe.shader_stages_ = {pipe.vs_->GetStageCreateInfo(), fs->GetStageCreateInfo()};
pipe.dsl_bindings_ = {
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
};
pipe.InitState();
VkDynamicState dyn_state = VK_DYNAMIC_STATE_SCISSOR;
pipe.dyn_state_ci_ = LvlInitStruct<VkPipelineDynamicStateCreateInfo>();
pipe.dyn_state_ci_.dynamicStateCount = 1;
pipe.dyn_state_ci_.pDynamicStates = &dyn_state;
ASSERT_VK_SUCCESS(pipe.CreateGraphicsPipeline());
pipe.descriptor_set_->WriteDescriptorImageInfo(0, view, sampler, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
pipe.descriptor_set_->UpdateDescriptorSets();
m_commandBuffer->begin();
m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
VkViewport viewport = {0, 0, 16, 16, 0, 1};
vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
VkRect2D scissor = {{0, 0}, {16, 16}};
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
vk::CmdBindDescriptorSets(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_layout_.handle(), 0, 1,
&pipe.descriptor_set_->set_, 0, nullptr);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, test_struct.err_msg.c_str());
m_commandBuffer->Draw(1, 0, 0, 0);
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRenderPass();
m_commandBuffer->end();
delete fs;
vk::DestroySampler(m_device->device(), sampler, nullptr);
}
}
TEST_F(VkLayerTest, IllegalAddressModeWithCornerSampledNV) {
TEST_DESCRIPTION(
"Create image with VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV flag and sample it with something other than "
"VK_SAMPLER_ADDRESS_MODE_CLAMP_EDGE.");
AddRequiredExtensions(VK_NV_CORNER_SAMPLED_IMAGE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, 0));
ASSERT_NO_FATAL_FAILURE(InitViewport());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkImageObj test_image(m_device);
VkImageCreateInfo image_info = VkImageObj::create_info();
image_info.flags = VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV;
image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
// If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV,
// imageType must be VK_IMAGE_TYPE_2D or VK_IMAGE_TYPE_3D
image_info.imageType = VK_IMAGE_TYPE_2D;
// If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and imageType is VK_IMAGE_TYPE_2D,
// extent.width and extent.height must be greater than 1.
image_info.extent = {2, 2, 1};
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
test_image.init(&image_info);
ASSERT_TRUE(test_image.initialized());
VkSamplerCreateInfo sci = SafeSaneSamplerCreateInfo();
sci.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
vk_testing::Sampler sampler(*m_device, sci);
VkImageView view = test_image.targetView(image_info.format);
CreatePipelineHelper pipe(*this);
VkShaderObj fs(this, bindStateFragSamplerShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
pipe.InitInfo();
pipe.shader_stages_ = {pipe.vs_->GetStageCreateInfo(), fs.GetStageCreateInfo()};
pipe.dsl_bindings_ = {
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
};
pipe.InitState();
pipe.CreateGraphicsPipeline();
pipe.descriptor_set_->WriteDescriptorImageInfo(0, view, sampler.handle(), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
pipe.descriptor_set_->UpdateDescriptorSets();
m_commandBuffer->begin();
m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
VkViewport viewport = {0, 0, 16, 16, 0, 1};
vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
VkRect2D scissor = {{0, 0}, {16, 16}};
vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
vk::CmdBindDescriptorSets(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_layout_.handle(), 0, 1,
&pipe.descriptor_set_->set_, 0, nullptr);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-flags-02696");
m_commandBuffer->Draw(1, 0, 0, 0);
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRenderPass();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, MultiplaneImageSamplerConversionMismatch) {
TEST_DESCRIPTION(
"Create sampler with ycbcr conversion and use with an image created without ycrcb conversion or immutable sampler");
// 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";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
ASSERT_NO_FATAL_FAILURE(InitViewport());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
const VkImageCreateInfo ci = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
NULL,
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, // need for multi-planar
VK_IMAGE_TYPE_2D,
VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
{128, 128, 1},
1,
1,
VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_TILING_LINEAR,
VK_IMAGE_USAGE_SAMPLED_BIT,
VK_SHARING_MODE_EXCLUSIVE,
VK_IMAGE_LAYOUT_UNDEFINED};
// Verify formats
bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
if (!supported) {
GTEST_SKIP() << "Multiplane image format not supported";
}
if (!ImageFormatAndFeaturesSupported(gpu(), VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR, VK_IMAGE_TILING_OPTIMAL,
VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT)) {
GTEST_SKIP() << "Required formats/features not supported";
}
// Create Ycbcr conversion
VkSamplerYcbcrConversionCreateInfo ycbcr_create_info = LvlInitStruct<VkSamplerYcbcrConversionCreateInfo>();
ycbcr_create_info.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
ycbcr_create_info.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
ycbcr_create_info.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
ycbcr_create_info.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY};
ycbcr_create_info.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
ycbcr_create_info.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
ycbcr_create_info.chromaFilter = VK_FILTER_NEAREST;
ycbcr_create_info.forceExplicitReconstruction = false;
vk_testing::SamplerYcbcrConversion conversions[2];
conversions[0].init(*m_device, ycbcr_create_info, false);
ycbcr_create_info.components.a = VK_COMPONENT_SWIZZLE_ZERO; // Just anything different than above
conversions[1].init(*m_device, ycbcr_create_info, false);
VkSamplerYcbcrConversionInfo ycbcr_info = LvlInitStruct<VkSamplerYcbcrConversionInfo>();
ycbcr_info.conversion = conversions[0].handle();
// Create a sampler using conversion
VkSamplerCreateInfo sci = SafeSaneSamplerCreateInfo();
sci.pNext = &ycbcr_info;
// Create two samplers with two different conversions, such that one will mismatch
// It will make the second sampler fail to see if the log prints the second sampler or the first sampler.
vk_testing::Sampler samplers[2];
samplers[0].init(*m_device, sci);
ycbcr_info.conversion = conversions[1].handle(); // Need two samplers with different conversions
samplers[1].init(*m_device, sci);
vk_testing::Sampler BadSampler;
sci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-addressModeU-01646");
BadSampler.init(*m_device, sci);
m_errorMonitor->VerifyFound();
sci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
sci.unnormalizedCoordinates = VK_TRUE;
sci.minLod = 0.0;
sci.maxLod = 0.0;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-addressModeU-01646");
BadSampler.init(*m_device, sci);
m_errorMonitor->VerifyFound();
if (features2.features.samplerAnisotropy == VK_TRUE) {
sci.unnormalizedCoordinates = VK_FALSE;
sci.anisotropyEnable = VK_TRUE;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-addressModeU-01646");
BadSampler.init(*m_device, sci);
m_errorMonitor->VerifyFound();
}
// Create an image without a Ycbcr conversion
VkImageObj mpimage(m_device);
mpimage.init(&ci);
ycbcr_info.conversion = conversions[0].handle(); // Need two samplers with different conversions
VkImageViewCreateInfo ivci = LvlInitStruct<VkImageViewCreateInfo>(&ycbcr_info);
ivci.image = mpimage.handle();
ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
ivci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
ivci.subresourceRange.layerCount = 1;
ivci.subresourceRange.baseMipLevel = 0;
ivci.subresourceRange.levelCount = 1;
ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT;
vk_testing::ImageView view(*m_device, ivci);
VkSampler vksamplers[2] = {samplers[0].handle(), samplers[1].handle()};
// Use the image and sampler together in a descriptor set
OneOffDescriptorSet descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_ALL, vksamplers},
});
if (!descriptor_set.set_) {
GTEST_SKIP() << "Failed to allocate descriptor set, skipping test.";
}
// Use the same image view twice, using the same sampler, with the *second* mismatched with the *second* immutable sampler
VkDescriptorImageInfo image_infos[2];
image_infos[0] = {};
image_infos[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
image_infos[0].imageView = view.handle();
image_infos[0].sampler = samplers[0].handle();
image_infos[1] = image_infos[0];
// Update the descriptor set expecting to get an error
VkWriteDescriptorSet descriptor_write = LvlInitStruct<VkWriteDescriptorSet>();
descriptor_write.dstSet = descriptor_set.set_;
descriptor_write.dstBinding = 0;
descriptor_write.descriptorCount = 2;
descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptor_write.pImageInfo = image_infos;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkWriteDescriptorSet-descriptorType-01948");
vk::UpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
m_errorMonitor->VerifyFound();
// pImmutableSamplers = nullptr causes an error , VUID-VkWriteDescriptorSet-descriptorType-02738.
// Because if pNext chains a VkSamplerYcbcrConversionInfo, the sampler has to be a immutable sampler.
OneOffDescriptorSet descriptor_set_1947(m_device,
{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
});
descriptor_write.dstSet = descriptor_set_1947.set_;
descriptor_write.descriptorCount = 1;
descriptor_write.pImageInfo = &image_infos[0];
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkWriteDescriptorSet-descriptorType-02738");
vk::UpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, InvalidSamplerFilterMinmax) {
TEST_DESCRIPTION("Invalid uses of VK_EXT_sampler_filter_minmax.");
// Enable KHR multiplane req'd extensions
AddRequiredExtensions(VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Enable Ycbcr Conversion Features
VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcr_features = LvlInitStruct<VkPhysicalDeviceSamplerYcbcrConversionFeatures>();
ycbcr_features.samplerYcbcrConversion = VK_TRUE;
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &ycbcr_features));
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";
}
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";
}
VkSampler sampler;
// Create Ycbcr conversion
VkSamplerYcbcrConversionCreateInfo ycbcr_create_info = LvlInitStruct<VkSamplerYcbcrConversionCreateInfo>();
ycbcr_create_info.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
ycbcr_create_info.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
ycbcr_create_info.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
ycbcr_create_info.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY};
ycbcr_create_info.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
ycbcr_create_info.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
ycbcr_create_info.chromaFilter = VK_FILTER_NEAREST;
ycbcr_create_info.forceExplicitReconstruction = false;
VkSamplerYcbcrConversion conversion;
vkCreateSamplerYcbcrConversionFunction(m_device->handle(), &ycbcr_create_info, nullptr, &conversion);
VkSamplerYcbcrConversionInfo ycbcr_info = LvlInitStruct<VkSamplerYcbcrConversionInfo>();
ycbcr_info.conversion = conversion;
VkSamplerReductionModeCreateInfo reduction_info = LvlInitStruct<VkSamplerReductionModeCreateInfo>();
reduction_info.reductionMode = VK_SAMPLER_REDUCTION_MODE_MIN;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
sampler_info.pNext = &reduction_info;
// Wrong mode with a YCbCr Conversion used
reduction_info.pNext = &ycbcr_info;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-None-01647");
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
// Wrong mode with compareEnable
reduction_info.pNext = nullptr;
sampler_info.compareEnable = VK_TRUE;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-compareEnable-01423");
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
vkDestroySamplerYcbcrConversionFunction(m_device->handle(), conversion, nullptr);
}
TEST_F(VkLayerTest, CustomBorderColor) {
TEST_DESCRIPTION("Tests for VUs for VK_EXT_custom_border_color");
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto border_color_features = LvlInitStruct<VkPhysicalDeviceCustomBorderColorFeaturesEXT>();
GetPhysicalDeviceFeatures2(border_color_features);
if (border_color_features.customBorderColors != VK_TRUE) {
GTEST_SKIP() << "customBorderColors feature not supported";
}
// Disable without format
border_color_features.customBorderColorWithoutFormat = 0;
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &border_color_features));
VkSampler sampler;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
sampler_info.borderColor = VK_BORDER_COLOR_INT_CUSTOM_EXT;
// No SCBCCreateInfo in pNext
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-borderColor-04011");
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
VkSamplerCustomBorderColorCreateInfoEXT custom_color_cinfo = LvlInitStruct<VkSamplerCustomBorderColorCreateInfoEXT>();
custom_color_cinfo.format = VK_FORMAT_R32_SFLOAT;
sampler_info.pNext = &custom_color_cinfo;
// Format mismatch
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-07605");
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
custom_color_cinfo.format = VK_FORMAT_UNDEFINED;
// Format undefined with no customBorderColorWithoutFormat
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-04014");
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
m_errorMonitor->VerifyFound();
custom_color_cinfo.format = VK_FORMAT_R8G8B8A8_UINT;
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
VkDescriptorSetLayoutBinding dsl_binding = {0, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, &sampler};
VkDescriptorSetLayoutCreateInfo ds_layout_ci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL, 0, 1, &dsl_binding};
VkDescriptorSetLayout ds_layout;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDescriptorSetLayoutBinding-pImmutableSamplers-04009");
vk::CreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
m_errorMonitor->VerifyFound();
PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR =
(PFN_vkGetPhysicalDeviceProperties2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceProperties2KHR");
assert(vkGetPhysicalDeviceProperties2KHR != nullptr);
VkPhysicalDeviceCustomBorderColorPropertiesEXT custom_properties =
LvlInitStruct<VkPhysicalDeviceCustomBorderColorPropertiesEXT>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2KHR>(&custom_properties);
vkGetPhysicalDeviceProperties2KHR(gpu(), &prop2);
if ((custom_properties.maxCustomBorderColorSamplers <= 0xFFFF) &&
(prop2.properties.limits.maxSamplerAllocationCount >= custom_properties.maxCustomBorderColorSamplers)) {
VkSampler samplers[0xFFFF];
// Still have one custom border color sampler from above, so this should exceed max
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCreateInfo-None-04012");
if (prop2.properties.limits.maxSamplerAllocationCount <= custom_properties.maxCustomBorderColorSamplers) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCreateSampler-maxSamplerAllocationCount-04110");
}
for (uint32_t i = 0; i < custom_properties.maxCustomBorderColorSamplers; i++) {
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &samplers[i]);
}
m_errorMonitor->VerifyFound();
for (uint32_t i = 0; i < custom_properties.maxCustomBorderColorSamplers - 1; i++) {
vk::DestroySampler(m_device->device(), samplers[i], nullptr);
}
}
vk::DestroySampler(m_device->device(), sampler, nullptr);
}
TEST_F(VkLayerTest, CustomBorderColorFormatUndefined) {
TEST_DESCRIPTION("Tests for VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-04015");
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto border_color_features = LvlInitStruct<VkPhysicalDeviceCustomBorderColorFeaturesEXT>();
GetPhysicalDeviceFeatures2(border_color_features);
if (!border_color_features.customBorderColors || !border_color_features.customBorderColorWithoutFormat) {
GTEST_SKIP() << "Custom border color feature not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &border_color_features, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
ASSERT_NO_FATAL_FAILURE(InitViewport());
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkSampler sampler;
VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
sampler_info.borderColor = VK_BORDER_COLOR_INT_CUSTOM_EXT;
VkSamplerCustomBorderColorCreateInfoEXT custom_color_cinfo = LvlInitStruct<VkSamplerCustomBorderColorCreateInfoEXT>();
custom_color_cinfo.format = VK_FORMAT_UNDEFINED;
sampler_info.pNext = &custom_color_cinfo;
vk::CreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
VkImageObj image(m_device);
image.Init(32, 32, 1, VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
image.Layout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
OneOffDescriptorSet descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
});
const VkPipelineLayoutObj pipeline_layout(m_device, {&descriptor_set.layout_});
vk_testing::ImageView view;
auto image_view_create_info = SafeSaneImageViewCreateInfo(image, VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_IMAGE_ASPECT_COLOR_BIT);
view.init(*m_device, image_view_create_info);
VkDescriptorImageInfo img_info = {};
img_info.sampler = sampler;
img_info.imageView = view.handle();
img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkWriteDescriptorSet descriptor_writes[2] = {};
descriptor_writes[0] = LvlInitStruct<VkWriteDescriptorSet>();
descriptor_writes[0].dstSet = descriptor_set.set_;
descriptor_writes[0].dstBinding = 0;
descriptor_writes[0].descriptorCount = 1;
descriptor_writes[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptor_writes[0].pImageInfo = &img_info;
vk::UpdateDescriptorSets(m_device->device(), 1, descriptor_writes, 0, NULL);
char const *fsSource = R"glsl(
#version 450
layout(set=0, binding=0) uniform sampler2D s;
layout(location=0) out vec4 x;
void main(){
x = texture(s, vec2(1));
}
)glsl";
VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout.handle(), renderPass());
m_commandBuffer->begin();
m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
vk::CmdBindDescriptorSets(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout.handle(), 0, 1,
&descriptor_set.set_, 0, NULL);
VkViewport viewport = m_viewports[0];
VkRect2D scissor = m_scissors[0];
vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-04015");
m_commandBuffer->Draw(3, 1, 0, 0);
m_errorMonitor->VerifyFound();
vk::CmdEndRenderPass(m_commandBuffer->handle());
m_commandBuffer->end();
vk::DestroySampler(m_device->device(), sampler, nullptr);
}
TEST_F(VkLayerTest, UnnormalizedCoordinatesCombinedSampler) {
TEST_DESCRIPTION(
"If a samper is unnormalizedCoordinates, the imageview has to be some specific types. Uses COMBINED_IMAGE_SAMPLER");
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
// This generates OpImage*Dref* instruction on R8G8B8A8_UNORM format.
// Verify that it is allowed on this implementation if
// VK_KHR_format_feature_flags2 is available.
if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME)) {
auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
auto fmt_props = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
vk::GetPhysicalDeviceFormatProperties2(gpu(), VK_FORMAT_R8G8B8A8_UNORM, &fmt_props);
if (!(fmt_props_3.optimalTilingFeatures & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR)) {
GTEST_SKIP() << "R8G8B8A8_UNORM does not support OpImage*Dref* operations";
}
}
VkShaderObj vs(this, bindStateMinimalShaderText, VK_SHADER_STAGE_VERTEX_BIT);
const char fsSource[] = R"glsl(
#version 450
layout (set = 0, binding = 0) uniform sampler3D image_view_3d;
layout (set = 0, binding = 1) uniform sampler2D tex[2];
layout (set = 0, binding = 2) uniform sampler2DShadow tex_dep[2];
void main() {
// VUID 02702
// 3D Image View is used with unnormalized coordinates
// Also is VUID 02703 but the invalid image view is reported first
vec4 x = texture(image_view_3d, vec3(0));
// VUID 02703
// OpImageSampleDrefImplicitLod is used with unnormalized coordinates
float f = texture(tex_dep[0], vec3(0));
// VUID 02704
// OpImageSampleExplicitLod instructions that incudes a offset with unnormalized coordinates
x = textureLodOffset(tex[1], vec2(0), 0, ivec2(0));
}
)glsl";
VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
CreatePipelineHelper g_pipe(*this);
g_pipe.InitInfo();
g_pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
g_pipe.dsl_bindings_ = {{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr},
{1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_ALL_GRAPHICS, nullptr},
{2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}};
g_pipe.InitState();