Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // RendererVk.cpp: |
| 7 | // Implements the class methods for RendererVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 11 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 12 | // Placing this first seems to solve an intellisense bug. |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 13 | #include "libANGLE/renderer/vulkan/vk_utils.h" |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 14 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 15 | #include <EGL/eglext.h> |
| 16 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 17 | #include "common/debug.h" |
Jamie Madill | a66779f | 2017-01-06 10:43:44 -0500 | [diff] [blame] | 18 | #include "common/system_utils.h" |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/driver_utils.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
| 22 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/GlslangWrapper.h" |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/vulkan/ProgramVk.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 25 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
Luc Ferron | e4741fd | 2018-01-25 13:25:27 -0500 | [diff] [blame] | 26 | #include "libANGLE/renderer/vulkan/vk_caps_utils.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 27 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 28 | #include "platform/Platform.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 29 | |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 30 | // Consts |
| 31 | namespace |
| 32 | { |
| 33 | const uint32_t kMockVendorID = 0xba5eba11; |
| 34 | const uint32_t kMockDeviceID = 0xf005ba11; |
| 35 | constexpr char kMockDeviceName[] = "Vulkan Mock Device"; |
Omar El Sheikh | 0359b69 | 2018-07-23 17:22:00 -0600 | [diff] [blame] | 36 | constexpr size_t kInFlightCommandsLimit = 50000u; |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 37 | } // anonymous namespace |
| 38 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 39 | namespace rx |
| 40 | { |
| 41 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 42 | namespace |
| 43 | { |
Luc Ferron | daedf4d | 2018-03-16 09:28:53 -0400 | [diff] [blame] | 44 | // We currently only allocate 2 uniform buffer per descriptor set, one for the fragment shader and |
| 45 | // one for the vertex shader. |
| 46 | constexpr size_t kUniformBufferDescriptorsPerDescriptorSet = 2; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 47 | |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 48 | bool ShouldEnableMockICD(const egl::AttributeMap &attribs) |
| 49 | { |
| 50 | #if !defined(ANGLE_PLATFORM_ANDROID) |
| 51 | // Mock ICD does not currently run on Android |
| 52 | return (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, |
| 53 | EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) == |
| 54 | EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE); |
| 55 | #else |
| 56 | return false; |
| 57 | #endif // !defined(ANGLE_PLATFORM_ANDROID) |
| 58 | } |
| 59 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 60 | VkResult VerifyExtensionsPresent(const std::vector<VkExtensionProperties> &extensionProps, |
| 61 | const std::vector<const char *> &enabledExtensionNames) |
| 62 | { |
| 63 | // Compile the extensions names into a set. |
| 64 | std::set<std::string> extensionNames; |
| 65 | for (const auto &extensionProp : extensionProps) |
| 66 | { |
| 67 | extensionNames.insert(extensionProp.extensionName); |
| 68 | } |
| 69 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 70 | for (const char *extensionName : enabledExtensionNames) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 71 | { |
| 72 | if (extensionNames.count(extensionName) == 0) |
| 73 | { |
| 74 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return VK_SUCCESS; |
| 79 | } |
| 80 | |
Tobin Ehlis | 3a181e3 | 2018-08-29 15:17:05 -0600 | [diff] [blame] | 81 | // Array of Validation error/warning messages that will be ignored, should include bugID |
| 82 | constexpr std::array<const char *, 1> kSkippedMessages = { |
| 83 | // http://anglebug.com/2796 |
| 84 | " [ UNASSIGNED-CoreValidation-Shader-PointSizeMissing ] Object: VK_NULL_HANDLE (Type = 19) " |
| 85 | "| Pipeline topology is set to POINT_LIST, but PointSize is not written to in the shader " |
| 86 | "corresponding to VK_SHADER_STAGE_VERTEX_BIT."}; |
| 87 | |
| 88 | // Suppress validation errors that are known |
| 89 | // return "true" if given code/prefix/message is known, else return "false" |
| 90 | bool IsIgnoredDebugMessage(const char *message) |
| 91 | { |
| 92 | for (const auto &msg : kSkippedMessages) |
| 93 | { |
| 94 | if (strcmp(msg, message) == 0) |
| 95 | { |
| 96 | return true; |
| 97 | } |
| 98 | } |
| 99 | return false; |
| 100 | } |
| 101 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 102 | VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT flags, |
| 103 | VkDebugReportObjectTypeEXT objectType, |
| 104 | uint64_t object, |
| 105 | size_t location, |
| 106 | int32_t messageCode, |
| 107 | const char *layerPrefix, |
| 108 | const char *message, |
| 109 | void *userData) |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 110 | { |
Tobin Ehlis | 3a181e3 | 2018-08-29 15:17:05 -0600 | [diff] [blame] | 111 | if (IsIgnoredDebugMessage(message)) |
| 112 | { |
| 113 | return VK_FALSE; |
| 114 | } |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 115 | if ((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) != 0) |
| 116 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 117 | ERR() << message; |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 118 | #if !defined(NDEBUG) |
| 119 | // Abort the call in Debug builds. |
| 120 | return VK_TRUE; |
| 121 | #endif |
| 122 | } |
| 123 | else if ((flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) != 0) |
| 124 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 125 | WARN() << message; |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 126 | } |
| 127 | else |
| 128 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 129 | // Uncomment this if you want Vulkan spam. |
| 130 | // WARN() << message; |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | return VK_FALSE; |
| 134 | } |
| 135 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 136 | // If we're loading the validation layers, we could be running from any random directory. |
| 137 | // Change to the executable directory so we can find the layers, then change back to the |
| 138 | // previous directory to be safe we don't disrupt the application. |
| 139 | class ScopedVkLoaderEnvironment : angle::NonCopyable |
| 140 | { |
| 141 | public: |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 142 | ScopedVkLoaderEnvironment(bool enableValidationLayers, bool enableMockICD) |
| 143 | : mEnableValidationLayers(enableValidationLayers), |
| 144 | mEnableMockICD(enableMockICD), |
| 145 | mChangedCWD(false), |
| 146 | mChangedICDPath(false) |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 147 | { |
| 148 | // Changing CWD and setting environment variables makes no sense on Android, |
| 149 | // since this code is a part of Java application there. |
| 150 | // Android Vulkan loader doesn't need this either. |
| 151 | #if !defined(ANGLE_PLATFORM_ANDROID) |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 152 | if (enableMockICD) |
| 153 | { |
| 154 | // Override environment variable to use built Mock ICD |
| 155 | // ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn |
| 156 | mPreviousICDPath = angle::GetEnvironmentVar(g_VkICDPathEnv); |
| 157 | mChangedICDPath = angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON); |
| 158 | if (!mChangedICDPath) |
| 159 | { |
| 160 | ERR() << "Error setting Path for Mock/Null Driver."; |
| 161 | mEnableMockICD = false; |
| 162 | } |
| 163 | } |
Jamie Madill | 4684842 | 2018-08-09 10:46:06 -0400 | [diff] [blame] | 164 | if (mEnableValidationLayers || mEnableMockICD) |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 165 | { |
| 166 | const auto &cwd = angle::GetCWD(); |
| 167 | if (!cwd.valid()) |
| 168 | { |
| 169 | ERR() << "Error getting CWD for Vulkan layers init."; |
| 170 | mEnableValidationLayers = false; |
Jamie Madill | 4684842 | 2018-08-09 10:46:06 -0400 | [diff] [blame] | 171 | mEnableMockICD = false; |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 172 | } |
| 173 | else |
| 174 | { |
| 175 | mPreviousCWD = cwd.value(); |
| 176 | const char *exeDir = angle::GetExecutableDirectory(); |
| 177 | mChangedCWD = angle::SetCWD(exeDir); |
| 178 | if (!mChangedCWD) |
| 179 | { |
| 180 | ERR() << "Error setting CWD for Vulkan layers init."; |
| 181 | mEnableValidationLayers = false; |
Jamie Madill | 4684842 | 2018-08-09 10:46:06 -0400 | [diff] [blame] | 182 | mEnableMockICD = false; |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // Override environment variable to use the ANGLE layers. |
| 188 | if (mEnableValidationLayers) |
| 189 | { |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 190 | if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_DATA_DIR)) |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 191 | { |
| 192 | ERR() << "Error setting environment for Vulkan layers init."; |
| 193 | mEnableValidationLayers = false; |
| 194 | } |
| 195 | } |
| 196 | #endif // !defined(ANGLE_PLATFORM_ANDROID) |
| 197 | } |
| 198 | |
| 199 | ~ScopedVkLoaderEnvironment() |
| 200 | { |
| 201 | if (mChangedCWD) |
| 202 | { |
| 203 | #if !defined(ANGLE_PLATFORM_ANDROID) |
| 204 | ASSERT(mPreviousCWD.valid()); |
| 205 | angle::SetCWD(mPreviousCWD.value().c_str()); |
| 206 | #endif // !defined(ANGLE_PLATFORM_ANDROID) |
| 207 | } |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 208 | if (mChangedICDPath) |
| 209 | { |
Omar El Sheikh | 80d4ef1 | 2018-07-13 17:08:19 -0600 | [diff] [blame] | 210 | if (mPreviousICDPath.value().empty()) |
| 211 | { |
| 212 | angle::UnsetEnvironmentVar(g_VkICDPathEnv); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | angle::SetEnvironmentVar(g_VkICDPathEnv, mPreviousICDPath.value().c_str()); |
| 217 | } |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 218 | } |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 221 | bool canEnableValidationLayers() const { return mEnableValidationLayers; } |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 222 | |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 223 | bool canEnableMockICD() const { return mEnableMockICD; } |
| 224 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 225 | private: |
| 226 | bool mEnableValidationLayers; |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 227 | bool mEnableMockICD; |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 228 | bool mChangedCWD; |
| 229 | Optional<std::string> mPreviousCWD; |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 230 | bool mChangedICDPath; |
| 231 | Optional<std::string> mPreviousICDPath; |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 232 | }; |
| 233 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 234 | void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices, |
| 235 | bool preferMockICD, |
| 236 | VkPhysicalDevice *physicalDeviceOut, |
| 237 | VkPhysicalDeviceProperties *physicalDevicePropertiesOut) |
| 238 | { |
| 239 | ASSERT(!physicalDevices.empty()); |
| 240 | if (preferMockICD) |
| 241 | { |
| 242 | for (const VkPhysicalDevice &physicalDevice : physicalDevices) |
| 243 | { |
| 244 | vkGetPhysicalDeviceProperties(physicalDevice, physicalDevicePropertiesOut); |
| 245 | if ((kMockVendorID == physicalDevicePropertiesOut->vendorID) && |
| 246 | (kMockDeviceID == physicalDevicePropertiesOut->deviceID) && |
| 247 | (strcmp(kMockDeviceName, physicalDevicePropertiesOut->deviceName) == 0)) |
| 248 | { |
| 249 | *physicalDeviceOut = physicalDevice; |
| 250 | return; |
| 251 | } |
| 252 | } |
| 253 | WARN() << "Vulkan Mock Driver was requested but Mock Device was not found. Using default " |
| 254 | "physicalDevice instead."; |
| 255 | } |
| 256 | |
| 257 | // Fall back to first device. |
| 258 | *physicalDeviceOut = physicalDevices[0]; |
| 259 | vkGetPhysicalDeviceProperties(*physicalDeviceOut, physicalDevicePropertiesOut); |
| 260 | } |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 261 | } // anonymous namespace |
| 262 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 263 | // CommandBatch implementation. |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 264 | RendererVk::CommandBatch::CommandBatch() = default; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 265 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 266 | RendererVk::CommandBatch::~CommandBatch() = default; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 267 | |
| 268 | RendererVk::CommandBatch::CommandBatch(CommandBatch &&other) |
| 269 | : commandPool(std::move(other.commandPool)), fence(std::move(other.fence)), serial(other.serial) |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | RendererVk::CommandBatch &RendererVk::CommandBatch::operator=(CommandBatch &&other) |
| 274 | { |
| 275 | std::swap(commandPool, other.commandPool); |
| 276 | std::swap(fence, other.fence); |
| 277 | std::swap(serial, other.serial); |
| 278 | return *this; |
| 279 | } |
| 280 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 281 | void RendererVk::CommandBatch::destroy(VkDevice device) |
| 282 | { |
| 283 | commandPool.destroy(device); |
| 284 | fence.destroy(device); |
| 285 | } |
| 286 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 287 | // RendererVk implementation. |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 288 | RendererVk::RendererVk() |
| 289 | : mCapsInitialized(false), |
| 290 | mInstance(VK_NULL_HANDLE), |
| 291 | mEnableValidationLayers(false), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 292 | mDebugReportCallback(VK_NULL_HANDLE), |
| 293 | mPhysicalDevice(VK_NULL_HANDLE), |
| 294 | mQueue(VK_NULL_HANDLE), |
| 295 | mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()), |
| 296 | mDevice(VK_NULL_HANDLE), |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 297 | mLastCompletedQueueSerial(mQueueSerialFactory.generate()), |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 298 | mCurrentQueueSerial(mQueueSerialFactory.generate()) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 299 | { |
| 300 | } |
| 301 | |
| 302 | RendererVk::~RendererVk() |
| 303 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void RendererVk::onDestroy(vk::Context *context) |
| 307 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 308 | if (!mInFlightCommands.empty() || !mGarbage.empty()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 309 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 310 | // TODO(jmadill): Not nice to pass nullptr here, but shouldn't be a problem. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 311 | (void)finish(context); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 312 | } |
| 313 | |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 314 | mPipelineLayoutCache.destroy(mDevice); |
| 315 | mDescriptorSetLayoutCache.destroy(mDevice); |
| 316 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 317 | mRenderPassCache.destroy(mDevice); |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 318 | mPipelineCache.destroy(mDevice); |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 319 | mShaderLibrary.destroy(mDevice); |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 320 | |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 321 | GlslangWrapper::Release(); |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 322 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 323 | if (mCommandPool.valid()) |
| 324 | { |
| 325 | mCommandPool.destroy(mDevice); |
| 326 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 327 | |
| 328 | if (mDevice) |
| 329 | { |
| 330 | vkDestroyDevice(mDevice, nullptr); |
| 331 | mDevice = VK_NULL_HANDLE; |
| 332 | } |
| 333 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 334 | if (mDebugReportCallback) |
| 335 | { |
| 336 | ASSERT(mInstance); |
| 337 | auto destroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>( |
| 338 | vkGetInstanceProcAddr(mInstance, "vkDestroyDebugReportCallbackEXT")); |
| 339 | ASSERT(destroyDebugReportCallback); |
| 340 | destroyDebugReportCallback(mInstance, mDebugReportCallback, nullptr); |
| 341 | } |
| 342 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 343 | if (mInstance) |
| 344 | { |
| 345 | vkDestroyInstance(mInstance, nullptr); |
| 346 | mInstance = VK_NULL_HANDLE; |
| 347 | } |
| 348 | |
Omar El Sheikh | eb4b869 | 2018-07-17 10:55:40 -0600 | [diff] [blame] | 349 | mMemoryProperties.destroy(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 350 | mPhysicalDevice = VK_NULL_HANDLE; |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 353 | angle::Result RendererVk::initialize(vk::Context *context, |
| 354 | const egl::AttributeMap &attribs, |
| 355 | const char *wsiName) |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 356 | { |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 357 | ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs), |
| 358 | ShouldEnableMockICD(attribs)); |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 359 | mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers(); |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 360 | bool enableMockICD = scopedEnvironment.canEnableMockICD(); |
Jamie Madill | a66779f | 2017-01-06 10:43:44 -0500 | [diff] [blame] | 361 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 362 | // Gather global layer properties. |
| 363 | uint32_t instanceLayerCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 364 | ANGLE_VK_TRY(context, vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 365 | |
| 366 | std::vector<VkLayerProperties> instanceLayerProps(instanceLayerCount); |
| 367 | if (instanceLayerCount > 0) |
| 368 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 369 | ANGLE_VK_TRY(context, vkEnumerateInstanceLayerProperties(&instanceLayerCount, |
| 370 | instanceLayerProps.data())); |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 371 | } |
| 372 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 373 | uint32_t instanceExtensionCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 374 | ANGLE_VK_TRY(context, |
| 375 | vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr)); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 376 | |
| 377 | std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount); |
| 378 | if (instanceExtensionCount > 0) |
| 379 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 380 | ANGLE_VK_TRY(context, vkEnumerateInstanceExtensionProperties( |
| 381 | nullptr, &instanceExtensionCount, instanceExtensionProps.data())); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 384 | const char *const *enabledLayerNames = nullptr; |
| 385 | uint32_t enabledLayerCount = 0; |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 386 | if (mEnableValidationLayers) |
| 387 | { |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 388 | bool layersRequested = |
| 389 | (attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE) == EGL_TRUE); |
| 390 | mEnableValidationLayers = GetAvailableValidationLayers( |
| 391 | instanceLayerProps, layersRequested, &enabledLayerNames, &enabledLayerCount); |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 394 | std::vector<const char *> enabledInstanceExtensions; |
| 395 | enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 396 | enabledInstanceExtensions.push_back(wsiName); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 397 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 398 | // TODO(jmadill): Should be able to continue initialization if debug report ext missing. |
| 399 | if (mEnableValidationLayers) |
| 400 | { |
| 401 | enabledInstanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
| 402 | } |
| 403 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 404 | // Verify the required extensions are in the extension names set. Fail if not. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 405 | ANGLE_VK_TRY(context, |
| 406 | VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions)); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 407 | |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 408 | VkApplicationInfo applicationInfo; |
| 409 | applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 410 | applicationInfo.pNext = nullptr; |
| 411 | applicationInfo.pApplicationName = "ANGLE"; |
| 412 | applicationInfo.applicationVersion = 1; |
| 413 | applicationInfo.pEngineName = "ANGLE"; |
| 414 | applicationInfo.engineVersion = 1; |
| 415 | applicationInfo.apiVersion = VK_API_VERSION_1_0; |
| 416 | |
| 417 | VkInstanceCreateInfo instanceInfo; |
| 418 | instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
| 419 | instanceInfo.pNext = nullptr; |
| 420 | instanceInfo.flags = 0; |
| 421 | instanceInfo.pApplicationInfo = &applicationInfo; |
| 422 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 423 | // Enable requested layers and extensions. |
| 424 | instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size()); |
| 425 | instanceInfo.ppEnabledExtensionNames = |
| 426 | enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data(); |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 427 | instanceInfo.enabledLayerCount = enabledLayerCount; |
| 428 | instanceInfo.ppEnabledLayerNames = enabledLayerNames; |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 429 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 430 | ANGLE_VK_TRY(context, vkCreateInstance(&instanceInfo, nullptr, &mInstance)); |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 431 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 432 | if (mEnableValidationLayers) |
| 433 | { |
| 434 | VkDebugReportCallbackCreateInfoEXT debugReportInfo; |
| 435 | |
| 436 | debugReportInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; |
| 437 | debugReportInfo.pNext = nullptr; |
| 438 | debugReportInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | |
| 439 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
| 440 | VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
| 441 | debugReportInfo.pfnCallback = &DebugReportCallback; |
| 442 | debugReportInfo.pUserData = this; |
| 443 | |
| 444 | auto createDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>( |
| 445 | vkGetInstanceProcAddr(mInstance, "vkCreateDebugReportCallbackEXT")); |
| 446 | ASSERT(createDebugReportCallback); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 447 | ANGLE_VK_TRY(context, createDebugReportCallback(mInstance, &debugReportInfo, nullptr, |
| 448 | &mDebugReportCallback)); |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 449 | } |
| 450 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 451 | uint32_t physicalDeviceCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 452 | ANGLE_VK_TRY(context, vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, nullptr)); |
| 453 | ANGLE_VK_CHECK(context, physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 454 | |
| 455 | // TODO(jmadill): Handle multiple physical devices. For now, use the first device. |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 456 | std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 457 | ANGLE_VK_TRY(context, vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, |
| 458 | physicalDevices.data())); |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 459 | ChoosePhysicalDevice(physicalDevices, enableMockICD, &mPhysicalDevice, |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 460 | &mPhysicalDeviceProperties); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 461 | |
Jamie Madill | 30b5d84 | 2018-08-31 17:19:12 -0400 | [diff] [blame^] | 462 | vkGetPhysicalDeviceFeatures(mPhysicalDevice, &mPhysicalDeviceFeatures); |
| 463 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 464 | // Ensure we can find a graphics queue family. |
| 465 | uint32_t queueCount = 0; |
| 466 | vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr); |
| 467 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 468 | ANGLE_VK_CHECK(context, queueCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 469 | |
| 470 | mQueueFamilyProperties.resize(queueCount); |
| 471 | vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, |
| 472 | mQueueFamilyProperties.data()); |
| 473 | |
| 474 | size_t graphicsQueueFamilyCount = false; |
| 475 | uint32_t firstGraphicsQueueFamily = 0; |
| 476 | for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex) |
| 477 | { |
| 478 | const auto &queueInfo = mQueueFamilyProperties[familyIndex]; |
| 479 | if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) |
| 480 | { |
| 481 | ASSERT(queueInfo.queueCount > 0); |
| 482 | graphicsQueueFamilyCount++; |
| 483 | if (firstGraphicsQueueFamily == 0) |
| 484 | { |
| 485 | firstGraphicsQueueFamily = familyIndex; |
| 486 | } |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 491 | ANGLE_VK_CHECK(context, graphicsQueueFamilyCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 492 | |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 493 | initFeatures(); |
| 494 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 495 | // If only one queue family, go ahead and initialize the device. If there is more than one |
| 496 | // queue, we'll have to wait until we see a WindowSurface to know which supports present. |
| 497 | if (graphicsQueueFamilyCount == 1) |
| 498 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 499 | ANGLE_TRY(initializeDevice(context, firstGraphicsQueueFamily)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Jamie Madill | 035fd6b | 2017-10-03 15:43:22 -0400 | [diff] [blame] | 502 | // Store the physical device memory properties so we can find the right memory pools. |
| 503 | mMemoryProperties.init(mPhysicalDevice); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 504 | |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 505 | GlslangWrapper::Initialize(); |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 506 | |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 507 | // Initialize the format table. |
Luc Ferron | d50537a | 2018-02-07 17:02:08 -0500 | [diff] [blame] | 508 | mFormatTable.initialize(mPhysicalDevice, &mNativeTextureCaps, |
| 509 | &mNativeCaps.compressedTextureFormats); |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 510 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 511 | return angle::Result::Continue(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 514 | angle::Result RendererVk::initializeDevice(vk::Context *context, uint32_t queueFamilyIndex) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 515 | { |
| 516 | uint32_t deviceLayerCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 517 | ANGLE_VK_TRY(context, |
| 518 | vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, nullptr)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 519 | |
| 520 | std::vector<VkLayerProperties> deviceLayerProps(deviceLayerCount); |
| 521 | if (deviceLayerCount > 0) |
| 522 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 523 | ANGLE_VK_TRY(context, vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, |
| 524 | deviceLayerProps.data())); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | uint32_t deviceExtensionCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 528 | ANGLE_VK_TRY(context, vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, |
| 529 | &deviceExtensionCount, nullptr)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 530 | |
| 531 | std::vector<VkExtensionProperties> deviceExtensionProps(deviceExtensionCount); |
| 532 | if (deviceExtensionCount > 0) |
| 533 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 534 | ANGLE_VK_TRY(context, vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, |
| 535 | &deviceExtensionCount, |
| 536 | deviceExtensionProps.data())); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 537 | } |
| 538 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 539 | const char *const *enabledLayerNames = nullptr; |
| 540 | uint32_t enabledLayerCount = 0; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 541 | if (mEnableValidationLayers) |
| 542 | { |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 543 | mEnableValidationLayers = GetAvailableValidationLayers( |
| 544 | deviceLayerProps, false, &enabledLayerNames, &enabledLayerCount); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | std::vector<const char *> enabledDeviceExtensions; |
| 548 | enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 549 | |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 550 | // Selectively enable KHR_MAINTENANCE1 to support viewport flipping. |
| 551 | if (getFeatures().flipViewportY) |
| 552 | { |
| 553 | enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME); |
| 554 | } |
| 555 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 556 | ANGLE_VK_TRY(context, VerifyExtensionsPresent(deviceExtensionProps, enabledDeviceExtensions)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 557 | |
| 558 | VkDeviceQueueCreateInfo queueCreateInfo; |
| 559 | |
| 560 | float zeroPriority = 0.0f; |
| 561 | |
| 562 | queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 563 | queueCreateInfo.pNext = nullptr; |
| 564 | queueCreateInfo.flags = 0; |
| 565 | queueCreateInfo.queueFamilyIndex = queueFamilyIndex; |
| 566 | queueCreateInfo.queueCount = 1; |
| 567 | queueCreateInfo.pQueuePriorities = &zeroPriority; |
| 568 | |
| 569 | // Initialize the device |
| 570 | VkDeviceCreateInfo createInfo; |
| 571 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame] | 572 | createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 573 | createInfo.pNext = nullptr; |
| 574 | createInfo.flags = 0; |
| 575 | createInfo.queueCreateInfoCount = 1; |
| 576 | createInfo.pQueueCreateInfos = &queueCreateInfo; |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 577 | createInfo.enabledLayerCount = enabledLayerCount; |
| 578 | createInfo.ppEnabledLayerNames = enabledLayerNames; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 579 | createInfo.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size()); |
| 580 | createInfo.ppEnabledExtensionNames = |
| 581 | enabledDeviceExtensions.empty() ? nullptr : enabledDeviceExtensions.data(); |
| 582 | createInfo.pEnabledFeatures = nullptr; // TODO(jmadill): features |
| 583 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 584 | ANGLE_VK_TRY(context, vkCreateDevice(mPhysicalDevice, &createInfo, nullptr, &mDevice)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 585 | |
| 586 | mCurrentQueueFamilyIndex = queueFamilyIndex; |
| 587 | |
| 588 | vkGetDeviceQueue(mDevice, mCurrentQueueFamilyIndex, 0, &mQueue); |
| 589 | |
| 590 | // Initialize the command pool now that we know the queue family index. |
| 591 | VkCommandPoolCreateInfo commandPoolInfo; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 592 | commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 593 | commandPoolInfo.pNext = nullptr; |
| 594 | commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 595 | commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex; |
| 596 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 597 | ANGLE_TRY(mCommandPool.init(context, commandPoolInfo)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 598 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 599 | return angle::Result::Continue(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 600 | } |
| 601 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 602 | angle::Result RendererVk::selectPresentQueueForSurface(vk::Context *context, |
| 603 | VkSurfaceKHR surface, |
| 604 | uint32_t *presentQueueOut) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 605 | { |
| 606 | // We've already initialized a device, and can't re-create it unless it's never been used. |
| 607 | // TODO(jmadill): Handle the re-creation case if necessary. |
| 608 | if (mDevice != VK_NULL_HANDLE) |
| 609 | { |
| 610 | ASSERT(mCurrentQueueFamilyIndex != std::numeric_limits<uint32_t>::max()); |
| 611 | |
| 612 | // Check if the current device supports present on this surface. |
| 613 | VkBool32 supportsPresent = VK_FALSE; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 614 | ANGLE_VK_TRY(context, |
| 615 | vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, mCurrentQueueFamilyIndex, |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 616 | surface, &supportsPresent)); |
| 617 | |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 618 | if (supportsPresent == VK_TRUE) |
| 619 | { |
| 620 | *presentQueueOut = mCurrentQueueFamilyIndex; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 621 | return angle::Result::Continue(); |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 622 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | // Find a graphics and present queue. |
| 626 | Optional<uint32_t> newPresentQueue; |
| 627 | uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size()); |
| 628 | for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex) |
| 629 | { |
| 630 | const auto &queueInfo = mQueueFamilyProperties[queueIndex]; |
| 631 | if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) |
| 632 | { |
| 633 | VkBool32 supportsPresent = VK_FALSE; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 634 | ANGLE_VK_TRY(context, vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, queueIndex, |
| 635 | surface, &supportsPresent)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 636 | |
| 637 | if (supportsPresent == VK_TRUE) |
| 638 | { |
| 639 | newPresentQueue = queueIndex; |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 645 | ANGLE_VK_CHECK(context, newPresentQueue.valid(), VK_ERROR_INITIALIZATION_FAILED); |
| 646 | ANGLE_TRY(initializeDevice(context, newPresentQueue.value())); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 647 | |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 648 | *presentQueueOut = newPresentQueue.value(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 649 | return angle::Result::Continue(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | std::string RendererVk::getVendorString() const |
| 653 | { |
Olli Etuaho | c6a0618 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 654 | return GetVendorString(mPhysicalDeviceProperties.vendorID); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 655 | } |
| 656 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 657 | std::string RendererVk::getRendererDescription() const |
| 658 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 659 | std::stringstream strstr; |
| 660 | |
| 661 | uint32_t apiVersion = mPhysicalDeviceProperties.apiVersion; |
| 662 | |
| 663 | strstr << "Vulkan "; |
| 664 | strstr << VK_VERSION_MAJOR(apiVersion) << "."; |
| 665 | strstr << VK_VERSION_MINOR(apiVersion) << "."; |
| 666 | strstr << VK_VERSION_PATCH(apiVersion); |
| 667 | |
Olli Etuaho | c6a0618 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 668 | strstr << "("; |
| 669 | |
| 670 | // In the case of NVIDIA, deviceName does not necessarily contain "NVIDIA". Add "NVIDIA" so that |
| 671 | // Vulkan end2end tests can be selectively disabled on NVIDIA. TODO(jmadill): should not be |
| 672 | // needed after http://anglebug.com/1874 is fixed and end2end_tests use more sophisticated |
| 673 | // driver detection. |
| 674 | if (mPhysicalDeviceProperties.vendorID == VENDOR_ID_NVIDIA) |
| 675 | { |
| 676 | strstr << GetVendorString(mPhysicalDeviceProperties.vendorID) << " "; |
| 677 | } |
| 678 | |
| 679 | strstr << mPhysicalDeviceProperties.deviceName << ")"; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 680 | |
| 681 | return strstr.str(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 682 | } |
| 683 | |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 684 | void RendererVk::initFeatures() |
| 685 | { |
| 686 | // Use OpenGL line rasterization rules by default. |
| 687 | mFeatures.basicGLLineRasterization = true; |
| 688 | |
Luc Ferron | f786b70 | 2018-07-10 11:01:43 -0400 | [diff] [blame] | 689 | // TODO(lucferron): Currently disabled on Intel only since many tests are failing and need |
| 690 | // investigation. http://anglebug.com/2728 |
| 691 | mFeatures.flipViewportY = !IsIntel(mPhysicalDeviceProperties.vendorID); |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 694 | void RendererVk::ensureCapsInitialized() const |
| 695 | { |
| 696 | if (!mCapsInitialized) |
| 697 | { |
Jamie Madill | 30b5d84 | 2018-08-31 17:19:12 -0400 | [diff] [blame^] | 698 | vk::GenerateCaps(mPhysicalDeviceProperties, mPhysicalDeviceFeatures, mNativeTextureCaps, |
| 699 | &mNativeCaps, &mNativeExtensions, &mNativeLimitations); |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 700 | mCapsInitialized = true; |
| 701 | } |
| 702 | } |
| 703 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 704 | const gl::Caps &RendererVk::getNativeCaps() const |
| 705 | { |
| 706 | ensureCapsInitialized(); |
| 707 | return mNativeCaps; |
| 708 | } |
| 709 | |
| 710 | const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const |
| 711 | { |
| 712 | ensureCapsInitialized(); |
| 713 | return mNativeTextureCaps; |
| 714 | } |
| 715 | |
| 716 | const gl::Extensions &RendererVk::getNativeExtensions() const |
| 717 | { |
| 718 | ensureCapsInitialized(); |
| 719 | return mNativeExtensions; |
| 720 | } |
| 721 | |
| 722 | const gl::Limitations &RendererVk::getNativeLimitations() const |
| 723 | { |
| 724 | ensureCapsInitialized(); |
| 725 | return mNativeLimitations; |
| 726 | } |
| 727 | |
Luc Ferron | daedf4d | 2018-03-16 09:28:53 -0400 | [diff] [blame] | 728 | uint32_t RendererVk::getMaxActiveTextures() |
| 729 | { |
| 730 | // TODO(lucferron): expose this limitation to GL in Context Caps |
| 731 | return std::min<uint32_t>(mPhysicalDeviceProperties.limits.maxPerStageDescriptorSamplers, |
| 732 | gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES); |
| 733 | } |
| 734 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 735 | const vk::CommandPool &RendererVk::getCommandPool() const |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 736 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 737 | return mCommandPool; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 738 | } |
| 739 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 740 | angle::Result RendererVk::finish(vk::Context *context) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 741 | { |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 742 | if (!mCommandGraph.empty()) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 743 | { |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 744 | vk::Scoped<vk::CommandBuffer> commandBatch(mDevice); |
| 745 | ANGLE_TRY(flushCommandGraph(context, &commandBatch.get())); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 746 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 747 | VkSubmitInfo submitInfo; |
| 748 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 749 | submitInfo.pNext = nullptr; |
| 750 | submitInfo.waitSemaphoreCount = 0; |
| 751 | submitInfo.pWaitSemaphores = nullptr; |
| 752 | submitInfo.pWaitDstStageMask = nullptr; |
| 753 | submitInfo.commandBufferCount = 1; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 754 | submitInfo.pCommandBuffers = commandBatch.get().ptr(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 755 | submitInfo.signalSemaphoreCount = 0; |
| 756 | submitInfo.pSignalSemaphores = nullptr; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 757 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 758 | ANGLE_TRY(submitFrame(context, submitInfo, std::move(commandBatch.get()))); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 759 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 760 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 761 | ASSERT(mQueue != VK_NULL_HANDLE); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 762 | ANGLE_VK_TRY(context, vkQueueWaitIdle(mQueue)); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 763 | freeAllInFlightResources(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 764 | return angle::Result::Continue(); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 767 | void RendererVk::freeAllInFlightResources() |
| 768 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 769 | for (CommandBatch &batch : mInFlightCommands) |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 770 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 771 | batch.fence.destroy(mDevice); |
| 772 | batch.commandPool.destroy(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 773 | } |
| 774 | mInFlightCommands.clear(); |
| 775 | |
| 776 | for (auto &garbage : mGarbage) |
| 777 | { |
Jamie Madill | e88ec8e | 2017-10-31 17:18:14 -0400 | [diff] [blame] | 778 | garbage.destroy(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 779 | } |
| 780 | mGarbage.clear(); |
| 781 | } |
| 782 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 783 | angle::Result RendererVk::checkInFlightCommands(vk::Context *context) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 784 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 785 | int finishedCount = 0; |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 786 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 787 | for (CommandBatch &batch : mInFlightCommands) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 788 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 789 | VkResult result = batch.fence.getStatus(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 790 | if (result == VK_NOT_READY) |
| 791 | break; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 792 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 793 | ANGLE_VK_TRY(context, result); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 794 | ASSERT(batch.serial > mLastCompletedQueueSerial); |
| 795 | mLastCompletedQueueSerial = batch.serial; |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 796 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 797 | batch.fence.destroy(mDevice); |
| 798 | batch.commandPool.destroy(mDevice); |
| 799 | ++finishedCount; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 800 | } |
| 801 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 802 | mInFlightCommands.erase(mInFlightCommands.begin(), mInFlightCommands.begin() + finishedCount); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 803 | |
| 804 | size_t freeIndex = 0; |
| 805 | for (; freeIndex < mGarbage.size(); ++freeIndex) |
| 806 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 807 | if (!mGarbage[freeIndex].destroyIfComplete(mDevice, mLastCompletedQueueSerial)) |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 808 | break; |
| 809 | } |
| 810 | |
| 811 | // Remove the entries from the garbage list - they should be ready to go. |
| 812 | if (freeIndex > 0) |
| 813 | { |
| 814 | mGarbage.erase(mGarbage.begin(), mGarbage.begin() + freeIndex); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 817 | return angle::Result::Continue(); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 818 | } |
| 819 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 820 | angle::Result RendererVk::submitFrame(vk::Context *context, |
| 821 | const VkSubmitInfo &submitInfo, |
| 822 | vk::CommandBuffer &&commandBuffer) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 823 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 824 | VkFenceCreateInfo fenceInfo; |
| 825 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 826 | fenceInfo.pNext = nullptr; |
| 827 | fenceInfo.flags = 0; |
| 828 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 829 | vk::Scoped<CommandBatch> scopedBatch(mDevice); |
| 830 | CommandBatch &batch = scopedBatch.get(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 831 | ANGLE_TRY(batch.fence.init(context, fenceInfo)); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 832 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 833 | ANGLE_VK_TRY(context, vkQueueSubmit(mQueue, 1, &submitInfo, batch.fence.getHandle())); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 834 | |
| 835 | // Store this command buffer in the in-flight list. |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 836 | batch.commandPool = std::move(mCommandPool); |
| 837 | batch.serial = mCurrentQueueSerial; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 838 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 839 | mInFlightCommands.emplace_back(scopedBatch.release()); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 840 | |
Omar El Sheikh | 0359b69 | 2018-07-23 17:22:00 -0600 | [diff] [blame] | 841 | // Check that mInFlightCommands isn't growing too fast |
| 842 | // If it is, wait for the queue to complete work it has alread been assigned |
| 843 | if (mInFlightCommands.size() > kInFlightCommandsLimit) |
| 844 | { |
| 845 | vkQueueWaitIdle(mQueue); |
| 846 | } |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 847 | |
| 848 | // Increment the queue serial. If this fails, we should restart ANGLE. |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 849 | // TODO(jmadill): Overflow check. |
| 850 | mCurrentQueueSerial = mQueueSerialFactory.generate(); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 851 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 852 | ANGLE_TRY(checkInFlightCommands(context)); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 853 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 854 | // Simply null out the command buffer here - it was allocated using the command pool. |
| 855 | commandBuffer.releaseHandle(); |
| 856 | |
| 857 | // Reallocate the command pool for next frame. |
| 858 | // TODO(jmadill): Consider reusing command pools. |
| 859 | VkCommandPoolCreateInfo poolInfo; |
| 860 | poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 861 | poolInfo.pNext = nullptr; |
| 862 | poolInfo.flags = 0; |
| 863 | poolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex; |
| 864 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 865 | ANGLE_TRY(mCommandPool.init(context, poolInfo)); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 866 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 867 | return angle::Result::Continue(); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 868 | } |
| 869 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 870 | Serial RendererVk::getCurrentQueueSerial() const |
| 871 | { |
| 872 | return mCurrentQueueSerial; |
| 873 | } |
| 874 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 875 | bool RendererVk::isSerialInUse(Serial serial) const |
Jamie Madill | 9776035 | 2017-11-09 13:08:29 -0500 | [diff] [blame] | 876 | { |
| 877 | return serial > mLastCompletedQueueSerial; |
| 878 | } |
| 879 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 880 | angle::Result RendererVk::getCompatibleRenderPass(vk::Context *context, |
| 881 | const vk::RenderPassDesc &desc, |
| 882 | vk::RenderPass **renderPassOut) |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 883 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 884 | return mRenderPassCache.getCompatibleRenderPass(context, mCurrentQueueSerial, desc, |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 885 | renderPassOut); |
| 886 | } |
| 887 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 888 | angle::Result RendererVk::getRenderPassWithOps(vk::Context *context, |
| 889 | const vk::RenderPassDesc &desc, |
| 890 | const vk::AttachmentOpsArray &ops, |
| 891 | vk::RenderPass **renderPassOut) |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 892 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 893 | return mRenderPassCache.getRenderPassWithOps(context, mCurrentQueueSerial, desc, ops, |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 894 | renderPassOut); |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 895 | } |
| 896 | |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 897 | vk::CommandGraph *RendererVk::getCommandGraph() |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 898 | { |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 899 | return &mCommandGraph; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 900 | } |
| 901 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 902 | angle::Result RendererVk::flushCommandGraph(vk::Context *context, vk::CommandBuffer *commandBatch) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 903 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 904 | return mCommandGraph.submitCommands(context, mCurrentQueueSerial, &mRenderPassCache, |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 905 | &mCommandPool, commandBatch); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 906 | } |
| 907 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 908 | angle::Result RendererVk::flush(vk::Context *context, |
| 909 | const vk::Semaphore &waitSemaphore, |
| 910 | const vk::Semaphore &signalSemaphore) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 911 | { |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 912 | vk::Scoped<vk::CommandBuffer> commandBatch(mDevice); |
| 913 | ANGLE_TRY(flushCommandGraph(context, &commandBatch.get())); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 914 | |
| 915 | VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
| 916 | |
| 917 | VkSubmitInfo submitInfo; |
| 918 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 919 | submitInfo.pNext = nullptr; |
| 920 | submitInfo.waitSemaphoreCount = 1; |
| 921 | submitInfo.pWaitSemaphores = waitSemaphore.ptr(); |
| 922 | submitInfo.pWaitDstStageMask = &waitStageMask; |
| 923 | submitInfo.commandBufferCount = 1; |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 924 | submitInfo.pCommandBuffers = commandBatch.get().ptr(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 925 | submitInfo.signalSemaphoreCount = 1; |
| 926 | submitInfo.pSignalSemaphores = signalSemaphore.ptr(); |
| 927 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 928 | ANGLE_TRY(submitFrame(context, submitInfo, commandBatch.release())); |
| 929 | return angle::Result::Continue(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 930 | } |
| 931 | |
Jamie Madill | 78feddc | 2018-04-27 11:45:05 -0400 | [diff] [blame] | 932 | Serial RendererVk::issueShaderSerial() |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 933 | { |
Jamie Madill | 78feddc | 2018-04-27 11:45:05 -0400 | [diff] [blame] | 934 | return mShaderSerialFactory.generate(); |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 935 | } |
| 936 | |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 937 | angle::Result RendererVk::getPipeline(vk::Context *context, |
| 938 | const vk::ShaderAndSerial &vertexShader, |
| 939 | const vk::ShaderAndSerial &fragmentShader, |
| 940 | const vk::PipelineLayout &pipelineLayout, |
| 941 | const vk::PipelineDesc &pipelineDesc, |
| 942 | const gl::AttributesMask &activeAttribLocationsMask, |
| 943 | vk::PipelineAndSerial **pipelineOut) |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 944 | { |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 945 | ASSERT(vertexShader.getSerial() == |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 946 | pipelineDesc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial); |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 947 | ASSERT(fragmentShader.getSerial() == |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 948 | pipelineDesc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial); |
| 949 | |
| 950 | // Pull in a compatible RenderPass. |
| 951 | vk::RenderPass *compatibleRenderPass = nullptr; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 952 | ANGLE_TRY( |
| 953 | getCompatibleRenderPass(context, pipelineDesc.getRenderPassDesc(), &compatibleRenderPass)); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 954 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 955 | return mPipelineCache.getPipeline(context, *compatibleRenderPass, pipelineLayout, |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 956 | activeAttribLocationsMask, vertexShader.get(), |
| 957 | fragmentShader.get(), pipelineDesc, pipelineOut); |
| 958 | } |
| 959 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 960 | angle::Result RendererVk::getDescriptorSetLayout( |
| 961 | vk::Context *context, |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 962 | const vk::DescriptorSetLayoutDesc &desc, |
| 963 | vk::BindingPointer<vk::DescriptorSetLayout> *descriptorSetLayoutOut) |
| 964 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 965 | return mDescriptorSetLayoutCache.getDescriptorSetLayout(context, desc, descriptorSetLayoutOut); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 966 | } |
| 967 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 968 | angle::Result RendererVk::getPipelineLayout( |
| 969 | vk::Context *context, |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 970 | const vk::PipelineLayoutDesc &desc, |
| 971 | const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts, |
| 972 | vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut) |
| 973 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 974 | return mPipelineLayoutCache.getPipelineLayout(context, desc, descriptorSetLayouts, |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 975 | pipelineLayoutOut); |
| 976 | } |
| 977 | |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 978 | vk::ShaderLibrary *RendererVk::getShaderLibrary() |
| 979 | { |
| 980 | return &mShaderLibrary; |
| 981 | } |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 982 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 983 | uint32_t GetUniformBufferDescriptorCount() |
| 984 | { |
| 985 | return kUniformBufferDescriptorsPerDescriptorSet; |
| 986 | } |
| 987 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 988 | } // namespace rx |