Commit 1f344d60 by Xiaoxuan Liu Committed by Commit Bot

Vulkan: Add support for headless surface

How to enable: add below args config to args.gn in linux build ``` use_x11=false use_ozone=false angle_vulkan_display_mode="headless" ``` Bug: angleproject:5260 Change-Id: Iec931e74c061b56376ef028814859aa58af07f2f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2536518 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent 60570b85
...@@ -367,11 +367,10 @@ rx::DisplayImpl *CreateDisplayFromAttribs(EGLAttrib displayType, ...@@ -367,11 +367,10 @@ rx::DisplayImpl *CreateDisplayFromAttribs(EGLAttrib displayType,
{ {
impl = rx::CreateVulkanSimpleDisplay(state); impl = rx::CreateVulkanSimpleDisplay(state);
} }
else if (platformType == EGL_PLATFORM_VULKAN_DISPLAY_MODE_HEADLESS_ANGLE) else if (platformType == EGL_PLATFORM_VULKAN_DISPLAY_MODE_HEADLESS_ANGLE &&
rx::IsVulkanHeadlessDisplayAvailable())
{ {
// TODO: anglebug.com/5260 impl = rx::CreateVulkanHeadlessDisplay(state);
// Add support for headless rendering
UNIMPLEMENTED();
} }
else else
{ {
......
...@@ -107,6 +107,10 @@ if (is_linux) { ...@@ -107,6 +107,10 @@ if (is_linux) {
"display/DisplayVkSimple.h", "display/DisplayVkSimple.h",
"display/WindowSurfaceVkSimple.cpp", "display/WindowSurfaceVkSimple.cpp",
"display/WindowSurfaceVkSimple.h", "display/WindowSurfaceVkSimple.h",
"headless/DisplayVkHeadless.cpp",
"headless/DisplayVkHeadless.h",
"headless/WindowSurfaceVkHeadless.cpp",
"headless/WindowSurfaceVkHeadless.h",
] ]
} }
......
...@@ -25,6 +25,9 @@ DisplayImpl *CreateVulkanXcbDisplay(const egl::DisplayState &state); ...@@ -25,6 +25,9 @@ DisplayImpl *CreateVulkanXcbDisplay(const egl::DisplayState &state);
bool IsVulkanSimpleDisplayAvailable(); bool IsVulkanSimpleDisplayAvailable();
DisplayImpl *CreateVulkanSimpleDisplay(const egl::DisplayState &state); DisplayImpl *CreateVulkanSimpleDisplay(const egl::DisplayState &state);
bool IsVulkanHeadlessDisplayAvailable();
DisplayImpl *CreateVulkanHeadlessDisplay(const egl::DisplayState &state);
#endif // defined(ANGLE_PLATFORM_LINUX) #endif // defined(ANGLE_PLATFORM_LINUX)
#if defined(ANGLE_PLATFORM_ANDROID) #if defined(ANGLE_PLATFORM_ANDROID)
......
//
// Copyright 2020 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.
//
// DisplayVkHeadless.cpp:
// Implements the class methods for DisplayVkHeadless.
//
#include "DisplayVkHeadless.h"
#include "WindowSurfaceVkHeadless.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
namespace rx
{
DisplayVkHeadless::DisplayVkHeadless(const egl::DisplayState &state) : DisplayVk(state) {}
void DisplayVkHeadless::terminate()
{
DisplayVk::terminate();
}
bool DisplayVkHeadless::isValidNativeWindow(EGLNativeWindowType window) const
{
return true;
}
SurfaceImpl *DisplayVkHeadless::createWindowSurfaceVk(const egl::SurfaceState &state,
EGLNativeWindowType window)
{
return new WindowSurfaceVkHeadless(state, window);
}
egl::ConfigSet DisplayVkHeadless::generateConfigs()
{
constexpr GLenum kColorFormats[] = {GL_RGBA8, GL_BGRA8_EXT, GL_RGB565, GL_RGB8};
return egl_vk::GenerateConfigs(kColorFormats, egl_vk::kConfigDepthStencilFormats, this);
}
void DisplayVkHeadless::checkConfigSupport(egl::Config *config) {}
const char *DisplayVkHeadless::getWSIExtension() const
{
return VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME;
}
bool IsVulkanHeadlessDisplayAvailable()
{
return true;
}
DisplayImpl *CreateVulkanHeadlessDisplay(const egl::DisplayState &state)
{
return new DisplayVkHeadless(state);
}
} // namespace rx
//
// Copyright 2020 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.
//
// DisplayVkHeadless.h:
// Defines the class interface for DisplayVkHeadless, implementing
// DisplayVk for Linux via VK_EXT_headless_surface.
//
#ifndef LIBANGLE_RENDERER_VULKAN_DISPLAY_DISPLAYVKHEADLESS_H_
#define LIBANGLE_RENDERER_VULKAN_DISPLAY_DISPLAYVKHEADLESS_H_
#include "libANGLE/renderer/vulkan/DisplayVk.h"
namespace rx
{
class DisplayVkHeadless : public DisplayVk
{
public:
DisplayVkHeadless(const egl::DisplayState &state);
void terminate() override;
bool isValidNativeWindow(EGLNativeWindowType window) const override;
SurfaceImpl *createWindowSurfaceVk(const egl::SurfaceState &state,
EGLNativeWindowType window) override;
egl::ConfigSet generateConfigs() override;
void checkConfigSupport(egl::Config *config) override;
const char *getWSIExtension() const override;
private:
std::vector<VkSurfaceFormatKHR> mSurfaceFormats;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_DISPLAY_DISPLAYVKHEADLESS_H_
//
// Copyright 2020 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.
//
// WindowSurfaceVkHeadless.cpp:
// Implements the class methods for WindowSurfaceVkHeadless.
//
#include "WindowSurfaceVkHeadless.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
namespace rx
{
WindowSurfaceVkHeadless::WindowSurfaceVkHeadless(const egl::SurfaceState &surfaceState,
EGLNativeWindowType window)
: WindowSurfaceVk(surfaceState, window)
{}
WindowSurfaceVkHeadless::~WindowSurfaceVkHeadless() {}
angle::Result WindowSurfaceVkHeadless::createSurfaceVk(vk::Context *context,
gl::Extents *extentsOut)
{
RendererVk *renderer = context->getRenderer();
ASSERT(renderer != nullptr);
VkInstance instance = renderer->getInstance();
VkHeadlessSurfaceCreateInfoEXT createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT;
ANGLE_VK_TRY(context, vkCreateHeadlessSurfaceEXT(instance, &createInfo, nullptr, &mSurface));
return getCurrentWindowSize(context, extentsOut);
}
angle::Result WindowSurfaceVkHeadless::getCurrentWindowSize(vk::Context *context,
gl::Extents *extentsOut)
{
const VkPhysicalDevice &physicalDevice = context->getRenderer()->getPhysicalDevice();
ANGLE_VK_TRY(context, vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface,
&mSurfaceCaps));
// Spec: "For headless surfaces, currentExtent is the reserved value (0xFFFFFFFF, 0xFFFFFFFF).
// Whatever the application sets a swapchain's imageExtent to will be the size of the surface,
// after the first image is presented."
// For ANGLE, in headless mode, we share the same 'SimpleDisplayWindow' structure with front
// EGL window info to define the vulkan backend surface/image extents.
angle::vk::SimpleDisplayWindow *simpleWindow =
reinterpret_cast<angle::vk::SimpleDisplayWindow *>(mNativeWindowType);
// Update surface extent before output the new extent.
mSurfaceCaps.currentExtent.width = simpleWindow->width;
mSurfaceCaps.currentExtent.height = simpleWindow->height;
*extentsOut =
gl::Extents(mSurfaceCaps.currentExtent.width, mSurfaceCaps.currentExtent.height, 1);
return angle::Result::Continue;
}
} // namespace rx
//
// Copyright 2020 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.
//
// WindowSurfaceVkHeadless.h:
// Defines the class interface for WindowSurfaceVkHeadless, implementing WindowSurfaceVk.
//
#ifndef LIBANGLE_RENDERER_VULKAN_DISPLAY_WINDOWSURFACEVKHEADLESS_H_
#define LIBANGLE_RENDERER_VULKAN_DISPLAY_WINDOWSURFACEVKHEADLESS_H_
#include "libANGLE/renderer/vulkan/SurfaceVk.h"
namespace rx
{
class WindowSurfaceVkHeadless : public WindowSurfaceVk
{
public:
WindowSurfaceVkHeadless(const egl::SurfaceState &surfaceState, EGLNativeWindowType window);
~WindowSurfaceVkHeadless() final;
private:
angle::Result createSurfaceVk(vk::Context *context, gl::Extents *extentsOut) override;
angle::Result getCurrentWindowSize(vk::Context *context, gl::Extents *extentsOut) override;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_DISPLAY_WINDOWSURFACEVKHEADLESS_H_
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