blob: 0a54c6cb0daf881c58410d25967ac2657207a590 [file] [log] [blame]
Jamie Madill9e54b5a2016-05-25 12:57:39 -04001//
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 Madill4d0bf552016-12-28 15:45:24 -050012// Placing this first seems to solve an intellisense bug.
Jamie Madill3c424b42018-01-19 12:35:09 -050013#include "libANGLE/renderer/vulkan/vk_utils.h"
Jamie Madill4d0bf552016-12-28 15:45:24 -050014
Jamie Madille09bd5d2016-11-29 16:20:35 -050015#include <EGL/eglext.h>
16
Jamie Madill9e54b5a2016-05-25 12:57:39 -040017#include "common/debug.h"
Jamie Madilla66779f2017-01-06 10:43:44 -050018#include "common/system_utils.h"
Jamie Madill4d0bf552016-12-28 15:45:24 -050019#include "libANGLE/renderer/driver_utils.h"
Jamie Madill1f46bc12018-02-20 16:09:43 -050020#include "libANGLE/renderer/vulkan/CommandGraph.h"
Jamie Madille09bd5d2016-11-29 16:20:35 -050021#include "libANGLE/renderer/vulkan/CompilerVk.h"
22#include "libANGLE/renderer/vulkan/FramebufferVk.h"
Jamie Madill8ecf7f92017-01-13 17:29:52 -050023#include "libANGLE/renderer/vulkan/GlslangWrapper.h"
Jamie Madillffa4cbb2018-01-23 13:04:07 -050024#include "libANGLE/renderer/vulkan/ProgramVk.h"
Jamie Madille09bd5d2016-11-29 16:20:35 -050025#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
Luc Ferrone4741fd2018-01-25 13:25:27 -050026#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
Jamie Madill3c424b42018-01-19 12:35:09 -050027#include "libANGLE/renderer/vulkan/vk_format_utils.h"
Jamie Madille09bd5d2016-11-29 16:20:35 -050028#include "platform/Platform.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040029
Tobin Ehlisa3b220f2018-03-06 16:22:13 -070030// Consts
31namespace
32{
33const uint32_t kMockVendorID = 0xba5eba11;
34const uint32_t kMockDeviceID = 0xf005ba11;
35constexpr char kMockDeviceName[] = "Vulkan Mock Device";
36} // anonymous namespace
37
Jamie Madill9e54b5a2016-05-25 12:57:39 -040038namespace rx
39{
40
Jamie Madille09bd5d2016-11-29 16:20:35 -050041namespace
42{
Luc Ferrondaedf4d2018-03-16 09:28:53 -040043// We currently only allocate 2 uniform buffer per descriptor set, one for the fragment shader and
44// one for the vertex shader.
45constexpr size_t kUniformBufferDescriptorsPerDescriptorSet = 2;
Jamie Madille09bd5d2016-11-29 16:20:35 -050046
47VkResult 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 Madillacf2f3a2017-11-21 19:22:44 -050057 for (const char *extensionName : enabledExtensionNames)
Jamie Madille09bd5d2016-11-29 16:20:35 -050058 {
59 if (extensionNames.count(extensionName) == 0)
60 {
61 return VK_ERROR_EXTENSION_NOT_PRESENT;
62 }
63 }
64
65 return VK_SUCCESS;
66}
67
Yuly Novikov199f4292018-01-19 19:04:05 -050068VKAPI_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 Madill0448ec82016-12-23 13:41:47 -050076{
77 if ((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) != 0)
78 {
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -050079 ERR() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050080#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 Novikovbcb3f9b2017-01-27 22:45:18 -050087 WARN() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050088 }
89 else
90 {
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -050091 // Uncomment this if you want Vulkan spam.
92 // WARN() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050093 }
94
95 return VK_FALSE;
96}
97
Yuly Novikov199f4292018-01-19 19:04:05 -050098// 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.
101class ScopedVkLoaderEnvironment : angle::NonCopyable
102{
103 public:
Jamie Madillaaca96e2018-06-12 10:19:48 -0400104 explicit ScopedVkLoaderEnvironment(bool enableValidationLayers)
Yuly Novikov199f4292018-01-19 19:04:05 -0500105 : 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 Ehlisa3b220f2018-03-06 16:22:13 -0700135 if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_DATA_DIR))
Yuly Novikov199f4292018-01-19 19:04:05 -0500136 {
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 Madillaaca96e2018-06-12 10:19:48 -0400155 bool canEnableValidationLayers() const { return mEnableValidationLayers; }
Yuly Novikov199f4292018-01-19 19:04:05 -0500156
157 private:
158 bool mEnableValidationLayers;
159 bool mChangedCWD;
160 Optional<std::string> mPreviousCWD;
161};
162
Jamie Madille09bd5d2016-11-29 16:20:35 -0500163} // anonymous namespace
164
Jamie Madill49ac74b2017-12-21 14:42:33 -0500165// CommandBatch implementation.
Jamie Madillaaca96e2018-06-12 10:19:48 -0400166RendererVk::CommandBatch::CommandBatch() = default;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500167
Jamie Madillaaca96e2018-06-12 10:19:48 -0400168RendererVk::CommandBatch::~CommandBatch() = default;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500169
170RendererVk::CommandBatch::CommandBatch(CommandBatch &&other)
171 : commandPool(std::move(other.commandPool)), fence(std::move(other.fence)), serial(other.serial)
172{
173}
174
175RendererVk::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 Madill9f2a8612017-11-30 12:43:09 -0500183// RendererVk implementation.
Jamie Madill0448ec82016-12-23 13:41:47 -0500184RendererVk::RendererVk()
185 : mCapsInitialized(false),
186 mInstance(VK_NULL_HANDLE),
187 mEnableValidationLayers(false),
Jamie Madill4d0bf552016-12-28 15:45:24 -0500188 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 Madill4c26fc22017-02-24 11:04:10 -0500193 mGlslangWrapper(nullptr),
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400194 mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
Jamie Madillaaca96e2018-06-12 10:19:48 -0400195 mCurrentQueueSerial(mQueueSerialFactory.generate())
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400196{
197}
198
199RendererVk::~RendererVk()
200{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500201 if (!mInFlightCommands.empty() || !mGarbage.empty())
Jamie Madill4c26fc22017-02-24 11:04:10 -0500202 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500203 // TODO(jmadill): Not nice to pass nullptr here, but shouldn't be a problem.
204 vk::Error error = finish(nullptr);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500205 if (error.isError())
206 {
207 ERR() << "Error during VK shutdown: " << error;
208 }
209 }
210
Jamie Madillc7918ce2018-06-13 13:25:31 -0400211 mPipelineLayoutCache.destroy(mDevice);
212 mDescriptorSetLayoutCache.destroy(mDevice);
213
Jamie Madill9f2a8612017-11-30 12:43:09 -0500214 mRenderPassCache.destroy(mDevice);
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500215 mPipelineCache.destroy(mDevice);
Jamie Madilld47044a2018-04-27 11:45:03 -0400216 mShaderLibrary.destroy(mDevice);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500217
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500218 if (mGlslangWrapper)
219 {
220 GlslangWrapper::ReleaseReference();
221 mGlslangWrapper = nullptr;
222 }
223
Jamie Madill5deea722017-02-16 10:44:46 -0500224 if (mCommandPool.valid())
225 {
226 mCommandPool.destroy(mDevice);
227 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500228
229 if (mDevice)
230 {
231 vkDestroyDevice(mDevice, nullptr);
232 mDevice = VK_NULL_HANDLE;
233 }
234
Jamie Madill0448ec82016-12-23 13:41:47 -0500235 if (mDebugReportCallback)
236 {
237 ASSERT(mInstance);
238 auto destroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
239 vkGetInstanceProcAddr(mInstance, "vkDestroyDebugReportCallbackEXT"));
240 ASSERT(destroyDebugReportCallback);
241 destroyDebugReportCallback(mInstance, mDebugReportCallback, nullptr);
242 }
243
Jamie Madill4d0bf552016-12-28 15:45:24 -0500244 if (mInstance)
245 {
246 vkDestroyInstance(mInstance, nullptr);
247 mInstance = VK_NULL_HANDLE;
248 }
249
250 mPhysicalDevice = VK_NULL_HANDLE;
Jamie Madill327ba852016-11-30 12:38:28 -0500251}
252
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700253void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices,
254 bool preferMockICD,
255 VkPhysicalDevice *physicalDeviceOut,
256 VkPhysicalDeviceProperties *physicalDevicePropertiesOut)
257{
258 ASSERT(!physicalDevices.empty());
259 if (preferMockICD)
260 {
261 for (const VkPhysicalDevice &physicalDevice : physicalDevices)
262 {
263 vkGetPhysicalDeviceProperties(physicalDevice, physicalDevicePropertiesOut);
264 if ((kMockVendorID == physicalDevicePropertiesOut->vendorID) &&
265 (kMockDeviceID == physicalDevicePropertiesOut->deviceID) &&
266 (strcmp(kMockDeviceName, physicalDevicePropertiesOut->deviceName) == 0))
267 {
268 *physicalDeviceOut = physicalDevice;
269 return;
270 }
271 }
272 WARN() << "Vulkan Mock Driver was requested but Mock Device was not found. Using default "
273 "physicalDevice instead.";
274 }
275
276 // Fall back to first device.
277 *physicalDeviceOut = physicalDevices[0];
278 vkGetPhysicalDeviceProperties(*physicalDeviceOut, physicalDevicePropertiesOut);
279}
280
Frank Henigman29f148b2016-11-23 21:05:36 -0500281vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName)
Jamie Madill327ba852016-11-30 12:38:28 -0500282{
Jamie Madilldf9ad2b2018-02-02 12:40:01 -0500283 ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs));
Yuly Novikov199f4292018-01-19 19:04:05 -0500284 mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers();
Jamie Madilla66779f2017-01-06 10:43:44 -0500285
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700286#if !defined(ANGLE_PLATFORM_ANDROID)
287 // Mock ICD does not currently run on Android
Jamie Madillaaca96e2018-06-12 10:19:48 -0400288 bool enableNullDriver = (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
289 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) ==
290 EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700291 if (enableNullDriver)
292 {
293 // Override environment variable to use built Mock ICD
294 // ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn
295 ANGLE_VK_CHECK(angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON),
296 VK_ERROR_INITIALIZATION_FAILED);
297 }
Jamie Madillaaca96e2018-06-12 10:19:48 -0400298#else
299 constexpr bool enableNullDriver = false;
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700300#endif // !defined(ANGLE_PLATFORM_ANDROID)
Jamie Madill0448ec82016-12-23 13:41:47 -0500301 // Gather global layer properties.
302 uint32_t instanceLayerCount = 0;
303 ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr));
304
305 std::vector<VkLayerProperties> instanceLayerProps(instanceLayerCount);
306 if (instanceLayerCount > 0)
307 {
308 ANGLE_VK_TRY(
309 vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProps.data()));
310 }
311
Jamie Madille09bd5d2016-11-29 16:20:35 -0500312 uint32_t instanceExtensionCount = 0;
313 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr));
314
315 std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount);
316 if (instanceExtensionCount > 0)
317 {
318 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount,
319 instanceExtensionProps.data()));
320 }
321
Yuly Novikov199f4292018-01-19 19:04:05 -0500322 const char *const *enabledLayerNames = nullptr;
323 uint32_t enabledLayerCount = 0;
Jamie Madill0448ec82016-12-23 13:41:47 -0500324 if (mEnableValidationLayers)
325 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500326 bool layersRequested =
327 (attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE) == EGL_TRUE);
328 mEnableValidationLayers = GetAvailableValidationLayers(
329 instanceLayerProps, layersRequested, &enabledLayerNames, &enabledLayerCount);
Jamie Madill0448ec82016-12-23 13:41:47 -0500330 }
331
Jamie Madille09bd5d2016-11-29 16:20:35 -0500332 std::vector<const char *> enabledInstanceExtensions;
333 enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
Frank Henigman29f148b2016-11-23 21:05:36 -0500334 enabledInstanceExtensions.push_back(wsiName);
Jamie Madille09bd5d2016-11-29 16:20:35 -0500335
Jamie Madill0448ec82016-12-23 13:41:47 -0500336 // TODO(jmadill): Should be able to continue initialization if debug report ext missing.
337 if (mEnableValidationLayers)
338 {
339 enabledInstanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
340 }
341
Jamie Madille09bd5d2016-11-29 16:20:35 -0500342 // Verify the required extensions are in the extension names set. Fail if not.
343 ANGLE_VK_TRY(VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions));
344
Jamie Madill327ba852016-11-30 12:38:28 -0500345 VkApplicationInfo applicationInfo;
346 applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
347 applicationInfo.pNext = nullptr;
348 applicationInfo.pApplicationName = "ANGLE";
349 applicationInfo.applicationVersion = 1;
350 applicationInfo.pEngineName = "ANGLE";
351 applicationInfo.engineVersion = 1;
352 applicationInfo.apiVersion = VK_API_VERSION_1_0;
353
354 VkInstanceCreateInfo instanceInfo;
355 instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
356 instanceInfo.pNext = nullptr;
357 instanceInfo.flags = 0;
358 instanceInfo.pApplicationInfo = &applicationInfo;
359
Jamie Madille09bd5d2016-11-29 16:20:35 -0500360 // Enable requested layers and extensions.
361 instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size());
362 instanceInfo.ppEnabledExtensionNames =
363 enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data();
Yuly Novikov199f4292018-01-19 19:04:05 -0500364 instanceInfo.enabledLayerCount = enabledLayerCount;
365 instanceInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill327ba852016-11-30 12:38:28 -0500366
367 ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance));
368
Jamie Madill0448ec82016-12-23 13:41:47 -0500369 if (mEnableValidationLayers)
370 {
371 VkDebugReportCallbackCreateInfoEXT debugReportInfo;
372
373 debugReportInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
374 debugReportInfo.pNext = nullptr;
375 debugReportInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT |
376 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
377 VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
378 debugReportInfo.pfnCallback = &DebugReportCallback;
379 debugReportInfo.pUserData = this;
380
381 auto createDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(
382 vkGetInstanceProcAddr(mInstance, "vkCreateDebugReportCallbackEXT"));
383 ASSERT(createDebugReportCallback);
384 ANGLE_VK_TRY(
385 createDebugReportCallback(mInstance, &debugReportInfo, nullptr, &mDebugReportCallback));
386 }
387
Jamie Madill4d0bf552016-12-28 15:45:24 -0500388 uint32_t physicalDeviceCount = 0;
389 ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, nullptr));
390 ANGLE_VK_CHECK(physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED);
391
392 // TODO(jmadill): Handle multiple physical devices. For now, use the first device.
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700393 std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
394 ANGLE_VK_TRY(
395 vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data()));
396 ChoosePhysicalDevice(physicalDevices, enableNullDriver, &mPhysicalDevice,
397 &mPhysicalDeviceProperties);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500398
399 // Ensure we can find a graphics queue family.
400 uint32_t queueCount = 0;
401 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
402
403 ANGLE_VK_CHECK(queueCount > 0, VK_ERROR_INITIALIZATION_FAILED);
404
405 mQueueFamilyProperties.resize(queueCount);
406 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount,
407 mQueueFamilyProperties.data());
408
409 size_t graphicsQueueFamilyCount = false;
410 uint32_t firstGraphicsQueueFamily = 0;
411 for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex)
412 {
413 const auto &queueInfo = mQueueFamilyProperties[familyIndex];
414 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
415 {
416 ASSERT(queueInfo.queueCount > 0);
417 graphicsQueueFamilyCount++;
418 if (firstGraphicsQueueFamily == 0)
419 {
420 firstGraphicsQueueFamily = familyIndex;
421 }
422 break;
423 }
424 }
425
426 ANGLE_VK_CHECK(graphicsQueueFamilyCount > 0, VK_ERROR_INITIALIZATION_FAILED);
427
428 // If only one queue family, go ahead and initialize the device. If there is more than one
429 // queue, we'll have to wait until we see a WindowSurface to know which supports present.
430 if (graphicsQueueFamilyCount == 1)
431 {
432 ANGLE_TRY(initializeDevice(firstGraphicsQueueFamily));
433 }
434
Jamie Madill035fd6b2017-10-03 15:43:22 -0400435 // Store the physical device memory properties so we can find the right memory pools.
436 mMemoryProperties.init(mPhysicalDevice);
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500437
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500438 mGlslangWrapper = GlslangWrapper::GetReference();
439
Jamie Madill6a89d222017-11-02 11:59:51 -0400440 // Initialize the format table.
Luc Ferrond50537a2018-02-07 17:02:08 -0500441 mFormatTable.initialize(mPhysicalDevice, &mNativeTextureCaps,
442 &mNativeCaps.compressedTextureFormats);
Jamie Madill6a89d222017-11-02 11:59:51 -0400443
Jamie Madill327ba852016-11-30 12:38:28 -0500444 return vk::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400445}
446
Jamie Madill4d0bf552016-12-28 15:45:24 -0500447vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex)
448{
449 uint32_t deviceLayerCount = 0;
450 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, nullptr));
451
452 std::vector<VkLayerProperties> deviceLayerProps(deviceLayerCount);
453 if (deviceLayerCount > 0)
454 {
455 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount,
456 deviceLayerProps.data()));
457 }
458
459 uint32_t deviceExtensionCount = 0;
460 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr,
461 &deviceExtensionCount, nullptr));
462
463 std::vector<VkExtensionProperties> deviceExtensionProps(deviceExtensionCount);
464 if (deviceExtensionCount > 0)
465 {
466 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(
467 mPhysicalDevice, nullptr, &deviceExtensionCount, deviceExtensionProps.data()));
468 }
469
Yuly Novikov199f4292018-01-19 19:04:05 -0500470 const char *const *enabledLayerNames = nullptr;
471 uint32_t enabledLayerCount = 0;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500472 if (mEnableValidationLayers)
473 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500474 mEnableValidationLayers = GetAvailableValidationLayers(
475 deviceLayerProps, false, &enabledLayerNames, &enabledLayerCount);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500476 }
477
478 std::vector<const char *> enabledDeviceExtensions;
479 enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
480
Luc Ferronbf6dc372018-06-28 15:24:19 -0400481 // Selectively enable KHR_MAINTENANCE1 to support viewport flipping.
482 if (getFeatures().flipViewportY)
483 {
484 enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
485 }
486
Jamie Madill4d0bf552016-12-28 15:45:24 -0500487 ANGLE_VK_TRY(VerifyExtensionsPresent(deviceExtensionProps, enabledDeviceExtensions));
488
489 VkDeviceQueueCreateInfo queueCreateInfo;
490
491 float zeroPriority = 0.0f;
492
493 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
494 queueCreateInfo.pNext = nullptr;
495 queueCreateInfo.flags = 0;
496 queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
497 queueCreateInfo.queueCount = 1;
498 queueCreateInfo.pQueuePriorities = &zeroPriority;
499
500 // Initialize the device
501 VkDeviceCreateInfo createInfo;
502
Jamie Madill50cf2be2018-06-15 09:46:57 -0400503 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
504 createInfo.pNext = nullptr;
505 createInfo.flags = 0;
506 createInfo.queueCreateInfoCount = 1;
507 createInfo.pQueueCreateInfos = &queueCreateInfo;
Yuly Novikov199f4292018-01-19 19:04:05 -0500508 createInfo.enabledLayerCount = enabledLayerCount;
509 createInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500510 createInfo.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size());
511 createInfo.ppEnabledExtensionNames =
512 enabledDeviceExtensions.empty() ? nullptr : enabledDeviceExtensions.data();
513 createInfo.pEnabledFeatures = nullptr; // TODO(jmadill): features
514
515 ANGLE_VK_TRY(vkCreateDevice(mPhysicalDevice, &createInfo, nullptr, &mDevice));
516
517 mCurrentQueueFamilyIndex = queueFamilyIndex;
518
519 vkGetDeviceQueue(mDevice, mCurrentQueueFamilyIndex, 0, &mQueue);
520
521 // Initialize the command pool now that we know the queue family index.
522 VkCommandPoolCreateInfo commandPoolInfo;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500523 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
524 commandPoolInfo.pNext = nullptr;
525 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500526 commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
527
Jamie Madill5deea722017-02-16 10:44:46 -0500528 ANGLE_TRY(mCommandPool.init(mDevice, commandPoolInfo));
Jamie Madill4d0bf552016-12-28 15:45:24 -0500529
Jamie Madill4d0bf552016-12-28 15:45:24 -0500530 return vk::NoError();
531}
532
533vk::ErrorOrResult<uint32_t> RendererVk::selectPresentQueueForSurface(VkSurfaceKHR surface)
534{
535 // We've already initialized a device, and can't re-create it unless it's never been used.
536 // TODO(jmadill): Handle the re-creation case if necessary.
537 if (mDevice != VK_NULL_HANDLE)
538 {
539 ASSERT(mCurrentQueueFamilyIndex != std::numeric_limits<uint32_t>::max());
540
541 // Check if the current device supports present on this surface.
542 VkBool32 supportsPresent = VK_FALSE;
543 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, mCurrentQueueFamilyIndex,
544 surface, &supportsPresent));
545
546 return (supportsPresent == VK_TRUE);
547 }
548
549 // Find a graphics and present queue.
550 Optional<uint32_t> newPresentQueue;
551 uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size());
552 for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex)
553 {
554 const auto &queueInfo = mQueueFamilyProperties[queueIndex];
555 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
556 {
557 VkBool32 supportsPresent = VK_FALSE;
558 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, queueIndex, surface,
559 &supportsPresent));
560
561 if (supportsPresent == VK_TRUE)
562 {
563 newPresentQueue = queueIndex;
564 break;
565 }
566 }
567 }
568
569 ANGLE_VK_CHECK(newPresentQueue.valid(), VK_ERROR_INITIALIZATION_FAILED);
570 ANGLE_TRY(initializeDevice(newPresentQueue.value()));
571
572 return newPresentQueue.value();
573}
574
575std::string RendererVk::getVendorString() const
576{
Olli Etuahoc6a06182018-04-13 14:11:46 +0300577 return GetVendorString(mPhysicalDeviceProperties.vendorID);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500578}
579
Jamie Madille09bd5d2016-11-29 16:20:35 -0500580std::string RendererVk::getRendererDescription() const
581{
Jamie Madill4d0bf552016-12-28 15:45:24 -0500582 std::stringstream strstr;
583
584 uint32_t apiVersion = mPhysicalDeviceProperties.apiVersion;
585
586 strstr << "Vulkan ";
587 strstr << VK_VERSION_MAJOR(apiVersion) << ".";
588 strstr << VK_VERSION_MINOR(apiVersion) << ".";
589 strstr << VK_VERSION_PATCH(apiVersion);
590
Olli Etuahoc6a06182018-04-13 14:11:46 +0300591 strstr << "(";
592
593 // In the case of NVIDIA, deviceName does not necessarily contain "NVIDIA". Add "NVIDIA" so that
594 // Vulkan end2end tests can be selectively disabled on NVIDIA. TODO(jmadill): should not be
595 // needed after http://anglebug.com/1874 is fixed and end2end_tests use more sophisticated
596 // driver detection.
597 if (mPhysicalDeviceProperties.vendorID == VENDOR_ID_NVIDIA)
598 {
599 strstr << GetVendorString(mPhysicalDeviceProperties.vendorID) << " ";
600 }
601
602 strstr << mPhysicalDeviceProperties.deviceName << ")";
Jamie Madill4d0bf552016-12-28 15:45:24 -0500603
604 return strstr.str();
Jamie Madille09bd5d2016-11-29 16:20:35 -0500605}
606
Jamie Madillacccc6c2016-05-03 17:22:10 -0400607void RendererVk::ensureCapsInitialized() const
608{
609 if (!mCapsInitialized)
610 {
Luc Ferrond50537a2018-02-07 17:02:08 -0500611 vk::GenerateCaps(mPhysicalDeviceProperties, mNativeTextureCaps, &mNativeCaps,
Jamie Madill1266d202018-06-29 09:11:34 -0400612 &mNativeExtensions, &mNativeLimitations, &mFeatures);
Jamie Madillacccc6c2016-05-03 17:22:10 -0400613 mCapsInitialized = true;
614 }
615}
616
Jamie Madillacccc6c2016-05-03 17:22:10 -0400617const gl::Caps &RendererVk::getNativeCaps() const
618{
619 ensureCapsInitialized();
620 return mNativeCaps;
621}
622
623const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const
624{
625 ensureCapsInitialized();
626 return mNativeTextureCaps;
627}
628
629const gl::Extensions &RendererVk::getNativeExtensions() const
630{
631 ensureCapsInitialized();
632 return mNativeExtensions;
633}
634
635const gl::Limitations &RendererVk::getNativeLimitations() const
636{
637 ensureCapsInitialized();
638 return mNativeLimitations;
639}
640
Luc Ferrondaedf4d2018-03-16 09:28:53 -0400641uint32_t RendererVk::getMaxActiveTextures()
642{
643 // TODO(lucferron): expose this limitation to GL in Context Caps
644 return std::min<uint32_t>(mPhysicalDeviceProperties.limits.maxPerStageDescriptorSamplers,
645 gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
646}
647
Jamie Madill49ac74b2017-12-21 14:42:33 -0500648const vk::CommandPool &RendererVk::getCommandPool() const
Jamie Madill4d0bf552016-12-28 15:45:24 -0500649{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500650 return mCommandPool;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500651}
652
Jamie Madill49ac74b2017-12-21 14:42:33 -0500653vk::Error RendererVk::finish(const gl::Context *context)
Jamie Madill4d0bf552016-12-28 15:45:24 -0500654{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500655 if (!mCommandGraph.empty())
Jamie Madill49ac74b2017-12-21 14:42:33 -0500656 {
657 vk::CommandBuffer commandBatch;
658 ANGLE_TRY(flushCommandGraph(context, &commandBatch));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400659
Jamie Madill49ac74b2017-12-21 14:42:33 -0500660 VkSubmitInfo submitInfo;
661 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
662 submitInfo.pNext = nullptr;
663 submitInfo.waitSemaphoreCount = 0;
664 submitInfo.pWaitSemaphores = nullptr;
665 submitInfo.pWaitDstStageMask = nullptr;
666 submitInfo.commandBufferCount = 1;
667 submitInfo.pCommandBuffers = commandBatch.ptr();
668 submitInfo.signalSemaphoreCount = 0;
669 submitInfo.pSignalSemaphores = nullptr;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500670
Jamie Madill49ac74b2017-12-21 14:42:33 -0500671 ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch)));
672 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500673
Jamie Madill4c26fc22017-02-24 11:04:10 -0500674 ASSERT(mQueue != VK_NULL_HANDLE);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500675 ANGLE_VK_TRY(vkQueueWaitIdle(mQueue));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400676 freeAllInFlightResources();
Jamie Madill4c26fc22017-02-24 11:04:10 -0500677 return vk::NoError();
678}
679
Jamie Madill0c0dc342017-03-24 14:18:51 -0400680void RendererVk::freeAllInFlightResources()
681{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500682 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill0c0dc342017-03-24 14:18:51 -0400683 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500684 batch.fence.destroy(mDevice);
685 batch.commandPool.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400686 }
687 mInFlightCommands.clear();
688
689 for (auto &garbage : mGarbage)
690 {
Jamie Madille88ec8e2017-10-31 17:18:14 -0400691 garbage.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400692 }
693 mGarbage.clear();
694}
695
Jamie Madill4c26fc22017-02-24 11:04:10 -0500696vk::Error RendererVk::checkInFlightCommands()
697{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500698 int finishedCount = 0;
Jamie Madillf651c772017-02-21 15:03:51 -0500699
Jamie Madill49ac74b2017-12-21 14:42:33 -0500700 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500701 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500702 VkResult result = batch.fence.getStatus(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400703 if (result == VK_NOT_READY)
704 break;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500705
Jamie Madill0c0dc342017-03-24 14:18:51 -0400706 ANGLE_VK_TRY(result);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500707 ASSERT(batch.serial > mLastCompletedQueueSerial);
708 mLastCompletedQueueSerial = batch.serial;
Jamie Madill0c0dc342017-03-24 14:18:51 -0400709
Jamie Madill49ac74b2017-12-21 14:42:33 -0500710 batch.fence.destroy(mDevice);
711 batch.commandPool.destroy(mDevice);
712 ++finishedCount;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500713 }
714
Jamie Madill49ac74b2017-12-21 14:42:33 -0500715 mInFlightCommands.erase(mInFlightCommands.begin(), mInFlightCommands.begin() + finishedCount);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400716
717 size_t freeIndex = 0;
718 for (; freeIndex < mGarbage.size(); ++freeIndex)
719 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500720 if (!mGarbage[freeIndex].destroyIfComplete(mDevice, mLastCompletedQueueSerial))
Jamie Madill0c0dc342017-03-24 14:18:51 -0400721 break;
722 }
723
724 // Remove the entries from the garbage list - they should be ready to go.
725 if (freeIndex > 0)
726 {
727 mGarbage.erase(mGarbage.begin(), mGarbage.begin() + freeIndex);
Jamie Madillf651c772017-02-21 15:03:51 -0500728 }
729
Jamie Madill4c26fc22017-02-24 11:04:10 -0500730 return vk::NoError();
731}
732
Jamie Madill49ac74b2017-12-21 14:42:33 -0500733vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo, vk::CommandBuffer &&commandBuffer)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500734{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500735 VkFenceCreateInfo fenceInfo;
736 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
737 fenceInfo.pNext = nullptr;
738 fenceInfo.flags = 0;
739
740 CommandBatch batch;
741 ANGLE_TRY(batch.fence.init(mDevice, fenceInfo));
742
743 ANGLE_VK_TRY(vkQueueSubmit(mQueue, 1, &submitInfo, batch.fence.getHandle()));
Jamie Madill4c26fc22017-02-24 11:04:10 -0500744
745 // Store this command buffer in the in-flight list.
Jamie Madill49ac74b2017-12-21 14:42:33 -0500746 batch.commandPool = std::move(mCommandPool);
747 batch.serial = mCurrentQueueSerial;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500748
Jamie Madill49ac74b2017-12-21 14:42:33 -0500749 mInFlightCommands.emplace_back(std::move(batch));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400750
751 // Sanity check.
752 ASSERT(mInFlightCommands.size() < 1000u);
753
754 // Increment the queue serial. If this fails, we should restart ANGLE.
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400755 // TODO(jmadill): Overflow check.
756 mCurrentQueueSerial = mQueueSerialFactory.generate();
Jamie Madill0c0dc342017-03-24 14:18:51 -0400757
758 ANGLE_TRY(checkInFlightCommands());
759
Jamie Madill49ac74b2017-12-21 14:42:33 -0500760 // Simply null out the command buffer here - it was allocated using the command pool.
761 commandBuffer.releaseHandle();
762
763 // Reallocate the command pool for next frame.
764 // TODO(jmadill): Consider reusing command pools.
765 VkCommandPoolCreateInfo poolInfo;
766 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
767 poolInfo.pNext = nullptr;
768 poolInfo.flags = 0;
769 poolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
770
771 mCommandPool.init(mDevice, poolInfo);
772
Jamie Madill4c26fc22017-02-24 11:04:10 -0500773 return vk::NoError();
774}
775
Jamie Madillaaca96e2018-06-12 10:19:48 -0400776GlslangWrapper *RendererVk::getGlslangWrapper() const
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500777{
778 return mGlslangWrapper;
779}
780
Jamie Madill4c26fc22017-02-24 11:04:10 -0500781Serial RendererVk::getCurrentQueueSerial() const
782{
783 return mCurrentQueueSerial;
784}
785
Jamie Madillaaca96e2018-06-12 10:19:48 -0400786bool RendererVk::isSerialInUse(Serial serial) const
Jamie Madill97760352017-11-09 13:08:29 -0500787{
788 return serial > mLastCompletedQueueSerial;
789}
790
Jamie Madill9f2a8612017-11-30 12:43:09 -0500791vk::Error RendererVk::getCompatibleRenderPass(const vk::RenderPassDesc &desc,
792 vk::RenderPass **renderPassOut)
793{
794 return mRenderPassCache.getCompatibleRenderPass(mDevice, mCurrentQueueSerial, desc,
795 renderPassOut);
796}
797
Jamie Madillbef918c2017-12-13 13:11:30 -0500798vk::Error RendererVk::getRenderPassWithOps(const vk::RenderPassDesc &desc,
799 const vk::AttachmentOpsArray &ops,
800 vk::RenderPass **renderPassOut)
Jamie Madill9f2a8612017-11-30 12:43:09 -0500801{
Jamie Madillbef918c2017-12-13 13:11:30 -0500802 return mRenderPassCache.getRenderPassWithOps(mDevice, mCurrentQueueSerial, desc, ops,
803 renderPassOut);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500804}
805
Jamie Madilla5e06072018-05-18 14:36:05 -0400806vk::CommandGraph *RendererVk::getCommandGraph()
Jamie Madill49ac74b2017-12-21 14:42:33 -0500807{
Jamie Madilla5e06072018-05-18 14:36:05 -0400808 return &mCommandGraph;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500809}
810
811vk::Error RendererVk::flushCommandGraph(const gl::Context *context, vk::CommandBuffer *commandBatch)
812{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500813 return mCommandGraph.submitCommands(mDevice, mCurrentQueueSerial, &mRenderPassCache,
814 &mCommandPool, commandBatch);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500815}
816
817vk::Error RendererVk::flush(const gl::Context *context,
818 const vk::Semaphore &waitSemaphore,
819 const vk::Semaphore &signalSemaphore)
820{
821 vk::CommandBuffer commandBatch;
822 ANGLE_TRY(flushCommandGraph(context, &commandBatch));
823
824 VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
825
826 VkSubmitInfo submitInfo;
827 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
828 submitInfo.pNext = nullptr;
829 submitInfo.waitSemaphoreCount = 1;
830 submitInfo.pWaitSemaphores = waitSemaphore.ptr();
831 submitInfo.pWaitDstStageMask = &waitStageMask;
832 submitInfo.commandBufferCount = 1;
833 submitInfo.pCommandBuffers = commandBatch.ptr();
834 submitInfo.signalSemaphoreCount = 1;
835 submitInfo.pSignalSemaphores = signalSemaphore.ptr();
836
837 ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch)));
838 return vk::NoError();
839}
840
Jamie Madill78feddc2018-04-27 11:45:05 -0400841Serial RendererVk::issueShaderSerial()
Jamie Madillf2f6d372018-01-10 21:37:23 -0500842{
Jamie Madill78feddc2018-04-27 11:45:05 -0400843 return mShaderSerialFactory.generate();
Jamie Madillf2f6d372018-01-10 21:37:23 -0500844}
845
Jamie Madill9aef3672018-04-27 11:45:06 -0400846vk::Error RendererVk::getAppPipeline(const ProgramVk *programVk,
847 const vk::PipelineDesc &desc,
848 const gl::AttributesMask &activeAttribLocationsMask,
849 vk::PipelineAndSerial **pipelineOut)
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500850{
Jamie Madill33318de2018-05-01 11:22:54 -0400851 ASSERT(programVk->getVertexModuleSerial() ==
852 desc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial);
853 ASSERT(programVk->getFragmentModuleSerial() ==
854 desc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial);
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500855
856 // Pull in a compatible RenderPass.
857 vk::RenderPass *compatibleRenderPass = nullptr;
858 ANGLE_TRY(getCompatibleRenderPass(desc.getRenderPassDesc(), &compatibleRenderPass));
859
Jamie Madill9b168d02018-06-13 13:25:32 -0400860 const vk::PipelineLayout &pipelineLayout = programVk->getPipelineLayout();
861
Jamie Madillc7918ce2018-06-13 13:25:31 -0400862 return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout,
Luc Ferronceb71902018-02-05 15:18:47 -0500863 activeAttribLocationsMask, programVk->getLinkedVertexModule(),
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500864 programVk->getLinkedFragmentModule(), desc, pipelineOut);
865}
866
Jamie Madill9aef3672018-04-27 11:45:06 -0400867vk::Error RendererVk::getInternalPipeline(const vk::ShaderAndSerial &vertexShader,
868 const vk::ShaderAndSerial &fragmentShader,
869 const vk::PipelineLayout &pipelineLayout,
870 const vk::PipelineDesc &pipelineDesc,
871 const gl::AttributesMask &activeAttribLocationsMask,
872 vk::PipelineAndSerial **pipelineOut)
873{
874 ASSERT(vertexShader.queueSerial() ==
875 pipelineDesc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial);
876 ASSERT(fragmentShader.queueSerial() ==
877 pipelineDesc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial);
878
879 // Pull in a compatible RenderPass.
880 vk::RenderPass *compatibleRenderPass = nullptr;
881 ANGLE_TRY(getCompatibleRenderPass(pipelineDesc.getRenderPassDesc(), &compatibleRenderPass));
882
883 return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout,
884 activeAttribLocationsMask, vertexShader.get(),
885 fragmentShader.get(), pipelineDesc, pipelineOut);
886}
887
Jamie Madill9b168d02018-06-13 13:25:32 -0400888vk::Error RendererVk::getDescriptorSetLayout(
889 const vk::DescriptorSetLayoutDesc &desc,
890 vk::BindingPointer<vk::DescriptorSetLayout> *descriptorSetLayoutOut)
891{
892 return mDescriptorSetLayoutCache.getDescriptorSetLayout(mDevice, desc, descriptorSetLayoutOut);
893}
894
895vk::Error RendererVk::getPipelineLayout(
896 const vk::PipelineLayoutDesc &desc,
897 const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts,
898 vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut)
899{
900 return mPipelineLayoutCache.getPipelineLayout(mDevice, desc, descriptorSetLayouts,
901 pipelineLayoutOut);
902}
903
Jamie Madilld47044a2018-04-27 11:45:03 -0400904vk::ShaderLibrary *RendererVk::getShaderLibrary()
905{
906 return &mShaderLibrary;
907}
Luc Ferron90968362018-05-04 08:47:22 -0400908
Jamie Madillaaca96e2018-06-12 10:19:48 -0400909uint32_t GetUniformBufferDescriptorCount()
910{
911 return kUniformBufferDescriptorsPerDescriptorSet;
912}
913
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400914} // namespace rx