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