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