blob: a374cbcc328b72f4583613b03fb59a324f67be3a [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001// VK tests
2//
3// Copyright (C) 2014 LunarG, Inc.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23#ifndef VKTESTBINDING_H
24#define VKTESTBINDING_H
25
26#include <vector>
27
28#include "vulkan.h"
29
30namespace vk_testing {
31
32typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function);
33void set_error_callback(ErrorCallback callback);
34
35class PhysicalGpu;
36class BaseObject;
37class Object;
38class DynamicStateObject;
39class Device;
40class Queue;
41class GpuMemory;
42class Fence;
43class Semaphore;
44class Event;
45class QueryPool;
46class Buffer;
47class BufferView;
48class Image;
49class ImageView;
50class ColorAttachmentView;
51class DepthStencilView;
52class Shader;
53class Pipeline;
54class PipelineDelta;
55class Sampler;
56class DescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -050057class PipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058class DescriptorSetPool;
59class DescriptorSet;
60class DynamicVpStateObject;
61class DynamicRsStateObject;
62class DynamicMsaaStateObject;
63class DynamicCbStateObject;
64class DynamicDsStateObject;
65class CmdBuffer;
66
67class PhysicalGpu {
68public:
Tony Barbourd1c35722015-04-16 15:59:00 -060069 explicit PhysicalGpu(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060070
Tony Barbourd1c35722015-04-16 15:59:00 -060071 const VkPhysicalDevice &obj() const { return gpu_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060072
Tony Barbourd1c35722015-04-16 15:59:00 -060073 // vkGetPhysicalDeviceInfo()
74 VkPhysicalDeviceProperties properties() const;
75 VkPhysicalDevicePerformance performance() const;
76 VkPhysicalDeviceMemoryProperties memory_properties() const;
77 std::vector<VkPhysicalDeviceQueueProperties> queue_properties() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060078
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060079
Tobin Ehlis3dd031b2015-04-16 10:13:25 -060080 // vkGetGlobalExtensionInfo()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060081 std::vector<VkExtensionProperties> extensions() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060082
83 // vkEnumerateLayers()
84 std::vector<const char *> layers(std::vector<char> &buf) const;
85
Tony Barbourd1c35722015-04-16 15:59:00 -060086 // vkGetMultiDeviceCompatibility()
87 VkPhysicalDeviceCompatibilityInfo compatibility(const PhysicalGpu &other) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060088
89private:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060090 void add_extension_dependencies(uint32_t dependency_count,
91 VkExtensionProperties *depencency_props,
92 std::vector<VkExtensionProperties> &ext_list);
Tony Barbourd1c35722015-04-16 15:59:00 -060093 VkPhysicalDevice gpu_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094};
95
96class BaseObject {
97public:
Mike Stroyanb050c682015-04-17 12:36:38 -060098 const VkObject &obj() const { return obj_; }
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -060099 VkObjectType type() const { return object_type_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600100 bool initialized() const { return (obj_ != VK_NULL_HANDLE); }
101
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600102protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600103 explicit BaseObject() :
104 object_type_((VkObjectType) 0), obj_(VK_NULL_HANDLE), own_obj_(false){}
105 explicit BaseObject(VkObject obj, VkObjectType object_type) :
106 object_type_(object_type), obj_(obj), own_obj_(false){}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600107
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600108 void init(VkObject obj, VkObjectType object_type, bool own);
109 void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600110
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600111 void reinit(VkObject obj, VkObjectType object_type, bool own);
112 void reinit(VkObject obj, VkObjectType object_type) { reinit(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600113
114 bool own() const { return own_obj_; }
115
116private:
117 // base objects are non-copyable
118 BaseObject(const BaseObject &);
119 BaseObject &operator=(const BaseObject &);
120
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600121 VkObjectType object_type_;
Mike Stroyanb050c682015-04-17 12:36:38 -0600122 VkObject obj_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600123 bool own_obj_;
124};
125
126class Object : public BaseObject {
127public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600128 const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600129
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600130 // vkGetObjectInfo()
131 uint32_t memory_allocation_count() const;
132 std::vector<VkMemoryRequirements> memory_requirements() const;
133
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500134 // vkBindObjectMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500135 void bind_memory(const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600136
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600137 // Unless an object is initialized with init_no_mem(), memories are
Courtney Goeltzenleuchterb66f5fd2015-05-01 17:56:13 -0600138 // automatically allocated and bound. These methods can be used to
139 // map/unmap the primary memory.
Tony Barbourd1c35722015-04-16 15:59:00 -0600140 std::vector<VkDeviceMemory> memories() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600141
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600142 const void *map(VkFlags flags) const;
143 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600144 const void *map() const { return map(0); }
145 void *map() { return map(0); }
146
147 void unmap() const;
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500148 const Device* dev_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600149
150protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600151 explicit Object() :
152 mem_alloc_count_(0), internal_mems_(NULL),
153 primary_mem_(NULL), bound(false) {}
154 explicit Object(const Device &dev, VkObject obj, VkObjectType object_type) :
155 dev_(&dev),
156 mem_alloc_count_(0), internal_mems_(NULL),
Chris Forbes94ba49d2015-05-25 11:13:03 +1200157 primary_mem_(NULL), bound(false) { init(obj, object_type); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600158 ~Object() { cleanup(); }
159
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600160 void init(VkObject obj, VkObjectType object_type, bool own);
161 void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600162
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600163 void reinit(VkObject obj, VkObjectType object_type, bool own);
164 void reinit(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600165
166 // allocate and bind internal memories
Courtney Goeltzenleuchter30a39452015-04-22 10:02:41 -0600167 void alloc_memory();
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600168 void alloc_memory(VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchter30a39452015-04-22 10:02:41 -0600169 void alloc_memory(const std::vector<VkDeviceMemory> &mems);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600170
171private:
172 void cleanup();
173
174 uint32_t mem_alloc_count_;
175 GpuMemory *internal_mems_;
176 GpuMemory *primary_mem_;
Tony Barbour44bb3ab2015-04-09 16:00:18 -0600177 bool bound;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600178};
179
180class DynamicStateObject : public Object {
181public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600182 const VkDynamicStateObject &obj() const { return reinterpret_cast<const VkDynamicStateObject &>(Object::obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600183
184protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600185 explicit DynamicStateObject() : Object() {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600186};
187
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600188template<typename T, class C, VkObjectType V>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189class DerivedObject : public C {
190public:
191 const T &obj() const { return reinterpret_cast<const T &>(C::obj()); }
192
193protected:
194 typedef T obj_type;
195 typedef C base_type;
196
197 explicit DerivedObject() {}
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600198 explicit DerivedObject(T obj) : C(obj, V) {}
199 explicit DerivedObject(const Device &dev, T obj) : C(dev, obj, V) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600200};
201
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600202class Device : public DerivedObject<VkDevice, BaseObject, VK_OBJECT_TYPE_DEVICE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600203public:
Tony Barbourd1c35722015-04-16 15:59:00 -0600204 explicit Device(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600205 ~Device();
206
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600207 VkDevice device() const { return obj(); }
208
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600209 // vkCreateDevice()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600210 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600211 void init(std::vector<VkExtensionProperties> extensions); // all queues, all extensions, etc
212 void init() { std::vector<VkExtensionProperties> extensions; init(extensions); };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600213
214 const PhysicalGpu &gpu() const { return gpu_; }
215
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600216 // vkGetDeviceProcAddr()
217 void *get_proc(const char *name) const { return vkGetDeviceProcAddr(obj(), name); }
218
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219 // vkGetDeviceQueue()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500220 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600221 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
222 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
223 uint32_t graphics_queue_node_index_;
224
225 struct Format {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600226 VkFormat format;
227 VkImageTiling tiling;
228 VkFlags features;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600229 };
230 // vkGetFormatInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600231 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600232 const std::vector<Format> &formats() const { return formats_; }
233
234 // vkDeviceWaitIdle()
235 void wait();
236
237 // vkWaitForFences()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600238 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
239 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800241 // vkUpdateDescriptorSets()
242 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
243 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
244
245 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
246 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors);
247 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
248 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors);
249
250 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
251 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
252 uint32_t count);
253
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600254private:
255 enum QueueIndex {
256 GRAPHICS,
257 COMPUTE,
258 DMA,
259 QUEUE_COUNT,
260 };
261
262 void init_queues();
263 void init_formats();
264
265 PhysicalGpu gpu_;
266
267 std::vector<Queue *> queues_[QUEUE_COUNT];
268 std::vector<Format> formats_;
269};
270
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600271class Queue : public DerivedObject<VkQueue, BaseObject, VK_OBJECT_TYPE_QUEUE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600272public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600273 explicit Queue(VkQueue queue) : DerivedObject(queue) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600274
275 // vkQueueSubmit()
276 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
277 void submit(const CmdBuffer &cmd, Fence &fence);
278 void submit(const CmdBuffer &cmd);
279
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600280 // vkQueueAddMemReferences()
281 // vkQueueRemoveMemReferences()
Tony Barbourd1c35722015-04-16 15:59:00 -0600282 void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
283 void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600284
285 // vkQueueWaitIdle()
286 void wait();
287
288 // vkQueueSignalSemaphore()
289 // vkQueueWaitSemaphore()
290 void signal_semaphore(Semaphore &sem);
291 void wait_semaphore(Semaphore &sem);
292};
293
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600294/* Note: This needs to be BaseObject so that we don't try to destroy
295 * the object when the object is device memory.
296 */
297class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject, VK_OBJECT_TYPE_DEVICE_MEMORY> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600298public:
299 ~GpuMemory();
300
301 // vkAllocMemory()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600302 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600303 // vkPinSystemMemory()
304 void init(const Device &dev, size_t size, const void *data);
305 // vkOpenSharedMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600306 void init(const Device &dev, const VkMemoryOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307 // vkOpenPeerMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600308 void init(const Device &dev, const VkPeerMemoryOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600310 void init(const Device &dev, VkDeviceMemory mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311
312 // vkSetMemoryPriority()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600313 void set_priority(VkMemoryPriority priority);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600314
315 // vkMapMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600316 const void *map(VkFlags flags) const;
317 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600318 const void *map() const { return map(0); }
319 void *map() { return map(0); }
320
321 // vkUnmapMemory()
322 void unmap() const;
323
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600324 static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600325 const VkMemoryAllocInfo *next_info);
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600326private:
327 const Device* dev_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600328};
329
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600330class Fence : public DerivedObject<VkFence, Object, VK_OBJECT_TYPE_FENCE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600331public:
332 // vkCreateFence()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600333 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600334
335 // vkGetFenceStatus()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600336 VkResult status() const { return vkGetFenceStatus(dev_->obj(), obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600337
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600338 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
339 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340};
341
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600342class Semaphore : public DerivedObject<VkSemaphore, Object, VK_OBJECT_TYPE_SEMAPHORE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600343public:
344 // vkCreateSemaphore()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600345 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600346 // vkOpenSharedSemaphore()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600347 void init(const Device &dev, const VkSemaphoreOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600348
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600349 static VkSemaphoreCreateInfo create_info(uint32_t init_count, VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350};
351
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600352class Event : public DerivedObject<VkEvent, Object, VK_OBJECT_TYPE_EVENT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600353public:
354 // vkCreateEvent()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600355 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600356
357 // vkGetEventStatus()
358 // vkSetEvent()
359 // vkResetEvent()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600360 VkResult status() const { return vkGetEventStatus(dev_->obj(), obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600361 void set();
362 void reset();
363
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600364 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365};
366
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600367class QueryPool : public DerivedObject<VkQueryPool, Object, VK_OBJECT_TYPE_QUERY_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368public:
369 // vkCreateQueryPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600370 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600371
372 // vkGetQueryPoolResults()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600373 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600374
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600375 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600376};
377
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600378class Buffer : public DerivedObject<VkBuffer, Object, VK_OBJECT_TYPE_BUFFER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600379public:
380 explicit Buffer() {}
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600381 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbourd1c35722015-04-16 15:59:00 -0600382 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600383
384 // vkCreateBuffer()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600385 void init(const Device &dev, const VkBufferCreateInfo &info);
Tony Barbourd1c35722015-04-16 15:59:00 -0600386 void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); }
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600387 void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, 0), reqs); }
388 void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600389 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600390
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500391 // vkQueueBindSparseBufferMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500392 void bind_memory(VkDeviceSize offset, VkDeviceSize size,
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500393 const GpuMemory &mem, VkDeviceSize mem_offset);
394
Tony Barbourd1c35722015-04-16 15:59:00 -0600395 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600396
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbourd1c35722015-04-16 15:59:00 -0600398 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600399 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600400 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600401 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
402 barrier.buffer = obj();
403 barrier.outputMask = output_mask;
404 barrier.inputMask = input_mask;
405 barrier.offset = offset;
406 barrier.size = size;
407 return barrier;
408 }
409private:
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600410 VkBufferCreateInfo create_info_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600411};
412
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600413class BufferView : public DerivedObject<VkBufferView, Object, VK_OBJECT_TYPE_BUFFER_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600414public:
415 // vkCreateBufferView()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600416 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600417};
418
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600419class Image : public DerivedObject<VkImage, Object, VK_OBJECT_TYPE_IMAGE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600420public:
421 explicit Image() : format_features_(0) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600422 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600423
424 // vkCreateImage()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600425 void init(const Device &dev, const VkImageCreateInfo &info);
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600426 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600427 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 // vkOpenPeerImage()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600429 void init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600430
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500431 // vkQueueBindSparseImageMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500432 void bind_memory(const Device &dev, const VkImageMemoryBindInfo &info,
Tony Barbourd1c35722015-04-16 15:59:00 -0600433 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600434
435 // vkGetImageSubresourceInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600436 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600437
438 bool transparent() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600439 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600440
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600441 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
442 VkExtent3D extent() const { return create_info_.extent; }
443 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
444 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600445
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600446 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
447 VkImageLayout old_layout,
448 VkImageLayout new_layout,
449 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600450 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600451 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600452 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
453 barrier.outputMask = output_mask;
454 barrier.inputMask = input_mask;
455 barrier.oldLayout = old_layout;
456 barrier.newLayout = new_layout;
457 barrier.image = obj();
458 barrier.subresourceRange = range;
459 return barrier;
460 }
461
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600462 static VkImageCreateInfo create_info();
463 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
464 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
465 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600466 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600467 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
468 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600469
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600470 static VkExtent2D extent(int32_t width, int32_t height);
471 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
472 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600473
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600474 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
475 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476
477private:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600478 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600479
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600480 VkImageCreateInfo create_info_;
481 VkFlags format_features_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600482};
483
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600484class ImageView : public DerivedObject<VkImageView, Object, VK_OBJECT_TYPE_IMAGE_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600485public:
486 // vkCreateImageView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600487 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600488};
489
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600490class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object, VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600491public:
492 // vkCreateColorAttachmentView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493 void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600494};
495
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600496class DepthStencilView : public DerivedObject<VkDepthStencilView, Object, VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600497public:
498 // vkCreateDepthStencilView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600499 void init(const Device &dev, const VkDepthStencilViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600500};
501
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600502class Shader : public DerivedObject<VkShader, Object, VK_OBJECT_TYPE_SHADER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600503public:
504 // vkCreateShader()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600505 void init(const Device &dev, const VkShaderCreateInfo &info);
506 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600507
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600508 static VkShaderCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600509};
510
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600511class Pipeline : public DerivedObject<VkPipeline, Object, VK_OBJECT_TYPE_PIPELINE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512public:
513 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600514 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600515 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600516 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600517 // vkCreateComputePipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600518 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600519 // vkLoadPipeline()
520 void init(const Device&dev, size_t size, const void *data);
521 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600522 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600523
Chris Forbes95292b12015-05-25 11:13:26 +1200524 // vkCreateGraphicsPipeline with error return
525 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
526
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600527 // vkStorePipeline()
528 size_t store(size_t size, void *data);
529};
530
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600531class Sampler : public DerivedObject<VkSampler, Object, VK_OBJECT_TYPE_SAMPLER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600532public:
533 // vkCreateSampler()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600534 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600535};
536
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600537class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600538public:
539 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600540 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600541};
542
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600543class PipelineLayout : public DerivedObject<VkPipelineLayout, Object, VK_OBJECT_TYPE_PIPELINE_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600544public:
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500545 // vCreatePipelineLayout()
546 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600547};
548
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600549class DescriptorPool : public DerivedObject<VkDescriptorPool, Object, VK_OBJECT_TYPE_DESCRIPTOR_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600550public:
551 // vkCreateDescriptorPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600552 void init(const Device &dev, VkDescriptorPoolUsage usage,
553 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600554
555 // vkResetDescriptorPool()
556 void reset();
557
558 // vkAllocDescriptorSets()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500559 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
560 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
561 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600562
563 // vkClearDescriptorSets()
564 void clear_sets(const std::vector<DescriptorSet *> &sets);
565 void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); }
566};
567
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600568class DescriptorSet : public DerivedObject<VkDescriptorSet, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600569public:
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800570 explicit DescriptorSet() : DerivedObject() {}
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600571 explicit DescriptorSet(const Device &dev, VkDescriptorSet set) : DerivedObject(dev, set) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600572};
573
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600574class DynamicVpStateObject : public DerivedObject<VkDynamicVpState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_VP_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600575public:
576 // vkCreateDynamicViewportState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600577 void init(const Device &dev, const VkDynamicVpStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600578};
579
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600580class DynamicRsStateObject : public DerivedObject<VkDynamicRsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_RS_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600581public:
582 // vkCreateDynamicRasterState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600583 void init(const Device &dev, const VkDynamicRsStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600584};
585
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600586class DynamicCbStateObject : public DerivedObject<VkDynamicCbState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_CB_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587public:
588 // vkCreateDynamicColorBlendState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600589 void init(const Device &dev, const VkDynamicCbStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600590};
591
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600592class DynamicDsStateObject : public DerivedObject<VkDynamicDsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_DS_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600593public:
594 // vkCreateDynamicDepthStencilState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600595 void init(const Device &dev, const VkDynamicDsStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600596};
597
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600598class CmdBuffer : public DerivedObject<VkCmdBuffer, Object, VK_OBJECT_TYPE_COMMAND_BUFFER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600599public:
600 explicit CmdBuffer() {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600601 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600602
603 // vkCreateCommandBuffer()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600604 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600605
606 // vkBeginCommandBuffer()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600607 void begin(const VkCmdBufferBeginInfo *info);
608 void begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600609 void begin();
610
611 // vkEndCommandBuffer()
612 // vkResetCommandBuffer()
613 void end();
614 void reset();
615
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600616 static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600617};
618
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600619inline const void *Object::map(VkFlags flags) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600620{
621 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
622}
623
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600624inline void *Object::map(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600625{
626 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
627}
628
629inline void Object::unmap() const
630{
631 if (primary_mem_)
632 primary_mem_->unmap();
633}
634
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600635inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600636 const VkMemoryAllocInfo *next_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600637{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600638 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
640 if (next_info != NULL)
641 info.pNext = (void *) next_info;
642
643 info.allocationSize = reqs.size;
Jeremy Hayes38ce2b12015-04-15 14:17:56 -0600644 info.memProps = reqs.memPropsRequired;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
646 return info;
647}
648
Tony Barbourd1c35722015-04-16 15:59:00 -0600649inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600650{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600651 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600652 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
653 info.size = size;
654 info.usage = usage;
655 return info;
656}
657
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600658inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600659{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600660 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600661 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
662 info.flags = flags;
663 return info;
664}
665
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600666inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600667{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600668 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600669 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
670 return info;
671}
672
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600673inline VkSemaphoreCreateInfo Semaphore::create_info(uint32_t init_count, VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600674{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600675 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600676 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
677 info.initialCount = init_count;
678 info.flags = flags;
679 return info;
680}
681
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600682inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600683{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600684 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
686 info.flags = flags;
687 return info;
688}
689
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600690inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600691{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600692 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600693 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
694 info.queryType = type;
695 info.slots = slot_count;
696 return info;
697}
698
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600699inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600700{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600701 VkImageCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600702 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
703 info.extent.width = 1;
704 info.extent.height = 1;
705 info.extent.depth = 1;
706 info.mipLevels = 1;
707 info.arraySize = 1;
708 info.samples = 1;
709 return info;
710}
711
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600712inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600713{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600714 VkImageSubresource subres = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600715 subres.aspect = aspect;
716 subres.mipLevel = mip_level;
717 subres.arraySlice = array_slice;
718 return subres;
719}
720
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600721inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600722{
723 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
724}
725
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600726inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600727 uint32_t base_array_slice, uint32_t array_size)
728{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600729 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600730 range.aspect = aspect;
731 range.baseMipLevel = base_mip_level;
732 range.mipLevels = mip_levels;
733 range.baseArraySlice = base_array_slice;
734 range.arraySize = array_size;
735 return range;
736}
737
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600738inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600739{
740 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
741}
742
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600743inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600744{
745 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
746}
747
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600748inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600749{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600750 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600751 extent.width = width;
752 extent.height = height;
753 return extent;
754}
755
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600756inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600757{
758 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 return Image::extent(width, height);
761}
762
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600763inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600764{
765 return Image::extent(extent.width, extent.height);
766}
767
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600768inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600769{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600770 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600771 extent.width = width;
772 extent.height = height;
773 extent.depth = depth;
774 return extent;
775}
776
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600777inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600778{
779 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
780 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
781 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
782 return Image::extent(width, height, depth);
783}
784
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600785inline VkShaderCreateInfo Shader::create_info(size_t code_size, const void *code, VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600786{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600787 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600788 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
789 info.codeSize = code_size;
790 info.pCode = code;
791 info.flags = flags;
792 return info;
793}
794
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800795inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
796 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600797{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800798 VkWriteDescriptorSet write = {};
799 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
800 write.destSet = set.obj();
801 write.destBinding = binding;
802 write.destArrayElement = array_element;
803 write.count = count;
804 write.descriptorType = type;
805 write.pDescriptors = descriptors;
806 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600807}
808
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800809inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
810 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600811{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800812 return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600813}
814
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800815inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
816 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
817 uint32_t count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600818{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800819 VkCopyDescriptorSet copy = {};
820 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
821 copy.srcSet = src_set.obj();
822 copy.srcBinding = src_binding;
823 copy.srcArrayElement = src_array_element;
824 copy.destSet = dst_set.obj();
825 copy.destBinding = dst_binding;
826 copy.destArrayElement = dst_array_element;
827 copy.count = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600828
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800829 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600830}
831
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600832inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600833{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600834 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600835 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
836 info.queueNodeIndex = queueNodeIndex;
837 return info;
838}
839
840}; // namespace vk_testing
841
842#endif // VKTESTBINDING_H