forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vktestbinding.cpp
1141 lines (940 loc) · 46.2 KB
/
vktestbinding.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-2022 The Khronos Group Inc.
* Copyright (c) 2015-2022 Valve Corporation
* Copyright (c) 2015-2022 LunarG, 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
* Author: Tony Barbour <tony@LunarG.com>
*/
#include "vktestbinding.h"
#include <string.h> // memset(), memcmp()
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include "test_common.h"
#include "vk_typemap_helper.h"
#include "vk_format_utils.h"
namespace {
#define NON_DISPATCHABLE_HANDLE_INIT(create_func, dev, ...) \
do { \
handle_type handle; \
auto result = create_func(dev.handle(), __VA_ARGS__, NULL, &handle); \
if (EXPECT((result == VK_SUCCESS) || (result == VK_ERROR_VALIDATION_FAILED_EXT) || \
(result == VK_ERROR_OUT_OF_DEVICE_MEMORY) || (result == VK_ERROR_OUT_OF_HOST_MEMORY))) { \
if (result == VK_SUCCESS) { \
NonDispHandle::init(dev.handle(), handle); \
} \
} \
} while (0)
#define NON_DISPATCHABLE_HANDLE_DTOR(cls, destroy_func) \
cls::~cls() noexcept { \
if (initialized()) { \
destroy_func(device(), handle(), NULL); \
handle_ = VK_NULL_HANDLE; \
} \
}
#define STRINGIFY(x) #x
#define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__))
vk_testing::ErrorCallback error_callback;
bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function) {
if (error_callback) {
error_callback(expr, file, line, function);
} else {
std::cerr << file << ":" << line << ": " << function << ": Expectation `" << expr << "' failed.\n";
}
return false;
}
} // namespace
namespace vk_testing {
void set_error_callback(ErrorCallback callback) { error_callback = callback; }
VkPhysicalDeviceProperties PhysicalDevice::properties() const {
VkPhysicalDeviceProperties info;
vk::GetPhysicalDeviceProperties(handle(), &info);
return info;
}
std::vector<VkQueueFamilyProperties> PhysicalDevice::queue_properties() const {
std::vector<VkQueueFamilyProperties> info;
uint32_t count;
// Call once with NULL data to receive count
vk::GetPhysicalDeviceQueueFamilyProperties(handle(), &count, NULL);
info.resize(count);
vk::GetPhysicalDeviceQueueFamilyProperties(handle(), &count, info.data());
return info;
}
VkPhysicalDeviceMemoryProperties PhysicalDevice::memory_properties() const {
VkPhysicalDeviceMemoryProperties info;
vk::GetPhysicalDeviceMemoryProperties(handle(), &info);
return info;
}
VkPhysicalDeviceFeatures PhysicalDevice::features() const {
VkPhysicalDeviceFeatures features;
vk::GetPhysicalDeviceFeatures(handle(), &features);
return features;
}
/*
* Return list of Global layers available
*/
std::vector<VkLayerProperties> GetGlobalLayers() {
VkResult err;
uint32_t layer_count = 32;
std::vector<VkLayerProperties> layers(layer_count);
for (;;) {
err = vk::EnumerateInstanceLayerProperties(&layer_count, layers.data());
if (err == VK_SUCCESS) {
layers.resize(layer_count);
return layers;
} else if (err == VK_INCOMPLETE) {
layer_count *= 2; // wasn't enough space, increase it
layers.resize(layer_count);
} else {
return {};
}
}
}
/*
* Return list of Global extensions provided by the ICD / Loader
*/
std::vector<VkExtensionProperties> GetGlobalExtensions() { return GetGlobalExtensions(nullptr); }
/*
* Return list of Global extensions provided by the specified layer
* If pLayerName is NULL, will return extensions implemented by the loader /
* ICDs
*/
std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName) {
VkResult err;
uint32_t extension_count = 32;
std::vector<VkExtensionProperties> extensions(extension_count);
for (;;) {
err = vk::EnumerateInstanceExtensionProperties(pLayerName, &extension_count, extensions.data());
if (err == VK_SUCCESS) {
extensions.resize(extension_count);
return extensions;
} else if (err == VK_INCOMPLETE) {
extension_count *= 2; // wasn't enough space, increase it
extensions.resize(extension_count);
} else {
return {};
}
}
}
/*
* Return list of PhysicalDevice extensions provided by the specified layer
* If pLayerName is NULL, will return extensions for ICD / loader.
*/
std::vector<VkExtensionProperties> PhysicalDevice::extensions(const char *pLayerName) const {
VkResult err;
uint32_t extension_count = 512;
std::vector<VkExtensionProperties> extensions(extension_count);
for (;;) {
err = vk::EnumerateDeviceExtensionProperties(handle(), pLayerName, &extension_count, extensions.data());
if (err == VK_SUCCESS) {
extensions.resize(extension_count);
return extensions;
} else if (err == VK_INCOMPLETE) {
extension_count *= 2; // wasn't enough space, increase it
extensions.resize(extension_count);
} else {
return {};
}
}
}
bool PhysicalDevice::set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkFlags properties,
const VkFlags forbid) const {
uint32_t type_mask = type_bits;
// Search memtypes to find first index with those properties
for (uint32_t i = 0; i < memory_properties_.memoryTypeCount; i++) {
if ((type_mask & 1) == 1) {
// Type is available, does it match user properties?
if ((memory_properties_.memoryTypes[i].propertyFlags & properties) == properties &&
(memory_properties_.memoryTypes[i].propertyFlags & forbid) == 0 &&
(memory_properties_.memoryHeaps[memory_properties_.memoryTypes[i].heapIndex].size >= info->allocationSize)) {
info->memoryTypeIndex = i;
return true;
}
}
type_mask >>= 1;
}
// No memory types matched, return failure
return false;
}
/*
* Return list of PhysicalDevice layers
*/
std::vector<VkLayerProperties> PhysicalDevice::layers() const {
VkResult err;
uint32_t layer_count = 32;
std::vector<VkLayerProperties> layers(layer_count);
for (;;) {
err = vk::EnumerateDeviceLayerProperties(handle(), &layer_count, layers.data());
if (err == VK_SUCCESS) {
layers.resize(layer_count);
return layers;
} else if (err == VK_INCOMPLETE) {
layer_count *= 2; // wasn't enough space, increase it
layers.resize(layer_count);
} else {
return {};
}
}
}
QueueCreateInfoArray::QueueCreateInfoArray(const std::vector<VkQueueFamilyProperties> &queue_props)
: queue_info_(), queue_priorities_() {
queue_info_.reserve(queue_props.size());
for (uint32_t i = 0; i < (uint32_t)queue_props.size(); ++i) {
if (queue_props[i].queueCount > 0) {
VkDeviceQueueCreateInfo qi = LvlInitStruct<VkDeviceQueueCreateInfo>();
qi.queueFamilyIndex = i;
qi.queueCount = queue_props[i].queueCount;
queue_priorities_.emplace_back(qi.queueCount, 0.0f);
qi.pQueuePriorities = queue_priorities_[i].data();
queue_info_.push_back(qi);
}
}
}
Device::~Device() noexcept {
if (!initialized()) return;
vk::DestroyDevice(handle(), NULL);
}
void Device::init(std::vector<const char *> &extensions, VkPhysicalDeviceFeatures *features, void *create_device_pnext) {
// request all queues
const std::vector<VkQueueFamilyProperties> queue_props = phy_.queue_properties();
QueueCreateInfoArray queue_info(phy_.queue_properties());
for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphics_queue_node_index_ = i;
break;
}
}
// Only request creation with queuefamilies that have at least one queue
std::vector<VkDeviceQueueCreateInfo> create_queue_infos;
auto qci = queue_info.data();
for (uint32_t j = 0; j < queue_info.size(); ++j) {
if (qci[j].queueCount) {
create_queue_infos.push_back(qci[j]);
}
}
enabled_extensions_ = extensions;
VkDeviceCreateInfo dev_info = LvlInitStruct<VkDeviceCreateInfo>(create_device_pnext);
dev_info.queueCreateInfoCount = create_queue_infos.size();
dev_info.pQueueCreateInfos = create_queue_infos.data();
dev_info.enabledLayerCount = 0;
dev_info.ppEnabledLayerNames = NULL;
dev_info.enabledExtensionCount = extensions.size();
dev_info.ppEnabledExtensionNames = extensions.data();
VkPhysicalDeviceFeatures all_features;
// Let VkPhysicalDeviceFeatures2 take priority over VkPhysicalDeviceFeatures,
// since it supports extensions
if (!(LvlFindInChain<VkPhysicalDeviceFeatures2>(dev_info.pNext))) {
if (features) {
dev_info.pEnabledFeatures = features;
} else {
// request all supportable features enabled
all_features = phy().features();
dev_info.pEnabledFeatures = &all_features;
}
}
init(dev_info);
}
void Device::init(const VkDeviceCreateInfo &info) {
VkDevice dev;
if (EXPECT(vk::CreateDevice(phy_.handle(), &info, NULL, &dev) == VK_SUCCESS)) Handle::init(dev);
init_queues(info);
init_formats();
}
void Device::init_queues(const VkDeviceCreateInfo &info) {
uint32_t queue_node_count;
vk::GetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, NULL);
EXPECT(queue_node_count >= 1);
std::vector<VkQueueFamilyProperties> queue_props(queue_node_count);
vk::GetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, queue_props.data());
queue_families_.resize(queue_node_count);
for (uint32_t i = 0; i < info.queueCreateInfoCount; i++) {
const auto &queue_create_info = info.pQueueCreateInfos[i];
auto queue_family_i = queue_create_info.queueFamilyIndex;
const auto &queue_family_prop = queue_props[queue_family_i];
QueueFamilyQueues &queue_storage = queue_families_[queue_family_i];
queue_storage.reserve(queue_create_info.queueCount);
for (uint32_t queue_i = 0; queue_i < queue_create_info.queueCount; ++queue_i) {
// TODO: Need to add support for separate MEMMGR and work queues,
// including synchronization
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(handle(), queue_family_i, queue_i, &queue);
// Store single copy of the queue object that will self destruct
queue_storage.emplace_back(new Queue(queue, queue_family_i));
if (queue_family_prop.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
queues_[GRAPHICS].push_back(queue_storage.back().get());
}
if (queue_family_prop.queueFlags & VK_QUEUE_COMPUTE_BIT) {
queues_[COMPUTE].push_back(queue_storage.back().get());
}
if (queue_family_prop.queueFlags & VK_QUEUE_TRANSFER_BIT) {
queues_[DMA].push_back(queue_storage.back().get());
}
}
}
EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty() || !queues_[DMA].empty());
}
const Device::QueueFamilyQueues &Device::queue_family_queues(uint32_t queue_family) const {
assert(queue_family < queue_families_.size());
return queue_families_[queue_family];
}
void Device::init_formats() {
// For each 1.0 core format, undefined = first, 12x12_SRGB_BLOCK = last
for (int f = VK_FORMAT_UNDEFINED; f <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK; f++) {
const VkFormat fmt = static_cast<VkFormat>(f);
const VkFormatProperties props = format_properties(fmt);
if (props.linearTilingFeatures) {
const Format tmp = {fmt, VK_IMAGE_TILING_LINEAR, props.linearTilingFeatures};
formats_.push_back(tmp);
}
if (props.optimalTilingFeatures) {
const Format tmp = {fmt, VK_IMAGE_TILING_OPTIMAL, props.optimalTilingFeatures};
formats_.push_back(tmp);
}
}
EXPECT(!formats_.empty());
}
bool Device::IsEnabledExtension(const char *extension) {
const auto is_x = [&extension](const char *enabled_extension) { return strcmp(extension, enabled_extension) == 0; };
return std::any_of(enabled_extensions_.begin(), enabled_extensions_.end(), is_x);
}
VkFormatProperties Device::format_properties(VkFormat format) {
VkFormatProperties data;
vk::GetPhysicalDeviceFormatProperties(phy().handle(), format, &data);
return data;
}
void Device::wait() { EXPECT(vk::DeviceWaitIdle(handle()) == VK_SUCCESS); }
VkResult Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) {
const std::vector<VkFence> fence_handles = MakeVkHandles<VkFence>(fences);
VkResult err = vk::WaitForFences(handle(), fence_handles.size(), fence_handles.data(), wait_all, timeout);
EXPECT(err == VK_SUCCESS || err == VK_TIMEOUT);
return err;
}
void Device::update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes,
const std::vector<VkCopyDescriptorSet> &copies) {
vk::UpdateDescriptorSets(handle(), writes.size(), writes.data(), copies.size(), copies.data());
}
VkResult Queue::submit(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success) {
const std::vector<VkCommandBuffer> cmd_handles = MakeVkHandles<VkCommandBuffer>(cmds);
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = nullptr;
submit_info.pWaitDstStageMask = nullptr;
submit_info.commandBufferCount = static_cast<uint32_t>(cmd_handles.size());
submit_info.pCommandBuffers = cmd_handles.data();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = nullptr;
VkResult result = vk::QueueSubmit(handle(), 1, &submit_info, fence.handle());
if (expect_success) EXPECT(result == VK_SUCCESS);
return result;
}
VkResult Queue::submit(const CommandBuffer &cmd, const Fence &fence, bool expect_success) {
return submit(std::vector<const CommandBuffer *>(1, &cmd), fence, expect_success);
}
VkResult Queue::submit(const CommandBuffer &cmd, bool expect_success) {
Fence fence;
return submit(cmd, fence);
}
VkResult Queue::submit2(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success) {
std::vector<VkCommandBufferSubmitInfo> cmd_submit_infos;
for (size_t i = 0; i < cmds.size(); i++) {
VkCommandBufferSubmitInfo cmd_submit_info = LvlInitStruct<VkCommandBufferSubmitInfo>();
cmd_submit_info.deviceMask = 0;
cmd_submit_info.commandBuffer = cmds[i]->handle();
cmd_submit_infos.push_back(cmd_submit_info);
}
VkSubmitInfo2 submit_info = LvlInitStruct<VkSubmitInfo2>();
submit_info.flags = 0;
submit_info.waitSemaphoreInfoCount = 0;
submit_info.pWaitSemaphoreInfos = nullptr;
submit_info.signalSemaphoreInfoCount = 0;
submit_info.pSignalSemaphoreInfos = nullptr;
submit_info.commandBufferInfoCount = static_cast<uint32_t>(cmd_submit_infos.size());
submit_info.pCommandBufferInfos = cmd_submit_infos.data();
// requires synchronization2 to be enabled
VkResult result = vk::QueueSubmit2(handle(), 1, &submit_info, fence.handle());
if (expect_success) EXPECT(result == VK_SUCCESS);
return result;
}
VkResult Queue::submit2(const CommandBuffer &cmd, const Fence &fence, bool expect_success) {
return submit2(std::vector<const CommandBuffer *>(1, &cmd), fence, expect_success);
}
VkResult Queue::wait() {
VkResult result = vk::QueueWaitIdle(handle());
EXPECT(result == VK_SUCCESS);
return result;
}
DeviceMemory::~DeviceMemory() noexcept {
if (initialized()) vk::FreeMemory(device(), handle(), NULL);
}
void DeviceMemory::init(const Device &dev, const VkMemoryAllocateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::AllocateMemory, dev, &info);
}
const void *DeviceMemory::map(VkFlags flags) const {
void *data;
if (!EXPECT(vk::MapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL;
return data;
}
void *DeviceMemory::map(VkFlags flags) {
void *data;
if (!EXPECT(vk::MapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL;
return data;
}
void DeviceMemory::unmap() const { vk::UnmapMemory(device(), handle()); }
VkMemoryAllocateInfo DeviceMemory::get_resource_alloc_info(const Device &dev, const VkMemoryRequirements &reqs,
VkMemoryPropertyFlags mem_props) {
// Find appropriate memory type for given reqs
VkPhysicalDeviceMemoryProperties dev_mem_props = dev.phy().memory_properties();
uint32_t mem_type_index = 0;
for (mem_type_index = 0; mem_type_index < dev_mem_props.memoryTypeCount; ++mem_type_index) {
if (mem_props == (mem_props & dev_mem_props.memoryTypes[mem_type_index].propertyFlags)) break;
}
// If we exceeded types, then this device doesn't have the memory we need
assert(mem_type_index < dev_mem_props.memoryTypeCount);
VkMemoryAllocateInfo info = alloc_info(reqs.size, mem_type_index);
EXPECT(dev.phy().set_memory_type(reqs.memoryTypeBits, &info, mem_props));
return info;
}
NON_DISPATCHABLE_HANDLE_DTOR(Fence, vk::DestroyFence)
void Fence::init(const Device &dev, const VkFenceCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vk::CreateFence, dev, &info); }
VkResult Fence::wait(uint64_t timeout) const {
VkFence fence = handle();
return vk::WaitForFences(device(), 1, &fence, VK_TRUE, timeout);
}
VkResult Fence::reset() {
VkFence fence = handle();
return vk::ResetFences(device(), 1, &fence);
}
VkResult Fence::export_handle(Fence::ExternalHandle &ext_handle, VkExternalFenceHandleTypeFlagBits handle_type) {
#ifdef _WIN32
auto ghi = LvlInitStruct<VkFenceGetWin32HandleInfoKHR>();
ghi.fence = handle();
ghi.handleType = handle_type;
auto vkGetFenceWin32HandleKHR = (PFN_vkGetFenceWin32HandleKHR)vk::GetDeviceProcAddr(device(), "vkGetFenceWin32HandleKHR");
return vkGetFenceWin32HandleKHR(device(), &ghi, &ext_handle);
#else
auto gfi = LvlInitStruct<VkFenceGetFdInfoKHR>();
gfi.fence = handle();
gfi.handleType = handle_type;
auto vkGetFenceFdKHR = (PFN_vkGetFenceFdKHR)vk::GetDeviceProcAddr(device(), "vkGetFenceFdKHR");
return vkGetFenceFdKHR(device(), &gfi, &ext_handle);
#endif
}
VkResult Fence::import_handle(Fence::ExternalHandle ext_handle, VkExternalFenceHandleTypeFlagBits handle_type,
VkFenceImportFlags flags) {
#ifdef _WIN32
auto ifi = LvlInitStruct<VkImportFenceWin32HandleInfoKHR>();
ifi.fence = handle();
ifi.handleType = handle_type;
ifi.handle = ext_handle;
ifi.flags = flags;
auto vkImportFenceWin32HandleKHR =
reinterpret_cast<PFN_vkImportFenceWin32HandleKHR>(vk::GetDeviceProcAddr(device(), "vkImportFenceWin32HandleKHR"));
return vkImportFenceWin32HandleKHR(device(), &ifi);
#else
auto ifi = LvlInitStruct<VkImportFenceFdInfoKHR>();
ifi.fence = handle();
ifi.handleType = handle_type;
ifi.fd = ext_handle;
ifi.flags = flags;
auto vkImportFenceFdKHR = reinterpret_cast<PFN_vkImportFenceFdKHR>(vk::GetDeviceProcAddr(device(), "vkImportFenceFdKHR"));
return vkImportFenceFdKHR(device(), &ifi);
#endif
}
NON_DISPATCHABLE_HANDLE_DTOR(Semaphore, vk::DestroySemaphore)
void Semaphore::init(const Device &dev, const VkSemaphoreCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateSemaphore, dev, &info);
}
VkResult Semaphore::export_handle(Semaphore::ExternalHandle &ext_handle, VkExternalSemaphoreHandleTypeFlagBits handle_type) {
#ifdef _WIN32
ext_handle = nullptr;
auto ghi = LvlInitStruct<VkSemaphoreGetWin32HandleInfoKHR>();
ghi.semaphore = handle();
ghi.handleType = handle_type;
auto vkGetSemaphoreWin32HandleKHR =
reinterpret_cast<PFN_vkGetSemaphoreWin32HandleKHR>(vk::GetDeviceProcAddr(device(), "vkGetSemaphoreWin32HandleKHR"));
return vkGetSemaphoreWin32HandleKHR(device(), &ghi, &ext_handle);
#else
ext_handle = -1;
auto ghi = LvlInitStruct<VkSemaphoreGetFdInfoKHR>();
ghi.semaphore = handle();
ghi.handleType = handle_type;
auto vkGetSemaphoreFdKHR = reinterpret_cast<PFN_vkGetSemaphoreFdKHR>(vk::GetDeviceProcAddr(device(), "vkGetSemaphoreFdKHR"));
return vkGetSemaphoreFdKHR(device(), &ghi, &ext_handle);
#endif
}
VkResult Semaphore::import_handle(Semaphore::ExternalHandle ext_handle, VkExternalSemaphoreHandleTypeFlagBits handle_type,
VkSemaphoreImportFlags flags) {
#ifdef _WIN32
auto ihi = LvlInitStruct<VkImportSemaphoreWin32HandleInfoKHR>();
ihi.semaphore = handle();
ihi.handleType = handle_type;
ihi.handle = ext_handle;
ihi.flags = flags;
auto vkImportSemaphoreWin32HandleKHR =
reinterpret_cast<PFN_vkImportSemaphoreWin32HandleKHR>(vk::GetDeviceProcAddr(device(), "vkImportSemaphoreWin32HandleKHR"));
return vkImportSemaphoreWin32HandleKHR(device(), &ihi);
#else
// Import opaque handle exported above
auto ihi = LvlInitStruct<VkImportSemaphoreFdInfoKHR>();
ihi.semaphore = handle();
ihi.handleType = handle_type;
ihi.fd = ext_handle;
ihi.flags = flags;
auto vkImportSemaphoreFdKHR =
reinterpret_cast<PFN_vkImportSemaphoreFdKHR>(vk::GetDeviceProcAddr(device(), "vkImportSemaphoreFdKHR"));
return vkImportSemaphoreFdKHR(device(), &ihi);
#endif
}
NON_DISPATCHABLE_HANDLE_DTOR(Event, vk::DestroyEvent)
void Event::init(const Device &dev, const VkEventCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vk::CreateEvent, dev, &info); }
void Event::set() { EXPECT(vk::SetEvent(device(), handle()) == VK_SUCCESS); }
void Event::cmd_set(const CommandBuffer &cmd, VkPipelineStageFlags stage_mask) {
vk::CmdSetEvent(cmd.handle(), handle(), stage_mask);
}
void Event::cmd_reset(const CommandBuffer &cmd, VkPipelineStageFlags stage_mask) {
vk::CmdResetEvent(cmd.handle(), handle(), stage_mask);
}
void Event::cmd_wait(const CommandBuffer &cmd, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask,
const std::vector<VkMemoryBarrier> &memory_barriers, const std::vector<VkBufferMemoryBarrier> &buffer_barriers,
const std::vector<VkImageMemoryBarrier> &image_barriers) {
VkEvent event_handle = handle();
vk::CmdWaitEvents(cmd.handle(), 1, &event_handle, src_stage_mask, dst_stage_mask, static_cast<uint32_t>(memory_barriers.size()),
memory_barriers.data(), static_cast<uint32_t>(buffer_barriers.size()), buffer_barriers.data(),
static_cast<uint32_t>(image_barriers.size()), image_barriers.data());
}
void Event::reset() { EXPECT(vk::ResetEvent(device(), handle()) == VK_SUCCESS); }
NON_DISPATCHABLE_HANDLE_DTOR(QueryPool, vk::DestroyQueryPool)
void QueryPool::init(const Device &dev, const VkQueryPoolCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateQueryPool, dev, &info);
}
VkResult QueryPool::results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride) {
VkResult err = vk::GetQueryPoolResults(device(), handle(), first, count, size, data, stride, 0);
EXPECT(err == VK_SUCCESS || err == VK_NOT_READY);
return err;
}
NON_DISPATCHABLE_HANDLE_DTOR(Buffer, vk::DestroyBuffer)
void Buffer::init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props, void *alloc_info_pnext) {
init_no_mem(dev, info);
auto alloc_info = DeviceMemory::get_resource_alloc_info(dev, memory_requirements(), mem_props);
alloc_info.pNext = alloc_info_pnext;
internal_mem_.init(dev, alloc_info);
bind_memory(internal_mem_, 0);
}
void Buffer::init_no_mem(const Device &dev, const VkBufferCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateBuffer, dev, &info);
create_info_ = info;
}
VkMemoryRequirements Buffer::memory_requirements() const {
VkMemoryRequirements reqs;
vk::GetBufferMemoryRequirements(device(), handle(), &reqs);
return reqs;
}
void Buffer::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) {
EXPECT(vk::BindBufferMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS);
}
void Buffer::bind_memory(const Device &dev, VkMemoryPropertyFlags mem_props, VkDeviceSize mem_offset) {
if (!internal_mem_.initialized()) {
internal_mem_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements(), mem_props));
}
bind_memory(internal_mem_, mem_offset);
}
NON_DISPATCHABLE_HANDLE_DTOR(BufferView, vk::DestroyBufferView)
void BufferView::init(const Device &dev, const VkBufferViewCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateBufferView, dev, &info);
}
NON_DISPATCHABLE_HANDLE_DTOR(Image, vk::DestroyImage)
void Image::init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props) {
init_no_mem(dev, info);
if (initialized()) {
internal_mem_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements(), mem_props));
bind_memory(internal_mem_, 0);
}
}
void Image::init_no_mem(const Device &dev, const VkImageCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateImage, dev, &info);
if (initialized()) {
init_info(dev, info);
}
}
void Image::init_info(const Device &dev, const VkImageCreateInfo &info) {
create_info_ = info;
for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) {
if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) {
format_features_ = it->features;
break;
}
}
}
VkMemoryRequirements Image::memory_requirements() const {
VkMemoryRequirements reqs;
vk::GetImageMemoryRequirements(device(), handle(), &reqs);
return reqs;
}
void Image::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) {
EXPECT(vk::BindImageMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS);
}
VkSubresourceLayout Image::subresource_layout(const VkImageSubresource &subres) const {
VkSubresourceLayout data;
size_t size = sizeof(data);
vk::GetImageSubresourceLayout(device(), handle(), &subres, &data);
if (size != sizeof(data)) memset(&data, 0, sizeof(data));
return data;
}
VkSubresourceLayout Image::subresource_layout(const VkImageSubresourceLayers &subrescopy) const {
VkSubresourceLayout data;
VkImageSubresource subres = subresource(subrescopy.aspectMask, subrescopy.mipLevel, subrescopy.baseArrayLayer);
size_t size = sizeof(data);
vk::GetImageSubresourceLayout(device(), handle(), &subres, &data);
if (size != sizeof(data)) memset(&data, 0, sizeof(data));
return data;
}
bool Image::transparent() const {
return (create_info_.tiling == VK_IMAGE_TILING_LINEAR && create_info_.samples == VK_SAMPLE_COUNT_1_BIT &&
!(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)));
}
VkImageAspectFlags Image::aspect_mask(VkFormat format) {
VkImageAspectFlags image_aspect;
if (FormatIsDepthAndStencil(format)) {
image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
} else if (FormatIsDepthOnly(format)) {
image_aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
} else if (FormatIsStencilOnly(format)) {
image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT;
} else { // color
image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
}
return image_aspect;
}
NON_DISPATCHABLE_HANDLE_DTOR(ImageView, vk::DestroyImageView)
void ImageView::init(const Device &dev, const VkImageViewCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateImageView, dev, &info);
}
AccelerationStructure::~AccelerationStructure() {
if (initialized()) {
PFN_vkDestroyAccelerationStructureNV vkDestroyAccelerationStructureNV =
(PFN_vkDestroyAccelerationStructureNV)vk::GetDeviceProcAddr(device(), "vkDestroyAccelerationStructureNV");
assert(vkDestroyAccelerationStructureNV != nullptr);
vkDestroyAccelerationStructureNV(device(), handle(), nullptr);
}
}
AccelerationStructureKHR::~AccelerationStructureKHR() {
if (initialized()) {
PFN_vkDestroyAccelerationStructureKHR vkDestroyAccelerationStructureKHR =
(PFN_vkDestroyAccelerationStructureKHR)vk::GetDeviceProcAddr(device(), "vkDestroyAccelerationStructureKHR");
assert(vkDestroyAccelerationStructureKHR != nullptr);
vkDestroyAccelerationStructureKHR(device(), handle(), nullptr);
}
}
VkMemoryRequirements2 AccelerationStructure::memory_requirements() const {
PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV =
(PFN_vkGetAccelerationStructureMemoryRequirementsNV)vk::GetDeviceProcAddr(device(),
"vkGetAccelerationStructureMemoryRequirementsNV");
assert(vkGetAccelerationStructureMemoryRequirementsNV != nullptr);
VkMemoryRequirements2 memoryRequirements = {};
VkAccelerationStructureMemoryRequirementsInfoNV memoryRequirementsInfo =
LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
memoryRequirementsInfo.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
memoryRequirementsInfo.accelerationStructure = handle();
vkGetAccelerationStructureMemoryRequirementsNV(device(), &memoryRequirementsInfo, &memoryRequirements);
return memoryRequirements;
}
VkMemoryRequirements2 AccelerationStructure::build_scratch_memory_requirements() const {
PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV =
(PFN_vkGetAccelerationStructureMemoryRequirementsNV)vk::GetDeviceProcAddr(device(),
"vkGetAccelerationStructureMemoryRequirementsNV");
assert(vkGetAccelerationStructureMemoryRequirementsNV != nullptr);
VkAccelerationStructureMemoryRequirementsInfoNV memoryRequirementsInfo =
LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
memoryRequirementsInfo.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
memoryRequirementsInfo.accelerationStructure = handle();
VkMemoryRequirements2 memoryRequirements = {};
vkGetAccelerationStructureMemoryRequirementsNV(device(), &memoryRequirementsInfo, &memoryRequirements);
return memoryRequirements;
}
void AccelerationStructure::init(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory) {
PFN_vkCreateAccelerationStructureNV vkCreateAccelerationStructureNV =
(PFN_vkCreateAccelerationStructureNV)vk::GetDeviceProcAddr(dev.handle(), "vkCreateAccelerationStructureNV");
assert(vkCreateAccelerationStructureNV != nullptr);
NON_DISPATCHABLE_HANDLE_INIT(vkCreateAccelerationStructureNV, dev, &info);
info_ = info.info;
if (init_memory) {
memory_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements().memoryRequirements,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
PFN_vkBindAccelerationStructureMemoryNV vkBindAccelerationStructureMemoryNV =
(PFN_vkBindAccelerationStructureMemoryNV)vk::GetDeviceProcAddr(dev.handle(), "vkBindAccelerationStructureMemoryNV");
assert(vkBindAccelerationStructureMemoryNV != nullptr);
VkBindAccelerationStructureMemoryInfoNV bind_info = LvlInitStruct<VkBindAccelerationStructureMemoryInfoNV>();
bind_info.accelerationStructure = handle();
bind_info.memory = memory_.handle();
EXPECT(vkBindAccelerationStructureMemoryNV(dev.handle(), 1, &bind_info) == VK_SUCCESS);
PFN_vkGetAccelerationStructureHandleNV vkGetAccelerationStructureHandleNV =
(PFN_vkGetAccelerationStructureHandleNV)vk::GetDeviceProcAddr(dev.handle(), "vkGetAccelerationStructureHandleNV");
assert(vkGetAccelerationStructureHandleNV != nullptr);
EXPECT(vkGetAccelerationStructureHandleNV(dev.handle(), handle(), sizeof(uint64_t), &opaque_handle_) == VK_SUCCESS);
}
}
vk_testing::Buffer AccelerationStructure::create_scratch_buffer(const Device &device, VkBufferCreateInfo *pCreateInfo /*= nullptr*/,
bool buffer_device_address /*= false*/) const {
VkMemoryRequirements scratch_buffer_memory_requirements = build_scratch_memory_requirements().memoryRequirements;
VkBufferCreateInfo create_info = {};
create_info.size = scratch_buffer_memory_requirements.size;
if (pCreateInfo) {
create_info.sType = pCreateInfo->sType;
create_info.usage = pCreateInfo->usage;
} else {
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
create_info.usage = VK_BUFFER_USAGE_RAY_TRACING_BIT_NV;
if (buffer_device_address) create_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
}
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
void *pNext = nullptr;
if (buffer_device_address) {
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
pNext = &alloc_flags;
}
return vk_testing::Buffer(device, create_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, pNext);
}
void AccelerationStructureKHR::init(const Device &dev, const VkAccelerationStructureCreateInfoKHR &info, bool init_memory) {
PFN_vkCreateAccelerationStructureKHR vkCreateAccelerationStructureKHR =
(PFN_vkCreateAccelerationStructureKHR)vk::GetDeviceProcAddr(dev.handle(), "vkCreateAccelerationStructureKHR");
assert(vkCreateAccelerationStructureKHR != nullptr);
NON_DISPATCHABLE_HANDLE_INIT(vkCreateAccelerationStructureKHR, dev, &info);
info_ = info;
}
vk_testing::Buffer AccelerationStructureKHR::create_scratch_buffer(const Device &device,
const VkBufferCreateInfo *pCreateInfo /*= nullptr*/,
bool buffer_device_address /*= false*/) const {
VkBufferCreateInfo create_info = {};
create_info.size = 0;
if (pCreateInfo) {
create_info.sType = pCreateInfo->sType;
create_info.usage = pCreateInfo->usage;
create_info.size = pCreateInfo->size;
} else {
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
create_info.usage = VK_BUFFER_USAGE_RAY_TRACING_BIT_NV;
if (buffer_device_address) create_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
}
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
void *pNext = nullptr;
if (buffer_device_address) {
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
pNext = &alloc_flags;
}
return vk_testing::Buffer(device, create_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, pNext);
}
NON_DISPATCHABLE_HANDLE_DTOR(ShaderModule, vk::DestroyShaderModule)
void ShaderModule::init(const Device &dev, const VkShaderModuleCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateShaderModule, dev, &info);
}
VkResult ShaderModule::init_try(const Device &dev, const VkShaderModuleCreateInfo &info) {
VkShaderModule mod;
VkResult err = vk::CreateShaderModule(dev.handle(), &info, NULL, &mod);
if (err == VK_SUCCESS) NonDispHandle::init(dev.handle(), mod);
return err;
}
NON_DISPATCHABLE_HANDLE_DTOR(Pipeline, vk::DestroyPipeline)
void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info) {
VkPipelineCache cache;
VkPipelineCacheCreateInfo ci = LvlInitStruct<VkPipelineCacheCreateInfo>();
VkResult err = vk::CreatePipelineCache(dev.handle(), &ci, NULL, &cache);
if (err == VK_SUCCESS) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateGraphicsPipelines, dev, cache, 1, &info);
vk::DestroyPipelineCache(dev.handle(), cache, NULL);
}
}
VkResult Pipeline::init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info) {
VkPipeline pipe;
VkPipelineCache cache;
VkPipelineCacheCreateInfo ci = LvlInitStruct<VkPipelineCacheCreateInfo>();
VkResult err = vk::CreatePipelineCache(dev.handle(), &ci, NULL, &cache);
EXPECT(err == VK_SUCCESS);
if (err == VK_SUCCESS) {
err = vk::CreateGraphicsPipelines(dev.handle(), cache, 1, &info, NULL, &pipe);
if (err == VK_SUCCESS) {
NonDispHandle::init(dev.handle(), pipe);
}
vk::DestroyPipelineCache(dev.handle(), cache, NULL);
}
return err;
}
void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info) {
VkPipelineCache cache;
VkPipelineCacheCreateInfo ci = LvlInitStruct<VkPipelineCacheCreateInfo>();
VkResult err = vk::CreatePipelineCache(dev.handle(), &ci, NULL, &cache);
if (err == VK_SUCCESS) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateComputePipelines, dev, cache, 1, &info);
vk::DestroyPipelineCache(dev.handle(), cache, NULL);
}
}
NON_DISPATCHABLE_HANDLE_DTOR(PipelineLayout, vk::DestroyPipelineLayout)
void PipelineLayout::init(const Device &dev, VkPipelineLayoutCreateInfo &info,
const std::vector<const DescriptorSetLayout *> &layouts) {
const std::vector<VkDescriptorSetLayout> layout_handles = MakeVkHandles<VkDescriptorSetLayout>(layouts);
info.setLayoutCount = layout_handles.size();
info.pSetLayouts = layout_handles.data();
init(dev, info);
}
void PipelineLayout::init(const Device &dev, VkPipelineLayoutCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreatePipelineLayout, dev, &info);
}
NON_DISPATCHABLE_HANDLE_DTOR(Sampler, vk::DestroySampler)
void Sampler::init(const Device &dev, const VkSamplerCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateSampler, dev, &info);
}
NON_DISPATCHABLE_HANDLE_DTOR(DescriptorSetLayout, vk::DestroyDescriptorSetLayout)
void DescriptorSetLayout::init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info) {
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateDescriptorSetLayout, dev, &info);
}
NON_DISPATCHABLE_HANDLE_DTOR(DescriptorPool, vk::DestroyDescriptorPool)
void DescriptorPool::init(const Device &dev, const VkDescriptorPoolCreateInfo &info) {
setDynamicUsage(info.flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
NON_DISPATCHABLE_HANDLE_INIT(vk::CreateDescriptorPool, dev, &info);
}
void DescriptorPool::reset() { EXPECT(vk::ResetDescriptorPool(device(), handle(), 0) == VK_SUCCESS); }
std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev,
const std::vector<const DescriptorSetLayout *> &layouts) {
const std::vector<VkDescriptorSetLayout> layout_handles = MakeVkHandles<VkDescriptorSetLayout>(layouts);
std::vector<VkDescriptorSet> set_handles;
set_handles.resize(layout_handles.size());
VkDescriptorSetAllocateInfo alloc_info = LvlInitStruct<VkDescriptorSetAllocateInfo>();
alloc_info.descriptorSetCount = layout_handles.size();
alloc_info.descriptorPool = handle();
alloc_info.pSetLayouts = layout_handles.data();
VkResult err = vk::AllocateDescriptorSets(device(), &alloc_info, set_handles.data());
EXPECT(err == VK_SUCCESS);
std::vector<DescriptorSet *> sets;
for (std::vector<VkDescriptorSet>::const_iterator it = set_handles.begin(); it != set_handles.end(); it++) {
// do descriptor sets need memories bound?
DescriptorSet *descriptorSet = new DescriptorSet(dev, this, *it);