blob: 530d3c6d8bbee84bec6a50dea32d66dfc8e99cd2 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-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 Lobodzinski556f7212015-04-17 14:11:39 -050057class PipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-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 Barbour8205d902015-04-16 15:59:00 -060069 explicit PhysicalGpu(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060070
Tony Barbour8205d902015-04-16 15:59:00 -060071 const VkPhysicalDevice &obj() const { return gpu_; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060072
Tony Barbour8205d902015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078
79 // vkGetProcAddr()
80 void *get_proc(const char *name) const { return vkGetProcAddr(gpu_, name); }
81
Tobin Ehlisf6cc4e72015-04-16 10:13:25 -060082 // vkGetGlobalExtensionInfo()
Courtney Goeltzenleuchter9cc421e2015-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 Barbour8205d902015-04-16 15:59:00 -060088 // vkGetMultiDeviceCompatibility()
89 VkPhysicalDeviceCompatibilityInfo compatibility(const PhysicalGpu &other) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090
91private:
Tony Barbour8205d902015-04-16 15:59:00 -060092 VkPhysicalDevice gpu_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060093};
94
95class BaseObject {
96public:
Mike Stroyan230e6252015-04-17 12:36:38 -060097 const VkObject &obj() const { return obj_; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 bool initialized() const { return (obj_ != VK_NULL_HANDLE); }
99
100 // vkGetObjectInfo()
101 uint32_t memory_allocation_count() const;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600102 std::vector<VkMemoryRequirements> memory_requirements() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600103
104protected:
105 explicit BaseObject() : obj_(VK_NULL_HANDLE), own_obj_(false) {}
Mike Stroyan230e6252015-04-17 12:36:38 -0600106 explicit BaseObject(VkObject obj) : obj_(VK_NULL_HANDLE), own_obj_(false) { init(obj); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600107
Mike Stroyan230e6252015-04-17 12:36:38 -0600108 void init(VkObject obj, bool own);
109 void init(VkObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110
Mike Stroyan230e6252015-04-17 12:36:38 -0600111 void reinit(VkObject obj, bool own);
112 void reinit(VkObject obj) { reinit(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113
114 bool own() const { return own_obj_; }
Mike Stroyan230e6252015-04-17 12:36:38 -0600115 VkDevice device() const { return device_; }
116 VkObjectType object_type_;
117 VkDevice device_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118
119private:
120 // base objects are non-copyable
121 BaseObject(const BaseObject &);
122 BaseObject &operator=(const BaseObject &);
123
Mike Stroyan230e6252015-04-17 12:36:38 -0600124 VkObject obj_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600125 bool own_obj_;
126};
127
128class Object : public BaseObject {
129public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130 const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500132 // vkQueueBindObjectMemory()
Tony Barbour8205d902015-04-16 15:59:00 -0600133 void bind_memory(const Device &dev, uint32_t alloc_idx, const GpuMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500134 void unbind_memory(const Device &dev, uint32_t alloc_idx);
135 void unbind_memory(const Device &dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500137 // vkQueueBindObjectMemoryRange()
Tony Barbour8205d902015-04-16 15:59:00 -0600138 void bind_memory(const Device &dev, uint32_t alloc_idx, VkDeviceSize offset, VkDeviceSize size,
139 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140
141 // Unless an object is initialized with init_no_mem(), memories are
142 // automatically allocated and bound. These methods can be used to get
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600143 // the memories (for vkQueueAddMemReferences), or to map/unmap the primary memory.
Tony Barbour8205d902015-04-16 15:59:00 -0600144 std::vector<VkDeviceMemory> memories() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600146 const void *map(VkFlags flags) const;
147 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148 const void *map() const { return map(0); }
149 void *map() { return map(0); }
150
151 void unmap() const;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500152 const Device* dev_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153
154protected:
Tony Barbour2b5fb342015-04-09 16:00:18 -0600155 explicit Object() : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL), bound(false) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 explicit Object(VkObject obj) : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL) { init(obj); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600157 ~Object() { cleanup(); }
158
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600159 void init(VkObject obj, bool own);
160 void init(VkObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600162 void reinit(VkObject obj, bool own);
163 void reinit(VkObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600164
165 // allocate and bind internal memories
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500166 void alloc_memory(const Device &dev);
Tony Barbour8205d902015-04-16 15:59:00 -0600167 void alloc_memory(const Device &dev, const std::vector<VkDeviceMemory> &mems);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600168
169private:
170 void cleanup();
171
172 uint32_t mem_alloc_count_;
173 GpuMemory *internal_mems_;
174 GpuMemory *primary_mem_;
Tony Barbour2b5fb342015-04-09 16:00:18 -0600175 bool bound;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600176};
177
178class DynamicStateObject : public Object {
179public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600180 const VkDynamicStateObject &obj() const { return reinterpret_cast<const VkDynamicStateObject &>(Object::obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600181
182protected:
183 explicit DynamicStateObject() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600184 explicit DynamicStateObject(VkDynamicStateObject obj) : Object(obj) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600185};
186
187template<typename T, class C>
188class DerivedObject : public C {
189public:
190 const T &obj() const { return reinterpret_cast<const T &>(C::obj()); }
191
192protected:
193 typedef T obj_type;
194 typedef C base_type;
195
196 explicit DerivedObject() {}
197 explicit DerivedObject(T obj) : C(obj) {}
198};
199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200class Device : public DerivedObject<VkDevice, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201public:
Tony Barbour8205d902015-04-16 15:59:00 -0600202 explicit Device(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600203 ~Device();
204
205 // vkCreateDevice()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600206 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600207 void init(bool enable_layers); // all queues, all extensions, etc
208 void init() { init(false); };
209
210 const PhysicalGpu &gpu() const { return gpu_; }
211
212 // vkGetDeviceQueue()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500213 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600214 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
215 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
216 uint32_t graphics_queue_node_index_;
217
218 struct Format {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 VkFormat format;
220 VkImageTiling tiling;
221 VkFlags features;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 };
223 // vkGetFormatInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600224 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600225 const std::vector<Format> &formats() const { return formats_; }
226
227 // vkDeviceWaitIdle()
228 void wait();
229
230 // vkWaitForFences()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
232 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233
234 // vkBeginDescriptorPoolUpdate()
235 // vkEndDescriptorPoolUpdate()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600236 void begin_descriptor_pool_update(VkDescriptorUpdateMode mode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600237 void end_descriptor_pool_update(CmdBuffer &cmd);
238
239private:
240 enum QueueIndex {
241 GRAPHICS,
242 COMPUTE,
243 DMA,
244 QUEUE_COUNT,
245 };
246
247 void init_queues();
248 void init_formats();
249
250 PhysicalGpu gpu_;
251
252 std::vector<Queue *> queues_[QUEUE_COUNT];
253 std::vector<Format> formats_;
254};
255
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600256class Queue : public DerivedObject<VkQueue, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600257public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600258 explicit Queue(VkQueue queue) : DerivedObject(queue) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600259
260 // vkQueueSubmit()
261 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
262 void submit(const CmdBuffer &cmd, Fence &fence);
263 void submit(const CmdBuffer &cmd);
264
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600265 // vkQueueAddMemReferences()
266 // vkQueueRemoveMemReferences()
Tony Barbour8205d902015-04-16 15:59:00 -0600267 void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
268 void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600269
270 // vkQueueWaitIdle()
271 void wait();
272
273 // vkQueueSignalSemaphore()
274 // vkQueueWaitSemaphore()
275 void signal_semaphore(Semaphore &sem);
276 void wait_semaphore(Semaphore &sem);
277};
278
Tony Barbour8205d902015-04-16 15:59:00 -0600279class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600280public:
281 ~GpuMemory();
282
283 // vkAllocMemory()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600284 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 // vkPinSystemMemory()
286 void init(const Device &dev, size_t size, const void *data);
287 // vkOpenSharedMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600288 void init(const Device &dev, const VkMemoryOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600289 // vkOpenPeerMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600290 void init(const Device &dev, const VkPeerMemoryOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600291
Tony Barbour8205d902015-04-16 15:59:00 -0600292 void init(VkDeviceMemory mem) { BaseObject::init(mem, false); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600293
294 // vkSetMemoryPriority()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600295 void set_priority(VkMemoryPriority priority);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600296
297 // vkMapMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600298 const void *map(VkFlags flags) const;
299 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 const void *map() const { return map(0); }
301 void *map() { return map(0); }
302
303 // vkUnmapMemory()
304 void unmap() const;
305
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600306 static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600307 const VkMemoryAllocInfo *next_info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600308};
309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310class Fence : public DerivedObject<VkFence, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311public:
312 // vkCreateFence()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314
315 // vkGetFenceStatus()
Mike Stroyan230e6252015-04-17 12:36:38 -0600316 VkResult status() const { return vkGetFenceStatus(device(), obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600318 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
319 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600320};
321
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600322class Semaphore : public DerivedObject<VkSemaphore, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600323public:
324 // vkCreateSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600325 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600326 // vkOpenSharedSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600327 void init(const Device &dev, const VkSemaphoreOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600328
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600329 static VkSemaphoreCreateInfo create_info(uint32_t init_count, VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330};
331
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332class Event : public DerivedObject<VkEvent, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333public:
334 // vkCreateEvent()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600335 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600336
337 // vkGetEventStatus()
338 // vkSetEvent()
339 // vkResetEvent()
Mike Stroyan230e6252015-04-17 12:36:38 -0600340 VkResult status() const { return vkGetEventStatus(device(), obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600341 void set();
342 void reset();
343
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345};
346
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600347class QueryPool : public DerivedObject<VkQueryPool, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600348public:
349 // vkCreateQueryPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600350 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351
352 // vkGetQueryPoolResults()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600353 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600354
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600355 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600356};
357
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600358class Buffer : public DerivedObject<VkBuffer, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600359public:
360 explicit Buffer() {}
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600361 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbour8205d902015-04-16 15:59:00 -0600362 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363
364 // vkCreateBuffer()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600365 void init(const Device &dev, const VkBufferCreateInfo &info);
Tony Barbour8205d902015-04-16 15:59:00 -0600366 void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); }
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600367 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368
Tony Barbour8205d902015-04-16 15:59:00 -0600369 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600370
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600371 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbour8205d902015-04-16 15:59:00 -0600372 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600374 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600375 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
376 barrier.buffer = obj();
377 barrier.outputMask = output_mask;
378 barrier.inputMask = input_mask;
379 barrier.offset = offset;
380 barrier.size = size;
381 return barrier;
382 }
383private:
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600384 VkBufferCreateInfo create_info_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385};
386
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600387class BufferView : public DerivedObject<VkBufferView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388public:
389 // vkCreateBufferView()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600390 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391};
392
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600393class Image : public DerivedObject<VkImage, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394public:
395 explicit Image() : format_features_(0) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600397
398 // vkCreateImage()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600399 void init(const Device &dev, const VkImageCreateInfo &info);
400 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401 // vkOpenPeerImage()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600402 void init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600403
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500404 // vkQueueBindImageMemoryRange()
405 void bind_memory(const Device &dev, uint32_t alloc_idx, const VkImageMemoryBindInfo &info,
Tony Barbour8205d902015-04-16 15:59:00 -0600406 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407
408 // vkGetImageSubresourceInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410
411 bool transparent() const;
Tony Barbour8205d902015-04-16 15:59:00 -0600412 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600413
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600414 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
415 VkExtent3D extent() const { return create_info_.extent; }
416 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
417 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600419 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
420 VkImageLayout old_layout,
421 VkImageLayout new_layout,
422 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600424 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
426 barrier.outputMask = output_mask;
427 barrier.inputMask = input_mask;
428 barrier.oldLayout = old_layout;
429 barrier.newLayout = new_layout;
430 barrier.image = obj();
431 barrier.subresourceRange = range;
432 return barrier;
433 }
434
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600435 static VkImageCreateInfo create_info();
436 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
437 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
438 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600440 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
441 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 static VkExtent2D extent(int32_t width, int32_t height);
444 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
445 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600446
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600447 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
448 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449
450private:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600451 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600453 VkImageCreateInfo create_info_;
454 VkFlags format_features_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600455};
456
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600457class ImageView : public DerivedObject<VkImageView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600458public:
459 // vkCreateImageView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600460 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600461};
462
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600463class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464public:
465 // vkCreateColorAttachmentView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467};
468
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600469class DepthStencilView : public DerivedObject<VkDepthStencilView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470public:
471 // vkCreateDepthStencilView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600472 void init(const Device &dev, const VkDepthStencilViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473};
474
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600475class Shader : public DerivedObject<VkShader, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600476public:
477 // vkCreateShader()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600478 void init(const Device &dev, const VkShaderCreateInfo &info);
479 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600481 static VkShaderCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482};
483
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600484class Pipeline : public DerivedObject<VkPipeline, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600485public:
486 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600487 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600488 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600489 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600490 // vkCreateComputePipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600491 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600492 // vkLoadPipeline()
493 void init(const Device&dev, size_t size, const void *data);
494 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600495 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496
497 // vkStorePipeline()
498 size_t store(size_t size, void *data);
499};
500
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600501class Sampler : public DerivedObject<VkSampler, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600502public:
503 // vkCreateSampler()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600504 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505};
506
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508public:
509 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600510 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600511};
512
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500513class PipelineLayout : public DerivedObject<VkPipelineLayout, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600514public:
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500515 // vCreatePipelineLayout()
516 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600517};
518
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600519class DescriptorPool : public DerivedObject<VkDescriptorPool, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600520public:
521 // vkCreateDescriptorPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600522 void init(const Device &dev, VkDescriptorPoolUsage usage,
523 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524
525 // vkResetDescriptorPool()
526 void reset();
527
528 // vkAllocDescriptorSets()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500529 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
530 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
531 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600532
533 // vkClearDescriptorSets()
534 void clear_sets(const std::vector<DescriptorSet *> &sets);
535 void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); }
536};
537
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600538class DescriptorSet : public DerivedObject<VkDescriptorSet, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540 explicit DescriptorSet(VkDescriptorSet set) : DerivedObject(set) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541
542 // vkUpdateDescriptors()
543 void update(const std::vector<const void *> &update_array);
544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600545 static VkUpdateSamplers update(uint32_t binding, uint32_t index, uint32_t count, const VkSampler *samplers);
546 static VkUpdateSamplers update(uint32_t binding, uint32_t index, const std::vector<VkSampler> &samplers);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600548 static VkUpdateSamplerTextures update(uint32_t binding, uint32_t index, uint32_t count, const VkSamplerImageViewInfo *textures);
549 static VkUpdateSamplerTextures update(uint32_t binding, uint32_t index, const std::vector<VkSamplerImageViewInfo> &textures);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600550
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600551 static VkUpdateImages update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const VkImageViewAttachInfo *views);
552 static VkUpdateImages update(VkDescriptorType type, uint32_t binding, uint32_t index, const std::vector<VkImageViewAttachInfo> &views);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600553
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600554 static VkUpdateBuffers update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const VkBufferViewAttachInfo *views);
555 static VkUpdateBuffers update(VkDescriptorType type, uint32_t binding, uint32_t index, const std::vector<VkBufferViewAttachInfo> &views);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600556
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600557 static VkUpdateAsCopy update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const DescriptorSet &set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600558
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600559 static VkBufferViewAttachInfo attach_info(const BufferView &view);
560 static VkImageViewAttachInfo attach_info(const ImageView &view, VkImageLayout layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600561};
562
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600563class DynamicVpStateObject : public DerivedObject<VkDynamicVpState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600564public:
565 // vkCreateDynamicViewportState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600566 void init(const Device &dev, const VkDynamicVpStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600567};
568
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600569class DynamicRsStateObject : public DerivedObject<VkDynamicRsState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600570public:
571 // vkCreateDynamicRasterState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600572 void init(const Device &dev, const VkDynamicRsStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600573};
574
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600575class DynamicCbStateObject : public DerivedObject<VkDynamicCbState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576public:
577 // vkCreateDynamicColorBlendState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600578 void init(const Device &dev, const VkDynamicCbStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579};
580
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600581class DynamicDsStateObject : public DerivedObject<VkDynamicDsState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582public:
583 // vkCreateDynamicDepthStencilState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600584 void init(const Device &dev, const VkDynamicDsStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600585};
586
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587class CmdBuffer : public DerivedObject<VkCmdBuffer, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588public:
589 explicit CmdBuffer() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600590 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600591
592 // vkCreateCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600593 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600594
595 // vkBeginCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600596 void begin(const VkCmdBufferBeginInfo *info);
597 void begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 void begin();
599
600 // vkEndCommandBuffer()
601 // vkResetCommandBuffer()
602 void end();
603 void reset();
604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600605 static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600606};
607
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600608inline const void *Object::map(VkFlags flags) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609{
610 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
611}
612
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600613inline void *Object::map(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600614{
615 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
616}
617
618inline void Object::unmap() const
619{
620 if (primary_mem_)
621 primary_mem_->unmap();
622}
623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600625 const VkMemoryAllocInfo *next_info)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600626{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600627 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600628 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
629 if (next_info != NULL)
630 info.pNext = (void *) next_info;
631
632 info.allocationSize = reqs.size;
Jeremy Hayesd02809a2015-04-15 14:17:56 -0600633 info.memProps = reqs.memPropsRequired;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600634 info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
635 return info;
636}
637
Tony Barbour8205d902015-04-16 15:59:00 -0600638inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600639{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600640 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600641 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 info.size = size;
643 info.usage = usage;
644 return info;
645}
646
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600647inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600649 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
651 info.flags = flags;
652 return info;
653}
654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600655inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600657 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
659 return info;
660}
661
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600662inline VkSemaphoreCreateInfo Semaphore::create_info(uint32_t init_count, VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600663{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600664 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
666 info.initialCount = init_count;
667 info.flags = flags;
668 return info;
669}
670
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600671inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600673 VkEventCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600674 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
675 info.flags = flags;
676 return info;
677}
678
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600679inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600681 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600682 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
683 info.queryType = type;
684 info.slots = slot_count;
685 return info;
686}
687
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600688inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600690 VkImageCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600691 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
692 info.extent.width = 1;
693 info.extent.height = 1;
694 info.extent.depth = 1;
695 info.mipLevels = 1;
696 info.arraySize = 1;
697 info.samples = 1;
698 return info;
699}
700
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600701inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600702{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600703 VkImageSubresource subres = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600704 subres.aspect = aspect;
705 subres.mipLevel = mip_level;
706 subres.arraySlice = array_slice;
707 return subres;
708}
709
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600710inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600711{
712 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
713}
714
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716 uint32_t base_array_slice, uint32_t array_size)
717{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600718 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600719 range.aspect = aspect;
720 range.baseMipLevel = base_mip_level;
721 range.mipLevels = mip_levels;
722 range.baseArraySlice = base_array_slice;
723 range.arraySize = array_size;
724 return range;
725}
726
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600727inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600728{
729 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
730}
731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600733{
734 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
735}
736
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600738{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600739 VkExtent2D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600740 extent.width = width;
741 extent.height = height;
742 return extent;
743}
744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600746{
747 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
748 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
749 return Image::extent(width, height);
750}
751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600753{
754 return Image::extent(extent.width, extent.height);
755}
756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 VkExtent3D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 extent.width = width;
761 extent.height = height;
762 extent.depth = depth;
763 return extent;
764}
765
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600766inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600767{
768 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
769 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
770 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
771 return Image::extent(width, height, depth);
772}
773
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600774inline VkShaderCreateInfo Shader::create_info(size_t code_size, const void *code, VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600776 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600777 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
778 info.codeSize = code_size;
779 info.pCode = code;
780 info.flags = flags;
781 return info;
782}
783
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600784inline VkBufferViewAttachInfo DescriptorSet::attach_info(const BufferView &view)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600785{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600786 VkBufferViewAttachInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787 info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO;
788 info.view = view.obj();
789 return info;
790}
791
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600792inline VkImageViewAttachInfo DescriptorSet::attach_info(const ImageView &view, VkImageLayout layout)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600794 VkImageViewAttachInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600795 info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
796 info.view = view.obj();
797 info.layout = layout;
798 return info;
799}
800
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600801inline VkUpdateSamplers DescriptorSet::update(uint32_t binding, uint32_t index, uint32_t count, const VkSampler *samplers)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600802{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600803 VkUpdateSamplers info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600804 info.sType = VK_STRUCTURE_TYPE_UPDATE_SAMPLERS;
805 info.binding = binding;
806 info.arrayIndex = index;
807 info.count = count;
808 info.pSamplers = samplers;
809 return info;
810}
811
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812inline VkUpdateSamplers DescriptorSet::update(uint32_t binding, uint32_t index, const std::vector<VkSampler> &samplers)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600813{
814 return update(binding, index, samplers.size(), &samplers[0]);
815}
816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817inline VkUpdateSamplerTextures DescriptorSet::update(uint32_t binding, uint32_t index, uint32_t count, const VkSamplerImageViewInfo *textures)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600818{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600819 VkUpdateSamplerTextures info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600820 info.sType = VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES;
821 info.binding = binding;
822 info.arrayIndex = index;
823 info.count = count;
824 info.pSamplerImageViews = textures;
825 return info;
826}
827
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600828inline VkUpdateSamplerTextures DescriptorSet::update(uint32_t binding, uint32_t index, const std::vector<VkSamplerImageViewInfo> &textures)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600829{
830 return update(binding, index, textures.size(), &textures[0]);
831}
832
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600833inline VkUpdateImages DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count,
834 const VkImageViewAttachInfo *views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600835{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600836 VkUpdateImages info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600837 info.sType = VK_STRUCTURE_TYPE_UPDATE_IMAGES;
838 info.descriptorType = type;
839 info.binding = binding;
840 info.arrayIndex = index;
841 info.count = count;
842 info.pImageViews = views;
843 return info;
844}
845
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600846inline VkUpdateImages DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index,
847 const std::vector<VkImageViewAttachInfo> &views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848{
849 return update(type, binding, index, views.size(), &views[0]);
850}
851
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600852inline VkUpdateBuffers DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count,
853 const VkBufferViewAttachInfo *views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600855 VkUpdateBuffers info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600856 info.sType = VK_STRUCTURE_TYPE_UPDATE_BUFFERS;
857 info.descriptorType = type;
858 info.binding = binding;
859 info.arrayIndex = index;
860 info.count = count;
861 info.pBufferViews = views;
862 return info;
863}
864
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600865inline VkUpdateBuffers DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index,
866 const std::vector<VkBufferViewAttachInfo> &views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600867{
868 return update(type, binding, index, views.size(), &views[0]);
869}
870
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600871inline VkUpdateAsCopy DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const DescriptorSet &set)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600872{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600873 VkUpdateAsCopy info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600874 info.sType = VK_STRUCTURE_TYPE_UPDATE_AS_COPY;
875 info.descriptorType = type;
876 info.binding = binding;
877 info.arrayElement = index;
878 info.count = count;
879 info.descriptorSet = set.obj();
880 return info;
881}
882
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600883inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600884{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600885 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600886 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
887 info.queueNodeIndex = queueNodeIndex;
888 return info;
889}
890
891}; // namespace vk_testing
892
893#endif // VKTESTBINDING_H