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