Hash :
ccd9a43b
Author :
Date :
2024-05-22T11:15:39
Split EGL_ANGLE_device_d3d into D3D9 and D3D11 versions. Add EGL_ANGLE_device_d3d9 and EGL_ANGLE_device_d3d11 which make it possible to know what type of device can be queried ahead of time without generating EGL errors. Refactor the DeviceD3D class into Device9 and Device11. Remove the getType method now that it's not needed for internal validation. Keep EGL_ANGLE_device_d3d for backwards compatibility. Bug: angleproject:342096132 Change-Id: Ib950abad58e46a5be269891ea7afd0cb8534cbe8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5559163 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DeviceVk.cpp:
// Implements the class methods for DeviceVk.
//
#include "libANGLE/renderer/vulkan/DeviceVk.h"
#include <stdint.h>
#include "common/debug.h"
#include "common/vulkan/vulkan_icd.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/vk_renderer.h"
namespace rx
{
namespace
{
DeviceVk *gDevice = nullptr;
class [[nodiscard]] ScopedEnv : public angle::vk::ScopedVkLoaderEnvironment
{
public:
ScopedEnv()
: angle::vk::ScopedVkLoaderEnvironment(
gDevice ? gDevice->getRenderer()->getEnableValidationLayers() : false,
gDevice ? gDevice->getRenderer()->getEnabledICD() : angle::vk::ICD::Default)
{
if (!gDevice)
{
WARN() << "No DeviceVk instance.";
}
}
};
} // namespace
DeviceVk::DeviceVk() = default;
DeviceVk::~DeviceVk()
{
if (gDevice == this)
{
gDevice = nullptr;
}
}
egl::Error DeviceVk::initialize()
{
return egl::NoError();
}
egl::Error DeviceVk::getAttribute(const egl::Display *display, EGLint attribute, void **outValue)
{
vk::Renderer *renderer =
static_cast<rx::DisplayVk *>(display->getImplementation())->getRenderer();
ASSERT(mRenderer == nullptr || mRenderer == renderer);
mRenderer = renderer;
switch (attribute)
{
case EGL_VULKAN_VERSION_ANGLE:
{
auto version = static_cast<intptr_t>(mRenderer->getDeviceVersion());
*outValue = reinterpret_cast<void *>(version);
return egl::NoError();
}
case EGL_VULKAN_INSTANCE_ANGLE:
{
*outValue = mRenderer->getInstance();
return egl::NoError();
}
case EGL_VULKAN_DEVICE_ANGLE:
{
*outValue = mRenderer->getDevice();
return egl::NoError();
}
case EGL_VULKAN_PHYSICAL_DEVICE_ANGLE:
{
*outValue = mRenderer->getPhysicalDevice();
return egl::NoError();
}
case EGL_VULKAN_QUEUE_ANGLE:
{
// Usage of the Vulkan queue by the application is incompatible with the
// asyncCommandQueue feature; there is no way for the application to synchronize with
// the async thread's usage of the queue.
ASSERT(!mRenderer->getFeatures().asyncCommandQueue.enabled);
// egl::ContextPriority::Medium is the default context priority.
*outValue = mRenderer->getQueue(egl::ContextPriority::Medium);
return egl::NoError();
}
case EGL_VULKAN_QUEUE_FAMILIY_INDEX_ANGLE:
{
intptr_t index = static_cast<intptr_t>(mRenderer->getQueueFamilyIndex());
*outValue = reinterpret_cast<void *>(index);
return egl::NoError();
}
case EGL_VULKAN_DEVICE_EXTENSIONS_ANGLE:
{
char **extensions = const_cast<char **>(mRenderer->getEnabledDeviceExtensions().data());
*outValue = reinterpret_cast<void *>(extensions);
return egl::NoError();
}
case EGL_VULKAN_INSTANCE_EXTENSIONS_ANGLE:
{
char **extensions =
const_cast<char **>(mRenderer->getEnabledInstanceExtensions().data());
*outValue = reinterpret_cast<void *>(extensions);
return egl::NoError();
}
case EGL_VULKAN_FEATURES_ANGLE:
{
const auto *features = &mRenderer->getEnabledFeatures();
*outValue = const_cast<void *>(reinterpret_cast<const void *>(features));
return egl::NoError();
}
case EGL_VULKAN_GET_INSTANCE_PROC_ADDR:
{
*outValue = reinterpret_cast<void *>(DeviceVk::WrappedGetInstanceProcAddr);
ASSERT(!gDevice || gDevice == this);
gDevice = this;
return egl::NoError();
}
default:
return egl::EglBadAccess();
}
}
void DeviceVk::generateExtensions(egl::DeviceExtensions *outExtensions) const
{
outExtensions->deviceVulkan = true;
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance)
{
ScopedEnv scopedEnv;
return vkCreateInstance(pCreateInfo, pAllocator, pInstance);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedEnumerateInstanceExtensionProperties(const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedEnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceLayerProperties(pPropertyCount, pProperties);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL DeviceVk::WrappedEnumerateInstanceVersion(uint32_t *pApiVersion)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceVersion(pApiVersion);
}
// static
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DeviceVk::WrappedGetInstanceProcAddr(VkInstance instance,
const char *pName)
{
if (!pName || pName[0] != 'v' || pName[1] != 'k')
{
return nullptr;
}
if (instance != VK_NULL_HANDLE)
{
return vkGetInstanceProcAddr(instance, pName);
}
if (!strcmp(pName, "vkCreateInstance"))
{
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedCreateInstance);
}
if (!strcmp(pName, "vkEnumerateInstanceExtensionProperties"))
{
return reinterpret_cast<PFN_vkVoidFunction>(
DeviceVk::WrappedEnumerateInstanceExtensionProperties);
}
if (!strcmp(pName, "vkEnumerateInstanceLayerProperties"))
{
return reinterpret_cast<PFN_vkVoidFunction>(
DeviceVk::WrappedEnumerateInstanceLayerProperties);
}
if (!strcmp(pName, "vkEnumerateInstanceVersion"))
{
if (!vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"))
{
// Vulkan 1.0 doesn't have vkEnumerateInstanceVersion.
return nullptr;
}
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedEnumerateInstanceVersion);
}
if (!strcmp(pName, "vkGetInstanceProcAddr"))
{
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedGetInstanceProcAddr);
}
return vkGetInstanceProcAddr(instance, pName);
}
} // namespace rx