Skip to content

Commit

Permalink
GL MSAA tweaks
Browse files Browse the repository at this point in the history
* Invalidate the msaa color buffer after resolving, in hopes that the driver can avoid flushing it out to memory.

* Add a glFinish in the texture_target_gl tests to work around an ANGLE driver bug.

Diffs=
7cc6f5bbe3 GL MSAA tweaks (#8753)

Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com>
  • Loading branch information
csmartdalton and csmartdalton committed Dec 14, 2024
1 parent da575e1 commit 1880239
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3c322193bf69e92663ae4346cf16396ef1578239
7cc6f5bbe3c726fc1c94f2075aed7f262240282d
2 changes: 1 addition & 1 deletion renderer/include/rive/renderer/gl/gles3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct GLCapabilities
int contextVersionMajor;
int contextVersionMinor;
bool isGLES : 1;
bool isANGLEOrWebGL : 1;
bool isAndroidANGLE : 1;
bool isPowerVR : 1;
bool ANGLE_base_vertex_base_instance_shader_builtin : 1;
bool ANGLE_shader_pixel_local_storage : 1;
Expand Down
35 changes: 19 additions & 16 deletions renderer/src/gl/render_context_gl_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,26 +1683,32 @@ void RenderContextGLImpl::flush(const FlushDescriptor& desc)
}
else
{
// Depth/stencil don't need to be written out.
glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER,
// Depth/stencil can be discarded.
glInvalidateFramebuffer(GL_FRAMEBUFFER,
2,
msaaDepthStencilColor.data());
if ((desc.combinedShaderFeatures &
gpu::ShaderFeatures::ENABLE_ADVANCED_BLEND) &&
m_capabilities.KHR_blend_equation_advanced_coherent)
{
glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
if (msaaResolveAction ==
RenderTargetGL::MSAAResolveAction::framebufferBlit)
{
renderTarget->bindDestinationFramebuffer(GL_DRAW_FRAMEBUFFER);
glutils::BlitFramebuffer(desc.renderTargetUpdateBounds,
renderTarget->height(),
GL_COLOR_BUFFER_BIT);
// Now that color is resolved elsewhere we can discard the MSAA
// color buffer as well.
glInvalidateFramebuffer(GL_READ_FRAMEBUFFER,
1,
msaaDepthStencilColor.data() + 2);
}

if ((desc.combinedShaderFeatures &
gpu::ShaderFeatures::ENABLE_ADVANCED_BLEND) &&
m_capabilities.KHR_blend_equation_advanced_coherent)
{
glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
if (clipPlanesEnabled)
{
glDisable(GL_CLIP_DISTANCE0_EXT);
Expand Down Expand Up @@ -1779,10 +1785,8 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
#endif
if (capabilities.isGLES)
{
#ifdef RIVE_WEBGL
capabilities.isANGLEOrWebGL = true;
#else
capabilities.isANGLEOrWebGL = strstr(glVersionStr, "ANGLE") != NULL;
#ifdef RIVE_ANDROID
capabilities.isAndroidANGLE = strstr(glVersionStr, "ANGLE") != NULL;
#endif
#ifdef _MSC_VER
sscanf_s(
Expand All @@ -1796,7 +1800,6 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
}
else
{
capabilities.isANGLEOrWebGL = false;
#ifdef _MSC_VER
sscanf_s(
#else
Expand Down Expand Up @@ -1924,7 +1927,7 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
// this extension but then doesn't support gl_ClipDistance in the
// shader. Only use clip planes on ANGLE if ANGLE_clip_cull_distance is
// supported.
else if (!capabilities.isANGLEOrWebGL &&
else if (!capabilities.isAndroidANGLE &&
strcmp(ext, "GL_EXT_clip_cull_distance") == 0)
{
capabilities.EXT_clip_cull_distance = true;
Expand Down
11 changes: 11 additions & 0 deletions tests/gm/texture_target_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ class TextureTargetGL : public GM
copyFrameDescriptor.clearColor = 0xffff0000;
renderContext->beginFrame(std::move(copyFrameDescriptor));
originalRenderTarget->bindDestinationFramebuffer(GL_FRAMEBUFFER);
if (plsImplGL->capabilities().isAndroidANGLE)
{
// Some android devices shipping with ANGLE have a
// syncronization issue drawing this texture into the main
// framebuffer. glFinish is a very heavy handed workaround, but
// it's the only one so far to work.
// Sadly, we can't incorporate a workaround this heavy into the
// main GL runtime. Apps that run into it will have to come up
// with the best workaround for them.
glFinish();
}
plsImplGL->blitTextureToFramebufferAsDraw(m_offscreenTex,
{0, 0, 256, 256},
256);
Expand Down

0 comments on commit 1880239

Please sign in to comment.