blob: c631ec5598ebf22e52145ccf31bf0266706b79ab [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;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700571 info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600572 return info;
573}
574
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800575class CommandBuffer : public internal::Handle<VkCommandBuffer> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600576public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800577 ~CommandBuffer();
Chia-I Wube2b9172015-07-03 11:49:42 +0800578
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800579 explicit CommandBuffer() : Handle() {}
580 explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600581
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 // vkAllocateCommandBuffers()
583 void init(const Device &dev, const VkCommandBufferAllocateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600584
585 // vkBeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800586 void begin(const VkCommandBufferBeginInfo *info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587 void begin();
588
589 // vkEndCommandBuffer()
590 // vkResetCommandBuffer()
591 void end();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800592 void reset(VkCommandBufferResetFlags flags);
593 void reset() { reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800595 static VkCommandBufferAllocateInfo create_info(VkCommandPool const &pool);
Chia-I Wube2b9172015-07-03 11:49:42 +0800596
597private:
598 VkDevice dev_handle_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800599 VkCommandPool cmd_pool_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600600};
601
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600603{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800604 VkMemoryAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800605 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Chia-I Wuf8f074f2015-07-03 10:58:57 +0800606 info.allocationSize = size;
607 info.memoryTypeIndex = memory_type_index;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600608 return info;
609}
610
Tony Barbourd1c35722015-04-16 15:59:00 -0600611inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600612{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600613 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600614 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
615 info.size = size;
616 info.usage = usage;
617 return info;
618}
619
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600620inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600621{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600622 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600623 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
624 info.flags = flags;
625 return info;
626}
627
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600628inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600629{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600630 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600631 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
632 return info;
633}
634
Tony Barbouraf892a12015-06-26 12:56:09 -0600635inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600636{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600637 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600638 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 info.flags = flags;
640 return info;
641}
642
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600643inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600644{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600645 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600646 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
647 info.flags = flags;
648 return info;
649}
650
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600651inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600652{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600653 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600654 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
655 info.queryType = type;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800656 info.entryCount = slot_count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600657 return info;
658}
659
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600660inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600661{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600662 VkImageCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600663 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
664 info.extent.width = 1;
665 info.extent.height = 1;
666 info.extent.depth = 1;
667 info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600668 info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800669 info.samples = VK_SAMPLE_COUNT_1_BIT;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600670 return info;
671}
672
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600673inline VkImageSubresource Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600674{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600675 VkImageSubresource subres = {};
Chia-I Wu52b07e72015-10-27 19:55:05 +0800676 subres.aspectMask = aspect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600677 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600678 subres.arrayLayer = array_layer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600679 return subres;
680}
681
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600682inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600683{
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600684 return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685}
686
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800687inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size)
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600688{
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800689 VkImageSubresourceLayers subres = {};
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800690 subres.aspectMask = aspect;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600691 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600692 subres.baseArrayLayer = array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800693 subres.layerCount = array_size;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600694 return subres;
695}
696
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600697inline VkImageAspectFlagBits Image::image_aspect(VkImageAspectFlags flags)
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600698{
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600699 /*
700 * This will map VkImageAspectFlags into a single VkImageAspect.
701 * If there is more than one bit defined we'll get an assertion.
702 */
703 switch (flags) {
704 case VK_IMAGE_ASPECT_COLOR_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600705 return VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600706 case VK_IMAGE_ASPECT_DEPTH_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600707 return VK_IMAGE_ASPECT_DEPTH_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600708 case VK_IMAGE_ASPECT_STENCIL_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600709 return VK_IMAGE_ASPECT_STENCIL_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600710 case VK_IMAGE_ASPECT_METADATA_BIT:
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600711 return VK_IMAGE_ASPECT_METADATA_BIT;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600712 default:
713 assert(!"Invalid VkImageAspect");
714 }
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600715 return VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600716}
717
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800718inline 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 -0600719{
720 return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size);
721}
722
723inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600724 uint32_t base_array_layer, uint32_t num_layers)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600725{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600726 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600727 range.aspectMask = aspect_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600728 range.baseMipLevel = base_mip_level;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800729 range.levelCount = mip_levels;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600730 range.baseArrayLayer = base_array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800731 range.layerCount = num_layers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600732 return range;
733}
734
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600735inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600736{
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600737 return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600738}
739
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600740inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600741{
Chia-I Wu52b07e72015-10-27 19:55:05 +0800742 return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600743}
744
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600745inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600746{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600747 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600748 extent.width = width;
749 extent.height = height;
750 return extent;
751}
752
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600754{
755 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
756 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
757 return Image::extent(width, height);
758}
759
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600760inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600761{
762 return Image::extent(extent.width, extent.height);
763}
764
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600765inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600766{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600767 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600768 extent.width = width;
769 extent.height = height;
770 extent.depth = depth;
771 return extent;
772}
773
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600774inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600775{
776 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
777 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
778 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
779 return Image::extent(width, height, depth);
780}
781
Chia-I Wu8094f192015-10-26 19:22:06 +0800782inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags)
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600783{
784 VkShaderModuleCreateInfo info = {};
785 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
786 info.codeSize = code_size;
787 info.pCode = code;
788 info.flags = flags;
789 return info;
790}
791
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800792inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600793 VkDescriptorType type, uint32_t count, const VkDescriptorImageInfo *image_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600794{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800795 VkWriteDescriptorSet write = {};
796 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800797 write.dstSet = set.handle();
798 write.dstBinding = binding;
799 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800800 write.descriptorCount = count;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800801 write.descriptorType = type;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600802 write.pImageInfo = image_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800803 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600804}
805
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800806inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600807 VkDescriptorType type, uint32_t count, const VkDescriptorBufferInfo *buffer_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600808{
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600809 VkWriteDescriptorSet write = {};
810 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800811 write.dstSet = set.handle();
812 write.dstBinding = binding;
813 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800814 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600815 write.descriptorType = type;
816 write.pBufferInfo = buffer_info;
817 return write;
818}
819
820inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
821 VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views)
822{
823 VkWriteDescriptorSet write = {};
824 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800825 write.dstSet = set.handle();
826 write.dstBinding = binding;
827 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800828 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600829 write.descriptorType = type;
830 write.pTexelBufferView = buffer_views;
831 return write;
832}
833
834inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
835 VkDescriptorType type, const std::vector<VkDescriptorImageInfo> &image_info)
836{
837 return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]);
838}
839
840inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
841 VkDescriptorType type, const std::vector<VkDescriptorBufferInfo> &buffer_info)
842{
843 return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]);
844}
845
846inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
847 VkDescriptorType type, const std::vector<VkBufferView> &buffer_views)
848{
849 return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600850}
851
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800852inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
853 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
854 uint32_t count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600855{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800856 VkCopyDescriptorSet copy = {};
857 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800858 copy.srcSet = src_set.handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800859 copy.srcBinding = src_binding;
860 copy.srcArrayElement = src_array_element;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800861 copy.dstSet = dst_set.handle();
862 copy.dstBinding = dst_binding;
863 copy.dstArrayElement = dst_array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800864 copy.descriptorCount = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600865
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800866 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867}
868
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800869inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600870{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800871 VkCommandBufferAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800872 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800873 info.commandPool = pool;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800874 info.bufferCount = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600875 return info;
876}
877
878}; // namespace vk_testing
879
880#endif // VKTESTBINDING_H