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