Skip to content

Commit

Permalink
Tolerate throws in wasm/* tests, add 2gb-in-4gb variants. (#3665)
Browse files Browse the repository at this point in the history
* Tolerate throws in wasm/* tests, add 2gb-in-4gb variants.

For browsers that don't support this large of wasm memory sizes,
consider as PASS, so that browser features don't block webgl
conformance.
For UAs that throw on use of large TypedArrays, FAIL but safely.

Also, Firefox *does* support ~4GB wasm memory sizes, but currently
throws when >2GB TypedArray views are passed to entrypoints. However,
Firefox does support <2GB-sized views of >2GB ArrayBuffers, so add tests
for that.
This reflects the ability for apps to use large WASM heaps, so long as
only smaller views are passed to webgl.
  • Loading branch information
kdashg authored Jul 25, 2024
1 parent 0ee1bed commit 2d0e7f8
Show file tree
Hide file tree
Showing 19 changed files with 929 additions and 315 deletions.
24 changes: 15 additions & 9 deletions sdk/tests/conformance2/wasm/00_test_list.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
--min-version 2.0.1 readpixels-16gb-wasm-memory.html
--min-version 2.0.1 readpixels-4gb-wasm-memory.html
--min-version 2.0.1 teximage2d-16gb-wasm-memory.html
--min-version 2.0.1 teximage2d-4gb-wasm-memory.html
--min-version 2.0.1 texsubimage2d-16gb-wasm-memory.html
--min-version 2.0.1 texsubimage2d-4gb-wasm-memory.html
--min-version 2.0.1 bufferdata-16gb-wasm-memory.html
--min-version 2.0.1 bufferdata-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 bufferdata-4gb-wasm-memory.html
--min-version 2.0.1 buffersubdata-16gb-wasm-memory.html
--min-version 2.0.1 bufferdata-16gb-wasm-memory.html
--min-version 2.0.1 buffersubdata-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 buffersubdata-4gb-wasm-memory.html
--min-version 2.0.1 buffersubdata-16gb-wasm-memory.html
--min-version 2.0.1 getbuffersubdata-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 getbuffersubdata-4gb-wasm-memory.html
--min-version 2.0.1 getbuffersubdata-16gb-wasm-memory.html
--min-version 2.0.1 getbuffersubdata-4gb-wasm-memory.html
--min-version 2.0.1 readpixels-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 readpixels-4gb-wasm-memory.html
--min-version 2.0.1 readpixels-16gb-wasm-memory.html
--min-version 2.0.1 teximage2d-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 teximage2d-4gb-wasm-memory.html
--min-version 2.0.1 teximage2d-16gb-wasm-memory.html
--min-version 2.0.1 texsubimage2d-2gb-in-4gb-wasm-memory.html
--min-version 2.0.1 texsubimage2d-4gb-wasm-memory.html
--min-version 2.0.1 texsubimage2d-16gb-wasm-memory.html
44 changes: 28 additions & 16 deletions sdk/tests/conformance2/wasm/bufferdata-16gb-wasm-memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,42 @@
<script>
"use strict";
description(document.title);
debug("Tests that bufferData can be called on WebAssembly Memory of 16GB in size.");
debug("Tests that bufferData can be called on the end of a WebAssembly Memory of 16GB in size.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const SIZE = 16 * 1024 * 1024 * 1024;
let view = new Uint8Array(new WebAssembly.Memory({ index: 'i64', initial: SIZE / PAGE }).buffer);
let expectedData = new Uint8Array([1, 2, 3, 4]);
const length = expectedData.length;
const offset = SIZE - length;
view.set(expectedData, offset);
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ index: 'i64', initial: SIZE / PAGE }).buffer);
} catch (e) {
testPassed(`Allocating ${SIZE} threw: ${e}`);
return;
}

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, length);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
let expectedData = new Uint8Array([1, 2, 3, 4]);
const length = expectedData.length;
const offset = SIZE - length;
view.set(expectedData, offset);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, actualData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
for (let i = 0; i < length; i++) {
shouldBe(`actualData[${i}]`, `expectedData[${i}]`);
}
let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
try {
gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, length);
} catch (e) {
testFailed(`bufferData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, actualData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
Expand Down
64 changes: 64 additions & 0 deletions sdk/tests/conformance2/wasm/bufferdata-2gb-in-4gb-wasm-memory.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
Copyright (c) 2024 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>bufferData test to Wasm Memory 4GB in size.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description(document.title);
debug("Tests that bufferData can be called on the end of a ~2GB view into ~4GB of WebAssembly Memory.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const HEAP_SIZE = 4 * 1024 * 1024 * 1024 - PAGE;
const VIEW_SIZE = 2 * 1024 * 1024 * 1024 - PAGE;
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ initial: HEAP_SIZE / PAGE }).buffer, 0, VIEW_SIZE);
} catch (e) {
testPassed(`Allocating ${HEAP_SIZE} threw: ${e}`);
return;
}

let expectedData = new Uint8Array([1, 2, 3, 4]);
const length = expectedData.length;
const offset = view.length - length;
view.set(expectedData, offset);

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
try {
gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, length);
} catch (e) {
testFailed(`bufferData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, actualData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>
44 changes: 28 additions & 16 deletions sdk/tests/conformance2/wasm/bufferdata-4gb-wasm-memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,42 @@
<script>
"use strict";
description(document.title);
debug("Tests that bufferData can be called on WebAssembly Memory of 4GB in size.");
debug("Tests that bufferData can be called on the end of a WebAssembly Memory of nearly 4GB in size.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const SIZE = 4 * 1024 * 1024 * 1024 - PAGE;
let view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE / PAGE }).buffer);
let expectedData = new Uint8Array([1, 2, 3, 4]);
const length = expectedData.length;
const offset = SIZE - length;
view.set(expectedData, offset);
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE / PAGE }).buffer);
} catch (e) {
testPassed(`Allocating ${SIZE} threw: ${e}`);
return;
}

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, length);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
let expectedData = new Uint8Array([1, 2, 3, 4]);
const length = expectedData.length;
const offset = SIZE - length;
view.set(expectedData, offset);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, actualData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
for (let i = 0; i < length; i++) {
shouldBe(`actualData[${i}]`, `expectedData[${i}]`);
}
let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
try {
gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, length);
} catch (e) {
testFailed(`bufferData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, actualData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
Expand Down
46 changes: 29 additions & 17 deletions sdk/tests/conformance2/wasm/buffersubdata-16gb-wasm-memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,43 @@
<script>
"use strict";
description(document.title);
debug("Tests that bufferSubData can be called on WebAssembly Memory of 16GB in size.");
debug("Tests that bufferSubData can be called on the end of a WebAssembly Memory of 16GB in size.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const SIZE = 16 * 1024 * 1024 * 1024;
let view = new Uint8Array(new WebAssembly.Memory({ index: 'i64', initial: SIZE / PAGE }).buffer);
let expectedData = new Uint8Array([1, 2]);
const length = expectedData.length;
let srcOffset = SIZE - length;
view.set(expectedData, srcOffset);
const dstByteOffset = 4;
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ index: 'i64', initial: SIZE / PAGE }).buffer);
} catch (e) {
testPassed(`Allocating ${SIZE} threw: ${e}`);
return;
}

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, 8, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, view, srcOffset, length);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
let expectedData = new Uint8Array([1, 2]);
const length = expectedData.length;
let srcOffset = SIZE - length;
view.set(expectedData, srcOffset);
const dstByteOffset = 4;

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, dstByteOffset, actualData);
for (let i = 0; i < length; i++) {
shouldBe(`actualData[${i}]`, `expectedData[${i}]`);
}
let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, 8, gl.STATIC_DRAW);
try {
gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, view, srcOffset, length);
} catch (e) {
testFailed(`bufferSubData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, dstByteOffset, actualData);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--
Copyright (c) 2024 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>bufferSubData test to Wasm Memory 4GB in size.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description(document.title);
debug("Tests that bufferSubData can be called on the end of a ~2GB view into ~4GB of WebAssembly Memory.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const HEAP_SIZE = 4 * 1024 * 1024 * 1024 - PAGE;
const VIEW_SIZE = 2 * 1024 * 1024 * 1024 - PAGE;
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ initial: HEAP_SIZE / PAGE }).buffer, 0, VIEW_SIZE);
} catch (e) {
testPassed(`Allocating ${HEAP_SIZE} threw: ${e}`);
return;
}

let expectedData = new Uint8Array([1, 2]);
const length = expectedData.length;
let srcOffset = view.length - length;
view.set(expectedData, srcOffset);
const dstByteOffset = 4;

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, 8, gl.STATIC_DRAW);
try {
gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, view, srcOffset, length);
} catch (e) {
testFailed(`bufferSubData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, dstByteOffset, actualData);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>
46 changes: 29 additions & 17 deletions sdk/tests/conformance2/wasm/buffersubdata-4gb-wasm-memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,43 @@
<script>
"use strict";
description(document.title);
debug("Tests that bufferSubData can be called on WebAssembly Memory of 4GB in size.");
debug("Tests that bufferSubData can be called on the end of a WebAssembly Memory of nearly 4GB in size.");
debug("");
let wtu = WebGLTestUtils;
let gl = wtu.create3DContext("canvas", undefined, 2);

const PAGE = 65536;
const SIZE = 4 * 1024 * 1024 * 1024 - PAGE;
let view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE / PAGE }).buffer);
let expectedData = new Uint8Array([1, 2]);
const length = expectedData.length;
let srcOffset = SIZE - length;
view.set(expectedData, srcOffset);
const dstByteOffset = 4;
(() => {
let view;
try {
view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE / PAGE }).buffer);
} catch (e) {
testPassed(`Allocating ${SIZE} threw: ${e}`);
return;
}

let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, 8, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, view, srcOffset, length);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
let expectedData = new Uint8Array([1, 2]);
const length = expectedData.length;
let srcOffset = SIZE - length;
view.set(expectedData, srcOffset);
const dstByteOffset = 4;

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, dstByteOffset, actualData);
for (let i = 0; i < length; i++) {
shouldBe(`actualData[${i}]`, `expectedData[${i}]`);
}
let buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, 8, gl.STATIC_DRAW);
try {
gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, view, srcOffset, length);
} catch (e) {
testFailed(`bufferSubData from ${view.length} byte view threw: ${e}`);
return;
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

let actualData = new Uint8Array(length);
gl.getBufferSubData(gl.ARRAY_BUFFER, dstByteOffset, actualData);
expectArray(actualData, expectedData);
})();

var successfullyParsed = true;
</script>
Expand Down
Loading

0 comments on commit 2d0e7f8

Please sign in to comment.