Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // 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 Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 27 | #include <assert.h> |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | |
| 29 | #include "vulkan.h" |
| 30 | |
| 31 | namespace vk_testing { |
| 32 | |
| 33 | typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function); |
| 34 | void set_error_callback(ErrorCallback callback); |
| 35 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 36 | class PhysicalDevice; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 37 | class Device; |
| 38 | class Queue; |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 39 | class DeviceMemory; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 40 | class Fence; |
| 41 | class Semaphore; |
| 42 | class Event; |
| 43 | class QueryPool; |
| 44 | class Buffer; |
| 45 | class BufferView; |
| 46 | class Image; |
| 47 | class ImageView; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 48 | class DepthStencilView; |
| 49 | class Shader; |
| 50 | class Pipeline; |
| 51 | class PipelineDelta; |
| 52 | class Sampler; |
| 53 | class DescriptorSetLayout; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 54 | class PipelineLayout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 55 | class DescriptorSetPool; |
| 56 | class DescriptorSet; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 57 | class CmdBuffer; |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 58 | class CmdPool; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 59 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 60 | std::vector<VkLayerProperties> GetGlobalLayers(); |
| 61 | std::vector<VkExtensionProperties> GetGlobalExtensions(); |
| 62 | std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName); |
| 63 | |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 64 | namespace internal { |
| 65 | |
| 66 | template<typename T> |
| 67 | class Handle { |
| 68 | public: |
| 69 | const T &handle() const { return handle_; } |
| 70 | bool initialized() const { return (handle_ != VK_NULL_HANDLE); } |
| 71 | |
| 72 | protected: |
| 73 | typedef T handle_type; |
| 74 | |
| 75 | explicit Handle() : handle_(VK_NULL_HANDLE) {} |
| 76 | explicit Handle(T handle) : handle_(handle) {} |
| 77 | |
| 78 | void init(T handle) |
| 79 | { |
| 80 | assert(!initialized()); |
| 81 | handle_ = handle; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | // handles are non-copyable |
| 86 | Handle(const Handle &); |
| 87 | Handle &operator=(const Handle &); |
| 88 | |
| 89 | T handle_; |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | template<typename T> |
| 94 | class NonDispHandle : public Handle<T> { |
| 95 | protected: |
| 96 | explicit NonDispHandle() : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {} |
| 97 | explicit NonDispHandle(VkDevice dev, T handle) : Handle<T>(handle), dev_handle_(dev) {} |
| 98 | |
| 99 | const VkDevice &device() const { return dev_handle_; } |
| 100 | |
| 101 | void init(VkDevice dev, T handle) |
| 102 | { |
| 103 | assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE); |
| 104 | Handle<T>::init(handle); |
| 105 | dev_handle_ = dev; |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | VkDevice dev_handle_; |
| 110 | }; |
| 111 | |
| 112 | } // namespace internal |
| 113 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 114 | class PhysicalDevice : public internal::Handle<VkPhysicalDevice> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | public: |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 116 | explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy) |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 117 | { |
| 118 | memory_properties_ = memory_properties(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 119 | device_properties_ = properties(); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 120 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 122 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 123 | VkPhysicalDeviceProperties properties() const; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 124 | VkPhysicalDeviceMemoryProperties memory_properties() const; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 125 | std::vector<VkQueueFamilyProperties> queue_properties() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 126 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 127 | bool set_memory_type(const uint32_t type_bits, VkMemoryAllocInfo *info, const VkMemoryPropertyFlags properties, |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 128 | const VkMemoryPropertyFlags forbid = 0) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 130 | // vkEnumerateDeviceExtensionProperties() |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 131 | std::vector<VkExtensionProperties> extensions() const; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 132 | std::vector<VkExtensionProperties> extensions(const char * pLayerName) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 133 | |
| 134 | // vkEnumerateLayers() |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 135 | std::vector<VkLayerProperties> layers() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 136 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 137 | private: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 138 | void add_extension_dependencies(uint32_t dependency_count, |
| 139 | VkExtensionProperties *depencency_props, |
| 140 | std::vector<VkExtensionProperties> &ext_list); |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 141 | |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 142 | VkPhysicalDeviceMemoryProperties memory_properties_; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 143 | |
| 144 | VkPhysicalDeviceProperties device_properties_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 145 | }; |
| 146 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 147 | class Device : public internal::Handle<VkDevice> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 148 | public: |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 149 | explicit Device(VkPhysicalDevice phy) : phy_(phy) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 150 | ~Device(); |
| 151 | |
| 152 | // vkCreateDevice() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 153 | void init(const VkDeviceCreateInfo &info); |
Courtney Goeltzenleuchter | 5bac609 | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 154 | 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 156 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 157 | const PhysicalDevice &phy() const { return phy_; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 158 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 159 | // vkGetDeviceProcAddr() |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 160 | PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); } |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 161 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 162 | // vkGetDeviceQueue() |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 163 | const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 164 | 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 Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 169 | VkFormat format; |
| 170 | VkImageTiling tiling; |
| 171 | VkFlags features; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 | }; |
| 173 | // vkGetFormatInfo() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 174 | VkFormatProperties format_properties(VkFormat format); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 175 | const std::vector<Format> &formats() const { return formats_; } |
| 176 | |
| 177 | // vkDeviceWaitIdle() |
| 178 | void wait(); |
| 179 | |
| 180 | // vkWaitForFences() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 181 | 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 183 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 184 | // vkUpdateDescriptorSets() |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 185 | void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies); |
| 186 | void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); } |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 197 | private: |
| 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 Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 208 | PhysicalDevice phy_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 209 | |
| 210 | std::vector<Queue *> queues_[QUEUE_COUNT]; |
| 211 | std::vector<Format> formats_; |
| 212 | }; |
| 213 | |
Chia-I Wu | df12ffd | 2015-07-03 10:53:18 +0800 | [diff] [blame] | 214 | class Queue : public internal::Handle<VkQueue> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 215 | public: |
Tony Barbour | fb21ea3 | 2015-07-23 10:35:30 -0600 | [diff] [blame] | 216 | explicit Queue(VkQueue queue, int index) : Handle(queue) {family_index_ = index;} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 217 | |
| 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 223 | // vkQueueWaitIdle() |
| 224 | void wait(); |
| 225 | |
| 226 | // vkQueueSignalSemaphore() |
| 227 | // vkQueueWaitSemaphore() |
| 228 | void signal_semaphore(Semaphore &sem); |
| 229 | void wait_semaphore(Semaphore &sem); |
Tony Barbour | fb21ea3 | 2015-07-23 10:35:30 -0600 | [diff] [blame] | 230 | |
| 231 | int get_family_index() {return family_index_;} |
| 232 | |
| 233 | private: |
| 234 | int family_index_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 235 | }; |
| 236 | |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 237 | class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 238 | public: |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 239 | ~DeviceMemory(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | |
| 241 | // vkAllocMemory() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 242 | void init(const Device &dev, const VkMemoryAllocInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 243 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 244 | // vkMapMemory() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 245 | const void *map(VkFlags flags) const; |
| 246 | void *map(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 247 | const void *map() const { return map(0); } |
| 248 | void *map() { return map(0); } |
| 249 | |
| 250 | // vkUnmapMemory() |
| 251 | void unmap() const; |
| 252 | |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 253 | static VkMemoryAllocInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 254 | }; |
| 255 | |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 256 | class Fence : public internal::NonDispHandle<VkFence> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 257 | public: |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 258 | ~Fence(); |
| 259 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 260 | // vkCreateFence() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 261 | void init(const Device &dev, const VkFenceCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 262 | |
| 263 | // vkGetFenceStatus() |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 264 | VkResult status() const { return vkGetFenceStatus(device(), handle()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 265 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 266 | static VkFenceCreateInfo create_info(VkFenceCreateFlags flags); |
| 267 | static VkFenceCreateInfo create_info(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | }; |
| 269 | |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 270 | class Semaphore : public internal::NonDispHandle<VkSemaphore> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 271 | public: |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 272 | ~Semaphore(); |
| 273 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 274 | // vkCreateSemaphore() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 275 | void init(const Device &dev, const VkSemaphoreCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 276 | |
Tony Barbour | af892a1 | 2015-06-26 12:56:09 -0600 | [diff] [blame] | 277 | static VkSemaphoreCreateInfo create_info(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 278 | }; |
| 279 | |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 280 | class Event : public internal::NonDispHandle<VkEvent> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 281 | public: |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 282 | ~Event(); |
| 283 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 284 | // vkCreateEvent() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 285 | void init(const Device &dev, const VkEventCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 286 | |
| 287 | // vkGetEventStatus() |
| 288 | // vkSetEvent() |
| 289 | // vkResetEvent() |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 290 | VkResult status() const { return vkGetEventStatus(device(), handle()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 291 | void set(); |
| 292 | void reset(); |
| 293 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 294 | static VkEventCreateInfo create_info(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | }; |
| 296 | |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 297 | class QueryPool : public internal::NonDispHandle<VkQueryPool> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 298 | public: |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 299 | ~QueryPool(); |
| 300 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 301 | // vkCreateQueryPool() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 302 | void init(const Device &dev, const VkQueryPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 303 | |
| 304 | // vkGetQueryPoolResults() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | VkResult results(uint32_t start, uint32_t count, size_t size, void *data); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 306 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 307 | static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | }; |
| 309 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 310 | class Buffer : public internal::NonDispHandle<VkBuffer> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | public: |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 312 | explicit Buffer() : NonDispHandle() {} |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 313 | explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); } |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 314 | explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 315 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 316 | ~Buffer(); |
| 317 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 318 | // vkCreateBuffer() |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 319 | void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props); |
| 320 | void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); } |
| 321 | void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props) { init(dev, create_info(size, 0), mem_props); } |
| 322 | void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); } |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 323 | void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT), reqs); } |
| 324 | void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT), reqs); } |
| 325 | 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 Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 326 | void init_no_mem(const Device &dev, const VkBufferCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 328 | // get the internal memory |
| 329 | const DeviceMemory &memory() const { return internal_mem_; } |
| 330 | DeviceMemory &memory() { return internal_mem_; } |
| 331 | |
| 332 | // vkGetObjectMemoryRequirements() |
| 333 | VkMemoryRequirements memory_requirements() const; |
| 334 | |
| 335 | // vkBindObjectMemory() |
| 336 | void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset); |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 337 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 338 | static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 339 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 340 | VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 341 | VkDeviceSize offset, VkDeviceSize size) const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 342 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 343 | VkBufferMemoryBarrier barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 345 | barrier.buffer = handle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 346 | barrier.outputMask = output_mask; |
| 347 | barrier.inputMask = input_mask; |
| 348 | barrier.offset = offset; |
| 349 | barrier.size = size; |
| 350 | return barrier; |
| 351 | } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 352 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 353 | private: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 354 | VkBufferCreateInfo create_info_; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 355 | |
| 356 | DeviceMemory internal_mem_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 357 | }; |
| 358 | |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 359 | class BufferView : public internal::NonDispHandle<VkBufferView> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 360 | public: |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 361 | ~BufferView(); |
| 362 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 363 | // vkCreateBufferView() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 364 | void init(const Device &dev, const VkBufferViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | }; |
| 366 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 367 | class Image : public internal::NonDispHandle<VkImage> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | public: |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 369 | explicit Image() : NonDispHandle(), format_features_(0) {} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 370 | explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 372 | ~Image(); |
| 373 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 374 | // vkCreateImage() |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 375 | void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props); |
| 376 | void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); } |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 377 | void init_no_mem(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 378 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 379 | // get the internal memory |
| 380 | const DeviceMemory &memory() const { return internal_mem_; } |
| 381 | DeviceMemory &memory() { return internal_mem_; } |
| 382 | |
| 383 | // vkGetObjectMemoryRequirements() |
| 384 | VkMemoryRequirements memory_requirements() const; |
| 385 | |
| 386 | // vkBindObjectMemory() |
| 387 | void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 388 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 389 | // vkGetImageSubresourceLayout() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 390 | VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 391 | VkSubresourceLayout subresource_layout(const VkImageSubresourceCopy &subres) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 392 | |
| 393 | bool transparent() const; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 394 | bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 395 | |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 396 | VkImageSubresourceRange subresource_range(VkImageAspectFlagBits aspect) const { return subresource_range(create_info_, aspect); } |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 397 | VkExtent3D extent() const { return create_info_.extent; } |
| 398 | VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); } |
| 399 | VkFormat format() const {return create_info_.format;} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 400 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 401 | VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, |
| 402 | VkImageLayout old_layout, |
| 403 | VkImageLayout new_layout, |
| 404 | const VkImageSubresourceRange &range) const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 405 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 406 | VkImageMemoryBarrier barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 407 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 408 | barrier.outputMask = output_mask; |
| 409 | barrier.inputMask = input_mask; |
| 410 | barrier.oldLayout = old_layout; |
| 411 | barrier.newLayout = new_layout; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 412 | barrier.image = handle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 413 | barrier.subresourceRange = range; |
| 414 | return barrier; |
| 415 | } |
| 416 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 417 | static VkImageCreateInfo create_info(); |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 418 | static VkImageAspectFlagBits image_aspect(VkImageAspectFlags flags); |
| 419 | static VkImageSubresource subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer); |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 420 | static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer); |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 421 | static VkImageSubresourceCopy subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size); |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 422 | static VkImageSubresourceCopy subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, uint32_t array_size); |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 423 | static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels, |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 424 | uint32_t base_array_layer, uint32_t num_layers); |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 425 | static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 426 | static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 427 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 428 | static VkExtent2D extent(int32_t width, int32_t height); |
| 429 | static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level); |
| 430 | static VkExtent2D extent(const VkExtent3D &extent); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 431 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 432 | static VkExtent3D extent(int32_t width, int32_t height, int32_t depth); |
| 433 | static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 434 | |
| 435 | private: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 436 | void init_info(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 437 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 438 | VkImageCreateInfo create_info_; |
| 439 | VkFlags format_features_; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 440 | |
| 441 | DeviceMemory internal_mem_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 442 | }; |
| 443 | |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 444 | class ImageView : public internal::NonDispHandle<VkImageView> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 445 | public: |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 446 | ~ImageView(); |
| 447 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 448 | // vkCreateImageView() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 449 | void init(const Device &dev, const VkImageViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 450 | }; |
| 451 | |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 452 | class ShaderModule : public internal::NonDispHandle<VkShaderModule> { |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 453 | public: |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 454 | ~ShaderModule(); |
| 455 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 456 | // 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 Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 463 | class Shader : public internal::NonDispHandle<VkShader> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 464 | public: |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 465 | ~Shader(); |
| 466 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 467 | // vkCreateShader() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 468 | void init(const Device &dev, const VkShaderCreateInfo &info); |
| 469 | VkResult init_try(const Device &dev, const VkShaderCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 470 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 471 | static VkShaderCreateInfo create_info(VkShaderModule module, const char *pName, VkFlags flags, VkShaderStageFlagBits stage); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 472 | }; |
| 473 | |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 474 | class Pipeline : public internal::NonDispHandle<VkPipeline> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 475 | public: |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 476 | ~Pipeline(); |
| 477 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 478 | // vkCreateGraphicsPipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 479 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 480 | // vkCreateGraphicsPipelineDerivative() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 481 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 482 | // vkCreateComputePipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 483 | void init(const Device &dev, const VkComputePipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 484 | // vkLoadPipeline() |
| 485 | void init(const Device&dev, size_t size, const void *data); |
| 486 | // vkLoadPipelineDerivative() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 487 | void init(const Device&dev, size_t size, const void *data, VkPipeline basePipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 488 | |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 489 | // vkCreateGraphicsPipeline with error return |
| 490 | VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info); |
| 491 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 492 | // vkStorePipeline() |
| 493 | size_t store(size_t size, void *data); |
| 494 | }; |
| 495 | |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 496 | class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> { |
| 497 | public: |
| 498 | ~PipelineLayout(); |
| 499 | |
| 500 | // vCreatePipelineLayout() |
| 501 | void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts); |
| 502 | }; |
| 503 | |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 504 | class Sampler : public internal::NonDispHandle<VkSampler> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 505 | public: |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 506 | ~Sampler(); |
| 507 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 508 | // vkCreateSampler() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 509 | void init(const Device &dev, const VkSamplerCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 510 | }; |
| 511 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 512 | class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 513 | public: |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 514 | ~DescriptorSetLayout(); |
| 515 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 516 | // vkCreateDescriptorSetLayout() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 517 | void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 518 | }; |
| 519 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 520 | class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 521 | public: |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 522 | ~DescriptorPool(); |
| 523 | |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 524 | // Descriptor sets allocated from this pool will need access to the original object |
| 525 | VkDescriptorPool GetObj() { return pool_; } |
| 526 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 527 | // vkCreateDescriptorPool() |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 528 | void init(const Device &dev, const VkDescriptorPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 529 | |
| 530 | // vkResetDescriptorPool() |
| 531 | void reset(); |
| 532 | |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 533 | // vkFreeDescriptorSet() |
| 534 | void setDynamicUsage(bool isDynamic) { dynamic_usage_ = isDynamic; } |
| 535 | bool getDynamicUsage() { return dynamic_usage_; } |
| 536 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 537 | // vkAllocDescriptorSets() |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 538 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts); |
| 539 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count); |
| 540 | DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout); |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 541 | |
| 542 | private: |
| 543 | VkDescriptorPool pool_; |
| 544 | |
| 545 | // Track whether this pool's usage is VK_DESCRIPTOR_POOL_USAGE_DYNAMIC |
| 546 | bool dynamic_usage_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 547 | }; |
| 548 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 549 | class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 550 | public: |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 551 | ~DescriptorSet(); |
| 552 | |
| 553 | explicit DescriptorSet() : NonDispHandle() {} |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 554 | explicit DescriptorSet(const Device &dev, DescriptorPool* pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { containing_pool_ = pool;} |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 555 | |
| 556 | private: |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 557 | DescriptorPool* containing_pool_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 558 | }; |
| 559 | |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 560 | class CmdPool : public internal::NonDispHandle<VkCmdPool> { |
| 561 | public: |
| 562 | ~CmdPool(); |
| 563 | |
| 564 | explicit CmdPool() : NonDispHandle() {} |
| 565 | explicit CmdPool(const Device &dev, const VkCmdPoolCreateInfo &info) { init(dev, info); } |
| 566 | |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 567 | void init(const Device &dev, const VkCmdPoolCreateInfo &info); |
| 568 | |
| 569 | static VkCmdPoolCreateInfo create_info(uint32_t queue_family_index); |
| 570 | }; |
| 571 | |
| 572 | inline VkCmdPoolCreateInfo CmdPool::create_info(uint32_t queue_family_index) |
| 573 | { |
| 574 | VkCmdPoolCreateInfo info = {}; |
Tony Barbour | e815fd7 | 2015-07-27 09:36:24 -0600 | [diff] [blame] | 575 | info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO; |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 576 | info.queueFamilyIndex = queue_family_index; |
| 577 | return info; |
| 578 | } |
| 579 | |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 580 | class CmdBuffer : public internal::Handle<VkCmdBuffer> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 581 | public: |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 582 | ~CmdBuffer(); |
| 583 | |
| 584 | explicit CmdBuffer() : Handle() {} |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 585 | explicit CmdBuffer(const Device &dev, const VkCmdBufferAllocInfo &info) { init(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 586 | |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 587 | // vkAllocCommandBuffers() |
| 588 | void init(const Device &dev, const VkCmdBufferAllocInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 589 | |
| 590 | // vkBeginCommandBuffer() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 591 | void begin(const VkCmdBufferBeginInfo *info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 592 | void begin(); |
| 593 | |
| 594 | // vkEndCommandBuffer() |
| 595 | // vkResetCommandBuffer() |
| 596 | void end(); |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 597 | void reset(VkCmdBufferResetFlags flags); |
Courtney Goeltzenleuchter | 7b0d95d | 2015-09-11 11:40:48 -0600 | [diff] [blame] | 598 | void reset() { reset(VK_CMD_BUFFER_RESET_RELEASE_RESOURCES_BIT); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 599 | |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 600 | static VkCmdBufferAllocInfo create_info(VkCmdPool const &pool); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 601 | |
| 602 | private: |
| 603 | VkDevice dev_handle_; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 604 | VkCmdPool cmd_pool_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 605 | }; |
| 606 | |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 607 | inline VkMemoryAllocInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 608 | { |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 609 | VkMemoryAllocInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 610 | info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 611 | info.allocationSize = size; |
| 612 | info.memoryTypeIndex = memory_type_index; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 613 | return info; |
| 614 | } |
| 615 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 616 | inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 617 | { |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 618 | VkBufferCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 619 | info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 620 | info.size = size; |
| 621 | info.usage = usage; |
| 622 | return info; |
| 623 | } |
| 624 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 625 | inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 626 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 627 | VkFenceCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 628 | info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 629 | info.flags = flags; |
| 630 | return info; |
| 631 | } |
| 632 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 633 | inline VkFenceCreateInfo Fence::create_info() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 634 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 635 | VkFenceCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 636 | info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 637 | return info; |
| 638 | } |
| 639 | |
Tony Barbour | af892a1 | 2015-06-26 12:56:09 -0600 | [diff] [blame] | 640 | inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 641 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 642 | VkSemaphoreCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 643 | info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 644 | info.flags = flags; |
| 645 | return info; |
| 646 | } |
| 647 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 648 | inline VkEventCreateInfo Event::create_info(VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 649 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 650 | VkEventCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 651 | info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 652 | info.flags = flags; |
| 653 | return info; |
| 654 | } |
| 655 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 656 | inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 657 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 658 | VkQueryPoolCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 659 | info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 660 | info.queryType = type; |
| 661 | info.slots = slot_count; |
| 662 | return info; |
| 663 | } |
| 664 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 665 | inline VkImageCreateInfo Image::create_info() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 666 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 667 | VkImageCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 668 | info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 669 | info.extent.width = 1; |
| 670 | info.extent.height = 1; |
| 671 | info.extent.depth = 1; |
| 672 | info.mipLevels = 1; |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 673 | info.arrayLayers = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 674 | info.samples = 1; |
| 675 | return info; |
| 676 | } |
| 677 | |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 678 | inline VkImageSubresource Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 679 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 680 | VkImageSubresource subres = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 681 | subres.aspect = aspect; |
| 682 | subres.mipLevel = mip_level; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 683 | subres.arrayLayer = array_layer; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 684 | return subres; |
| 685 | } |
| 686 | |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 687 | inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 688 | { |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 689 | return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 690 | } |
| 691 | |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 692 | inline VkImageSubresourceCopy Image::subresource(VkImageAspectFlagBits aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size) |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 693 | { |
| 694 | VkImageSubresourceCopy subres = {}; |
| 695 | subres.aspect = aspect; |
| 696 | subres.mipLevel = mip_level; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 697 | subres.baseArrayLayer = array_layer; |
| 698 | subres.numLayers = array_size; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 699 | return subres; |
| 700 | } |
| 701 | |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 702 | inline VkImageAspectFlagBits Image::image_aspect(VkImageAspectFlags flags) |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 703 | { |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 704 | /* |
| 705 | * This will map VkImageAspectFlags into a single VkImageAspect. |
| 706 | * If there is more than one bit defined we'll get an assertion. |
| 707 | */ |
| 708 | switch (flags) { |
| 709 | case VK_IMAGE_ASPECT_COLOR_BIT: |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 710 | return VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 711 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 712 | return VK_IMAGE_ASPECT_DEPTH_BIT; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 713 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 714 | return VK_IMAGE_ASPECT_STENCIL_BIT; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 715 | case VK_IMAGE_ASPECT_METADATA_BIT: |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 716 | return VK_IMAGE_ASPECT_METADATA_BIT; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 717 | default: |
| 718 | assert(!"Invalid VkImageAspect"); |
| 719 | } |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 720 | return VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 721 | } |
| 722 | |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 723 | inline VkImageSubresourceCopy Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, uint32_t array_size) |
| 724 | { |
| 725 | return subresource(image_aspect(range.aspectMask), range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size); |
| 726 | } |
| 727 | |
| 728 | inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels, |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 729 | uint32_t base_array_layer, uint32_t num_layers) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 730 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 731 | VkImageSubresourceRange range = {}; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 732 | range.aspectMask = aspect_mask; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 733 | range.baseMipLevel = base_mip_level; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 734 | range.numLevels = mip_levels; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 735 | range.baseArrayLayer = base_array_layer; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 736 | range.numLayers = num_layers; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 737 | return range; |
| 738 | } |
| 739 | |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 740 | inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 741 | { |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 742 | return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 743 | } |
| 744 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 745 | inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 746 | { |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 747 | return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arrayLayer, 1); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 748 | } |
| 749 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 750 | inline VkExtent2D Image::extent(int32_t width, int32_t height) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 751 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 752 | VkExtent2D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 753 | extent.width = width; |
| 754 | extent.height = height; |
| 755 | return extent; |
| 756 | } |
| 757 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 758 | inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 759 | { |
| 760 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 761 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 762 | return Image::extent(width, height); |
| 763 | } |
| 764 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 765 | inline VkExtent2D Image::extent(const VkExtent3D &extent) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 766 | { |
| 767 | return Image::extent(extent.width, extent.height); |
| 768 | } |
| 769 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 770 | inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 771 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 772 | VkExtent3D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 773 | extent.width = width; |
| 774 | extent.height = height; |
| 775 | extent.depth = depth; |
| 776 | return extent; |
| 777 | } |
| 778 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 779 | inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 780 | { |
| 781 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 782 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 783 | const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; |
| 784 | return Image::extent(width, height, depth); |
| 785 | } |
| 786 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 787 | inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const void *code, VkFlags flags) |
| 788 | { |
| 789 | VkShaderModuleCreateInfo info = {}; |
| 790 | info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 791 | info.codeSize = code_size; |
| 792 | info.pCode = code; |
| 793 | info.flags = flags; |
| 794 | return info; |
| 795 | } |
| 796 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 797 | inline VkShaderCreateInfo Shader::create_info(VkShaderModule module, const char *pName, VkFlags flags, VkShaderStageFlagBits stage) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 798 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 799 | VkShaderCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 800 | info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 801 | info.module = module; |
| 802 | info.pName = pName; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 803 | info.flags = flags; |
Cody Northrop | fd4bcfd | 2015-08-24 15:11:10 -0600 | [diff] [blame] | 804 | info.stage = stage; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 805 | return info; |
| 806 | } |
| 807 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 808 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 809 | VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 810 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 811 | VkWriteDescriptorSet write = {}; |
| 812 | write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 813 | write.destSet = set.handle(); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 814 | write.destBinding = binding; |
| 815 | write.destArrayElement = array_element; |
| 816 | write.count = count; |
| 817 | write.descriptorType = type; |
| 818 | write.pDescriptors = descriptors; |
| 819 | return write; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 820 | } |
| 821 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 822 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 823 | VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 824 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 825 | return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 826 | } |
| 827 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 828 | inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element, |
| 829 | const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element, |
| 830 | uint32_t count) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 831 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 832 | VkCopyDescriptorSet copy = {}; |
| 833 | copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 834 | copy.srcSet = src_set.handle(); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 835 | copy.srcBinding = src_binding; |
| 836 | copy.srcArrayElement = src_array_element; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 837 | copy.destSet = dst_set.handle(); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 838 | copy.destBinding = dst_binding; |
| 839 | copy.destArrayElement = dst_array_element; |
| 840 | copy.count = count; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 841 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 842 | return copy; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 843 | } |
| 844 | |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 845 | inline VkCmdBufferAllocInfo CmdBuffer::create_info(VkCmdPool const &pool) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 846 | { |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 847 | VkCmdBufferAllocInfo info = {}; |
| 848 | info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_ALLOC_INFO; |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 849 | info.cmdPool = pool; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 850 | info.count = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 851 | return info; |
| 852 | } |
| 853 | |
| 854 | }; // namespace vk_testing |
| 855 | |
| 856 | #endif // VKTESTBINDING_H |