Hash :
82fddcb1
Author :
Date :
2019-01-18T14:27:43
Vulkan: Implement GLsync and EGLSync fence syncs
That is required in GLES 3 for GLsync and EGL_KHR_fence_sync and
EGL_KHR_wait_sync (or EGL 1.5) for EGLSync.
The two constructs (GLsync and EGLSync) have similar semantics and share
the implementation on the Vulkan backend.
The implementation of a fence sync object is achieved through the
combined use of a vkEvent and the implicit vkFence inserted at the end
of every submission. Imagine the following command buffer:
glDraw : Draw
glCreateSync: Set Event <-- insertion of fence sync
glDraw : Draw
: Signal Fence <-- implicit fence at the end of submission
glFlush : Submit
Assume the serial S is associated to this submission. The following
hold:
- If event is set, the fence sync is signaled
- If S is already finished, the fence sync is signaled
- If client is waiting on the sync and S is not yet flushed, there will
be a deadlock (unless multi-threaded and another thread performs the
flush).
The event is used to implement server waits (glWaitSync), as vkEvent is
the only entity the GPU can signal and wait on within the command
buffer. The wait is inserted in the command graph without incurring a
flush, i.e. the wait can be within the same command buffer as event set.
The event however does not support CPU waits (glClientWaitSync).
vkFence is the only entity the CPU can wait on. For client wait
therefore, the following algorithm is used:
- If the event is already set, there's no wait -> already signaled
- If timeout is zero, there's no wait -> timeout expired
- If S is not flushed, flush it to ensure forward progress.
- Wait until S is finished -> condition satisfied / timeout expired.
Bug: angleproject:2466
Change-Id: I678995a6139dd9533fa8ad361a3d292b202c52a4
Reviewed-on: https://chromium-review.googlesource.com/c/1422552
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@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
//
// 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/RendererVk.h"
#include "libANGLE/renderer/vulkan/SurfaceVk.h"
#include "libANGLE/renderer/vulkan/SyncVk.h"
namespace rx
{
DisplayVk::DisplayVk(const egl::DisplayState &state)
: DisplayImpl(state), vk::Context(new RendererVk()), mScratchBuffer(1000u)
{}
DisplayVk::~DisplayVk()
{
delete mRenderer;
}
egl::Error DisplayVk::initialize(egl::Display *display)
{
ASSERT(mRenderer != nullptr && display != nullptr);
angle::Result result = mRenderer->initialize(this, display, getWSIName());
ANGLE_TRY(angle::ToEGL(result, this, EGL_NOT_INITIALIZED));
return egl::NoError();
}
void DisplayVk::terminate()
{
ASSERT(mRenderer);
mRenderer->onDestroy(this);
}
egl::Error DisplayVk::makeCurrent(egl::Surface * /*drawSurface*/,
egl::Surface * /*readSurface*/,
gl::Context * /*context*/)
{
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)
{
return angle::ToEGL(mRenderer->finish(this), this, EGL_BAD_ACCESS);
}
egl::Error DisplayVk::waitNative(const gl::Context *context, EGLint engine)
{
UNIMPLEMENTED();
return egl::EglBadAccess();
}
SurfaceImpl *DisplayVk::createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
EGLint width = attribs.getAsInt(EGL_WIDTH, 0);
EGLint height = attribs.getAsInt(EGL_HEIGHT, 0);
return createWindowSurfaceVk(state, window, width, height);
}
SurfaceImpl *DisplayVk::createPbufferSurface(const egl::SurfaceState &state,
const egl::AttributeMap &attribs)
{
ASSERT(mRenderer);
EGLint width = attribs.getAsInt(EGL_WIDTH, 0);
EGLint height = attribs.getAsInt(EGL_HEIGHT, 0);
return new OffscreenSurfaceVk(state, width, height);
}
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)
{
UNIMPLEMENTED();
return static_cast<ImageImpl *>(0);
}
rx::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();
}
void DisplayVk::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness = true;
outExtensions->surfaceOrientation = true;
outExtensions->displayTextureShareGroup = true;
// TODO(geofflang): Extension is exposed but not implemented so that other aspects of the Vulkan
// backend can be tested in Chrome. http://anglebug.com/2722
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;
}
void DisplayVk::generateCaps(egl::Caps *outCaps) const
{
outCaps->textureNPOT = true;
}
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: " << 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));
}
} // namespace rx