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