Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // RendererVk.cpp: |
| 7 | // Implements the class methods for RendererVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 11 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 12 | #include <EGL/eglext.h> |
| 13 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 14 | #include "common/debug.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 15 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
| 16 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 17 | #include "libANGLE/renderer/vulkan/TextureVk.h" |
| 18 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
| 19 | #include "platform/Platform.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 20 | |
| 21 | namespace rx |
| 22 | { |
| 23 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 24 | namespace |
| 25 | { |
| 26 | |
| 27 | VkResult VerifyExtensionsPresent(const std::vector<VkExtensionProperties> &extensionProps, |
| 28 | const std::vector<const char *> &enabledExtensionNames) |
| 29 | { |
| 30 | // Compile the extensions names into a set. |
| 31 | std::set<std::string> extensionNames; |
| 32 | for (const auto &extensionProp : extensionProps) |
| 33 | { |
| 34 | extensionNames.insert(extensionProp.extensionName); |
| 35 | } |
| 36 | |
| 37 | for (const auto &extensionName : enabledExtensionNames) |
| 38 | { |
| 39 | if (extensionNames.count(extensionName) == 0) |
| 40 | { |
| 41 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return VK_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | } // anonymous namespace |
| 49 | |
| 50 | RendererVk::RendererVk() : mCapsInitialized(false), mInstance(VK_NULL_HANDLE) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
| 54 | RendererVk::~RendererVk() |
| 55 | { |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 56 | vkDestroyInstance(mInstance, nullptr); |
| 57 | } |
| 58 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 59 | vk::Error RendererVk::initialize(const egl::AttributeMap &attribs) |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 60 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 61 | uint32_t instanceExtensionCount = 0; |
| 62 | ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr)); |
| 63 | |
| 64 | std::vector<VkExtensionProperties> instanceExtensionProps(instanceExtensionCount); |
| 65 | if (instanceExtensionCount > 0) |
| 66 | { |
| 67 | ANGLE_VK_TRY(vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, |
| 68 | instanceExtensionProps.data())); |
| 69 | } |
| 70 | |
| 71 | std::vector<const char *> enabledInstanceExtensions; |
| 72 | enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 73 | #if defined(ANGLE_PLATFORM_WINDOWS) |
| 74 | enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 75 | #else |
| 76 | #error Unsupported Vulkan platform. |
| 77 | #endif // defined(ANGLE_PLATFORM_WINDOWS) |
| 78 | |
| 79 | // Verify the required extensions are in the extension names set. Fail if not. |
| 80 | ANGLE_VK_TRY(VerifyExtensionsPresent(instanceExtensionProps, enabledInstanceExtensions)); |
| 81 | |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 82 | VkApplicationInfo applicationInfo; |
| 83 | applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 84 | applicationInfo.pNext = nullptr; |
| 85 | applicationInfo.pApplicationName = "ANGLE"; |
| 86 | applicationInfo.applicationVersion = 1; |
| 87 | applicationInfo.pEngineName = "ANGLE"; |
| 88 | applicationInfo.engineVersion = 1; |
| 89 | applicationInfo.apiVersion = VK_API_VERSION_1_0; |
| 90 | |
| 91 | VkInstanceCreateInfo instanceInfo; |
| 92 | instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
| 93 | instanceInfo.pNext = nullptr; |
| 94 | instanceInfo.flags = 0; |
| 95 | instanceInfo.pApplicationInfo = &applicationInfo; |
| 96 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 97 | // Enable requested layers and extensions. |
| 98 | instanceInfo.enabledExtensionCount = static_cast<uint32_t>(enabledInstanceExtensions.size()); |
| 99 | instanceInfo.ppEnabledExtensionNames = |
| 100 | enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data(); |
| 101 | instanceInfo.enabledLayerCount = 0u; |
| 102 | instanceInfo.ppEnabledLayerNames = nullptr; |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 103 | |
| 104 | ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance)); |
| 105 | |
| 106 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame^] | 109 | std::string RendererVk::getRendererDescription() const |
| 110 | { |
| 111 | // TODO(jmadill): Description. |
| 112 | return "Vulkan"; |
| 113 | } |
| 114 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 115 | void RendererVk::ensureCapsInitialized() const |
| 116 | { |
| 117 | if (!mCapsInitialized) |
| 118 | { |
| 119 | generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations); |
| 120 | mCapsInitialized = true; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void RendererVk::generateCaps(gl::Caps * /*outCaps*/, |
| 125 | gl::TextureCapsMap * /*outTextureCaps*/, |
| 126 | gl::Extensions * /*outExtensions*/, |
| 127 | gl::Limitations * /* outLimitations */) const |
| 128 | { |
Jamie Madill | 327ba85 | 2016-11-30 12:38:28 -0500 | [diff] [blame] | 129 | // TODO(jmadill): Caps. |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | const gl::Caps &RendererVk::getNativeCaps() const |
| 133 | { |
| 134 | ensureCapsInitialized(); |
| 135 | return mNativeCaps; |
| 136 | } |
| 137 | |
| 138 | const gl::TextureCapsMap &RendererVk::getNativeTextureCaps() const |
| 139 | { |
| 140 | ensureCapsInitialized(); |
| 141 | return mNativeTextureCaps; |
| 142 | } |
| 143 | |
| 144 | const gl::Extensions &RendererVk::getNativeExtensions() const |
| 145 | { |
| 146 | ensureCapsInitialized(); |
| 147 | return mNativeExtensions; |
| 148 | } |
| 149 | |
| 150 | const gl::Limitations &RendererVk::getNativeLimitations() const |
| 151 | { |
| 152 | ensureCapsInitialized(); |
| 153 | return mNativeLimitations; |
| 154 | } |
| 155 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 156 | } // namespace rx |