Hash :
08142700
Author :
Date :
2020-10-01T19:30:03
Work-around test runner & DebugAnnotator Note: This precedes another CL that needs this change. DebugAnnotator uses a global variable. The test runner doesn't change state between testing different back-ends. This works-around the problem by setting the global variable when the context is switched. Because the GL back-end doesn't have its own DebugAnnotator sub-class, add a Display* to DisplayImpl::makeCurrent(), so that DisplayGL::makeCurrent() can install the front-end-Display's DebugAnnotator. Note: the Vulkan back-end gets this fix even though the new DebugAnnotatorVk class will be added in a follow-on CL. Bug: b/162068318 Bug: b/169243237 Bug: angleproject:5121 Change-Id: If08626a5310f9b4e3210e1a897a6886248e4d8ac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2451423 Reviewed-by: Ian Elliott <ianelliott@google.com> Commit-Queue: Ian Elliott <ianelliott@google.com>
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
//
// 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.
//
// DisplayVk.cpp:
// Implements the class methods for DisplayVk.
//
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/ImageVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/SurfaceVk.h"
#include "libANGLE/renderer/vulkan/SyncVk.h"
#include "libANGLE/trace.h"
namespace rx
{
DisplayVk::DisplayVk(const egl::DisplayState &state)
: DisplayImpl(state),
vk::Context(new RendererVk()),
mScratchBuffer(1000u),
mHasSurfaceWithRobustInit(false)
{}
DisplayVk::~DisplayVk()
{
delete mRenderer;
}
egl::Error DisplayVk::initialize(egl::Display *display)
{
ASSERT(mRenderer != nullptr && display != nullptr);
angle::Result result = mRenderer->initialize(this, display, getWSIExtension(), getWSILayer());
ANGLE_TRY(angle::ToEGL(result, this, EGL_NOT_INITIALIZED));
return egl::NoError();
}
void DisplayVk::terminate()
{
mRenderer->reloadVolkIfNeeded();
ASSERT(mRenderer);
mRenderer->onDestroy();
}
egl::Error DisplayVk::makeCurrent(egl::Display * /*display*/,
egl::Surface * /*drawSurface*/,
egl::Surface * /*readSurface*/,
gl::Context * /*context*/)
{
// Ensure the appropriate global DebugAnnotator is used
ASSERT(mRenderer);
mRenderer->setGlobalDebugAnnotator();
return egl::NoError();
}
bool DisplayVk::testDeviceLost()
{
return mRenderer->isDeviceLost();
}
egl::Error DisplayVk::restoreLostDevice(const egl::Display *display)
{
// A vulkan device cannot be restored, the entire renderer would have to be re-created along
// with any other EGL objects that reference it.
return egl::EglBadDisplay();
}
std::string DisplayVk::getVendorString() const
{
std::string vendorString = "Google Inc.";
if (mRenderer)
{
vendorString += " " + mRenderer->getVendorString();
}
return vendorString;
}
DeviceImpl *DisplayVk::createDevice()
{
UNIMPLEMENTED();
return nullptr;
}
egl::Error DisplayVk::waitClient(const gl::Context *context)
{
ANGLE_TRACE_EVENT0("gpu.angle", "DisplayVk::waitClient");
ContextVk *contextVk = vk::GetImpl(context);
return angle::ToEGL(contextVk->finishImpl(), this, EGL_BAD_ACCESS);
}
egl::Error DisplayVk::waitNative(const gl::Context *context, EGLint engine)
{
ANGLE_TRACE_EVENT0("gpu.angle", "DisplayVk::waitNative");
return angle::ResultToEGL(waitNativeImpl());
}
angle::Result DisplayVk::waitNativeImpl()
{
return angle::Result::Continue;
}
SurfaceImpl *DisplayVk::createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
if (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE)
{
mHasSurfaceWithRobustInit = true;
}
return createWindowSurfaceVk(state, window);
}
SurfaceImpl *DisplayVk::createPbufferSurface(const egl::SurfaceState &state,
const egl::AttributeMap &attribs)
{
if (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE)
{
mHasSurfaceWithRobustInit = true;
}
ASSERT(mRenderer);
return new OffscreenSurfaceVk(state, mRenderer);
}
SurfaceImpl *DisplayVk::createPbufferFromClientBuffer(const egl::SurfaceState &state,
EGLenum buftype,
EGLClientBuffer clientBuffer,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return static_cast<SurfaceImpl *>(0);
}
SurfaceImpl *DisplayVk::createPixmapSurface(const egl::SurfaceState &state,
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return static_cast<SurfaceImpl *>(0);
}
ImageImpl *DisplayVk::createImage(const egl::ImageState &state,
const gl::Context *context,
EGLenum target,
const egl::AttributeMap &attribs)
{
return new ImageVk(state, context);
}
ShareGroupImpl *DisplayVk::createShareGroup()
{
return new ShareGroupVk();
}
ContextImpl *DisplayVk::createContext(const gl::State &state,
gl::ErrorSet *errorSet,
const egl::Config *configuration,
const gl::Context *shareContext,
const egl::AttributeMap &attribs)
{
return new ContextVk(state, errorSet, mRenderer);
}
StreamProducerImpl *DisplayVk::createStreamProducerD3DTexture(
egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return static_cast<StreamProducerImpl *>(0);
}
EGLSyncImpl *DisplayVk::createSync(const egl::AttributeMap &attribs)
{
return new EGLSyncVk(attribs);
}
gl::Version DisplayVk::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
gl::Version DisplayVk::getMaxConformantESVersion() const
{
return mRenderer->getMaxConformantESVersion();
}
void DisplayVk::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness = getRenderer()->getNativeExtensions().robustness;
outExtensions->surfaceOrientation = true;
outExtensions->displayTextureShareGroup = true;
outExtensions->displaySemaphoreShareGroup = true;
outExtensions->robustResourceInitialization = true;
// The Vulkan implementation will always say that EGL_KHR_swap_buffers_with_damage is supported.
// When the Vulkan driver supports VK_KHR_incremental_present, it will use it. Otherwise, it
// will ignore the hint and do a regular swap.
outExtensions->swapBuffersWithDamage = true;
outExtensions->fenceSync = true;
outExtensions->waitSync = true;
outExtensions->image = true;
outExtensions->imageBase = true;
outExtensions->imagePixmap = false; // ANGLE does not support pixmaps
outExtensions->glTexture2DImage = true;
outExtensions->glTextureCubemapImage = true;
outExtensions->glTexture3DImage = false;
outExtensions->glRenderbufferImage = true;
outExtensions->imageNativeBuffer =
getRenderer()->getFeatures().supportsAndroidHardwareBuffer.enabled;
outExtensions->surfacelessContext = true;
outExtensions->glColorspace = getRenderer()->getFeatures().supportsSwapchainColorspace.enabled;
outExtensions->imageGlColorspace = outExtensions->glColorspace;
#if defined(ANGLE_PLATFORM_ANDROID)
outExtensions->framebufferTargetANDROID = true;
#endif // defined(ANGLE_PLATFORM_ANDROID)
// Disable context priority when non-zero memory init is enabled. This enforces a queue order.
outExtensions->contextPriority = !getRenderer()->getFeatures().allocateNonZeroMemory.enabled;
outExtensions->noConfigContext = true;
#if defined(ANGLE_PLATFORM_ANDROID)
outExtensions->nativeFenceSyncANDROID =
getRenderer()->getFeatures().supportsAndroidNativeFenceSync.enabled;
#endif // defined(ANGLE_PLATFORM_ANDROID)
#if defined(ANGLE_PLATFORM_GGP)
outExtensions->ggpStreamDescriptor = true;
outExtensions->swapWithFrameToken = getRenderer()->getFeatures().supportsGGPFrameToken.enabled;
#endif // defined(ANGLE_PLATFORM_GGP)
}
void DisplayVk::generateCaps(egl::Caps *outCaps) const
{
outCaps->textureNPOT = true;
outCaps->stencil8 = getRenderer()->getNativeExtensions().stencilIndex8;
}
const char *DisplayVk::getWSILayer() const
{
return nullptr;
}
bool DisplayVk::getScratchBuffer(size_t requstedSizeBytes,
angle::MemoryBuffer **scratchBufferOut) const
{
return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
}
void DisplayVk::handleError(VkResult result,
const char *file,
const char *function,
unsigned int line)
{
ASSERT(result != VK_SUCCESS);
std::stringstream errorStream;
errorStream << "Internal Vulkan error (" << result << "): " << VulkanResultString(result)
<< ", in " << file << ", " << function << ":" << line << ".";
mStoredErrorString = errorStream.str();
if (result == VK_ERROR_DEVICE_LOST)
{
WARN() << mStoredErrorString;
mRenderer->notifyDeviceLost();
}
}
// TODO(jmadill): Remove this. http://anglebug.com/3041
egl::Error DisplayVk::getEGLError(EGLint errorCode)
{
return egl::Error(errorCode, 0, std::move(mStoredErrorString));
}
void DisplayVk::populateFeatureList(angle::FeatureList *features)
{
mRenderer->getFeatures().populateFeatureList(features);
}
bool DisplayVk::isRobustResourceInitEnabled() const
{
// We return true if any surface was created with robust resource init enabled.
return mHasSurfaceWithRobustInit;
}
void ShareGroupVk::onDestroy(const egl::Display *display)
{
DisplayVk *displayVk = vk::GetImpl(display);
mPipelineLayoutCache.destroy(displayVk->getDevice());
mDescriptorSetLayoutCache.destroy(displayVk->getDevice());
}
} // namespace rx