Commit 4b4ecb54 authored by Kenneth Russell's avatar Kenneth Russell Committed by Commit Bot

Call DiscardFramebufferEXT earlier in WebGL's DrawingBuffer.

If the GL_EXT_discard_framebuffer extension is available, use it to
discard the depth and stencil buffers earlier, in ResolveIfNeeded.
This attempts to avoid resolves and flushes of these attachments
from tile memory to main memory when using implicit antialiasing.

Continue invalidating the framebuffer, including the color buffer, upon
BindFramebuffer in FinishPrepareTransferableResourceGpu.

Small updates to two related web tests,
fast/webgl/webgl-composite-modes-repaint.html and
fast/webgl/webgl-composite-modes-tabswitching.html .

Bug: 784743
Change-Id: I6184b35bc867fbaba6540889da6d1783d7b40083
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351388
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarJames Darpinian <jdarpinian@chromium.org>
Reviewed-by: default avatarShrek Shao <shrekshao@google.com>
Cr-Commit-Position: refs/heads/master@{#814888}
parent b00164ba
...@@ -452,8 +452,8 @@ bool DrawingBuffer::FinishPrepareTransferableResourceGpu( ...@@ -452,8 +452,8 @@ bool DrawingBuffer::FinishPrepareTransferableResourceGpu(
// Specify the buffer that we will put in the mailbox. // Specify the buffer that we will put in the mailbox.
scoped_refptr<ColorBuffer> color_buffer_for_mailbox; scoped_refptr<ColorBuffer> color_buffer_for_mailbox;
if (preserve_drawing_buffer_ == kDiscard) { if (preserve_drawing_buffer_ == kDiscard) {
// If we can discard the backbuffer, send the old backbuffer directly // Send the old backbuffer directly into the mailbox, and allocate
// into the mailbox, and allocate (or recycle) a new backbuffer. // (or recycle) a new backbuffer.
color_buffer_for_mailbox = back_color_buffer_; color_buffer_for_mailbox = back_color_buffer_;
back_color_buffer_ = CreateOrRecycleColorBuffer(); back_color_buffer_ = CreateOrRecycleColorBuffer();
if (!back_color_buffer_) { if (!back_color_buffer_) {
...@@ -463,8 +463,9 @@ bool DrawingBuffer::FinishPrepareTransferableResourceGpu( ...@@ -463,8 +463,9 @@ bool DrawingBuffer::FinishPrepareTransferableResourceGpu(
AttachColorBufferToReadFramebuffer(); AttachColorBufferToReadFramebuffer();
// Explicitly specify that m_fbo (which is now bound to the just-allocated // Explicitly specify that m_fbo (which is now bound to the just-allocated
// m_backColorBuffer) is not initialized, to save GPU memory bandwidth for // m_backColorBuffer) is not initialized, to save GPU memory bandwidth on
// tile-based GPU architectures. // tile-based GPU architectures. Note that the depth and stencil attachments
// are also discarded before multisample resolves, implicit or explicit.
if (discard_framebuffer_supported_) { if (discard_framebuffer_supported_) {
const GLenum kAttachments[3] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, const GLenum kAttachments[3] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT,
GL_STENCIL_ATTACHMENT}; GL_STENCIL_ATTACHMENT};
...@@ -1314,9 +1315,23 @@ void DrawingBuffer::ResolveMultisampleFramebufferInternal() { ...@@ -1314,9 +1315,23 @@ void DrawingBuffer::ResolveMultisampleFramebufferInternal() {
} }
void DrawingBuffer::ResolveIfNeeded() { void DrawingBuffer::ResolveIfNeeded() {
DCHECK(state_restorer_);
if (anti_aliasing_mode_ != kAntialiasingModeNone && if (anti_aliasing_mode_ != kAntialiasingModeNone &&
!contents_change_resolved_) !contents_change_resolved_) {
if (preserve_drawing_buffer_ == kDiscard &&
discard_framebuffer_supported_) {
// Discard the depth and stencil buffers as early as possible, before
// making any potentially-unneeded calls to BindFramebuffer (even no-ops),
// in order to maximize the chances that their storage can be kept in tile
// memory.
const GLenum kAttachments[2] = {GL_DEPTH_ATTACHMENT,
GL_STENCIL_ATTACHMENT};
state_restorer_->SetFramebufferBindingDirty();
gl_->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
gl_->DiscardFramebufferEXT(GL_FRAMEBUFFER, 2, kAttachments);
}
ResolveMultisampleFramebufferInternal(); ResolveMultisampleFramebufferInternal();
}
contents_change_resolved_ = true; contents_change_resolved_ = true;
auto* gl = ContextProvider()->ContextGL(); auto* gl = ContextProvider()->ContextGL();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<body onload="runRepaintTest()"> <body onload="runRepaintTest()">
<span id="description" style="color: white"> <span id="description" style="color: white">
This test is only useful as a pixel test. You should see two rows with 4 canvases in each. The top row of canvases should have a black background, the bottom row should have a dark blue background. This test is only useful as a pixel test. You should see two rows with 4 canvases in each. The top row of canvases should have a black background, the bottom row should have a dark blue background.
The canvases in the first two rows should have a single triangle. The canvases on the left should have two triangles superimposed on top of each other. The canvases in the first two rows should have a single triangle. The canvases on the right should have two triangles superimposed on top of each other.
If multisampling is supported, the odd columns should have smooth edges instead of jagged stair-stepping. If multisampling is supported, the odd columns should have smooth edges instead of jagged stair-stepping.
</span> </span>
<br> <br>
...@@ -52,8 +52,11 @@ document.getElementById("description").style.top = "-5000px"; ...@@ -52,8 +52,11 @@ document.getElementById("description").style.top = "-5000px";
for (var i=0; i<8; ++i) { for (var i=0; i<8; ++i) {
var attrs = { var attrs = {
// The bottom row has 'alpha': true.
'alpha': (i >= 4), 'alpha': (i >= 4),
// The 3rd and 4th column has 'preserveDrawingBuffer': true.
'preserveDrawingBuffer': (i % 4) >= 2, 'preserveDrawingBuffer': (i % 4) >= 2,
// The 2nd and 4th column has 'antialias': true.
'antialias': (i % 2) == 1 'antialias': (i % 2) == 1
}; };
var can = document.createElement('canvas'); var can = document.createElement('canvas');
...@@ -103,6 +106,8 @@ function draw(gl, offset) { ...@@ -103,6 +106,8 @@ function draw(gl, offset) {
// draw // draw
gl.drawArrays(gl.TRIANGLES, 0, 3); gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.deleteBuffer(buffer);
} }
function drawAll(offset) { function drawAll(offset) {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<script src="../../resources/visibility.js"></script> <script src="../../resources/visibility.js"></script>
<span id="description" style="color: white"> <span id="description" style="color: white">
This test is only useful as a pixel test. You should see two rows with 4 canvases in each. The top row of canvases should have a black background, the bottom row should have a dark blue background. This test is only useful as a pixel test. You should see two rows with 4 canvases in each. The top row of canvases should have a black background, the bottom row should have a dark blue background.
The canvases in the first two rows should have a single triangle. The canvases on the left should have three triangles superimposed on top of each other. The canvases in the first two rows should have a single triangle. The canvases on the right should have three triangles superimposed on top of each other.
If multisampling is supported, the odd columns should have smooth edges instead of jagged stair-stepping. If multisampling is supported, the odd columns should have smooth edges instead of jagged stair-stepping.
</span> </span>
<br> <br>
...@@ -106,6 +106,8 @@ function draw(gl, offset) { ...@@ -106,6 +106,8 @@ function draw(gl, offset) {
// draw // draw
gl.drawArrays(gl.TRIANGLES, 0, 3); gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.deleteBuffer(buffer);
} }
function drawAll(offset) { function drawAll(offset) {
......
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