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