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