1 /*
2  * Copyright (c) 2015-2016, 2019 The Khronos Group Inc.
3  * Copyright (c) 2015-2016, 2019 Valve Corporation
4  * Copyright (c) 2015-2016, 2019 LunarG, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
19  * Author: Cody Northrop <cody@lunarg.com>
20  * Author: John Zulauf <jzulauf@lunarg.com>
21  */
22 
23 #ifndef VKTESTBINDING_H
24 #define VKTESTBINDING_H
25 
26 #include <algorithm>
27 #include <assert.h>
28 #include <iterator>
29 #include <memory>
30 #include <vector>
31 
32 #include "vulkan/vulkan.h"
33 
34 namespace vk_testing {
35 
36 template <class Dst, class Src>
MakeVkHandles(const std::vector<Src> & v)37 std::vector<Dst> MakeVkHandles(const std::vector<Src> &v) {
38     std::vector<Dst> handles;
39     handles.reserve(v.size());
40     std::transform(v.begin(), v.end(), std::back_inserter(handles), [](const Src &o) { return o.handle(); });
41     return handles;
42 }
43 
44 template <class Dst, class Src>
MakeVkHandles(const std::vector<Src * > & v)45 std::vector<Dst> MakeVkHandles(const std::vector<Src *> &v) {
46     std::vector<Dst> handles;
47     handles.reserve(v.size());
48     std::transform(v.begin(), v.end(), std::back_inserter(handles), [](const Src *o) { return o->handle(); });
49     return handles;
50 }
51 
52 typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function);
53 void set_error_callback(ErrorCallback callback);
54 
55 class PhysicalDevice;
56 class Device;
57 class Queue;
58 class DeviceMemory;
59 class Fence;
60 class Semaphore;
61 class Event;
62 class QueryPool;
63 class Buffer;
64 class BufferView;
65 class Image;
66 class ImageView;
67 class DepthStencilView;
68 class Shader;
69 class Pipeline;
70 class PipelineDelta;
71 class Sampler;
72 class DescriptorSetLayout;
73 class PipelineLayout;
74 class DescriptorSetPool;
75 class DescriptorSet;
76 class CommandBuffer;
77 class CommandPool;
78 
79 std::vector<VkLayerProperties> GetGlobalLayers();
80 std::vector<VkExtensionProperties> GetGlobalExtensions();
81 std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
82 
83 namespace internal {
84 
85 template <typename T>
86 class Handle {
87    public:
handle()88     const T &handle() const { return handle_; }
initialized()89     bool initialized() const { return (handle_ != T{}); }
90 
91    protected:
92     typedef T handle_type;
93 
Handle()94     explicit Handle() : handle_{} {}
Handle(T handle)95     explicit Handle(T handle) : handle_(handle) {}
96 
97     // handles are non-copyable
98     Handle(const Handle &) = delete;
99     Handle &operator=(const Handle &) = delete;
100 
101     // handles can be moved out
Handle(Handle && src)102     Handle(Handle &&src) NOEXCEPT : handle_{src.handle_} { src.handle_ = {}; }
103     Handle &operator=(Handle &&src) NOEXCEPT {
104         handle_ = src.handle_;
105         src.handle_ = {};
106         return *this;
107     }
108 
init(T handle)109     void init(T handle) {
110         assert(!initialized());
111         handle_ = handle;
112     }
113 
114    private:
115     T handle_;
116 };
117 
118 template <typename T>
119 class NonDispHandle : public Handle<T> {
120    protected:
NonDispHandle()121     explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {}
NonDispHandle(VkDevice dev,T handle)122     explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {}
123 
NonDispHandle(NonDispHandle && src)124     NonDispHandle(NonDispHandle &&src) : Handle<T>(std::move(src)) {
125         dev_handle_ = src.dev_handle_;
126         src.dev_handle_ = VK_NULL_HANDLE;
127     }
128     NonDispHandle &operator=(NonDispHandle &&src) {
129         Handle<T>::operator=(std::move(src));
130         dev_handle_ = src.dev_handle_;
131         src.dev_handle_ = VK_NULL_HANDLE;
132         return *this;
133     }
134 
device()135     const VkDevice &device() const { return dev_handle_; }
136 
init(VkDevice dev,T handle)137     void init(VkDevice dev, T handle) {
138         assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE);
139         Handle<T>::init(handle);
140         dev_handle_ = dev;
141     }
142 
143    private:
144     VkDevice dev_handle_;
145 };
146 
147 }  // namespace internal
148 
149 class PhysicalDevice : public internal::Handle<VkPhysicalDevice> {
150    public:
PhysicalDevice(VkPhysicalDevice phy)151     explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy) {
152         memory_properties_ = memory_properties();
153         device_properties_ = properties();
154     }
155 
156     VkPhysicalDeviceProperties properties() const;
157     VkPhysicalDeviceMemoryProperties memory_properties() const;
158     std::vector<VkQueueFamilyProperties> queue_properties() const;
159     VkPhysicalDeviceFeatures features() const;
160 
161     bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkMemoryPropertyFlags properties,
162                          const VkMemoryPropertyFlags forbid = 0) const;
163 
164     // vkEnumerateDeviceExtensionProperties()
165     std::vector<VkExtensionProperties> extensions() const;
166     std::vector<VkExtensionProperties> extensions(const char *pLayerName) const;
167 
168     // vkEnumerateLayers()
169     std::vector<VkLayerProperties> layers() const;
170 
171    private:
172     void add_extension_dependencies(uint32_t dependency_count, VkExtensionProperties *depencency_props,
173                                     std::vector<VkExtensionProperties> &ext_list);
174 
175     VkPhysicalDeviceMemoryProperties memory_properties_;
176 
177     VkPhysicalDeviceProperties device_properties_;
178 };
179 
180 class QueueCreateInfoArray {
181    private:
182     std::vector<VkDeviceQueueCreateInfo> queue_info_;
183     std::vector<std::vector<float>> queue_priorities_;
184 
185    public:
186     QueueCreateInfoArray(const std::vector<VkQueueFamilyProperties> &queue_props);
size()187     size_t size() const { return queue_info_.size(); }
data()188     const VkDeviceQueueCreateInfo *data() const { return queue_info_.data(); }
189 };
190 
191 class Device : public internal::Handle<VkDevice> {
192    public:
Device(VkPhysicalDevice phy)193     explicit Device(VkPhysicalDevice phy) : phy_(phy) {}
194     ~Device();
195 
196     // vkCreateDevice()
197     void init(const VkDeviceCreateInfo &info);
198     void init(std::vector<const char *> &extensions, VkPhysicalDeviceFeatures *features = nullptr,
199               void *create_device_pnext = nullptr);  // all queues, all extensions, etc
init()200     void init() {
201         std::vector<const char *> extensions;
202         init(extensions);
203     };
204 
phy()205     const PhysicalDevice &phy() const { return phy_; }
206 
GetEnabledExtensions()207     std::vector<const char *> GetEnabledExtensions() { return enabled_extensions_; }
208     bool IsEnabledExtension(const char *extension);
209 
210     // vkGetDeviceProcAddr()
get_proc(const char * name)211     PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); }
212 
213     // vkGetDeviceQueue()
graphics_queues()214     const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
compute_queues()215     const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
dma_queues()216     const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
217 
218     typedef std::vector<std::unique_ptr<Queue>> QueueFamilyQueues;
219     typedef std::vector<QueueFamilyQueues> QueueFamilies;
220     const QueueFamilyQueues &queue_family_queues(uint32_t queue_family) const;
221 
222     uint32_t graphics_queue_node_index_;
223 
224     struct Format {
225         VkFormat format;
226         VkImageTiling tiling;
227         VkFlags features;
228     };
229     // vkGetFormatInfo()
230     VkFormatProperties format_properties(VkFormat format);
formats()231     const std::vector<Format> &formats() const { return formats_; }
232 
233     // vkDeviceWaitIdle()
234     void wait();
235 
236     // vkWaitForFences()
237     VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
wait(const Fence & fence)238     VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t)-1); }
239 
240     // vkUpdateDescriptorSets()
241     void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
update_descriptor_sets(const std::vector<VkWriteDescriptorSet> & writes)242     void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) {
243         return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>());
244     }
245 
246     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
247                                                      VkDescriptorType type, uint32_t count,
248                                                      const VkDescriptorImageInfo *image_info);
249     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
250                                                      VkDescriptorType type, uint32_t count,
251                                                      const VkDescriptorBufferInfo *buffer_info);
252     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
253                                                      VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views);
254     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
255                                                      VkDescriptorType type, const std::vector<VkDescriptorImageInfo> &image_info);
256     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
257                                                      VkDescriptorType type, const std::vector<VkDescriptorBufferInfo> &buffer_info);
258     static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
259                                                      VkDescriptorType type, const std::vector<VkBufferView> &buffer_views);
260 
261     static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
262                                                    const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
263                                                    uint32_t count);
264 
265    private:
266     enum QueueIndex {
267         GRAPHICS,
268         COMPUTE,
269         DMA,
270         QUEUE_COUNT,
271     };
272 
273     void init_queues();
274     void init_formats();
275 
276     PhysicalDevice phy_;
277 
278     std::vector<const char *> enabled_extensions_;
279 
280     QueueFamilies queue_families_;
281     std::vector<Queue *> queues_[QUEUE_COUNT];
282     std::vector<Format> formats_;
283 };
284 
285 class Queue : public internal::Handle<VkQueue> {
286    public:
Queue(VkQueue queue,int index)287     explicit Queue(VkQueue queue, int index) : Handle(queue) { family_index_ = index; }
288 
289     // vkQueueSubmit()
290     VkResult submit(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success = true);
291     VkResult submit(const CommandBuffer &cmd, const Fence &fence, bool expect_success = true);
292     VkResult submit(const CommandBuffer &cmd, bool expect_success = true);
293 
294     // vkQueueWaitIdle()
295     VkResult wait();
296 
get_family_index()297     int get_family_index() { return family_index_; }
298 
299    private:
300     int family_index_;
301 };
302 
303 class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> {
304    public:
305     ~DeviceMemory();
306 
307     // vkAllocateMemory()
308     void init(const Device &dev, const VkMemoryAllocateInfo &info);
309 
310     // vkMapMemory()
311     const void *map(VkFlags flags) const;
312     void *map(VkFlags flags);
map()313     const void *map() const { return map(0); }
map()314     void *map() { return map(0); }
315 
316     // vkUnmapMemory()
317     void unmap() const;
318 
319     static VkMemoryAllocateInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index);
320     static VkMemoryAllocateInfo get_resource_alloc_info(const vk_testing::Device &dev, const VkMemoryRequirements &reqs,
321                                                         VkMemoryPropertyFlags mem_props);
322 };
323 
324 class Fence : public internal::NonDispHandle<VkFence> {
325    public:
326     ~Fence();
327 
328     // vkCreateFence()
329     void init(const Device &dev, const VkFenceCreateInfo &info);
330 
331     // vkGetFenceStatus()
status()332     VkResult status() const { return vkGetFenceStatus(device(), handle()); }
333     VkResult wait(VkBool32 wait_all, uint64_t timeout) const;
334 
335     static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
336     static VkFenceCreateInfo create_info();
337 };
338 
339 class Semaphore : public internal::NonDispHandle<VkSemaphore> {
340    public:
341     ~Semaphore();
342 
343     // vkCreateSemaphore()
344     void init(const Device &dev, const VkSemaphoreCreateInfo &info);
345 
346     static VkSemaphoreCreateInfo create_info(VkFlags flags);
347 };
348 
349 class Event : public internal::NonDispHandle<VkEvent> {
350    public:
351     ~Event();
352 
353     // vkCreateEvent()
354     void init(const Device &dev, const VkEventCreateInfo &info);
355 
356     // vkGetEventStatus()
357     // vkSetEvent()
358     // vkResetEvent()
status()359     VkResult status() const { return vkGetEventStatus(device(), handle()); }
360     void set();
361     void reset();
362 
363     static VkEventCreateInfo create_info(VkFlags flags);
364 };
365 
366 class QueryPool : public internal::NonDispHandle<VkQueryPool> {
367    public:
368     ~QueryPool();
369 
370     // vkCreateQueryPool()
371     void init(const Device &dev, const VkQueryPoolCreateInfo &info);
372 
373     // vkGetQueryPoolResults()
374     VkResult results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride);
375 
376     static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
377 };
378 
379 class Buffer : public internal::NonDispHandle<VkBuffer> {
380    public:
Buffer()381     explicit Buffer() : NonDispHandle() {}
Buffer(const Device & dev,const VkBufferCreateInfo & info)382     explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Buffer(const Device & dev,VkDeviceSize size)383     explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
384 
385     ~Buffer();
386 
387     // vkCreateBuffer()
388     void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props);
init(const Device & dev,const VkBufferCreateInfo & info)389     void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); }
390     void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props,
391               VkBufferUsageFlags usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, const std::vector<uint32_t> &queue_families = {}) {
392         init(dev, create_info(size, usage, &queue_families), mem_props);
393     }
init(const Device & dev,VkDeviceSize size)394     void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); }
395     void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs,
396                      const std::vector<uint32_t> *queue_families = nullptr) {
397         init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, queue_families), reqs);
398     }
399     void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs,
400                      const std::vector<uint32_t> *queue_families = nullptr) {
401         init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families), reqs);
402     }
403     void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs,
404                              const std::vector<uint32_t> *queue_families = nullptr, bool memory = true) {
405         if (memory)
406             init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families), reqs);
407         else
408             init_no_mem(dev,
409                         create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families));
410     }
411     void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
412 
413     // get the internal memory
memory()414     const DeviceMemory &memory() const { return internal_mem_; }
memory()415     DeviceMemory &memory() { return internal_mem_; }
416 
417     // vkGetObjectMemoryRequirements()
418     VkMemoryRequirements memory_requirements() const;
419 
420     // vkBindObjectMemory()
421     void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
422 
create_info()423     const VkBufferCreateInfo &create_info() const { return create_info_; }
424     static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage, const std::vector<uint32_t> *queue_families = nullptr);
425 
buffer_memory_barrier(VkFlags output_mask,VkFlags input_mask,VkDeviceSize offset,VkDeviceSize size)426     VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkDeviceSize offset,
427                                                 VkDeviceSize size) const {
428         VkBufferMemoryBarrier barrier = {};
429         barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
430         barrier.buffer = handle();
431         barrier.srcAccessMask = output_mask;
432         barrier.dstAccessMask = input_mask;
433         barrier.offset = offset;
434         barrier.size = size;
435         if (create_info_.sharingMode == VK_SHARING_MODE_CONCURRENT) {
436             barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
437             barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
438         }
439         return barrier;
440     }
441 
442    private:
443     VkBufferCreateInfo create_info_;
444 
445     DeviceMemory internal_mem_;
446 };
447 
448 class BufferView : public internal::NonDispHandle<VkBufferView> {
449    public:
450     ~BufferView();
451 
452     // vkCreateBufferView()
453     void init(const Device &dev, const VkBufferViewCreateInfo &info);
454     static VkBufferViewCreateInfo createInfo(VkBuffer buffer, VkFormat format, VkDeviceSize offset = 0,
455                                              VkDeviceSize range = VK_WHOLE_SIZE);
456 };
457 
createInfo(VkBuffer buffer,VkFormat format,VkDeviceSize offset,VkDeviceSize range)458 inline VkBufferViewCreateInfo BufferView::createInfo(VkBuffer buffer, VkFormat format, VkDeviceSize offset, VkDeviceSize range) {
459     VkBufferViewCreateInfo info = {};
460     info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
461     info.pNext = nullptr;
462     info.flags = VkFlags(0);
463     info.buffer = buffer;
464     info.format = format;
465     info.offset = offset;
466     info.range = range;
467     return info;
468 }
469 
470 class Image : public internal::NonDispHandle<VkImage> {
471    public:
Image()472     explicit Image() : NonDispHandle(), format_features_(0) {}
Image(const Device & dev,const VkImageCreateInfo & info)473     explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
474 
475     ~Image();
476 
477     // vkCreateImage()
478     void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props);
init(const Device & dev,const VkImageCreateInfo & info)479     void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); }
480     void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
481 
482     // get the internal memory
memory()483     const DeviceMemory &memory() const { return internal_mem_; }
memory()484     DeviceMemory &memory() { return internal_mem_; }
485 
486     // vkGetObjectMemoryRequirements()
487     VkMemoryRequirements memory_requirements() const;
488 
489     // vkBindObjectMemory()
490     void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
491 
492     // vkGetImageSubresourceLayout()
493     VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
494     VkSubresourceLayout subresource_layout(const VkImageSubresourceLayers &subres) const;
495 
496     bool transparent() const;
copyable()497     bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
498 
subresource_range(VkImageAspectFlags aspect)499     VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect) const { return subresource_range(create_info_, aspect); }
extent()500     VkExtent3D extent() const { return create_info_.extent; }
extent(uint32_t mip_level)501     VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
format()502     VkFormat format() const { return create_info_.format; }
usage()503     VkImageUsageFlags usage() const { return create_info_.usage; }
sharing_mode()504     VkSharingMode sharing_mode() const { return create_info_.sharingMode; }
505     VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkImageLayout old_layout,
506                                               VkImageLayout new_layout, const VkImageSubresourceRange &range,
507                                               uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
508                                               uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED) const {
509         VkImageMemoryBarrier barrier = {};
510         barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
511         barrier.srcAccessMask = output_mask;
512         barrier.dstAccessMask = input_mask;
513         barrier.oldLayout = old_layout;
514         barrier.newLayout = new_layout;
515         barrier.image = handle();
516         barrier.subresourceRange = range;
517         barrier.srcQueueFamilyIndex = srcQueueFamilyIndex;
518         barrier.dstQueueFamilyIndex = dstQueueFamilyIndex;
519         return barrier;
520     }
521 
522     static VkImageCreateInfo create_info();
523     static VkImageSubresource subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer);
524     static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer);
525     static VkImageSubresourceLayers subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer,
526                                                 uint32_t array_size);
527     static VkImageSubresourceLayers subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer,
528                                                 uint32_t array_size);
529     static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels,
530                                                      uint32_t base_array_layer, uint32_t num_layers);
531     static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask);
532     static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
533 
534     static VkExtent2D extent(int32_t width, int32_t height);
535     static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
536     static VkExtent2D extent(const VkExtent3D &extent);
537 
538     static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
539     static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
540 
541    private:
542     void init_info(const Device &dev, const VkImageCreateInfo &info);
543 
544     VkImageCreateInfo create_info_;
545     VkFlags format_features_;
546 
547     DeviceMemory internal_mem_;
548 };
549 
550 class ImageView : public internal::NonDispHandle<VkImageView> {
551    public:
552     ~ImageView();
553 
554     // vkCreateImageView()
555     void init(const Device &dev, const VkImageViewCreateInfo &info);
556 };
557 
558 class AccelerationStructure : public internal::NonDispHandle<VkAccelerationStructureNV> {
559    public:
560     explicit AccelerationStructure(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory = true) {
561         init(dev, info, init_memory);
562     }
563     ~AccelerationStructure();
564 
565     // vkCreateAccelerationStructureNV
566     void init(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory = true);
567 
568     // vkGetAccelerationStructureMemoryRequirementsNV()
569     VkMemoryRequirements2 memory_requirements() const;
570     VkMemoryRequirements2 build_scratch_memory_requirements() const;
571 
opaque_handle()572     uint64_t opaque_handle() const { return opaque_handle_; }
573 
info()574     const VkAccelerationStructureInfoNV &info() const { return info_; }
575 
dev()576     const VkDevice &dev() const { return device(); }
577 
578     void create_scratch_buffer(const Device &dev, Buffer *buffer);
579 
580    private:
581     VkAccelerationStructureInfoNV info_;
582     DeviceMemory memory_;
583     uint64_t opaque_handle_;
584 };
585 
586 class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
587    public:
588     ~ShaderModule();
589 
590     // vkCreateShaderModule()
591     void init(const Device &dev, const VkShaderModuleCreateInfo &info);
592     VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
593 
594     static VkShaderModuleCreateInfo create_info(size_t code_size, const uint32_t *code, VkFlags flags);
595 };
596 
597 class Pipeline : public internal::NonDispHandle<VkPipeline> {
598    public:
599     ~Pipeline();
600 
601     // vkCreateGraphicsPipeline()
602     void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
603     // vkCreateGraphicsPipelineDerivative()
604     void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
605     // vkCreateComputePipeline()
606     void init(const Device &dev, const VkComputePipelineCreateInfo &info);
607     // vkLoadPipeline()
608     void init(const Device &dev, size_t size, const void *data);
609     // vkLoadPipelineDerivative()
610     void init(const Device &dev, size_t size, const void *data, VkPipeline basePipeline);
611 
612     // vkCreateGraphicsPipeline with error return
613     VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
614 
615     // vkStorePipeline()
616     size_t store(size_t size, void *data);
617 };
618 
619 class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> {
620    public:
PipelineLayout()621     PipelineLayout() NOEXCEPT : NonDispHandle(){};
622     ~PipelineLayout();
623 
624     // Move constructor for Visual Studio 2013
PipelineLayout(PipelineLayout && src)625     PipelineLayout(PipelineLayout &&src) : NonDispHandle(std::move(src)){};
626 
627     PipelineLayout &operator=(PipelineLayout &&src) {
628         this->~PipelineLayout();
629         this->NonDispHandle::operator=(std::move(src));
630         return *this;
631     };
632 
633     // vCreatePipelineLayout()
634     void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
635 };
636 
637 class Sampler : public internal::NonDispHandle<VkSampler> {
638    public:
639     ~Sampler();
640 
641     // vkCreateSampler()
642     void init(const Device &dev, const VkSamplerCreateInfo &info);
643 };
644 
645 class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> {
646    public:
DescriptorSetLayout()647     DescriptorSetLayout() NOEXCEPT : NonDispHandle(){};
648     ~DescriptorSetLayout();
649 
650     // Move constructor for Visual Studio 2013
DescriptorSetLayout(DescriptorSetLayout && src)651     DescriptorSetLayout(DescriptorSetLayout &&src) : NonDispHandle(std::move(src)){};
652 
653     DescriptorSetLayout &operator=(DescriptorSetLayout &&src) NOEXCEPT {
654         this->~DescriptorSetLayout();
655         this->NonDispHandle::operator=(std::move(src));
656         return *this;
657     }
658 
659     // vkCreateDescriptorSetLayout()
660     void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
661 };
662 
663 class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> {
664    public:
665     ~DescriptorPool();
666 
667     // Descriptor sets allocated from this pool will need access to the original
668     // object
GetObj()669     VkDescriptorPool GetObj() { return pool_; }
670 
671     // vkCreateDescriptorPool()
672     void init(const Device &dev, const VkDescriptorPoolCreateInfo &info);
673 
674     // vkResetDescriptorPool()
675     void reset();
676 
677     // vkFreeDescriptorSet()
setDynamicUsage(bool isDynamic)678     void setDynamicUsage(bool isDynamic) { dynamic_usage_ = isDynamic; }
getDynamicUsage()679     bool getDynamicUsage() { return dynamic_usage_; }
680 
681     // vkAllocateDescriptorSets()
682     std::vector<DescriptorSet *> alloc_sets(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts);
683     std::vector<DescriptorSet *> alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count);
684     DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout);
685 
686     template <typename PoolSizes>
687     static VkDescriptorPoolCreateInfo create_info(VkDescriptorPoolCreateFlags flags, uint32_t max_sets,
688                                                   const PoolSizes &pool_sizes);
689 
690    private:
691     VkDescriptorPool pool_;
692 
693     // Track whether this pool's usage is VK_DESCRIPTOR_POOL_USAGE_DYNAMIC
694     bool dynamic_usage_;
695 };
696 
697 template <typename PoolSizes>
create_info(VkDescriptorPoolCreateFlags flags,uint32_t max_sets,const PoolSizes & pool_sizes)698 inline VkDescriptorPoolCreateInfo DescriptorPool::create_info(VkDescriptorPoolCreateFlags flags, uint32_t max_sets,
699                                                               const PoolSizes &pool_sizes) {
700     VkDescriptorPoolCreateInfo info{};
701     info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
702     info.pNext = nullptr;
703     info.flags = flags;
704     info.maxSets = max_sets;
705     info.poolSizeCount = pool_sizes.size();
706     info.pPoolSizes = (info.poolSizeCount) ? pool_sizes.data() : nullptr;
707     return info;
708 }
709 
710 class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> {
711    public:
712     ~DescriptorSet();
713 
DescriptorSet()714     explicit DescriptorSet() : NonDispHandle() {}
DescriptorSet(const Device & dev,DescriptorPool * pool,VkDescriptorSet set)715     explicit DescriptorSet(const Device &dev, DescriptorPool *pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) {
716         containing_pool_ = pool;
717     }
718 
719    private:
720     DescriptorPool *containing_pool_;
721 };
722 
723 class CommandPool : public internal::NonDispHandle<VkCommandPool> {
724    public:
725     ~CommandPool();
726 
CommandPool()727     explicit CommandPool() : NonDispHandle() {}
CommandPool(const Device & dev,const VkCommandPoolCreateInfo & info)728     explicit CommandPool(const Device &dev, const VkCommandPoolCreateInfo &info) { init(dev, info); }
729 
730     void init(const Device &dev, const VkCommandPoolCreateInfo &info);
731 
732     static VkCommandPoolCreateInfo create_info(uint32_t queue_family_index, VkCommandPoolCreateFlags flags);
733 };
734 
create_info(uint32_t queue_family_index,VkCommandPoolCreateFlags flags)735 inline VkCommandPoolCreateInfo CommandPool::create_info(uint32_t queue_family_index, VkCommandPoolCreateFlags flags) {
736     VkCommandPoolCreateInfo info = {};
737     info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
738     info.queueFamilyIndex = queue_family_index;
739     info.flags = flags;
740     return info;
741 }
742 
743 class CommandBuffer : public internal::Handle<VkCommandBuffer> {
744    public:
745     ~CommandBuffer();
746 
CommandBuffer()747     explicit CommandBuffer() : Handle() {}
CommandBuffer(const Device & dev,const VkCommandBufferAllocateInfo & info)748     explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); }
749 
750     // vkAllocateCommandBuffers()
751     void init(const Device &dev, const VkCommandBufferAllocateInfo &info);
752 
753     // vkBeginCommandBuffer()
754     void begin(const VkCommandBufferBeginInfo *info);
755     void begin();
756 
757     // vkEndCommandBuffer()
758     // vkResetCommandBuffer()
759     void end();
760     void reset(VkCommandBufferResetFlags flags);
reset()761     void reset() { reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); }
762 
763     static VkCommandBufferAllocateInfo create_info(VkCommandPool const &pool);
764 
765    private:
766     VkDevice dev_handle_;
767     VkCommandPool cmd_pool_;
768 };
769 
alloc_info(VkDeviceSize size,uint32_t memory_type_index)770 inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) {
771     VkMemoryAllocateInfo info = {};
772     info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
773     info.allocationSize = size;
774     info.memoryTypeIndex = memory_type_index;
775     return info;
776 }
777 
create_info(VkDeviceSize size,VkFlags usage,const std::vector<uint32_t> * queue_families)778 inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage, const std::vector<uint32_t> *queue_families) {
779     VkBufferCreateInfo info = {};
780     info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
781     info.size = size;
782     info.usage = usage;
783 
784     if (queue_families && queue_families->size() > 1) {
785         info.sharingMode = VK_SHARING_MODE_CONCURRENT;
786         info.queueFamilyIndexCount = static_cast<uint32_t>(queue_families->size());
787         info.pQueueFamilyIndices = queue_families->data();
788     }
789 
790     return info;
791 }
792 
create_info(VkFenceCreateFlags flags)793 inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags) {
794     VkFenceCreateInfo info = {};
795     info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
796     info.flags = flags;
797     return info;
798 }
799 
create_info()800 inline VkFenceCreateInfo Fence::create_info() {
801     VkFenceCreateInfo info = {};
802     info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
803     return info;
804 }
805 
create_info(VkFlags flags)806 inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags) {
807     VkSemaphoreCreateInfo info = {};
808     info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
809     info.flags = flags;
810     return info;
811 }
812 
create_info(VkFlags flags)813 inline VkEventCreateInfo Event::create_info(VkFlags flags) {
814     VkEventCreateInfo info = {};
815     info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
816     info.flags = flags;
817     return info;
818 }
819 
create_info(VkQueryType type,uint32_t slot_count)820 inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) {
821     VkQueryPoolCreateInfo info = {};
822     info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
823     info.queryType = type;
824     info.queryCount = slot_count;
825     return info;
826 }
827 
create_info()828 inline VkImageCreateInfo Image::create_info() {
829     VkImageCreateInfo info = {};
830     info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
831     info.extent.width = 1;
832     info.extent.height = 1;
833     info.extent.depth = 1;
834     info.mipLevels = 1;
835     info.arrayLayers = 1;
836     info.samples = VK_SAMPLE_COUNT_1_BIT;
837     return info;
838 }
839 
subresource(VkImageAspectFlags aspect,uint32_t mip_level,uint32_t array_layer)840 inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer) {
841     VkImageSubresource subres = {};
842     if (aspect == 0) {
843         assert(!"Invalid VkImageAspectFlags");
844     }
845     subres.aspectMask = aspect;
846     subres.mipLevel = mip_level;
847     subres.arrayLayer = array_layer;
848     return subres;
849 }
850 
subresource(const VkImageSubresourceRange & range,uint32_t mip_level,uint32_t array_layer)851 inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer) {
852     return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer);
853 }
854 
subresource(VkImageAspectFlags aspect,uint32_t mip_level,uint32_t array_layer,uint32_t array_size)855 inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer,
856                                                    uint32_t array_size) {
857     VkImageSubresourceLayers subres = {};
858     switch (aspect) {
859         case VK_IMAGE_ASPECT_COLOR_BIT:
860         case VK_IMAGE_ASPECT_DEPTH_BIT:
861         case VK_IMAGE_ASPECT_STENCIL_BIT:
862         case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT:
863             /* valid */
864             break;
865         default:
866             assert(!"Invalid VkImageAspectFlags");
867     }
868     subres.aspectMask = aspect;
869     subres.mipLevel = mip_level;
870     subres.baseArrayLayer = array_layer;
871     subres.layerCount = array_size;
872     return subres;
873 }
874 
subresource(const VkImageSubresourceRange & range,uint32_t mip_level,uint32_t array_layer,uint32_t array_size)875 inline VkImageSubresourceLayers Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer,
876                                                    uint32_t array_size) {
877     return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size);
878 }
879 
subresource_range(VkImageAspectFlags aspect_mask,uint32_t base_mip_level,uint32_t mip_levels,uint32_t base_array_layer,uint32_t num_layers)880 inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level,
881                                                         uint32_t mip_levels, uint32_t base_array_layer, uint32_t num_layers) {
882     VkImageSubresourceRange range = {};
883     if (aspect_mask == 0) {
884         assert(!"Invalid VkImageAspectFlags");
885     }
886     range.aspectMask = aspect_mask;
887     range.baseMipLevel = base_mip_level;
888     range.levelCount = mip_levels;
889     range.baseArrayLayer = base_array_layer;
890     range.layerCount = num_layers;
891     return range;
892 }
893 
subresource_range(const VkImageCreateInfo & info,VkImageAspectFlags aspect_mask)894 inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask) {
895     return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers);
896 }
897 
subresource_range(const VkImageSubresource & subres)898 inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) {
899     return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1);
900 }
901 
extent(int32_t width,int32_t height)902 inline VkExtent2D Image::extent(int32_t width, int32_t height) {
903     VkExtent2D extent = {};
904     extent.width = width;
905     extent.height = height;
906     return extent;
907 }
908 
extent(const VkExtent2D & extent,uint32_t mip_level)909 inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) {
910     const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
911     const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
912     return Image::extent(width, height);
913 }
914 
extent(const VkExtent3D & extent)915 inline VkExtent2D Image::extent(const VkExtent3D &extent) { return Image::extent(extent.width, extent.height); }
916 
extent(int32_t width,int32_t height,int32_t depth)917 inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) {
918     VkExtent3D extent = {};
919     extent.width = width;
920     extent.height = height;
921     extent.depth = depth;
922     return extent;
923 }
924 
extent(const VkExtent3D & extent,uint32_t mip_level)925 inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) {
926     const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
927     const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
928     const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
929     return Image::extent(width, height, depth);
930 }
931 
create_info(size_t code_size,const uint32_t * code,VkFlags flags)932 inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags) {
933     VkShaderModuleCreateInfo info = {};
934     info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
935     info.codeSize = code_size;
936     info.pCode = code;
937     info.flags = flags;
938     return info;
939 }
940 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,uint32_t count,const VkDescriptorImageInfo * image_info)941 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
942                                                          VkDescriptorType type, uint32_t count,
943                                                          const VkDescriptorImageInfo *image_info) {
944     VkWriteDescriptorSet write = {};
945     write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
946     write.dstSet = set.handle();
947     write.dstBinding = binding;
948     write.dstArrayElement = array_element;
949     write.descriptorCount = count;
950     write.descriptorType = type;
951     write.pImageInfo = image_info;
952     return write;
953 }
954 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,uint32_t count,const VkDescriptorBufferInfo * buffer_info)955 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
956                                                          VkDescriptorType type, uint32_t count,
957                                                          const VkDescriptorBufferInfo *buffer_info) {
958     VkWriteDescriptorSet write = {};
959     write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
960     write.dstSet = set.handle();
961     write.dstBinding = binding;
962     write.dstArrayElement = array_element;
963     write.descriptorCount = count;
964     write.descriptorType = type;
965     write.pBufferInfo = buffer_info;
966     return write;
967 }
968 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,uint32_t count,const VkBufferView * buffer_views)969 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
970                                                          VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views) {
971     VkWriteDescriptorSet write = {};
972     write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
973     write.dstSet = set.handle();
974     write.dstBinding = binding;
975     write.dstArrayElement = array_element;
976     write.descriptorCount = count;
977     write.descriptorType = type;
978     write.pTexelBufferView = buffer_views;
979     return write;
980 }
981 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,const std::vector<VkDescriptorImageInfo> & image_info)982 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
983                                                          VkDescriptorType type,
984                                                          const std::vector<VkDescriptorImageInfo> &image_info) {
985     return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]);
986 }
987 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,const std::vector<VkDescriptorBufferInfo> & buffer_info)988 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
989                                                          VkDescriptorType type,
990                                                          const std::vector<VkDescriptorBufferInfo> &buffer_info) {
991     return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]);
992 }
993 
write_descriptor_set(const DescriptorSet & set,uint32_t binding,uint32_t array_element,VkDescriptorType type,const std::vector<VkBufferView> & buffer_views)994 inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
995                                                          VkDescriptorType type, const std::vector<VkBufferView> &buffer_views) {
996     return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]);
997 }
998 
copy_descriptor_set(const DescriptorSet & src_set,uint32_t src_binding,uint32_t src_array_element,const DescriptorSet & dst_set,uint32_t dst_binding,uint32_t dst_array_element,uint32_t count)999 inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding,
1000                                                        uint32_t src_array_element, const DescriptorSet &dst_set,
1001                                                        uint32_t dst_binding, uint32_t dst_array_element, uint32_t count) {
1002     VkCopyDescriptorSet copy = {};
1003     copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
1004     copy.srcSet = src_set.handle();
1005     copy.srcBinding = src_binding;
1006     copy.srcArrayElement = src_array_element;
1007     copy.dstSet = dst_set.handle();
1008     copy.dstBinding = dst_binding;
1009     copy.dstArrayElement = dst_array_element;
1010     copy.descriptorCount = count;
1011 
1012     return copy;
1013 }
1014 
create_info(VkCommandPool const & pool)1015 inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool) {
1016     VkCommandBufferAllocateInfo info = {};
1017     info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1018     info.commandPool = pool;
1019     info.commandBufferCount = 1;
1020     return info;
1021 }
1022 
1023 }  // namespace vk_testing
1024 
1025 #endif  // VKTESTBINDING_H
1026