Commit 7a38f3f5 by Geoff Lang Committed by Angle LUCI CQ

GL: Skip redundant flushes.

Skip flushes when there is no work submitted since the last flush. Clone of geofflang's: https://chromium-review.googlesource.com/2911879 Bug: chromium:1181068 Change-Id: Idd8a1c61b814d746bf1e0225cfc4ca375a7bb224 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2915675 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent efd8da4d
...@@ -80,6 +80,8 @@ angle::Result BufferGL::setData(const gl::Context *context, ...@@ -80,6 +80,8 @@ angle::Result BufferGL::setData(const gl::Context *context,
mBufferSize = size; mBufferSize = size;
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -89,6 +91,7 @@ angle::Result BufferGL::setSubData(const gl::Context *context, ...@@ -89,6 +91,7 @@ angle::Result BufferGL::setSubData(const gl::Context *context,
size_t size, size_t size,
size_t offset) size_t offset)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -102,6 +105,8 @@ angle::Result BufferGL::setSubData(const gl::Context *context, ...@@ -102,6 +105,8 @@ angle::Result BufferGL::setSubData(const gl::Context *context,
memcpy(mShadowCopy.data() + offset, data, size); memcpy(mShadowCopy.data() + offset, data, size);
} }
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -111,6 +116,7 @@ angle::Result BufferGL::copySubData(const gl::Context *context, ...@@ -111,6 +116,7 @@ angle::Result BufferGL::copySubData(const gl::Context *context,
GLintptr destOffset, GLintptr destOffset,
GLsizeiptr size) GLsizeiptr size)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -130,11 +136,14 @@ angle::Result BufferGL::copySubData(const gl::Context *context, ...@@ -130,11 +136,14 @@ angle::Result BufferGL::copySubData(const gl::Context *context,
memcpy(mShadowCopy.data() + destOffset, sourceGL->mShadowCopy.data() + sourceOffset, size); memcpy(mShadowCopy.data() + destOffset, sourceGL->mShadowCopy.data() + sourceOffset, size);
} }
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **mapPtr) angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **mapPtr)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -162,6 +171,8 @@ angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **ma ...@@ -162,6 +171,8 @@ angle::Result BufferGL::map(const gl::Context *context, GLenum access, void **ma
mMapOffset = 0; mMapOffset = 0;
mMapSize = mBufferSize; mMapSize = mBufferSize;
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -171,6 +182,7 @@ angle::Result BufferGL::mapRange(const gl::Context *context, ...@@ -171,6 +182,7 @@ angle::Result BufferGL::mapRange(const gl::Context *context,
GLbitfield access, GLbitfield access,
void **mapPtr) void **mapPtr)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -191,11 +203,14 @@ angle::Result BufferGL::mapRange(const gl::Context *context, ...@@ -191,11 +203,14 @@ angle::Result BufferGL::mapRange(const gl::Context *context,
mMapOffset = offset; mMapOffset = offset;
mMapSize = length; mMapSize = length;
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result) angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -219,6 +234,9 @@ angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result) ...@@ -219,6 +234,9 @@ angle::Result BufferGL::unmap(const gl::Context *context, GLboolean *result)
} }
mIsMapped = false; mIsMapped = false;
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -229,6 +247,7 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context, ...@@ -229,6 +247,7 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context,
bool primitiveRestartEnabled, bool primitiveRestartEnabled,
gl::IndexRange *outRange) gl::IndexRange *outRange)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
...@@ -260,6 +279,8 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context, ...@@ -260,6 +279,8 @@ angle::Result BufferGL::getIndexRange(const gl::Context *context,
} }
} }
contextGL->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -329,6 +329,8 @@ angle::Result ContextGL::drawArrays(const gl::Context *context, ...@@ -329,6 +329,8 @@ angle::Result ContextGL::drawArrays(const gl::Context *context,
ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count,
instanceCount)); instanceCount));
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -348,6 +350,8 @@ angle::Result ContextGL::drawArraysInstanced(const gl::Context *context, ...@@ -348,6 +350,8 @@ angle::Result ContextGL::drawArraysInstanced(const gl::Context *context,
ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount)); ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount));
ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, ANGLE_GL_TRY(context, getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count,
adjustedInstanceCount)); adjustedInstanceCount));
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -469,6 +473,8 @@ angle::Result ContextGL::drawArraysInstancedBaseInstance(const gl::Context *cont ...@@ -469,6 +473,8 @@ angle::Result ContextGL::drawArraysInstancedBaseInstance(const gl::Context *cont
resetUpdatedAttributes(attribToResetMask); resetUpdatedAttributes(attribToResetMask);
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -500,6 +506,8 @@ angle::Result ContextGL::drawElements(const gl::Context *context, ...@@ -500,6 +506,8 @@ angle::Result ContextGL::drawElements(const gl::Context *context,
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type), getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type),
drawIndexPtr, instanceCount)); drawIndexPtr, instanceCount));
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -532,6 +540,8 @@ angle::Result ContextGL::drawElementsBaseVertex(const gl::Context *context, ...@@ -532,6 +540,8 @@ angle::Result ContextGL::drawElementsBaseVertex(const gl::Context *context,
ToGLenum(mode), count, ToGLenum(type), drawIndexPtr, ToGLenum(mode), count, ToGLenum(type), drawIndexPtr,
instanceCount, baseVertex)); instanceCount, baseVertex));
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -579,6 +589,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertex(const gl::Context *cont ...@@ -579,6 +589,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertex(const gl::Context *cont
ANGLE_GL_TRY(context, getFunctions()->drawElementsInstancedBaseVertex( ANGLE_GL_TRY(context, getFunctions()->drawElementsInstancedBaseVertex(
ToGLenum(mode), count, ToGLenum(type), drawIndexPointer, ToGLenum(mode), count, ToGLenum(type), drawIndexPointer,
adjustedInstanceCount, baseVertex)); adjustedInstanceCount, baseVertex));
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -625,6 +637,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertexBaseInstance(const gl::C ...@@ -625,6 +637,8 @@ angle::Result ContextGL::drawElementsInstancedBaseVertexBaseInstance(const gl::C
resetUpdatedAttributes(attribToResetMask); resetUpdatedAttributes(attribToResetMask);
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -654,6 +668,8 @@ angle::Result ContextGL::drawRangeElements(const gl::Context *context, ...@@ -654,6 +668,8 @@ angle::Result ContextGL::drawRangeElements(const gl::Context *context,
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type), getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type),
drawIndexPointer, instanceCount)); drawIndexPointer, instanceCount));
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -685,6 +701,8 @@ angle::Result ContextGL::drawRangeElementsBaseVertex(const gl::Context *context, ...@@ -685,6 +701,8 @@ angle::Result ContextGL::drawRangeElementsBaseVertex(const gl::Context *context,
ToGLenum(mode), count, ToGLenum(type), drawIndexPointer, ToGLenum(mode), count, ToGLenum(type), drawIndexPointer,
instanceCount, baseVertex)); instanceCount, baseVertex));
} }
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -693,6 +711,8 @@ angle::Result ContextGL::drawArraysIndirect(const gl::Context *context, ...@@ -693,6 +711,8 @@ angle::Result ContextGL::drawArraysIndirect(const gl::Context *context,
const void *indirect) const void *indirect)
{ {
ANGLE_GL_TRY(context, getFunctions()->drawArraysIndirect(ToGLenum(mode), indirect)); ANGLE_GL_TRY(context, getFunctions()->drawArraysIndirect(ToGLenum(mode), indirect));
mRenderer->markWorkSubmitted();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -712,6 +732,8 @@ angle::Result ContextGL::multiDrawArrays(const gl::Context *context, ...@@ -712,6 +732,8 @@ angle::Result ContextGL::multiDrawArrays(const gl::Context *context,
const GLsizei *counts, const GLsizei *counts,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysGeneral(this, context, mode, firsts, counts, drawcount); return rx::MultiDrawArraysGeneral(this, context, mode, firsts, counts, drawcount);
} }
...@@ -722,6 +744,8 @@ angle::Result ContextGL::multiDrawArraysInstanced(const gl::Context *context, ...@@ -722,6 +744,8 @@ angle::Result ContextGL::multiDrawArraysInstanced(const gl::Context *context,
const GLsizei *instanceCounts, const GLsizei *instanceCounts,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysInstancedGeneral(this, context, mode, firsts, counts, instanceCounts, return rx::MultiDrawArraysInstancedGeneral(this, context, mode, firsts, counts, instanceCounts,
drawcount); drawcount);
} }
...@@ -733,6 +757,8 @@ angle::Result ContextGL::multiDrawElements(const gl::Context *context, ...@@ -733,6 +757,8 @@ angle::Result ContextGL::multiDrawElements(const gl::Context *context,
const GLvoid *const *indices, const GLvoid *const *indices,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsGeneral(this, context, mode, counts, type, indices, drawcount); return rx::MultiDrawElementsGeneral(this, context, mode, counts, type, indices, drawcount);
} }
...@@ -744,6 +770,8 @@ angle::Result ContextGL::multiDrawElementsInstanced(const gl::Context *context, ...@@ -744,6 +770,8 @@ angle::Result ContextGL::multiDrawElementsInstanced(const gl::Context *context,
const GLsizei *instanceCounts, const GLsizei *instanceCounts,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsInstancedGeneral(this, context, mode, counts, type, indices, return rx::MultiDrawElementsInstancedGeneral(this, context, mode, counts, type, indices,
instanceCounts, drawcount); instanceCounts, drawcount);
} }
...@@ -756,6 +784,8 @@ angle::Result ContextGL::multiDrawArraysInstancedBaseInstance(const gl::Context ...@@ -756,6 +784,8 @@ angle::Result ContextGL::multiDrawArraysInstancedBaseInstance(const gl::Context
const GLuint *baseInstances, const GLuint *baseInstances,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawArraysInstancedBaseInstanceGeneral( return rx::MultiDrawArraysInstancedBaseInstanceGeneral(
this, context, mode, firsts, counts, instanceCounts, baseInstances, drawcount); this, context, mode, firsts, counts, instanceCounts, baseInstances, drawcount);
} }
...@@ -771,6 +801,8 @@ angle::Result ContextGL::multiDrawElementsInstancedBaseVertexBaseInstance( ...@@ -771,6 +801,8 @@ angle::Result ContextGL::multiDrawElementsInstancedBaseVertexBaseInstance(
const GLuint *baseInstances, const GLuint *baseInstances,
GLsizei drawcount) GLsizei drawcount)
{ {
mRenderer->markWorkSubmitted();
return rx::MultiDrawElementsInstancedBaseVertexBaseInstanceGeneral( return rx::MultiDrawElementsInstancedBaseVertexBaseInstanceGeneral(
this, context, mode, counts, type, indices, instanceCounts, baseVertices, baseInstances, this, context, mode, counts, type, indices, instanceCounts, baseVertices, baseInstances,
drawcount); drawcount);
...@@ -942,4 +974,9 @@ void ContextGL::flushIfNecessaryBeforeDeleteTextures() ...@@ -942,4 +974,9 @@ void ContextGL::flushIfNecessaryBeforeDeleteTextures()
mRenderer->flushIfNecessaryBeforeDeleteTextures(); mRenderer->flushIfNecessaryBeforeDeleteTextures();
} }
void ContextGL::markWorkSubmitted()
{
mRenderer->markWorkSubmitted();
}
} // namespace rx } // namespace rx
...@@ -269,6 +269,8 @@ class ContextGL : public ContextImpl ...@@ -269,6 +269,8 @@ class ContextGL : public ContextImpl
void setNeedsFlushBeforeDeleteTextures(); void setNeedsFlushBeforeDeleteTextures();
void flushIfNecessaryBeforeDeleteTextures(); void flushIfNecessaryBeforeDeleteTextures();
void markWorkSubmitted();
private: private:
angle::Result setDrawArraysState(const gl::Context *context, angle::Result setDrawArraysState(const gl::Context *context,
GLint first, GLint first,
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "libANGLE/renderer/gl/renderergl_utils.h" #include "libANGLE/renderer/gl/renderergl_utils.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/renderer_utils.h"
#include <iostream>
namespace namespace
{ {
...@@ -215,8 +217,14 @@ RendererGL::~RendererGL() ...@@ -215,8 +217,14 @@ RendererGL::~RendererGL()
angle::Result RendererGL::flush() angle::Result RendererGL::flush()
{ {
if (!mWorkDoneSinceLastFlush && !mNeedsFlushBeforeDeleteTextures)
{
return angle::Result::Continue;
}
mFunctions->flush(); mFunctions->flush();
mNeedsFlushBeforeDeleteTextures = false; mNeedsFlushBeforeDeleteTextures = false;
mWorkDoneSinceLastFlush = false;
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -229,6 +237,7 @@ angle::Result RendererGL::finish() ...@@ -229,6 +237,7 @@ angle::Result RendererGL::finish()
mFunctions->finish(); mFunctions->finish();
mNeedsFlushBeforeDeleteTextures = false; mNeedsFlushBeforeDeleteTextures = false;
mWorkDoneSinceLastFlush = false;
if (mFeatures.finishDoesNotCauseQueriesToBeAvailable.enabled && mUseDebugOutput) if (mFeatures.finishDoesNotCauseQueriesToBeAvailable.enabled && mUseDebugOutput)
{ {
...@@ -335,23 +344,27 @@ angle::Result RendererGL::dispatchCompute(const gl::Context *context, ...@@ -335,23 +344,27 @@ angle::Result RendererGL::dispatchCompute(const gl::Context *context,
GLuint numGroupsZ) GLuint numGroupsZ)
{ {
mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ); mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) angle::Result RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{ {
mFunctions->dispatchComputeIndirect(indirect); mFunctions->dispatchComputeIndirect(indirect);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result RendererGL::memoryBarrier(GLbitfield barriers) angle::Result RendererGL::memoryBarrier(GLbitfield barriers)
{ {
mFunctions->memoryBarrier(barriers); mFunctions->memoryBarrier(barriers);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result RendererGL::memoryBarrierByRegion(GLbitfield barriers) angle::Result RendererGL::memoryBarrierByRegion(GLbitfield barriers)
{ {
mFunctions->memoryBarrierByRegion(barriers); mFunctions->memoryBarrierByRegion(barriers);
mWorkDoneSinceLastFlush = true;
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -431,6 +444,11 @@ void RendererGL::setNeedsFlushBeforeDeleteTextures() ...@@ -431,6 +444,11 @@ void RendererGL::setNeedsFlushBeforeDeleteTextures()
mNeedsFlushBeforeDeleteTextures = true; mNeedsFlushBeforeDeleteTextures = true;
} }
void RendererGL::markWorkSubmitted()
{
mWorkDoneSinceLastFlush = true;
}
void RendererGL::flushIfNecessaryBeforeDeleteTextures() void RendererGL::flushIfNecessaryBeforeDeleteTextures()
{ {
if (mNeedsFlushBeforeDeleteTextures) if (mNeedsFlushBeforeDeleteTextures)
......
...@@ -135,6 +135,8 @@ class RendererGL : angle::NonCopyable ...@@ -135,6 +135,8 @@ class RendererGL : angle::NonCopyable
void setNeedsFlushBeforeDeleteTextures(); void setNeedsFlushBeforeDeleteTextures();
void flushIfNecessaryBeforeDeleteTextures(); void flushIfNecessaryBeforeDeleteTextures();
void markWorkSubmitted();
void handleGPUSwitch(); void handleGPUSwitch();
protected: protected:
...@@ -164,6 +166,8 @@ class RendererGL : angle::NonCopyable ...@@ -164,6 +166,8 @@ class RendererGL : angle::NonCopyable
mutable gl::Limitations mNativeLimitations; mutable gl::Limitations mNativeLimitations;
mutable MultiviewImplementationTypeGL mMultiviewImplementationType; mutable MultiviewImplementationTypeGL mMultiviewImplementationType;
bool mWorkDoneSinceLastFlush = false;
// The thread-to-context mapping for the currently active worker threads. // The thread-to-context mapping for the currently active worker threads.
angle::HashMap<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts; angle::HashMap<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts;
// The worker contexts available to use. // The worker contexts available to use.
......
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