blob: def76e25ed44acf3830dc2882a459b23a7f45214 [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
79 // vkGetProcAddr()
80 void *get_proc(const char *name) const { return vkGetProcAddr(gpu_, name); }
81
Tobin Ehlis3dd031b2015-04-16 10:13:25 -060082 // vkGetGlobalExtensionInfo()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083 std::vector<const char *> extensions() const;
84
85 // vkEnumerateLayers()
86 std::vector<const char *> layers(std::vector<char> &buf) const;
87
Tony Barbourd1c35722015-04-16 15:59:00 -060088 // vkGetMultiDeviceCompatibility()
89 VkPhysicalDeviceCompatibilityInfo compatibility(const PhysicalGpu &other) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060090
91private:
Tony Barbourd1c35722015-04-16 15:59:00 -060092 VkPhysicalDevice gpu_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060093};
94
95class BaseObject {
96public:
Mike Stroyanb050c682015-04-17 12:36:38 -060097 const VkObject &obj() const { return obj_; }
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -060098 VkObjectType type() const { return object_type_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060099 bool initialized() const { return (obj_ != VK_NULL_HANDLE); }
100
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600101protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600102 explicit BaseObject() :
103 object_type_((VkObjectType) 0), obj_(VK_NULL_HANDLE), own_obj_(false){}
104 explicit BaseObject(VkObject obj, VkObjectType object_type) :
105 object_type_(object_type), obj_(obj), own_obj_(false){}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600106
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600107 void init(VkObject obj, VkObjectType object_type, bool own);
108 void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600109
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600110 void reinit(VkObject obj, VkObjectType object_type, bool own);
111 void reinit(VkObject obj, VkObjectType object_type) { reinit(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112
113 bool own() const { return own_obj_; }
114
115private:
116 // base objects are non-copyable
117 BaseObject(const BaseObject &);
118 BaseObject &operator=(const BaseObject &);
119
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600120 VkObjectType object_type_;
Mike Stroyanb050c682015-04-17 12:36:38 -0600121 VkObject obj_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600122 bool own_obj_;
123};
124
125class Object : public BaseObject {
126public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600127 const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600128
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600129 // vkGetObjectInfo()
130 uint32_t memory_allocation_count() const;
131 std::vector<VkMemoryRequirements> memory_requirements() const;
132
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500133 // vkBindObjectMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500134 void bind_memory(const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter30a39452015-04-22 10:02:41 -0600135 void unbind_memory();
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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600211 void init(bool enable_layers); // all queues, all extensions, etc
212 void init() { init(false); };
213
214 const PhysicalGpu &gpu() const { return gpu_; }
215
216 // vkGetDeviceQueue()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500217 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600218 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
219 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
220 uint32_t graphics_queue_node_index_;
221
222 struct Format {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600223 VkFormat format;
224 VkImageTiling tiling;
225 VkFlags features;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600226 };
227 // vkGetFormatInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600228 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600229 const std::vector<Format> &formats() const { return formats_; }
230
231 // vkDeviceWaitIdle()
232 void wait();
233
234 // vkWaitForFences()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600235 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
236 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600237
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800238 // vkUpdateDescriptorSets()
239 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
240 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
241
242 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
243 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors);
244 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
245 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors);
246
247 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
248 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
249 uint32_t count);
250
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600251private:
252 enum QueueIndex {
253 GRAPHICS,
254 COMPUTE,
255 DMA,
256 QUEUE_COUNT,
257 };
258
259 void init_queues();
260 void init_formats();
261
262 PhysicalGpu gpu_;
263
264 std::vector<Queue *> queues_[QUEUE_COUNT];
265 std::vector<Format> formats_;
266};
267
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600268class Queue : public DerivedObject<VkQueue, BaseObject, VK_OBJECT_TYPE_QUEUE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600269public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600270 explicit Queue(VkQueue queue) : DerivedObject(queue) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600271
272 // vkQueueSubmit()
273 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
274 void submit(const CmdBuffer &cmd, Fence &fence);
275 void submit(const CmdBuffer &cmd);
276
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600277 // vkQueueAddMemReferences()
278 // vkQueueRemoveMemReferences()
Tony Barbourd1c35722015-04-16 15:59:00 -0600279 void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
280 void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281
282 // vkQueueWaitIdle()
283 void wait();
284
285 // vkQueueSignalSemaphore()
286 // vkQueueWaitSemaphore()
287 void signal_semaphore(Semaphore &sem);
288 void wait_semaphore(Semaphore &sem);
289};
290
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600291/* Note: This needs to be BaseObject so that we don't try to destroy
292 * the object when the object is device memory.
293 */
294class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject, VK_OBJECT_TYPE_DEVICE_MEMORY> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600295public:
296 ~GpuMemory();
297
298 // vkAllocMemory()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600299 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600300 // vkPinSystemMemory()
301 void init(const Device &dev, size_t size, const void *data);
302 // vkOpenSharedMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600303 void init(const Device &dev, const VkMemoryOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600304 // vkOpenPeerMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600305 void init(const Device &dev, const VkPeerMemoryOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600306
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600307 void init(const Device &dev, VkDeviceMemory mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308
309 // vkSetMemoryPriority()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600310 void set_priority(VkMemoryPriority priority);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311
312 // vkMapMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600313 const void *map(VkFlags flags) const;
314 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600315 const void *map() const { return map(0); }
316 void *map() { return map(0); }
317
318 // vkUnmapMemory()
319 void unmap() const;
320
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600321 static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600322 const VkMemoryAllocInfo *next_info);
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600323private:
324 const Device* dev_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600325};
326
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600327class Fence : public DerivedObject<VkFence, Object, VK_OBJECT_TYPE_FENCE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600328public:
329 // vkCreateFence()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600330 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600331
332 // vkGetFenceStatus()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600333 VkResult status() const { return vkGetFenceStatus(dev_->obj(), obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600334
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600335 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
336 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600337};
338
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600339class Semaphore : public DerivedObject<VkSemaphore, Object, VK_OBJECT_TYPE_SEMAPHORE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340public:
341 // vkCreateSemaphore()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600342 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600343 // vkOpenSharedSemaphore()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344 void init(const Device &dev, const VkSemaphoreOpenInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600345
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600346 static VkSemaphoreCreateInfo create_info(uint32_t init_count, VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600347};
348
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600349class Event : public DerivedObject<VkEvent, Object, VK_OBJECT_TYPE_EVENT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350public:
351 // vkCreateEvent()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600352 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600353
354 // vkGetEventStatus()
355 // vkSetEvent()
356 // vkResetEvent()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600357 VkResult status() const { return vkGetEventStatus(dev_->obj(), obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600358 void set();
359 void reset();
360
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600361 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600362};
363
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600364class QueryPool : public DerivedObject<VkQueryPool, Object, VK_OBJECT_TYPE_QUERY_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365public:
366 // vkCreateQueryPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600367 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368
369 // vkGetQueryPoolResults()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600370 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600371
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600372 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600373};
374
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600375class Buffer : public DerivedObject<VkBuffer, Object, VK_OBJECT_TYPE_BUFFER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600376public:
377 explicit Buffer() {}
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600378 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbourd1c35722015-04-16 15:59:00 -0600379 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600380
381 // vkCreateBuffer()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600382 void init(const Device &dev, const VkBufferCreateInfo &info);
Tony Barbourd1c35722015-04-16 15:59:00 -0600383 void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); }
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600384 void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, 0), reqs); }
385 void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600386 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600387
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500388 // vkQueueBindSparseBufferMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500389 void bind_memory(VkDeviceSize offset, VkDeviceSize size,
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500390 const GpuMemory &mem, VkDeviceSize mem_offset);
391
Tony Barbourd1c35722015-04-16 15:59:00 -0600392 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600393
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600394 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbourd1c35722015-04-16 15:59:00 -0600395 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600396 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600398 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
399 barrier.buffer = obj();
400 barrier.outputMask = output_mask;
401 barrier.inputMask = input_mask;
402 barrier.offset = offset;
403 barrier.size = size;
404 return barrier;
405 }
406private:
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600407 VkBufferCreateInfo create_info_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600408};
409
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600410class BufferView : public DerivedObject<VkBufferView, Object, VK_OBJECT_TYPE_BUFFER_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600411public:
412 // vkCreateBufferView()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600413 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600414};
415
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600416class Image : public DerivedObject<VkImage, Object, VK_OBJECT_TYPE_IMAGE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600417public:
418 explicit Image() : format_features_(0) {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600419 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600420
421 // vkCreateImage()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600422 void init(const Device &dev, const VkImageCreateInfo &info);
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600423 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600424 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600425 // vkOpenPeerImage()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600426 void init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600427
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500428 // vkQueueBindSparseImageMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500429 void bind_memory(const Device &dev, const VkImageMemoryBindInfo &info,
Tony Barbourd1c35722015-04-16 15:59:00 -0600430 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600431
432 // vkGetImageSubresourceInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600433 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600434
435 bool transparent() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600436 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600437
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600438 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
439 VkExtent3D extent() const { return create_info_.extent; }
440 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
441 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600442
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600443 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
444 VkImageLayout old_layout,
445 VkImageLayout new_layout,
446 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600448 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600449 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
450 barrier.outputMask = output_mask;
451 barrier.inputMask = input_mask;
452 barrier.oldLayout = old_layout;
453 barrier.newLayout = new_layout;
454 barrier.image = obj();
455 barrier.subresourceRange = range;
456 return barrier;
457 }
458
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600459 static VkImageCreateInfo create_info();
460 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
461 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
462 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600463 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600464 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
465 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600466
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600467 static VkExtent2D extent(int32_t width, int32_t height);
468 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
469 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600470
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600471 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
472 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600473
474private:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600475 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600477 VkImageCreateInfo create_info_;
478 VkFlags format_features_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600479};
480
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600481class ImageView : public DerivedObject<VkImageView, Object, VK_OBJECT_TYPE_IMAGE_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600482public:
483 // vkCreateImageView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600484 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600485};
486
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600487class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object, VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600488public:
489 // vkCreateColorAttachmentView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600490 void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600491};
492
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600493class DepthStencilView : public DerivedObject<VkDepthStencilView, Object, VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600494public:
495 // vkCreateDepthStencilView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600496 void init(const Device &dev, const VkDepthStencilViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600497};
498
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600499class Shader : public DerivedObject<VkShader, Object, VK_OBJECT_TYPE_SHADER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600500public:
501 // vkCreateShader()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600502 void init(const Device &dev, const VkShaderCreateInfo &info);
503 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600504
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600505 static VkShaderCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600506};
507
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600508class Pipeline : public DerivedObject<VkPipeline, Object, VK_OBJECT_TYPE_PIPELINE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600509public:
510 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600511 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600513 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600514 // vkCreateComputePipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600515 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600516 // vkLoadPipeline()
517 void init(const Device&dev, size_t size, const void *data);
518 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600519 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600520
521 // vkStorePipeline()
522 size_t store(size_t size, void *data);
523};
524
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600525class Sampler : public DerivedObject<VkSampler, Object, VK_OBJECT_TYPE_SAMPLER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600526public:
527 // vkCreateSampler()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600528 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600529};
530
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600531class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600532public:
533 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600534 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600535};
536
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600537class PipelineLayout : public DerivedObject<VkPipelineLayout, Object, VK_OBJECT_TYPE_PIPELINE_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600538public:
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500539 // vCreatePipelineLayout()
540 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600541};
542
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600543class DescriptorPool : public DerivedObject<VkDescriptorPool, Object, VK_OBJECT_TYPE_DESCRIPTOR_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600544public:
545 // vkCreateDescriptorPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600546 void init(const Device &dev, VkDescriptorPoolUsage usage,
547 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600548
549 // vkResetDescriptorPool()
550 void reset();
551
552 // vkAllocDescriptorSets()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500553 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
554 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
555 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600556
557 // vkClearDescriptorSets()
558 void clear_sets(const std::vector<DescriptorSet *> &sets);
559 void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); }
560};
561
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600562class DescriptorSet : public DerivedObject<VkDescriptorSet, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600563public:
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800564 explicit DescriptorSet() : DerivedObject() {}
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600565 explicit DescriptorSet(const Device &dev, VkDescriptorSet set) : DerivedObject(dev, set) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600566};
567
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600568class DynamicVpStateObject : public DerivedObject<VkDynamicVpState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_VP_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600569public:
570 // vkCreateDynamicViewportState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600571 void init(const Device &dev, const VkDynamicVpStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600572};
573
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600574class DynamicRsStateObject : public DerivedObject<VkDynamicRsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_RS_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600575public:
576 // vkCreateDynamicRasterState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600577 void init(const Device &dev, const VkDynamicRsStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600578};
579
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600580class DynamicCbStateObject : public DerivedObject<VkDynamicCbState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_CB_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600581public:
582 // vkCreateDynamicColorBlendState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600583 void init(const Device &dev, const VkDynamicCbStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600584};
585
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600586class DynamicDsStateObject : public DerivedObject<VkDynamicDsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_DS_STATE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587public:
588 // vkCreateDynamicDepthStencilState()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600589 void init(const Device &dev, const VkDynamicDsStateCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600590};
591
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600592class CmdBuffer : public DerivedObject<VkCmdBuffer, Object, VK_OBJECT_TYPE_COMMAND_BUFFER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600593public:
594 explicit CmdBuffer() {}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600595 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600596
597 // vkCreateCommandBuffer()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600598 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600599
600 // vkBeginCommandBuffer()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600601 void begin(const VkCmdBufferBeginInfo *info);
602 void begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600603 void begin();
604
605 // vkEndCommandBuffer()
606 // vkResetCommandBuffer()
607 void end();
608 void reset();
609
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600610 static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600611};
612
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600613inline const void *Object::map(VkFlags flags) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600614{
615 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
616}
617
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600618inline void *Object::map(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619{
620 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
621}
622
623inline void Object::unmap() const
624{
625 if (primary_mem_)
626 primary_mem_->unmap();
627}
628
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600629inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600630 const VkMemoryAllocInfo *next_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600631{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600632 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
634 if (next_info != NULL)
635 info.pNext = (void *) next_info;
636
637 info.allocationSize = reqs.size;
Jeremy Hayes38ce2b12015-04-15 14:17:56 -0600638 info.memProps = reqs.memPropsRequired;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
640 return info;
641}
642
Tony Barbourd1c35722015-04-16 15:59:00 -0600643inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600644{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600645 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600646 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
647 info.size = size;
648 info.usage = usage;
649 return info;
650}
651
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600652inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600653{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600654 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600655 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
656 info.flags = flags;
657 return info;
658}
659
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600660inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600661{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600662 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600663 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
664 return info;
665}
666
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600667inline VkSemaphoreCreateInfo Semaphore::create_info(uint32_t init_count, VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600669 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600670 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
671 info.initialCount = init_count;
672 info.flags = flags;
673 return info;
674}
675
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600676inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600677{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600678 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600679 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
680 info.flags = flags;
681 return info;
682}
683
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600684inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600686 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600687 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
688 info.queryType = type;
689 info.slots = slot_count;
690 return info;
691}
692
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600693inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600694{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600695 VkImageCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600696 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
697 info.extent.width = 1;
698 info.extent.height = 1;
699 info.extent.depth = 1;
700 info.mipLevels = 1;
701 info.arraySize = 1;
702 info.samples = 1;
703 return info;
704}
705
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600706inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600707{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600708 VkImageSubresource subres = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600709 subres.aspect = aspect;
710 subres.mipLevel = mip_level;
711 subres.arraySlice = array_slice;
712 return subres;
713}
714
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600715inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600716{
717 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
718}
719
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600720inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600721 uint32_t base_array_slice, uint32_t array_size)
722{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600723 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600724 range.aspect = aspect;
725 range.baseMipLevel = base_mip_level;
726 range.mipLevels = mip_levels;
727 range.baseArraySlice = base_array_slice;
728 range.arraySize = array_size;
729 return range;
730}
731
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600732inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600733{
734 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
735}
736
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600737inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600738{
739 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
740}
741
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600742inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600743{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600744 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600745 extent.width = width;
746 extent.height = height;
747 return extent;
748}
749
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600750inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600751{
752 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
753 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
754 return Image::extent(width, height);
755}
756
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600757inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600758{
759 return Image::extent(extent.width, extent.height);
760}
761
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600762inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600763{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600764 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600765 extent.width = width;
766 extent.height = height;
767 extent.depth = depth;
768 return extent;
769}
770
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600771inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600772{
773 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
774 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
775 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
776 return Image::extent(width, height, depth);
777}
778
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600779inline VkShaderCreateInfo Shader::create_info(size_t code_size, const void *code, VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600780{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600781 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600782 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
783 info.codeSize = code_size;
784 info.pCode = code;
785 info.flags = flags;
786 return info;
787}
788
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800789inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
790 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600791{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800792 VkWriteDescriptorSet write = {};
793 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
794 write.destSet = set.obj();
795 write.destBinding = binding;
796 write.destArrayElement = array_element;
797 write.count = count;
798 write.descriptorType = type;
799 write.pDescriptors = descriptors;
800 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600801}
802
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800803inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
804 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600805{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800806 return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600807}
808
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800809inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
810 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
811 uint32_t count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600812{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800813 VkCopyDescriptorSet copy = {};
814 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
815 copy.srcSet = src_set.obj();
816 copy.srcBinding = src_binding;
817 copy.srcArrayElement = src_array_element;
818 copy.destSet = dst_set.obj();
819 copy.destBinding = dst_binding;
820 copy.destArrayElement = dst_array_element;
821 copy.count = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600822
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800823 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600824}
825
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600826inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600827{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600828 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600829 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
830 info.queueNodeIndex = queueNodeIndex;
831 return info;
832}
833
834}; // namespace vk_testing
835
836#endif // VKTESTBINDING_H