Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[WebGL] Simulated vertexAttrib0 can sometimes cause OUT_OF_MEMORY errors
https://bugs.webkit.org/show_bug.cgi?id=181558 <rdar://problem/36189833> Reviewed by Eric Carlson. Source/WebCore: Very large element indices in the ELEMENT_ARRAY_BUFFER meant that our simulated vertexAttrib0 buffer might be too large. We need to check for out-of-memory, but we can also detect some of the issues earlier in our validation code. Additionally, make sure that we don't accidentally cast an unsigned to a signed. Test: fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies.html * html/canvas/WebGL2RenderingContext.cpp: (WebCore::WebGL2RenderingContext::validateIndexArrayConservative): Update validation code to look for overflow, rather than relying on looking for sign changes. * html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::validateIndexArrayConservative): Ditto. * html/canvas/WebGLRenderingContextBase.cpp: (WebCore::WebGLRenderingContextBase::validateIndexArrayPrecise): (WebCore::WebGLRenderingContextBase::drawArrays): Check that we were able to simulate. (WebCore::WebGLRenderingContextBase::drawElements): (WebCore::WebGLRenderingContextBase::validateSimulatedVertexAttrib0): Update validation code, and use GC3Duint, since that's what the indicies are. (WebCore::WebGLRenderingContextBase::simulateVertexAttrib0): Ditto. (WebCore::WebGLRenderingContextBase::drawArraysInstanced): Check that we were able to simulate. (WebCore::WebGLRenderingContextBase::drawElementsInstanced): * html/canvas/WebGLRenderingContextBase.h: LayoutTests: * fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies-expected.txt: Added. * fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies.html: Added. * platform/mac/TestExpectations: Test crashes on Sierra and earlier. Canonical link: https://commits.webkit.org/197474@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
188 additions
and 29 deletions.
- +12 −0 LayoutTests/ChangeLog
- +5 −0 LayoutTests/fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies-expected.txt
- +67 −0 LayoutTests/fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies.html
- +4 −0 LayoutTests/platform/mac/TestExpectations
- +32 −0 Source/WebCore/ChangeLog
- +6 −4 Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
- +6 −4 Source/WebCore/html/canvas/WebGLRenderingContext.cpp
- +54 −19 Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
- +2 −2 Source/WebCore/html/canvas/WebGLRenderingContextBase.h
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,5 @@ | ||
CONSOLE MESSAGE: line 49: WebGL: INVALID_OPERATION: drawElements: attempt to access out of bounds arrays | ||
CONSOLE MESSAGE: line 59: WebGL: INVALID_OPERATION: drawElements: unable to simulate vertexAttrib0 array | ||
PASS: MAX_UINT index was unable to be simulated | ||
PASS: Huge index was unable to be simulated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,67 @@ | ||
<canvas id="canvas" width="10" height="10"></canvas> | ||
<div></div> | ||
<script id='vertex-shader' type='x-shader/x-vertex'> | ||
attribute vec3 position; | ||
void main(void) { | ||
gl_Position = vec4(position, 1.0); | ||
} | ||
</script> | ||
<script id='fragment-shader' type='x-shader/x-fragment'> | ||
precision mediump float; | ||
void main(void) { | ||
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); | ||
} | ||
</script> | ||
<script> | ||
function output(msg) { | ||
document.querySelector("div").innerHTML += msg + "<br>"; | ||
} | ||
|
||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
|
||
let canvas = document.getElementById("canvas"); | ||
let gl = canvas.getContext("webgl"); | ||
|
||
gl.getExtension("OES_element_index_uint"); | ||
|
||
let vShader = gl.createShader(gl.VERTEX_SHADER); | ||
gl.shaderSource(vShader, document.getElementById("vertex-shader").text); | ||
gl.compileShader(vShader); | ||
|
||
let fShader = gl.createShader(gl.FRAGMENT_SHADER); | ||
gl.shaderSource(fShader, document.getElementById("fragment-shader").text); | ||
gl.compileShader(fShader); | ||
program = gl.createProgram(); | ||
gl.attachShader(program, vShader); | ||
gl.attachShader(program, fShader); | ||
gl.linkProgram(program); | ||
gl.useProgram(program); | ||
|
||
let buffer = gl.createBuffer(); | ||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); | ||
|
||
let data; | ||
|
||
// Maximum uint. | ||
data = new Uint8Array([255, 255, 255, 255]); | ||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.DYNAMIC_DRAW); | ||
gl.drawElements(gl.TRIANGLE_STRIP, 1, gl.UNSIGNED_INT,0); | ||
|
||
if (gl.getError() == gl.INVALID_OPERATION) | ||
output("PASS: MAX_UINT index was unable to be simulated"); | ||
else | ||
output("FAIL: MAX_UINT index did not fail validation"); | ||
|
||
// Two large numbers, one of which is smaller than 0.25 * max uint. | ||
data = new Uint32Array([380000000, 4294967295]); | ||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.DYNAMIC_DRAW); | ||
gl.drawElements(gl.TRIANGLE_STRIP, 1, gl.UNSIGNED_INT,0); | ||
|
||
if (gl.getError() == gl.INVALID_OPERATION) | ||
output("PASS: Huge index was unable to be simulated"); | ||
else | ||
output("FAIL: Huge index did not fail validation"); | ||
|
||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters