Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // VK tests |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 2 | // |
| 3 | // Copyright (C) 2014 LunarG, Inc. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | // copy of this software and associated documentation files (the "Software"), |
| 7 | // to deal in the Software without restriction, including without limitation |
| 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | // and/or sell copies of the Software, and to permit persons to whom the |
| 10 | // Software is furnished to do so, subject to the following conditions: |
| 11 | // |
| 12 | // The above copyright notice and this permission notice shall be included |
| 13 | // in all copies or substantial portions of the Software. |
| 14 | // |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | // DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | #include <iostream> |
| 24 | #include <string.h> // memset(), memcmp() |
Courtney Goeltzenleuchter | 6d55b9c | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 25 | #include <assert.h> |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 26 | #include <stdarg.h> |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 27 | #include "vktestbinding.h" |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 28 | |
| 29 | namespace { |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 30 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 31 | #define NON_DISPATCHABLE_HANDLE_INIT(create_func, dev, ...) \ |
| 32 | do { \ |
| 33 | handle_type handle; \ |
| 34 | if (EXPECT(create_func(dev.handle(), __VA_ARGS__, &handle) == VK_SUCCESS)) \ |
| 35 | NonDispHandle::init(dev.handle(), handle); \ |
| 36 | } while (0) |
| 37 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 38 | #define NON_DISPATCHABLE_HANDLE_DTOR(cls, destroy_func) \ |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 39 | cls::~cls() \ |
| 40 | { \ |
| 41 | if (initialized()) \ |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 42 | EXPECT(destroy_func(device(), handle()) == VK_SUCCESS); \ |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 45 | #define STRINGIFY(x) #x |
| 46 | #define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__)) |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 47 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 48 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 49 | vk_testing::ErrorCallback error_callback; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 50 | |
| 51 | bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function) |
| 52 | { |
| 53 | if (error_callback) { |
| 54 | error_callback(expr, file, line, function); |
| 55 | } else { |
| 56 | std::cerr << file << ":" << line << ": " << function << |
| 57 | ": Expectation `" << expr << "' failed.\n"; |
| 58 | } |
| 59 | |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | template<class T, class S> |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 64 | std::vector<T> make_handles(const std::vector<S> &v) |
| 65 | { |
| 66 | std::vector<T> handles; |
| 67 | handles.reserve(v.size()); |
| 68 | for (typename std::vector<S>::const_iterator it = v.begin(); it != v.end(); it++) |
| 69 | handles.push_back((*it)->handle()); |
| 70 | return handles; |
| 71 | } |
| 72 | |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 73 | VkMemoryAllocInfo get_resource_alloc_info(const vk_testing::Device &dev, const VkMemoryRequirements &reqs, VkMemoryPropertyFlags mem_props) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 74 | { |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 75 | VkMemoryAllocInfo info = vk_testing::DeviceMemory::alloc_info(reqs.size, 0); |
| 76 | dev.phy().set_memory_type(reqs.memoryTypeBits, &info, mem_props); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 77 | |
| 78 | return info; |
| 79 | } |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 80 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 81 | } // namespace |
| 82 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | namespace vk_testing { |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 84 | |
| 85 | void set_error_callback(ErrorCallback callback) |
| 86 | { |
| 87 | error_callback = callback; |
| 88 | } |
| 89 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 90 | VkPhysicalDeviceProperties PhysicalDevice::properties() const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 91 | { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 92 | VkPhysicalDeviceProperties info; |
| 93 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 94 | EXPECT(vkGetPhysicalDeviceProperties(handle(), &info) == VK_SUCCESS); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 95 | |
| 96 | return info; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 97 | } |
| 98 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 99 | std::vector<VkPhysicalDeviceQueueProperties> PhysicalDevice::queue_properties() const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 100 | { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 101 | std::vector<VkPhysicalDeviceQueueProperties> info; |
| 102 | uint32_t count; |
| 103 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 104 | if (EXPECT(vkGetPhysicalDeviceQueueCount(handle(), &count) == VK_SUCCESS)) { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 105 | info.resize(count); |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 106 | if (!EXPECT(vkGetPhysicalDeviceQueueProperties(handle(), count, &info[0]) == VK_SUCCESS)) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 107 | info.clear(); |
| 108 | } |
| 109 | |
| 110 | return info; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 111 | } |
| 112 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 113 | VkPhysicalDeviceMemoryProperties PhysicalDevice::memory_properties() const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 114 | { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 115 | VkPhysicalDeviceMemoryProperties info; |
| 116 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 117 | EXPECT(vkGetPhysicalDeviceMemoryProperties(handle(), &info) == VK_SUCCESS); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 118 | |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 119 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 120 | return info; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 121 | } |
| 122 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 123 | /* |
| 124 | * Return list of Global layers available |
| 125 | */ |
| 126 | std::vector<VkLayerProperties> GetGlobalLayers() |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 127 | { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 128 | VkResult err; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 129 | std::vector<VkLayerProperties> layers; |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 130 | uint32_t layer_count; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 131 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 132 | do { |
| 133 | layer_count = 0; |
| 134 | err = vkGetGlobalLayerProperties(&layer_count, NULL); |
| 135 | |
| 136 | if (err == VK_SUCCESS) { |
| 137 | layers.reserve(layer_count); |
| 138 | err = vkGetGlobalLayerProperties(&layer_count, &layers[0]); |
| 139 | } |
| 140 | } while (err == VK_INCOMPLETE); |
| 141 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 142 | assert(err == VK_SUCCESS); |
| 143 | |
| 144 | return layers; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 145 | } |
| 146 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 147 | /* |
| 148 | * Return list of Global extensions provided by the ICD / Loader |
| 149 | */ |
| 150 | std::vector<VkExtensionProperties> GetGlobalExtensions() |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 151 | { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 152 | return GetGlobalExtensions(NULL); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * Return list of Global extensions provided by the specified layer |
| 157 | * If pLayerName is NULL, will return extensions implemented by the loader / ICDs |
| 158 | */ |
| 159 | std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName) |
| 160 | { |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 161 | std::vector<VkExtensionProperties> exts; |
| 162 | uint32_t ext_count; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 163 | VkResult err; |
| 164 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 165 | do { |
| 166 | ext_count = 0; |
| 167 | err = vkGetGlobalExtensionProperties(pLayerName, &ext_count, NULL); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 168 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 169 | if (err == VK_SUCCESS) { |
Courtney Goeltzenleuchter | b774fb4 | 2015-07-06 15:45:58 -0600 | [diff] [blame] | 170 | exts.resize(ext_count); |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 171 | err = vkGetGlobalExtensionProperties(pLayerName, &ext_count, &exts[0]); |
| 172 | } |
| 173 | } while (err == VK_INCOMPLETE); |
| 174 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 175 | assert(err == VK_SUCCESS); |
| 176 | |
| 177 | return exts; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Return list of PhysicalDevice extensions provided by the ICD / Loader |
| 182 | */ |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 183 | std::vector<VkExtensionProperties> PhysicalDevice::extensions() const |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 184 | { |
| 185 | return extensions(NULL); |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Return list of PhysicalDevice extensions provided by the specified layer |
| 190 | * If pLayerName is NULL, will return extensions for ICD / loader. |
| 191 | */ |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 192 | std::vector<VkExtensionProperties> PhysicalDevice::extensions(const char *pLayerName) const |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 193 | { |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 194 | std::vector<VkExtensionProperties> exts; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 195 | VkResult err; |
| 196 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 197 | do { |
| 198 | uint32_t extCount = 0; |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 199 | err = vkGetPhysicalDeviceExtensionProperties(handle(), pLayerName, &extCount, NULL); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 200 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 201 | if (err == VK_SUCCESS) { |
Ian Elliott | 331f4e8 | 2015-07-06 14:33:04 -0600 | [diff] [blame^] | 202 | exts.resize(extCount); |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 203 | err = vkGetPhysicalDeviceExtensionProperties(handle(), pLayerName, &extCount, &exts[0]); |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 204 | } |
| 205 | } while (err == VK_INCOMPLETE); |
| 206 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 207 | assert(err == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 208 | |
| 209 | return exts; |
| 210 | } |
| 211 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 212 | VkResult PhysicalDevice::set_memory_type(const uint32_t type_bits, VkMemoryAllocInfo *info, const VkFlags properties) const |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 213 | { |
| 214 | uint32_t type_mask = type_bits; |
| 215 | // Search memtypes to find first index with those properties |
| 216 | for (uint32_t i = 0; i < 32; i++) { |
| 217 | if ((type_mask & 1) == 1) { |
| 218 | // Type is available, does it match user properties? |
| 219 | if ((memory_properties_.memoryTypes[i].propertyFlags & properties) == properties) { |
| 220 | info->memoryTypeIndex = i; |
| 221 | return VK_SUCCESS; |
| 222 | } |
| 223 | } |
| 224 | type_mask >>= 1; |
| 225 | } |
| 226 | // No memory types matched, return failure |
| 227 | return VK_UNSUPPORTED; |
| 228 | } |
| 229 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 230 | /* |
| 231 | * Return list of PhysicalDevice layers |
| 232 | */ |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 233 | std::vector<VkLayerProperties> PhysicalDevice::layers() const |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 234 | { |
| 235 | std::vector<VkLayerProperties> layer_props; |
| 236 | VkResult err; |
| 237 | |
| 238 | do { |
| 239 | uint32_t layer_count = 0; |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 240 | err = vkGetPhysicalDeviceLayerProperties(handle(), &layer_count, NULL); |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 241 | |
| 242 | if (err == VK_SUCCESS) { |
| 243 | layer_props.reserve(layer_count); |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 244 | err = vkGetPhysicalDeviceLayerProperties(handle(), &layer_count, &layer_props[0]); |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 245 | } |
| 246 | } while (err == VK_INCOMPLETE); |
| 247 | |
| 248 | assert(err == VK_SUCCESS); |
| 249 | |
| 250 | return layer_props; |
| 251 | } |
| 252 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 253 | Device::~Device() |
| 254 | { |
| 255 | if (!initialized()) |
| 256 | return; |
| 257 | |
| 258 | for (int i = 0; i < QUEUE_COUNT; i++) { |
| 259 | for (std::vector<Queue *>::iterator it = queues_[i].begin(); it != queues_[i].end(); it++) |
| 260 | delete *it; |
| 261 | queues_[i].clear(); |
| 262 | } |
| 263 | |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 264 | EXPECT(vkDestroyDevice(handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 265 | } |
| 266 | |
Courtney Goeltzenleuchter | 61414de | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 267 | void Device::init(std::vector<const char *> &layers, std::vector<const char *> &extensions) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 268 | { |
| 269 | // request all queues |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 270 | const std::vector<VkPhysicalDeviceQueueProperties> queue_props = phy_.queue_properties(); |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 271 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 272 | queue_info.reserve(queue_props.size()); |
| 273 | for (int i = 0; i < queue_props.size(); i++) { |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 274 | VkDeviceQueueCreateInfo qi = {}; |
Chris Forbes | fa6d36e | 2015-07-11 19:11:39 +1200 | [diff] [blame] | 275 | qi.queueFamilyIndex = i; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 276 | qi.queueCount = queue_props[i].queueCount; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 277 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 278 | graphics_queue_node_index_ = i; |
| 279 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 280 | queue_info.push_back(qi); |
| 281 | } |
| 282 | |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 283 | VkDeviceCreateInfo dev_info = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 284 | dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 285 | dev_info.pNext = NULL; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 286 | dev_info.queueRecordCount = queue_info.size(); |
| 287 | dev_info.pRequestedQueues = &queue_info[0]; |
Courtney Goeltzenleuchter | 61414de | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 288 | dev_info.layerCount = layers.size(); |
| 289 | dev_info.ppEnabledLayerNames = &layers[0]; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 290 | dev_info.extensionCount = extensions.size(); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 291 | dev_info.ppEnabledExtensionNames = &extensions[0]; |
Jon Ashburn | 80d3b71 | 2015-05-18 09:06:15 -0600 | [diff] [blame] | 292 | dev_info.flags = 0; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 293 | |
| 294 | init(dev_info); |
| 295 | } |
| 296 | |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 297 | void Device::init(const VkDeviceCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 298 | { |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 299 | VkDevice dev; |
| 300 | |
| 301 | if (EXPECT(vkCreateDevice(phy_.handle(), &info, &dev) == VK_SUCCESS)) |
| 302 | Handle::init(dev); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 303 | |
| 304 | init_queues(); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 305 | init_formats(); |
| 306 | } |
| 307 | |
| 308 | void Device::init_queues() |
| 309 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 310 | VkResult err; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 311 | uint32_t queue_node_count; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 312 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 313 | err = vkGetPhysicalDeviceQueueCount(phy_.handle(), &queue_node_count); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 314 | EXPECT(err == VK_SUCCESS); |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 315 | EXPECT(queue_node_count >= 1); |
| 316 | |
Tony Barbour | 25e3b83 | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 317 | VkPhysicalDeviceQueueProperties* queue_props = new VkPhysicalDeviceQueueProperties[queue_node_count]; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 318 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 319 | err = vkGetPhysicalDeviceQueueProperties(phy_.handle(), queue_node_count, queue_props); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 320 | EXPECT(err == VK_SUCCESS); |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 321 | |
Tony Barbour | 8bef8ee | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 322 | for (uint32_t i = 0; i < queue_node_count; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 323 | VkQueue queue; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 324 | |
Tony Barbour | 8bef8ee | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 325 | for (uint32_t j = 0; j < queue_props[i].queueCount; j++) { |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 326 | // TODO: Need to add support for separate MEMMGR and work queues, including synchronization |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 327 | err = vkGetDeviceQueue(handle(), i, j, &queue); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | EXPECT(err == VK_SUCCESS); |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 329 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 330 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 331 | queues_[GRAPHICS].push_back(new Queue(queue)); |
| 332 | } |
| 333 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 334 | if (queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) { |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 335 | queues_[COMPUTE].push_back(new Queue(queue)); |
| 336 | } |
| 337 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 338 | if (queue_props[i].queueFlags & VK_QUEUE_DMA_BIT) { |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 339 | queues_[DMA].push_back(new Queue(queue)); |
| 340 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Chris Forbes | 4506d3f | 2015-06-04 10:49:27 +1200 | [diff] [blame] | 344 | delete[] queue_props; |
Tony Barbour | 25e3b83 | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 345 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 346 | EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty()); |
| 347 | } |
| 348 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 349 | void Device::init_formats() |
| 350 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 351 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 352 | const VkFormat fmt = static_cast<VkFormat>(f); |
| 353 | const VkFormatProperties props = format_properties(fmt); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 354 | |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 355 | if (props.linearTilingFeatures) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 356 | const Format tmp = { fmt, VK_IMAGE_TILING_LINEAR, props.linearTilingFeatures }; |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 357 | formats_.push_back(tmp); |
| 358 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 359 | |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 360 | if (props.optimalTilingFeatures) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 361 | const Format tmp = { fmt, VK_IMAGE_TILING_OPTIMAL, props.optimalTilingFeatures }; |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 362 | formats_.push_back(tmp); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | EXPECT(!formats_.empty()); |
| 367 | } |
| 368 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | VkFormatProperties Device::format_properties(VkFormat format) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 370 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 371 | VkFormatProperties data; |
Courtney Goeltzenleuchter | 4da96aa | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 372 | if (!EXPECT(vkGetPhysicalDeviceFormatProperties(phy().handle(), format, &data) == VK_SUCCESS)) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 373 | memset(&data, 0, sizeof(data)); |
| 374 | |
| 375 | return data; |
| 376 | } |
| 377 | |
| 378 | void Device::wait() |
| 379 | { |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 380 | EXPECT(vkDeviceWaitIdle(handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 381 | } |
| 382 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 383 | VkResult Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 384 | { |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 385 | const std::vector<VkFence> fence_handles = make_handles<VkFence>(fences); |
| 386 | VkResult err = vkWaitForFences(handle(), fence_handles.size(), &fence_handles[0], wait_all, timeout); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 387 | EXPECT(err == VK_SUCCESS || err == VK_TIMEOUT); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 388 | |
| 389 | return err; |
| 390 | } |
| 391 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 392 | VkResult Device::update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies) |
| 393 | { |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 394 | return vkUpdateDescriptorSets(handle(), writes.size(), &writes[0], copies.size(), &copies[0]); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 395 | } |
| 396 | |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 397 | void Queue::submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 398 | { |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 399 | const std::vector<VkCmdBuffer> cmd_handles = make_handles<VkCmdBuffer>(cmds); |
| 400 | EXPECT(vkQueueSubmit(handle(), cmd_handles.size(), &cmd_handles[0], fence.handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 401 | } |
| 402 | |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 403 | void Queue::submit(const CmdBuffer &cmd, Fence &fence) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 404 | { |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 405 | submit(std::vector<const CmdBuffer*>(1, &cmd), fence); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 406 | } |
| 407 | |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 408 | void Queue::submit(const CmdBuffer &cmd) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 409 | { |
| 410 | Fence fence; |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 411 | submit(cmd, fence); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 412 | } |
| 413 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 414 | void Queue::wait() |
| 415 | { |
Chia-I Wu | f2862c7 | 2015-07-03 10:53:18 +0800 | [diff] [blame] | 416 | EXPECT(vkQueueWaitIdle(handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 417 | } |
| 418 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 419 | void Queue::signal_semaphore(Semaphore &sem) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 420 | { |
Chia-I Wu | 2454b92 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 421 | EXPECT(vkQueueSignalSemaphore(handle(), sem.handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 422 | } |
| 423 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 424 | void Queue::wait_semaphore(Semaphore &sem) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 425 | { |
Chia-I Wu | 2454b92 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 426 | EXPECT(vkQueueWaitSemaphore(handle(), sem.handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 427 | } |
| 428 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 429 | DeviceMemory::~DeviceMemory() |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 430 | { |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 431 | if (initialized()) |
| 432 | EXPECT(vkFreeMemory(device(), handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 433 | } |
| 434 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 435 | void DeviceMemory::init(const Device &dev, const VkMemoryAllocInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 436 | { |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 437 | NON_DISPATCHABLE_HANDLE_INIT(vkAllocMemory, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 438 | } |
| 439 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 440 | const void *DeviceMemory::map(VkFlags flags) const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 441 | { |
| 442 | void *data; |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 443 | if (!EXPECT(vkMapMemory(device(), handle(), 0 ,0, flags, &data) == VK_SUCCESS)) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 444 | data = NULL; |
| 445 | |
| 446 | return data; |
| 447 | } |
| 448 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 449 | void *DeviceMemory::map(VkFlags flags) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 450 | { |
| 451 | void *data; |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 452 | if (!EXPECT(vkMapMemory(device(), handle(), 0, 0, flags, &data) == VK_SUCCESS)) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 453 | data = NULL; |
| 454 | |
| 455 | return data; |
| 456 | } |
| 457 | |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 458 | void DeviceMemory::unmap() const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 459 | { |
Chia-I Wu | ba0836f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 460 | EXPECT(vkUnmapMemory(device(), handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 461 | } |
| 462 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 463 | NON_DISPATCHABLE_HANDLE_DTOR(Fence, vkDestroyFence) |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 464 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 465 | void Fence::init(const Device &dev, const VkFenceCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 466 | { |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 467 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateFence, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 468 | } |
| 469 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 470 | NON_DISPATCHABLE_HANDLE_DTOR(Semaphore, vkDestroySemaphore) |
Chia-I Wu | 2454b92 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 471 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 472 | void Semaphore::init(const Device &dev, const VkSemaphoreCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 473 | { |
Chia-I Wu | 2454b92 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 474 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateSemaphore, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 475 | } |
| 476 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 477 | NON_DISPATCHABLE_HANDLE_DTOR(Event, vkDestroyEvent) |
Chia-I Wu | 9b6db1d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 478 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 479 | void Event::init(const Device &dev, const VkEventCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 480 | { |
Chia-I Wu | 9b6db1d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 481 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateEvent, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void Event::set() |
| 485 | { |
Chia-I Wu | 9b6db1d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 486 | EXPECT(vkSetEvent(device(), handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void Event::reset() |
| 490 | { |
Chia-I Wu | 9b6db1d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 491 | EXPECT(vkResetEvent(device(), handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 492 | } |
| 493 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 494 | NON_DISPATCHABLE_HANDLE_DTOR(QueryPool, vkDestroyQueryPool) |
Chia-I Wu | fd0ce99 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 495 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 496 | void QueryPool::init(const Device &dev, const VkQueryPoolCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 497 | { |
Chia-I Wu | fd0ce99 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 498 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateQueryPool, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 499 | } |
| 500 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 501 | VkResult QueryPool::results(uint32_t start, uint32_t count, size_t size, void *data) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 502 | { |
| 503 | size_t tmp = size; |
Chia-I Wu | fd0ce99 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 504 | VkResult err = vkGetQueryPoolResults(device(), handle(), start, count, &tmp, data, 0); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 505 | if (err == VK_SUCCESS) { |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 506 | if (!EXPECT(tmp == size)) |
| 507 | memset(data, 0, size); |
| 508 | } else { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 509 | EXPECT(err == VK_NOT_READY); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | return err; |
| 513 | } |
| 514 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 515 | NON_DISPATCHABLE_HANDLE_DTOR(Buffer, vkDestroyBuffer) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 516 | |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 517 | void Buffer::init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props) |
Tony Barbour | 9431056 | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 518 | { |
| 519 | init_no_mem(dev, info); |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 520 | |
| 521 | internal_mem_.init(dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); |
| 522 | bind_memory(internal_mem_, 0); |
Tony Barbour | 9431056 | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 523 | } |
| 524 | |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 525 | void Buffer::init_no_mem(const Device &dev, const VkBufferCreateInfo &info) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 526 | { |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 527 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateBuffer, dev, &info); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 528 | create_info_ = info; |
| 529 | } |
| 530 | |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 531 | VkMemoryRequirements Buffer::memory_requirements() const |
Mark Lobodzinski | fb9f564 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 532 | { |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 533 | VkMemoryRequirements reqs; |
| 534 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 535 | EXPECT(vkGetBufferMemoryRequirements(device(), handle(), &reqs) == VK_SUCCESS); |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 536 | |
| 537 | return reqs; |
| 538 | } |
| 539 | |
| 540 | void Buffer::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) |
| 541 | { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 542 | EXPECT(vkBindBufferMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); |
Mark Lobodzinski | fb9f564 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 543 | } |
| 544 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 545 | NON_DISPATCHABLE_HANDLE_DTOR(BufferView, vkDestroyBufferView) |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 546 | |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 547 | void BufferView::init(const Device &dev, const VkBufferViewCreateInfo &info) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 548 | { |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 549 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateBufferView, dev, &info); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 550 | } |
| 551 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 552 | NON_DISPATCHABLE_HANDLE_DTOR(Image, vkDestroyImage) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 553 | |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 554 | void Image::init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props) |
Tony Barbour | 9431056 | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 555 | { |
| 556 | init_no_mem(dev, info); |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 557 | |
| 558 | internal_mem_.init(dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); |
| 559 | bind_memory(internal_mem_, 0); |
Tony Barbour | 9431056 | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 560 | } |
| 561 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 562 | void Image::init_no_mem(const Device &dev, const VkImageCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 563 | { |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 564 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateImage, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 565 | init_info(dev, info); |
| 566 | } |
| 567 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 568 | void Image::init_info(const Device &dev, const VkImageCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 569 | { |
| 570 | create_info_ = info; |
| 571 | |
| 572 | for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { |
| 573 | if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { |
| 574 | format_features_ = it->features; |
| 575 | break; |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 580 | VkMemoryRequirements Image::memory_requirements() const |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 581 | { |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 582 | VkMemoryRequirements reqs; |
| 583 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 584 | EXPECT(vkGetImageMemoryRequirements(device(), handle(), &reqs) == VK_SUCCESS); |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 585 | |
| 586 | return reqs; |
| 587 | } |
| 588 | |
| 589 | void Image::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) |
| 590 | { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 591 | EXPECT(vkBindImageMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 592 | } |
| 593 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 594 | VkSubresourceLayout Image::subresource_layout(const VkImageSubresource &subres) const |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 595 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 596 | VkSubresourceLayout data; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 597 | size_t size = sizeof(data); |
Chia-I Wu | f4aed6c | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 598 | if (!EXPECT(vkGetImageSubresourceLayout(device(), handle(), &subres, &data) == VK_SUCCESS && size == sizeof(data))) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 599 | memset(&data, 0, sizeof(data)); |
| 600 | |
| 601 | return data; |
| 602 | } |
| 603 | |
| 604 | bool Image::transparent() const |
| 605 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 606 | return (create_info_.tiling == VK_IMAGE_TILING_LINEAR && |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 607 | create_info_.samples == 1 && |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 608 | !(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 609 | VK_IMAGE_USAGE_DEPTH_STENCIL_BIT))); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 610 | } |
| 611 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 612 | NON_DISPATCHABLE_HANDLE_DTOR(ImageView, vkDestroyImageView) |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 613 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 614 | void ImageView::init(const Device &dev, const VkImageViewCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 615 | { |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 616 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateImageView, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 617 | } |
| 618 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 619 | NON_DISPATCHABLE_HANDLE_DTOR(AttachmentView, vkDestroyAttachmentView) |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 620 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 621 | void AttachmentView::init(const Device &dev, const VkAttachmentViewCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 622 | { |
Chia-I Wu | 76ab1ff | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 623 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateAttachmentView, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 624 | } |
| 625 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 626 | NON_DISPATCHABLE_HANDLE_DTOR(ShaderModule, vkDestroyShaderModule) |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 627 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 628 | void ShaderModule::init(const Device &dev, const VkShaderModuleCreateInfo &info) |
| 629 | { |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 630 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateShaderModule, dev, &info); |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | VkResult ShaderModule::init_try(const Device &dev, const VkShaderModuleCreateInfo &info) |
| 634 | { |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 635 | VkShaderModule mod; |
| 636 | |
| 637 | VkResult err = vkCreateShaderModule(dev.handle(), &info, &mod); |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 638 | if (err == VK_SUCCESS) |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 639 | NonDispHandle::init(dev.handle(), mod); |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 640 | |
| 641 | return err; |
| 642 | } |
| 643 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 644 | NON_DISPATCHABLE_HANDLE_DTOR(Shader, vkDestroyShader) |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 645 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 646 | void Shader::init(const Device &dev, const VkShaderCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 647 | { |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 648 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateShader, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 649 | } |
| 650 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 651 | VkResult Shader::init_try(const Device &dev, const VkShaderCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 652 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 653 | VkShader sh; |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 654 | |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 655 | VkResult err = vkCreateShader(dev.handle(), &info, &sh); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 656 | if (err == VK_SUCCESS) |
Chia-I Wu | b48eddb | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 657 | NonDispHandle::init(dev.handle(), sh); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 658 | |
| 659 | return err; |
| 660 | } |
| 661 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 662 | NON_DISPATCHABLE_HANDLE_DTOR(Pipeline, vkDestroyPipeline) |
Chia-I Wu | 2b1d4d0 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 663 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 664 | void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 665 | { |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 666 | VkPipelineCache cache; |
| 667 | VkPipelineCacheCreateInfo ci; |
| 668 | memset((void *) &ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
| 669 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 670 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, &cache); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 671 | if (err == VK_SUCCESS) { |
Chia-I Wu | 2b1d4d0 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 672 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateGraphicsPipelines, dev, cache, 1, &info); |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 673 | vkDestroyPipelineCache(dev.handle(), cache); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 674 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 675 | } |
| 676 | |
Chris Forbes | dc2188c | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 677 | VkResult Pipeline::init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info) |
| 678 | { |
| 679 | VkPipeline pipe; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 680 | VkPipelineCache cache; |
| 681 | VkPipelineCacheCreateInfo ci; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 682 | memset((void *) &ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
| 683 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 684 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, &cache); |
| 685 | EXPECT(err == VK_SUCCESS); |
Chris Forbes | dc2188c | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 686 | if (err == VK_SUCCESS) { |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 687 | err = vkCreateGraphicsPipelines(dev.handle(), cache, 1, &info, &pipe); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 688 | if (err == VK_SUCCESS) { |
Chia-I Wu | 2b1d4d0 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 689 | NonDispHandle::init(dev.handle(), pipe); |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 690 | vkDestroyPipelineCache(dev.handle(), cache); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 691 | } |
Chris Forbes | dc2188c | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return err; |
| 695 | } |
| 696 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 697 | void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 698 | { |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 699 | VkPipelineCache cache; |
| 700 | VkPipelineCacheCreateInfo ci; |
| 701 | memset((void *) &ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
| 702 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 703 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, &cache); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 704 | if (err == VK_SUCCESS) { |
Chia-I Wu | 2b1d4d0 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 705 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateComputePipelines, dev, cache, 1, &info); |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 706 | vkDestroyPipelineCache(dev.handle(), cache); |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 707 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 708 | } |
| 709 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 710 | NON_DISPATCHABLE_HANDLE_DTOR(PipelineLayout, vkDestroyPipelineLayout) |
Chia-I Wu | deb9913 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 711 | |
| 712 | void PipelineLayout::init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts) |
| 713 | { |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 714 | const std::vector<VkDescriptorSetLayout> layout_handles = make_handles<VkDescriptorSetLayout>(layouts); |
| 715 | info.pSetLayouts = &layout_handles[0]; |
Chia-I Wu | deb9913 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 716 | |
| 717 | NON_DISPATCHABLE_HANDLE_INIT(vkCreatePipelineLayout, dev, &info); |
| 718 | } |
| 719 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 720 | NON_DISPATCHABLE_HANDLE_DTOR(Sampler, vkDestroySampler) |
Chia-I Wu | 6abe35d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 721 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 722 | void Sampler::init(const Device &dev, const VkSamplerCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 723 | { |
Chia-I Wu | 6abe35d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 724 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateSampler, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 727 | NON_DISPATCHABLE_HANDLE_DTOR(DescriptorSetLayout, vkDestroyDescriptorSetLayout) |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 728 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 729 | void DescriptorSetLayout::init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 730 | { |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 731 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorSetLayout, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 732 | } |
| 733 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 734 | NON_DISPATCHABLE_HANDLE_DTOR(DescriptorPool, vkDestroyDescriptorPool) |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 735 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 736 | void DescriptorPool::init(const Device &dev, VkDescriptorPoolUsage usage, |
| 737 | uint32_t max_sets, const VkDescriptorPoolCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 738 | { |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 739 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorPool, dev, usage, max_sets, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 740 | } |
| 741 | |
Chia-I Wu | dee9561 | 2015-03-26 15:23:52 +0800 | [diff] [blame] | 742 | void DescriptorPool::reset() |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 743 | { |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 744 | EXPECT(vkResetDescriptorPool(device(), handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 745 | } |
| 746 | |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 747 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 748 | { |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 749 | const std::vector<VkDescriptorSetLayout> layout_handles = make_handles<VkDescriptorSetLayout>(layouts); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 750 | |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 751 | std::vector<VkDescriptorSet> set_handles; |
| 752 | set_handles.resize(layout_handles.size()); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 753 | |
| 754 | uint32_t set_count; |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 755 | VkResult err = vkAllocDescriptorSets(device(), handle(), usage, layout_handles.size(), &layout_handles[0], &set_handles[0], &set_count); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 756 | if (err == VK_SUCCESS) |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 757 | EXPECT(set_count == set_handles.size()); |
| 758 | set_handles.resize(set_count); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 759 | |
| 760 | std::vector<DescriptorSet *> sets; |
| 761 | sets.reserve(set_count); |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 762 | for (std::vector<VkDescriptorSet>::const_iterator it = set_handles.begin(); it != set_handles.end(); it++) { |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 763 | // do descriptor sets need memories bound? |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 764 | DescriptorSet *descriptorSet = new DescriptorSet(dev, handle(), *it); |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 765 | sets.push_back(descriptorSet); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 766 | } |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 767 | return sets; |
| 768 | } |
| 769 | |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 770 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 771 | { |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 772 | return alloc_sets(dev, usage, std::vector<const DescriptorSetLayout *>(count, &layout)); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 773 | } |
| 774 | |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 775 | DescriptorSet *DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 776 | { |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 777 | std::vector<DescriptorSet *> set = alloc_sets(dev, usage, layout, 1); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 778 | return (set.empty()) ? NULL : set[0]; |
| 779 | } |
| 780 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 781 | DescriptorSet::~DescriptorSet() |
| 782 | { |
| 783 | if (initialized()) { |
| 784 | VkDescriptorSet sets[1] = { handle() }; |
| 785 | EXPECT(vkFreeDescriptorSets(device(), pool_, 1, sets) == VK_SUCCESS); |
| 786 | } |
| 787 | } |
Chia-I Wu | 55a871f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 788 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 789 | NON_DISPATCHABLE_HANDLE_DTOR(DynamicViewportState, vkDestroyDynamicViewportState) |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 790 | |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 791 | void DynamicViewportState::init(const Device &dev, const VkDynamicViewportStateCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 792 | { |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 793 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDynamicViewportState, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 794 | } |
| 795 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 796 | NON_DISPATCHABLE_HANDLE_DTOR(DynamicRasterState, vkDestroyDynamicRasterState) |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 797 | |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 798 | void DynamicRasterState::init(const Device &dev, const VkDynamicRasterStateCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 799 | { |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 800 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDynamicRasterState, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 801 | } |
| 802 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 803 | NON_DISPATCHABLE_HANDLE_DTOR(DynamicColorBlendState, vkDestroyDynamicColorBlendState) |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 804 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 805 | void DynamicColorBlendState::init(const Device &dev, const VkDynamicColorBlendStateCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 806 | { |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 807 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDynamicColorBlendState, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 810 | NON_DISPATCHABLE_HANDLE_DTOR(DynamicDepthStencilState, vkDestroyDynamicDepthStencilState) |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 811 | |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 812 | void DynamicDepthStencilState::init(const Device &dev, const VkDynamicDepthStencilStateCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 813 | { |
Chia-I Wu | 6b11e60 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 814 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDynamicDepthStencilState, dev, &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 815 | } |
| 816 | |
Courtney Goeltzenleuchter | 902d081 | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 817 | NON_DISPATCHABLE_HANDLE_DTOR(CmdPool, vkDestroyCommandPool) |
| 818 | |
| 819 | void CmdPool::init(const Device &dev, const VkCmdPoolCreateInfo &info) |
| 820 | { |
| 821 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateCommandPool, dev, &info); |
| 822 | } |
| 823 | |
| 824 | |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 825 | CmdBuffer::~CmdBuffer() |
| 826 | { |
| 827 | if (initialized()) |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 828 | EXPECT(vkDestroyCommandBuffer(dev_handle_, handle()) == VK_SUCCESS); |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 829 | } |
| 830 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 831 | void CmdBuffer::init(const Device &dev, const VkCmdBufferCreateInfo &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 832 | { |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 833 | VkCmdBuffer cmd; |
| 834 | |
| 835 | if (EXPECT(vkCreateCommandBuffer(dev.handle(), &info, &cmd) == VK_SUCCESS)) { |
| 836 | Handle::init(cmd); |
| 837 | dev_handle_ = dev.handle(); |
| 838 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 839 | } |
| 840 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 841 | void CmdBuffer::begin(const VkCmdBufferBeginInfo *info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 842 | { |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 843 | EXPECT(vkBeginCommandBuffer(handle(), info) == VK_SUCCESS); |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 846 | void CmdBuffer::begin() |
| 847 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 848 | VkCmdBufferBeginInfo info = {}; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 849 | info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 850 | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 851 | info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 852 | |
| 853 | begin(&info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | void CmdBuffer::end() |
| 857 | { |
Chia-I Wu | 78c2a35 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 858 | EXPECT(vkEndCommandBuffer(handle()) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 859 | } |
| 860 | |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 861 | void CmdBuffer::reset(VkCmdBufferResetFlags flags) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 862 | { |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 863 | EXPECT(vkResetCommandBuffer(handle(), flags) == VK_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 864 | } |
| 865 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 866 | }; // namespace vk_testing |