blob: ec131105ccde32d667c9fc994c8b93101e73f79b [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
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060067std::vector<VkLayerProperties> GetGlobalLayers();
68std::vector<VkExtensionProperties> GetGlobalExtensions();
69std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
70
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060071class PhysicalGpu {
72public:
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -060073 explicit PhysicalGpu(VkPhysicalDevice gpu) : gpu_(gpu)
74 {
75 memory_properties_ = memory_properties();
76 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060077
Tony Barbourd1c35722015-04-16 15:59:00 -060078 const VkPhysicalDevice &obj() const { return gpu_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060079
Tony Barbourd1c35722015-04-16 15:59:00 -060080 VkPhysicalDeviceProperties properties() const;
81 VkPhysicalDevicePerformance performance() const;
82 VkPhysicalDeviceMemoryProperties memory_properties() const;
83 std::vector<VkPhysicalDeviceQueueProperties> queue_properties() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060084
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -060085 VkResult set_memory_type(const uint32_t type_bits, VkMemoryAllocInfo *info, const VkMemoryPropertyFlags properties) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060086
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060087 // vkGetPhysicalDeviceExtensionProperties()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060088 std::vector<VkExtensionProperties> extensions() const;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060089 std::vector<VkExtensionProperties> extensions(const char * pLayerName) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060090
91 // vkEnumerateLayers()
92 std::vector<const char *> layers(std::vector<char> &buf) const;
93
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094private:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060095 void add_extension_dependencies(uint32_t dependency_count,
96 VkExtensionProperties *depencency_props,
97 std::vector<VkExtensionProperties> &ext_list);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -060098 VkPhysicalDeviceMemoryProperties memory_properties_;
Tony Barbourd1c35722015-04-16 15:59:00 -060099 VkPhysicalDevice gpu_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600100};
101
102class BaseObject {
103public:
Mike Stroyanb050c682015-04-17 12:36:38 -0600104 const VkObject &obj() const { return obj_; }
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600105 VkObjectType type() const { return object_type_; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600106 bool initialized() const { return (obj_ != VK_NULL_HANDLE); }
107
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600108protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600109 explicit BaseObject() :
110 object_type_((VkObjectType) 0), obj_(VK_NULL_HANDLE), own_obj_(false){}
111 explicit BaseObject(VkObject obj, VkObjectType object_type) :
112 object_type_(object_type), obj_(obj), own_obj_(false){}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600113
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600114 void init(VkObject obj, VkObjectType object_type, bool own);
115 void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600116
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600117 void reinit(VkObject obj, VkObjectType object_type, bool own);
118 void reinit(VkObject obj, VkObjectType object_type) { reinit(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600119
120 bool own() const { return own_obj_; }
121
122private:
123 // base objects are non-copyable
124 BaseObject(const BaseObject &);
125 BaseObject &operator=(const BaseObject &);
126
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600127 VkObjectType object_type_;
Mike Stroyanb050c682015-04-17 12:36:38 -0600128 VkObject obj_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600129 bool own_obj_;
130};
131
132class Object : public BaseObject {
133public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600134 const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600135
Tony Barbour59a47322015-06-24 16:06:58 -0600136 // vkGetObjectMemoryRequirements()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600137 uint32_t memory_allocation_count() const;
138 std::vector<VkMemoryRequirements> memory_requirements() const;
139
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500140 // vkBindObjectMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500141 void bind_memory(const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600142
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600143 // Unless an object is initialized with init_no_mem(), memories are
Courtney Goeltzenleuchterb66f5fd2015-05-01 17:56:13 -0600144 // automatically allocated and bound. These methods can be used to
145 // map/unmap the primary memory.
Tony Barbourd1c35722015-04-16 15:59:00 -0600146 std::vector<VkDeviceMemory> memories() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600147
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600148 const void *map(VkFlags flags) const;
149 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600150 const void *map() const { return map(0); }
151 void *map() { return map(0); }
152
153 void unmap() const;
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500154 const Device* dev_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600155
156protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600157 explicit Object() :
158 mem_alloc_count_(0), internal_mems_(NULL),
159 primary_mem_(NULL), bound(false) {}
160 explicit Object(const Device &dev, VkObject obj, VkObjectType object_type) :
161 dev_(&dev),
162 mem_alloc_count_(0), internal_mems_(NULL),
Chris Forbes94ba49d2015-05-25 11:13:03 +1200163 primary_mem_(NULL), bound(false) { init(obj, object_type); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600164 ~Object() { cleanup(); }
165
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600166 void init(VkObject obj, VkObjectType object_type, bool own);
167 void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600168
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600169 void reinit(VkObject obj, VkObjectType object_type, bool own);
170 void reinit(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600171
172 // allocate and bind internal memories
Courtney Goeltzenleuchter30a39452015-04-22 10:02:41 -0600173 void alloc_memory();
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600174 void alloc_memory(VkMemoryPropertyFlags &reqs);
Courtney Goeltzenleuchter30a39452015-04-22 10:02:41 -0600175 void alloc_memory(const std::vector<VkDeviceMemory> &mems);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600176
177private:
178 void cleanup();
179
180 uint32_t mem_alloc_count_;
181 GpuMemory *internal_mems_;
182 GpuMemory *primary_mem_;
Tony Barbour44bb3ab2015-04-09 16:00:18 -0600183 bool bound;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600184};
185
186class DynamicStateObject : public Object {
187public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600188 const VkDynamicStateObject &obj() const { return reinterpret_cast<const VkDynamicStateObject &>(Object::obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189
190protected:
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600191 explicit DynamicStateObject() : Object() {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600192};
193
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600194template<typename T, class C, VkObjectType V>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600195class DerivedObject : public C {
196public:
197 const T &obj() const { return reinterpret_cast<const T &>(C::obj()); }
198
199protected:
200 typedef T obj_type;
201 typedef C base_type;
202
203 explicit DerivedObject() {}
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600204 explicit DerivedObject(T obj) : C(obj, V) {}
205 explicit DerivedObject(const Device &dev, T obj) : C(dev, obj, V) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600206};
207
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600208class Device : public DerivedObject<VkDevice, BaseObject, VK_OBJECT_TYPE_DEVICE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600209public:
Tony Barbourd1c35722015-04-16 15:59:00 -0600210 explicit Device(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600211 ~Device();
212
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600213 VkDevice device() const { return obj(); }
214
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600215 // vkCreateDevice()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600216 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600217 void init(std::vector<const char *> &extensions); // all queues, all extensions, etc
218 void init() { std::vector<const char *> extensions; init(extensions); };
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219
220 const PhysicalGpu &gpu() const { return gpu_; }
221
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600222 // vkGetDeviceProcAddr()
223 void *get_proc(const char *name) const { return vkGetDeviceProcAddr(obj(), name); }
224
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600225 // vkGetDeviceQueue()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500226 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600227 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
228 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
229 uint32_t graphics_queue_node_index_;
230
231 struct Format {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600232 VkFormat format;
233 VkImageTiling tiling;
234 VkFlags features;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600235 };
236 // vkGetFormatInfo()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600237 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238 const std::vector<Format> &formats() const { return formats_; }
239
240 // vkDeviceWaitIdle()
241 void wait();
242
243 // vkWaitForFences()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600244 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
245 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600246
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800247 // vkUpdateDescriptorSets()
248 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
249 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
250
251 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
252 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors);
253 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
254 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors);
255
256 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
257 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
258 uint32_t count);
259
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600260private:
261 enum QueueIndex {
262 GRAPHICS,
263 COMPUTE,
264 DMA,
265 QUEUE_COUNT,
266 };
267
268 void init_queues();
269 void init_formats();
270
271 PhysicalGpu gpu_;
272
273 std::vector<Queue *> queues_[QUEUE_COUNT];
274 std::vector<Format> formats_;
275};
276
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600277class Queue : public DerivedObject<VkQueue, BaseObject, VK_OBJECT_TYPE_QUEUE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600278public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600279 explicit Queue(VkQueue queue) : DerivedObject(queue) {}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600280
281 // vkQueueSubmit()
282 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
283 void submit(const CmdBuffer &cmd, Fence &fence);
284 void submit(const CmdBuffer &cmd);
285
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600286 // vkQueueAddMemReferences()
287 // vkQueueRemoveMemReferences()
Tony Barbourd1c35722015-04-16 15:59:00 -0600288 void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
289 void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600290
291 // vkQueueWaitIdle()
292 void wait();
293
294 // vkQueueSignalSemaphore()
295 // vkQueueWaitSemaphore()
296 void signal_semaphore(Semaphore &sem);
297 void wait_semaphore(Semaphore &sem);
298};
299
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600300/* Note: This needs to be BaseObject so that we don't try to destroy
301 * the object when the object is device memory.
302 */
303class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject, VK_OBJECT_TYPE_DEVICE_MEMORY> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600304public:
305 ~GpuMemory();
306
307 // vkAllocMemory()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600308 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600309 void init(const Device &dev, VkDeviceMemory mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600310
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311 // vkMapMemory()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600312 const void *map(VkFlags flags) const;
313 void *map(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600314 const void *map() const { return map(0); }
315 void *map() { return map(0); }
316
317 // vkUnmapMemory()
318 void unmap() const;
319
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600320 static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs,
321 const VkMemoryAllocInfo *next_info);
322
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
Tony Barbouraf892a12015-06-26 12:56:09 -0600344 static VkSemaphoreCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600345};
346
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600347class Event : public DerivedObject<VkEvent, Object, VK_OBJECT_TYPE_EVENT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600348public:
349 // vkCreateEvent()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600350 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600351
352 // vkGetEventStatus()
353 // vkSetEvent()
354 // vkResetEvent()
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600355 VkResult status() const { return vkGetEventStatus(dev_->obj(), obj()); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600356 void set();
357 void reset();
358
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600359 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600360};
361
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600362class QueryPool : public DerivedObject<VkQueryPool, Object, VK_OBJECT_TYPE_QUERY_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600363public:
364 // vkCreateQueryPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600365 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600366
367 // vkGetQueryPoolResults()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600368 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600369
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600370 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600371};
372
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600373class Buffer : public DerivedObject<VkBuffer, Object, VK_OBJECT_TYPE_BUFFER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600374public:
375 explicit Buffer() {}
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600376 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbourd1c35722015-04-16 15:59:00 -0600377 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600378
379 // vkCreateBuffer()
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600380 void init(const Device &dev, const VkBufferCreateInfo &info);
Tony Barbourd1c35722015-04-16 15:59:00 -0600381 void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); }
Cody Northrop7fb43862015-06-22 14:56:14 -0600382 void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT), reqs); }
383 void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); }
384 void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT | VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); }
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600385 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
Mark Lobodzinski942b1722015-05-11 17:21:15 -0500426 // vkQueueBindSparseImageMemory()
Mark Lobodzinski23065352015-05-29 09:32:35 -0500427 void bind_memory(const Device &dev, const VkImageMemoryBindInfo &info,
Tony Barbourd1c35722015-04-16 15:59:00 -0600428 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600429
Tony Barbour59a47322015-06-24 16:06:58 -0600430 // vkGetImageSubresourceLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600431 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600432
433 bool transparent() const;
Tony Barbourd1c35722015-04-16 15:59:00 -0600434 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600435
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600436 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
437 VkExtent3D extent() const { return create_info_.extent; }
438 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
439 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600440
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600441 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
442 VkImageLayout old_layout,
443 VkImageLayout new_layout,
444 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600445 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600446 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
448 barrier.outputMask = output_mask;
449 barrier.inputMask = input_mask;
450 barrier.oldLayout = old_layout;
451 barrier.newLayout = new_layout;
452 barrier.image = obj();
453 barrier.subresourceRange = range;
454 return barrier;
455 }
456
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600457 static VkImageCreateInfo create_info();
458 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
459 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
460 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600461 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600462 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
463 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600464
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600465 static VkExtent2D extent(int32_t width, int32_t height);
466 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
467 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600468
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600469 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
470 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600471
472private:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600473 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600474
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600475 VkImageCreateInfo create_info_;
476 VkFlags format_features_;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600477};
478
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600479class ImageView : public DerivedObject<VkImageView, Object, VK_OBJECT_TYPE_IMAGE_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600480public:
481 // vkCreateImageView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600482 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600483};
484
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600485class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object, VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600486public:
487 // vkCreateColorAttachmentView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600488 void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600489};
490
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600491class DepthStencilView : public DerivedObject<VkDepthStencilView, Object, VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600492public:
493 // vkCreateDepthStencilView()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600494 void init(const Device &dev, const VkDepthStencilViewCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600495};
496
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600497class ShaderModule : public DerivedObject<VkShaderModule, Object, VK_OBJECT_TYPE_SHADER_MODULE> {
498public:
499 // vkCreateShaderModule()
500 void init(const Device &dev, const VkShaderModuleCreateInfo &info);
501 VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
502
503 static VkShaderModuleCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
504};
505
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600506class Shader : public DerivedObject<VkShader, Object, VK_OBJECT_TYPE_SHADER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600507public:
508 // vkCreateShader()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600509 void init(const Device &dev, const VkShaderCreateInfo &info);
510 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600511
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600512 static VkShaderCreateInfo create_info(VkShaderModule module, const char *pName, VkFlags flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600513};
514
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600515class Pipeline : public DerivedObject<VkPipeline, Object, VK_OBJECT_TYPE_PIPELINE> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600516public:
517 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600518 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600519 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600520 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600521 // vkCreateComputePipeline()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600522 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600523 // vkLoadPipeline()
524 void init(const Device&dev, size_t size, const void *data);
525 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600526 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600527
Chris Forbes95292b12015-05-25 11:13:26 +1200528 // vkCreateGraphicsPipeline with error return
529 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
530
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600531 // vkStorePipeline()
532 size_t store(size_t size, void *data);
533};
534
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600535class Sampler : public DerivedObject<VkSampler, Object, VK_OBJECT_TYPE_SAMPLER> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600536public:
537 // vkCreateSampler()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600538 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600539};
540
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600541class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600542public:
543 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600544 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600545};
546
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600547class PipelineLayout : public DerivedObject<VkPipelineLayout, Object, VK_OBJECT_TYPE_PIPELINE_LAYOUT> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600548public:
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500549 // vCreatePipelineLayout()
550 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600551};
552
Courtney Goeltzenleuchter992fb4f2015-04-19 19:07:33 -0600553class DescriptorPool : public DerivedObject<VkDescriptorPool, Object, VK_OBJECT_TYPE_DESCRIPTOR_POOL> {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600554public:
555 // vkCreateDescriptorPool()
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600556 void init(const Device &dev, VkDescriptorPoolUsage usage,
557 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600558
559 // vkResetDescriptorPool()
560 void reset();
561
562 // vkAllocDescriptorSets()
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500563 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
564 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
565 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600566};
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);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600608 void begin();
609
610 // vkEndCommandBuffer()
611 // vkResetCommandBuffer()
612 void end();
613 void reset();
614
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600615 static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600616};
617
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600618inline const void *Object::map(VkFlags flags) const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619{
620 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
621}
622
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600623inline void *Object::map(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600624{
625 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
626}
627
628inline void Object::unmap() const
629{
630 if (primary_mem_)
631 primary_mem_->unmap();
632}
633
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600634inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs,
635 const VkMemoryAllocInfo *next_info)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600636{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600637 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600638 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
639 if (next_info != NULL)
640 info.pNext = (void *) next_info;
641
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600642 info.allocationSize = reqs.size;
643 info.memoryTypeIndex = 0;
644
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 return info;
646}
647
Tony Barbourd1c35722015-04-16 15:59:00 -0600648inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600649{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600650 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600651 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
652 info.size = size;
653 info.usage = usage;
654 return info;
655}
656
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600657inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600658{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600659 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600660 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
661 info.flags = flags;
662 return info;
663}
664
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600665inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600666{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600667 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
669 return info;
670}
671
Tony Barbouraf892a12015-06-26 12:56:09 -0600672inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600673{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600674 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600675 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600676 info.flags = flags;
677 return info;
678}
679
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600680inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600681{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600682 VkEventCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600683 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
684 info.flags = flags;
685 return info;
686}
687
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600688inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600689{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600690 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600691 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
692 info.queryType = type;
693 info.slots = slot_count;
694 return info;
695}
696
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600697inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600698{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600699 VkImageCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600700 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
701 info.extent.width = 1;
702 info.extent.height = 1;
703 info.extent.depth = 1;
704 info.mipLevels = 1;
705 info.arraySize = 1;
706 info.samples = 1;
707 return info;
708}
709
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600710inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600711{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600712 VkImageSubresource subres = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600713 subres.aspect = aspect;
714 subres.mipLevel = mip_level;
715 subres.arraySlice = array_slice;
716 return subres;
717}
718
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600719inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600720{
721 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
722}
723
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600724inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600725 uint32_t base_array_slice, uint32_t array_size)
726{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600727 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600728 range.aspect = aspect;
729 range.baseMipLevel = base_mip_level;
730 range.mipLevels = mip_levels;
731 range.baseArraySlice = base_array_slice;
732 range.arraySize = array_size;
733 return range;
734}
735
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600736inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600737{
738 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
739}
740
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600741inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600742{
743 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
744}
745
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600746inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600747{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600748 VkExtent2D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600749 extent.width = width;
750 extent.height = height;
751 return extent;
752}
753
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600754inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600755{
756 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
757 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
758 return Image::extent(width, height);
759}
760
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600761inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600762{
763 return Image::extent(extent.width, extent.height);
764}
765
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600766inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600767{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600768 VkExtent3D extent = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600769 extent.width = width;
770 extent.height = height;
771 extent.depth = depth;
772 return extent;
773}
774
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600775inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600776{
777 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
778 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
779 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
780 return Image::extent(width, height, depth);
781}
782
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600783inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const void *code, VkFlags flags)
784{
785 VkShaderModuleCreateInfo info = {};
786 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
787 info.codeSize = code_size;
788 info.pCode = code;
789 info.flags = flags;
790 return info;
791}
792
793inline VkShaderCreateInfo Shader::create_info(VkShaderModule module, const char *pName, VkFlags flags)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600794{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600795 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600796 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600797 info.module = module;
798 info.pName = pName;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600799 info.flags = flags;
800 return info;
801}
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, uint32_t count, const VkDescriptorInfo *descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600805{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800806 VkWriteDescriptorSet write = {};
807 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
808 write.destSet = set.obj();
809 write.destBinding = binding;
810 write.destArrayElement = array_element;
811 write.count = count;
812 write.descriptorType = type;
813 write.pDescriptors = descriptors;
814 return write;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600815}
816
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800817inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
818 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600819{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800820 return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600821}
822
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800823inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
824 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
825 uint32_t count)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600826{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800827 VkCopyDescriptorSet copy = {};
828 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
829 copy.srcSet = src_set.obj();
830 copy.srcBinding = src_binding;
831 copy.srcArrayElement = src_array_element;
832 copy.destSet = dst_set.obj();
833 copy.destBinding = dst_binding;
834 copy.destArrayElement = dst_array_element;
835 copy.count = count;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600836
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800837 return copy;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600838}
839
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600840inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600841{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600842 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600843 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
844 info.queueNodeIndex = queueNodeIndex;
845 return info;
846}
847
848}; // namespace vk_testing
849
850#endif // VKTESTBINDING_H