blob: a8eb41b7f28eb8f073c281dbefb7b162a2388a3b [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;
57class DescriptorSetLayoutChain;
58class 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:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060097 const VkBaseObject &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) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600106 explicit BaseObject(VkBaseObject obj) : obj_(VK_NULL_HANDLE), own_obj_(false) { init(obj); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600107
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600108 void init(VkBaseObject obj, bool own);
109 void init(VkBaseObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600111 void reinit(VkBaseObject obj, bool own);
112 void reinit(VkBaseObject obj) { reinit(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113
114 bool own() const { return own_obj_; }
115
116private:
117 // base objects are non-copyable
118 BaseObject(const BaseObject &);
119 BaseObject &operator=(const BaseObject &);
120
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600121 VkBaseObject obj_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600122 bool own_obj_;
123};
124
125class Object : public BaseObject {
126public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600127 const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600128
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500129 // vkQueueBindObjectMemory()
Tony Barbour8205d902015-04-16 15:59:00 -0600130 void bind_memory(const Device &dev, uint32_t alloc_idx, const GpuMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500131 void unbind_memory(const Device &dev, uint32_t alloc_idx);
132 void unbind_memory(const Device &dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600133
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500134 // vkQueueBindObjectMemoryRange()
Tony Barbour8205d902015-04-16 15:59:00 -0600135 void bind_memory(const Device &dev, uint32_t alloc_idx, VkDeviceSize offset, VkDeviceSize size,
136 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137
138 // Unless an object is initialized with init_no_mem(), memories are
139 // automatically allocated and bound. These methods can be used to get
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600140 // the memories (for vkQueueAddMemReferences), or to map/unmap the primary memory.
Tony Barbour8205d902015-04-16 15:59:00 -0600141 std::vector<VkDeviceMemory> memories() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143 const void *map(VkFlags flags) const;
144 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145 const void *map() const { return map(0); }
146 void *map() { return map(0); }
147
148 void unmap() const;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500149 const Device* dev_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600150
151protected:
Tony Barbour2b5fb342015-04-09 16:00:18 -0600152 explicit Object() : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL), bound(false) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600153 explicit Object(VkObject obj) : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL) { init(obj); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600154 ~Object() { cleanup(); }
155
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 void init(VkObject obj, bool own);
157 void init(VkObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600158
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600159 void reinit(VkObject obj, bool own);
160 void reinit(VkObject obj) { init(obj, true); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161
162 // allocate and bind internal memories
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500163 void alloc_memory(const Device &dev);
Tony Barbour8205d902015-04-16 15:59:00 -0600164 void alloc_memory(const Device &dev, const std::vector<VkDeviceMemory> &mems);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600165
166private:
167 void cleanup();
168
169 uint32_t mem_alloc_count_;
170 GpuMemory *internal_mems_;
171 GpuMemory *primary_mem_;
Tony Barbour2b5fb342015-04-09 16:00:18 -0600172 bool bound;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173};
174
175class DynamicStateObject : public Object {
176public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600177 const VkDynamicStateObject &obj() const { return reinterpret_cast<const VkDynamicStateObject &>(Object::obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178
179protected:
180 explicit DynamicStateObject() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600181 explicit DynamicStateObject(VkDynamicStateObject obj) : Object(obj) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600182};
183
184template<typename T, class C>
185class DerivedObject : public C {
186public:
187 const T &obj() const { return reinterpret_cast<const T &>(C::obj()); }
188
189protected:
190 typedef T obj_type;
191 typedef C base_type;
192
193 explicit DerivedObject() {}
194 explicit DerivedObject(T obj) : C(obj) {}
195};
196
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600197class Device : public DerivedObject<VkDevice, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198public:
Tony Barbour8205d902015-04-16 15:59:00 -0600199 explicit Device(VkPhysicalDevice gpu) : gpu_(gpu) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600200 ~Device();
201
202 // vkCreateDevice()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600203 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600204 void init(bool enable_layers); // all queues, all extensions, etc
205 void init() { init(false); };
206
207 const PhysicalGpu &gpu() const { return gpu_; }
208
209 // vkGetDeviceQueue()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500210 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
212 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
213 uint32_t graphics_queue_node_index_;
214
215 struct Format {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600216 VkFormat format;
217 VkImageTiling tiling;
218 VkFlags features;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 };
220 // vkGetFormatInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600221 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 const std::vector<Format> &formats() const { return formats_; }
223
224 // vkDeviceWaitIdle()
225 void wait();
226
227 // vkWaitForFences()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
229 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600230
231 // vkBeginDescriptorPoolUpdate()
232 // vkEndDescriptorPoolUpdate()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600233 void begin_descriptor_pool_update(VkDescriptorUpdateMode mode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600234 void end_descriptor_pool_update(CmdBuffer &cmd);
235
236private:
237 enum QueueIndex {
238 GRAPHICS,
239 COMPUTE,
240 DMA,
241 QUEUE_COUNT,
242 };
243
244 void init_queues();
245 void init_formats();
246
247 PhysicalGpu gpu_;
248
249 std::vector<Queue *> queues_[QUEUE_COUNT];
250 std::vector<Format> formats_;
251};
252
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600253class Queue : public DerivedObject<VkQueue, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600254public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600255 explicit Queue(VkQueue queue) : DerivedObject(queue) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256
257 // vkQueueSubmit()
258 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
259 void submit(const CmdBuffer &cmd, Fence &fence);
260 void submit(const CmdBuffer &cmd);
261
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600262 // vkQueueAddMemReferences()
263 // vkQueueRemoveMemReferences()
Tony Barbour8205d902015-04-16 15:59:00 -0600264 void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
265 void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266
267 // vkQueueWaitIdle()
268 void wait();
269
270 // vkQueueSignalSemaphore()
271 // vkQueueWaitSemaphore()
272 void signal_semaphore(Semaphore &sem);
273 void wait_semaphore(Semaphore &sem);
274};
275
Tony Barbour8205d902015-04-16 15:59:00 -0600276class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277public:
278 ~GpuMemory();
279
280 // vkAllocMemory()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600281 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600282 // vkPinSystemMemory()
283 void init(const Device &dev, size_t size, const void *data);
284 // vkOpenSharedMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600285 void init(const Device &dev, const VkMemoryOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600286 // vkOpenPeerMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600287 void init(const Device &dev, const VkPeerMemoryOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288
Tony Barbour8205d902015-04-16 15:59:00 -0600289 void init(VkDeviceMemory mem) { BaseObject::init(mem, false); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600290
291 // vkSetMemoryPriority()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292 void set_priority(VkMemoryPriority priority);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600293
294 // vkMapMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600295 const void *map(VkFlags flags) const;
296 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297 const void *map() const { return map(0); }
298 void *map() { return map(0); }
299
300 // vkUnmapMemory()
301 void unmap() const;
302
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600303 static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600304 const VkMemoryAllocInfo *next_info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307class Fence : public DerivedObject<VkFence, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600308public:
309 // vkCreateFence()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311
312 // vkGetFenceStatus()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313 VkResult status() const { return vkGetFenceStatus(obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
316 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317};
318
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600319class Semaphore : public DerivedObject<VkSemaphore, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600320public:
321 // vkCreateSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600322 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600323 // vkOpenSharedSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324 void init(const Device &dev, const VkSemaphoreOpenInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600325
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 static VkSemaphoreCreateInfo create_info(uint32_t init_count, VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600327};
328
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600329class Event : public DerivedObject<VkEvent, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330public:
331 // vkCreateEvent()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333
334 // vkGetEventStatus()
335 // vkSetEvent()
336 // vkResetEvent()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600337 VkResult status() const { return vkGetEventStatus(obj()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600338 void set();
339 void reset();
340
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600341 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600342};
343
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344class QueryPool : public DerivedObject<VkQueryPool, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345public:
346 // vkCreateQueryPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600347 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600348
349 // vkGetQueryPoolResults()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600350 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600352 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600353};
354
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600355class Buffer : public DerivedObject<VkBuffer, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600356public:
357 explicit Buffer() {}
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600358 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbour8205d902015-04-16 15:59:00 -0600359 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360
361 // vkCreateBuffer()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600362 void init(const Device &dev, const VkBufferCreateInfo &info);
Tony Barbour8205d902015-04-16 15:59:00 -0600363 void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); }
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600364 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365
Tony Barbour8205d902015-04-16 15:59:00 -0600366 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600367
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600368 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbour8205d902015-04-16 15:59:00 -0600369 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600370 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600371 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600372 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
373 barrier.buffer = obj();
374 barrier.outputMask = output_mask;
375 barrier.inputMask = input_mask;
376 barrier.offset = offset;
377 barrier.size = size;
378 return barrier;
379 }
380private:
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600381 VkBufferCreateInfo create_info_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382};
383
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384class BufferView : public DerivedObject<VkBufferView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385public:
386 // vkCreateBufferView()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600387 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388};
389
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600390class Image : public DerivedObject<VkImage, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391public:
392 explicit Image() : format_features_(0) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600393 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394
395 // vkCreateImage()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396 void init(const Device &dev, const VkImageCreateInfo &info);
397 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 // vkOpenPeerImage()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600399 void init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600400
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500401 // vkQueueBindImageMemoryRange()
402 void bind_memory(const Device &dev, uint32_t alloc_idx, const VkImageMemoryBindInfo &info,
Tony Barbour8205d902015-04-16 15:59:00 -0600403 const GpuMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600404
405 // vkGetImageSubresourceInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600406 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407
408 bool transparent() const;
Tony Barbour8205d902015-04-16 15:59:00 -0600409 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
412 VkExtent3D extent() const { return create_info_.extent; }
413 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
414 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600416 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
417 VkImageLayout old_layout,
418 VkImageLayout new_layout,
419 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600420 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600421 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
423 barrier.outputMask = output_mask;
424 barrier.inputMask = input_mask;
425 barrier.oldLayout = old_layout;
426 barrier.newLayout = new_layout;
427 barrier.image = obj();
428 barrier.subresourceRange = range;
429 return barrier;
430 }
431
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600432 static VkImageCreateInfo create_info();
433 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
434 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
435 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600436 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600437 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
438 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600440 static VkExtent2D extent(int32_t width, int32_t height);
441 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
442 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600443
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600444 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
445 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600446
447private:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600450 VkImageCreateInfo create_info_;
451 VkFlags format_features_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600452};
453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600454class ImageView : public DerivedObject<VkImageView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600455public:
456 // vkCreateImageView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600457 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600458};
459
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600460class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600461public:
462 // vkCreateColorAttachmentView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600463 void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464};
465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466class DepthStencilView : public DerivedObject<VkDepthStencilView, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467public:
468 // vkCreateDepthStencilView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600469 void init(const Device &dev, const VkDepthStencilViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470};
471
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600472class Shader : public DerivedObject<VkShader, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473public:
474 // vkCreateShader()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600475 void init(const Device &dev, const VkShaderCreateInfo &info);
476 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600478 static VkShaderCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600479};
480
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600481class Pipeline : public DerivedObject<VkPipeline, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482public:
483 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600484 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600485 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600486 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600487 // vkCreateComputePipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600488 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600489 // vkLoadPipeline()
490 void init(const Device&dev, size_t size, const void *data);
491 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600492 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600493
494 // vkStorePipeline()
495 size_t store(size_t size, void *data);
496};
497
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600498class Sampler : public DerivedObject<VkSampler, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600499public:
500 // vkCreateSampler()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600501 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600502};
503
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600504class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505public:
506 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508};
509
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600510class DescriptorSetLayoutChain : public DerivedObject<VkDescriptorSetLayoutChain, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600511public:
512 // vkCreateDescriptorSetLayoutChain()
513 void init(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts);
514};
515
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600516class DescriptorPool : public DerivedObject<VkDescriptorPool, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600517public:
518 // vkCreateDescriptorPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600519 void init(const Device &dev, VkDescriptorPoolUsage usage,
520 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600521
522 // vkResetDescriptorPool()
523 void reset();
524
525 // vkAllocDescriptorSets()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500526 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
527 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
528 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600529
530 // vkClearDescriptorSets()
531 void clear_sets(const std::vector<DescriptorSet *> &sets);
532 void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); }
533};
534
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600535class DescriptorSet : public DerivedObject<VkDescriptorSet, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600536public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600537 explicit DescriptorSet(VkDescriptorSet set) : DerivedObject(set) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600538
539 // vkUpdateDescriptors()
540 void update(const std::vector<const void *> &update_array);
541
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600542 static VkUpdateSamplers update(uint32_t binding, uint32_t index, uint32_t count, const VkSampler *samplers);
543 static VkUpdateSamplers update(uint32_t binding, uint32_t index, const std::vector<VkSampler> &samplers);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600545 static VkUpdateSamplerTextures update(uint32_t binding, uint32_t index, uint32_t count, const VkSamplerImageViewInfo *textures);
546 static VkUpdateSamplerTextures update(uint32_t binding, uint32_t index, const std::vector<VkSamplerImageViewInfo> &textures);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600548 static VkUpdateImages update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const VkImageViewAttachInfo *views);
549 static VkUpdateImages update(VkDescriptorType type, uint32_t binding, uint32_t index, const std::vector<VkImageViewAttachInfo> &views);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600550
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600551 static VkUpdateBuffers update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const VkBufferViewAttachInfo *views);
552 static VkUpdateBuffers update(VkDescriptorType type, uint32_t binding, uint32_t index, const std::vector<VkBufferViewAttachInfo> &views);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600553
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600554 static VkUpdateAsCopy update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const DescriptorSet &set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600555
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600556 static VkBufferViewAttachInfo attach_info(const BufferView &view);
557 static VkImageViewAttachInfo attach_info(const ImageView &view, VkImageLayout layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600558};
559
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600560class DynamicVpStateObject : public DerivedObject<VkDynamicVpState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600561public:
562 // vkCreateDynamicViewportState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600563 void init(const Device &dev, const VkDynamicVpStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600564};
565
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600566class DynamicRsStateObject : public DerivedObject<VkDynamicRsState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600567public:
568 // vkCreateDynamicRasterState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600569 void init(const Device &dev, const VkDynamicRsStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600570};
571
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600572class DynamicCbStateObject : public DerivedObject<VkDynamicCbState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600573public:
574 // vkCreateDynamicColorBlendState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600575 void init(const Device &dev, const VkDynamicCbStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576};
577
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600578class DynamicDsStateObject : public DerivedObject<VkDynamicDsState, DynamicStateObject> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579public:
580 // vkCreateDynamicDepthStencilState()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600581 void init(const Device &dev, const VkDynamicDsStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582};
583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600584class CmdBuffer : public DerivedObject<VkCmdBuffer, Object> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600585public:
586 explicit CmdBuffer() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588
589 // vkCreateCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600590 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600591
592 // vkBeginCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600593 void begin(const VkCmdBufferBeginInfo *info);
594 void begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600595 void begin();
596
597 // vkEndCommandBuffer()
598 // vkResetCommandBuffer()
599 void end();
600 void reset();
601
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600602 static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600603};
604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600605inline const void *Object::map(VkFlags flags) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600606{
607 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
608}
609
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600610inline void *Object::map(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600611{
612 return (primary_mem_) ? primary_mem_->map(flags) : NULL;
613}
614
615inline void Object::unmap() const
616{
617 if (primary_mem_)
618 primary_mem_->unmap();
619}
620
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600621inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600622 const VkMemoryAllocInfo *next_info)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600623{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600624 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
626 if (next_info != NULL)
627 info.pNext = (void *) next_info;
628
629 info.allocationSize = reqs.size;
Jeremy Hayesd02809a2015-04-15 14:17:56 -0600630 info.memProps = reqs.memPropsRequired;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600631 info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
632 return info;
633}
634
Tony Barbour8205d902015-04-16 15:59:00 -0600635inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600636{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600637 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 info.size = size;
640 info.usage = usage;
641 return info;
642}
643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600644inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600645{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600646 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
648 info.flags = flags;
649 return info;
650}
651
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600652inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600653{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600654 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600655 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
656 return info;
657}
658
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600659inline VkSemaphoreCreateInfo Semaphore::create_info(uint32_t init_count, VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600660{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600661 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600662 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
663 info.initialCount = init_count;
664 info.flags = flags;
665 return info;
666}
667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600668inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600669{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600670 VkEventCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600671 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
672 info.flags = flags;
673 return info;
674}
675
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600676inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600678 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
680 info.queryType = type;
681 info.slots = slot_count;
682 return info;
683}
684
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600686{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600687 VkImageCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600688 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
689 info.extent.width = 1;
690 info.extent.height = 1;
691 info.extent.depth = 1;
692 info.mipLevels = 1;
693 info.arraySize = 1;
694 info.samples = 1;
695 return info;
696}
697
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600698inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600699{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600700 VkImageSubresource subres = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600701 subres.aspect = aspect;
702 subres.mipLevel = mip_level;
703 subres.arraySlice = array_slice;
704 return subres;
705}
706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600708{
709 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
710}
711
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600712inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600713 uint32_t base_array_slice, uint32_t array_size)
714{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716 range.aspect = aspect;
717 range.baseMipLevel = base_mip_level;
718 range.mipLevels = mip_levels;
719 range.baseArraySlice = base_array_slice;
720 range.arraySize = array_size;
721 return range;
722}
723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725{
726 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
727}
728
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600729inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600730{
731 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
732}
733
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600734inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600735{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600736 VkExtent2D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600737 extent.width = width;
738 extent.height = height;
739 return extent;
740}
741
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600742inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600743{
744 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
745 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
746 return Image::extent(width, height);
747}
748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750{
751 return Image::extent(extent.width, extent.height);
752}
753
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600754inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600755{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600756 VkExtent3D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600757 extent.width = width;
758 extent.height = height;
759 extent.depth = depth;
760 return extent;
761}
762
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764{
765 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
766 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
767 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
768 return Image::extent(width, height, depth);
769}
770
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600771inline VkShaderCreateInfo Shader::create_info(size_t code_size, const void *code, VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600772{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600773 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
775 info.codeSize = code_size;
776 info.pCode = code;
777 info.flags = flags;
778 return info;
779}
780
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600781inline VkBufferViewAttachInfo DescriptorSet::attach_info(const BufferView &view)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600782{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600783 VkBufferViewAttachInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600784 info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO;
785 info.view = view.obj();
786 return info;
787}
788
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600789inline VkImageViewAttachInfo DescriptorSet::attach_info(const ImageView &view, VkImageLayout layout)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600790{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600791 VkImageViewAttachInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600792 info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
793 info.view = view.obj();
794 info.layout = layout;
795 return info;
796}
797
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600798inline VkUpdateSamplers DescriptorSet::update(uint32_t binding, uint32_t index, uint32_t count, const VkSampler *samplers)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600799{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600800 VkUpdateSamplers info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600801 info.sType = VK_STRUCTURE_TYPE_UPDATE_SAMPLERS;
802 info.binding = binding;
803 info.arrayIndex = index;
804 info.count = count;
805 info.pSamplers = samplers;
806 return info;
807}
808
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600809inline VkUpdateSamplers DescriptorSet::update(uint32_t binding, uint32_t index, const std::vector<VkSampler> &samplers)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600810{
811 return update(binding, index, samplers.size(), &samplers[0]);
812}
813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814inline VkUpdateSamplerTextures DescriptorSet::update(uint32_t binding, uint32_t index, uint32_t count, const VkSamplerImageViewInfo *textures)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600815{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600816 VkUpdateSamplerTextures info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600817 info.sType = VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES;
818 info.binding = binding;
819 info.arrayIndex = index;
820 info.count = count;
821 info.pSamplerImageViews = textures;
822 return info;
823}
824
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600825inline VkUpdateSamplerTextures DescriptorSet::update(uint32_t binding, uint32_t index, const std::vector<VkSamplerImageViewInfo> &textures)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600826{
827 return update(binding, index, textures.size(), &textures[0]);
828}
829
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600830inline VkUpdateImages DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count,
831 const VkImageViewAttachInfo *views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600832{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600833 VkUpdateImages info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600834 info.sType = VK_STRUCTURE_TYPE_UPDATE_IMAGES;
835 info.descriptorType = type;
836 info.binding = binding;
837 info.arrayIndex = index;
838 info.count = count;
839 info.pImageViews = views;
840 return info;
841}
842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600843inline VkUpdateImages DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index,
844 const std::vector<VkImageViewAttachInfo> &views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600845{
846 return update(type, binding, index, views.size(), &views[0]);
847}
848
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600849inline VkUpdateBuffers DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count,
850 const VkBufferViewAttachInfo *views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600851{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600852 VkUpdateBuffers info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853 info.sType = VK_STRUCTURE_TYPE_UPDATE_BUFFERS;
854 info.descriptorType = type;
855 info.binding = binding;
856 info.arrayIndex = index;
857 info.count = count;
858 info.pBufferViews = views;
859 return info;
860}
861
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600862inline VkUpdateBuffers DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index,
863 const std::vector<VkBufferViewAttachInfo> &views)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600864{
865 return update(type, binding, index, views.size(), &views[0]);
866}
867
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600868inline VkUpdateAsCopy DescriptorSet::update(VkDescriptorType type, uint32_t binding, uint32_t index, uint32_t count, const DescriptorSet &set)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600870 VkUpdateAsCopy info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600871 info.sType = VK_STRUCTURE_TYPE_UPDATE_AS_COPY;
872 info.descriptorType = type;
873 info.binding = binding;
874 info.arrayElement = index;
875 info.count = count;
876 info.descriptorSet = set.obj();
877 return info;
878}
879
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600880inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600881{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600882 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600883 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
884 info.queueNodeIndex = queueNodeIndex;
885 return info;
886}
887
888}; // namespace vk_testing
889
890#endif // VKTESTBINDING_H