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