blob: 13246202eb35fa3ef0ed285e12837dd541b00011 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
5 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Karl Schultz6addd812016-02-02 17:17:23 -070017 *
18 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
19 * Author: Cody Northrop <cody@lunarg.com>
20 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060021
22#ifndef VKTESTBINDING_H
23#define VKTESTBINDING_H
24
Chia-I Wub0ed7d42015-07-03 10:13:26 +080025#include <assert.h>
Mark Lobodzinski722841d2016-09-07 16:34:56 -060026#include <vector>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060027
David Pinedo9316d3b2015-11-06 12:54:48 -070028#include "vulkan/vulkan.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060029
30namespace vk_testing {
31
Mark Lobodzinski722841d2016-09-07 16:34:56 -060032typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060033void set_error_callback(ErrorCallback callback);
34
Chia-I Wu999f0482015-07-03 10:32:05 +080035class PhysicalDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036class Device;
37class Queue;
Chia-I Wuf8f074f2015-07-03 10:58:57 +080038class DeviceMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039class Fence;
40class Semaphore;
41class Event;
42class QueryPool;
43class Buffer;
44class BufferView;
45class Image;
46class ImageView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060047class DepthStencilView;
48class Shader;
49class Pipeline;
50class PipelineDelta;
51class Sampler;
52class DescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -050053class PipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060054class DescriptorSetPool;
55class DescriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080056class CommandBuffer;
57class CommandPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060059std::vector<VkLayerProperties> GetGlobalLayers();
60std::vector<VkExtensionProperties> GetGlobalExtensions();
61std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
62
Chia-I Wub0ed7d42015-07-03 10:13:26 +080063namespace internal {
64
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070065template <typename T>
66class Handle {
67 public:
Chia-I Wub0ed7d42015-07-03 10:13:26 +080068 const T &handle() const { return handle_; }
69 bool initialized() const { return (handle_ != VK_NULL_HANDLE); }
70
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070071 protected:
Chia-I Wub0ed7d42015-07-03 10:13:26 +080072 typedef T handle_type;
73
74 explicit Handle() : handle_(VK_NULL_HANDLE) {}
75 explicit Handle(T handle) : handle_(handle) {}
76
Karl Schultz6addd812016-02-02 17:17:23 -070077 void init(T handle) {
Chia-I Wub0ed7d42015-07-03 10:13:26 +080078 assert(!initialized());
79 handle_ = handle;
80 }
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082 private:
Chia-I Wub0ed7d42015-07-03 10:13:26 +080083 // handles are non-copyable
84 Handle(const Handle &);
85 Handle &operator=(const Handle &);
86
87 T handle_;
88};
89
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070090template <typename T>
91class NonDispHandle : public Handle<T> {
92 protected:
Chia-I Wub0ed7d42015-07-03 10:13:26 +080093 explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -060094 explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {}
Chia-I Wub0ed7d42015-07-03 10:13:26 +080095
96 const VkDevice &device() const { return dev_handle_; }
97
Karl Schultz6addd812016-02-02 17:17:23 -070098 void init(VkDevice dev, T handle) {
Chia-I Wub0ed7d42015-07-03 10:13:26 +080099 assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE);
100 Handle<T>::init(handle);
101 dev_handle_ = dev;
102 }
103
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700104 private:
Chia-I Wub0ed7d42015-07-03 10:13:26 +0800105 VkDevice dev_handle_;
106};
107
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700108} // namespace internal
Chia-I Wub0ed7d42015-07-03 10:13:26 +0800109
Chia-I Wu999f0482015-07-03 10:32:05 +0800110class PhysicalDevice : public internal::Handle<VkPhysicalDevice> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700111 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700112 explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy) {
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600113 memory_properties_ = memory_properties();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600114 device_properties_ = properties();
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600115 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600116
Tony Barbourd1c35722015-04-16 15:59:00 -0600117 VkPhysicalDeviceProperties properties() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600118 VkPhysicalDeviceMemoryProperties memory_properties() const;
Cody Northropd0802882015-08-03 17:04:53 -0600119 std::vector<VkQueueFamilyProperties> queue_properties() const;
Chris Forbesf9cfe182016-04-04 17:22:42 +1200120 VkPhysicalDeviceFeatures features() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600121
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600122 bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkMemoryPropertyFlags properties,
Karl Schultz6addd812016-02-02 17:17:23 -0700123 const VkMemoryPropertyFlags forbid = 0) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600124
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600125 // vkEnumerateDeviceExtensionProperties()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600126 std::vector<VkExtensionProperties> extensions() const;
Karl Schultz6addd812016-02-02 17:17:23 -0700127 std::vector<VkExtensionProperties> extensions(const char *pLayerName) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600128
129 // vkEnumerateLayers()
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600130 std::vector<VkLayerProperties> layers() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700132 private:
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600133 void add_extension_dependencies(uint32_t dependency_count, VkExtensionProperties *depencency_props,
134 std::vector<VkExtensionProperties> &ext_list);
Chia-I Wu999f0482015-07-03 10:32:05 +0800135
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600136 VkPhysicalDeviceMemoryProperties memory_properties_;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600137
138 VkPhysicalDeviceProperties device_properties_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600139};
140
Chia-I Wuf368b602015-07-03 10:41:20 +0800141class Device : public internal::Handle<VkDevice> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700142 public:
Chia-I Wu999f0482015-07-03 10:32:05 +0800143 explicit Device(VkPhysicalDevice phy) : phy_(phy) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600144 ~Device();
145
146 // vkCreateDevice()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600147 void init(const VkDeviceCreateInfo &info);
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600148 void init(std::vector<const char *> &extensions,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700149 VkPhysicalDeviceFeatures *features = nullptr); // all queues, all extensions, etc
Karl Schultz6addd812016-02-02 17:17:23 -0700150 void init() {
Karl Schultz6addd812016-02-02 17:17:23 -0700151 std::vector<const char *> extensions;
Tony Barbour4c70d102016-08-08 16:06:56 -0600152 init(extensions);
Karl Schultz6addd812016-02-02 17:17:23 -0700153 };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600154
Chia-I Wu999f0482015-07-03 10:32:05 +0800155 const PhysicalDevice &phy() const { return phy_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600156
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600157 // vkGetDeviceProcAddr()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600158 PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); }
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600159
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600160 // vkGetDeviceQueue()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600161 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600162 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
163 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
164 uint32_t graphics_queue_node_index_;
165
166 struct Format {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600167 VkFormat format;
168 VkImageTiling tiling;
169 VkFlags features;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600170 };
171 // vkGetFormatInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600172 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600173 const std::vector<Format> &formats() const { return formats_; }
174
175 // vkDeviceWaitIdle()
176 void wait();
177
178 // vkWaitForFences()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600179 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
180 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t)-1); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600181
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800182 // vkUpdateDescriptorSets()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600183 void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
184 void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) {
185 return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>());
Karl Schultz6addd812016-02-02 17:17:23 -0700186 }
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800187
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600188 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
189 VkDescriptorType type, uint32_t count,
190 const VkDescriptorImageInfo *image_info);
191 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
192 VkDescriptorType type, uint32_t count,
193 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
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600203 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);
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800206
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700207 private:
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600208 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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700225 public:
Mark Lobodzinski722841d2016-09-07 16:34:56 -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
Karl Schultz6addd812016-02-02 17:17:23 -0700236 int get_family_index() { return family_index_; }
Tony Barbourfb21ea32015-07-23 10:35:30 -0600237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700238 private:
Tony Barbourfb21ea32015-07-23 10:35:30 -0600239 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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700243 public:
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;
Karl Schultz6addd812016-02-02 17:17:23 -0700251 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600252 const void *map() const { return map(0); }
Karl Schultz6addd812016-02-02 17:17:23 -0700253 void *map() { return map(0); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600254
255 // vkUnmapMemory()
256 void unmap() const;
257
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600258 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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700262 public:
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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700276 public:
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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700286 public:
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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700303 public:
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()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600310 VkResult results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311
Mark Lobodzinski722841d2016-09-07 16:34:56 -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> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700316 public:
Chia-I Wu681d7a02015-07-03 13:44:34 +0800317 explicit Buffer() : NonDispHandle() {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -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()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600324 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); }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800327 void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); }
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600328 void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) {
Karl Schultz6addd812016-02-02 17:17:23 -0700329 init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT), reqs);
330 }
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600331 void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) {
Karl Schultz6addd812016-02-02 17:17:23 -0700332 init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs);
333 }
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600334 void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) {
335 init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs);
Karl Schultz6addd812016-02-02 17:17:23 -0700336 }
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600337 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600338
Chia-I Wu681d7a02015-07-03 13:44:34 +0800339 // get the internal memory
340 const DeviceMemory &memory() const { return internal_mem_; }
Karl Schultz6addd812016-02-02 17:17:23 -0700341 DeviceMemory &memory() { return internal_mem_; }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800342
343 // vkGetObjectMemoryRequirements()
344 VkMemoryRequirements memory_requirements() const;
345
346 // vkBindObjectMemory()
347 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500348
Tony Barbourd1c35722015-04-16 15:59:00 -0600349 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600351 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkDeviceSize offset,
Karl Schultz6addd812016-02-02 17:17:23 -0700352 VkDeviceSize size) const {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600354 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800355 barrier.buffer = handle();
Chia-I Wua4594202015-10-27 19:54:37 +0800356 barrier.srcAccessMask = output_mask;
357 barrier.dstAccessMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600358 barrier.offset = offset;
359 barrier.size = size;
360 return barrier;
361 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800362
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700363 private:
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600364 VkBufferCreateInfo create_info_;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800365
366 DeviceMemory internal_mem_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600367};
368
Chia-I Wu3158bf32015-07-03 11:49:42 +0800369class BufferView : public internal::NonDispHandle<VkBufferView> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700370 public:
Chia-I Wu3158bf32015-07-03 11:49:42 +0800371 ~BufferView();
372
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600373 // vkCreateBufferView()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600374 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600375};
376
Chia-I Wu681d7a02015-07-03 13:44:34 +0800377class Image : public internal::NonDispHandle<VkImage> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700378 public:
Chia-I Wu681d7a02015-07-03 13:44:34 +0800379 explicit Image() : NonDispHandle(), format_features_(0) {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600380 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600381
Chia-I Wu681d7a02015-07-03 13:44:34 +0800382 ~Image();
383
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600384 // vkCreateImage()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600385 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props);
386 void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600388
Chia-I Wu681d7a02015-07-03 13:44:34 +0800389 // get the internal memory
390 const DeviceMemory &memory() const { return internal_mem_; }
Karl Schultz6addd812016-02-02 17:17:23 -0700391 DeviceMemory &memory() { return internal_mem_; }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800392
393 // vkGetObjectMemoryRequirements()
394 VkMemoryRequirements memory_requirements() const;
395
396 // vkBindObjectMemory()
397 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600398
Tony Barbour59a47322015-06-24 16:06:58 -0600399 // vkGetImageSubresourceLayout()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600400 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
401 VkSubresourceLayout subresource_layout(const VkImageSubresourceLayers &subres) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600402
403 bool transparent() const;
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600404 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600405
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600406 VkImageSubresourceRange subresource_range(VkImageAspectFlagBits aspect) const {
Karl Schultz6addd812016-02-02 17:17:23 -0700407 return subresource_range(create_info_, aspect);
408 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600409 VkExtent3D extent() const { return create_info_.extent; }
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600410 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
Karl Schultz6addd812016-02-02 17:17:23 -0700411 VkFormat format() const { return create_info_.format; }
Mike Weiblene6e01172017-03-07 22:18:40 -0700412 VkImageUsageFlags usage() const { return create_info_.usage; }
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600413 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkImageLayout old_layout,
414 VkImageLayout new_layout, const VkImageSubresourceRange &range) const {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600415 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600416 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Chia-I Wua4594202015-10-27 19:54:37 +0800417 barrier.srcAccessMask = output_mask;
418 barrier.dstAccessMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600419 barrier.oldLayout = old_layout;
420 barrier.newLayout = new_layout;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800421 barrier.image = handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600422 barrier.subresourceRange = range;
423 return barrier;
424 }
425
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600426 static VkImageCreateInfo create_info();
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600427 static VkImageSubresource subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer);
428 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer);
429 static VkImageSubresourceLayers subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer,
Karl Schultz6addd812016-02-02 17:17:23 -0700430 uint32_t array_size);
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600431 static VkImageSubresourceLayers subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer,
432 uint32_t array_size);
433 static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels,
434 uint32_t base_array_layer, uint32_t num_layers);
435 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask);
436 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600437
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600438 static VkExtent2D extent(int32_t width, int32_t height);
439 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
440 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600441
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600442 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
443 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600444
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700445 private:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600446 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600448 VkImageCreateInfo create_info_;
449 VkFlags format_features_;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800450
451 DeviceMemory internal_mem_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600452};
453
Chia-I Wu3158bf32015-07-03 11:49:42 +0800454class ImageView : public internal::NonDispHandle<VkImageView> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700455 public:
Chia-I Wu3158bf32015-07-03 11:49:42 +0800456 ~ImageView();
457
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600458 // vkCreateImageView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600459 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600460};
461
Chia-I Wu4d0c7922015-07-03 11:49:42 +0800462class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700463 public:
Chia-I Wu4d0c7922015-07-03 11:49:42 +0800464 ~ShaderModule();
465
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600466 // vkCreateShaderModule()
467 void init(const Device &dev, const VkShaderModuleCreateInfo &info);
468 VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
469
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600470 static VkShaderModuleCreateInfo create_info(size_t code_size, const uint32_t *code, VkFlags flags);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600471};
472
Chia-I Wu2ff72fd2015-07-03 11:49:42 +0800473class Pipeline : public internal::NonDispHandle<VkPipeline> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700474 public:
Chia-I Wu2ff72fd2015-07-03 11:49:42 +0800475 ~Pipeline();
476
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600477 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600478 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600479 // vkCreateGraphicsPipelineDerivative()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600480 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600481 // vkCreateComputePipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600482 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600483 // vkLoadPipeline()
Karl Schultz6addd812016-02-02 17:17:23 -0700484 void init(const Device &dev, size_t size, const void *data);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600485 // vkLoadPipelineDerivative()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600486 void init(const Device &dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600487
Chris Forbes95292b12015-05-25 11:13:26 +1200488 // vkCreateGraphicsPipeline with error return
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600489 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Chris Forbes95292b12015-05-25 11:13:26 +1200490
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600491 // vkStorePipeline()
492 size_t store(size_t size, void *data);
493};
494
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800495class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700496 public:
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800497 ~PipelineLayout();
498
499 // vCreatePipelineLayout()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600500 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800501};
502
Chia-I Wu8c721c62015-07-03 11:49:42 +0800503class Sampler : public internal::NonDispHandle<VkSampler> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700504 public:
Chia-I Wu8c721c62015-07-03 11:49:42 +0800505 ~Sampler();
506
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600507 // vkCreateSampler()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600508 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600509};
510
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600511class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700512 public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800513 ~DescriptorSetLayout();
514
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600515 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600516 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600517};
518
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800519class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700520 public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800521 ~DescriptorPool();
522
Karl Schultz6addd812016-02-02 17:17:23 -0700523 // Descriptor sets allocated from this pool will need access to the original
524 // object
Cody Northropcdc72a42015-10-08 11:39:25 -0600525 VkDescriptorPool GetObj() { return pool_; }
526
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600527 // vkCreateDescriptorPool()
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600528 void init(const Device &dev, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600529
530 // vkResetDescriptorPool()
531 void reset();
532
Cody Northropcdc72a42015-10-08 11:39:25 -0600533 // vkFreeDescriptorSet()
534 void setDynamicUsage(bool isDynamic) { dynamic_usage_ = isDynamic; }
535 bool getDynamicUsage() { return dynamic_usage_; }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 // vkAllocateDescriptorSets()
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600538 std::vector<DescriptorSet *> alloc_sets(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts);
539 std::vector<DescriptorSet *> alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count);
540 DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout);
Cody Northropcdc72a42015-10-08 11:39:25 -0600541
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700542 private:
Cody Northropcdc72a42015-10-08 11:39:25 -0600543 VkDescriptorPool pool_;
544
545 // Track whether this pool's usage is VK_DESCRIPTOR_POOL_USAGE_DYNAMIC
546 bool dynamic_usage_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600547};
548
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800549class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700550 public:
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800551 ~DescriptorSet();
552
553 explicit DescriptorSet() : NonDispHandle() {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600554 explicit DescriptorSet(const Device &dev, DescriptorPool *pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) {
Karl Schultz6addd812016-02-02 17:17:23 -0700555 containing_pool_ = pool;
556 }
Tony Barbour67e99152015-07-10 14:10:27 -0600557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700558 private:
Karl Schultz6addd812016-02-02 17:17:23 -0700559 DescriptorPool *containing_pool_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600560};
561
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800562class CommandPool : public internal::NonDispHandle<VkCommandPool> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700563 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800564 ~CommandPool();
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600565
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800566 explicit CommandPool() : NonDispHandle() {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600567 explicit CommandPool(const Device &dev, const VkCommandPoolCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600568
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800569 void init(const Device &dev, const VkCommandPoolCreateInfo &info);
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600570
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800571 static VkCommandPoolCreateInfo create_info(uint32_t queue_family_index);
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600572};
573
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600574inline VkCommandPoolCreateInfo CommandPool::create_info(uint32_t queue_family_index) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800575 VkCommandPoolCreateInfo info = {};
576 info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600577 info.queueFamilyIndex = queue_family_index;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700578 info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Courtney Goeltzenleuchteree5d80b2015-07-10 19:50:17 -0600579 return info;
580}
581
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582class CommandBuffer : public internal::Handle<VkCommandBuffer> {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700583 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800584 ~CommandBuffer();
Chia-I Wube2b9172015-07-03 11:49:42 +0800585
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800586 explicit CommandBuffer() : Handle() {}
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600587 explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600588
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800589 // vkAllocateCommandBuffers()
590 void init(const Device &dev, const VkCommandBufferAllocateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600591
592 // vkBeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800593 void begin(const VkCommandBufferBeginInfo *info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594 void begin();
595
596 // vkEndCommandBuffer()
597 // vkResetCommandBuffer()
598 void end();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800599 void reset(VkCommandBufferResetFlags flags);
600 void reset() { reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600601
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 static VkCommandBufferAllocateInfo create_info(VkCommandPool const &pool);
Chia-I Wube2b9172015-07-03 11:49:42 +0800603
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700604 private:
Chia-I Wube2b9172015-07-03 11:49:42 +0800605 VkDevice dev_handle_;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800606 VkCommandPool cmd_pool_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600607};
608
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600609inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800610 VkMemoryAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800611 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Chia-I Wuf8f074f2015-07-03 10:58:57 +0800612 info.allocationSize = size;
613 info.memoryTypeIndex = memory_type_index;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600614 return info;
615}
616
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600617inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage) {
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600618 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
620 info.size = size;
621 info.usage = usage;
622 return info;
623}
624
Karl Schultz6addd812016-02-02 17:17:23 -0700625inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600626 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600627 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
628 info.flags = flags;
629 return info;
630}
631
Karl Schultz6addd812016-02-02 17:17:23 -0700632inline VkFenceCreateInfo Fence::create_info() {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600633 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600634 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
635 return info;
636}
637
Karl Schultz6addd812016-02-02 17:17:23 -0700638inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600639 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600640 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600641 info.flags = flags;
642 return info;
643}
644
Karl Schultz6addd812016-02-02 17:17:23 -0700645inline VkEventCreateInfo Event::create_info(VkFlags flags) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600646 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600647 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
648 info.flags = flags;
649 return info;
650}
651
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600652inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) {
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;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700656 info.queryCount = slot_count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600657 return info;
658}
659
Karl Schultz6addd812016-02-02 17:17:23 -0700660inline VkImageCreateInfo Image::create_info() {
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
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600672inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600673 VkImageSubresource subres = {};
Karl Schultz0ab73f82016-03-29 12:41:24 -0600674 if (aspect == 0) {
675 assert(!"Invalid VkImageAspectFlags");
676 }
Chia-I Wu52b07e72015-10-27 19:55:05 +0800677 subres.aspectMask = aspect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600678 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600679 subres.arrayLayer = array_layer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600680 return subres;
681}
682
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600683inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer) {
684 return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685}
686
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600687inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer,
Karl Schultz6addd812016-02-02 17:17:23 -0700688 uint32_t array_size) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800689 VkImageSubresourceLayers subres = {};
Karl Schultz0ab73f82016-03-29 12:41:24 -0600690 switch (aspect) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700691 case VK_IMAGE_ASPECT_COLOR_BIT:
692 case VK_IMAGE_ASPECT_DEPTH_BIT:
693 case VK_IMAGE_ASPECT_STENCIL_BIT:
694 case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT:
695 /* valid */
696 break;
697 default:
698 assert(!"Invalid VkImageAspectFlags");
Karl Schultz0ab73f82016-03-29 12:41:24 -0600699 }
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800700 subres.aspectMask = aspect;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600701 subres.mipLevel = mip_level;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -0600702 subres.baseArrayLayer = array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800703 subres.layerCount = array_size;
Courtney Goeltzenleuchter01ee1ca2015-09-10 16:41:13 -0600704 return subres;
705}
706
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600707inline VkImageSubresourceLayers Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer,
708 uint32_t array_size) {
709 return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size);
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600710}
711
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600712inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level,
713 uint32_t mip_levels, uint32_t base_array_layer, uint32_t num_layers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600714 VkImageSubresourceRange range = {};
Karl Schultz0ab73f82016-03-29 12:41:24 -0600715 if (aspect_mask == 0) {
716 assert(!"Invalid VkImageAspectFlags");
717 }
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600718 range.aspectMask = aspect_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600719 range.baseMipLevel = base_mip_level;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800720 range.levelCount = mip_levels;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600721 range.baseArrayLayer = base_array_layer;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800722 range.layerCount = num_layers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600723 return range;
724}
725
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600726inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask) {
727 return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600728}
729
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600730inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) {
731 return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600732}
733
Karl Schultz6addd812016-02-02 17:17:23 -0700734inline VkExtent2D Image::extent(int32_t width, int32_t height) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600735 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600736 extent.width = width;
737 extent.height = height;
738 return extent;
739}
740
Karl Schultz6addd812016-02-02 17:17:23 -0700741inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) {
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600742 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
743 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600744 return Image::extent(width, height);
745}
746
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600747inline VkExtent2D Image::extent(const VkExtent3D &extent) { return Image::extent(extent.width, extent.height); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600748
Karl Schultz6addd812016-02-02 17:17:23 -0700749inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600750 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600751 extent.width = width;
752 extent.height = height;
753 extent.depth = depth;
754 return extent;
755}
756
Karl Schultz6addd812016-02-02 17:17:23 -0700757inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) {
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600758 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
759 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
760 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600761 return Image::extent(width, height, depth);
762}
763
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600764inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags) {
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600765 VkShaderModuleCreateInfo info = {};
766 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
767 info.codeSize = code_size;
768 info.pCode = code;
769 info.flags = flags;
770 return info;
771}
772
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600773inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
774 VkDescriptorType type, uint32_t count,
775 const VkDescriptorImageInfo *image_info) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800776 VkWriteDescriptorSet write = {};
777 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800778 write.dstSet = set.handle();
779 write.dstBinding = binding;
780 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800781 write.descriptorCount = count;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800782 write.descriptorType = type;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600783 write.pImageInfo = image_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800784 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600785}
786
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600787inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
788 VkDescriptorType type, uint32_t count,
789 const VkDescriptorBufferInfo *buffer_info) {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600790 VkWriteDescriptorSet write = {};
791 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800792 write.dstSet = set.handle();
793 write.dstBinding = binding;
794 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800795 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600796 write.descriptorType = type;
797 write.pBufferInfo = buffer_info;
798 return write;
799}
800
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600801inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
802 VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views) {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600803 VkWriteDescriptorSet write = {};
804 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800805 write.dstSet = set.handle();
806 write.dstBinding = binding;
807 write.dstArrayElement = array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800808 write.descriptorCount = count;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600809 write.descriptorType = type;
810 write.pTexelBufferView = buffer_views;
811 return write;
812}
813
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600814inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
815 VkDescriptorType type,
816 const std::vector<VkDescriptorImageInfo> &image_info) {
817 return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]);
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600818}
819
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600820inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
821 VkDescriptorType type,
822 const std::vector<VkDescriptorBufferInfo> &buffer_info) {
823 return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]);
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600824}
825
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600826inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
827 VkDescriptorType type, const std::vector<VkBufferView> &buffer_views) {
828 return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600829}
830
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600831inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding,
832 uint32_t src_array_element, const DescriptorSet &dst_set,
833 uint32_t dst_binding, uint32_t dst_array_element, uint32_t count) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800834 VkCopyDescriptorSet copy = {};
835 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800836 copy.srcSet = src_set.handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800837 copy.srcBinding = src_binding;
838 copy.srcArrayElement = src_array_element;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800839 copy.dstSet = dst_set.handle();
840 copy.dstBinding = dst_binding;
841 copy.dstArrayElement = dst_array_element;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800842 copy.descriptorCount = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600843
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800844 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600845}
846
Mark Lobodzinski722841d2016-09-07 16:34:56 -0600847inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800848 VkCommandBufferAllocateInfo info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800849 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800850 info.commandPool = pool;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700851 info.commandBufferCount = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600852 return info;
853}
854
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700855}; // namespace vk_testing
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700857#endif // VKTESTBINDING_H