blob: d1bf56e74b9abce7c493ae56066879bcf79e6cad [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>
Chia-I Wua10be9d2015-07-03 10:13:26 +080027#include <assert.h>
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060028
29#include "vulkan.h"
30
31namespace vk_testing {
32
33typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function);
34void set_error_callback(ErrorCallback callback);
35
Chia-I Wuf5fb1092015-07-03 10:32:05 +080036class PhysicalDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060037class Device;
38class Queue;
Chia-I Wuba0836f2015-07-03 10:58:57 +080039class DeviceMemory;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040class Fence;
41class Semaphore;
42class Event;
43class QueryPool;
44class Buffer;
45class BufferView;
46class Image;
47class ImageView;
48class ColorAttachmentView;
49class DepthStencilView;
50class Shader;
51class Pipeline;
52class PipelineDelta;
53class Sampler;
54class DescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -050055class PipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060056class DescriptorSetPool;
57class DescriptorSet;
Chia-I Wu6b11e602015-07-03 11:49:42 +080058class DynamicViewportState;
Cody Northropf5bd2252015-08-17 11:10:49 -060059class DynamicRasterLineState;
60class DynamicRasterDepthBiasState;
Chia-I Wu6b11e602015-07-03 11:49:42 +080061class DynamicColorBlendState;
Cody Northrop2605cb02015-08-18 15:21:16 -060062class DynamicDepthState;
63class DynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060064class CmdBuffer;
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -060065class CmdPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060066
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060067std::vector<VkLayerProperties> GetGlobalLayers();
68std::vector<VkExtensionProperties> GetGlobalExtensions();
69std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
70
Chia-I Wua10be9d2015-07-03 10:13:26 +080071namespace internal {
72
73template<typename T>
74class Handle {
75public:
76 const T &handle() const { return handle_; }
77 bool initialized() const { return (handle_ != VK_NULL_HANDLE); }
78
79protected:
80 typedef T handle_type;
81
82 explicit Handle() : handle_(VK_NULL_HANDLE) {}
83 explicit Handle(T handle) : handle_(handle) {}
84
85 void init(T handle)
86 {
87 assert(!initialized());
88 handle_ = handle;
89 }
90
91private:
92 // handles are non-copyable
93 Handle(const Handle &);
94 Handle &operator=(const Handle &);
95
96 T handle_;
97};
98
99
100template<typename T>
101class NonDispHandle : public Handle<T> {
102protected:
103 explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {}
104 explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {}
105
106 const VkDevice &device() const { return dev_handle_; }
107
108 void init(VkDevice dev, T handle)
109 {
110 assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE);
111 Handle<T>::init(handle);
112 dev_handle_ = dev;
113 }
114
115private:
116 VkDevice dev_handle_;
117};
118
119} // namespace internal
120
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800121class PhysicalDevice : public internal::Handle<VkPhysicalDevice> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600122public:
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800123 explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy)
Mark Lobodzinski72346292015-07-02 16:49:40 -0600124 {
125 memory_properties_ = memory_properties();
126 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600127
Tony Barbour8205d902015-04-16 15:59:00 -0600128 VkPhysicalDeviceProperties properties() const;
Tony Barbour8205d902015-04-16 15:59:00 -0600129 VkPhysicalDeviceMemoryProperties memory_properties() const;
Cody Northropef72e2a2015-08-03 17:04:53 -0600130 std::vector<VkQueueFamilyProperties> queue_properties() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131
Mike Stroyand72da752015-08-04 10:49:29 -0600132 VkResult set_memory_type(const uint32_t type_bits, VkMemoryAllocInfo *info, const VkMemoryPropertyFlags properties,
133 const VkMemoryPropertyFlags forbid = 0) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600134
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600135 // vkGetPhysicalDeviceExtensionProperties()
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600136 std::vector<VkExtensionProperties> extensions() const;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600137 std::vector<VkExtensionProperties> extensions(const char * pLayerName) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600138
139 // vkEnumerateLayers()
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600140 std::vector<VkLayerProperties> layers() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600141
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142private:
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600143 void add_extension_dependencies(uint32_t dependency_count,
144 VkExtensionProperties *depencency_props,
145 std::vector<VkExtensionProperties> &ext_list);
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800146
Mark Lobodzinski72346292015-07-02 16:49:40 -0600147 VkPhysicalDeviceMemoryProperties memory_properties_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148};
149
Chia-I Wua2636292015-07-03 10:41:20 +0800150class Device : public internal::Handle<VkDevice> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600151public:
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800152 explicit Device(VkPhysicalDevice phy) : phy_(phy) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 ~Device();
154
155 // vkCreateDevice()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600156 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -0600157 void init(std::vector<const char*> &layers, std::vector<const char *> &extensions); // all queues, all extensions, etc
158 void init() { std::vector<const char *> layers; std::vector<const char *> extensions; init(layers, extensions); };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600159
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800160 const PhysicalDevice &phy() const { return phy_; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161
Jon Ashburn1245cec2015-05-18 13:20:15 -0600162 // vkGetDeviceProcAddr()
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600163 PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); }
Jon Ashburn1245cec2015-05-18 13:20:15 -0600164
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600165 // vkGetDeviceQueue()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500166 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600167 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
168 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
169 uint32_t graphics_queue_node_index_;
170
171 struct Format {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600172 VkFormat format;
173 VkImageTiling tiling;
174 VkFlags features;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600175 };
176 // vkGetFormatInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600177 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178 const std::vector<Format> &formats() const { return formats_; }
179
180 // vkDeviceWaitIdle()
181 void wait();
182
183 // vkWaitForFences()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600184 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
185 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600186
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800187 // vkUpdateDescriptorSets()
188 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
189 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
190
191 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
192 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors);
193 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
194 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors);
195
196 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
197 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
198 uint32_t count);
199
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600200private:
201 enum QueueIndex {
202 GRAPHICS,
203 COMPUTE,
204 DMA,
205 QUEUE_COUNT,
206 };
207
208 void init_queues();
209 void init_formats();
210
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800211 PhysicalDevice phy_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600212
213 std::vector<Queue *> queues_[QUEUE_COUNT];
214 std::vector<Format> formats_;
215};
216
Chia-I Wuf2862c72015-07-03 10:53:18 +0800217class Queue : public internal::Handle<VkQueue> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218public:
Tony Barbour0caa94f2015-07-23 10:35:30 -0600219 explicit Queue(VkQueue queue, int index) : Handle(queue) {family_index_ = index;}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220
221 // vkQueueSubmit()
222 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
223 void submit(const CmdBuffer &cmd, Fence &fence);
224 void submit(const CmdBuffer &cmd);
225
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600226 // vkQueueWaitIdle()
227 void wait();
228
229 // vkQueueSignalSemaphore()
230 // vkQueueWaitSemaphore()
231 void signal_semaphore(Semaphore &sem);
232 void wait_semaphore(Semaphore &sem);
Tony Barbour0caa94f2015-07-23 10:35:30 -0600233
234 int get_family_index() {return family_index_;}
235
236private:
237 int family_index_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238};
239
Chia-I Wuba0836f2015-07-03 10:58:57 +0800240class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600241public:
Chia-I Wuba0836f2015-07-03 10:58:57 +0800242 ~DeviceMemory();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600243
244 // vkAllocMemory()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600245 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600246
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247 // vkMapMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600248 const void *map(VkFlags flags) const;
249 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250 const void *map() const { return map(0); }
251 void *map() { return map(0); }
252
253 // vkUnmapMemory()
254 void unmap() const;
255
Chia-I Wuba0836f2015-07-03 10:58:57 +0800256 static VkMemoryAllocInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600257};
258
Chia-I Wua4992342015-07-03 11:45:55 +0800259class Fence : public internal::NonDispHandle<VkFence> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600260public:
Chia-I Wua4992342015-07-03 11:45:55 +0800261 ~Fence();
262
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600263 // vkCreateFence()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600264 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265
266 // vkGetFenceStatus()
Chia-I Wua4992342015-07-03 11:45:55 +0800267 VkResult status() const { return vkGetFenceStatus(device(), handle()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600268
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600269 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
270 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600271};
272
Chia-I Wu2454b922015-07-03 11:49:42 +0800273class Semaphore : public internal::NonDispHandle<VkSemaphore> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600274public:
Chia-I Wu2454b922015-07-03 11:49:42 +0800275 ~Semaphore();
276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 // vkCreateSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279
Tony Barbour864fd382015-06-26 12:56:09 -0600280 static VkSemaphoreCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600281};
282
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800283class Event : public internal::NonDispHandle<VkEvent> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600284public:
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800285 ~Event();
286
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600287 // vkCreateEvent()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600288 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600289
290 // vkGetEventStatus()
291 // vkSetEvent()
292 // vkResetEvent()
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800293 VkResult status() const { return vkGetEventStatus(device(), handle()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 void set();
295 void reset();
296
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600298};
299
Chia-I Wufd0ce992015-07-03 11:49:42 +0800300class QueryPool : public internal::NonDispHandle<VkQueryPool> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600301public:
Chia-I Wufd0ce992015-07-03 11:49:42 +0800302 ~QueryPool();
303
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600304 // vkCreateQueryPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600305 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306
307 // vkGetQueryPoolResults()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600308 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311};
312
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800313class Buffer : public internal::NonDispHandle<VkBuffer> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314public:
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800315 explicit Buffer() : NonDispHandle() {}
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600316 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbour8205d902015-04-16 15:59:00 -0600317 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800319 ~Buffer();
320
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600321 // vkCreateBuffer()
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800322 void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props);
323 void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); }
324 void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props) { init(dev, create_info(size, 0), mem_props); }
325 void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); }
Cody Northropd0e7d222015-06-22 14:56:14 -0600326 void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT), reqs); }
327 void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); }
328 void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT | VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); }
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600329 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800331 // get the internal memory
332 const DeviceMemory &memory() const { return internal_mem_; }
333 DeviceMemory &memory() { return internal_mem_; }
334
335 // vkGetObjectMemoryRequirements()
336 VkMemoryRequirements memory_requirements() const;
337
338 // vkBindObjectMemory()
339 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500340
Tony Barbour8205d902015-04-16 15:59:00 -0600341 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600343 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbour8205d902015-04-16 15:59:00 -0600344 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600346 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800348 barrier.buffer = handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 barrier.outputMask = output_mask;
350 barrier.inputMask = input_mask;
351 barrier.offset = offset;
352 barrier.size = size;
353 return barrier;
354 }
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800355
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600356private:
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600357 VkBufferCreateInfo create_info_;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800358
359 DeviceMemory internal_mem_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360};
361
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800362class BufferView : public internal::NonDispHandle<VkBufferView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800364 ~BufferView();
365
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366 // vkCreateBufferView()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600367 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368};
369
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800370class Image : public internal::NonDispHandle<VkImage> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600371public:
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800372 explicit Image() : NonDispHandle(), format_features_(0) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600373 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600374
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800375 ~Image();
376
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 // vkCreateImage()
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800378 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props);
379 void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600380 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600381
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800382 // get the internal memory
383 const DeviceMemory &memory() const { return internal_mem_; }
384 DeviceMemory &memory() { return internal_mem_; }
385
386 // vkGetObjectMemoryRequirements()
387 VkMemoryRequirements memory_requirements() const;
388
389 // vkBindObjectMemory()
390 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391
Tony Barbour426b9052015-06-24 16:06:58 -0600392 // vkGetImageSubresourceLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600393 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394
395 bool transparent() const;
Tony Barbour8205d902015-04-16 15:59:00 -0600396 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600397
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600398 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
399 VkExtent3D extent() const { return create_info_.extent; }
400 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
401 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600402
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600403 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
404 VkImageLayout old_layout,
405 VkImageLayout new_layout,
406 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600408 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
410 barrier.outputMask = output_mask;
411 barrier.inputMask = input_mask;
412 barrier.oldLayout = old_layout;
413 barrier.newLayout = new_layout;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800414 barrier.image = handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 barrier.subresourceRange = range;
416 return barrier;
417 }
418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600419 static VkImageCreateInfo create_info();
420 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
421 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
422 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600424 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
425 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600426
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600427 static VkExtent2D extent(int32_t width, int32_t height);
428 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
429 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
432 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600433
434private:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600435 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600436
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600437 VkImageCreateInfo create_info_;
438 VkFlags format_features_;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800439
440 DeviceMemory internal_mem_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600441};
442
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800443class ImageView : public internal::NonDispHandle<VkImageView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600444public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800445 ~ImageView();
446
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600447 // vkCreateImageView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449};
450
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800451//class AttachmentView : public DerivedObject<VkAttachmentView, Object, VK_OBJECT_TYPE_ATTACHMENT_VIEW> {
452class AttachmentView : public internal::NonDispHandle<VkAttachmentView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600453public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800454 ~AttachmentView();
455
Chia-I Wuc278df82015-07-07 11:50:03 +0800456 // vkCreateAttachmentView()
457 void init(const Device &dev, const VkAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600458};
459
Chia-I Wub48eddb2015-07-03 11:49:42 +0800460class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600461public:
Chia-I Wub48eddb2015-07-03 11:49:42 +0800462 ~ShaderModule();
463
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600464 // vkCreateShaderModule()
465 void init(const Device &dev, const VkShaderModuleCreateInfo &info);
466 VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
467
468 static VkShaderModuleCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
469};
470
Chia-I Wub48eddb2015-07-03 11:49:42 +0800471class Shader : public internal::NonDispHandle<VkShader> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472public:
Chia-I Wub48eddb2015-07-03 11:49:42 +0800473 ~Shader();
474
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475 // vkCreateShader()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600476 void init(const Device &dev, const VkShaderCreateInfo &info);
477 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600478
Cody Northrop87ae5e12015-08-24 15:11:10 -0600479 static VkShaderCreateInfo create_info(VkShaderModule module, const char *pName, VkFlags flags, VkShaderStage stage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480};
481
Chia-I Wu2b1d4d02015-07-03 11:49:42 +0800482class Pipeline : public internal::NonDispHandle<VkPipeline> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600483public:
Chia-I Wu2b1d4d02015-07-03 11:49:42 +0800484 ~Pipeline();
485
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600486 // 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
Chris Forbesdc2188c2015-05-25 11:13:26 +1200497 // vkCreateGraphicsPipeline with error return
498 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
499
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600500 // vkStorePipeline()
501 size_t store(size_t size, void *data);
502};
503
Chia-I Wudeb99132015-07-03 11:49:42 +0800504class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> {
505public:
506 ~PipelineLayout();
507
508 // vCreatePipelineLayout()
509 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
510};
511
Chia-I Wu6abe35d2015-07-03 11:49:42 +0800512class Sampler : public internal::NonDispHandle<VkSampler> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600513public:
Chia-I Wu6abe35d2015-07-03 11:49:42 +0800514 ~Sampler();
515
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600516 // vkCreateSampler()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600517 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600518};
519
Chia-I Wu55a871f2015-07-03 11:49:42 +0800520class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600521public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800522 ~DescriptorSetLayout();
523
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600525 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600526};
527
Chia-I Wu55a871f2015-07-03 11:49:42 +0800528class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600529public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800530 ~DescriptorPool();
531
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600532 // vkCreateDescriptorPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600533 void init(const Device &dev, VkDescriptorPoolUsage usage,
534 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600535
536 // vkResetDescriptorPool()
537 void reset();
538
539 // vkAllocDescriptorSets()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500540 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
541 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
542 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600543};
544
Chia-I Wu55a871f2015-07-03 11:49:42 +0800545class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600546public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800547 ~DescriptorSet();
548
549 explicit DescriptorSet() : NonDispHandle() {}
Tony Barboure84a8d62015-07-10 14:10:27 -0600550 explicit DescriptorSet(const Device &dev, VkDescriptorPool pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { pool_ = pool;}
551
552private:
553 VkDescriptorPool pool_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600554};
555
Tony Barbourde4124d2015-07-03 10:33:54 -0600556class DynamicViewportState : public internal::NonDispHandle<VkDynamicViewportState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600557public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800558 ~DynamicViewportState();
559
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600560 // vkCreateDynamicViewportState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600561 void init(const Device &dev, const VkDynamicViewportStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562};
563
Cody Northropf5bd2252015-08-17 11:10:49 -0600564class DynamicRasterLineState : public internal::NonDispHandle<VkDynamicRasterLineState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600565public:
Cody Northropf5bd2252015-08-17 11:10:49 -0600566 ~DynamicRasterLineState();
Chia-I Wu6b11e602015-07-03 11:49:42 +0800567
Cody Northropf5bd2252015-08-17 11:10:49 -0600568 // vkCreateDynamicRasterLineState()
569 void init(const Device &dev, const VkDynamicRasterLineStateCreateInfo &info);
570};
571
572class DynamicRasterDepthBiasState : public internal::NonDispHandle<VkDynamicRasterDepthBiasState> {
573public:
574 ~DynamicRasterDepthBiasState();
575
576 // vkCreateDynamicRasterDepthBiasState()
577 void init(const Device &dev, const VkDynamicRasterDepthBiasStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600578};
579
Tony Barbourde4124d2015-07-03 10:33:54 -0600580class DynamicColorBlendState : public internal::NonDispHandle<VkDynamicColorBlendState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800582 ~DynamicColorBlendState();
583
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 // vkCreateDynamicColorBlendState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600585 void init(const Device &dev, const VkDynamicColorBlendStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586};
587
Cody Northrop2605cb02015-08-18 15:21:16 -0600588class DynamicDepthState : public internal::NonDispHandle<VkDynamicDepthState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600589public:
Cody Northrop2605cb02015-08-18 15:21:16 -0600590 ~DynamicDepthState();
Chia-I Wu6b11e602015-07-03 11:49:42 +0800591
Cody Northrop2605cb02015-08-18 15:21:16 -0600592 // vkCreateDynamicDepthState()
593 void init(const Device &dev, const VkDynamicDepthStateCreateInfo &info);
594};
595
596class DynamicStencilState : public internal::NonDispHandle<VkDynamicStencilState> {
597public:
598 ~DynamicStencilState();
599
600 // vkCreateDynamicStencilState()
601 void init(const Device &dev, const VkDynamicStencilStateCreateInfo &frontInfo, const VkDynamicStencilStateCreateInfo &backInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600602};
603
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -0600604class CmdPool : public internal::NonDispHandle<VkCmdPool> {
605public:
606 ~CmdPool();
607
608 explicit CmdPool() : NonDispHandle() {}
609 explicit CmdPool(const Device &dev, const VkCmdPoolCreateInfo &info) { init(dev, info); }
610
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -0600611 void init(const Device &dev, const VkCmdPoolCreateInfo &info);
612
613 static VkCmdPoolCreateInfo create_info(uint32_t queue_family_index);
614};
615
616inline VkCmdPoolCreateInfo CmdPool::create_info(uint32_t queue_family_index)
617{
618 VkCmdPoolCreateInfo info = {};
Tony Barbour73c22f42015-07-27 09:36:24 -0600619 info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -0600620 info.queueFamilyIndex = queue_family_index;
621 return info;
622}
623
Chia-I Wu78c2a352015-07-03 11:49:42 +0800624class CmdBuffer : public internal::Handle<VkCmdBuffer> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625public:
Chia-I Wu78c2a352015-07-03 11:49:42 +0800626 ~CmdBuffer();
627
628 explicit CmdBuffer() : Handle() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600629 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630
631 // vkCreateCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600632 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600633
634 // vkBeginCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600635 void begin(const VkCmdBufferBeginInfo *info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600636 void begin();
637
638 // vkEndCommandBuffer()
639 // vkResetCommandBuffer()
640 void end();
Cody Northropf02f9f82015-07-09 18:08:05 -0600641 void reset(VkCmdBufferResetFlags flags);
642 void reset() { reset(VK_CMD_BUFFER_RESET_RELEASE_RESOURCES); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600643
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -0600644 static VkCmdBufferCreateInfo create_info(VkCmdPool const &pool);
Chia-I Wu78c2a352015-07-03 11:49:42 +0800645
646private:
647 VkDevice dev_handle_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648};
649
Chia-I Wuba0836f2015-07-03 10:58:57 +0800650inline VkMemoryAllocInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600651{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600652 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600653 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Chia-I Wuba0836f2015-07-03 10:58:57 +0800654 info.allocationSize = size;
655 info.memoryTypeIndex = memory_type_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656 return info;
657}
658
Tony Barbour8205d902015-04-16 15:59:00 -0600659inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600660{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600661 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600662 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
663 info.size = size;
664 info.usage = usage;
665 return info;
666}
667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600668inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600669{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600670 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600671 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
672 info.flags = flags;
673 return info;
674}
675
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600676inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600678 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
680 return info;
681}
682
Tony Barbour864fd382015-06-26 12:56:09 -0600683inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600684{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600686 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600687 info.flags = flags;
688 return info;
689}
690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600691inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600692{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600693 VkEventCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600694 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
695 info.flags = flags;
696 return info;
697}
698
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600699inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600700{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600701 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600702 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
703 info.queryType = type;
704 info.slots = slot_count;
705 return info;
706}
707
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600708inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600709{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600710 VkImageCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600711 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
712 info.extent.width = 1;
713 info.extent.height = 1;
714 info.extent.depth = 1;
715 info.mipLevels = 1;
716 info.arraySize = 1;
717 info.samples = 1;
718 return info;
719}
720
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600722{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600723 VkImageSubresource subres = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600724 subres.aspect = aspect;
725 subres.mipLevel = mip_level;
726 subres.arraySlice = array_slice;
727 return subres;
728}
729
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600730inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600731{
732 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
733}
734
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600735inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 uint32_t base_array_slice, uint32_t array_size)
737{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600738 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600739 range.aspect = aspect;
740 range.baseMipLevel = base_mip_level;
741 range.mipLevels = mip_levels;
742 range.baseArraySlice = base_array_slice;
743 range.arraySize = array_size;
744 return range;
745}
746
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748{
749 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
750}
751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600753{
754 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
755}
756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 VkExtent2D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 extent.width = width;
761 extent.height = height;
762 return extent;
763}
764
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600765inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766{
767 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
768 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
769 return Image::extent(width, height);
770}
771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600773{
774 return Image::extent(extent.width, extent.height);
775}
776
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600777inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600778{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 VkExtent3D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600780 extent.width = width;
781 extent.height = height;
782 extent.depth = depth;
783 return extent;
784}
785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600786inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787{
788 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
789 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
790 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
791 return Image::extent(width, height, depth);
792}
793
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600794inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const void *code, VkFlags flags)
795{
796 VkShaderModuleCreateInfo info = {};
797 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
798 info.codeSize = code_size;
799 info.pCode = code;
800 info.flags = flags;
801 return info;
802}
803
Cody Northrop87ae5e12015-08-24 15:11:10 -0600804inline VkShaderCreateInfo Shader::create_info(VkShaderModule module, const char *pName, VkFlags flags, VkShaderStage stage)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600806 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600807 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600808 info.module = module;
809 info.pName = pName;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600810 info.flags = flags;
Cody Northrop87ae5e12015-08-24 15:11:10 -0600811 info.stage = stage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600812 return info;
813}
814
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800815inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
816 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600817{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800818 VkWriteDescriptorSet write = {};
819 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800820 write.destSet = set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800821 write.destBinding = binding;
822 write.destArrayElement = array_element;
823 write.count = count;
824 write.descriptorType = type;
825 write.pDescriptors = descriptors;
826 return write;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600827}
828
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800829inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
830 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800832 return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600833}
834
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800835inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
836 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
837 uint32_t count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600838{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800839 VkCopyDescriptorSet copy = {};
840 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800841 copy.srcSet = src_set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800842 copy.srcBinding = src_binding;
843 copy.srcArrayElement = src_array_element;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800844 copy.destSet = dst_set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800845 copy.destBinding = dst_binding;
846 copy.destArrayElement = dst_array_element;
847 copy.count = count;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800849 return copy;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600850}
851
Courtney Goeltzenleuchter902d0812015-07-10 19:50:17 -0600852inline VkCmdBufferCreateInfo CmdBuffer::create_info(VkCmdPool const &pool)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600854 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600855 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Cody Northropf02f9f82015-07-09 18:08:05 -0600856 info.cmdPool = pool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 return info;
858}
859
860}; // namespace vk_testing
861
862#endif // VKTESTBINDING_H