blob: 82340d606013da0e5286427cc6a488dc1e7e5016 [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;
59class DynamicRasterState;
60class DynamicColorBlendState;
61class DynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060062class CmdBuffer;
63
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060064std::vector<VkLayerProperties> GetGlobalLayers();
65std::vector<VkExtensionProperties> GetGlobalExtensions();
66std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName);
67
Chia-I Wua10be9d2015-07-03 10:13:26 +080068namespace internal {
69
70template<typename T>
71class Handle {
72public:
73 const T &handle() const { return handle_; }
74 bool initialized() const { return (handle_ != VK_NULL_HANDLE); }
75
76protected:
77 typedef T handle_type;
78
79 explicit Handle() : handle_(VK_NULL_HANDLE) {}
80 explicit Handle(T handle) : handle_(handle) {}
81
82 void init(T handle)
83 {
84 assert(!initialized());
85 handle_ = handle;
86 }
87
88private:
89 // handles are non-copyable
90 Handle(const Handle &);
91 Handle &operator=(const Handle &);
92
93 T handle_;
94};
95
96
97template<typename T>
98class NonDispHandle : public Handle<T> {
99protected:
100 explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {}
101 explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {}
102
103 const VkDevice &device() const { return dev_handle_; }
104
105 void init(VkDevice dev, T handle)
106 {
107 assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE);
108 Handle<T>::init(handle);
109 dev_handle_ = dev;
110 }
111
112private:
113 VkDevice dev_handle_;
114};
115
116} // namespace internal
117
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800118class PhysicalDevice : public internal::Handle<VkPhysicalDevice> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600119public:
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800120 explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy)
Mark Lobodzinski72346292015-07-02 16:49:40 -0600121 {
122 memory_properties_ = memory_properties();
123 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600124
Tony Barbour8205d902015-04-16 15:59:00 -0600125 VkPhysicalDeviceProperties properties() const;
126 VkPhysicalDevicePerformance performance() const;
127 VkPhysicalDeviceMemoryProperties memory_properties() const;
128 std::vector<VkPhysicalDeviceQueueProperties> queue_properties() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600129
Mark Lobodzinski72346292015-07-02 16:49:40 -0600130 VkResult set_memory_type(const uint32_t type_bits, VkMemoryAllocInfo *info, const VkMemoryPropertyFlags properties) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600132 // vkGetPhysicalDeviceExtensionProperties()
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600133 std::vector<VkExtensionProperties> extensions() const;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600134 std::vector<VkExtensionProperties> extensions(const char * pLayerName) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135
136 // vkEnumerateLayers()
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600137 std::vector<VkLayerProperties> layers() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600138
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139private:
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600140 void add_extension_dependencies(uint32_t dependency_count,
141 VkExtensionProperties *depencency_props,
142 std::vector<VkExtensionProperties> &ext_list);
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800143
Mark Lobodzinski72346292015-07-02 16:49:40 -0600144 VkPhysicalDeviceMemoryProperties memory_properties_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145};
146
Chia-I Wua2636292015-07-03 10:41:20 +0800147class Device : public internal::Handle<VkDevice> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148public:
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800149 explicit Device(VkPhysicalDevice phy) : phy_(phy) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600150 ~Device();
151
152 // vkCreateDevice()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600153 void init(const VkDeviceCreateInfo &info);
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -0600154 void init(std::vector<const char*> &layers, std::vector<const char *> &extensions); // all queues, all extensions, etc
155 void init() { std::vector<const char *> layers; std::vector<const char *> extensions; init(layers, extensions); };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800157 const PhysicalDevice &phy() const { return phy_; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600158
Jon Ashburn1245cec2015-05-18 13:20:15 -0600159 // vkGetDeviceProcAddr()
Chia-I Wua2636292015-07-03 10:41:20 +0800160 void *get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); }
Jon Ashburn1245cec2015-05-18 13:20:15 -0600161
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600162 // vkGetDeviceQueue()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500163 const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600164 const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; }
165 const std::vector<Queue *> &dma_queues() { return queues_[DMA]; }
166 uint32_t graphics_queue_node_index_;
167
168 struct Format {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600169 VkFormat format;
170 VkImageTiling tiling;
171 VkFlags features;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600172 };
173 // vkGetFormatInfo()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600174 VkFormatProperties format_properties(VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600175 const std::vector<Format> &formats() const { return formats_; }
176
177 // vkDeviceWaitIdle()
178 void wait();
179
180 // vkWaitForFences()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600181 VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout);
182 VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600183
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800184 // vkUpdateDescriptorSets()
185 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies);
186 VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); }
187
188 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
189 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors);
190 static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
191 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors);
192
193 static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
194 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
195 uint32_t count);
196
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600197private:
198 enum QueueIndex {
199 GRAPHICS,
200 COMPUTE,
201 DMA,
202 QUEUE_COUNT,
203 };
204
205 void init_queues();
206 void init_formats();
207
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800208 PhysicalDevice phy_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600209
210 std::vector<Queue *> queues_[QUEUE_COUNT];
211 std::vector<Format> formats_;
212};
213
Chia-I Wuf2862c72015-07-03 10:53:18 +0800214class Queue : public internal::Handle<VkQueue> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215public:
Chia-I Wuf2862c72015-07-03 10:53:18 +0800216 explicit Queue(VkQueue queue) : Handle(queue) {}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217
218 // vkQueueSubmit()
219 void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence);
220 void submit(const CmdBuffer &cmd, Fence &fence);
221 void submit(const CmdBuffer &cmd);
222
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600223 // vkQueueWaitIdle()
224 void wait();
225
226 // vkQueueSignalSemaphore()
227 // vkQueueWaitSemaphore()
228 void signal_semaphore(Semaphore &sem);
229 void wait_semaphore(Semaphore &sem);
230};
231
Chia-I Wuba0836f2015-07-03 10:58:57 +0800232class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233public:
Chia-I Wuba0836f2015-07-03 10:58:57 +0800234 ~DeviceMemory();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600235
236 // vkAllocMemory()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600237 void init(const Device &dev, const VkMemoryAllocInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600239 // vkMapMemory()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600240 const void *map(VkFlags flags) const;
241 void *map(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242 const void *map() const { return map(0); }
243 void *map() { return map(0); }
244
245 // vkUnmapMemory()
246 void unmap() const;
247
Chia-I Wuba0836f2015-07-03 10:58:57 +0800248 static VkMemoryAllocInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600249};
250
Chia-I Wua4992342015-07-03 11:45:55 +0800251class Fence : public internal::NonDispHandle<VkFence> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600252public:
Chia-I Wua4992342015-07-03 11:45:55 +0800253 ~Fence();
254
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600255 // vkCreateFence()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600256 void init(const Device &dev, const VkFenceCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600257
258 // vkGetFenceStatus()
Chia-I Wua4992342015-07-03 11:45:55 +0800259 VkResult status() const { return vkGetFenceStatus(device(), handle()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600260
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600261 static VkFenceCreateInfo create_info(VkFenceCreateFlags flags);
262 static VkFenceCreateInfo create_info();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600263};
264
Chia-I Wu2454b922015-07-03 11:49:42 +0800265class Semaphore : public internal::NonDispHandle<VkSemaphore> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266public:
Chia-I Wu2454b922015-07-03 11:49:42 +0800267 ~Semaphore();
268
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600269 // vkCreateSemaphore()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270 void init(const Device &dev, const VkSemaphoreCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600271
Tony Barbour864fd382015-06-26 12:56:09 -0600272 static VkSemaphoreCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273};
274
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800275class Event : public internal::NonDispHandle<VkEvent> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600276public:
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800277 ~Event();
278
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279 // vkCreateEvent()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280 void init(const Device &dev, const VkEventCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600281
282 // vkGetEventStatus()
283 // vkSetEvent()
284 // vkResetEvent()
Chia-I Wu9b6db1d2015-07-03 11:49:42 +0800285 VkResult status() const { return vkGetEventStatus(device(), handle()); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600286 void set();
287 void reset();
288
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600289 static VkEventCreateInfo create_info(VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600290};
291
Chia-I Wufd0ce992015-07-03 11:49:42 +0800292class QueryPool : public internal::NonDispHandle<VkQueryPool> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600293public:
Chia-I Wufd0ce992015-07-03 11:49:42 +0800294 ~QueryPool();
295
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600296 // vkCreateQueryPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 void init(const Device &dev, const VkQueryPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600298
299 // vkGetQueryPoolResults()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300 VkResult results(uint32_t start, uint32_t count, size_t size, void *data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600301
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600302 static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600303};
304
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800305class Buffer : public internal::NonDispHandle<VkBuffer> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306public:
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800307 explicit Buffer() : NonDispHandle() {}
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600308 explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); }
Tony Barbour8205d902015-04-16 15:59:00 -0600309 explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600310
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800311 ~Buffer();
312
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600313 // vkCreateBuffer()
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800314 void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props);
315 void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); }
316 void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props) { init(dev, create_info(size, 0), mem_props); }
317 void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); }
Cody Northropd0e7d222015-06-22 14:56:14 -0600318 void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT), reqs); }
319 void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); }
320 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 -0600321 void init_no_mem(const Device &dev, const VkBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600322
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800323 // get the internal memory
324 const DeviceMemory &memory() const { return internal_mem_; }
325 DeviceMemory &memory() { return internal_mem_; }
326
327 // vkGetObjectMemoryRequirements()
328 VkMemoryRequirements memory_requirements() const;
329
330 // vkBindObjectMemory()
331 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500332
Tony Barbour8205d902015-04-16 15:59:00 -0600333 static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600335 VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask,
Tony Barbour8205d902015-04-16 15:59:00 -0600336 VkDeviceSize offset, VkDeviceSize size) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600337 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600338 VkBufferMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600339 barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800340 barrier.buffer = handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600341 barrier.outputMask = output_mask;
342 barrier.inputMask = input_mask;
343 barrier.offset = offset;
344 barrier.size = size;
345 return barrier;
346 }
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800347
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600348private:
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600349 VkBufferCreateInfo create_info_;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800350
351 DeviceMemory internal_mem_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600352};
353
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800354class BufferView : public internal::NonDispHandle<VkBufferView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600355public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800356 ~BufferView();
357
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600358 // vkCreateBufferView()
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600359 void init(const Device &dev, const VkBufferViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360};
361
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800362class Image : public internal::NonDispHandle<VkImage> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363public:
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800364 explicit Image() : NonDispHandle(), format_features_(0) {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800367 ~Image();
368
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600369 // vkCreateImage()
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800370 void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props);
371 void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600372 void init_no_mem(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800374 // get the internal memory
375 const DeviceMemory &memory() const { return internal_mem_; }
376 DeviceMemory &memory() { return internal_mem_; }
377
378 // vkGetObjectMemoryRequirements()
379 VkMemoryRequirements memory_requirements() const;
380
381 // vkBindObjectMemory()
382 void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600383
Tony Barbour426b9052015-06-24 16:06:58 -0600384 // vkGetImageSubresourceLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600385 VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386
387 bool transparent() const;
Tony Barbour8205d902015-04-16 15:59:00 -0600388 bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600390 VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); }
391 VkExtent3D extent() const { return create_info_.extent; }
392 VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); }
393 VkFormat format() const {return create_info_.format;}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600395 VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask,
396 VkImageLayout old_layout,
397 VkImageLayout new_layout,
398 const VkImageSubresourceRange &range) const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600399 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600400 VkImageMemoryBarrier barrier = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
402 barrier.outputMask = output_mask;
403 barrier.inputMask = input_mask;
404 barrier.oldLayout = old_layout;
405 barrier.newLayout = new_layout;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800406 barrier.image = handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407 barrier.subresourceRange = range;
408 return barrier;
409 }
410
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 static VkImageCreateInfo create_info();
412 static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice);
413 static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice);
414 static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 uint32_t base_array_slice, uint32_t array_size);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600416 static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect);
417 static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600419 static VkExtent2D extent(int32_t width, int32_t height);
420 static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level);
421 static VkExtent2D extent(const VkExtent3D &extent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600423 static VkExtent3D extent(int32_t width, int32_t height, int32_t depth);
424 static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425
426private:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600427 void init_info(const Device &dev, const VkImageCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600429 VkImageCreateInfo create_info_;
430 VkFlags format_features_;
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800431
432 DeviceMemory internal_mem_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600433};
434
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800435class ImageView : public internal::NonDispHandle<VkImageView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600436public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800437 ~ImageView();
438
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439 // vkCreateImageView()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600440 void init(const Device &dev, const VkImageViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600441};
442
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800443//class AttachmentView : public DerivedObject<VkAttachmentView, Object, VK_OBJECT_TYPE_ATTACHMENT_VIEW> {
444class AttachmentView : public internal::NonDispHandle<VkAttachmentView> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600445public:
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800446 ~AttachmentView();
447
Chia-I Wuc278df82015-07-07 11:50:03 +0800448 // vkCreateAttachmentView()
449 void init(const Device &dev, const VkAttachmentViewCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450};
451
Chia-I Wub48eddb2015-07-03 11:49:42 +0800452class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600453public:
Chia-I Wub48eddb2015-07-03 11:49:42 +0800454 ~ShaderModule();
455
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600456 // vkCreateShaderModule()
457 void init(const Device &dev, const VkShaderModuleCreateInfo &info);
458 VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info);
459
460 static VkShaderModuleCreateInfo create_info(size_t code_size, const void *code, VkFlags flags);
461};
462
Chia-I Wub48eddb2015-07-03 11:49:42 +0800463class Shader : public internal::NonDispHandle<VkShader> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464public:
Chia-I Wub48eddb2015-07-03 11:49:42 +0800465 ~Shader();
466
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467 // vkCreateShader()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600468 void init(const Device &dev, const VkShaderCreateInfo &info);
469 VkResult init_try(const Device &dev, const VkShaderCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600471 static VkShaderCreateInfo create_info(VkShaderModule module, const char *pName, VkFlags flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472};
473
Chia-I Wu2b1d4d02015-07-03 11:49:42 +0800474class Pipeline : public internal::NonDispHandle<VkPipeline> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475public:
Chia-I Wu2b1d4d02015-07-03 11:49:42 +0800476 ~Pipeline();
477
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600478 // vkCreateGraphicsPipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600479 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480 // vkCreateGraphicsPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600481 void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482 // vkCreateComputePipeline()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600483 void init(const Device &dev, const VkComputePipelineCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600484 // vkLoadPipeline()
485 void init(const Device&dev, size_t size, const void *data);
486 // vkLoadPipelineDerivative()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600487 void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600488
Chris Forbesdc2188c2015-05-25 11:13:26 +1200489 // vkCreateGraphicsPipeline with error return
490 VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info);
491
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600492 // vkStorePipeline()
493 size_t store(size_t size, void *data);
494};
495
Chia-I Wudeb99132015-07-03 11:49:42 +0800496class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> {
497public:
498 ~PipelineLayout();
499
500 // vCreatePipelineLayout()
501 void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts);
502};
503
Chia-I Wu6abe35d2015-07-03 11:49:42 +0800504class Sampler : public internal::NonDispHandle<VkSampler> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505public:
Chia-I Wu6abe35d2015-07-03 11:49:42 +0800506 ~Sampler();
507
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508 // vkCreateSampler()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600509 void init(const Device &dev, const VkSamplerCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600510};
511
Chia-I Wu55a871f2015-07-03 11:49:42 +0800512class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600513public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800514 ~DescriptorSetLayout();
515
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600516 // vkCreateDescriptorSetLayout()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600517 void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600518};
519
Chia-I Wu55a871f2015-07-03 11:49:42 +0800520class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600521public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800522 ~DescriptorPool();
523
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524 // vkCreateDescriptorPool()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600525 void init(const Device &dev, VkDescriptorPoolUsage usage,
526 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600527
528 // vkResetDescriptorPool()
529 void reset();
530
531 // vkAllocDescriptorSets()
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500532 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts);
533 std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count);
534 DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600535};
536
Chia-I Wu55a871f2015-07-03 11:49:42 +0800537class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600538public:
Chia-I Wu55a871f2015-07-03 11:49:42 +0800539 ~DescriptorSet();
540
541 explicit DescriptorSet() : NonDispHandle() {}
Tony Barboure84a8d62015-07-10 14:10:27 -0600542 explicit DescriptorSet(const Device &dev, VkDescriptorPool pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { pool_ = pool;}
543
544private:
545 VkDescriptorPool pool_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600546};
547
Tony Barbourde4124d2015-07-03 10:33:54 -0600548class DynamicViewportState : public internal::NonDispHandle<VkDynamicViewportState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600549public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800550 ~DynamicViewportState();
551
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600552 // vkCreateDynamicViewportState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600553 void init(const Device &dev, const VkDynamicViewportStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600554};
555
Tony Barbourde4124d2015-07-03 10:33:54 -0600556class DynamicRasterState : public internal::NonDispHandle<VkDynamicRasterState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600557public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800558 ~DynamicRasterState();
559
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600560 // vkCreateDynamicRasterState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600561 void init(const Device &dev, const VkDynamicRasterStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562};
563
Tony Barbourde4124d2015-07-03 10:33:54 -0600564class DynamicColorBlendState : public internal::NonDispHandle<VkDynamicColorBlendState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600565public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800566 ~DynamicColorBlendState();
567
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 // vkCreateDynamicColorBlendState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600569 void init(const Device &dev, const VkDynamicColorBlendStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600570};
571
Tony Barbourde4124d2015-07-03 10:33:54 -0600572class DynamicDepthStencilState : public internal::NonDispHandle<VkDynamicDepthStencilState> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600573public:
Chia-I Wu6b11e602015-07-03 11:49:42 +0800574 ~DynamicDepthStencilState();
575
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576 // vkCreateDynamicDepthStencilState()
Tony Barbourde4124d2015-07-03 10:33:54 -0600577 void init(const Device &dev, const VkDynamicDepthStencilStateCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600578};
579
Chia-I Wu78c2a352015-07-03 11:49:42 +0800580class CmdBuffer : public internal::Handle<VkCmdBuffer> {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581public:
Chia-I Wu78c2a352015-07-03 11:49:42 +0800582 ~CmdBuffer();
583
584 explicit CmdBuffer() : Handle() {}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600585 explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586
587 // vkCreateCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600588 void init(const Device &dev, const VkCmdBufferCreateInfo &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600589
590 // vkBeginCommandBuffer()
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600591 void begin(const VkCmdBufferBeginInfo *info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600592 void begin();
593
594 // vkEndCommandBuffer()
595 // vkResetCommandBuffer()
596 void end();
Cody Northropf02f9f82015-07-09 18:08:05 -0600597 void reset(VkCmdBufferResetFlags flags);
598 void reset() { reset(VK_CMD_BUFFER_RESET_RELEASE_RESOURCES); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600599
Cody Northropf02f9f82015-07-09 18:08:05 -0600600 static VkCmdBufferCreateInfo create_info(VkCmdPool pool);
Chia-I Wu78c2a352015-07-03 11:49:42 +0800601
602private:
603 VkDevice dev_handle_;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600604};
605
Chia-I Wuba0836f2015-07-03 10:58:57 +0800606inline VkMemoryAllocInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600608 VkMemoryAllocInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Chia-I Wuba0836f2015-07-03 10:58:57 +0800610 info.allocationSize = size;
611 info.memoryTypeIndex = memory_type_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600612 return info;
613}
614
Tony Barbour8205d902015-04-16 15:59:00 -0600615inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600617 VkBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
619 info.size = size;
620 info.usage = usage;
621 return info;
622}
623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
628 info.flags = flags;
629 return info;
630}
631
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600632inline VkFenceCreateInfo Fence::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600633{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600634 VkFenceCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
636 return info;
637}
638
Tony Barbour864fd382015-06-26 12:56:09 -0600639inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600640{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600641 VkSemaphoreCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600643 info.flags = flags;
644 return info;
645}
646
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600647inline VkEventCreateInfo Event::create_info(VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600649 VkEventCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
651 info.flags = flags;
652 return info;
653}
654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600655inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600657 VkQueryPoolCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
659 info.queryType = type;
660 info.slots = slot_count;
661 return info;
662}
663
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600664inline VkImageCreateInfo Image::create_info()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600666 VkImageCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
668 info.extent.width = 1;
669 info.extent.height = 1;
670 info.extent.depth = 1;
671 info.mipLevels = 1;
672 info.arraySize = 1;
673 info.samples = 1;
674 return info;
675}
676
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600677inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600679 VkImageSubresource subres = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 subres.aspect = aspect;
681 subres.mipLevel = mip_level;
682 subres.arraySlice = array_slice;
683 return subres;
684}
685
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600686inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600687{
688 return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice);
689}
690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600691inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600692 uint32_t base_array_slice, uint32_t array_size)
693{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600694 VkImageSubresourceRange range = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600695 range.aspect = aspect;
696 range.baseMipLevel = base_mip_level;
697 range.mipLevels = mip_levels;
698 range.baseArraySlice = base_array_slice;
699 range.arraySize = array_size;
700 return range;
701}
702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600703inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600704{
705 return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize);
706}
707
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600708inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600709{
710 return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1);
711}
712
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600713inline VkExtent2D Image::extent(int32_t width, int32_t height)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600714{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715 VkExtent2D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716 extent.width = width;
717 extent.height = height;
718 return extent;
719}
720
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600722{
723 const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1;
724 const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1;
725 return Image::extent(width, height);
726}
727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600728inline VkExtent2D Image::extent(const VkExtent3D &extent)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729{
730 return Image::extent(extent.width, extent.height);
731}
732
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600733inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600735 VkExtent3D extent = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 extent.width = width;
737 extent.height = height;
738 extent.depth = depth;
739 return extent;
740}
741
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600742inline VkExtent3D Image::extent(const VkExtent3D &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 const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1;
747 return Image::extent(width, height, depth);
748}
749
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600750inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const void *code, VkFlags flags)
751{
752 VkShaderModuleCreateInfo info = {};
753 info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
754 info.codeSize = code_size;
755 info.pCode = code;
756 info.flags = flags;
757 return info;
758}
759
760inline VkShaderCreateInfo Shader::create_info(VkShaderModule module, const char *pName, VkFlags flags)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600761{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600762 VkShaderCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600763 info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600764 info.module = module;
765 info.pName = pName;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766 info.flags = flags;
767 return info;
768}
769
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800770inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
771 VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600772{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800773 VkWriteDescriptorSet write = {};
774 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800775 write.destSet = set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800776 write.destBinding = binding;
777 write.destArrayElement = array_element;
778 write.count = count;
779 write.descriptorType = type;
780 write.pDescriptors = descriptors;
781 return write;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600782}
783
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800784inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element,
785 VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600786{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800787 return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600788}
789
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800790inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element,
791 const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element,
792 uint32_t count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800794 VkCopyDescriptorSet copy = {};
795 copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800796 copy.srcSet = src_set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800797 copy.srcBinding = src_binding;
798 copy.srcArrayElement = src_array_element;
Chia-I Wu55a871f2015-07-03 11:49:42 +0800799 copy.destSet = dst_set.handle();
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800800 copy.destBinding = dst_binding;
801 copy.destArrayElement = dst_array_element;
802 copy.count = count;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600803
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800804 return copy;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805}
806
Cody Northropf02f9f82015-07-09 18:08:05 -0600807inline VkCmdBufferCreateInfo CmdBuffer::create_info(VkCmdPool pool)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600808{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600809 VkCmdBufferCreateInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600810 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Cody Northropf02f9f82015-07-09 18:08:05 -0600811 info.cmdPool = pool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600812 return info;
813}
814
815}; // namespace vk_testing
816
817#endif // VKTESTBINDING_H