forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer_validation_tests.h
More file actions
966 lines (806 loc) · 39.6 KB
/
Copy pathlayer_validation_tests.h
File metadata and controls
966 lines (806 loc) · 39.6 KB
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
/*
* 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.
*
* 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
*/
#ifndef VKLAYERTEST_H
#define VKLAYERTEST_H
#include <vulkan/vulkan.h>
#include "layers/vk_lunarg_device_profile_api_layer.h"
#include "vk_layer_settings_ext.h"
#if defined(ANDROID)
#include <android/log.h>
#if defined(VALIDATION_APK)
#include <android_native_app_glue.h>
#endif
#endif
#include "icd-spv.h"
#include "test_common.h"
#include "vk_layer_config.h"
#include "vk_layer_data.h"
#include "vk_format_utils.h"
#include "vkrenderframework.h"
#include "vk_typemap_helper.h"
#include "convert_to_renderpass2.h"
#include <algorithm>
#include <cmath>
#include <functional>
#include <limits>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>
using std::string;
using std::vector;
//--------------------------------------------------------------------------------------
// Mesh and VertexFormat Data
//--------------------------------------------------------------------------------------
enum BsoFailSelect {
BsoFailNone,
BsoFailLineWidth,
BsoFailDepthBias,
BsoFailViewport,
BsoFailScissor,
BsoFailBlend,
BsoFailDepthBounds,
BsoFailStencilReadMask,
BsoFailStencilWriteMask,
BsoFailStencilReference,
BsoFailCmdClearAttachments,
BsoFailIndexBuffer,
BsoFailIndexBufferBadSize,
BsoFailIndexBufferBadOffset,
BsoFailIndexBufferBadMapSize,
BsoFailIndexBufferBadMapOffset,
BsoFailLineStipple,
};
static const char bindStateMinimalShaderText[] = R"glsl(
#version 450
void main() {}
)glsl";
static const char bindStateVertShaderText[] = R"glsl(
#version 450
void main() {
gl_Position = vec4(1);
}
)glsl";
static const char bindStateVertPointSizeShaderText[] = R"glsl(
#version 450
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
};
void main() {
gl_Position = vec4(1);
gl_PointSize = 1.0;
}
)glsl";
static char const bindStateGeomShaderText[] = R"glsl(
#version 450
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
void main() {
gl_Position = vec4(1);
EmitVertex();
}
)glsl";
static char const bindStateGeomPointSizeShaderText[] = R"glsl(
#version 450
layout (points) in;
layout (points) out;
layout (max_vertices = 1) out;
void main() {
gl_Position = vec4(1);
gl_PointSize = 1.0;
EmitVertex();
}
)glsl";
static const char bindStateTscShaderText[] = R"glsl(
#version 450
layout(vertices=3) out;
void main() {
gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;
gl_TessLevelInner[0] = 1;
}
)glsl";
static const char bindStateTeshaderText[] = R"glsl(
#version 450
layout(triangles, equal_spacing, cw) in;
void main() { gl_Position = vec4(1); }
)glsl";
static const char bindStateFragShaderText[] = R"glsl(
#version 450
layout(location = 0) out vec4 uFragColor;
void main(){
uFragColor = vec4(0,1,0,1);
}
)glsl";
static const char bindStateFragSamplerShaderText[] = 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";
static const char bindStateFragUniformShaderText[] = R"glsl(
#version 450
layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;
layout(location=0) out vec4 x;
void main(){
x = vec4(bar.y);
}
)glsl";
static char const bindStateFragSubpassLoadInputText[] = R"glsl(
#version 450
layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;
void main() {
vec4 color = subpassLoad(x);
}
)glsl";
[[maybe_unused]] static const char *bindStateRTShaderText = R"glsl(
#version 460
#extension GL_EXT_ray_tracing : require
void main() {}
)glsl";
// Static arrays helper
template <class ElementT, size_t array_size>
size_t size(ElementT (&)[array_size]) {
return array_size;
}
template <class ElementT, size_t array_size>
uint32_t size32(ElementT (&)[array_size]) {
return static_cast<uint32_t>(array_size);
}
template <class Container>
uint32_t size32(const Container &c) {
return static_cast<uint32_t>(c.size());
}
// Format search helper
VkFormat FindSupportedDepthOnlyFormat(VkPhysicalDevice phy);
VkFormat FindSupportedStencilOnlyFormat(VkPhysicalDevice phy);
VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy);
// Returns true if *any* requested features are available.
// Assumption is that the framework can successfully create an image as
// long as at least one of the feature bits is present (excepting VTX_BUF).
bool ImageFormatIsSupported(VkPhysicalDevice phy, VkFormat format, VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL,
VkFormatFeatureFlags features = ~VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
// Returns true if format and *all* requested features are available.
bool ImageFormatAndFeaturesSupported(VkPhysicalDevice phy, VkFormat format, VkImageTiling tiling, VkFormatFeatureFlags features);
// Returns true if format and *all* requested features are available.
bool ImageFormatAndFeaturesSupported(const VkInstance inst, const VkPhysicalDevice phy, const VkImageCreateInfo info,
const VkFormatFeatureFlags features);
// Returns true if format and *all* requested features are available.
bool BufferFormatAndFeaturesSupported(VkPhysicalDevice phy, VkFormat format, VkFormatFeatureFlags features);
// Simple sane SamplerCreateInfo boilerplate
VkSamplerCreateInfo SafeSaneSamplerCreateInfo();
VkImageViewCreateInfo SafeSaneImageViewCreateInfo(VkImage image, VkFormat format, VkImageAspectFlags aspect_mask);
VkImageViewCreateInfo SafeSaneImageViewCreateInfo(const VkImageObj &image, VkFormat format, VkImageAspectFlags aspect_mask);
bool CheckSynchronization2SupportAndInitState(VkRenderFramework *renderFramework);
// Dependent "false" type for the static assert, as GCC will evaluate
// non-dependent static_asserts even for non-instantiated templates
template <typename T>
struct AlwaysFalse : std::false_type {};
// Helpers to get nearest greater or smaller value (of float) -- useful for testing the boundary cases of Vulkan limits
template <typename T>
T NearestGreater(const T from) {
using Lim = std::numeric_limits<T>;
const auto positive_direction = Lim::has_infinity ? Lim::infinity() : Lim::max();
return std::nextafter(from, positive_direction);
}
template <typename T>
T NearestSmaller(const T from) {
using Lim = std::numeric_limits<T>;
const auto negative_direction = Lim::has_infinity ? -Lim::infinity() : Lim::lowest();
return std::nextafter(from, negative_direction);
}
class VkLayerTest : public VkRenderFramework {
public:
const char *kValidationLayerName = "VK_LAYER_KHRONOS_validation";
const char *kSynchronization2LayerName = "VK_LAYER_KHRONOS_synchronization2";
void VKTriangleTest(BsoFailSelect failCase);
void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
BsoFailSelect failCase);
void Init(VkPhysicalDeviceFeatures *features = nullptr, VkPhysicalDeviceFeatures2 *features2 = nullptr,
const VkCommandPoolCreateFlags flags = 0, void *instance_pnext = nullptr);
enum class WsiPreference { Default, Wayland, X11, XCB };
void AddSurfaceExtension(const WsiPreference preference = WsiPreference::Default);
VkCommandBufferObj *CommandBuffer();
void OOBRayTracingShadersTestBody(bool gpu_assisted);
template <typename Features>
VkPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2(Features &feature_query) {
auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&feature_query);
return GetPhysicalDeviceFeatures2(features2);
}
template <typename Properties>
VkPhysicalDeviceProperties2 GetPhysicalDeviceProperties2(Properties &props_query) {
auto props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&props_query);
return GetPhysicalDeviceProperties2(props2);
}
template <typename Proc, bool assert_proc = true>
[[nodiscard]] const Proc GetInstanceProcAddr(const char *proc_name) const noexcept {
static_assert(std::is_pointer_v<Proc>);
auto proc = reinterpret_cast<Proc>(vk::GetInstanceProcAddr(instance(), proc_name));
if constexpr (assert_proc) {
assert(proc);
}
return proc;
}
template <typename Proc, bool assert_proc = true>
[[nodiscard]] const Proc GetDeviceProcAddr(const char *proc_name) noexcept {
static_assert(std::is_pointer_v<Proc>);
auto proc = reinterpret_cast<Proc>(vk::GetDeviceProcAddr(device(), proc_name));
if constexpr (assert_proc) {
assert(proc);
}
return proc;
}
bool IsDriver(VkDriverId driver_id);
protected:
uint32_t m_instance_api_version = 0;
uint32_t m_target_api_version = 0;
bool m_enableWSI;
void SetTargetApiVersion(uint32_t target_api_version);
uint32_t DeviceValidationVersion() const;
bool LoadDeviceProfileLayer(
PFN_vkSetPhysicalDeviceFormatPropertiesEXT &fpvkSetPhysicalDeviceFormatPropertiesEXT,
PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT &fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT);
bool LoadDeviceProfileLayer(
PFN_vkSetPhysicalDeviceFormatProperties2EXT &fpvkSetPhysicalDeviceFormatProperties2EXT,
PFN_vkGetOriginalPhysicalDeviceFormatProperties2EXT &fpvkGetOriginalPhysicalDeviceFormatProperties2EXT);
bool LoadDeviceProfileLayer(PFN_vkSetPhysicalDeviceLimitsEXT &fpvkSetPhysicalDeviceLimitsEXT,
PFN_vkGetOriginalPhysicalDeviceLimitsEXT &fpvkGetOriginalPhysicalDeviceLimitsEXT);
bool LoadDeviceProfileLayer(PFN_vkSetPhysicalDeviceFeaturesEXT &fpvkSetPhysicalDeviceFeaturesEXT,
PFN_vkGetOriginalPhysicalDeviceFeaturesEXT &fpvkGetOriginalPhysicalDeviceFeaturesEXT);
bool LoadDeviceProfileLayer(PFN_VkSetPhysicalDeviceProperties2EXT &fpvkSetPhysicalDeviceProperties2EXT);
VkLayerTest();
};
template <>
VkPhysicalDeviceFeatures2 VkLayerTest::GetPhysicalDeviceFeatures2(VkPhysicalDeviceFeatures2 &feature_query);
template <>
VkPhysicalDeviceProperties2 VkLayerTest::GetPhysicalDeviceProperties2(VkPhysicalDeviceProperties2 &props2);
class VkPositiveLayerTest : public VkLayerTest {
public:
protected:
};
class VkBestPracticesLayerTest : public VkLayerTest {
public:
void InitBestPracticesFramework();
void InitBestPracticesFramework(const char* ValidationChecksToEnable);
protected:
VkValidationFeatureEnableEXT enables_[1] = {VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT};
VkValidationFeatureDisableEXT disables_[4] = {
VK_VALIDATION_FEATURE_DISABLE_THREAD_SAFETY_EXT, VK_VALIDATION_FEATURE_DISABLE_API_PARAMETERS_EXT,
VK_VALIDATION_FEATURE_DISABLE_OBJECT_LIFETIMES_EXT, VK_VALIDATION_FEATURE_DISABLE_CORE_CHECKS_EXT};
VkValidationFeaturesEXT features_ = {VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT, nullptr, 1, enables_, 4, disables_};
};
class VkAmdBestPracticesLayerTest : public VkBestPracticesLayerTest {};
class VkArmBestPracticesLayerTest : public VkBestPracticesLayerTest {
public:
std::unique_ptr<VkImageObj> CreateImage(VkFormat format, const uint32_t width, const uint32_t height,
VkImageUsageFlags attachment_usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
VkRenderPass CreateRenderPass(VkFormat format, VkAttachmentLoadOp load_op = VK_ATTACHMENT_LOAD_OP_CLEAR,
VkAttachmentStoreOp store_op = VK_ATTACHMENT_STORE_OP_STORE);
VkFramebuffer CreateFramebuffer(const uint32_t width, const uint32_t height, VkImageView image_view, VkRenderPass renderpass);
VkSampler CreateDefaultSampler();
};
class VkNvidiaBestPracticesLayerTest : public VkBestPracticesLayerTest {};
class VkWsiEnabledLayerTest : public VkLayerTest {
public:
protected:
VkWsiEnabledLayerTest() { m_enableWSI = true; }
};
class VkGpuAssistedLayerTest : public VkLayerTest {
public:
VkValidationFeaturesEXT GetValidationFeatures();
void ShaderBufferSizeTest(VkDeviceSize buffer_size, VkDeviceSize binding_offset, VkDeviceSize binding_range,
VkDescriptorType descriptor_type, const char *fragment_shader, const char *expected_error);
protected:
bool CanEnableGpuAV();
};
class VkDebugPrintfTest : public VkLayerTest {
public:
void InitDebugPrintfFramework();
protected:
};
class VkSyncValTest : public VkLayerTest {
public:
void InitSyncValFramework(bool enable_queue_submit_validation = false);
protected:
VkValidationFeatureEnableEXT enables_[1] = {VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT};
VkValidationFeatureDisableEXT disables_[4] = {
VK_VALIDATION_FEATURE_DISABLE_THREAD_SAFETY_EXT, VK_VALIDATION_FEATURE_DISABLE_API_PARAMETERS_EXT,
VK_VALIDATION_FEATURE_DISABLE_OBJECT_LIFETIMES_EXT, VK_VALIDATION_FEATURE_DISABLE_CORE_CHECKS_EXT};
VkValidationFeaturesEXT features_ = {VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT, nullptr, 1, enables_, 4, disables_};
};
class VkBufferTest {
public:
enum eTestEnFlags {
eDoubleDelete,
eInvalidDeviceOffset,
eInvalidMemoryOffset,
eBindNullBuffer,
eBindFakeBuffer,
eFreeInvalidHandle,
eNone,
};
enum eTestConditions { eOffsetAlignment = 1 };
static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0);
// A constructor which performs validation tests within construction.
VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone);
~VkBufferTest();
bool GetBufferCurrent();
const VkBuffer &GetBuffer();
void TestDoubleDestroy();
protected:
bool AllocateCurrent;
bool BoundCurrent;
bool CreateCurrent;
bool InvalidDeleteEn;
VkBuffer VulkanBuffer;
VkDevice VulkanDevice;
VkDeviceMemory VulkanMemory;
};
struct CreatePipelineHelper;
class VkVerticesObj {
public:
VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
VkDeviceSize aVertexCount, const float *aVerticies);
~VkVerticesObj();
bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj);
bool AddVertexInputToPipeHelpr(CreatePipelineHelper *pipelineHelper);
void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr);
protected:
static uint32_t BindIdGenerator;
bool BoundCurrent;
unsigned AttributeCount;
unsigned BindingCount;
uint32_t BindId;
VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
VkVertexInputAttributeDescription *VertexInputAttributeDescription;
VkVertexInputBindingDescription *VertexInputBindingDescription;
VkConstantBufferObj VulkanMemoryBuffer;
};
struct OneOffDescriptorSet {
VkDeviceObj *device_;
VkDescriptorPool pool_;
VkDescriptorSetLayoutObj layout_;
VkDescriptorSet set_;
typedef std::vector<VkDescriptorSetLayoutBinding> Bindings;
std::vector<VkDescriptorBufferInfo> buffer_infos;
std::vector<VkDescriptorImageInfo> image_infos;
std::vector<VkBufferView> buffer_views;
std::vector<VkWriteDescriptorSet> descriptor_writes;
OneOffDescriptorSet(VkDeviceObj *device, const Bindings &bindings, VkDescriptorSetLayoutCreateFlags layout_flags = 0,
void *layout_pnext = NULL, VkDescriptorPoolCreateFlags poolFlags = 0, void *allocate_pnext = NULL,
int buffer_info_size = 10, int image_info_size = 10, int buffer_view_size = 10);
~OneOffDescriptorSet();
bool Initialized();
void Clear();
void WriteDescriptorBufferInfo(int binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range,
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32_t arrayElement = 0,
uint32_t count = 1);
void WriteDescriptorBufferView(int binding, VkBufferView buffer_view,
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
uint32_t arrayElement = 0, uint32_t count = 1);
void WriteDescriptorImageInfo(int binding, VkImageView image_view, VkSampler sampler,
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, uint32_t arrayElement = 0,
uint32_t count = 1);
void UpdateDescriptorSets();
};
template <typename T>
bool IsValidVkStruct(const T &s) {
return LvlTypeMap<T>::kSType == s.sType;
}
// Helper class for tersely creating create pipeline tests
//
// Designed with minimal error checking to ensure easy error state creation
// See OneshotTest for typical usage
struct CreatePipelineHelper {
public:
std::vector<VkDescriptorSetLayoutBinding> dsl_bindings_;
std::unique_ptr<OneOffDescriptorSet> descriptor_set_;
std::vector<VkPipelineShaderStageCreateInfo> shader_stages_;
VkPipelineVertexInputStateCreateInfo vi_ci_ = {};
VkPipelineInputAssemblyStateCreateInfo ia_ci_ = {};
VkPipelineTessellationStateCreateInfo tess_ci_ = {};
VkViewport viewport_ = {};
VkRect2D scissor_ = {};
VkPipelineViewportStateCreateInfo vp_state_ci_ = {};
VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci_ = {};
VkPipelineLayoutCreateInfo pipeline_layout_ci_ = {};
VkPipelineLayoutObj pipeline_layout_;
VkPipelineDynamicStateCreateInfo dyn_state_ci_ = {};
VkPipelineRasterizationStateCreateInfo rs_state_ci_ = {};
VkPipelineRasterizationLineStateCreateInfoEXT line_state_ci_ = {};
std::vector<VkPipelineColorBlendAttachmentState> cb_attachments_ = {};
VkPipelineColorBlendStateCreateInfo cb_ci_ = {};
VkPipelineDepthStencilStateCreateInfo ds_ci_ = {};
VkGraphicsPipelineCreateInfo gp_ci_ = {};
VkPipelineCacheCreateInfo pc_ci_ = {};
VkPipeline pipeline_ = VK_NULL_HANDLE;
VkPipelineCache pipeline_cache_ = VK_NULL_HANDLE;
std::unique_ptr<VkShaderObj> vs_;
std::unique_ptr<VkShaderObj> fs_;
VkLayerTest &layer_test_;
std::optional<VkGraphicsPipelineLibraryCreateInfoEXT> gpl_info;
CreatePipelineHelper(VkLayerTest &test, uint32_t color_attachments_count = 1u);
~CreatePipelineHelper();
void InitDescriptorSetInfo();
void InitInputAndVertexInfo();
void InitMultisampleInfo();
void InitPipelineLayoutInfo();
void InitViewportInfo();
void InitDynamicStateInfo();
void InitShaderInfo();
void ResetShaderInfo(const char *vertex_shader_text, const char *fragment_shader_text);
void InitRasterizationInfo();
void InitLineRasterizationInfo();
void InitBlendStateInfo();
void InitGraphicsPipelineInfo();
void InitPipelineCacheInfo();
// Not called by default during init_info
void InitTesselationState();
// TDB -- add control for optional and/or additional initialization
void InitInfo();
void InitState();
void InitPipelineCache();
void LateBindPipelineInfo();
VkResult CreateGraphicsPipeline(bool implicit_destroy = true, bool do_late_bind = true);
void InitVertexInputLibInfo(void *p_next = nullptr);
template <typename StageContainer>
void InitPreRasterLibInfoFromContainer(const StageContainer &stages, void *p_next = nullptr) {
InitPreRasterLibInfo(static_cast<uint32_t>(stages.size()), stages.data(), p_next);
}
void InitPreRasterLibInfo(uint32_t count, const VkPipelineShaderStageCreateInfo *info, void *p_next = nullptr);
template <typename StageContainer>
void InitFragmentLibInfoFromContainer(const StageContainer &stages, void *p_next = nullptr) {
InitFragmentLibInfo(static_cast<uint32_t>(stages.size()), stages.data(), p_next);
}
void InitFragmentLibInfo(uint32_t count, const VkPipelineShaderStageCreateInfo *info, void *p_next = nullptr);
void InitFragmentOutputLibInfo(void *p_next = nullptr);
// Helper function to create a simple test case (positive or negative)
//
// info_override can be any callable that takes a CreatePipelineHeper &
// flags, error can be any args accepted by "SetDesiredFailure".
template <typename Test, typename OverrideFunc, typename ErrorContainer>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags, const ErrorContainer &errors) {
CreatePipelineHelper helper(test);
helper.InitInfo();
info_override(helper);
helper.InitState();
for (const auto &error : errors) test.Monitor().SetDesiredFailureMsg(flags, error);
helper.CreateGraphicsPipeline();
if (!errors.empty()) {
test.Monitor().VerifyFound();
}
}
template <typename Test, typename OverrideFunc>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags, const char *error) {
std::array errors = {error};
OneshotTest(test, info_override, flags, errors);
}
template <typename Test, typename OverrideFunc>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags, const std::string &error) {
std::array errors = {error};
OneshotTest(test, info_override, flags, errors);
}
template <typename Test, typename OverrideFunc>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags) {
std::array<const char *, 0> errors;
OneshotTest(test, info_override, flags, errors);
}
};
struct CreateComputePipelineHelper {
public:
std::vector<VkDescriptorSetLayoutBinding> dsl_bindings_;
std::unique_ptr<OneOffDescriptorSet> descriptor_set_;
VkPipelineLayoutCreateInfo pipeline_layout_ci_ = {};
VkPipelineLayoutObj pipeline_layout_;
VkComputePipelineCreateInfo cp_ci_ = {};
VkPipelineCacheCreateInfo pc_ci_ = {};
VkPipeline pipeline_ = VK_NULL_HANDLE;
VkPipelineCache pipeline_cache_ = VK_NULL_HANDLE;
std::unique_ptr<VkShaderObj> cs_;
bool override_skip_ = false;
VkLayerTest &layer_test_;
CreateComputePipelineHelper(VkLayerTest &test);
~CreateComputePipelineHelper();
void InitDescriptorSetInfo();
void InitPipelineLayoutInfo();
void InitShaderInfo();
void InitComputePipelineInfo();
void InitPipelineCacheInfo();
// TDB -- add control for optional and/or additional initialization
void InitInfo();
void InitState();
void InitPipelineCache();
void LateBindPipelineInfo();
VkResult CreateComputePipeline(bool implicit_destroy = true, bool do_late_bind = true);
// Helper function to create a simple test case (positive or negative)
//
// info_override can be any callable that takes a CreatePipelineHeper &
// flags, error can be any args accepted by "SetDesiredFailure".
template <typename Test, typename OverrideFunc, typename Error>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags, const std::vector<Error> &errors,
bool positive_test = false) {
CreateComputePipelineHelper helper(test);
helper.InitInfo();
info_override(helper);
// Allow lambda to decide if to skip trying to compile pipeline to prevent crashing
if (helper.override_skip_) {
helper.override_skip_ = false; // reset
return;
}
helper.InitState();
for (const auto &error : errors) test.Monitor().SetDesiredFailureMsg(flags, error);
helper.CreateComputePipeline();
if (!errors.empty()) {
test.Monitor().VerifyFound();
}
}
template <typename Test, typename OverrideFunc, typename Error>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags, Error error) {
OneshotTest(test, info_override, flags, std::vector<Error>(1, error));
}
template <typename Test, typename OverrideFunc>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const VkFlags flags) {
OneshotTest(test, info_override, flags, std::vector<std::string>{});
}
};
// Helper class for tersely creating create ray tracing pipeline tests
//
// Designed with minimal error checking to ensure easy error state creation
// See OneshotTest for typical usage
struct CreateNVRayTracingPipelineHelper {
public:
std::vector<VkDescriptorSetLayoutBinding> dsl_bindings_;
std::unique_ptr<OneOffDescriptorSet> descriptor_set_;
std::vector<VkPipelineShaderStageCreateInfo> shader_stages_;
VkPipelineLayoutCreateInfo pipeline_layout_ci_ = {};
VkPipelineLayoutObj pipeline_layout_;
VkRayTracingPipelineCreateInfoNV rp_ci_ = {};
VkRayTracingPipelineCreateInfoKHR rp_ci_KHR_ = {};
VkPipelineCacheCreateInfo pc_ci_ = {};
VkPipeline pipeline_ = VK_NULL_HANDLE;
VkPipelineCache pipeline_cache_ = VK_NULL_HANDLE;
std::vector<VkRayTracingShaderGroupCreateInfoNV> groups_;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> groups_KHR_;
std::unique_ptr<VkShaderObj> rgs_;
std::unique_ptr<VkShaderObj> chs_;
std::unique_ptr<VkShaderObj> mis_;
VkLayerTest &layer_test_;
CreateNVRayTracingPipelineHelper(VkLayerTest &test);
~CreateNVRayTracingPipelineHelper();
void InitShaderGroups();
void InitShaderGroupsKHR();
void InitDescriptorSetInfo();
void InitDescriptorSetInfoKHR();
void InitPipelineLayoutInfo();
void InitShaderInfo();
void InitShaderInfoKHR();
void InitNVRayTracingPipelineInfo();
void InitKHRRayTracingPipelineInfo();
void InitPipelineCacheInfo();
void InitInfo(bool isKHR = false);
void InitState();
void InitPipelineCache();
void LateBindPipelineInfo(bool isKHR = false);
VkResult CreateNVRayTracingPipeline(bool implicit_destroy = true, bool do_late_bind = true);
VkResult CreateKHRRayTracingPipeline(bool implicit_destroy = true, bool do_late_bind = true);
// Helper function to create a simple test case (positive or negative)
//
// info_override can be any callable that takes a CreateNVRayTracingPipelineHelper &
// flags, error can be any args accepted by "SetDesiredFailure".
template <typename Test, typename OverrideFunc, typename Error>
static void OneshotTest(Test &test, const OverrideFunc &info_override, const std::vector<Error> &errors,
const VkFlags flags = kErrorBit) {
CreateNVRayTracingPipelineHelper helper(test);
helper.InitInfo();
info_override(helper);
helper.InitState();
for (const auto &error : errors) test.Monitor().SetDesiredFailureMsg(flags, error);
helper.CreateNVRayTracingPipeline();
test.Monitor().VerifyFound();
}
template <typename Test, typename OverrideFunc, typename Error>
static void OneshotTest(Test &test, const OverrideFunc &info_override, Error error, const VkFlags flags = kErrorBit) {
OneshotTest(test, info_override, std::vector<Error>(1, error), flags);
}
template <typename Test, typename OverrideFunc>
static void OneshotPositiveTest(Test &test, const OverrideFunc &info_override, const VkFlags message_flag_mask = kErrorBit) {
CreateNVRayTracingPipelineHelper helper(test);
helper.InitInfo();
info_override(helper);
helper.InitState();
ASSERT_VK_SUCCESS(helper.CreateNVRayTracingPipeline());
}
};
class BarrierQueueFamilyBase {
public:
struct QueueFamilyObjs {
uint32_t index;
// We would use std::unique_ptr, but this triggers a compiler error on older compilers
VkQueueObj *queue = nullptr;
VkCommandPoolObj *command_pool = nullptr;
VkCommandBufferObj *command_buffer = nullptr;
VkCommandBufferObj *command_buffer2 = nullptr;
~QueueFamilyObjs();
void Init(VkDeviceObj *device, uint32_t qf_index, VkQueue qf_queue, VkCommandPoolCreateFlags cp_flags);
};
struct Context {
VkLayerTest *layer_test;
uint32_t default_index;
std::unordered_map<uint32_t, QueueFamilyObjs> queue_families;
Context(VkLayerTest *test, const std::vector<uint32_t> &queue_family_indices);
void Reset();
};
BarrierQueueFamilyBase(Context *context) : context_(context), image_(context->layer_test->DeviceObj()) {}
QueueFamilyObjs *GetQueueFamilyInfo(Context *context, uint32_t qfi);
enum Modifier {
NONE,
DOUBLE_RECORD,
DOUBLE_COMMAND_BUFFER,
};
static const uint32_t kInvalidQueueFamily = vvl::kU32Max;
Context *context_;
VkImageObj image_;
VkBufferObj buffer_;
};
class BarrierQueueFamilyTestHelper : public BarrierQueueFamilyBase {
public:
BarrierQueueFamilyTestHelper(Context *context) : BarrierQueueFamilyBase(context) {}
// Init with queue families non-null for CONCURRENT sharing mode (which requires them)
void Init(std::vector<uint32_t> *families, bool image_memory = true, bool buffer_memory = true);
void operator()(const std::string &img_err, const std::string &buf_err = "", uint32_t src = VK_QUEUE_FAMILY_IGNORED,
uint32_t dst = VK_QUEUE_FAMILY_IGNORED, uint32_t queue_family_index = kInvalidQueueFamily,
Modifier mod = Modifier::NONE);
void operator()(uint32_t src = VK_QUEUE_FAMILY_IGNORED, uint32_t dst = VK_QUEUE_FAMILY_IGNORED,
uint32_t queue_family_index = kInvalidQueueFamily, Modifier mod = Modifier::NONE) {
(*this)("", "", src, dst, queue_family_index, mod);
}
VkImageMemoryBarrier image_barrier_;
VkBufferMemoryBarrier buffer_barrier_;
};
class Barrier2QueueFamilyTestHelper : public BarrierQueueFamilyBase {
public:
Barrier2QueueFamilyTestHelper(Context *context) : BarrierQueueFamilyBase(context) {}
// Init with queue families non-null for CONCURRENT sharing mode (which requires them)
void Init(std::vector<uint32_t> *families, bool image_memory = true, bool buffer_memory = true);
void operator()(const std::string &img_err, const std::string &buf_err = "", uint32_t src = VK_QUEUE_FAMILY_IGNORED,
uint32_t dst = VK_QUEUE_FAMILY_IGNORED, uint32_t queue_family_index = kInvalidQueueFamily,
Modifier mod = Modifier::NONE);
void operator()(uint32_t src = VK_QUEUE_FAMILY_IGNORED, uint32_t dst = VK_QUEUE_FAMILY_IGNORED,
uint32_t queue_family_index = kInvalidQueueFamily, Modifier mod = Modifier::NONE) {
(*this)("", "", src, dst, queue_family_index, mod);
}
VkImageMemoryBarrier2KHR image_barrier_;
VkBufferMemoryBarrier2KHR buffer_barrier_;
};
struct DebugUtilsLabelCheckData {
std::function<void(const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, DebugUtilsLabelCheckData *)> callback;
size_t count;
};
bool operator==(const VkDebugUtilsLabelEXT &rhs, const VkDebugUtilsLabelEXT &lhs);
VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
#if GTEST_IS_THREADSAFE
struct ThreadTestData {
VkCommandBuffer commandBuffer;
VkDevice device;
VkEvent event;
VkDescriptorSet descriptorSet;
VkBuffer buffer;
uint32_t binding;
std::atomic<bool> *bailout;
};
void AddToCommandBuffer(ThreadTestData *);
void UpdateDescriptor(ThreadTestData *);
#endif // GTEST_IS_THREADSAFE
// Helper class that fails the tests with a stuck worker thread.
// Its purpose is similar to an assert. We assume the code is correct.
// Then, in case of a bug or regression, the CI will continue to operate.
// Usage Example:
// TEST_F(VkLayerTest, MyTrickyTestWithThreads) {
// // The constructor parameter is the number of the worker threads
// ThreadTimeoutHelper timeout_helper(2);
// auto worker = [&]() {
// auto timeout_guard = timeout_helper.ThreadGuard();
// // Some code here
// };
// std::thread t0(worker);
// std::thread t1(worker);
// if (!timeout_helper.WaitForThreads(60)) ADD_FAILURE() << "It's time to move on";
// t0.join();
// t1.join();
// }
class ThreadTimeoutHelper {
public:
explicit ThreadTimeoutHelper(int thread_count = 1) : active_threads_(thread_count) {}
bool WaitForThreads(int timeout_in_seconds);
struct Guard {
Guard(ThreadTimeoutHelper &timeout_helper) : timeout_helper_(timeout_helper) {}
~Guard() { timeout_helper_.OnThreadDone(); }
ThreadTimeoutHelper &timeout_helper_;
};
Guard ThreadGuard() { return Guard(*this); }
private:
void OnThreadDone();
int active_threads_;
std::condition_variable cv_;
std::mutex mutex_;
};
void ReleaseNullFence(ThreadTestData *);
void TestRenderPassCreate(ErrorMonitor *error_monitor, const VkDevice device, const VkRenderPassCreateInfo *create_info,
bool rp2_supported, const char *rp1_vuid, const char *rp2_vuid);
void PositiveTestRenderPassCreate(ErrorMonitor *error_monitor, const VkDevice device, const VkRenderPassCreateInfo *create_info,
bool rp2_supported);
void PositiveTestRenderPass2KHRCreate(ErrorMonitor *error_monitor, const VkDevice device,
const VkRenderPassCreateInfo2KHR *create_info);
void TestRenderPass2KHRCreate(ErrorMonitor *error_monitor, const VkDevice device, const VkRenderPassCreateInfo2KHR *create_info,
const char *rp2_vuid);
void TestRenderPassBegin(ErrorMonitor *error_monitor, const VkDevice device, const VkCommandBuffer command_buffer,
const VkRenderPassBeginInfo *begin_info, bool rp2Supported, const char *rp1_vuid, const char *rp2_vuid);
// Helpers for the tests below
void ValidOwnershipTransferOp(ErrorMonitor *monitor, VkCommandBufferObj *cb, VkPipelineStageFlags src_stages,
VkPipelineStageFlags dst_stages, const VkBufferMemoryBarrier *buf_barrier,
const VkImageMemoryBarrier *img_barrier);
void ValidOwnershipTransferOp(ErrorMonitor *monitor, VkCommandBufferObj *cb, const VkBufferMemoryBarrier2KHR *buf_barrier,
const VkImageMemoryBarrier2KHR *img_barrier);
void ValidOwnershipTransfer(ErrorMonitor *monitor, VkCommandBufferObj *cb_from, VkCommandBufferObj *cb_to,
VkPipelineStageFlags src_stages, VkPipelineStageFlags dst_stages,
const VkBufferMemoryBarrier *buf_barrier, const VkImageMemoryBarrier *img_barrier);
void ValidOwnershipTransfer(ErrorMonitor *monitor, VkCommandBufferObj *cb_from, VkCommandBufferObj *cb_to,
const VkBufferMemoryBarrier2KHR *buf_barrier, const VkImageMemoryBarrier2KHR *img_barrier);
VkResult GPDIFPHelper(VkPhysicalDevice dev, const VkImageCreateInfo *ci, VkImageFormatProperties *limits = nullptr);
VkFormat FindFormatLinearWithoutMips(VkPhysicalDevice gpu, VkImageCreateInfo image_ci);
bool FindFormatWithoutSamples(VkPhysicalDevice gpu, VkImageCreateInfo &image_ci);
bool FindUnsupportedImage(VkPhysicalDevice gpu, VkImageCreateInfo &image_ci);
VkFormat FindFormatWithoutFeatures(VkPhysicalDevice gpu, VkImageTiling tiling,
VkFormatFeatureFlags undesired_features = vvl::kU32Max);
VkExternalMemoryHandleTypeFlags FindSupportedExternalMemoryHandleTypes(VkPhysicalDevice gpu,
const VkBufferCreateInfo &buffer_create_info,
VkExternalMemoryFeatureFlags requested_features);
VkExternalMemoryHandleTypeFlags FindSupportedExternalMemoryHandleTypes(VkPhysicalDevice gpu,
const VkImageCreateInfo &image_create_info,
VkExternalMemoryFeatureFlags requested_features);
VkExternalMemoryHandleTypeFlagsNV FindSupportedExternalMemoryHandleTypesNV(const VkLayerTest &test,
const VkImageCreateInfo &image_create_info,
VkExternalMemoryFeatureFlagsNV requested_features);
VkExternalFenceHandleTypeFlags FindSupportedExternalFenceHandleTypes(VkPhysicalDevice gpu,
VkExternalFenceFeatureFlags requested_features);
VkExternalSemaphoreHandleTypeFlags FindSupportedExternalSemaphoreHandleTypes(VkPhysicalDevice gpu,
VkExternalSemaphoreFeatureFlags requested_features);
VkExternalMemoryHandleTypeFlags GetCompatibleHandleTypes(VkPhysicalDevice gpu, const VkBufferCreateInfo &buffer_create_info,
VkExternalMemoryHandleTypeFlagBits handle_type);
VkExternalMemoryHandleTypeFlags GetCompatibleHandleTypes(VkPhysicalDevice gpu, const VkImageCreateInfo &image_create_info,
VkExternalMemoryHandleTypeFlagBits handle_type);
VkExternalFenceHandleTypeFlags GetCompatibleHandleTypes(VkPhysicalDevice gpu, VkExternalFenceHandleTypeFlagBits handle_type);
VkExternalSemaphoreHandleTypeFlags GetCompatibleHandleTypes(VkPhysicalDevice gpu,
VkExternalSemaphoreHandleTypeFlagBits handle_type);
void SetImageLayout(VkDeviceObj *device, VkImageAspectFlags aspect, VkImage image, VkImageLayout image_layout);
void AllocateDisjointMemory(VkDeviceObj *device, PFN_vkGetImageMemoryRequirements2KHR fp, VkImage mp_image,
VkDeviceMemory *mp_image_mem, VkImageAspectFlagBits plane);
void NegHeightViewportTests(VkDeviceObj *m_device, VkCommandBufferObj *m_commandBuffer, ErrorMonitor *m_errorMonitor);
void CreateSamplerTest(VkLayerTest &test, const VkSamplerCreateInfo *pCreateInfo, const std::string &code = "");
void CreateBufferTest(VkLayerTest &test, const VkBufferCreateInfo *pCreateInfo, const std::string &code = "");
void CreateImageTest(VkLayerTest &test, const VkImageCreateInfo *pCreateInfo, const std::string &code = "");
void CreateBufferViewTest(VkLayerTest &test, const VkBufferViewCreateInfo *pCreateInfo, const std::vector<std::string> &codes);
void CreateImageViewTest(VkLayerTest &test, const VkImageViewCreateInfo *pCreateInfo, const std::string &code = "");
bool InitFrameworkForRayTracingTest(VkRenderFramework *framework, bool is_khr, VkPhysicalDeviceFeatures2KHR *features2 = nullptr,
VkValidationFeaturesEXT *enabled_features = nullptr);
void GetSimpleGeometryForAccelerationStructureTests(const VkDeviceObj &device, VkBufferObj *vbo, VkBufferObj *ibo,
VkGeometryNV *geometry, VkDeviceSize offset = 0, bool buffer_device_address = false);
std::pair<VkBufferObj &&, VkAccelerationStructureGeometryKHR> GetSimpleAABB(const VkDeviceObj &device,
uint32_t vk_api_version = VK_API_VERSION_1_2);
void print_android(const char *c);
#endif // VKLAYERTEST_H