Commit 222a81cf by Geoff Lang Committed by Angle LUCI CQ

Reland: GL: Skip redundant flushes.

Skip flushes when there is no work submitted since the last flush. Bug: chromium:1181068 Change-Id: Iab31f8949f7eb07dffb7b0930069cbb3ca69ef57 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2956453Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent ebf75698
......@@ -80,6 +80,8 @@ angle::Result BufferGL::setData(const gl::Context *context,
mBufferSize = size;
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -89,6 +91,7 @@ angle::Result BufferGL::setSubData(const gl::Context *context,
size_t size,
size_t offset)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -102,6 +105,8 @@ angle::Result BufferGL::setSubData(const gl::Context *context,
memcpy(mShadowCopy.data() + offset, data, size);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -111,6 +116,7 @@ angle::Result BufferGL::copySubData(const gl::Context *context,
GLintptr destOffset,
GLsizeiptr size)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -130,11 +136,14 @@ angle::Result BufferGL::copySubData(const gl::Context *context,
memcpy(mShadowCopy.data() + destOffset, sourceGL->mShadowCopy.data() + sourceOffset, size);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **mapPtr)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -162,6 +171,8 @@ angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **ma
mMapOffset = 0;
mMapSize = mBufferSize;
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -171,6 +182,7 @@ angle::Result BufferGL::mapRange(const gl::Context *context,
GLbitfield access,
void **mapPtr)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -191,11 +203,14 @@ angle::Result BufferGL::mapRange(const gl::Context *context,
mMapOffset = offset;
mMapSize = length;
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -219,6 +234,9 @@ angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result)
}
mIsMapped = false;
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -229,6 +247,7 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context,
bool primitiveRestartEnabled,
gl::IndexRange *outRange)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -260,6 +279,8 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context,
}
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......
......@@ -329,6 +329,8 @@ angle::Result ContextGL::drawArrays(const gl::Context *context,
ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count,
instanceCount));
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -348,6 +350,8 @@ angle::Result ContextGL::drawArraysInstanced(const gl::Context *context,
ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount));
ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count,
adjustedInstanceCount));
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -469,6 +473,8 @@ angle::Result ContextGL::drawArraysInstancedBaseInstance(const gl::Context *cont
resetUpdatedAttributes(attribToResetMask);
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -500,6 +506,8 @@ angle::Result ContextGL::drawElements(const gl::Context *context,
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type),
drawIndexPtr, instanceCount));
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -532,6 +540,8 @@ angle::Result ContextGL::drawElementsBaseVertex(const gl::Context *context,
ToGLenum(mode), count, ToGLenum(type), drawIndexPtr,
instanceCount, baseVertex));
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -579,6 +589,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertex(const gl::Context *cont
ANGLE_GL_TRY(context, getFunctions()->drawElementsInstancedBaseVertex(
ToGLenum(mode), count, ToGLenum(type), drawIndexPointer,
adjustedInstanceCount, baseVertex));
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -625,6 +637,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertexBaseInstance(const gl::C
resetUpdatedAttributes(attribToResetMask);
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -654,6 +668,8 @@ angle::Result ContextGL::drawRangeElements(const gl::Context *context,
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type),
drawIndexPointer, instanceCount));
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -685,6 +701,8 @@ angle::Result ContextGL::drawRangeElementsBaseVertex(const gl::Context *context,
ToGLenum(mode), count, ToGLenum(type), drawIndexPointer,
instanceCount, baseVertex));
}
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -693,6 +711,8 @@ angle::Result ContextGL::drawArraysIndirect(const gl::Context *context,
const void *indirect)
{
ANGLE_GL_TRY(context, getFunctions()->drawArraysIndirect(ToGLenum(mode), indirect));
mRenderer->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -712,6 +732,8 @@ angle::Result ContextGL::multiDrawArrays(const gl::Context *context,
const GLsizei *counts,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysGeneral(this, context, mode, firsts, counts, drawcount);
}
......@@ -722,6 +744,8 @@ angle::Result ContextGL::multiDrawArraysInstanced(const gl::Context *context,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysInstancedGeneral(this, context, mode, firsts, counts, instanceCounts,
drawcount);
}
......@@ -733,6 +757,8 @@ angle::Result ContextGL::multiDrawElements(const gl::Context *context,
const GLvoid *const *indices,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsGeneral(this, context, mode, counts, type, indices, drawcount);
}
......@@ -744,6 +770,8 @@ angle::Result ContextGL::multiDrawElementsInstanced(const gl::Context *context,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsInstancedGeneral(this, context, mode, counts, type, indices,
instanceCounts, drawcount);
}
......@@ -756,6 +784,8 @@ angle::Result ContextGL::multiDrawArraysInstancedBaseInstance(const gl::Context
const GLuint *baseInstances,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysInstancedBaseInstanceGeneral(
this, context, mode, firsts, counts, instanceCounts, baseInstances, drawcount);
}
......@@ -771,6 +801,8 @@ angle::Result ContextGL::multiDrawElementsInstancedBaseVertexBaseInstance(
const GLuint *baseInstances,
GLsizei drawcount)
{
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsInstancedBaseVertexBaseInstanceGeneral(
this, context, mode, counts, type, indices, instanceCounts, baseVertices, baseInstances,
drawcount);
......@@ -942,4 +974,9 @@ void ContextGL::flushIfNecessaryBeforeDeleteTextures()
mRenderer->flushIfNecessaryBeforeDeleteTextures();
}
void ContextGL::markWorkSubmitted()
{
mRenderer->markWorkSubmitted();
}
} // namespace rx
......@@ -269,6 +269,8 @@ class ContextGL : public ContextImpl
void setNeedsFlushBeforeDeleteTextures();
void flushIfNecessaryBeforeDeleteTextures();
void markWorkSubmitted();
const gl::Debug &getDebug() const { return mState.getDebug(); }
private:
......
......@@ -69,9 +69,11 @@ FenceNVSyncGL::~FenceNVSyncGL()
angle::Result FenceNVSyncGL::set(const gl::Context *context, GLenum condition)
{
ASSERT(condition == GL_ALL_COMPLETED_NV);
mSyncObject = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
ANGLE_CHECK(GetImplAs<ContextGL>(context), mSyncObject != 0,
"glFenceSync failed to create a GLsync object.", GL_OUT_OF_MEMORY);
ContextGL *contextGL = GetImplAs<ContextGL>(context);
mSyncObject = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
ANGLE_CHECK(contextGL, mSyncObject != 0, "glFenceSync failed to create a GLsync object.",
GL_OUT_OF_MEMORY);
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......
......@@ -502,6 +502,7 @@ angle::Result FramebufferGL::invalidateSub(const gl::Context *context,
angle::Result FramebufferGL::clear(const gl::Context *context, GLbitfield mask)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
......@@ -520,6 +521,7 @@ angle::Result FramebufferGL::clear(const gl::Context *context, GLbitfield mask)
GL_NONE, 0, nullptr, 0.0f, 0);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -528,6 +530,7 @@ angle::Result FramebufferGL::clearBufferfv(const gl::Context *context,
GLint drawbuffer,
const GLfloat *values)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
......@@ -547,6 +550,7 @@ angle::Result FramebufferGL::clearBufferfv(const gl::Context *context,
reinterpret_cast<const uint8_t *>(values), 0.0f, 0);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -555,6 +559,7 @@ angle::Result FramebufferGL::clearBufferuiv(const gl::Context *context,
GLint drawbuffer,
const GLuint *values)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
......@@ -574,6 +579,7 @@ angle::Result FramebufferGL::clearBufferuiv(const gl::Context *context,
reinterpret_cast<const uint8_t *>(values), 0.0f, 0);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -582,6 +588,7 @@ angle::Result FramebufferGL::clearBufferiv(const gl::Context *context,
GLint drawbuffer,
const GLint *values)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
......@@ -601,6 +608,7 @@ angle::Result FramebufferGL::clearBufferiv(const gl::Context *context,
reinterpret_cast<const uint8_t *>(values), 0.0f, 0);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -610,6 +618,7 @@ angle::Result FramebufferGL::clearBufferfi(const gl::Context *context,
GLfloat depth,
GLint stencil)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
......@@ -629,6 +638,7 @@ angle::Result FramebufferGL::clearBufferfi(const gl::Context *context,
nullptr, depth, stencil);
}
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......@@ -733,6 +743,7 @@ angle::Result FramebufferGL::blit(const gl::Context *context,
GLbitfield mask,
GLenum filter)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
......@@ -851,6 +862,7 @@ angle::Result FramebufferGL::blit(const gl::Context *context,
finalSourceArea.y1(), finalDestArea.x, finalDestArea.y,
finalDestArea.x1(), finalDestArea.y1(), blitMask, filter);
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......
......@@ -181,6 +181,9 @@ angle::Result StandardQueryGL::resume(const gl::Context *context)
mFunctions->genQueries(1, &mActiveQuery);
mStateManager->beginQuery(mType, this, mActiveQuery);
ContextGL *contextGL = GetImplAs<ContextGL>(context);
contextGL->markWorkSubmitted();
}
return angle::Result::Continue;
......@@ -239,13 +242,20 @@ class SyncProviderGL
class SyncProviderGLSync : public SyncProviderGL
{
public:
SyncProviderGLSync(const FunctionsGL *functions) : mFunctions(functions), mSync(nullptr)
{
mSync = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
}
SyncProviderGLSync(const FunctionsGL *functions) : mFunctions(functions), mSync(nullptr) {}
~SyncProviderGLSync() override { mFunctions->deleteSync(mSync); }
angle::Result init(const gl::Context *context, gl::QueryType type) override
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
mSync = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
ANGLE_CHECK(contextGL, mSync != 0, "glFenceSync failed to create a GLsync object.",
GL_OUT_OF_MEMORY);
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
angle::Result flush(const gl::Context *context, bool force, bool *finished) override
{
if (force)
......@@ -337,12 +347,12 @@ angle::Result SyncQueryGL::end(const gl::Context *context)
else if (nativegl::SupportsOcclusionQueries(mFunctions))
{
mSyncProvider.reset(new SyncProviderGLQuery(mFunctions));
ANGLE_TRY(mSyncProvider->init(context, gl::QueryType::AnySamples));
}
else
{
ANGLE_GL_UNREACHABLE(GetImplAs<ContextGL>(context));
}
ANGLE_TRY(mSyncProvider->init(context, gl::QueryType::AnySamples));
return angle::Result::Continue;
}
......
......@@ -215,8 +215,14 @@ RendererGL::~RendererGL()
angle::Result RendererGL::flush()
{
if (!mWorkDoneSinceLastFlush && !mNeedsFlushBeforeDeleteTextures)
{
return angle::Result::Continue;
}
mFunctions->flush();
mNeedsFlushBeforeDeleteTextures = false;
mWorkDoneSinceLastFlush = false;
return angle::Result::Continue;
}
......@@ -229,6 +235,7 @@ angle::Result RendererGL::finish()
mFunctions->finish();
mNeedsFlushBeforeDeleteTextures = false;
mWorkDoneSinceLastFlush = false;
if (mFeatures.finishDoesNotCauseQueriesToBeAvailable.enabled && mUseDebugOutput)
{
......@@ -335,23 +342,27 @@ angle::Result RendererGL::dispatchCompute(const gl::Context *context,
GLuint numGroupsZ)
{
mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue;
}
angle::Result RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{
mFunctions->dispatchComputeIndirect(indirect);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue;
}
angle::Result RendererGL::memoryBarrier(GLbitfield barriers)
{
mFunctions->memoryBarrier(barriers);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue;
}
angle::Result RendererGL::memoryBarrierByRegion(GLbitfield barriers)
{
mFunctions->memoryBarrierByRegion(barriers);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue;
}
......@@ -431,6 +442,11 @@ void RendererGL::setNeedsFlushBeforeDeleteTextures()
mNeedsFlushBeforeDeleteTextures = true;
}
void RendererGL::markWorkSubmitted()
{
mWorkDoneSinceLastFlush = true;
}
void RendererGL::flushIfNecessaryBeforeDeleteTextures()
{
if (mNeedsFlushBeforeDeleteTextures)
......
......@@ -135,6 +135,8 @@ class RendererGL : angle::NonCopyable
void setNeedsFlushBeforeDeleteTextures();
void flushIfNecessaryBeforeDeleteTextures();
void markWorkSubmitted();
void handleGPUSwitch();
protected:
......@@ -164,6 +166,8 @@ class RendererGL : angle::NonCopyable
mutable gl::Limitations mNativeLimitations;
mutable MultiviewImplementationTypeGL mMultiviewImplementationType;
bool mWorkDoneSinceLastFlush = false;
// The thread-to-context mapping for the currently active worker threads.
angle::HashMap<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts;
// The worker contexts available to use.
......
......@@ -36,9 +36,11 @@ void SyncGL::onDestroy(const gl::Context *context)
angle::Result SyncGL::set(const gl::Context *context, GLenum condition, GLbitfield flags)
{
ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0);
mSyncObject = mFunctions->fenceSync(condition, flags);
ANGLE_CHECK(GetImplAs<ContextGL>(context), mSyncObject != 0,
"glFenceSync failed to create a GLsync object.", GL_OUT_OF_MEMORY);
ContextGL *contextGL = GetImplAs<ContextGL>(context);
mSyncObject = mFunctions->fenceSync(condition, flags);
ANGLE_CHECK(contextGL, mSyncObject != 0, "glFenceSync failed to create a GLsync object.",
GL_OUT_OF_MEMORY);
contextGL->markWorkSubmitted();
return angle::Result::Continue;
}
......
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