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