blob: 7cc7c5b406d43dcce8ce3b13d4ac5a0dfc54b474 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06002// Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060021//
22// Author: Cody Northrop <cody@lunarg.com>
23// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060024
25#ifndef VKTESTBINDING_H
26#define VKTESTBINDING_H
27
28#include <vector>
Chia-I Wub0ed7d42015-07-03 10:13:26 +080029#include <assert.h>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060030
David Pinedo9316d3b2015-11-06 12:54:48 -070031#include "vulkan/vulkan.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060032
33namespace vk_testing {
34
35typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function);
36void set_error_callback(ErrorCallback callback);
37
Chia-I Wu999f0482015-07-03 10:32:05 +080038class PhysicalDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039class Device;
40class Queue;
Chia-I Wuf8f074f2015-07-03 10:58:57 +080041class DeviceMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060042class Fence;
43class Semaphore;
44class Event;
45class QueryPool;
46class Buffer;
47class BufferView;
48class Image;
49class ImageView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060050class DepthStencilView;
51class Shader;
52class Pipeline;
53class PipelineDelta;
54class Sampler;
55class DescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -050056class PipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060057class DescriptorSetPool;
58class DescriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080059class CommandBuffer;
60class CommandPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060061
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060062std::vector<VkLayerProperties> GetGlobalLayers();
63std::vector<VkExtensionProperties> GetGlobalExtensions();
64std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
65
Chia-I Wub0ed7d42015-07-03 10:13:26 +080066namespace internal {
67
68template<typename T>
69class Handle {
70public:
71 const T &handle() const { return handle_; }
72 bool initialized() const { return (handle_ != VK_NULL_HANDLE); }
73
74protected:
75 typedef T handle_type;
76
77 explicit Handle() : handle_(VK_NULL_HANDLE) {}
78 explicit Handle(T handle) : handle_(handle) {}
79
80 void init(T handle)
81 {
82 assert(!initialized());
83 handle_ = handle;
84 }
85
86private:
87 // handles are non-copyable
88 Handle(const Handle &);
89 Handle &operator=(const Handle &);
90
91 T handle_;
92};
93
94
95template<typename T>
96class NonDispHandle : public Handle<T> {
97protected:
98 explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {}
99 explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {}
100
101 const VkDevice &device() const { return dev_handle_; }
102
103 void init(VkDevice dev, T handle)
104 {
105 assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE);
106 Handle<T>::init(handle);
107 dev_handle_ = dev;
108 }
109
110private:
111 VkDevice dev_handle_;
112};
113
114} // namespace internal
115
Chia-I Wu999f0482015-07-03 10:32:05 +0800116class PhysicalDevice : public internal::Handle<VkPhysicalDevice> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600117public:
Chia-I Wu999f0482015-07-03 10:32:05 +0800118 explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy)
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600119 {
120 memory_properties_ = memory_properties();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600121 device_properties_ = properties();
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600122 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600123
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600124
Tony Barbourd1c35722015-04-16 15:59:00 -0600125 VkPhysicalDeviceProperties properties() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600126 VkPhysicalDeviceMemoryProperties memory_properties() const;
Cody Northropd0802882015-08-03 17:04:53 -0600127 std::vector<VkQueueFamilyProperties> queue_properties() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600128
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800129 bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkMemoryPropertyFlags properties,
Mike Stroyan713b2d72015-08-04 10:49:29 -0600130 const VkMemoryPropertyFlags forbid = 0) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600132 // vkEnumerateDeviceExtensionProperties()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600133 std::vector<VkExtensionProperties> extensions() const;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600134 std::vector<VkExtensionProperties> extensions(const char * pLayerName) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600135
136 // vkEnumerateLayers()
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600137 std::vector<VkLayerProperties> layers() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600138
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600139private:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600140 void add_extension_dependencies(uint32_t dependency_count,
141 VkExtensionProperties *depencency_props,
142 std::vector<VkExtensionProperties> &ext_list);
Chia-I Wu999f0482015-07-03 10:32:05 +0800143
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600144 VkPhysicalDeviceMemoryProperties memory_properties_;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600145
146 VkPhysicalDeviceProperties device_properties_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600147};
148
Chia-I Wuf368b602015-07-03 10:41:20 +0800149class Device : public internal::Handle<VkDevice> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600150public:
Chia-I Wu999f0482015-07-03 10:32:05 +0800151 explicit Device(VkPhysicalDevice phy) : phy_(phy) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600152 ~Device();
153
154 // vkCreateDevice()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600155 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600156 void init(std::vector<const char*> &layers, std::vector<const char *> &extensions); // all queues, all extensions, etc
157 void init() { std::vector<const char *> layers; std::vector<const char *> extensions; init(layers, extensions); };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600158
Chia-I Wu999f0482015-07-03 10:32:05 +0800159 const PhysicalDevice &phy() const { return phy_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600160
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600161 // vkGetDeviceProcAddr()
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600162 PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); }
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600163
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600164 // vkGetDeviceQueue()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500165 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600166 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
167 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
168 uint32_t graphics_queue_node_index_;
169
170 struct Format {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600171 VkFormat format;
172 VkImageTiling tiling;
173 VkFlags features;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600174 };
175 // vkGetFormatInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600176 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600177 const std::vector<Format> &formats() const { return formats_; }
178
179 // vkDeviceWaitIdle()
180 void wait();
181
182 // vkWaitForFences()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600183 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
184 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600185
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800186 // vkUpdateDescriptorSets()
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600187 void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
188 void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800189
190 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600191 VkDescriptorType type, uint32_t count, const VkDescriptorImageInfo *image_info);
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800192 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600193 VkDescriptorType type, uint32_t count, const VkDescriptorBufferInfo *buffer_info);
194 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
195 VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views);
196 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
197 VkDescriptorType type, const std::vector<VkDescriptorImageInfo> &image_info);
198 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
199 VkDescriptorType type, const std::vector<VkDescriptorBufferInfo> &buffer_info);
200 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
201 VkDescriptorType type, const std::vector<VkBufferView> &buffer_views);
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800202
203 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
204 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
205 uint32_t count);
206
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600207private:
208 enum QueueIndex {
209 GRAPHICS,
210 COMPUTE,
211 DMA,
212 QUEUE_COUNT,
213 };
214
215 void init_queues();
216 void init_formats();
217
Chia-I Wu999f0482015-07-03 10:32:05 +0800218 PhysicalDevice phy_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219
220 std::vector<Queue *> queues_[QUEUE_COUNT];
221 std::vector<Format> formats_;
222};
223
Chia-I Wudf12ffd2015-07-03 10:53:18 +0800224class Queue : public internal::Handle<VkQueue> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600225public:
Tony Barbourfb21ea32015-07-23 10:35:30 -0600226 explicit Queue(VkQueue queue, int index) : Handle(queue) {family_index_ = index;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600227
228 // vkQueueSubmit()
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800229 void submit(const std::vector<const CommandBuffer *> &cmds, Fence &fence);
230 void submit(const CommandBuffer &cmd, Fence &fence);
231 void submit(const CommandBuffer &cmd);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600232
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600233 // vkQueueWaitIdle()
234 void wait();
235
Tony Barbourfb21ea32015-07-23 10:35:30 -0600236 int get_family_index() {return family_index_;}
237
238private:
239 int family_index_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240};
241
Chia-I Wuf8f074f2015-07-03 10:58:57 +0800242class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600243public:
Chia-I Wuf8f074f2015-07-03 10:58:57 +0800244 ~DeviceMemory();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600245
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800246 // vkAllocateMemory()
247 void init(const Device &dev, const VkMemoryAllocateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600248
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600249 // vkMapMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 const void *map(VkFlags flags) const;
251 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600252 const void *map() const { return map(0); }
253 void *map() { return map(0); }
254
255 // vkUnmapMemory()
256 void unmap() const;
257
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800258 static VkMemoryAllocateInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259};
260
Chia-I Wud9e8e822015-07-03 11:45:55 +0800261class Fence : public internal::NonDispHandle<VkFence> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600262public:
Chia-I Wud9e8e822015-07-03 11:45:55 +0800263 ~Fence();
264
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600265 // vkCreateFence()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600267
268 // vkGetFenceStatus()
Chia-I Wud9e8e822015-07-03 11:45:55 +0800269 VkResult status() const { return vkGetFenceStatus(device(), handle()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600270
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
272 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600273};
274
Chia-I Wu6b1c2482015-07-03 11:49:42 +0800275class Semaphore : public internal::NonDispHandle<VkSemaphore> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600276public:
Chia-I Wu6b1c2482015-07-03 11:49:42 +0800277 ~Semaphore();
278
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600279 // vkCreateSemaphore()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600280 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281
Tony Barbouraf892a12015-06-26 12:56:09 -0600282 static VkSemaphoreCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600283};
284
Chia-I Wuc5c97992015-07-03 11:49:42 +0800285class Event : public internal::NonDispHandle<VkEvent> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600286public:
Chia-I Wuc5c97992015-07-03 11:49:42 +0800287 ~Event();
288
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600289 // vkCreateEvent()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600290 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600291
292 // vkGetEventStatus()
293 // vkSetEvent()
294 // vkResetEvent()
Chia-I Wuc5c97992015-07-03 11:49:42 +0800295 VkResult status() const { return vkGetEventStatus(device(), handle()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600296 void set();
297 void reset();
298
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600299 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600300};
301
Chia-I Wu1b7d4762015-07-03 11:49:42 +0800302class QueryPool : public internal::NonDispHandle<VkQueryPool> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600303public:
Chia-I Wu1b7d4762015-07-03 11:49:42 +0800304 ~QueryPool();
305
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600306 // vkCreateQueryPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600307 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308
309 // vkGetQueryPoolResults()
Chia-I Wuccc93a72015-10-26 18:36:20 +0800310 VkResult results(uint32_t start, uint32_t count, size_t size, void *data, size_t stride);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600312 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313};
314
Chia-I Wu681d7a02015-07-03 13:44:34 +0800315class Buffer : public internal::NonDispHandle<VkBuffer> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600316public:
Chia-I Wu681d7a02015-07-03 13:44:34 +0800317 explicit Buffer() : NonDispHandle() {}
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600318 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbourd1c35722015-04-16 15:59:00 -0600319 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600320
Chia-I Wu681d7a02015-07-03 13:44:34 +0800321 ~Buffer();
322
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600323 // vkCreateBuffer()
Chia-I Wu681d7a02015-07-03 13:44:34 +0800324 void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props);
325 void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); }
326 void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props) { init(dev, create_info(size, 0), mem_props); }
327 void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT), reqs); }
329 void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs); }
330 void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs); }
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600331 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600332
Chia-I Wu681d7a02015-07-03 13:44:34 +0800333 // get the internal memory
334 const DeviceMemory &memory() const { return internal_mem_; }
335 DeviceMemory &memory() { return internal_mem_; }
336
337 // vkGetObjectMemoryRequirements()
338 VkMemoryRequirements memory_requirements() const;
339
340 // vkBindObjectMemory()
341 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500342
Tony Barbourd1c35722015-04-16 15:59:00 -0600343 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600344
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600345 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbourd1c35722015-04-16 15:59:00 -0600346 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600347 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600348 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600349 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800350 barrier.buffer = handle();
Chia-I Wua4594202015-10-27 19:54:37 +0800351 barrier.srcAccessMask = output_mask;
352 barrier.dstAccessMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600353 barrier.offset = offset;
354 barrier.size = size;
355 return barrier;
356 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800357
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600358private:
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600359 VkBufferCreateInfo create_info_;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800360
361 DeviceMemory internal_mem_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600362};
363
Chia-I Wu3158bf32015-07-03 11:49:42 +0800364class BufferView : public internal::NonDispHandle<VkBufferView> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365public:
Chia-I Wu3158bf32015-07-03 11:49:42 +0800366 ~BufferView();
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 // vkCreateBufferView()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600369 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600370};
371
Chia-I Wu681d7a02015-07-03 13:44:34 +0800372class Image : public internal::NonDispHandle<VkImage> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600373public:
Chia-I Wu681d7a02015-07-03 13:44:34 +0800374 explicit Image() : NonDispHandle(), format_features_(0) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600375 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600376
Chia-I Wu681d7a02015-07-03 13:44:34 +0800377 ~Image();
378
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600379 // vkCreateImage()
Chia-I Wu681d7a02015-07-03 13:44:34 +0800380 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props);
381 void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600382 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600383
Chia-I Wu681d7a02015-07-03 13:44:34 +0800384 // get the internal memory
385 const DeviceMemory &memory() const { return internal_mem_; }
386 DeviceMemory &memory() { return internal_mem_; }
387
388 // vkGetObjectMemoryRequirements()
389 VkMemoryRequirements memory_requirements() const;
390
391 // vkBindObjectMemory()
392 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600393
Tony Barbour59a47322015-06-24 16:06:58 -0600394 // vkGetImageSubresourceLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600395 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800396 VkSubresourceLayout subresource_layout(const VkImageSubresourceLayers &subres) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600397
398 bool transparent() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600399 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600400
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600401 VkImageSubresourceRange subresource_range(VkImageAspectFlagBits aspect) const { return subresource_range(create_info_, aspect); }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600402 VkExtent3D extent() const { return create_info_.extent; }
403 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
404 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600405
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
407 VkImageLayout old_layout,
408 VkImageLayout new_layout,
409 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600410 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600411 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600412 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Chia-I Wua4594202015-10-27 19:54:37 +0800413 barrier.srcAccessMask = output_mask;
414 barrier.dstAccessMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600415 barrier.oldLayout = old_layout;
416 barrier.newLayout = new_layout;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800417 barrier.image = handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 barrier.subresourceRange = range;
419 return barrier;
420 }
421
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600422 static VkImageCreateInfo create_info();
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600423 static VkImageAspectFlagBits image_aspect(VkImageAspectFlags flags);
424 static VkImageSubresource subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer);
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600425 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer);
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800426 static VkImageSubresourceLayers subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size);
427 static VkImageSubresourceLayers subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, uint32_t array_size);
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600428 static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600429 uint32_t base_array_layer, uint32_t num_layers);
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600430 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600431 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600432
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600433 static VkExtent2D extent(int32_t width, int32_t height);
434 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
435 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600436
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600437 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
438 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600439
440private:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600441 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600442
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600443 VkImageCreateInfo create_info_;
444 VkFlags format_features_;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800445
446 DeviceMemory internal_mem_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447};
448
Chia-I Wu3158bf32015-07-03 11:49:42 +0800449class ImageView : public internal::NonDispHandle<VkImageView> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600450public:
Chia-I Wu3158bf32015-07-03 11:49:42 +0800451 ~ImageView();
452
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600453 // vkCreateImageView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600454 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600455};
456
Chia-I Wu4d0c7922015-07-03 11:49:42 +0800457class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600458public:
Chia-I Wu4d0c7922015-07-03 11:49:42 +0800459 ~ShaderModule();
460
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600461 // vkCreateShaderModule()
462 void init(const Device &dev, const VkShaderModuleCreateInfo &info);
463 VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
464
Chia-I Wu8094f192015-10-26 19:22:06 +0800465 static VkShaderModuleCreateInfo create_info(size_t code_size, const uint32_t *code, VkFlags flags);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600466};
467
Chia-I Wu2ff72fd2015-07-03 11:49:42 +0800468class Pipeline : public internal::NonDispHandle<VkPipeline> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600469public:
Chia-I Wu2ff72fd2015-07-03 11:49:42 +0800470 ~Pipeline();
471
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600472 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600473 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600474 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600475 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476 // vkCreateComputePipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600477 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600478 // vkLoadPipeline()
479 void init(const Device&dev, size_t size, const void *data);
480 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600481 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600482
Chris Forbes95292b12015-05-25 11:13:26 +1200483 // vkCreateGraphicsPipeline with error return
484 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
485
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600486 // vkStorePipeline()
487 size_t store(size_t size, void *data);
488};
489
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800490class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> {
491public:
492 ~PipelineLayout();
493
494 // vCreatePipelineLayout()
495 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
496};
497
Chia-I Wu8c721c62015-07-03 11:49:42 +0800498class Sampler : public internal::NonDispHandle<VkSampler> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600499public:
Chia-I Wu8c721c62015-07-03 11:49:42 +0800500 ~Sampler();
501
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600502 // vkCreateSampler()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600503 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600504};
505
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800506class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600507public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800508 ~DescriptorSetLayout();
509
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600510 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600511 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512};
513
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800514class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600515public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800516 ~DescriptorPool();
517
Cody Northropcdc72a42015-10-08 11:39:25 -0600518 // Descriptor sets allocated from this pool will need access to the original object
519 VkDescriptorPool GetObj() { return pool_; }
520
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600521 // vkCreateDescriptorPool()
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600522 void init(const Device &dev, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600523
524 // vkResetDescriptorPool()
525 void reset();
526
Cody Northropcdc72a42015-10-08 11:39:25 -0600527 // vkFreeDescriptorSet()
528 void setDynamicUsage(bool isDynamic) { dynamic_usage_ = isDynamic; }
529 bool getDynamicUsage() { return dynamic_usage_; }
530
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800531 // vkAllocateDescriptorSets()
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600532 std::vector<DescriptorSet *> alloc_sets(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts);
533 std::vector<DescriptorSet *> alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count);
534 DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout);
Cody Northropcdc72a42015-10-08 11:39:25 -0600535
536private:
537 VkDescriptorPool pool_;
538
539 // Track whether this pool's usage is VK_DESCRIPTOR_POOL_USAGE_DYNAMIC
540 bool dynamic_usage_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600541};
542
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800543class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600544public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800545 ~DescriptorSet();
546
547 explicit DescriptorSet() : NonDispHandle() {}
Cody Northropcdc72a42015-10-08 11:39:25 -0600548 explicit DescriptorSet(const Device &dev, DescriptorPool* pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { containing_pool_ = pool;}
Tony Barbour67e99152015-07-10 14:10:27 -0600549
550private:
Cody Northropcdc72a42015-10-08 11:39:25 -0600551 DescriptorPool* containing_pool_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600552};
553
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800554class CommandPool : public internal::NonDispHandle<VkCommandPool> {
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600555public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800556 ~CommandPool();
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600557
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800558 explicit CommandPool() : NonDispHandle() {}
559 explicit CommandPool(const Device &dev, const VkCommandPoolCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600560
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800561 void init(const Device &dev, const VkCommandPoolCreateInfo &info);
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600562
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800563 static VkCommandPoolCreateInfo create_info(uint32_t queue_family_index);
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600564};
565
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800566inline VkCommandPoolCreateInfo CommandPool::create_info(uint32_t queue_family_index)
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600567{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800568 VkCommandPoolCreateInfo info = {};
569 info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600570 info.queueFamilyIndex = queue_family_index;
571 return info;
572}
573
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800574class CommandBuffer : public internal::Handle<VkCommandBuffer> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600575public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800576 ~CommandBuffer();
Chia-I Wube2b9172015-07-03 11:49:42 +0800577
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 explicit CommandBuffer() : Handle() {}
579 explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600580
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 // vkAllocateCommandBuffers()
582 void init(const Device &dev, const VkCommandBufferAllocateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600583
584 // vkBeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800585 void begin(const VkCommandBufferBeginInfo *info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600586 void begin();
587
588 // vkEndCommandBuffer()
589 // vkResetCommandBuffer()
590 void end();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800591 void reset(VkCommandBufferResetFlags flags);
592 void reset() { reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600593
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800594 static VkCommandBufferAllocateInfo create_info(VkCommandPool const &pool);
Chia-I Wube2b9172015-07-03 11:49:42 +0800595
596private:
597 VkDevice dev_handle_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800598 VkCommandPool cmd_pool_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600599};
600
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800601inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600602{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800603 VkMemoryAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800604 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Chia-I Wuf8f074f2015-07-03 10:58:57 +0800605 info.allocationSize = size;
606 info.memoryTypeIndex = memory_type_index;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600607 return info;
608}
609
Tony Barbourd1c35722015-04-16 15:59:00 -0600610inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600611{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600612 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600613 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
614 info.size = size;
615 info.usage = usage;
616 return info;
617}
618
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600619inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600620{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600621 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600622 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
623 info.flags = flags;
624 return info;
625}
626
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600627inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600628{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600629 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600630 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
631 return info;
632}
633
Tony Barbouraf892a12015-06-26 12:56:09 -0600634inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600635{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600636 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600637 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600638 info.flags = flags;
639 return info;
640}
641
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600642inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600643{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600644 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
646 info.flags = flags;
647 return info;
648}
649
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600650inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600651{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600652 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600653 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
654 info.queryType = type;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800655 info.entryCount = slot_count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600656 return info;
657}
658
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600659inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600660{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600661 VkImageCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600662 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
663 info.extent.width = 1;
664 info.extent.height = 1;
665 info.extent.depth = 1;
666 info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600667 info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800668 info.samples = VK_SAMPLE_COUNT_1_BIT;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600669 return info;
670}
671
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600672inline VkImageSubresource Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600673{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600674 VkImageSubresource subres = {};
Chia-I Wu52b07e72015-10-27 19:55:05 +0800675 subres.aspectMask = aspect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600676 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600677 subres.arrayLayer = array_layer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600678 return subres;
679}
680
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600681inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600682{
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600683 return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600684}
685
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800686inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size)
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600687{
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800688 VkImageSubresourceLayers subres = {};
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800689 subres.aspectMask = aspect;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600690 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600691 subres.baseArrayLayer = array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800692 subres.layerCount = array_size;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600693 return subres;
694}
695
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600696inline VkImageAspectFlagBits Image::image_aspect(VkImageAspectFlags flags)
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600697{
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600698 /*
699 * This will map VkImageAspectFlags into a single VkImageAspect.
700 * If there is more than one bit defined we'll get an assertion.
701 */
702 switch (flags) {
703 case VK_IMAGE_ASPECT_COLOR_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600704 return VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600705 case VK_IMAGE_ASPECT_DEPTH_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600706 return VK_IMAGE_ASPECT_DEPTH_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600707 case VK_IMAGE_ASPECT_STENCIL_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600708 return VK_IMAGE_ASPECT_STENCIL_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600709 case VK_IMAGE_ASPECT_METADATA_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600710 return VK_IMAGE_ASPECT_METADATA_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600711 default:
712 assert(!"Invalid VkImageAspect");
713 }
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600714 return VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600715}
716
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800717inline VkImageSubresourceLayers Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, uint32_t array_size)
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600718{
719 return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size);
720}
721
722inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600723 uint32_t base_array_layer, uint32_t num_layers)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600724{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600725 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600726 range.aspectMask = aspect_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600727 range.baseMipLevel = base_mip_level;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800728 range.levelCount = mip_levels;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600729 range.baseArrayLayer = base_array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800730 range.layerCount = num_layers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600731 return range;
732}
733
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600734inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600735{
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600736 return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600737}
738
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600739inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600740{
Chia-I Wu52b07e72015-10-27 19:55:05 +0800741 return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600742}
743
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600744inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600745{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600746 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600747 extent.width = width;
748 extent.height = height;
749 return extent;
750}
751
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600752inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600753{
754 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
755 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
756 return Image::extent(width, height);
757}
758
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600759inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600760{
761 return Image::extent(extent.width, extent.height);
762}
763
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600764inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600765{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600766 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600767 extent.width = width;
768 extent.height = height;
769 extent.depth = depth;
770 return extent;
771}
772
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600773inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600774{
775 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
776 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
777 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
778 return Image::extent(width, height, depth);
779}
780
Chia-I Wu8094f192015-10-26 19:22:06 +0800781inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags)
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600782{
783 VkShaderModuleCreateInfo info = {};
784 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
785 info.codeSize = code_size;
786 info.pCode = code;
787 info.flags = flags;
788 return info;
789}
790
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800791inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600792 VkDescriptorType type, uint32_t count, const VkDescriptorImageInfo *image_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600793{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800794 VkWriteDescriptorSet write = {};
795 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800796 write.dstSet = set.handle();
797 write.dstBinding = binding;
798 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800799 write.descriptorCount = count;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800800 write.descriptorType = type;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600801 write.pImageInfo = image_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800802 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600803}
804
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800805inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600806 VkDescriptorType type, uint32_t count, const VkDescriptorBufferInfo *buffer_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600807{
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600808 VkWriteDescriptorSet write = {};
809 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800810 write.dstSet = set.handle();
811 write.dstBinding = binding;
812 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800813 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600814 write.descriptorType = type;
815 write.pBufferInfo = buffer_info;
816 return write;
817}
818
819inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
820 VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views)
821{
822 VkWriteDescriptorSet write = {};
823 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800824 write.dstSet = set.handle();
825 write.dstBinding = binding;
826 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800827 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600828 write.descriptorType = type;
829 write.pTexelBufferView = buffer_views;
830 return write;
831}
832
833inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
834 VkDescriptorType type, const std::vector<VkDescriptorImageInfo> &image_info)
835{
836 return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]);
837}
838
839inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
840 VkDescriptorType type, const std::vector<VkDescriptorBufferInfo> &buffer_info)
841{
842 return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]);
843}
844
845inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
846 VkDescriptorType type, const std::vector<VkBufferView> &buffer_views)
847{
848 return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600849}
850
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800851inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
852 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
853 uint32_t count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600854{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800855 VkCopyDescriptorSet copy = {};
856 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800857 copy.srcSet = src_set.handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800858 copy.srcBinding = src_binding;
859 copy.srcArrayElement = src_array_element;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800860 copy.dstSet = dst_set.handle();
861 copy.dstBinding = dst_binding;
862 copy.dstArrayElement = dst_array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800863 copy.descriptorCount = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600864
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800865 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600866}
867
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800868inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600869{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800870 VkCommandBufferAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800871 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800872 info.commandPool = pool;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800873 info.bufferCount = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600874 return info;
875}
876
877}; // namespace vk_testing
878
879#endif // VKTESTBINDING_H