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() ...@@ -145,7 +145,8 @@ EGLAttrib GetDisplayTypeFromEnvironment()
angle::ToLower(&angleDefaultEnv); angle::ToLower(&angleDefaultEnv);
#if defined(ANGLE_ENABLE_VULKAN) #if defined(ANGLE_ENABLE_VULKAN)
if (angleDefaultEnv == "vulkan") if ((angleDefaultEnv == "vulkan") || (angleDefaultEnv == "vulkan-null") ||
(angleDefaultEnv == "swiftshader"))
{ {
return EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE; return EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
} }
...@@ -195,16 +196,28 @@ EGLAttrib GetDisplayTypeFromEnvironment() ...@@ -195,16 +196,28 @@ EGLAttrib GetDisplayTypeFromEnvironment()
#endif #endif
} }
rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap, const DisplayState &state) EGLAttrib GetDeviceTypeFromEnvironment()
{ {
rx::DisplayImpl *impl = nullptr; std::string angleDefaultEnv = angle::GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM");
EGLAttrib displayType = angle::ToLower(&angleDefaultEnv);
attribMap.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
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) switch (displayType)
{ {
...@@ -405,14 +418,19 @@ Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay ...@@ -405,14 +418,19 @@ Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay
// Apply new attributes if the display is not initialized yet. // Apply new attributes if the display is not initialized yet.
if (!display->isInitialized()) 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) if (impl == nullptr)
{ {
// No valid display implementation for these attributes // No valid display implementation for these attributes
return nullptr; return nullptr;
} }
display->setAttributes(impl, attribMap); display->setupDisplayPlatform(impl);
} }
return display; return display;
...@@ -473,8 +491,9 @@ Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attri ...@@ -473,8 +491,9 @@ Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attri
// Apply new attributes if the display is not initialized yet. // Apply new attributes if the display is not initialized yet.
if (!display->isInitialized()) if (!display->isInitialized())
{ {
display->setAttributes(attribMap);
rx::DisplayImpl *impl = CreateDisplayFromDevice(device, display->getState()); rx::DisplayImpl *impl = CreateDisplayFromDevice(device, display->getState());
display->setAttributes(impl, attribMap); display->setupDisplayPlatform(impl);
} }
return display; return display;
...@@ -544,7 +563,7 @@ EGLLabelKHR Display::getLabel() const ...@@ -544,7 +563,7 @@ EGLLabelKHR Display::getLabel() const
return mState.label; return mState.label;
} }
void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap) void Display::setupDisplayPlatform(rx::DisplayImpl *impl)
{ {
ASSERT(!mInitialized); ASSERT(!mInitialized);
...@@ -552,8 +571,6 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap ...@@ -552,8 +571,6 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap
SafeDelete(mImplementation); SafeDelete(mImplementation);
mImplementation = impl; mImplementation = impl;
mAttributeMap = attribMap;
// TODO(jmadill): Store Platform in Display and init here. // TODO(jmadill): Store Platform in Display and init here.
const angle::PlatformMethods *platformMethods = const angle::PlatformMethods *platformMethods =
reinterpret_cast<const angle::PlatformMethods *>( reinterpret_cast<const angle::PlatformMethods *>(
...@@ -577,6 +594,23 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap ...@@ -577,6 +594,23 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap
static_cast<bool>(mAttributeMap.get(EGL_FEATURE_ALL_DISABLED_ANGLE, 0)); 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() Error Display::initialize()
{ {
ASSERT(mImplementation != nullptr); ASSERT(mImplementation != nullptr);
......
...@@ -211,7 +211,11 @@ class Display final : public LabeledObject, angle::NonCopyable ...@@ -211,7 +211,11 @@ class Display final : public LabeledObject, angle::NonCopyable
private: private:
Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice); 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(); 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