Commit 3eaf6294 by Brandon Schade Committed by Commit Bot

Vulkan: Add options to select more device types

Add support to set a default device type using existing ANGLE_DEFAULT_PLATFORM environment variable. The valid vulkan options are as follows: vulkan - vulkan with device hardware vulkan-null - vulkan with null device (Mock ICD) swiftshader - vulkan with swiftshader Bug: angleproject:3998 Change-Id: I15f00e8024818fbaf674ca6fcdbcdac5a90cace2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1956140 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent f60da874
......@@ -145,7 +145,8 @@ EGLAttrib GetDisplayTypeFromEnvironment()
angle::ToLower(&angleDefaultEnv);
#if defined(ANGLE_ENABLE_VULKAN)
if (angleDefaultEnv == "vulkan")
if ((angleDefaultEnv == "vulkan") || (angleDefaultEnv == "vulkan-null") ||
(angleDefaultEnv == "swiftshader"))
{
return EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
}
......@@ -195,16 +196,28 @@ EGLAttrib GetDisplayTypeFromEnvironment()
#endif
}
rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap, const DisplayState &state)
EGLAttrib GetDeviceTypeFromEnvironment()
{
rx::DisplayImpl *impl = nullptr;
EGLAttrib displayType =
attribMap.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
std::string angleDefaultEnv = angle::GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM");
angle::ToLower(&angleDefaultEnv);
if (displayType == EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE)
#if defined(ANGLE_ENABLE_VULKAN)
if (angleDefaultEnv == "vulkan-null")
{
displayType = GetDisplayTypeFromEnvironment();
return EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE;
}
else if (angleDefaultEnv == "swiftshader")
{
return EGL_PLATFORM_ANGLE_DEVICE_TYPE_SWIFTSHADER_ANGLE;
}
#endif
return EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE;
}
rx::DisplayImpl *CreateDisplayFromAttribs(EGLAttrib displayType, const DisplayState &state)
{
ASSERT(displayType != EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
rx::DisplayImpl *impl = nullptr;
switch (displayType)
{
......@@ -405,14 +418,19 @@ Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay
// Apply new attributes if the display is not initialized yet.
if (!display->isInitialized())
{
rx::DisplayImpl *impl = CreateDisplayFromAttribs(attribMap, display->getState());
display->setAttributes(attribMap);
display->updateAttribsFromEnvironment(attribMap);
EGLAttrib displayType = display->mAttributeMap.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
rx::DisplayImpl *impl = CreateDisplayFromAttribs(displayType, display->getState());
if (impl == nullptr)
{
// No valid display implementation for these attributes
return nullptr;
}
display->setAttributes(impl, attribMap);
display->setupDisplayPlatform(impl);
}
return display;
......@@ -473,8 +491,9 @@ Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attri
// Apply new attributes if the display is not initialized yet.
if (!display->isInitialized())
{
display->setAttributes(attribMap);
rx::DisplayImpl *impl = CreateDisplayFromDevice(device, display->getState());
display->setAttributes(impl, attribMap);
display->setupDisplayPlatform(impl);
}
return display;
......@@ -544,7 +563,7 @@ EGLLabelKHR Display::getLabel() const
return mState.label;
}
void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap)
void Display::setupDisplayPlatform(rx::DisplayImpl *impl)
{
ASSERT(!mInitialized);
......@@ -552,8 +571,6 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap
SafeDelete(mImplementation);
mImplementation = impl;
mAttributeMap = attribMap;
// TODO(jmadill): Store Platform in Display and init here.
const angle::PlatformMethods *platformMethods =
reinterpret_cast<const angle::PlatformMethods *>(
......@@ -577,6 +594,23 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap
static_cast<bool>(mAttributeMap.get(EGL_FEATURE_ALL_DISABLED_ANGLE, 0));
}
void Display::updateAttribsFromEnvironment(const AttributeMap &attribMap)
{
EGLAttrib displayType =
attribMap.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
if (displayType == EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE)
{
displayType = GetDisplayTypeFromEnvironment();
mAttributeMap.insert(EGL_PLATFORM_ANGLE_TYPE_ANGLE, displayType);
}
EGLAttrib deviceType = attribMap.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, 0);
if (deviceType == 0)
{
deviceType = GetDeviceTypeFromEnvironment();
mAttributeMap.insert(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, deviceType);
}
}
Error Display::initialize()
{
ASSERT(mImplementation != nullptr);
......
......@@ -211,7 +211,11 @@ class Display final : public LabeledObject, angle::NonCopyable
private:
Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
void setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap);
void setAttributes(const AttributeMap &attribMap) { mAttributeMap = attribMap; }
void setupDisplayPlatform(rx::DisplayImpl *impl);
void updateAttribsFromEnvironment(const AttributeMap &attribMap);
Error restoreLostDevice();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment