Commit e85587ac by Corentin Wallez Committed by Commit Bot

BlitGL: add a ScopedGLState to separate our state from the app's

BUG=angleproject:1356 Change-Id: I19ec4efa37d142ac7370815b078f4ba79caa0bea Reviewed-on: https://chromium-review.googlesource.com/412451 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2291c935
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include "libANGLE/renderer/gl/StateManagerGL.h" #include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/WorkaroundsGL.h" #include "libANGLE/renderer/gl/WorkaroundsGL.h"
namespace rx
{
namespace namespace
{ {
...@@ -46,10 +49,60 @@ gl::Error CheckLinkStatus(const rx::FunctionsGL *functions, GLuint program) ...@@ -46,10 +49,60 @@ gl::Error CheckLinkStatus(const rx::FunctionsGL *functions, GLuint program)
return gl::NoError(); return gl::NoError();
} }
} // anonymous namespace class ScopedGLState : public angle::NonCopyable
namespace rx
{ {
public:
enum
{
KEEP_SCISSOR = 1,
};
ScopedGLState(StateManagerGL *stateManager,
const FunctionsGL *functions,
gl::Rectangle viewport,
int keepState = 0)
: mStateManager(stateManager), mFunctions(functions)
{
if (!(keepState & KEEP_SCISSOR))
{
mStateManager->setScissorTestEnabled(false);
}
mStateManager->setViewport(viewport);
mStateManager->setDepthRange(0.0f, 1.0f);
mStateManager->setBlendEnabled(false);
mStateManager->setColorMask(true, true, true, true);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
mStateManager->pauseTransformFeedback();
mStateManager->pauseQueries();
}
~ScopedGLState()
{
// XFB resuming will be done automatically
mStateManager->resumeQueries();
}
void willUseTextureUnit(int unit)
{
if (mFunctions->bindSampler)
{
mStateManager->bindSampler(unit, 0);
}
}
private:
StateManagerGL *mStateManager;
const FunctionsGL *mFunctions;
};
} // anonymous namespace
BlitGL::BlitGL(const FunctionsGL *functions, BlitGL::BlitGL(const FunctionsGL *functions,
const WorkaroundsGL &workarounds, const WorkaroundsGL &workarounds,
...@@ -169,22 +222,13 @@ gl::Error BlitGL::copySubImageToLUMAWorkaroundTexture(GLuint texture, ...@@ -169,22 +222,13 @@ gl::Error BlitGL::copySubImageToLUMAWorkaroundTexture(GLuint texture,
mScratchTextures[1], 0); mScratchTextures[1], 0);
// Render to the destination texture, sampling from the scratch texture // Render to the destination texture, sampling from the scratch texture
mStateManager->setViewport(gl::Rectangle(0, 0, sourceArea.width, sourceArea.height)); ScopedGLState scopedState(mStateManager, mFunctions,
mStateManager->setScissorTestEnabled(false); gl::Rectangle(0, 0, sourceArea.width, sourceArea.height));
mStateManager->setDepthRange(0.0f, 1.0f); scopedState.willUseTextureUnit(0);
mStateManager->setBlendEnabled(false);
mStateManager->setColorMask(true, true, true, true);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]);
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST); setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST); setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
mStateManager->activeTexture(0); mStateManager->activeTexture(0);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]); mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]);
...@@ -311,6 +355,11 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source, ...@@ -311,6 +355,11 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source,
mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, format, inBoundsSource.x, inBoundsSource.y, mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, format, inBoundsSource.x, inBoundsSource.y,
inBoundsSource.width, inBoundsSource.height, 0); inBoundsSource.width, inBoundsSource.height, 0);
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
setScratchTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} }
// Compute normalized sampled draw quad region // Compute normalized sampled draw quad region
...@@ -343,28 +392,14 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source, ...@@ -343,28 +392,14 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source,
gl::Vector2 texCoordOffset = gl::Vector2(TOffset.x - DOffset.x * texCoordScale.x, gl::Vector2 texCoordOffset = gl::Vector2(TOffset.x - DOffset.x * texCoordScale.x,
TOffset.y - DOffset.y * texCoordScale.y); TOffset.y - DOffset.y * texCoordScale.y);
// Reset all the state except scissor and viewport // Reset all the state except scissor and use the viewport to draw exactly to the destination
mStateManager->setDepthRange(0.0f, 1.0f); // rectangle
mStateManager->setBlendEnabled(false); ScopedGLState scopedState(mStateManager, mFunctions, destArea, ScopedGLState::KEEP_SCISSOR);
mStateManager->setColorMask(true, true, true, true); scopedState.willUseTextureUnit(0);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
// Use the viewport to draw exactly to the destination rectangle
mStateManager->setViewport(destArea);
// Set uniforms // Set uniforms
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
setScratchTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mStateManager->activeTexture(0); mStateManager->activeTexture(0);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]); mStateManager->bindTexture(GL_TEXTURE_2D, textureId);
mStateManager->useProgram(mBlitProgram); mStateManager->useProgram(mBlitProgram);
mFunctions->uniform1i(mSourceTextureLocation, 0); mFunctions->uniform1i(mSourceTextureLocation, 0);
......
...@@ -86,7 +86,7 @@ egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Surface *readS ...@@ -86,7 +86,7 @@ egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Surface *readS
// Pause transform feedback before making a new surface current, to workaround anglebug.com/1426 // Pause transform feedback before making a new surface current, to workaround anglebug.com/1426
ContextGL *glContext = GetImplAs<ContextGL>(context); ContextGL *glContext = GetImplAs<ContextGL>(context);
glContext->getStateManager()->pauseTransformFeedback(context->getContextState()); glContext->getStateManager()->pauseTransformFeedback();
SurfaceGL *glDrawSurface = GetImplAs<SurfaceGL>(drawSurface); SurfaceGL *glDrawSurface = GetImplAs<SurfaceGL>(drawSurface);
ANGLE_TRY(glDrawSurface->makeCurrent()); ANGLE_TRY(glDrawSurface->makeCurrent());
......
...@@ -661,17 +661,27 @@ gl::Error StateManagerGL::setDrawElementsState(const gl::ContextState &data, ...@@ -661,17 +661,27 @@ gl::Error StateManagerGL::setDrawElementsState(const gl::ContextState &data,
return setGenericDrawState(data); return setGenericDrawState(data);
} }
gl::Error StateManagerGL::pauseTransformFeedback(const gl::ContextState &data) void StateManagerGL::pauseTransformFeedback()
{ {
// If the context is going to be changed, pause the previous context's transform feedback if (mPrevDrawTransformFeedback != nullptr)
if (data.getContext() != mPrevDrawContext)
{ {
if (mPrevDrawTransformFeedback != nullptr) mPrevDrawTransformFeedback->syncPausedState(true);
{ }
mPrevDrawTransformFeedback->syncPausedState(true); }
}
void StateManagerGL::pauseQueries()
{
for (QueryGL *prevQuery : mCurrentQueries)
{
prevQuery->pause();
}
}
void StateManagerGL::resumeQueries()
{
for (QueryGL *prevQuery : mCurrentQueries)
{
prevQuery->resume();
} }
return gl::Error(GL_NO_ERROR);
} }
gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data) gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data)
...@@ -681,10 +691,7 @@ gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data) ...@@ -681,10 +691,7 @@ gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data)
// If the context has changed, pause the previous context's queries // If the context has changed, pause the previous context's queries
if (data.getContext() != mPrevDrawContext) if (data.getContext() != mPrevDrawContext)
{ {
for (QueryGL *prevQuery : mCurrentQueries) pauseQueries();
{
prevQuery->pause();
}
} }
mCurrentQueries.clear(); mCurrentQueries.clear();
mPrevDrawTransformFeedback = nullptr; mPrevDrawTransformFeedback = nullptr;
......
...@@ -150,7 +150,9 @@ class StateManagerGL final : angle::NonCopyable ...@@ -150,7 +150,9 @@ class StateManagerGL final : angle::NonCopyable
GLsizei instanceCount, GLsizei instanceCount,
const GLvoid **outIndices); const GLvoid **outIndices);
gl::Error pauseTransformFeedback(const gl::ContextState &data); void pauseTransformFeedback();
void pauseQueries();
void resumeQueries();
gl::Error onMakeCurrent(const gl::ContextState &data); gl::Error onMakeCurrent(const gl::ContextState &data);
void syncState(const gl::State &state, const gl::State::DirtyBits &glDirtyBits); void syncState(const gl::State &state, const gl::State::DirtyBits &glDirtyBits);
......
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