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