blob: be91eded4e094c9c3738ff23291ed944c0c98bd6 [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 Madillbea35a62018-07-05 11:54:10 -0400183void RendererVk::CommandBatch::destroy(VkDevice device)
184{
185 commandPool.destroy(device);
186 fence.destroy(device);
187}
188
Jamie Madill9f2a8612017-11-30 12:43:09 -0500189// RendererVk implementation.
Jamie Madill0448ec82016-12-23 13:41:47 -0500190RendererVk::RendererVk()
191 : mCapsInitialized(false),
192 mInstance(VK_NULL_HANDLE),
193 mEnableValidationLayers(false),
Jamie Madill4d0bf552016-12-28 15:45:24 -0500194 mDebugReportCallback(VK_NULL_HANDLE),
195 mPhysicalDevice(VK_NULL_HANDLE),
196 mQueue(VK_NULL_HANDLE),
197 mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()),
198 mDevice(VK_NULL_HANDLE),
Jamie Madill4c26fc22017-02-24 11:04:10 -0500199 mGlslangWrapper(nullptr),
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400200 mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
Jamie Madillaaca96e2018-06-12 10:19:48 -0400201 mCurrentQueueSerial(mQueueSerialFactory.generate())
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400202{
203}
204
205RendererVk::~RendererVk()
206{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500207 if (!mInFlightCommands.empty() || !mGarbage.empty())
Jamie Madill4c26fc22017-02-24 11:04:10 -0500208 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500209 // TODO(jmadill): Not nice to pass nullptr here, but shouldn't be a problem.
210 vk::Error error = finish(nullptr);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500211 if (error.isError())
212 {
213 ERR() << "Error during VK shutdown: " << error;
214 }
215 }
216
Jamie Madillc7918ce2018-06-13 13:25:31 -0400217 mPipelineLayoutCache.destroy(mDevice);
218 mDescriptorSetLayoutCache.destroy(mDevice);
219
Jamie Madill9f2a8612017-11-30 12:43:09 -0500220 mRenderPassCache.destroy(mDevice);
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500221 mPipelineCache.destroy(mDevice);
Jamie Madilld47044a2018-04-27 11:45:03 -0400222 mShaderLibrary.destroy(mDevice);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500223
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500224 if (mGlslangWrapper)
225 {
226 GlslangWrapper::ReleaseReference();
227 mGlslangWrapper = nullptr;
228 }
229
Jamie Madill5deea722017-02-16 10:44:46 -0500230 if (mCommandPool.valid())
231 {
232 mCommandPool.destroy(mDevice);
233 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500234
235 if (mDevice)
236 {
237 vkDestroyDevice(mDevice, nullptr);
238 mDevice = VK_NULL_HANDLE;
239 }
240
Jamie Madill0448ec82016-12-23 13:41:47 -0500241 if (mDebugReportCallback)
242 {
243 ASSERT(mInstance);
244 auto destroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
245 vkGetInstanceProcAddr(mInstance, "vkDestroyDebugReportCallbackEXT"));
246 ASSERT(destroyDebugReportCallback);
247 destroyDebugReportCallback(mInstance, mDebugReportCallback, nullptr);
248 }
249
Jamie Madill4d0bf552016-12-28 15:45:24 -0500250 if (mInstance)
251 {
252 vkDestroyInstance(mInstance, nullptr);
253 mInstance = VK_NULL_HANDLE;
254 }
255
256 mPhysicalDevice = VK_NULL_HANDLE;
Jamie Madill327ba852016-11-30 12:38:28 -0500257}
258
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700259void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices,
260 bool preferMockICD,
261 VkPhysicalDevice *physicalDeviceOut,
262 VkPhysicalDeviceProperties *physicalDevicePropertiesOut)
263{
264 ASSERT(!physicalDevices.empty());
265 if (preferMockICD)
266 {
267 for (const VkPhysicalDevice &physicalDevice : physicalDevices)
268 {
269 vkGetPhysicalDeviceProperties(physicalDevice, physicalDevicePropertiesOut);
270 if ((kMockVendorID == physicalDevicePropertiesOut->vendorID) &&
271 (kMockDeviceID == physicalDevicePropertiesOut->deviceID) &&
272 (strcmp(kMockDeviceName, physicalDevicePropertiesOut->deviceName) == 0))
273 {
274 *physicalDeviceOut = physicalDevice;
275 return;
276 }
277 }
278 WARN() << "Vulkan Mock Driver was requested but Mock Device was not found. Using default "
279 "physicalDevice instead.";
280 }
281
282 // Fall back to first device.
283 *physicalDeviceOut = physicalDevices[0];
284 vkGetPhysicalDeviceProperties(*physicalDeviceOut, physicalDevicePropertiesOut);
285}
286
Frank Henigman29f148b2016-11-23 21:05:36 -0500287vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName)
Jamie Madill327ba852016-11-30 12:38:28 -0500288{
Jamie Madilldf9ad2b2018-02-02 12:40:01 -0500289 ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs));
Yuly Novikov199f4292018-01-19 19:04:05 -0500290 mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers();
Jamie Madilla66779f2017-01-06 10:43:44 -0500291
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700292#if !defined(ANGLE_PLATFORM_ANDROID)
293 // Mock ICD does not currently run on Android
Jamie Madillaaca96e2018-06-12 10:19:48 -0400294 bool enableNullDriver = (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
295 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) ==
296 EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700297 if (enableNullDriver)
298 {
299 // Override environment variable to use built Mock ICD
300 // ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn
301 ANGLE_VK_CHECK(angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON),
302 VK_ERROR_INITIALIZATION_FAILED);
303 }
Jamie Madillaaca96e2018-06-12 10:19:48 -0400304#else
305 constexpr bool enableNullDriver = false;
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700306#endif // !defined(ANGLE_PLATFORM_ANDROID)
Jamie Madill0448ec82016-12-23 13:41:47 -0500307 // Gather global layer properties.
308 uint32_t instanceLayerCount = 0;
309 ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr));
310
311 std::vector<VkLayerProperties> instanceLayerProps(instanceLayerCount);
312 if (instanceLayerCount > 0)
313 {
314 ANGLE_VK_TRY(
315 vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProps.data()));
316 }
317
Jamie Madille09bd5d2016-11-29 16:20:35 -0500318 uint32_t instanceExtensionCount = 0;
319 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr));
320
321 std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount);
322 if (instanceExtensionCount > 0)
323 {
324 ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount,
325 instanceExtensionProps.data()));
326 }
327
Yuly Novikov199f4292018-01-19 19:04:05 -0500328 const char *const *enabledLayerNames = nullptr;
329 uint32_t enabledLayerCount = 0;
Jamie Madill0448ec82016-12-23 13:41:47 -0500330 if (mEnableValidationLayers)
331 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500332 bool layersRequested =
333 (attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE) == EGL_TRUE);
334 mEnableValidationLayers = GetAvailableValidationLayers(
335 instanceLayerProps, layersRequested, &enabledLayerNames, &enabledLayerCount);
Jamie Madill0448ec82016-12-23 13:41:47 -0500336 }
337
Jamie Madille09bd5d2016-11-29 16:20:35 -0500338 std::vector<const char *> enabledInstanceExtensions;
339 enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
Frank Henigman29f148b2016-11-23 21:05:36 -0500340 enabledInstanceExtensions.push_back(wsiName);
Jamie Madille09bd5d2016-11-29 16:20:35 -0500341
Jamie Madill0448ec82016-12-23 13:41:47 -0500342 // TODO(jmadill): Should be able to continue initialization if debug report ext missing.
343 if (mEnableValidationLayers)
344 {
345 enabledInstanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
346 }
347
Jamie Madille09bd5d2016-11-29 16:20:35 -0500348 // Verify the required extensions are in the extension names set. Fail if not.
349 ANGLE_VK_TRY(VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions));
350
Jamie Madill327ba852016-11-30 12:38:28 -0500351 VkApplicationInfo applicationInfo;
352 applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
353 applicationInfo.pNext = nullptr;
354 applicationInfo.pApplicationName = "ANGLE";
355 applicationInfo.applicationVersion = 1;
356 applicationInfo.pEngineName = "ANGLE";
357 applicationInfo.engineVersion = 1;
358 applicationInfo.apiVersion = VK_API_VERSION_1_0;
359
360 VkInstanceCreateInfo instanceInfo;
361 instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
362 instanceInfo.pNext = nullptr;
363 instanceInfo.flags = 0;
364 instanceInfo.pApplicationInfo = &applicationInfo;
365
Jamie Madille09bd5d2016-11-29 16:20:35 -0500366 // Enable requested layers and extensions.
367 instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size());
368 instanceInfo.ppEnabledExtensionNames =
369 enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data();
Yuly Novikov199f4292018-01-19 19:04:05 -0500370 instanceInfo.enabledLayerCount = enabledLayerCount;
371 instanceInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill327ba852016-11-30 12:38:28 -0500372
373 ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance));
374
Jamie Madill0448ec82016-12-23 13:41:47 -0500375 if (mEnableValidationLayers)
376 {
377 VkDebugReportCallbackCreateInfoEXT debugReportInfo;
378
379 debugReportInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
380 debugReportInfo.pNext = nullptr;
381 debugReportInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT |
382 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
383 VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
384 debugReportInfo.pfnCallback = &DebugReportCallback;
385 debugReportInfo.pUserData = this;
386
387 auto createDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(
388 vkGetInstanceProcAddr(mInstance, "vkCreateDebugReportCallbackEXT"));
389 ASSERT(createDebugReportCallback);
390 ANGLE_VK_TRY(
391 createDebugReportCallback(mInstance, &debugReportInfo, nullptr, &mDebugReportCallback));
392 }
393
Jamie Madill4d0bf552016-12-28 15:45:24 -0500394 uint32_t physicalDeviceCount = 0;
395 ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, nullptr));
396 ANGLE_VK_CHECK(physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED);
397
398 // TODO(jmadill): Handle multiple physical devices. For now, use the first device.
Tobin Ehlisa3b220f2018-03-06 16:22:13 -0700399 std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
400 ANGLE_VK_TRY(
401 vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data()));
402 ChoosePhysicalDevice(physicalDevices, enableNullDriver, &mPhysicalDevice,
403 &mPhysicalDeviceProperties);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500404
405 // Ensure we can find a graphics queue family.
406 uint32_t queueCount = 0;
407 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
408
409 ANGLE_VK_CHECK(queueCount > 0, VK_ERROR_INITIALIZATION_FAILED);
410
411 mQueueFamilyProperties.resize(queueCount);
412 vkGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount,
413 mQueueFamilyProperties.data());
414
415 size_t graphicsQueueFamilyCount = false;
416 uint32_t firstGraphicsQueueFamily = 0;
417 for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex)
418 {
419 const auto &queueInfo = mQueueFamilyProperties[familyIndex];
420 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
421 {
422 ASSERT(queueInfo.queueCount > 0);
423 graphicsQueueFamilyCount++;
424 if (firstGraphicsQueueFamily == 0)
425 {
426 firstGraphicsQueueFamily = familyIndex;
427 }
428 break;
429 }
430 }
431
432 ANGLE_VK_CHECK(graphicsQueueFamilyCount > 0, VK_ERROR_INITIALIZATION_FAILED);
433
434 // If only one queue family, go ahead and initialize the device. If there is more than one
435 // queue, we'll have to wait until we see a WindowSurface to know which supports present.
436 if (graphicsQueueFamilyCount == 1)
437 {
438 ANGLE_TRY(initializeDevice(firstGraphicsQueueFamily));
439 }
440
Jamie Madill035fd6b2017-10-03 15:43:22 -0400441 // Store the physical device memory properties so we can find the right memory pools.
442 mMemoryProperties.init(mPhysicalDevice);
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500443
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500444 mGlslangWrapper = GlslangWrapper::GetReference();
445
Jamie Madill6a89d222017-11-02 11:59:51 -0400446 // Initialize the format table.
Luc Ferrond50537a2018-02-07 17:02:08 -0500447 mFormatTable.initialize(mPhysicalDevice, &mNativeTextureCaps,
448 &mNativeCaps.compressedTextureFormats);
Jamie Madill6a89d222017-11-02 11:59:51 -0400449
Jamie Madill327ba852016-11-30 12:38:28 -0500450 return vk::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400451}
452
Jamie Madill4d0bf552016-12-28 15:45:24 -0500453vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex)
454{
455 uint32_t deviceLayerCount = 0;
456 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount, nullptr));
457
458 std::vector<VkLayerProperties> deviceLayerProps(deviceLayerCount);
459 if (deviceLayerCount > 0)
460 {
461 ANGLE_VK_TRY(vkEnumerateDeviceLayerProperties(mPhysicalDevice, &deviceLayerCount,
462 deviceLayerProps.data()));
463 }
464
465 uint32_t deviceExtensionCount = 0;
466 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr,
467 &deviceExtensionCount, nullptr));
468
469 std::vector<VkExtensionProperties> deviceExtensionProps(deviceExtensionCount);
470 if (deviceExtensionCount > 0)
471 {
472 ANGLE_VK_TRY(vkEnumerateDeviceExtensionProperties(
473 mPhysicalDevice, nullptr, &deviceExtensionCount, deviceExtensionProps.data()));
474 }
475
Yuly Novikov199f4292018-01-19 19:04:05 -0500476 const char *const *enabledLayerNames = nullptr;
477 uint32_t enabledLayerCount = 0;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500478 if (mEnableValidationLayers)
479 {
Yuly Novikov199f4292018-01-19 19:04:05 -0500480 mEnableValidationLayers = GetAvailableValidationLayers(
481 deviceLayerProps, false, &enabledLayerNames, &enabledLayerCount);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500482 }
483
484 std::vector<const char *> enabledDeviceExtensions;
485 enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
486
Luc Ferronbf6dc372018-06-28 15:24:19 -0400487 // Selectively enable KHR_MAINTENANCE1 to support viewport flipping.
488 if (getFeatures().flipViewportY)
489 {
490 enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
491 }
492
Jamie Madill4d0bf552016-12-28 15:45:24 -0500493 ANGLE_VK_TRY(VerifyExtensionsPresent(deviceExtensionProps, enabledDeviceExtensions));
494
495 VkDeviceQueueCreateInfo queueCreateInfo;
496
497 float zeroPriority = 0.0f;
498
499 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
500 queueCreateInfo.pNext = nullptr;
501 queueCreateInfo.flags = 0;
502 queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
503 queueCreateInfo.queueCount = 1;
504 queueCreateInfo.pQueuePriorities = &zeroPriority;
505
506 // Initialize the device
507 VkDeviceCreateInfo createInfo;
508
Jamie Madill50cf2be2018-06-15 09:46:57 -0400509 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
510 createInfo.pNext = nullptr;
511 createInfo.flags = 0;
512 createInfo.queueCreateInfoCount = 1;
513 createInfo.pQueueCreateInfos = &queueCreateInfo;
Yuly Novikov199f4292018-01-19 19:04:05 -0500514 createInfo.enabledLayerCount = enabledLayerCount;
515 createInfo.ppEnabledLayerNames = enabledLayerNames;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500516 createInfo.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size());
517 createInfo.ppEnabledExtensionNames =
518 enabledDeviceExtensions.empty() ? nullptr : enabledDeviceExtensions.data();
519 createInfo.pEnabledFeatures = nullptr; // TODO(jmadill): features
520
521 ANGLE_VK_TRY(vkCreateDevice(mPhysicalDevice, &createInfo, nullptr, &mDevice));
522
523 mCurrentQueueFamilyIndex = queueFamilyIndex;
524
525 vkGetDeviceQueue(mDevice, mCurrentQueueFamilyIndex, 0, &mQueue);
526
527 // Initialize the command pool now that we know the queue family index.
528 VkCommandPoolCreateInfo commandPoolInfo;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500529 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
530 commandPoolInfo.pNext = nullptr;
531 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500532 commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
533
Jamie Madill5deea722017-02-16 10:44:46 -0500534 ANGLE_TRY(mCommandPool.init(mDevice, commandPoolInfo));
Jamie Madill4d0bf552016-12-28 15:45:24 -0500535
Jamie Madill4d0bf552016-12-28 15:45:24 -0500536 return vk::NoError();
537}
538
539vk::ErrorOrResult<uint32_t> RendererVk::selectPresentQueueForSurface(VkSurfaceKHR surface)
540{
541 // We've already initialized a device, and can't re-create it unless it's never been used.
542 // TODO(jmadill): Handle the re-creation case if necessary.
543 if (mDevice != VK_NULL_HANDLE)
544 {
545 ASSERT(mCurrentQueueFamilyIndex != std::numeric_limits<uint32_t>::max());
546
547 // Check if the current device supports present on this surface.
548 VkBool32 supportsPresent = VK_FALSE;
549 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, mCurrentQueueFamilyIndex,
550 surface, &supportsPresent));
551
552 return (supportsPresent == VK_TRUE);
553 }
554
555 // Find a graphics and present queue.
556 Optional<uint32_t> newPresentQueue;
557 uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size());
558 for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex)
559 {
560 const auto &queueInfo = mQueueFamilyProperties[queueIndex];
561 if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
562 {
563 VkBool32 supportsPresent = VK_FALSE;
564 ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, queueIndex, surface,
565 &supportsPresent));
566
567 if (supportsPresent == VK_TRUE)
568 {
569 newPresentQueue = queueIndex;
570 break;
571 }
572 }
573 }
574
575 ANGLE_VK_CHECK(newPresentQueue.valid(), VK_ERROR_INITIALIZATION_FAILED);
576 ANGLE_TRY(initializeDevice(newPresentQueue.value()));
577
578 return newPresentQueue.value();
579}
580
581std::string RendererVk::getVendorString() const
582{
Olli Etuahoc6a06182018-04-13 14:11:46 +0300583 return GetVendorString(mPhysicalDeviceProperties.vendorID);
Jamie Madill4d0bf552016-12-28 15:45:24 -0500584}
585
Jamie Madille09bd5d2016-11-29 16:20:35 -0500586std::string RendererVk::getRendererDescription() const
587{
Jamie Madill4d0bf552016-12-28 15:45:24 -0500588 std::stringstream strstr;
589
590 uint32_t apiVersion = mPhysicalDeviceProperties.apiVersion;
591
592 strstr << "Vulkan ";
593 strstr << VK_VERSION_MAJOR(apiVersion) << ".";
594 strstr << VK_VERSION_MINOR(apiVersion) << ".";
595 strstr << VK_VERSION_PATCH(apiVersion);
596
Olli Etuahoc6a06182018-04-13 14:11:46 +0300597 strstr << "(";
598
599 // In the case of NVIDIA, deviceName does not necessarily contain "NVIDIA". Add "NVIDIA" so that
600 // Vulkan end2end tests can be selectively disabled on NVIDIA. TODO(jmadill): should not be
601 // needed after http://anglebug.com/1874 is fixed and end2end_tests use more sophisticated
602 // driver detection.
603 if (mPhysicalDeviceProperties.vendorID == VENDOR_ID_NVIDIA)
604 {
605 strstr << GetVendorString(mPhysicalDeviceProperties.vendorID) << " ";
606 }
607
608 strstr << mPhysicalDeviceProperties.deviceName << ")";
Jamie Madill4d0bf552016-12-28 15:45:24 -0500609
610 return strstr.str();
Jamie Madille09bd5d2016-11-29 16:20:35 -0500611}
612
Jamie Madillacccc6c2016-05-03 17:22:10 -0400613void RendererVk::ensureCapsInitialized() const
614{
615 if (!mCapsInitialized)
616 {
Luc Ferrond50537a2018-02-07 17:02:08 -0500617 vk::GenerateCaps(mPhysicalDeviceProperties, mNativeTextureCaps, &mNativeCaps,
Jamie Madill1266d202018-06-29 09:11:34 -0400618 &mNativeExtensions, &mNativeLimitations, &mFeatures);
Jamie Madillacccc6c2016-05-03 17:22:10 -0400619 mCapsInitialized = true;
620 }
621}
622
Jamie Madillacccc6c2016-05-03 17:22:10 -0400623const gl::Caps &RendererVk::getNativeCaps() const
624{
625 ensureCapsInitialized();
626 return mNativeCaps;
627}
628
629const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const
630{
631 ensureCapsInitialized();
632 return mNativeTextureCaps;
633}
634
635const gl::Extensions &RendererVk::getNativeExtensions() const
636{
637 ensureCapsInitialized();
638 return mNativeExtensions;
639}
640
641const gl::Limitations &RendererVk::getNativeLimitations() const
642{
643 ensureCapsInitialized();
644 return mNativeLimitations;
645}
646
Luc Ferrondaedf4d2018-03-16 09:28:53 -0400647uint32_t RendererVk::getMaxActiveTextures()
648{
649 // TODO(lucferron): expose this limitation to GL in Context Caps
650 return std::min<uint32_t>(mPhysicalDeviceProperties.limits.maxPerStageDescriptorSamplers,
651 gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
652}
653
Jamie Madill49ac74b2017-12-21 14:42:33 -0500654const vk::CommandPool &RendererVk::getCommandPool() const
Jamie Madill4d0bf552016-12-28 15:45:24 -0500655{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500656 return mCommandPool;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500657}
658
Jamie Madill49ac74b2017-12-21 14:42:33 -0500659vk::Error RendererVk::finish(const gl::Context *context)
Jamie Madill4d0bf552016-12-28 15:45:24 -0500660{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500661 if (!mCommandGraph.empty())
Jamie Madill49ac74b2017-12-21 14:42:33 -0500662 {
663 vk::CommandBuffer commandBatch;
664 ANGLE_TRY(flushCommandGraph(context, &commandBatch));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400665
Jamie Madill49ac74b2017-12-21 14:42:33 -0500666 VkSubmitInfo submitInfo;
667 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
668 submitInfo.pNext = nullptr;
669 submitInfo.waitSemaphoreCount = 0;
670 submitInfo.pWaitSemaphores = nullptr;
671 submitInfo.pWaitDstStageMask = nullptr;
672 submitInfo.commandBufferCount = 1;
673 submitInfo.pCommandBuffers = commandBatch.ptr();
674 submitInfo.signalSemaphoreCount = 0;
675 submitInfo.pSignalSemaphores = nullptr;
Jamie Madill4d0bf552016-12-28 15:45:24 -0500676
Jamie Madill49ac74b2017-12-21 14:42:33 -0500677 ANGLE_TRY(submitFrame(submitInfo, std::move(commandBatch)));
678 }
Jamie Madill4d0bf552016-12-28 15:45:24 -0500679
Jamie Madill4c26fc22017-02-24 11:04:10 -0500680 ASSERT(mQueue != VK_NULL_HANDLE);
Jamie Madill4c26fc22017-02-24 11:04:10 -0500681 ANGLE_VK_TRY(vkQueueWaitIdle(mQueue));
Jamie Madill0c0dc342017-03-24 14:18:51 -0400682 freeAllInFlightResources();
Jamie Madill4c26fc22017-02-24 11:04:10 -0500683 return vk::NoError();
684}
685
Jamie Madill0c0dc342017-03-24 14:18:51 -0400686void RendererVk::freeAllInFlightResources()
687{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500688 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill0c0dc342017-03-24 14:18:51 -0400689 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500690 batch.fence.destroy(mDevice);
691 batch.commandPool.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400692 }
693 mInFlightCommands.clear();
694
695 for (auto &garbage : mGarbage)
696 {
Jamie Madille88ec8e2017-10-31 17:18:14 -0400697 garbage.destroy(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400698 }
699 mGarbage.clear();
700}
701
Jamie Madill4c26fc22017-02-24 11:04:10 -0500702vk::Error RendererVk::checkInFlightCommands()
703{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500704 int finishedCount = 0;
Jamie Madillf651c772017-02-21 15:03:51 -0500705
Jamie Madill49ac74b2017-12-21 14:42:33 -0500706 for (CommandBatch &batch : mInFlightCommands)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500707 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500708 VkResult result = batch.fence.getStatus(mDevice);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400709 if (result == VK_NOT_READY)
710 break;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500711
Jamie Madill0c0dc342017-03-24 14:18:51 -0400712 ANGLE_VK_TRY(result);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500713 ASSERT(batch.serial > mLastCompletedQueueSerial);
714 mLastCompletedQueueSerial = batch.serial;
Jamie Madill0c0dc342017-03-24 14:18:51 -0400715
Jamie Madill49ac74b2017-12-21 14:42:33 -0500716 batch.fence.destroy(mDevice);
717 batch.commandPool.destroy(mDevice);
718 ++finishedCount;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500719 }
720
Jamie Madill49ac74b2017-12-21 14:42:33 -0500721 mInFlightCommands.erase(mInFlightCommands.begin(), mInFlightCommands.begin() + finishedCount);
Jamie Madill0c0dc342017-03-24 14:18:51 -0400722
723 size_t freeIndex = 0;
724 for (; freeIndex < mGarbage.size(); ++freeIndex)
725 {
Jamie Madill49ac74b2017-12-21 14:42:33 -0500726 if (!mGarbage[freeIndex].destroyIfComplete(mDevice, mLastCompletedQueueSerial))
Jamie Madill0c0dc342017-03-24 14:18:51 -0400727 break;
728 }
729
730 // Remove the entries from the garbage list - they should be ready to go.
731 if (freeIndex > 0)
732 {
733 mGarbage.erase(mGarbage.begin(), mGarbage.begin() + freeIndex);
Jamie Madillf651c772017-02-21 15:03:51 -0500734 }
735
Jamie Madill4c26fc22017-02-24 11:04:10 -0500736 return vk::NoError();
737}
738
Jamie Madill49ac74b2017-12-21 14:42:33 -0500739vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo, vk::CommandBuffer &&commandBuffer)
Jamie Madill4c26fc22017-02-24 11:04:10 -0500740{
Jamie Madill49ac74b2017-12-21 14:42:33 -0500741 VkFenceCreateInfo fenceInfo;
742 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
743 fenceInfo.pNext = nullptr;
744 fenceInfo.flags = 0;
745
Jamie Madillbea35a62018-07-05 11:54:10 -0400746 vk::Scoped<CommandBatch> scopedBatch(mDevice);
747 CommandBatch &batch = scopedBatch.get();
Jamie Madill49ac74b2017-12-21 14:42:33 -0500748 ANGLE_TRY(batch.fence.init(mDevice, fenceInfo));
749
750 ANGLE_VK_TRY(vkQueueSubmit(mQueue, 1, &submitInfo, batch.fence.getHandle()));
Jamie Madill4c26fc22017-02-24 11:04:10 -0500751
752 // Store this command buffer in the in-flight list.
Jamie Madill49ac74b2017-12-21 14:42:33 -0500753 batch.commandPool = std::move(mCommandPool);
754 batch.serial = mCurrentQueueSerial;
Jamie Madill4c26fc22017-02-24 11:04:10 -0500755
Jamie Madillbea35a62018-07-05 11:54:10 -0400756 mInFlightCommands.emplace_back(scopedBatch.release());
Jamie Madill0c0dc342017-03-24 14:18:51 -0400757
758 // Sanity check.
759 ASSERT(mInFlightCommands.size() < 1000u);
760
761 // Increment the queue serial. If this fails, we should restart ANGLE.
Jamie Madillfb05bcb2017-06-07 15:43:18 -0400762 // TODO(jmadill): Overflow check.
763 mCurrentQueueSerial = mQueueSerialFactory.generate();
Jamie Madill0c0dc342017-03-24 14:18:51 -0400764
765 ANGLE_TRY(checkInFlightCommands());
766
Jamie Madill49ac74b2017-12-21 14:42:33 -0500767 // Simply null out the command buffer here - it was allocated using the command pool.
768 commandBuffer.releaseHandle();
769
770 // Reallocate the command pool for next frame.
771 // TODO(jmadill): Consider reusing command pools.
772 VkCommandPoolCreateInfo poolInfo;
773 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
774 poolInfo.pNext = nullptr;
775 poolInfo.flags = 0;
776 poolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
777
778 mCommandPool.init(mDevice, poolInfo);
779
Jamie Madill4c26fc22017-02-24 11:04:10 -0500780 return vk::NoError();
781}
782
Jamie Madillaaca96e2018-06-12 10:19:48 -0400783GlslangWrapper *RendererVk::getGlslangWrapper() const
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500784{
785 return mGlslangWrapper;
786}
787
Jamie Madill4c26fc22017-02-24 11:04:10 -0500788Serial RendererVk::getCurrentQueueSerial() const
789{
790 return mCurrentQueueSerial;
791}
792
Jamie Madillaaca96e2018-06-12 10:19:48 -0400793bool RendererVk::isSerialInUse(Serial serial) const
Jamie Madill97760352017-11-09 13:08:29 -0500794{
795 return serial > mLastCompletedQueueSerial;
796}
797
Jamie Madill9f2a8612017-11-30 12:43:09 -0500798vk::Error RendererVk::getCompatibleRenderPass(const vk::RenderPassDesc &desc,
799 vk::RenderPass **renderPassOut)
800{
801 return mRenderPassCache.getCompatibleRenderPass(mDevice, mCurrentQueueSerial, desc,
802 renderPassOut);
803}
804
Jamie Madillbef918c2017-12-13 13:11:30 -0500805vk::Error RendererVk::getRenderPassWithOps(const vk::RenderPassDesc &desc,
806 const vk::AttachmentOpsArray &ops,
807 vk::RenderPass **renderPassOut)
Jamie Madill9f2a8612017-11-30 12:43:09 -0500808{
Jamie Madillbef918c2017-12-13 13:11:30 -0500809 return mRenderPassCache.getRenderPassWithOps(mDevice, mCurrentQueueSerial, desc, ops,
810 renderPassOut);
Jamie Madill9f2a8612017-11-30 12:43:09 -0500811}
812
Jamie Madilla5e06072018-05-18 14:36:05 -0400813vk::CommandGraph *RendererVk::getCommandGraph()
Jamie Madill49ac74b2017-12-21 14:42:33 -0500814{
Jamie Madilla5e06072018-05-18 14:36:05 -0400815 return &mCommandGraph;
Jamie Madill49ac74b2017-12-21 14:42:33 -0500816}
817
818vk::Error RendererVk::flushCommandGraph(const gl::Context *context, vk::CommandBuffer *commandBatch)
819{
Jamie Madill1f46bc12018-02-20 16:09:43 -0500820 return mCommandGraph.submitCommands(mDevice, mCurrentQueueSerial, &mRenderPassCache,
821 &mCommandPool, commandBatch);
Jamie Madill49ac74b2017-12-21 14:42:33 -0500822}
823
824vk::Error RendererVk::flush(const gl::Context *context,
825 const vk::Semaphore &waitSemaphore,
826 const vk::Semaphore &signalSemaphore)
827{
Jamie Madillbea35a62018-07-05 11:54:10 -0400828 vk::Scoped<vk::CommandBuffer> commandBatch(mDevice);
829 ANGLE_TRY(flushCommandGraph(context, &commandBatch.get()));
Jamie Madill49ac74b2017-12-21 14:42:33 -0500830
831 VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
832
833 VkSubmitInfo submitInfo;
834 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
835 submitInfo.pNext = nullptr;
836 submitInfo.waitSemaphoreCount = 1;
837 submitInfo.pWaitSemaphores = waitSemaphore.ptr();
838 submitInfo.pWaitDstStageMask = &waitStageMask;
839 submitInfo.commandBufferCount = 1;
Jamie Madillbea35a62018-07-05 11:54:10 -0400840 submitInfo.pCommandBuffers = commandBatch.get().ptr();
Jamie Madill49ac74b2017-12-21 14:42:33 -0500841 submitInfo.signalSemaphoreCount = 1;
842 submitInfo.pSignalSemaphores = signalSemaphore.ptr();
843
Jamie Madillbea35a62018-07-05 11:54:10 -0400844 ANGLE_TRY(submitFrame(submitInfo, commandBatch.release()));
Jamie Madill49ac74b2017-12-21 14:42:33 -0500845 return vk::NoError();
846}
847
Jamie Madill78feddc2018-04-27 11:45:05 -0400848Serial RendererVk::issueShaderSerial()
Jamie Madillf2f6d372018-01-10 21:37:23 -0500849{
Jamie Madill78feddc2018-04-27 11:45:05 -0400850 return mShaderSerialFactory.generate();
Jamie Madillf2f6d372018-01-10 21:37:23 -0500851}
852
Jamie Madill9aef3672018-04-27 11:45:06 -0400853vk::Error RendererVk::getAppPipeline(const ProgramVk *programVk,
854 const vk::PipelineDesc &desc,
855 const gl::AttributesMask &activeAttribLocationsMask,
856 vk::PipelineAndSerial **pipelineOut)
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500857{
Jamie Madill33318de2018-05-01 11:22:54 -0400858 ASSERT(programVk->getVertexModuleSerial() ==
859 desc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial);
860 ASSERT(programVk->getFragmentModuleSerial() ==
861 desc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial);
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500862
863 // Pull in a compatible RenderPass.
864 vk::RenderPass *compatibleRenderPass = nullptr;
865 ANGLE_TRY(getCompatibleRenderPass(desc.getRenderPassDesc(), &compatibleRenderPass));
866
Jamie Madill9b168d02018-06-13 13:25:32 -0400867 const vk::PipelineLayout &pipelineLayout = programVk->getPipelineLayout();
868
Jamie Madillc7918ce2018-06-13 13:25:31 -0400869 return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout,
Luc Ferronceb71902018-02-05 15:18:47 -0500870 activeAttribLocationsMask, programVk->getLinkedVertexModule(),
Jamie Madillffa4cbb2018-01-23 13:04:07 -0500871 programVk->getLinkedFragmentModule(), desc, pipelineOut);
872}
873
Jamie Madill9aef3672018-04-27 11:45:06 -0400874vk::Error RendererVk::getInternalPipeline(const vk::ShaderAndSerial &vertexShader,
875 const vk::ShaderAndSerial &fragmentShader,
876 const vk::PipelineLayout &pipelineLayout,
877 const vk::PipelineDesc &pipelineDesc,
878 const gl::AttributesMask &activeAttribLocationsMask,
879 vk::PipelineAndSerial **pipelineOut)
880{
881 ASSERT(vertexShader.queueSerial() ==
882 pipelineDesc.getShaderStageInfo()[vk::ShaderType::VertexShader].moduleSerial);
883 ASSERT(fragmentShader.queueSerial() ==
884 pipelineDesc.getShaderStageInfo()[vk::ShaderType::FragmentShader].moduleSerial);
885
886 // Pull in a compatible RenderPass.
887 vk::RenderPass *compatibleRenderPass = nullptr;
888 ANGLE_TRY(getCompatibleRenderPass(pipelineDesc.getRenderPassDesc(), &compatibleRenderPass));
889
890 return mPipelineCache.getPipeline(mDevice, *compatibleRenderPass, pipelineLayout,
891 activeAttribLocationsMask, vertexShader.get(),
892 fragmentShader.get(), pipelineDesc, pipelineOut);
893}
894
Jamie Madill9b168d02018-06-13 13:25:32 -0400895vk::Error RendererVk::getDescriptorSetLayout(
896 const vk::DescriptorSetLayoutDesc &desc,
897 vk::BindingPointer<vk::DescriptorSetLayout> *descriptorSetLayoutOut)
898{
899 return mDescriptorSetLayoutCache.getDescriptorSetLayout(mDevice, desc, descriptorSetLayoutOut);
900}
901
902vk::Error RendererVk::getPipelineLayout(
903 const vk::PipelineLayoutDesc &desc,
904 const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts,
905 vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut)
906{
907 return mPipelineLayoutCache.getPipelineLayout(mDevice, desc, descriptorSetLayouts,
908 pipelineLayoutOut);
909}
910
Jamie Madilld47044a2018-04-27 11:45:03 -0400911vk::ShaderLibrary *RendererVk::getShaderLibrary()
912{
913 return &mShaderLibrary;
914}
Luc Ferron90968362018-05-04 08:47:22 -0400915
Jamie Madillaaca96e2018-06-12 10:19:48 -0400916uint32_t GetUniformBufferDescriptorCount()
917{
918 return kUniformBufferDescriptorsPerDescriptorSet;
919}
920
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400921} // namespace rx