Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 2 | * Copyright (c) 2015-2019 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2019 Valve Corporation |
| 4 | * Copyright (c) 2015-2019 LunarG, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 21 | |
Dave Houlton | 0cf0d13 | 2017-12-22 13:55:53 -0700 | [diff] [blame] | 22 | #include "test_common.h" // NOEXCEPT macro (must precede vktestbinding.h) |
| 23 | #include "vktestbinding.h" // Left for clarity, no harm, already included via test_common.h |
Tony-LunarG | 58c59b4 | 2019-01-03 13:19:11 -0700 | [diff] [blame] | 24 | #include "vk_typemap_helper.h" |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 25 | #include <algorithm> |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 26 | #include <assert.h> |
| 27 | #include <iostream> |
| 28 | #include <stdarg.h> |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 29 | #include <string.h> // memset(), memcmp() |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 30 | |
| 31 | namespace { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 32 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 33 | #define NON_DISPATCHABLE_HANDLE_INIT(create_func, dev, ...) \ |
| 34 | do { \ |
| 35 | handle_type handle; \ |
| 36 | if (EXPECT(create_func(dev.handle(), __VA_ARGS__, NULL, &handle) == VK_SUCCESS)) \ |
| 37 | NonDispHandle::init(dev.handle(), handle); \ |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 38 | } while (0) |
| 39 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 40 | #define NON_DISPATCHABLE_HANDLE_DTOR(cls, destroy_func) \ |
| 41 | cls::~cls() { \ |
| 42 | if (initialized()) destroy_func(device(), handle(), NULL); \ |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 45 | #define STRINGIFY(x) #x |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 46 | #define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__)) |
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 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 50 | bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 51 | if (error_callback) { |
| 52 | error_callback(expr, file, line, function); |
| 53 | } else { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 54 | std::cerr << file << ":" << line << ": " << function << ": Expectation `" << expr << "' failed.\n"; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 60 | } // namespace |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 61 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 62 | namespace vk_testing { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 63 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 64 | void set_error_callback(ErrorCallback callback) { error_callback = callback; } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 65 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 66 | VkPhysicalDeviceProperties PhysicalDevice::properties() const { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 67 | VkPhysicalDeviceProperties info; |
| 68 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 69 | vkGetPhysicalDeviceProperties(handle(), &info); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 70 | |
| 71 | return info; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 74 | std::vector<VkQueueFamilyProperties> PhysicalDevice::queue_properties() const { |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 75 | std::vector<VkQueueFamilyProperties> info; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 76 | uint32_t count; |
| 77 | |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 78 | // Call once with NULL data to receive count |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 79 | vkGetPhysicalDeviceQueueFamilyProperties(handle(), &count, NULL); |
| 80 | info.resize(count); |
| 81 | vkGetPhysicalDeviceQueueFamilyProperties(handle(), &count, info.data()); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 82 | |
| 83 | return info; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 84 | } |
| 85 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 86 | VkPhysicalDeviceMemoryProperties PhysicalDevice::memory_properties() const { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 87 | VkPhysicalDeviceMemoryProperties info; |
| 88 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 89 | vkGetPhysicalDeviceMemoryProperties(handle(), &info); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 90 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 91 | return info; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 92 | } |
| 93 | |
Chris Forbes | f9cfe18 | 2016-04-04 17:22:42 +1200 | [diff] [blame] | 94 | VkPhysicalDeviceFeatures PhysicalDevice::features() const { |
| 95 | VkPhysicalDeviceFeatures features; |
| 96 | vkGetPhysicalDeviceFeatures(handle(), &features); |
| 97 | return features; |
| 98 | } |
| 99 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 100 | /* |
| 101 | * Return list of Global layers available |
| 102 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 103 | std::vector<VkLayerProperties> GetGlobalLayers() { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 104 | VkResult err; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 105 | std::vector<VkLayerProperties> layers; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 106 | uint32_t layer_count; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 107 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 108 | do { |
| 109 | layer_count = 0; |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 110 | err = vkEnumerateInstanceLayerProperties(&layer_count, NULL); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 111 | |
| 112 | if (err == VK_SUCCESS) { |
| 113 | layers.reserve(layer_count); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 114 | err = vkEnumerateInstanceLayerProperties(&layer_count, layers.data()); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 115 | } |
| 116 | } while (err == VK_INCOMPLETE); |
| 117 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 118 | assert(err == VK_SUCCESS); |
| 119 | |
| 120 | return layers; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 121 | } |
| 122 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 123 | /* |
| 124 | * Return list of Global extensions provided by the ICD / Loader |
| 125 | */ |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 126 | std::vector<VkExtensionProperties> GetGlobalExtensions() { return GetGlobalExtensions(NULL); } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Return list of Global extensions provided by the specified layer |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | * If pLayerName is NULL, will return extensions implemented by the loader / |
| 131 | * ICDs |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 132 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 133 | std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName) { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 134 | std::vector<VkExtensionProperties> exts; |
| 135 | uint32_t ext_count; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 136 | VkResult err; |
| 137 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 138 | do { |
| 139 | ext_count = 0; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 140 | err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, NULL); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 141 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 142 | if (err == VK_SUCCESS) { |
Courtney Goeltzenleuchter | 381f3a2 | 2015-07-06 15:45:58 -0600 | [diff] [blame] | 143 | exts.resize(ext_count); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 144 | err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, exts.data()); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 145 | } |
| 146 | } while (err == VK_INCOMPLETE); |
| 147 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 148 | assert(err == VK_SUCCESS); |
| 149 | |
| 150 | return exts; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Return list of PhysicalDevice extensions provided by the ICD / Loader |
| 155 | */ |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 156 | std::vector<VkExtensionProperties> PhysicalDevice::extensions() const { return extensions(NULL); } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Return list of PhysicalDevice extensions provided by the specified layer |
| 160 | * If pLayerName is NULL, will return extensions for ICD / loader. |
| 161 | */ |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 162 | std::vector<VkExtensionProperties> PhysicalDevice::extensions(const char *pLayerName) const { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 163 | std::vector<VkExtensionProperties> exts; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 164 | VkResult err; |
| 165 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 166 | do { |
| 167 | uint32_t extCount = 0; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 168 | err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, &extCount, NULL); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 169 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 170 | if (err == VK_SUCCESS) { |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 171 | exts.resize(extCount); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 172 | err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, &extCount, exts.data()); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 173 | } |
| 174 | } while (err == VK_INCOMPLETE); |
| 175 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 176 | assert(err == VK_SUCCESS); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 177 | |
| 178 | return exts; |
| 179 | } |
| 180 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 181 | bool PhysicalDevice::set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkFlags properties, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 182 | const VkFlags forbid) const { |
| 183 | uint32_t type_mask = type_bits; |
| 184 | // Search memtypes to find first index with those properties |
| 185 | for (uint32_t i = 0; i < memory_properties_.memoryTypeCount; i++) { |
| 186 | if ((type_mask & 1) == 1) { |
| 187 | // Type is available, does it match user properties? |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 188 | if ((memory_properties_.memoryTypes[i].propertyFlags & properties) == properties && |
| 189 | (memory_properties_.memoryTypes[i].propertyFlags & forbid) == 0) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 190 | info->memoryTypeIndex = i; |
| 191 | return true; |
| 192 | } |
| 193 | } |
| 194 | type_mask >>= 1; |
| 195 | } |
| 196 | // No memory types matched, return failure |
| 197 | return false; |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 198 | } |
| 199 | |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 200 | /* |
| 201 | * Return list of PhysicalDevice layers |
| 202 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 203 | std::vector<VkLayerProperties> PhysicalDevice::layers() const { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 204 | std::vector<VkLayerProperties> layer_props; |
| 205 | VkResult err; |
| 206 | |
| 207 | do { |
| 208 | uint32_t layer_count = 0; |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 209 | err = vkEnumerateDeviceLayerProperties(handle(), &layer_count, NULL); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 210 | |
| 211 | if (err == VK_SUCCESS) { |
| 212 | layer_props.reserve(layer_count); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 213 | err = vkEnumerateDeviceLayerProperties(handle(), &layer_count, layer_props.data()); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 214 | } |
| 215 | } while (err == VK_INCOMPLETE); |
| 216 | |
| 217 | assert(err == VK_SUCCESS); |
| 218 | |
| 219 | return layer_props; |
| 220 | } |
| 221 | |
Dave Houlton | 6c72f35 | 2018-02-06 17:49:16 -0700 | [diff] [blame] | 222 | QueueCreateInfoArray::QueueCreateInfoArray(const std::vector<VkQueueFamilyProperties> &queue_props) |
| 223 | : queue_info_(), queue_priorities_() { |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 224 | queue_info_.reserve(queue_props.size()); |
| 225 | |
Petr Kraus | 540a67d | 2017-12-11 00:35:33 +0100 | [diff] [blame] | 226 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); ++i) { |
| 227 | if (queue_props[i].queueCount > 0) { |
| 228 | VkDeviceQueueCreateInfo qi = {}; |
| 229 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 230 | qi.pNext = NULL; |
| 231 | qi.queueFamilyIndex = i; |
| 232 | qi.queueCount = queue_props[i].queueCount; |
| 233 | queue_priorities_.emplace_back(qi.queueCount, 0.0f); |
| 234 | qi.pQueuePriorities = queue_priorities_[i].data(); |
| 235 | queue_info_.push_back(qi); |
| 236 | } |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | Device::~Device() { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 241 | if (!initialized()) return; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 242 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 243 | vkDestroyDevice(handle(), NULL); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 244 | } |
| 245 | |
Tony-LunarG | 58c59b4 | 2019-01-03 13:19:11 -0700 | [diff] [blame] | 246 | void Device::init(std::vector<const char *> &extensions, VkPhysicalDeviceFeatures *features, void *create_device_pnext) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 247 | // request all queues |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 248 | const std::vector<VkQueueFamilyProperties> queue_props = phy_.queue_properties(); |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 249 | QueueCreateInfoArray queue_info(phy_.queue_properties()); |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 250 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 252 | graphics_queue_node_index_ = i; |
William Henning | 6a354a5 | 2018-05-23 18:01:51 -0600 | [diff] [blame] | 253 | break; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 254 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 255 | } |
Tobin Ehlis | 04dea91 | 2017-11-14 12:10:11 -0700 | [diff] [blame] | 256 | // Only request creation with queuefamilies that have at least one queue |
| 257 | std::vector<VkDeviceQueueCreateInfo> create_queue_infos; |
| 258 | auto qci = queue_info.data(); |
| 259 | for (uint32_t j = 0; j < queue_info.size(); ++j) { |
| 260 | if (qci[j].queueCount) { |
| 261 | create_queue_infos.push_back(qci[j]); |
| 262 | } |
| 263 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 264 | |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 265 | enabled_extensions_ = extensions; |
| 266 | |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 267 | VkDeviceCreateInfo dev_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
Tony-LunarG | 58c59b4 | 2019-01-03 13:19:11 -0700 | [diff] [blame] | 269 | dev_info.pNext = create_device_pnext; |
Tobin Ehlis | 04dea91 | 2017-11-14 12:10:11 -0700 | [diff] [blame] | 270 | dev_info.queueCreateInfoCount = create_queue_infos.size(); |
| 271 | dev_info.pQueueCreateInfos = create_queue_infos.data(); |
Tony Barbour | 4c70d10 | 2016-08-08 16:06:56 -0600 | [diff] [blame] | 272 | dev_info.enabledLayerCount = 0; |
| 273 | dev_info.ppEnabledLayerNames = NULL; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 274 | dev_info.enabledExtensionCount = extensions.size(); |
Tony Barbour | 482c609 | 2015-07-27 09:37:48 -0600 | [diff] [blame] | 275 | dev_info.ppEnabledExtensionNames = extensions.data(); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 276 | |
Tony Barbour | 53f7e89 | 2016-08-09 13:44:00 -0600 | [diff] [blame] | 277 | VkPhysicalDeviceFeatures all_features; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 278 | // Let VkPhysicalDeviceFeatures2 take priority over VkPhysicalDeviceFeatures, |
| 279 | // since it supports extensions |
Tony-LunarG | 58c59b4 | 2019-01-03 13:19:11 -0700 | [diff] [blame] | 280 | |
| 281 | if (!(lvl_find_in_chain<VkPhysicalDeviceFeatures2>(dev_info.pNext))) { |
| 282 | if (features) { |
| 283 | dev_info.pEnabledFeatures = features; |
| 284 | } else { |
| 285 | // request all supportable features enabled |
| 286 | all_features = phy().features(); |
| 287 | dev_info.pEnabledFeatures = &all_features; |
| 288 | } |
Tony Barbour | 53f7e89 | 2016-08-09 13:44:00 -0600 | [diff] [blame] | 289 | } |
Chris Forbes | f9cfe18 | 2016-04-04 17:22:42 +1200 | [diff] [blame] | 290 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 291 | init(dev_info); |
| 292 | } |
| 293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 294 | void Device::init(const VkDeviceCreateInfo &info) { |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 295 | VkDevice dev; |
| 296 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 297 | if (EXPECT(vkCreateDevice(phy_.handle(), &info, NULL, &dev) == VK_SUCCESS)) Handle::init(dev); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 298 | |
| 299 | init_queues(); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 300 | init_formats(); |
| 301 | } |
| 302 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 303 | void Device::init_queues() { |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 304 | uint32_t queue_node_count; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 305 | |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 306 | // Call with NULL data to get count |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 307 | vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, NULL); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 308 | EXPECT(queue_node_count >= 1); |
| 309 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 310 | VkQueueFamilyProperties *queue_props = new VkQueueFamilyProperties[queue_node_count]; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 311 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 312 | vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, queue_props); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 313 | |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 314 | queue_families_.resize(queue_node_count); |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 315 | for (uint32_t i = 0; i < queue_node_count; i++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 316 | VkQueue queue; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 317 | |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 318 | QueueFamilyQueues &queue_storage = queue_families_[i]; |
| 319 | queue_storage.reserve(queue_props[i].queueCount); |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 320 | for (uint32_t j = 0; j < queue_props[i].queueCount; j++) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 321 | // TODO: Need to add support for separate MEMMGR and work queues, |
| 322 | // including synchronization |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 323 | vkGetDeviceQueue(handle(), i, j, &queue); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 324 | |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 325 | // Store single copy of the queue object that will self destruct |
| 326 | queue_storage.emplace_back(new Queue(queue, i)); |
| 327 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 329 | queues_[GRAPHICS].push_back(queue_storage.back().get()); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 332 | if (queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) { |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 333 | queues_[COMPUTE].push_back(queue_storage.back().get()); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 336 | if (queue_props[i].queueFlags & VK_QUEUE_TRANSFER_BIT) { |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 337 | queues_[DMA].push_back(queue_storage.back().get()); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 338 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Chris Forbes | 0203879 | 2015-06-04 10:49:27 +1200 | [diff] [blame] | 342 | delete[] queue_props; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 343 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 344 | EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty()); |
| 345 | } |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 346 | const Device::QueueFamilyQueues &Device::queue_family_queues(uint32_t queue_family) const { |
| 347 | assert(queue_family < queue_families_.size()); |
| 348 | return queue_families_[queue_family]; |
| 349 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 350 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 351 | void Device::init_formats() { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 352 | 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] | 353 | const VkFormat fmt = static_cast<VkFormat>(f); |
| 354 | const VkFormatProperties props = format_properties(fmt); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 355 | |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 356 | if (props.linearTilingFeatures) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 357 | const Format tmp = {fmt, VK_IMAGE_TILING_LINEAR, props.linearTilingFeatures}; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 358 | formats_.push_back(tmp); |
| 359 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 360 | |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 361 | if (props.optimalTilingFeatures) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 362 | const Format tmp = {fmt, VK_IMAGE_TILING_OPTIMAL, props.optimalTilingFeatures}; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 363 | formats_.push_back(tmp); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
| 367 | EXPECT(!formats_.empty()); |
| 368 | } |
| 369 | |
Cort Stratton | 72f89aa | 2018-05-27 10:40:27 -0700 | [diff] [blame] | 370 | bool Device::IsEnabledExtension(const char *extension) { |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 371 | const auto is_x = [&extension](const char *enabled_extension) { return strcmp(extension, enabled_extension) == 0; }; |
| 372 | return std::any_of(enabled_extensions_.begin(), enabled_extensions_.end(), is_x); |
| 373 | } |
| 374 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 375 | VkFormatProperties Device::format_properties(VkFormat format) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 376 | VkFormatProperties data; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 377 | vkGetPhysicalDeviceFormatProperties(phy().handle(), format, &data); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 378 | |
| 379 | return data; |
| 380 | } |
| 381 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 382 | void Device::wait() { EXPECT(vkDeviceWaitIdle(handle()) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 383 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 384 | VkResult Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) { |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 385 | const std::vector<VkFence> fence_handles = MakeVkHandles<VkFence>(fences); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 386 | VkResult err = vkWaitForFences(handle(), fence_handles.size(), fence_handles.data(), wait_all, timeout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 387 | EXPECT(err == VK_SUCCESS || err == VK_TIMEOUT); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 388 | |
| 389 | return err; |
| 390 | } |
| 391 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 392 | void Device::update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, |
| 393 | const std::vector<VkCopyDescriptorSet> &copies) { |
| 394 | vkUpdateDescriptorSets(handle(), writes.size(), writes.data(), copies.size(), copies.data()); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 395 | } |
| 396 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 397 | VkResult Queue::submit(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success) { |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 398 | const std::vector<VkCommandBuffer> cmd_handles = MakeVkHandles<VkCommandBuffer>(cmds); |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 399 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 400 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 401 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 402 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 403 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 404 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 405 | submit_info.commandBufferCount = (uint32_t)cmd_handles.size(); |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 406 | submit_info.pCommandBuffers = cmd_handles.data(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 407 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 408 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 409 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 410 | VkResult result = vkQueueSubmit(handle(), 1, &submit_info, fence.handle()); |
| 411 | if (expect_success) EXPECT(result == VK_SUCCESS); |
| 412 | return result; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 413 | } |
| 414 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 415 | VkResult Queue::submit(const CommandBuffer &cmd, const Fence &fence, bool expect_success) { |
| 416 | return submit(std::vector<const CommandBuffer *>(1, &cmd), fence, expect_success); |
| 417 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 418 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 419 | VkResult Queue::submit(const CommandBuffer &cmd, bool expect_success) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 420 | Fence fence; |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 421 | return submit(cmd, fence); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 422 | } |
| 423 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 424 | VkResult Queue::wait() { |
| 425 | VkResult result = vkQueueWaitIdle(handle()); |
| 426 | EXPECT(result == VK_SUCCESS); |
| 427 | return result; |
| 428 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 429 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 430 | DeviceMemory::~DeviceMemory() { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 431 | if (initialized()) vkFreeMemory(device(), handle(), NULL); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 432 | } |
| 433 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 434 | void DeviceMemory::init(const Device &dev, const VkMemoryAllocateInfo &info) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 435 | NON_DISPATCHABLE_HANDLE_INIT(vkAllocateMemory, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 436 | } |
| 437 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 438 | const void *DeviceMemory::map(VkFlags flags) const { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 439 | void *data; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 440 | if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 441 | |
| 442 | return data; |
| 443 | } |
| 444 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 445 | void *DeviceMemory::map(VkFlags flags) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 446 | void *data; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 447 | if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 448 | |
| 449 | return data; |
| 450 | } |
| 451 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 452 | void DeviceMemory::unmap() const { vkUnmapMemory(device(), handle()); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 453 | |
Mike Schuchardt | 8cacbb0 | 2017-10-26 14:06:38 -0600 | [diff] [blame] | 454 | VkMemoryAllocateInfo DeviceMemory::get_resource_alloc_info(const Device &dev, const VkMemoryRequirements &reqs, |
| 455 | VkMemoryPropertyFlags mem_props) { |
Tobin Ehlis | a3d6064 | 2017-11-14 10:02:46 -0700 | [diff] [blame] | 456 | // Find appropriate memory type for given reqs |
| 457 | VkPhysicalDeviceMemoryProperties dev_mem_props = dev.phy().memory_properties(); |
| 458 | uint32_t mem_type_index = 0; |
| 459 | for (mem_type_index = 0; mem_type_index < dev_mem_props.memoryTypeCount; ++mem_type_index) { |
| 460 | if (mem_props == (mem_props & dev_mem_props.memoryTypes[mem_type_index].propertyFlags)) break; |
| 461 | } |
| 462 | // If we exceeded types, then this device doesn't have the memory we need |
| 463 | assert(mem_type_index < dev_mem_props.memoryTypeCount); |
| 464 | VkMemoryAllocateInfo info = alloc_info(reqs.size, mem_type_index); |
Mike Schuchardt | 7e567b3 | 2017-11-16 13:15:20 -0700 | [diff] [blame] | 465 | EXPECT(dev.phy().set_memory_type(reqs.memoryTypeBits, &info, mem_props)); |
Mike Schuchardt | 8cacbb0 | 2017-10-26 14:06:38 -0600 | [diff] [blame] | 466 | return info; |
| 467 | } |
| 468 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 469 | NON_DISPATCHABLE_HANDLE_DTOR(Fence, vkDestroyFence) |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 470 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 471 | void Fence::init(const Device &dev, const VkFenceCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateFence, dev, &info); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 472 | |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 473 | VkResult Fence::wait(VkBool32 wait_all, uint64_t timeout) const { |
| 474 | VkFence fence = handle(); |
| 475 | return vkWaitForFences(device(), 1, &fence, wait_all, timeout); |
| 476 | } |
| 477 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 478 | NON_DISPATCHABLE_HANDLE_DTOR(Semaphore, vkDestroySemaphore) |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 479 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 480 | void Semaphore::init(const Device &dev, const VkSemaphoreCreateInfo &info) { |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 481 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateSemaphore, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 482 | } |
| 483 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 484 | NON_DISPATCHABLE_HANDLE_DTOR(Event, vkDestroyEvent) |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 485 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 486 | void Event::init(const Device &dev, const VkEventCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateEvent, dev, &info); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 487 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 488 | void Event::set() { EXPECT(vkSetEvent(device(), handle()) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 489 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 490 | void Event::reset() { EXPECT(vkResetEvent(device(), handle()) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 491 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 492 | NON_DISPATCHABLE_HANDLE_DTOR(QueryPool, vkDestroyQueryPool) |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 493 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 494 | void QueryPool::init(const Device &dev, const VkQueryPoolCreateInfo &info) { |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 495 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateQueryPool, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 496 | } |
| 497 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 498 | VkResult QueryPool::results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride) { |
| 499 | VkResult err = vkGetQueryPoolResults(device(), handle(), first, count, size, data, stride, 0); |
Chia-I Wu | ccc93a7 | 2015-10-26 18:36:20 +0800 | [diff] [blame] | 500 | EXPECT(err == VK_SUCCESS || err == VK_NOT_READY); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 501 | |
| 502 | return err; |
| 503 | } |
| 504 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 505 | NON_DISPATCHABLE_HANDLE_DTOR(Buffer, vkDestroyBuffer) |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 506 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 507 | void Buffer::init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props) { |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 508 | init_no_mem(dev, info); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 509 | |
Mike Schuchardt | 8cacbb0 | 2017-10-26 14:06:38 -0600 | [diff] [blame] | 510 | internal_mem_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements(), mem_props)); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 511 | bind_memory(internal_mem_, 0); |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 512 | } |
| 513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 514 | void Buffer::init_no_mem(const Device &dev, const VkBufferCreateInfo &info) { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 515 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateBuffer, dev, &info); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 516 | create_info_ = info; |
| 517 | } |
| 518 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 519 | VkMemoryRequirements Buffer::memory_requirements() const { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 520 | VkMemoryRequirements reqs; |
| 521 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 522 | vkGetBufferMemoryRequirements(device(), handle(), &reqs); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 523 | |
| 524 | return reqs; |
| 525 | } |
| 526 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 527 | void Buffer::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 528 | EXPECT(vkBindBufferMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 531 | NON_DISPATCHABLE_HANDLE_DTOR(BufferView, vkDestroyBufferView) |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 532 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 533 | void BufferView::init(const Device &dev, const VkBufferViewCreateInfo &info) { |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 534 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateBufferView, dev, &info); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 535 | } |
| 536 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 537 | NON_DISPATCHABLE_HANDLE_DTOR(Image, vkDestroyImage) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 538 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 539 | void Image::init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props) { |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 540 | init_no_mem(dev, info); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 541 | |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 542 | if (initialized()) { |
Mike Schuchardt | 8cacbb0 | 2017-10-26 14:06:38 -0600 | [diff] [blame] | 543 | internal_mem_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements(), mem_props)); |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 544 | bind_memory(internal_mem_, 0); |
| 545 | } |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 548 | void Image::init_no_mem(const Device &dev, const VkImageCreateInfo &info) { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 549 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateImage, dev, &info); |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 550 | if (initialized()) { |
| 551 | init_info(dev, info); |
| 552 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 553 | } |
| 554 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 555 | void Image::init_info(const Device &dev, const VkImageCreateInfo &info) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 556 | create_info_ = info; |
| 557 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 558 | for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { |
| 559 | if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 560 | format_features_ = it->features; |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 566 | VkMemoryRequirements Image::memory_requirements() const { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 567 | VkMemoryRequirements reqs; |
| 568 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 569 | vkGetImageMemoryRequirements(device(), handle(), &reqs); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 570 | |
| 571 | return reqs; |
| 572 | } |
| 573 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 574 | void Image::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 575 | EXPECT(vkBindImageMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 576 | } |
| 577 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 578 | VkSubresourceLayout Image::subresource_layout(const VkImageSubresource &subres) const { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 579 | VkSubresourceLayout data; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 580 | size_t size = sizeof(data); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 581 | vkGetImageSubresourceLayout(device(), handle(), &subres, &data); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 582 | if (size != sizeof(data)) memset(&data, 0, sizeof(data)); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 583 | |
| 584 | return data; |
| 585 | } |
| 586 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 587 | VkSubresourceLayout Image::subresource_layout(const VkImageSubresourceLayers &subrescopy) const { |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 588 | VkSubresourceLayout data; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 589 | VkImageSubresource subres = subresource(subrescopy.aspectMask, subrescopy.mipLevel, subrescopy.baseArrayLayer); |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 590 | size_t size = sizeof(data); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 591 | vkGetImageSubresourceLayout(device(), handle(), &subres, &data); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 592 | if (size != sizeof(data)) memset(&data, 0, sizeof(data)); |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 593 | |
| 594 | return data; |
| 595 | } |
| 596 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 597 | bool Image::transparent() const { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 598 | return (create_info_.tiling == VK_IMAGE_TILING_LINEAR && create_info_.samples == VK_SAMPLE_COUNT_1_BIT && |
| 599 | !(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 600 | } |
| 601 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 602 | NON_DISPATCHABLE_HANDLE_DTOR(ImageView, vkDestroyImageView) |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 603 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 604 | void ImageView::init(const Device &dev, const VkImageViewCreateInfo &info) { |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 605 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateImageView, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 608 | AccelerationStructure::~AccelerationStructure() { |
| 609 | if (initialized()) { |
| 610 | PFN_vkDestroyAccelerationStructureNV vkDestroyAccelerationStructureNV = |
| 611 | (PFN_vkDestroyAccelerationStructureNV)vkGetDeviceProcAddr(device(), "vkDestroyAccelerationStructureNV"); |
| 612 | assert(vkDestroyAccelerationStructureNV != nullptr); |
| 613 | |
| 614 | vkDestroyAccelerationStructureNV(device(), handle(), nullptr); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | VkMemoryRequirements2 AccelerationStructure::memory_requirements() const { |
| 619 | PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV = |
| 620 | (PFN_vkGetAccelerationStructureMemoryRequirementsNV)vkGetDeviceProcAddr(device(), |
| 621 | "vkGetAccelerationStructureMemoryRequirementsNV"); |
| 622 | assert(vkGetAccelerationStructureMemoryRequirementsNV != nullptr); |
| 623 | |
| 624 | VkAccelerationStructureMemoryRequirementsInfoNV memoryRequirementsInfo = {}; |
| 625 | memoryRequirementsInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 626 | memoryRequirementsInfo.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV; |
| 627 | memoryRequirementsInfo.accelerationStructure = handle(); |
| 628 | |
| 629 | VkMemoryRequirements2 memoryRequirements = {}; |
| 630 | vkGetAccelerationStructureMemoryRequirementsNV(device(), &memoryRequirementsInfo, &memoryRequirements); |
| 631 | return memoryRequirements; |
| 632 | } |
| 633 | |
| 634 | VkMemoryRequirements2 AccelerationStructure::build_scratch_memory_requirements() const { |
| 635 | PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV = |
| 636 | (PFN_vkGetAccelerationStructureMemoryRequirementsNV)vkGetDeviceProcAddr(device(), |
| 637 | "vkGetAccelerationStructureMemoryRequirementsNV"); |
| 638 | assert(vkGetAccelerationStructureMemoryRequirementsNV != nullptr); |
| 639 | |
| 640 | VkAccelerationStructureMemoryRequirementsInfoNV memoryRequirementsInfo = {}; |
| 641 | memoryRequirementsInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 642 | memoryRequirementsInfo.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV; |
| 643 | memoryRequirementsInfo.accelerationStructure = handle(); |
| 644 | |
| 645 | VkMemoryRequirements2 memoryRequirements = {}; |
| 646 | vkGetAccelerationStructureMemoryRequirementsNV(device(), &memoryRequirementsInfo, &memoryRequirements); |
| 647 | return memoryRequirements; |
| 648 | } |
| 649 | |
| 650 | void AccelerationStructure::init(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory) { |
| 651 | PFN_vkCreateAccelerationStructureNV vkCreateAccelerationStructureNV = |
| 652 | (PFN_vkCreateAccelerationStructureNV)vkGetDeviceProcAddr(dev.handle(), "vkCreateAccelerationStructureNV"); |
| 653 | assert(vkCreateAccelerationStructureNV != nullptr); |
| 654 | |
| 655 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateAccelerationStructureNV, dev, &info); |
| 656 | |
| 657 | info_ = info.info; |
| 658 | |
| 659 | if (init_memory) { |
| 660 | memory_.init(dev, DeviceMemory::get_resource_alloc_info(dev, memory_requirements().memoryRequirements, |
| 661 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)); |
| 662 | |
| 663 | PFN_vkBindAccelerationStructureMemoryNV vkBindAccelerationStructureMemoryNV = |
| 664 | (PFN_vkBindAccelerationStructureMemoryNV)vkGetDeviceProcAddr(dev.handle(), "vkBindAccelerationStructureMemoryNV"); |
| 665 | assert(vkBindAccelerationStructureMemoryNV != nullptr); |
| 666 | |
| 667 | VkBindAccelerationStructureMemoryInfoNV bind_info = {}; |
| 668 | bind_info.sType = VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV; |
| 669 | bind_info.accelerationStructure = handle(); |
| 670 | bind_info.memory = memory_.handle(); |
| 671 | EXPECT(vkBindAccelerationStructureMemoryNV(dev.handle(), 1, &bind_info) == VK_SUCCESS); |
Jason Macnak | e4b41ca | 2019-07-11 11:05:31 -0700 | [diff] [blame] | 672 | |
| 673 | PFN_vkGetAccelerationStructureHandleNV vkGetAccelerationStructureHandleNV = |
| 674 | (PFN_vkGetAccelerationStructureHandleNV)vkGetDeviceProcAddr(dev.handle(), "vkGetAccelerationStructureHandleNV"); |
| 675 | assert(vkGetAccelerationStructureHandleNV != nullptr); |
| 676 | EXPECT(vkGetAccelerationStructureHandleNV(dev.handle(), handle(), sizeof(uint64_t), &opaque_handle_) == VK_SUCCESS); |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | void AccelerationStructure::create_scratch_buffer(const Device &dev, Buffer *buffer) { |
| 681 | VkMemoryRequirements scratch_buffer_memory_requirements = build_scratch_memory_requirements().memoryRequirements; |
| 682 | |
| 683 | VkBufferCreateInfo create_info = {}; |
| 684 | create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 685 | create_info.size = scratch_buffer_memory_requirements.size; |
| 686 | create_info.usage = VK_BUFFER_USAGE_RAY_TRACING_BIT_NV; |
| 687 | return buffer->init(dev, create_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); |
| 688 | } |
| 689 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 690 | NON_DISPATCHABLE_HANDLE_DTOR(ShaderModule, vkDestroyShaderModule) |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 691 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 692 | void ShaderModule::init(const Device &dev, const VkShaderModuleCreateInfo &info) { |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 693 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateShaderModule, dev, &info); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 694 | } |
| 695 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 696 | VkResult ShaderModule::init_try(const Device &dev, const VkShaderModuleCreateInfo &info) { |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 697 | VkShaderModule mod; |
| 698 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 699 | VkResult err = vkCreateShaderModule(dev.handle(), &info, NULL, &mod); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 700 | if (err == VK_SUCCESS) NonDispHandle::init(dev.handle(), mod); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 701 | |
| 702 | return err; |
| 703 | } |
| 704 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 705 | NON_DISPATCHABLE_HANDLE_DTOR(Pipeline, vkDestroyPipeline) |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 706 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 707 | void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 708 | VkPipelineCache cache; |
| 709 | VkPipelineCacheCreateInfo ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 710 | memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 711 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 712 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 713 | if (err == VK_SUCCESS) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 714 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateGraphicsPipelines, dev, cache, 1, &info); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 715 | vkDestroyPipelineCache(dev.handle(), cache, NULL); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 716 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 717 | } |
| 718 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 719 | VkResult Pipeline::init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 720 | VkPipeline pipe; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 721 | VkPipelineCache cache; |
| 722 | VkPipelineCacheCreateInfo ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 723 | memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 724 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 725 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 726 | EXPECT(err == VK_SUCCESS); |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 727 | if (err == VK_SUCCESS) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 728 | err = vkCreateGraphicsPipelines(dev.handle(), cache, 1, &info, NULL, &pipe); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 729 | if (err == VK_SUCCESS) { |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 730 | NonDispHandle::init(dev.handle(), pipe); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 731 | } |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 732 | vkDestroyPipelineCache(dev.handle(), cache, NULL); |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | return err; |
| 736 | } |
| 737 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 738 | void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info) { |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 739 | VkPipelineCache cache; |
| 740 | VkPipelineCacheCreateInfo ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 741 | memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 742 | ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 743 | VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 744 | if (err == VK_SUCCESS) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 745 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateComputePipelines, dev, cache, 1, &info); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 746 | vkDestroyPipelineCache(dev.handle(), cache, NULL); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 747 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 748 | } |
| 749 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 750 | NON_DISPATCHABLE_HANDLE_DTOR(PipelineLayout, vkDestroyPipelineLayout) |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 751 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 752 | void PipelineLayout::init(const Device &dev, VkPipelineLayoutCreateInfo &info, |
| 753 | const std::vector<const DescriptorSetLayout *> &layouts) { |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 754 | const std::vector<VkDescriptorSetLayout> layout_handles = MakeVkHandles<VkDescriptorSetLayout>(layouts); |
Petr Kraus | 65ccc88 | 2017-12-03 15:36:03 +0100 | [diff] [blame] | 755 | info.setLayoutCount = layout_handles.size(); |
Tony Barbour | 482c609 | 2015-07-27 09:37:48 -0600 | [diff] [blame] | 756 | info.pSetLayouts = layout_handles.data(); |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 757 | |
| 758 | NON_DISPATCHABLE_HANDLE_INIT(vkCreatePipelineLayout, dev, &info); |
| 759 | } |
| 760 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 761 | NON_DISPATCHABLE_HANDLE_DTOR(Sampler, vkDestroySampler) |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 762 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 763 | void Sampler::init(const Device &dev, const VkSamplerCreateInfo &info) { |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 764 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateSampler, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 765 | } |
| 766 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 767 | NON_DISPATCHABLE_HANDLE_DTOR(DescriptorSetLayout, vkDestroyDescriptorSetLayout) |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 768 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 769 | void DescriptorSetLayout::init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info) { |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 770 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorSetLayout, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 773 | NON_DISPATCHABLE_HANDLE_DTOR(DescriptorPool, vkDestroyDescriptorPool) |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 774 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 775 | void DescriptorPool::init(const Device &dev, const VkDescriptorPoolCreateInfo &info) { |
| 776 | setDynamicUsage(info.flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT); |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 777 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorPool, dev, &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 778 | } |
| 779 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 780 | void DescriptorPool::reset() { EXPECT(vkResetDescriptorPool(device(), handle(), 0) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 781 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 782 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, |
| 783 | const std::vector<const DescriptorSetLayout *> &layouts) { |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 784 | const std::vector<VkDescriptorSetLayout> layout_handles = MakeVkHandles<VkDescriptorSetLayout>(layouts); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 785 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 786 | std::vector<VkDescriptorSet> set_handles; |
| 787 | set_handles.resize(layout_handles.size()); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 788 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 789 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 790 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 791 | alloc_info.descriptorSetCount = layout_handles.size(); |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 792 | alloc_info.descriptorPool = handle(); |
| 793 | alloc_info.pSetLayouts = layout_handles.data(); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 794 | VkResult err = vkAllocateDescriptorSets(device(), &alloc_info, set_handles.data()); |
Cody Northrop | 1e4f802 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 795 | EXPECT(err == VK_SUCCESS); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 796 | |
| 797 | std::vector<DescriptorSet *> sets; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 798 | 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] | 799 | // do descriptor sets need memories bound? |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 800 | DescriptorSet *descriptorSet = new DescriptorSet(dev, this, *it); |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 801 | sets.push_back(descriptorSet); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 802 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 803 | return sets; |
| 804 | } |
| 805 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 806 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count) { |
| 807 | return alloc_sets(dev, std::vector<const DescriptorSetLayout *>(count, &layout)); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 810 | DescriptorSet *DescriptorPool::alloc_sets(const Device &dev, const DescriptorSetLayout &layout) { |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 811 | std::vector<DescriptorSet *> set = alloc_sets(dev, layout, 1); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 812 | return (set.empty()) ? NULL : set[0]; |
| 813 | } |
| 814 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 815 | DescriptorSet::~DescriptorSet() { |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 816 | if (initialized()) { |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 817 | // Only call vkFree* on sets allocated from pool with usage *_DYNAMIC |
| 818 | if (containing_pool_->getDynamicUsage()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 819 | VkDescriptorSet sets[1] = {handle()}; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 820 | EXPECT(vkFreeDescriptorSets(device(), containing_pool_->GetObj(), 1, sets) == VK_SUCCESS); |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 821 | } |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 822 | } |
| 823 | } |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 824 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 825 | NON_DISPATCHABLE_HANDLE_DTOR(CommandPool, vkDestroyCommandPool) |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 826 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 827 | void CommandPool::init(const Device &dev, const VkCommandPoolCreateInfo &info) { |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 828 | NON_DISPATCHABLE_HANDLE_INIT(vkCreateCommandPool, dev, &info); |
| 829 | } |
| 830 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 831 | CommandBuffer::~CommandBuffer() { |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 832 | if (initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 833 | VkCommandBuffer cmds[] = {handle()}; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 834 | vkFreeCommandBuffers(dev_handle_, cmd_pool_, 1, cmds); |
| 835 | } |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 836 | } |
| 837 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 838 | void CommandBuffer::init(const Device &dev, const VkCommandBufferAllocateInfo &info) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 839 | VkCommandBuffer cmd; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 840 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 841 | // Make sure commandPool is set |
| 842 | assert(info.commandPool); |
Courtney Goeltzenleuchter | d8e68bb | 2015-07-13 12:53:32 -0600 | [diff] [blame] | 843 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 844 | if (EXPECT(vkAllocateCommandBuffers(dev.handle(), &info, &cmd) == VK_SUCCESS)) { |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 845 | Handle::init(cmd); |
| 846 | dev_handle_ = dev.handle(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 847 | cmd_pool_ = info.commandPool; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 848 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 849 | } |
| 850 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 851 | void CommandBuffer::begin(const VkCommandBufferBeginInfo *info) { EXPECT(vkBeginCommandBuffer(handle(), info) == VK_SUCCESS); } |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 852 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 853 | void CommandBuffer::begin() { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 854 | VkCommandBufferBeginInfo info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 855 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 856 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 857 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 858 | info.pInheritanceInfo = &hinfo; |
| 859 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 860 | hinfo.pNext = NULL; |
| 861 | hinfo.renderPass = VK_NULL_HANDLE; |
| 862 | hinfo.subpass = 0; |
| 863 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 864 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 865 | hinfo.queryFlags = 0; |
| 866 | hinfo.pipelineStatistics = 0; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 867 | |
| 868 | begin(&info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 869 | } |
| 870 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 871 | void CommandBuffer::end() { EXPECT(vkEndCommandBuffer(handle()) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 872 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 873 | void CommandBuffer::reset(VkCommandBufferResetFlags flags) { EXPECT(vkResetCommandBuffer(handle(), flags) == VK_SUCCESS); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 874 | |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 875 | } // namespace vk_testing |