New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 708730 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Apr 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

WebGL2 offscreen rendering demos show red background color

Project Member Reported by flo...@gmail.com, Apr 5 2017

Issue description

Chrome Version: 57.0.2987.133 (Official Build) (64-bit)
OS: 10.12, Win10 (others not yet tested)

In some cases in WebGL2, clearing an offscreen framebuffer with texture color-attachment, and then sampling that texture in a fragment shader produces a red color.

What steps will reproduce the problem?

In Chrome, go to the following demos: 
- https://floooh.github.io/oryol-webgl2/asmjs/SimpleRenderTarget.html
- https://floooh.github.io/oryol-webgl2/asmjs/RenderToCubeMap.html
- https://floooh.github.io/oryol-webgl2/asmjs/MultipleRenderTarget.html

Note how some of the rendered objects have a pure red 'background' color. Now do the same in Firefox, note how the background colors are grey (there's a separate issue in the render-to-cubemap demo in FF on OSX, where the background is black, please ignore).

In Chrome, no errors or warnings are printed on the JS console. The same demos on iOS running (or desktop platforms) in GL debuggers also don't produce any warnings (apart from a few redundant render states).

It looks like the clear operation using clearBufferfv() somehow breaks, since the actual rendering into the offscreen framebuffer works.

Different clear colors change nothing, the background is always a pure red (is this a debug-color maybe?).

I haven't been able yet to write a minimal reproducer in JS. A simple example where an offscreen framebuffer is cleared and blitted to the back buffer looks good. The examples are more complex in that they sample the texture which is attached to the offscreen framebuffer though.

A chrome://gpu log is attached

 
about_gpu.htm
155 KB View Download

Comment 1 by flo...@gmail.com, Apr 5 2017

> The same demos on iOS running (or desktop platforms) in GL debuggers also don't produce any warnings (apart from a few redundant render states).

I should clarify that I mean 'running the natively compiled iOS or desktop versions of the demos' here, not in browsers :)
Components: Internals>GPU>WebGL Blink>WebGL

Comment 3 by zmo@chromium.org, Apr 5 2017

Cc: kbr@chromium.org zmo@chromium.org kainino@chromium.org
Status: Available (was: Untriaged)
I saw the described difference between Chrome and Firefox on Linux (NVidia).

No, we don't use Red as debug-color.

Can you help reducing the demos into a minimized test case?

Comment 4 by zmo@chromium.org, Apr 5 2017

Labels: -Pri-3 Pri-2
Labels: -OS-Windows -OS-Mac OS-All
It seems to have already been fixed between 58.0.3029.54 and 59.0.3053.3.
Never mind, it's still there in 59. I had WebGL 2 disabled in my 59 dev profile.

Comment 7 by flo...@gmail.com, Apr 6 2017

@zmo: yes I'll try to create a minimal test case in JS, but it might be a few days until I can work on that

Comment 8 by flo...@gmail.com, Apr 10 2017

Just a quick update, I'm still trying to create a simplified test case which reproduces the problem but so far without success. I'm using a GL call log via the apitrace tool from the native OSX demo, and try to reproduce the GL call sequence in JS, but so far this doesn't show the problem.

The trace log is here: https://github.com/floooh/webgl2-test/blob/master/issue708730_repro/apitrace_osx.txt

And the wip JS code is here: https://github.com/floooh/webgl2-test/blob/master/issue708730_repro/script.js

I'll continue with this tomorrow, there must be some subtle difference between the WebGL2 version and the native version that I'm not yet aware of.

Cheers,
-Floh.


Comment 9 by kbr@chromium.org, Apr 10 2017

Is there a possibility of a bug in Emscripten's shim which translates ES 3.0 calls to WebGL 2.0 calls?

Comment 10 by flo...@gmail.com, Apr 11 2017

It's definitely possible that it is a bug in the emscripten shim yes, I'll try to get to the bottom of that. But it's still different behaviour in FF and Chrome, so may be an edge case which should IMHO trigger a warning on the JS console.

Comment 11 by flo...@gmail.com, Apr 11 2017

Hmm, replacing the single call to glClearBufferfv() with the 'old' glClearColor()/glClear() makes the offscreen clearing work in this demo. I'll have a closer look at the emscripten SDK now, maybe there's a problem with translating the pointer-parameter from glClearBufferfv() to a JS array (so that only the first 'red'-value is considered, which would explain the red clear color). It's strange though that this would only happen in Chrome.

Please don't spend any time on this issue for now :)

Comment 12 by flo...@gmail.com, Apr 11 2017

