blob: 4e0d5762f0f38dbd644210ed2c463a9f46af2238 [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/TextureVk.h"
26#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
Luc Ferrone4741fd2018-01-25 13:25:27 -050027#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
Jamie Madill3c424b42018-01-19 12:35:09 -050028#include "libANGLE/renderer/vulkan/vk_format_utils.h"
Jamie Madille09bd5d2016-11-29 16:20:35 -050029#include "platform/Platform.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040030
31namespace rx
32{
33
Jamie Madille09bd5d2016-11-29 16:20:35 -050034namespace
35{
Luc Ferrondaedf4d2018-03-16 09:28:53 -040036// We currently only allocate 2 uniform buffer per descriptor set, one for the fragment shader and
37// one for the vertex shader.
38constexpr size_t kUniformBufferDescriptorsPerDescriptorSet = 2;
Jamie Madille09bd5d2016-11-29 16:20:35 -050039
40VkResult VerifyExtensionsPresent(const std::vector<VkExtensionProperties> &extensionProps,
41 const std::vector<const char *> &enabledExtensionNames)
42{
43 // Compile the extensions names into a set.
44 std::set<std::string> extensionNames;
45 for (const auto &extensionProp : extensionProps)
46 {
47 extensionNames.insert(extensionProp.extensionName);
48 }
49
Jamie Madillacf2f3a2017-11-21 19:22:44 -050050 for (const char *extensionName : enabledExtensionNames)
Jamie Madille09bd5d2016-11-29 16:20:35 -050051 {
52 if (extensionNames.count(extensionName) == 0)
53 {
54 return VK_ERROR_EXTENSION_NOT_PRESENT;
55 }
56 }
57
58 return VK_SUCCESS;
59}
60
Yuly Novikov199f4292018-01-19 19:04:05 -050061VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT flags,
62 VkDebugReportObjectTypeEXT objectType,
63 uint64_t object,
64 size_t location,
65 int32_t messageCode,
66 const char *layerPrefix,
67 const char *message,
68 void *userData)
Jamie Madill0448ec82016-12-23 13:41:47 -050069{
70 if ((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) != 0)
71 {
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -050072 ERR() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050073#if !defined(NDEBUG)
74 // Abort the call in Debug builds.
75 return VK_TRUE;
76#endif
77 }
78 else if ((flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) != 0)
79 {
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -050080 WARN() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050081 }
82 else
83 {
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -050084 // Uncomment this if you want Vulkan spam.
85 // WARN() << message;
Jamie Madill0448ec82016-12-23 13:41:47 -050086 }
87
88 return VK_FALSE;
89}
90
Yuly Novikov199f4292018-01-19 19:04:05 -050091// If we're loading the validation layers, we could be running from any random directory.
92// Change to the executable directory so we can find the layers, then change back to the
93// previous directory to be safe we don't disrupt the application.
94class ScopedVkLoaderEnvironment : angle::NonCopyable
95{
96 public:
97 ScopedVkLoaderEnvironment(bool enableValidationLayers)
98 : mEnableValidationLayers(enableValidationLayers), mChangedCWD(false)
99 {
100// Changing CWD and setting environment variables makes no sense on Android,
101// since this code is a part of Java application there.
102// Android Vulkan loader doesn't need this either.
103#if !defined(ANGLE_PLATFORM_ANDROID)
104 if (mEnableValidationLayers)
105 {
106 const auto &cwd = angle::GetCWD();
107 if (!cwd.valid())
108 {
109 ERR() << "Error getting CWD for Vulkan layers init.";
110 mEnableValidationLayers = false;
111 }
112 else
113 {
114 mPreviousCWD = cwd.value();
115 const char *exeDir = angle::GetExecutableDirectory();
116 mChangedCWD = angle::SetCWD(exeDir);
117 if (!mChangedCWD)
118 {
119 ERR() << "Error setting CWD for Vulkan layers init.";
120 mEnableValidationLayers = false;
121 }
122 }
123 }
124
125 // Override environment variable to use the ANGLE layers.
126 if (mEnableValidationLayers)
127 {
jchen10046fa0e2018-02-02 14:51:36 +0800128 if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
Yuly Novikov199f4292018-01-19 19:04:05 -0500129 {
130 ERR() << "Error setting environment for Vulkan layers init.";
131 mEnableValidationLayers = false;
132 }
133 }
134#endif // !defined(ANGLE_PLATFORM_ANDROID)
135 }
136
137 ~ScopedVkLoaderEnvironment()
138 {
139 if (mChangedCWD)
140 {
141#if !defined(ANGLE_PLATFORM_ANDROID)
142 ASSERT(mPreviousCWD.valid());
143 angle::SetCWD(mPreviousCWD.value().c_str());
144#endif // !defined(ANGLE_PLATFORM_ANDROID)
145 }
146 }
147
148 bool canEnableValidationLayers() { return mEnableValidationLayers; }
149
150 private:
151 bool mEnableValidationLayers;
152 bool mChangedCWD;
153 Optional<std::string> mPreviousCWD;
154};
155
Jamie Madille09bd5d2016-11-29 16:20:35 -0500156} // anonymous namespace
157
Jamie Madill49ac74b2017-12-21 14:42:33 -0500158// CommandBatch implementation.
159RendererVk::CommandBatch::CommandBatch()
160{
161}
162
163RendererVk::CommandBatch::~CommandBatch()
164{
165}
166
167RendererVk::CommandBatch::CommandBatch(CommandBatch &&other)
168 : commandPool(std::move(other.commandPool)), fence(std::move(other.fence)), serial(other.serial)
169{
170}
171
172RendererVk::CommandBatch &RendererVk::CommandBatch::operator=(CommandBatch &&other)
173{
174 std::swap(commandPool, other.commandPool);
175 std::swap(fence, other.fence);
176 std::swap(serial, other.serial);
177 return *this;
178}
179
Jamie Madill9f2a8612017-11-30 12:43:09 -0500180// RendererVk implementation.
Jamie Madill0448ec82016-12-23 13:41:47 -0500181RendererVk::RendererVk()
182 : mCapsInitialized(false),
183 mInstance(VK_NULL_HANDLE),
184 mEnableValidationLayers(false),
Jamie Madill4d0bf552016-12-28 15:45:24 -0500185 mDebugReportCallback(VK_NULL_HANDLE),
186 mPhysicalDevice(VK_NULL_HANDLE),
187 mQueue(VK_NULL_HANDLE),
188 mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()),
189 mDevice(VK_NULL_HANDLE),
Jamie Madill4c26fc22017-02-24 11:04:10 -0500190 mGlslangWrapper(nullptr),
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400191 mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
192 mCurrentQueueSerial(mQueueSerialFactory.generate()),
Jamie Madill49ac74b2017-12-21 14:42:33 -0500193 mInFlightCommands()
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400194{
195}
196
197RendererVk::~RendererVk()
198{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500199 if (!mInFlightCommands.empty() || !mGarbage.empty())
Jamie Madill4c26fc22017-02-24 11:04:10 -0500200 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500201 // TODO(jmadill): Not nice to pass nullptr here, but shouldn't be a problem.
202 vk::Error error = finish(nullptr);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500203 if (error.isError())
204 {
205 ERR() << "Error during VK shutdown: " << error;
206 }
207 }
208
Jamie Madill8c3988c2017-12-21 14:44:56 -0500209 for (auto &descriptorSetLayout : mGraphicsDescriptorSetLayouts)
210 {
211 descriptorSetLayout.destroy(mDevice);
212 }
213
214 mGraphicsPipelineLayout.destroy(mDevice);
215
Jamie Madill9f2a8612017-11-30 12:43:09 -0500216 mRenderPassCache.destroy(mDevice);
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500217 mPipelineCache.destroy(mDevice);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500218
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500219 if (mGlslangWrapper)
220 {
221 GlslangWrapper::ReleaseReference();
222 mGlslangWrapper = nullptr;
223 }
224
Jamie Madill5deea722017-02-16 10:44:46 -0500225 if (mCommandPool.valid())
226 {
227 mCommandPool.destroy(mDevice);
228 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500229
230 if (mDevice)
231 {
232 vkDestroyDevice(mDevice, nullptr);
233 mDevice = VK_NULL_HANDLE;
234 }
235
Jamie Madill0448ec82016-12-23 13:41:47 -0500236 if (mDebugReportCallback)
237 {
238 ASSERT(mInstance);
239 auto destroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
240 vkGetInstanceProcAddr(mInstance, "vkDestroyDebugReportCallbackEXT"));
241 ASSERT(destroyDebugReportCallback);
242 destroyDebugReportCallback(mInstance, mDebugReportCallback, nullptr);
243 }
244
Jamie Madill4d0bf552016-12-28 15:45:24 -0500245 if (mInstance)
246 {
247 vkDestroyInstance(mInstance, nullptr);
248 mInstance = VK_NULL_HANDLE;
249 }
250
251 mPhysicalDevice = VK_NULL_HANDLE;
Jamie Madill327ba852016-11-30 12:38:28 -0500252}
253
Frank Henigman29f148b2016-11-23 21:05:36 -0500254vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName)
Jamie Madill327ba852016-11-30 12:38:28 -0500255{
Jamie Madilldf9ad2b2018-02-02 12:40:01 -0500256 ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs));
Yuly Novikov199f4292018-01-19 19:04:05 -0500257 mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers();
Jamie Madilla66779f2017-01-06 10:43:44 -0500258
Jamie Madill0448ec82016-12-23 13:41:47 -0500259 // Gather global layer properties.
260 uint32_t instanceLayerCount = 0;
261 ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr));
262
263 std::vector<VkLayerProperties> instanceLayerProps(instanceLayerCount);
264 if (instanceLayerCount > 0)
265 {
266 ANGLE_VK_TRY(
267 vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProps.data()));
268 }
269
Jamie Madille09bd5d2016-11-29 16:20:35 -0500270 uint32_t instanceExtensionCount = 0;
271 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr));
272
273 std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount);
274 if (instanceExtensionCount > 0)
275 {
276 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount,
277 instanceExtensionProps.data()));
278 }
279
Yuly Novikov199f4292018-01-19 19:04:05 -0500280 const char *const *enabledLayerNames = nullptr;
281 uint32_t enabledLayerCount = 0;
Jamie Madill0448ec82016-12-23 13:41:47 -0500282 if (mEnableValidationLayers)
283 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500284 bool layersRequested =
285 (attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE) == EGL_TRUE);
286 mEnableValidationLayers = GetAvailableValidationLayers(
287 instanceLayerProps, layersRequested, &enabledLayerNames, &enabledLayerCount);
Jamie Madill0448ec82016-12-23 13:41:47 -0500288 }
289
Jamie Madille09bd5d2016-11-29 16:20:35 -0500290 std::vector<const char *> enabledInstanceExtensions;
291 enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
Frank Henigman29f148b2016-11-23 21:05:36 -0500292 enabledInstanceExtensions.push_back(wsiName);
Jamie Madille09bd5d2016-11-29 16:20:35 -0500293
Jamie Madill0448ec82016-12-23 13:41:47 -0500294 // TODO(jmadill): Should be able to continue initialization if debug report ext missing.
295 if (mEnableValidationLayers)
296 {
297 enabledInstanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
298 }
299
Jamie Madille09bd5d2016-11-29 16:20:35 -0500300 // Verify the required extensions are in the extension names set. Fail if not.
301 ANGLE_VK_TRY(VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions));
302
Jamie Madill327ba852016-11-30 12:38:28 -0500303 VkApplicationInfo applicationInfo;
304 applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
305 applicationInfo.pNext = nullptr;
306 applicationInfo.pApplicationName = "ANGLE";
307 applicationInfo.applicationVersion = 1;
308 applicationInfo.pEngineName = "ANGLE";
309 applicationInfo.engineVersion = 1;
310 applicationInfo.apiVersion = VK_API_VERSION_1_0;
311
312 VkInstanceCreateInfo instanceInfo;
313 instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
314 instanceInfo.pNext = nullptr;
315 instanceInfo.flags = 0;
316 instanceInfo.pApplicationInfo = &applicationInfo;
317
Jamie Madille09bd5d2016-11-29 16:20:35 -0500318 // Enable requested layers and extensions.
319 instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size());
320 instanceInfo.ppEnabledExtensionNames =
321 enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data();
Yuly Novikov199f4292018-01-19 19:04:05 -0500322 instanceInfo.enabledLayerCount = enabledLayerCount;
323 instanceInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill327ba852016-11-30 12:38:28 -0500324
325 ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance));
326
Jamie Madill0448ec82016-12-23 13:41:47 -0500327 if (mEnableValidationLayers)
328 {
329 VkDebugReportCallbackCreateInfoEXT debugReportInfo;
330
331 debugReportInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
332 debugReportInfo.pNext = nullptr;
333 debugReportInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT |
334 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
335 VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
336 debugReportInfo.pfnCallback = &DebugReportCallback;
337 debugReportInfo.pUserData = this;
338
339 auto createDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(
340 vkGetInstanceProcAddr(mInstance, "vkCreateDebugReportCallbackEXT"));
341 ASSERT(createDebugReportCallback);
342 ANGLE_VK_TRY(
343 createDebugReportCallback(mInstance, &debugReportInfo, nullptr, &mDebugReportCallback));
344 }
345
Jamie Madill4d0bf552016-12-28 15:45:24 -0500346 uint32_t physicalDeviceCount = 0;
347 ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, nullptr));
348 ANGLE_VK_CHECK(physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED);
349
350 // TODO(jmadill): Handle multiple physical devices. For now, use the first device.
351 physicalDeviceCount = 1;
352 ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, &mPhysicalDevice));
353
354 vkGetPhysicalDeviceProperties(mPhysicalDevice, &mPhysicalDeviceProperties);
355
356 // Ensure we can find a graphics queue family.
357 uint32_t queueCount = 0;
358 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
359
360 ANGLE_VK_CHECK(queueCount > 0, VK_ERROR_INITIALIZATION_FAILED);
361
362 mQueueFamilyProperties.resize(queueCount);
363 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount,
364 mQueueFamilyProperties.data());
365
366 size_t graphicsQueueFamilyCount = false;
367 uint32_t firstGraphicsQueueFamily = 0;
368 for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex)
369 {
370 const auto &queueInfo = mQueueFamilyProperties[familyIndex];
371 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
372 {
373 ASSERT(queueInfo.queueCount > 0);
374 graphicsQueueFamilyCount++;
375 if (firstGraphicsQueueFamily == 0)
376 {
377 firstGraphicsQueueFamily = familyIndex;
378 }
379 break;
380 }
381 }
382
383 ANGLE_VK_CHECK(graphicsQueueFamilyCount > 0, VK_ERROR_INITIALIZATION_FAILED);
384
385 // If only one queue family, go ahead and initialize the device. If there is more than one
386 // queue, we'll have to wait until we see a WindowSurface to know which supports present.
387 if (graphicsQueueFamilyCount == 1)
388 {
389 ANGLE_TRY(initializeDevice(firstGraphicsQueueFamily));
390 }
391
Jamie Madill035fd6b2017-10-03 15:43:22 -0400392 // Store the physical device memory properties so we can find the right memory pools.
393 mMemoryProperties.init(mPhysicalDevice);
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500394
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500395 mGlslangWrapper = GlslangWrapper::GetReference();
396
Jamie Madill6a89d222017-11-02 11:59:51 -0400397 // Initialize the format table.
Luc Ferrond50537a2018-02-07 17:02:08 -0500398 mFormatTable.initialize(mPhysicalDevice, &mNativeTextureCaps,
399 &mNativeCaps.compressedTextureFormats);
Jamie Madill6a89d222017-11-02 11:59:51 -0400400
Jamie Madill8c3988c2017-12-21 14:44:56 -0500401 // Initialize the pipeline layout for GL programs.
402 ANGLE_TRY(initGraphicsPipelineLayout());
403
Jamie Madill327ba852016-11-30 12:38:28 -0500404 return vk::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400405}
406
Jamie Madill4d0bf552016-12-28 15:45:24 -0500407vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex)
408{
409 uint32_t deviceLayerCount = 0;
410 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, nullptr));
411
412 std::vector<VkLayerProperties> deviceLayerProps(deviceLayerCount);
413 if (deviceLayerCount > 0)
414 {
415 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount,
416 deviceLayerProps.data()));
417 }
418
419 uint32_t deviceExtensionCount = 0;
420 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr,
421 &deviceExtensionCount, nullptr));
422
423 std::vector<VkExtensionProperties> deviceExtensionProps(deviceExtensionCount);
424 if (deviceExtensionCount > 0)
425 {
426 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(
427 mPhysicalDevice, nullptr, &deviceExtensionCount, deviceExtensionProps.data()));
428 }
429
Yuly Novikov199f4292018-01-19 19:04:05 -0500430 const char *const *enabledLayerNames = nullptr;
431 uint32_t enabledLayerCount = 0;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500432 if (mEnableValidationLayers)
433 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500434 mEnableValidationLayers = GetAvailableValidationLayers(
435 deviceLayerProps, false, &enabledLayerNames, &enabledLayerCount);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500436 }
437
438 std::vector<const char *> enabledDeviceExtensions;
439 enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
440
441 ANGLE_VK_TRY(VerifyExtensionsPresent(deviceExtensionProps, enabledDeviceExtensions));
442
443 VkDeviceQueueCreateInfo queueCreateInfo;
444
445 float zeroPriority = 0.0f;
446
447 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
448 queueCreateInfo.pNext = nullptr;
449 queueCreateInfo.flags = 0;
450 queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
451 queueCreateInfo.queueCount = 1;
452 queueCreateInfo.pQueuePriorities = &zeroPriority;
453
454 // Initialize the device
455 VkDeviceCreateInfo createInfo;
456
457 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
458 createInfo.pNext = nullptr;
459 createInfo.flags = 0;
460 createInfo.queueCreateInfoCount = 1;
461 createInfo.pQueueCreateInfos = &queueCreateInfo;
Yuly Novikov199f4292018-01-19 19:04:05 -0500462 createInfo.enabledLayerCount = enabledLayerCount;
463 createInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500464 createInfo.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size());
465 createInfo.ppEnabledExtensionNames =
466 enabledDeviceExtensions.empty() ? nullptr : enabledDeviceExtensions.data();
467 createInfo.pEnabledFeatures = nullptr; // TODO(jmadill): features
468
469 ANGLE_VK_TRY(vkCreateDevice(mPhysicalDevice, &createInfo, nullptr, &mDevice));
470
471 mCurrentQueueFamilyIndex = queueFamilyIndex;
472
473 vkGetDeviceQueue(mDevice, mCurrentQueueFamilyIndex, 0, &mQueue);
474
475 // Initialize the command pool now that we know the queue family index.
476 VkCommandPoolCreateInfo commandPoolInfo;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500477 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
478 commandPoolInfo.pNext = nullptr;
479 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500480 commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
481
Jamie Madill5deea722017-02-16 10:44:46 -0500482 ANGLE_TRY(mCommandPool.init(mDevice, commandPoolInfo));
Jamie Madill4d0bf552016-12-28 15:45:24 -0500483
Jamie Madill4d0bf552016-12-28 15:45:24 -0500484 return vk::NoError();
485}
486
487vk::ErrorOrResult<uint32_t> RendererVk::selectPresentQueueForSurface(VkSurfaceKHR surface)
488{
489 // We've already initialized a device, and can't re-create it unless it's never been used.
490 // TODO(jmadill): Handle the re-creation case if necessary.
491 if (mDevice != VK_NULL_HANDLE)
492 {
493 ASSERT(mCurrentQueueFamilyIndex != std::numeric_limits<uint32_t>::max());
494
495 // Check if the current device supports present on this surface.
496 VkBool32 supportsPresent = VK_FALSE;
497 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, mCurrentQueueFamilyIndex,
498 surface, &supportsPresent));
499
500 return (supportsPresent == VK_TRUE);
501 }
502
503 // Find a graphics and present queue.
504 Optional<uint32_t> newPresentQueue;
505 uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size());
506 for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex)
507 {
508 const auto &queueInfo = mQueueFamilyProperties[queueIndex];
509 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
510 {
511 VkBool32 supportsPresent = VK_FALSE;
512 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, queueIndex, surface,
513 &supportsPresent));
514
515 if (supportsPresent == VK_TRUE)
516 {
517 newPresentQueue = queueIndex;
518 break;
519 }
520 }
521 }
522
523 ANGLE_VK_CHECK(newPresentQueue.valid(), VK_ERROR_INITIALIZATION_FAILED);
524 ANGLE_TRY(initializeDevice(newPresentQueue.value()));
525
526 return newPresentQueue.value();
527}
528
529std::string RendererVk::getVendorString() const
530{
531 switch (mPhysicalDeviceProperties.vendorID)
532 {
533 case VENDOR_ID_AMD:
534 return "Advanced Micro Devices";
535 case VENDOR_ID_NVIDIA:
536 return "NVIDIA";
537 case VENDOR_ID_INTEL:
538 return "Intel";
539 default:
540 {
541 // TODO(jmadill): More vendor IDs.
542 std::stringstream strstr;
543 strstr << "Vendor ID: " << mPhysicalDeviceProperties.vendorID;
544 return strstr.str();
545 }
546 }
547}
548
Jamie Madille09bd5d2016-11-29 16:20:35 -0500549std::string RendererVk::getRendererDescription() const
550{
Jamie Madill4d0bf552016-12-28 15:45:24 -0500551 std::stringstream strstr;
552
553 uint32_t apiVersion = mPhysicalDeviceProperties.apiVersion;
554
555 strstr << "Vulkan ";
556 strstr << VK_VERSION_MAJOR(apiVersion) << ".";
557 strstr << VK_VERSION_MINOR(apiVersion) << ".";
558 strstr << VK_VERSION_PATCH(apiVersion);
559
560 strstr << "(" << mPhysicalDeviceProperties.deviceName << ")";
561
562 return strstr.str();
Jamie Madille09bd5d2016-11-29 16:20:35 -0500563}
564
Jamie Madillacccc6c2016-05-03 17:22:10 -0400565void RendererVk::ensureCapsInitialized() const
566{
567 if (!mCapsInitialized)
568 {
Luc Ferrond50537a2018-02-07 17:02:08 -0500569 vk::GenerateCaps(mPhysicalDeviceProperties, mNativeTextureCaps, &mNativeCaps,
Luc Ferrone4741fd2018-01-25 13:25:27 -0500570 &mNativeExtensions, &mNativeLimitations);
Jamie Madillacccc6c2016-05-03 17:22:10 -0400571 mCapsInitialized = true;
572 }
573}
574
Jamie Madillacccc6c2016-05-03 17:22:10 -0400575const gl::Caps &RendererVk::getNativeCaps() const
576{
577 ensureCapsInitialized();
578 return mNativeCaps;
579}
580
581const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const
582{
583 ensureCapsInitialized();
584 return mNativeTextureCaps;
585}
586
587const gl::Extensions &RendererVk::getNativeExtensions() const
588{
589 ensureCapsInitialized();
590 return mNativeExtensions;
591}
592
593const gl::Limitations &RendererVk::getNativeLimitations() const
594{
595 ensureCapsInitialized();
596 return mNativeLimitations;
597}
598
Luc Ferrondaedf4d2018-03-16 09:28:53 -0400599uint32_t RendererVk::getMaxActiveTextures()
600{
601 // TODO(lucferron): expose this limitation to GL in Context Caps
602 return std::min<uint32_t>(mPhysicalDeviceProperties.limits.maxPerStageDescriptorSamplers,
603 gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
604}
605
606uint32_t RendererVk::getUniformBufferDescriptorCount()
607{
608 return kUniformBufferDescriptorsPerDescriptorSet;
609}
610
Jamie Madill49ac74b2017-12-21 14:42:33 -0500611const vk::CommandPool &RendererVk::getCommandPool() const
Jamie Madill4d0bf552016-12-28 15:45:24 -0500612{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500613 return mCommandPool;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500614}
615
Jamie Madill49ac74b2017-12-21 14:42:33 -0500616vk::Error RendererVk::finish(const gl::Context *context)
Jamie Madill4d0bf552016-12-28 15:45:24 -0500617{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500618 if (!mCommandGraph.empty())
Jamie Madill49ac74b2017-12-21 14:42:33 -0500619 {
620 vk::CommandBuffer commandBatch;
621 ANGLE_TRY(flushCommandGraph(context, &commandBatch));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400622
Jamie Madill49ac74b2017-12-21 14:42:33 -0500623 VkSubmitInfo submitInfo;
624 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
625 submitInfo.pNext = nullptr;
626 submitInfo.waitSemaphoreCount = 0;
627 submitInfo.pWaitSemaphores = nullptr;
628 submitInfo.pWaitDstStageMask = nullptr;
629 submitInfo.commandBufferCount = 1;
630 submitInfo.pCommandBuffers = commandBatch.ptr();
631 submitInfo.signalSemaphoreCount = 0;
632 submitInfo.pSignalSemaphores = nullptr;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500633
Jamie Madill49ac74b2017-12-21 14:42:33 -0500634 ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch)));
635 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500636
Jamie Madill4c26fc22017-02-24 11:04:10 -0500637 ASSERT(mQueue != VK_NULL_HANDLE);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500638 ANGLE_VK_TRY(vkQueueWaitIdle(mQueue));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400639 freeAllInFlightResources();
Jamie Madill4c26fc22017-02-24 11:04:10 -0500640 return vk::NoError();
641}
642
Jamie Madill0c0dc342017-03-24 14:18:51 -0400643void RendererVk::freeAllInFlightResources()
644{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500645 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill0c0dc342017-03-24 14:18:51 -0400646 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500647 batch.fence.destroy(mDevice);
648 batch.commandPool.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400649 }
650 mInFlightCommands.clear();
651
652 for (auto &garbage : mGarbage)
653 {
Jamie Madille88ec8e2017-10-31 17:18:14 -0400654 garbage.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400655 }
656 mGarbage.clear();
657}
658
Jamie Madill4c26fc22017-02-24 11:04:10 -0500659vk::Error RendererVk::checkInFlightCommands()
660{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500661 int finishedCount = 0;
Jamie Madillf651c772017-02-21 15:03:51 -0500662
Jamie Madill49ac74b2017-12-21 14:42:33 -0500663 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500664 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500665 VkResult result = batch.fence.getStatus(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400666 if (result == VK_NOT_READY)
667 break;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500668
Jamie Madill0c0dc342017-03-24 14:18:51 -0400669 ANGLE_VK_TRY(result);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500670 ASSERT(batch.serial > mLastCompletedQueueSerial);
671 mLastCompletedQueueSerial = batch.serial;
Jamie Madill0c0dc342017-03-24 14:18:51 -0400672
Jamie Madill49ac74b2017-12-21 14:42:33 -0500673 batch.fence.destroy(mDevice);
674 batch.commandPool.destroy(mDevice);
675 ++finishedCount;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500676 }
677
Jamie Madill49ac74b2017-12-21 14:42:33 -0500678 mInFlightCommands.erase(mInFlightCommands.begin(), mInFlightCommands.begin() + finishedCount);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400679
680 size_t freeIndex = 0;
681 for (; freeIndex < mGarbage.size(); ++freeIndex)
682 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500683 if (!mGarbage[freeIndex].destroyIfComplete(mDevice, mLastCompletedQueueSerial))
Jamie Madill0c0dc342017-03-24 14:18:51 -0400684 break;
685 }
686
687 // Remove the entries from the garbage list - they should be ready to go.
688 if (freeIndex > 0)
689 {
690 mGarbage.erase(mGarbage.begin(), mGarbage.begin() + freeIndex);
Jamie Madillf651c772017-02-21 15:03:51 -0500691 }
692
Jamie Madill4c26fc22017-02-24 11:04:10 -0500693 return vk::NoError();
694}
695
Jamie Madill49ac74b2017-12-21 14:42:33 -0500696vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo, vk::CommandBuffer &&commandBuffer)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500697{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500698 VkFenceCreateInfo fenceInfo;
699 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
700 fenceInfo.pNext = nullptr;
701 fenceInfo.flags = 0;
702
703 CommandBatch batch;
704 ANGLE_TRY(batch.fence.init(mDevice, fenceInfo));
705
706 ANGLE_VK_TRY(vkQueueSubmit(mQueue, 1, &submitInfo, batch.fence.getHandle()));
Jamie Madill4c26fc22017-02-24 11:04:10 -0500707
708 // Store this command buffer in the in-flight list.
Jamie Madill49ac74b2017-12-21 14:42:33 -0500709 batch.commandPool = std::move(mCommandPool);
710 batch.serial = mCurrentQueueSerial;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500711
Jamie Madill49ac74b2017-12-21 14:42:33 -0500712 mInFlightCommands.emplace_back(std::move(batch));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400713
714 // Sanity check.
715 ASSERT(mInFlightCommands.size() < 1000u);
716
717 // Increment the queue serial. If this fails, we should restart ANGLE.
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400718 // TODO(jmadill): Overflow check.
719 mCurrentQueueSerial = mQueueSerialFactory.generate();
Jamie Madill0c0dc342017-03-24 14:18:51 -0400720
721 ANGLE_TRY(checkInFlightCommands());
722
Jamie Madill49ac74b2017-12-21 14:42:33 -0500723 // Simply null out the command buffer here - it was allocated using the command pool.
724 commandBuffer.releaseHandle();
725
726 // Reallocate the command pool for next frame.
727 // TODO(jmadill): Consider reusing command pools.
728 VkCommandPoolCreateInfo poolInfo;
729 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
730 poolInfo.pNext = nullptr;
731 poolInfo.flags = 0;
732 poolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
733
734 mCommandPool.init(mDevice, poolInfo);
735
Jamie Madill4c26fc22017-02-24 11:04:10 -0500736 return vk::NoError();
737}
738
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500739GlslangWrapper *RendererVk::getGlslangWrapper()
740{
741 return mGlslangWrapper;
742}
743
Jamie Madill4c26fc22017-02-24 11:04:10 -0500744Serial RendererVk::getCurrentQueueSerial() const
745{
746 return mCurrentQueueSerial;
747}
748
Jamie Madill97760352017-11-09 13:08:29 -0500749bool RendererVk::isResourceInUse(const ResourceVk &resource)
750{
751 return isSerialInUse(resource.getQueueSerial());
752}
753
754bool RendererVk::isSerialInUse(Serial serial)
755{
756 return serial > mLastCompletedQueueSerial;
757}
758
Jamie Madill9f2a8612017-11-30 12:43:09 -0500759vk::Error RendererVk::getCompatibleRenderPass(const vk::RenderPassDesc &desc,
760 vk::RenderPass **renderPassOut)
761{
762 return mRenderPassCache.getCompatibleRenderPass(mDevice, mCurrentQueueSerial, desc,
763 renderPassOut);
764}
765
Jamie Madillbef918c2017-12-13 13:11:30 -0500766vk::Error RendererVk::getRenderPassWithOps(const vk::RenderPassDesc &desc,
767 const vk::AttachmentOpsArray &ops,
768 vk::RenderPass **renderPassOut)
Jamie Madill9f2a8612017-11-30 12:43:09 -0500769{
Jamie Madillbef918c2017-12-13 13:11:30 -0500770 return mRenderPassCache.getRenderPassWithOps(mDevice, mCurrentQueueSerial, desc, ops,
771 renderPassOut);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500772}
773
Jamie Madill1f46bc12018-02-20 16:09:43 -0500774vk::CommandGraphNode *RendererVk::allocateCommandNode()
Jamie Madill49ac74b2017-12-21 14:42:33 -0500775{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500776 return mCommandGraph.allocateNode();
Jamie Madill49ac74b2017-12-21 14:42:33 -0500777}
778
779vk::Error RendererVk::flushCommandGraph(const gl::Context *context, vk::CommandBuffer *commandBatch)
780{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500781 return mCommandGraph.submitCommands(mDevice, mCurrentQueueSerial, &mRenderPassCache,
782 &mCommandPool, commandBatch);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500783}
784
785vk::Error RendererVk::flush(const gl::Context *context,
786 const vk::Semaphore &waitSemaphore,
787 const vk::Semaphore &signalSemaphore)
788{
789 vk::CommandBuffer commandBatch;
790 ANGLE_TRY(flushCommandGraph(context, &commandBatch));
791
792 VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
793
794 VkSubmitInfo submitInfo;
795 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
796 submitInfo.pNext = nullptr;
797 submitInfo.waitSemaphoreCount = 1;
798 submitInfo.pWaitSemaphores = waitSemaphore.ptr();
799 submitInfo.pWaitDstStageMask = &waitStageMask;
800 submitInfo.commandBufferCount = 1;
801 submitInfo.pCommandBuffers = commandBatch.ptr();
802 submitInfo.signalSemaphoreCount = 1;
803 submitInfo.pSignalSemaphores = signalSemaphore.ptr();
804
805 ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch)));
806 return vk::NoError();
807}
808
Jamie Madill8c3988c2017-12-21 14:44:56 -0500809const vk::PipelineLayout &RendererVk::getGraphicsPipelineLayout() const
810{
811 return mGraphicsPipelineLayout;
812}
813
814const std::vector<vk::DescriptorSetLayout> &RendererVk::getGraphicsDescriptorSetLayouts() const
815{
816 return mGraphicsDescriptorSetLayouts;
817}
818
819vk::Error RendererVk::initGraphicsPipelineLayout()
820{
821 ASSERT(!mGraphicsPipelineLayout.valid());
822
823 // Create two descriptor set layouts: one for default uniform info, and one for textures.
824 // Skip one or both if there are no uniforms.
825 VkDescriptorSetLayoutBinding uniformBindings[2];
826 uint32_t blockCount = 0;
827
828 {
829 auto &layoutBinding = uniformBindings[blockCount];
830
831 layoutBinding.binding = blockCount;
Luc Ferron7a06ac12018-03-15 10:17:04 -0400832 layoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jamie Madill8c3988c2017-12-21 14:44:56 -0500833 layoutBinding.descriptorCount = 1;
834 layoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
835 layoutBinding.pImmutableSamplers = nullptr;
836
837 blockCount++;
838 }
839
840 {
841 auto &layoutBinding = uniformBindings[blockCount];
842
843 layoutBinding.binding = blockCount;
Luc Ferron7a06ac12018-03-15 10:17:04 -0400844 layoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jamie Madill8c3988c2017-12-21 14:44:56 -0500845 layoutBinding.descriptorCount = 1;
846 layoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
847 layoutBinding.pImmutableSamplers = nullptr;
848
849 blockCount++;
850 }
851
852 {
853 VkDescriptorSetLayoutCreateInfo uniformInfo;
854 uniformInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
855 uniformInfo.pNext = nullptr;
856 uniformInfo.flags = 0;
857 uniformInfo.bindingCount = blockCount;
858 uniformInfo.pBindings = uniformBindings;
859
860 vk::DescriptorSetLayout uniformLayout;
861 ANGLE_TRY(uniformLayout.init(mDevice, uniformInfo));
862 mGraphicsDescriptorSetLayouts.push_back(std::move(uniformLayout));
863 }
864
Luc Ferrondaedf4d2018-03-16 09:28:53 -0400865 std::vector<VkDescriptorSetLayoutBinding> textureBindings(getMaxActiveTextures());
Jamie Madill8c3988c2017-12-21 14:44:56 -0500866
867 // TODO(jmadill): This approach might not work well for texture arrays.
Yuly Novikov37968132018-01-23 18:19:29 -0500868 for (uint32_t textureIndex = 0; textureIndex < textureBindings.size(); ++textureIndex)
Jamie Madill8c3988c2017-12-21 14:44:56 -0500869 {
870 VkDescriptorSetLayoutBinding &layoutBinding = textureBindings[textureIndex];
871
872 layoutBinding.binding = textureIndex;
873 layoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
874 layoutBinding.descriptorCount = 1;
875 layoutBinding.stageFlags = (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
876 layoutBinding.pImmutableSamplers = nullptr;
877 }
878
879 {
880 VkDescriptorSetLayoutCreateInfo textureInfo;
881 textureInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
882 textureInfo.pNext = nullptr;
883 textureInfo.flags = 0;
884 textureInfo.bindingCount = static_cast<uint32_t>(textureBindings.size());
885 textureInfo.pBindings = textureBindings.data();
886
887 vk::DescriptorSetLayout textureLayout;
888 ANGLE_TRY(textureLayout.init(mDevice, textureInfo));
889 mGraphicsDescriptorSetLayouts.push_back(std::move(textureLayout));
890 }
891
892 VkPipelineLayoutCreateInfo createInfo;
893 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
894 createInfo.pNext = nullptr;
895 createInfo.flags = 0;
896 createInfo.setLayoutCount = static_cast<uint32_t>(mGraphicsDescriptorSetLayouts.size());
897 createInfo.pSetLayouts = mGraphicsDescriptorSetLayouts[0].ptr();
898 createInfo.pushConstantRangeCount = 0;
899 createInfo.pPushConstantRanges = nullptr;
900
901 ANGLE_TRY(mGraphicsPipelineLayout.init(mDevice, createInfo));
902
903 return vk::NoError();
904}
Jamie Madillf2f6d372018-01-10 21:37:23 -0500905
906Serial RendererVk::issueProgramSerial()
907{
908 return mProgramSerialFactory.generate();
909}
910
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500911vk::Error RendererVk::getPipeline(const ProgramVk *programVk,
912 const vk::PipelineDesc &desc,
Luc Ferronceb71902018-02-05 15:18:47 -0500913 const gl::AttributesMask &activeAttribLocationsMask,
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500914 vk::PipelineAndSerial **pipelineOut)
915{
916 ASSERT(programVk->getVertexModuleSerial() == desc.getShaderStageInfo()[0].moduleSerial);
917 ASSERT(programVk->getFragmentModuleSerial() == desc.getShaderStageInfo()[1].moduleSerial);
918
919 // Pull in a compatible RenderPass.
920 vk::RenderPass *compatibleRenderPass = nullptr;
921 ANGLE_TRY(getCompatibleRenderPass(desc.getRenderPassDesc(), &compatibleRenderPass));
922
923 return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, mGraphicsPipelineLayout,
Luc Ferronceb71902018-02-05 15:18:47 -0500924 activeAttribLocationsMask, programVk->getLinkedVertexModule(),
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500925 programVk->getLinkedFragmentModule(), desc, pipelineOut);
926}
927
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400928} // namespace rx