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 | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 199 | } // anonymous namespace |
| 200 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 201 | // CommandBatch implementation. |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 202 | RendererVk::CommandBatch::CommandBatch() = default; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 203 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 204 | RendererVk::CommandBatch::~CommandBatch() = default; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 205 | |
| 206 | RendererVk::CommandBatch::CommandBatch(CommandBatch &&other) |
| 207 | : commandPool(std::move(other.commandPool)), fence(std::move(other.fence)), serial(other.serial) |
| 208 | { |
| 209 | } |
| 210 | |
| 211 | RendererVk::CommandBatch &RendererVk::CommandBatch::operator=(CommandBatch &&other) |
| 212 | { |
| 213 | std::swap(commandPool, other.commandPool); |
| 214 | std::swap(fence, other.fence); |
| 215 | std::swap(serial, other.serial); |
| 216 | return *this; |
| 217 | } |
| 218 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 219 | void RendererVk::CommandBatch::destroy(VkDevice device) |
| 220 | { |
| 221 | commandPool.destroy(device); |
| 222 | fence.destroy(device); |
| 223 | } |
| 224 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 225 | // RendererVk implementation. |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 226 | RendererVk::RendererVk() |
| 227 | : mCapsInitialized(false), |
| 228 | mInstance(VK_NULL_HANDLE), |
| 229 | mEnableValidationLayers(false), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 230 | mDebugReportCallback(VK_NULL_HANDLE), |
| 231 | mPhysicalDevice(VK_NULL_HANDLE), |
| 232 | mQueue(VK_NULL_HANDLE), |
| 233 | mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()), |
| 234 | mDevice(VK_NULL_HANDLE), |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 235 | mGlslangWrapper(nullptr), |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 236 | mLastCompletedQueueSerial(mQueueSerialFactory.generate()), |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 237 | mCurrentQueueSerial(mQueueSerialFactory.generate()) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 238 | { |
| 239 | } |
| 240 | |
| 241 | RendererVk::~RendererVk() |
| 242 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 243 | if (!mInFlightCommands.empty() || !mGarbage.empty()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 244 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 245 | // TODO(jmadill): Not nice to pass nullptr here, but shouldn't be a problem. |
| 246 | vk::Error error = finish(nullptr); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 247 | if (error.isError()) |
| 248 | { |
| 249 | ERR() << "Error during VK shutdown: " << error; |
| 250 | } |
| 251 | } |
| 252 | |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 253 | mPipelineLayoutCache.destroy(mDevice); |
| 254 | mDescriptorSetLayoutCache.destroy(mDevice); |
| 255 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 256 | mRenderPassCache.destroy(mDevice); |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 257 | mPipelineCache.destroy(mDevice); |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 258 | mShaderLibrary.destroy(mDevice); |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 259 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 260 | if (mGlslangWrapper) |
| 261 | { |
| 262 | GlslangWrapper::ReleaseReference(); |
| 263 | mGlslangWrapper = nullptr; |
| 264 | } |
| 265 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 266 | if (mCommandPool.valid()) |
| 267 | { |
| 268 | mCommandPool.destroy(mDevice); |
| 269 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 270 | |
| 271 | if (mDevice) |
| 272 | { |
| 273 | vkDestroyDevice(mDevice, nullptr); |
| 274 | mDevice = VK_NULL_HANDLE; |
| 275 | } |
| 276 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 277 | if (mDebugReportCallback) |
| 278 | { |
| 279 | ASSERT(mInstance); |
| 280 | auto destroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>( |
| 281 | vkGetInstanceProcAddr(mInstance, "vkDestroyDebugReportCallbackEXT")); |
| 282 | ASSERT(destroyDebugReportCallback); |
| 283 | destroyDebugReportCallback(mInstance, mDebugReportCallback, nullptr); |
| 284 | } |
| 285 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 286 | if (mInstance) |
| 287 | { |
| 288 | vkDestroyInstance(mInstance, nullptr); |
| 289 | mInstance = VK_NULL_HANDLE; |
| 290 | } |
| 291 | |
| 292 | mPhysicalDevice = VK_NULL_HANDLE; |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 295 | void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices, |
| 296 | bool preferMockICD, |
| 297 | VkPhysicalDevice *physicalDeviceOut, |
| 298 | VkPhysicalDeviceProperties *physicalDevicePropertiesOut) |
| 299 | { |
| 300 | ASSERT(!physicalDevices.empty()); |
| 301 | if (preferMockICD) |
| 302 | { |
| 303 | for (const VkPhysicalDevice &physicalDevice : physicalDevices) |
| 304 | { |
| 305 | vkGetPhysicalDeviceProperties(physicalDevice, physicalDevicePropertiesOut); |
| 306 | if ((kMockVendorID == physicalDevicePropertiesOut->vendorID) && |
| 307 | (kMockDeviceID == physicalDevicePropertiesOut->deviceID) && |
| 308 | (strcmp(kMockDeviceName, physicalDevicePropertiesOut->deviceName) == 0)) |
| 309 | { |
| 310 | *physicalDeviceOut = physicalDevice; |
| 311 | return; |
| 312 | } |
| 313 | } |
| 314 | WARN() << "Vulkan Mock Driver was requested but Mock Device was not found. Using default " |
| 315 | "physicalDevice instead."; |
| 316 | } |
| 317 | |
| 318 | // Fall back to first device. |
| 319 | *physicalDeviceOut = physicalDevices[0]; |
| 320 | vkGetPhysicalDeviceProperties(*physicalDeviceOut, physicalDevicePropertiesOut); |
| 321 | } |
| 322 | |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 323 | vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName) |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 324 | { |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 325 | ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs), |
| 326 | ShouldEnableMockICD(attribs)); |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 327 | mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers(); |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 328 | bool enableMockICD = scopedEnvironment.canEnableMockICD(); |
Jamie Madill | a66779f | 2017-01-06 10:43:44 -0500 | [diff] [blame] | 329 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 330 | // Gather global layer properties. |
| 331 | uint32_t instanceLayerCount = 0; |
| 332 | ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); |
| 333 | |
| 334 | std::vector<VkLayerProperties> instanceLayerProps(instanceLayerCount); |
| 335 | if (instanceLayerCount > 0) |
| 336 | { |
| 337 | ANGLE_VK_TRY( |
| 338 | vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProps.data())); |
| 339 | } |
| 340 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 341 | uint32_t instanceExtensionCount = 0; |
| 342 | ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr)); |
| 343 | |
| 344 | std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount); |
| 345 | if (instanceExtensionCount > 0) |
| 346 | { |
| 347 | ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, |
| 348 | instanceExtensionProps.data())); |
| 349 | } |
| 350 | |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 351 | const char *const *enabledLayerNames = nullptr; |
| 352 | uint32_t enabledLayerCount = 0; |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 353 | if (mEnableValidationLayers) |
| 354 | { |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 355 | bool layersRequested = |
| 356 | (attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE) == EGL_TRUE); |
| 357 | mEnableValidationLayers = GetAvailableValidationLayers( |
| 358 | instanceLayerProps, layersRequested, &enabledLayerNames, &enabledLayerCount); |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 361 | std::vector<const char *> enabledInstanceExtensions; |
| 362 | enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 363 | enabledInstanceExtensions.push_back(wsiName); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 364 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 365 | // TODO(jmadill): Should be able to continue initialization if debug report ext missing. |
| 366 | if (mEnableValidationLayers) |
| 367 | { |
| 368 | enabledInstanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
| 369 | } |
| 370 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 371 | // Verify the required extensions are in the extension names set. Fail if not. |
| 372 | ANGLE_VK_TRY(VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions)); |
| 373 | |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 374 | VkApplicationInfo applicationInfo; |
| 375 | applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 376 | applicationInfo.pNext = nullptr; |
| 377 | applicationInfo.pApplicationName = "ANGLE"; |
| 378 | applicationInfo.applicationVersion = 1; |
| 379 | applicationInfo.pEngineName = "ANGLE"; |
| 380 | applicationInfo.engineVersion = 1; |
| 381 | applicationInfo.apiVersion = VK_API_VERSION_1_0; |
| 382 | |
| 383 | VkInstanceCreateInfo instanceInfo; |
| 384 | instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
| 385 | instanceInfo.pNext = nullptr; |
| 386 | instanceInfo.flags = 0; |
| 387 | instanceInfo.pApplicationInfo = &applicationInfo; |
| 388 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 389 | // Enable requested layers and extensions. |
| 390 | instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size()); |
| 391 | instanceInfo.ppEnabledExtensionNames = |
| 392 | enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data(); |
Yuly Novikov | 199f429 | 2018-01-19 19:04:05 -0500 | [diff] [blame] | 393 | instanceInfo.enabledLayerCount = enabledLayerCount; |
| 394 | instanceInfo.ppEnabledLayerNames = enabledLayerNames; |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 395 | |
| 396 | ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance)); |
| 397 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 398 | if (mEnableValidationLayers) |
| 399 | { |
| 400 | VkDebugReportCallbackCreateInfoEXT debugReportInfo; |
| 401 | |
| 402 | debugReportInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; |
| 403 | debugReportInfo.pNext = nullptr; |
| 404 | debugReportInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | |
| 405 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
| 406 | VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
| 407 | debugReportInfo.pfnCallback = &DebugReportCallback; |
| 408 | debugReportInfo.pUserData = this; |
| 409 | |
| 410 | auto createDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>( |
| 411 | vkGetInstanceProcAddr(mInstance, "vkCreateDebugReportCallbackEXT")); |
| 412 | ASSERT(createDebugReportCallback); |
| 413 | ANGLE_VK_TRY( |
| 414 | createDebugReportCallback(mInstance, &debugReportInfo, nullptr, &mDebugReportCallback)); |
| 415 | } |
| 416 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 417 | uint32_t physicalDeviceCount = 0; |
| 418 | ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, nullptr)); |
| 419 | ANGLE_VK_CHECK(physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
| 420 | |
| 421 | // TODO(jmadill): Handle multiple physical devices. For now, use the first device. |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 422 | std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount); |
| 423 | ANGLE_VK_TRY( |
| 424 | vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data())); |
Omar El Sheikh | 26c61b2 | 2018-06-29 12:50:59 -0600 | [diff] [blame] | 425 | ChoosePhysicalDevice(physicalDevices, enableMockICD, &mPhysicalDevice, |
Tobin Ehlis | a3b220f | 2018-03-06 16:22:13 -0700 | [diff] [blame] | 426 | &mPhysicalDeviceProperties); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 427 | |
| 428 | // Ensure we can find a graphics queue family. |
| 429 | uint32_t queueCount = 0; |
| 430 | vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr); |
| 431 | |
| 432 | ANGLE_VK_CHECK(queueCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
| 433 | |
| 434 | mQueueFamilyProperties.resize(queueCount); |
| 435 | vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, |
| 436 | mQueueFamilyProperties.data()); |
| 437 | |
| 438 | size_t graphicsQueueFamilyCount = false; |
| 439 | uint32_t firstGraphicsQueueFamily = 0; |
| 440 | for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex) |
| 441 | { |
| 442 | const auto &queueInfo = mQueueFamilyProperties[familyIndex]; |
| 443 | if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) |
| 444 | { |
| 445 | ASSERT(queueInfo.queueCount > 0); |
| 446 | graphicsQueueFamilyCount++; |
| 447 | if (firstGraphicsQueueFamily == 0) |
| 448 | { |
| 449 | firstGraphicsQueueFamily = familyIndex; |
| 450 | } |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | ANGLE_VK_CHECK(graphicsQueueFamilyCount > 0, VK_ERROR_INITIALIZATION_FAILED); |
| 456 | |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 457 | initFeatures(); |
| 458 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 459 | // If only one queue family, go ahead and initialize the device. If there is more than one |
| 460 | // queue, we'll have to wait until we see a WindowSurface to know which supports present. |
| 461 | if (graphicsQueueFamilyCount == 1) |
| 462 | { |
| 463 | ANGLE_TRY(initializeDevice(firstGraphicsQueueFamily)); |
| 464 | } |
| 465 | |
Jamie Madill | 035fd6b | 2017-10-03 15:43:22 -0400 | [diff] [blame] | 466 | // Store the physical device memory properties so we can find the right memory pools. |
| 467 | mMemoryProperties.init(mPhysicalDevice); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 468 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 469 | mGlslangWrapper = GlslangWrapper::GetReference(); |
| 470 | |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 471 | // Initialize the format table. |
Luc Ferron | d50537a | 2018-02-07 17:02:08 -0500 | [diff] [blame] | 472 | mFormatTable.initialize(mPhysicalDevice, &mNativeTextureCaps, |
| 473 | &mNativeCaps.compressedTextureFormats); |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 474 | |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 475 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 478 | vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex) |
| 479 | { |
| 480 | uint32_t deviceLayerCount = 0; |
| 481 | ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, nullptr)); |
| 482 | |
| 483 | std::vector<VkLayerProperties> deviceLayerProps(deviceLayerCount); |
| 484 | if (deviceLayerCount > 0) |
| 485 | { |
| 486 | ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, |
| 487 | deviceLayerProps.data())); |
| 488 | } |
| 489 | |
| 490 | uint32_t deviceExtensionCount = 0; |
| 491 | ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, |
| 492 | &deviceExtensionCount, nullptr)); |
| 493 | |
| 494 | std::vector<VkExtensionProperties> deviceExtensionProps(deviceExtensionCount); |
| 495 | if (deviceExtensionCount > 0) |
| 496 | { |
| 497 | ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties( |
| 498 | mPhysicalDevice, nullptr, &deviceExtensionCount, deviceExtensionProps.data())); |
| 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 | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 518 | ANGLE_VK_TRY(VerifyExtensionsPresent(deviceExtensionProps, enabledDeviceExtensions)); |
| 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 | |
| 546 | ANGLE_VK_TRY(vkCreateDevice(mPhysicalDevice, &createInfo, nullptr, &mDevice)); |
| 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 | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 559 | ANGLE_TRY(mCommandPool.init(mDevice, commandPoolInfo)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 560 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 561 | return vk::NoError(); |
| 562 | } |
| 563 | |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 564 | vk::Error RendererVk::selectPresentQueueForSurface(VkSurfaceKHR surface, uint32_t *presentQueueOut) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 565 | { |
| 566 | // We've already initialized a device, and can't re-create it unless it's never been used. |
| 567 | // TODO(jmadill): Handle the re-creation case if necessary. |
| 568 | if (mDevice != VK_NULL_HANDLE) |
| 569 | { |
| 570 | ASSERT(mCurrentQueueFamilyIndex != std::numeric_limits<uint32_t>::max()); |
| 571 | |
| 572 | // Check if the current device supports present on this surface. |
| 573 | VkBool32 supportsPresent = VK_FALSE; |
| 574 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, mCurrentQueueFamilyIndex, |
| 575 | surface, &supportsPresent)); |
| 576 | |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 577 | if (supportsPresent == VK_TRUE) |
| 578 | { |
| 579 | *presentQueueOut = mCurrentQueueFamilyIndex; |
| 580 | return vk::NoError(); |
| 581 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // Find a graphics and present queue. |
| 585 | Optional<uint32_t> newPresentQueue; |
| 586 | uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size()); |
| 587 | for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex) |
| 588 | { |
| 589 | const auto &queueInfo = mQueueFamilyProperties[queueIndex]; |
| 590 | if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) |
| 591 | { |
| 592 | VkBool32 supportsPresent = VK_FALSE; |
| 593 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, queueIndex, surface, |
| 594 | &supportsPresent)); |
| 595 | |
| 596 | if (supportsPresent == VK_TRUE) |
| 597 | { |
| 598 | newPresentQueue = queueIndex; |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | ANGLE_VK_CHECK(newPresentQueue.valid(), VK_ERROR_INITIALIZATION_FAILED); |
| 605 | ANGLE_TRY(initializeDevice(newPresentQueue.value())); |
| 606 | |
Jamie Madill | 6cad773 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 607 | *presentQueueOut = newPresentQueue.value(); |
| 608 | return vk::NoError(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | std::string RendererVk::getVendorString() const |
| 612 | { |
Olli Etuaho | c6a0618 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 613 | return GetVendorString(mPhysicalDeviceProperties.vendorID); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 614 | } |
| 615 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 616 | std::string RendererVk::getRendererDescription() const |
| 617 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 618 | std::stringstream strstr; |
| 619 | |
| 620 | uint32_t apiVersion = mPhysicalDeviceProperties.apiVersion; |
| 621 | |
| 622 | strstr << "Vulkan "; |
| 623 | strstr << VK_VERSION_MAJOR(apiVersion) << "."; |
| 624 | strstr << VK_VERSION_MINOR(apiVersion) << "."; |
| 625 | strstr << VK_VERSION_PATCH(apiVersion); |
| 626 | |
Olli Etuaho | c6a0618 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 627 | strstr << "("; |
| 628 | |
| 629 | // In the case of NVIDIA, deviceName does not necessarily contain "NVIDIA". Add "NVIDIA" so that |
| 630 | // Vulkan end2end tests can be selectively disabled on NVIDIA. TODO(jmadill): should not be |
| 631 | // needed after http://anglebug.com/1874 is fixed and end2end_tests use more sophisticated |
| 632 | // driver detection. |
| 633 | if (mPhysicalDeviceProperties.vendorID == VENDOR_ID_NVIDIA) |
| 634 | { |
| 635 | strstr << GetVendorString(mPhysicalDeviceProperties.vendorID) << " "; |
| 636 | } |
| 637 | |
| 638 | strstr << mPhysicalDeviceProperties.deviceName << ")"; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 639 | |
| 640 | return strstr.str(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 643 | void RendererVk::initFeatures() |
| 644 | { |
| 645 | // Use OpenGL line rasterization rules by default. |
| 646 | mFeatures.basicGLLineRasterization = true; |
| 647 | |
| 648 | // For now, set this manually to true to enable viewport flipping. A couple of features are not |
| 649 | // working well like copyTexImage, copySubTexImage, blit, and probably some more. Until |
| 650 | // everything is fixed, we will keep the viewport flipping feature disabled. |
| 651 | mFeatures.flipViewportY = false; |
| 652 | } |
| 653 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 654 | void RendererVk::ensureCapsInitialized() const |
| 655 | { |
| 656 | if (!mCapsInitialized) |
| 657 | { |
Luc Ferron | d50537a | 2018-02-07 17:02:08 -0500 | [diff] [blame] | 658 | vk::GenerateCaps(mPhysicalDeviceProperties, mNativeTextureCaps, &mNativeCaps, |
Jamie Madill | 1222207 | 2018-07-11 14:59:48 -0400 | [diff] [blame] | 659 | &mNativeExtensions, &mNativeLimitations); |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 660 | mCapsInitialized = true; |
| 661 | } |
| 662 | } |
| 663 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 664 | const gl::Caps &RendererVk::getNativeCaps() const |
| 665 | { |
| 666 | ensureCapsInitialized(); |
| 667 | return mNativeCaps; |
| 668 | } |
| 669 | |
| 670 | const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const |
| 671 | { |
| 672 | ensureCapsInitialized(); |
| 673 | return mNativeTextureCaps; |
| 674 | } |
| 675 | |
| 676 | const gl::Extensions &RendererVk::getNativeExtensions() const |
| 677 | { |
| 678 | ensureCapsInitialized(); |
| 679 | return mNativeExtensions; |
| 680 | } |
| 681 | |
| 682 | const gl::Limitations &RendererVk::getNativeLimitations() const |
| 683 | { |
| 684 | ensureCapsInitialized(); |
| 685 | return mNativeLimitations; |
| 686 | } |
| 687 | |
Luc Ferron | daedf4d | 2018-03-16 09:28:53 -0400 | [diff] [blame] | 688 | uint32_t RendererVk::getMaxActiveTextures() |
| 689 | { |
| 690 | // TODO(lucferron): expose this limitation to GL in Context Caps |
| 691 | return std::min<uint32_t>(mPhysicalDeviceProperties.limits.maxPerStageDescriptorSamplers, |
| 692 | gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES); |
| 693 | } |
| 694 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 695 | const vk::CommandPool &RendererVk::getCommandPool() const |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 696 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 697 | return mCommandPool; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 698 | } |
| 699 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 700 | vk::Error RendererVk::finish(const gl::Context *context) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 701 | { |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 702 | if (!mCommandGraph.empty()) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 703 | { |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame^] | 704 | vk::Scoped<vk::CommandBuffer> commandBatch(mDevice); |
| 705 | ANGLE_TRY(flushCommandGraph(context, &commandBatch.get())); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 706 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 707 | VkSubmitInfo submitInfo; |
| 708 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 709 | submitInfo.pNext = nullptr; |
| 710 | submitInfo.waitSemaphoreCount = 0; |
| 711 | submitInfo.pWaitSemaphores = nullptr; |
| 712 | submitInfo.pWaitDstStageMask = nullptr; |
| 713 | submitInfo.commandBufferCount = 1; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame^] | 714 | submitInfo.pCommandBuffers = commandBatch.get().ptr(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 715 | submitInfo.signalSemaphoreCount = 0; |
| 716 | submitInfo.pSignalSemaphores = nullptr; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 717 | |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame^] | 718 | ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch.get()))); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 719 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 720 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 721 | ASSERT(mQueue != VK_NULL_HANDLE); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 722 | ANGLE_VK_TRY(vkQueueWaitIdle(mQueue)); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 723 | freeAllInFlightResources(); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 724 | return vk::NoError(); |
| 725 | } |
| 726 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 727 | void RendererVk::freeAllInFlightResources() |
| 728 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 729 | for (CommandBatch &batch : mInFlightCommands) |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 730 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 731 | batch.fence.destroy(mDevice); |
| 732 | batch.commandPool.destroy(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 733 | } |
| 734 | mInFlightCommands.clear(); |
| 735 | |
| 736 | for (auto &garbage : mGarbage) |
| 737 | { |
Jamie Madill | e88ec8e | 2017-10-31 17:18:14 -0400 | [diff] [blame] | 738 | garbage.destroy(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 739 | } |
| 740 | mGarbage.clear(); |
| 741 | } |
| 742 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 743 | vk::Error RendererVk::checkInFlightCommands() |
| 744 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 745 | int finishedCount = 0; |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 746 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 747 | for (CommandBatch &batch : mInFlightCommands) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 748 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 749 | VkResult result = batch.fence.getStatus(mDevice); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 750 | if (result == VK_NOT_READY) |
| 751 | break; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 752 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 753 | ANGLE_VK_TRY(result); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 754 | ASSERT(batch.serial > mLastCompletedQueueSerial); |
| 755 | mLastCompletedQueueSerial = batch.serial; |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 756 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 757 | batch.fence.destroy(mDevice); |
| 758 | batch.commandPool.destroy(mDevice); |
| 759 | ++finishedCount; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 760 | } |
| 761 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 762 | mInFlightCommands.erase(mInFlightCommands.begin(), mInFlightCommands.begin() + finishedCount); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 763 | |
| 764 | size_t freeIndex = 0; |
| 765 | for (; freeIndex < mGarbage.size(); ++freeIndex) |
| 766 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 767 | if (!mGarbage[freeIndex].destroyIfComplete(mDevice, mLastCompletedQueueSerial)) |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 768 | break; |
| 769 | } |
| 770 | |
| 771 | // Remove the entries from the garbage list - they should be ready to go. |
| 772 | if (freeIndex > 0) |
| 773 | { |
| 774 | mGarbage.erase(mGarbage.begin(), mGarbage.begin() + freeIndex); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 775 | } |
| 776 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 777 | return vk::NoError(); |
| 778 | } |
| 779 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 780 | vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo, vk::CommandBuffer &&commandBuffer) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 781 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 782 | VkFenceCreateInfo fenceInfo; |
| 783 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 784 | fenceInfo.pNext = nullptr; |
| 785 | fenceInfo.flags = 0; |
| 786 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 787 | vk::Scoped<CommandBatch> scopedBatch(mDevice); |
| 788 | CommandBatch &batch = scopedBatch.get(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 789 | ANGLE_TRY(batch.fence.init(mDevice, fenceInfo)); |
| 790 | |
| 791 | ANGLE_VK_TRY(vkQueueSubmit(mQueue, 1, &submitInfo, batch.fence.getHandle())); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 792 | |
| 793 | // Store this command buffer in the in-flight list. |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 794 | batch.commandPool = std::move(mCommandPool); |
| 795 | batch.serial = mCurrentQueueSerial; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 796 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 797 | mInFlightCommands.emplace_back(scopedBatch.release()); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 798 | |
| 799 | // Sanity check. |
| 800 | ASSERT(mInFlightCommands.size() < 1000u); |
| 801 | |
| 802 | // Increment the queue serial. If this fails, we should restart ANGLE. |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 803 | // TODO(jmadill): Overflow check. |
| 804 | mCurrentQueueSerial = mQueueSerialFactory.generate(); |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 805 | |
| 806 | ANGLE_TRY(checkInFlightCommands()); |
| 807 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 808 | // Simply null out the command buffer here - it was allocated using the command pool. |
| 809 | commandBuffer.releaseHandle(); |
| 810 | |
| 811 | // Reallocate the command pool for next frame. |
| 812 | // TODO(jmadill): Consider reusing command pools. |
| 813 | VkCommandPoolCreateInfo poolInfo; |
| 814 | poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 815 | poolInfo.pNext = nullptr; |
| 816 | poolInfo.flags = 0; |
| 817 | poolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex; |
| 818 | |
Jamie Madill | eebe219 | 2018-07-11 09:01:18 -0400 | [diff] [blame] | 819 | ANGLE_TRY(mCommandPool.init(mDevice, poolInfo)); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 820 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 821 | return vk::NoError(); |
| 822 | } |
| 823 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 824 | GlslangWrapper *RendererVk::getGlslangWrapper() const |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 825 | { |
| 826 | return mGlslangWrapper; |
| 827 | } |
| 828 | |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 829 | Serial RendererVk::getCurrentQueueSerial() const |
| 830 | { |
| 831 | return mCurrentQueueSerial; |
| 832 | } |
| 833 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 834 | bool RendererVk::isSerialInUse(Serial serial) const |
Jamie Madill | 9776035 | 2017-11-09 13:08:29 -0500 | [diff] [blame] | 835 | { |
| 836 | return serial > mLastCompletedQueueSerial; |
| 837 | } |
| 838 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 839 | vk::Error RendererVk::getCompatibleRenderPass(const vk::RenderPassDesc &desc, |
| 840 | vk::RenderPass **renderPassOut) |
| 841 | { |
| 842 | return mRenderPassCache.getCompatibleRenderPass(mDevice, mCurrentQueueSerial, desc, |
| 843 | renderPassOut); |
| 844 | } |
| 845 | |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 846 | vk::Error RendererVk::getRenderPassWithOps(const vk::RenderPassDesc &desc, |
| 847 | const vk::AttachmentOpsArray &ops, |
| 848 | vk::RenderPass **renderPassOut) |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 849 | { |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 850 | return mRenderPassCache.getRenderPassWithOps(mDevice, mCurrentQueueSerial, desc, ops, |
| 851 | renderPassOut); |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 852 | } |
| 853 | |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 854 | vk::CommandGraph *RendererVk::getCommandGraph() |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 855 | { |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 856 | return &mCommandGraph; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | vk::Error RendererVk::flushCommandGraph(const gl::Context *context, vk::CommandBuffer *commandBatch) |
| 860 | { |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 861 | return mCommandGraph.submitCommands(mDevice, mCurrentQueueSerial, &mRenderPassCache, |
| 862 | &mCommandPool, commandBatch); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | vk::Error RendererVk::flush(const gl::Context *context, |
| 866 | const vk::Semaphore &waitSemaphore, |
| 867 | const vk::Semaphore &signalSemaphore) |
| 868 | { |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 869 | vk::Scoped<vk::CommandBuffer> commandBatch(mDevice); |
| 870 | ANGLE_TRY(flushCommandGraph(context, &commandBatch.get())); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 871 | |
| 872 | VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
| 873 | |
| 874 | VkSubmitInfo submitInfo; |
| 875 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 876 | submitInfo.pNext = nullptr; |
| 877 | submitInfo.waitSemaphoreCount = 1; |
| 878 | submitInfo.pWaitSemaphores = waitSemaphore.ptr(); |
| 879 | submitInfo.pWaitDstStageMask = &waitStageMask; |
| 880 | submitInfo.commandBufferCount = 1; |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 881 | submitInfo.pCommandBuffers = commandBatch.get().ptr(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 882 | submitInfo.signalSemaphoreCount = 1; |
| 883 | submitInfo.pSignalSemaphores = signalSemaphore.ptr(); |
| 884 | |
Jamie Madill | bea35a6 | 2018-07-05 11:54:10 -0400 | [diff] [blame] | 885 | ANGLE_TRY(submitFrame(submitInfo, commandBatch.release())); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 886 | return vk::NoError(); |
| 887 | } |
| 888 | |
Jamie Madill | 78feddc | 2018-04-27 11:45:05 -0400 | [diff] [blame] | 889 | Serial RendererVk::issueShaderSerial() |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 890 | { |
Jamie Madill | 78feddc | 2018-04-27 11:45:05 -0400 | [diff] [blame] | 891 | return mShaderSerialFactory.generate(); |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 892 | } |
| 893 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 894 | vk::Error RendererVk::getAppPipeline(const ProgramVk *programVk, |
| 895 | const vk::PipelineDesc &desc, |
| 896 | const gl::AttributesMask &activeAttribLocationsMask, |
| 897 | vk::PipelineAndSerial **pipelineOut) |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 898 | { |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 899 | ASSERT(programVk->getVertexModuleSerial() == |
| 900 | desc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial); |
| 901 | ASSERT(programVk->getFragmentModuleSerial() == |
| 902 | desc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial); |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 903 | |
| 904 | // Pull in a compatible RenderPass. |
| 905 | vk::RenderPass *compatibleRenderPass = nullptr; |
| 906 | ANGLE_TRY(getCompatibleRenderPass(desc.getRenderPassDesc(), &compatibleRenderPass)); |
| 907 | |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 908 | const vk::PipelineLayout &pipelineLayout = programVk->getPipelineLayout(); |
| 909 | |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 910 | return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout, |
Luc Ferron | ceb7190 | 2018-02-05 15:18:47 -0500 | [diff] [blame] | 911 | activeAttribLocationsMask, programVk->getLinkedVertexModule(), |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 912 | programVk->getLinkedFragmentModule(), desc, pipelineOut); |
| 913 | } |
| 914 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 915 | vk::Error RendererVk::getInternalPipeline(const vk::ShaderAndSerial &vertexShader, |
| 916 | const vk::ShaderAndSerial &fragmentShader, |
| 917 | const vk::PipelineLayout &pipelineLayout, |
| 918 | const vk::PipelineDesc &pipelineDesc, |
| 919 | const gl::AttributesMask &activeAttribLocationsMask, |
| 920 | vk::PipelineAndSerial **pipelineOut) |
| 921 | { |
| 922 | ASSERT(vertexShader.queueSerial() == |
| 923 | pipelineDesc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial); |
| 924 | ASSERT(fragmentShader.queueSerial() == |
| 925 | pipelineDesc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial); |
| 926 | |
| 927 | // Pull in a compatible RenderPass. |
| 928 | vk::RenderPass *compatibleRenderPass = nullptr; |
| 929 | ANGLE_TRY(getCompatibleRenderPass(pipelineDesc.getRenderPassDesc(), &compatibleRenderPass)); |
| 930 | |
| 931 | return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout, |
| 932 | activeAttribLocationsMask, vertexShader.get(), |
| 933 | fragmentShader.get(), pipelineDesc, pipelineOut); |
| 934 | } |
| 935 | |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 936 | vk::Error RendererVk::getDescriptorSetLayout( |
| 937 | const vk::DescriptorSetLayoutDesc &desc, |
| 938 | vk::BindingPointer<vk::DescriptorSetLayout> *descriptorSetLayoutOut) |
| 939 | { |
| 940 | return mDescriptorSetLayoutCache.getDescriptorSetLayout(mDevice, desc, descriptorSetLayoutOut); |
| 941 | } |
| 942 | |
| 943 | vk::Error RendererVk::getPipelineLayout( |
| 944 | const vk::PipelineLayoutDesc &desc, |
| 945 | const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts, |
| 946 | vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut) |
| 947 | { |
| 948 | return mPipelineLayoutCache.getPipelineLayout(mDevice, desc, descriptorSetLayouts, |
| 949 | pipelineLayoutOut); |
| 950 | } |
| 951 | |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 952 | vk::ShaderLibrary *RendererVk::getShaderLibrary() |
| 953 | { |
| 954 | return &mShaderLibrary; |
| 955 | } |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 956 | |
Jamie Madill | aaca96e | 2018-06-12 10:19:48 -0400 | [diff] [blame] | 957 | uint32_t GetUniformBufferDescriptorCount() |
| 958 | { |
| 959 | return kUniformBufferDescriptorsPerDescriptorSet; |
| 960 | } |
| 961 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 962 | } // namespace rx |