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