Ok I found the bug \O/, it's Chrome's clearBufferfv() implementation when called with
Float32Array and an offset into that array (that's what emscripten does, it passes the
global heap and an offset into that to clearBufferfv()). It looks like the offset is ignored, and Chrome will always take the four floats at the start of the array. I have attached a test case (it's much more complex then it needs to be though). When you run that there will be a rectangle in the center of the screen with a red background, this should be gray (and on Firefox it is).

The interesting part is this:

    // an 'oversized' Float32Array with the actual clear
    // color (0.25, 0.25, 0.25, 1.0) in the middle
    let fp32 = new Float32Array([
        1.0, 0.0, 0.0, 1.0,
        0.25, 0.25, 0.25, 1.0,
        0.0, 1.0, 0.0, 1.0
    ]);
    // call clearBufferfv with the Float32Array and and offset
    // to find the clear color (this seems to be broken in Chrome)
    gl.clearBufferfv(gl.COLOR, 0, fp32, 4);


gl.clearBufferfv() is called with an offset of 4 to arrive at the right clear color,
and this seems to be ignored.
issue708730_repro.zip
8.4 KB Download

Comment 13 by flo...@gmail.com, Apr 11 2017

Here's a much simpler, complete test case, this clears the WebGL2 canvas to read on Chrome, and to grey on Firefox:

<!DOCTYPE html>
<body>
    <canvas id="canvas" width="640" height="480"></canvas>
    <script>
        let canvas = document.getElementById('canvas');
        let gl = canvas.getContext('webgl2', {});
        let fp32 = new Float32Array([
        1.0, 0.0, 0.0, 1.0,
        0.25, 0.25, 0.25, 1.0,
        0.0, 1.0, 0.0, 1.0
        ]);
        function draw() {
        gl.clearBufferfv(gl.COLOR, 0, fp32, 4);
        requestAnimationFrame(draw);
        }
        draw();
    </script>
</body>

Comment 14 by zmo@chromium.org, Apr 11 2017

Cc: -zmo@chromium.org
Owner: zmo@chromium.org
Status: Assigned (was: Available)
Embarrassingly to say, clearBuffer*() calls with optional offset signatures are not implemented in Chrome because there are no tests for them.

Thanks for catching this and the test case.

Comment 15 by zmo@chromium.org, Apr 11 2017

Status: Started (was: Assigned)
CL is uploaded: https://codereview.chromium.org/2809873003/
Conformance test is uploaded: https://github.com/KhronosGroup/WebGL/pull/2364

Comment 16 by flo...@gmail.com, Apr 12 2017

Thanks for the quick fix! Looking forward to when it will go live :)
Project Member

Comment 17 by bugdroid1@chromium.org, Apr 13 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/67caee99605db7a1bde5ea88de2f8425672b0931

commit 67caee99605db7a1bde5ea88de2f8425672b0931
Author: zmo <zmo@chromium.org>
Date: Thu Apr 13 02:12:23 2017

Implement sub source for WebGL2's clearBuffer*().

Conformance test is uploaded: https://github.com/KhronosGroup/WebGL/pull/2364

BUG= 708730 
TEST=conformance2/rendering/clearbuffer-sub-source.html
R=kbr@chromium.org,kainino@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2809873003
Cr-Commit-Position: refs/heads/master@{#464246}

[modify] https://crrev.com/67caee99605db7a1bde5ea88de2f8425672b0931/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
[modify] https://crrev.com/67caee99605db7a1bde5ea88de2f8425672b0931/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.h
[modify] https://crrev.com/67caee99605db7a1bde5ea88de2f8425672b0931/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.idl

Comment 18 by zmo@chromium.org, Apr 13 2017

Status: Fixed (was: Started)
I verified the above CL fixed the issue.

Comment 19 by flo...@gmail.com, Apr 19 2017

Looks like the fix has arrived in Canary now (I'm on Version 60.0.3074.0 canary). Thanks a lot!
Project Member

Comment 20 by bugdroid1@chromium.org, Apr 19 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9589135cc575bcaeb2b730df193ca9cbc408cec4

commit 9589135cc575bcaeb2b730df193ca9cbc408cec4
Author: qiankun.miao <qiankun.miao@intel.com>
Date: Wed Apr 19 17:53:53 2017

Roll WebGL fd73a60..73fd432

https://chromium.googlesource.com/external/khronosgroup/webgl.git/+log/fd73a60..73fd432

BUG= 708730 ,  712584 ,  712117 ,  713127 ,  angleproject:1966 

TEST=bots

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.win:win_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2820113008
Cr-Commit-Position: refs/heads/master@{#465664}

[modify] https://crrev.com/9589135cc575bcaeb2b730df193ca9cbc408cec4/DEPS
[modify] https://crrev.com/9589135cc575bcaeb2b730df193ca9cbc408cec4/content/test/gpu/gpu_tests/webgl2_conformance_expectations.py
[modify] https://crrev.com/9589135cc575bcaeb2b730df193ca9cbc408cec4/content/test/gpu/gpu_tests/webgl_conformance_expectations.py
[modify] https://crrev.com/9589135cc575bcaeb2b730df193ca9cbc408cec4/content/test/gpu/gpu_tests/webgl_conformance_revision.txt

Components: -Internals>GPU>WebGL

Sign in to add a comment