Skip to content

Commit c860bcd

Browse files
committed
Some fixes for library_webgl.js in CAN_ADDRESS_GB mode
This is an overall size win too after compression.
1 parent f7651be commit c860bcd

12 files changed

+54
-37
lines changed

.circleci/config.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,12 @@ jobs:
798798
steps:
799799
- run-tests-chrome:
800800
title: "browser"
801-
# skip test_4gb_fail as it OOMs on the current bot
802-
test_targets: "browser skip:browser.test_4gb_fail"
801+
# Skip test_4gb_fail as it OOMs on the current bot
802+
# Include an representative selection of browser2gb
803+
test_targets: "
804+
browser skip:browser.test_4gb_fail
805+
browser2gb.test_gles2_uniform_arrays
806+
"
803807
test-browser-chrome-wasm64:
804808
executor: bionic
805809
steps:

src/library_webgl.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
8282
return HEAPU16;
8383
},
8484

85-
$heapAccessShiftForWebGLHeap: (heap) => 31 - Math.clz32(heap.BYTES_PER_ELEMENT),
85+
$toTypedArrayIndex: (pointer, heap) =>
86+
#if MEMORY64
87+
pointer / heap.BYTES_PER_ELEMENT,
88+
#else
89+
pointer >>> (31 - Math.clz32(heap.BYTES_PER_ELEMENT)),
90+
#endif
8691

8792
#if MIN_WEBGL_VERSION == 1
8893
$webgl_enable_ANGLE_instanced_arrays: (ctx) => {
@@ -1595,22 +1600,20 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15951600
return colorChannels[format - 0x1902]||1;
15961601
},
15971602

1598-
$emscriptenWebGLGetTexPixelData__deps: ['$computeUnpackAlignedImageSize', '$colorChannelsInGlTextureFormat', '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'],
1603+
$emscriptenWebGLGetTexPixelData__deps: ['$computeUnpackAlignedImageSize', '$colorChannelsInGlTextureFormat', '$heapObjectForWebGLType', '$toTypedArrayIndex'],
15991604
$emscriptenWebGLGetTexPixelData: (type, format, width, height, pixels, internalFormat) => {
16001605
var heap = heapObjectForWebGLType(type);
1601-
var shift = heapAccessShiftForWebGLHeap(heap);
1602-
var byteSize = 1<<shift;
1603-
var sizePerPixel = colorChannelsInGlTextureFormat(format) * byteSize;
1606+
var sizePerPixel = colorChannelsInGlTextureFormat(format) * heap.BYTES_PER_ELEMENT;
16041607
var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel, GL.unpackAlignment);
16051608
#if GL_ASSERTIONS
1606-
assert((pixels >> shift) << shift == pixels, 'Pointer to texture data passed to texture get function must be aligned to the byte size of the pixel type!');
1609+
assert(pixels % heap.BYTES_PER_ELEMENT == 0, 'Pointer to texture data passed to texture get function must be aligned to the byte size of the pixel type!');
16071610
#endif
1608-
return heap.subarray(pixels >> shift, pixels + bytes >> shift);
1611+
return heap.subarray(toTypedArrayIndex(pixels, heap), toTypedArrayIndex(pixels + bytes, heap));
16091612
},
16101613

16111614
glTexImage2D__deps: ['$emscriptenWebGLGetTexPixelData'
16121615
#if MAX_WEBGL_VERSION >= 2
1613-
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
1616+
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
16141617
#endif
16151618
],
16161619
glTexImage2D: (target, level, internalFormat, width, height, border, format, type, pixels) => {
@@ -1641,7 +1644,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16411644
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
16421645
} else if (pixels) {
16431646
var heap = heapObjectForWebGLType(type);
1644-
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
1647+
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, toTypedArrayIndex(pixels, heap));
16451648
} else {
16461649
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, null);
16471650
}
@@ -1653,7 +1656,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16531656

16541657
glTexSubImage2D__deps: ['$emscriptenWebGLGetTexPixelData'
16551658
#if MAX_WEBGL_VERSION >= 2
1656-
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
1659+
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
16571660
#endif
16581661
],
16591662
glTexSubImage2D: (target, level, xoffset, yoffset, width, height, format, type, pixels) => {
@@ -1674,7 +1677,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16741677
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
16751678
} else if (pixels) {
16761679
var heap = heapObjectForWebGLType(type);
1677-
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
1680+
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
16781681
} else {
16791682
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, null);
16801683
}
@@ -1688,7 +1691,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16881691

16891692
glReadPixels__deps: ['$emscriptenWebGLGetTexPixelData'
16901693
#if MAX_WEBGL_VERSION >= 2
1691-
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
1694+
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
16921695
#endif
16931696
],
16941697
glReadPixels: (x, y, width, height, format, type, pixels) => {
@@ -1700,7 +1703,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
17001703
GLctx.readPixels(x, y, width, height, format, type, pixels);
17011704
} else {
17021705
var heap = heapObjectForWebGLType(type);
1703-
GLctx.readPixels(x, y, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
1706+
GLctx.readPixels(x, y, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
17041707
}
17051708
return;
17061709
}

test/code_size/hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4540,
5-
"a.js.gz": 2345,
4+
"a.js": 4589,
5+
"a.js.gz": 2341,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15560,
9-
"total_gz": 9448
8+
"total": 15609,
9+
"total_gz": 9444
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17746,
5-
"a.js.gz": 7982,
4+
"a.js": 17795,
5+
"a.js.gz": 7978,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21436,
9-
"total_gz": 11054
8+
"total": 21485,
9+
"total_gz": 11050
1010
}

test/code_size/hello_webgl_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4027,
5-
"a.js.gz": 2173,
4+
"a.js": 4075,
5+
"a.js.gz": 2170,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15047,
9-
"total_gz": 9276
8+
"total": 15095,
9+
"total_gz": 9273
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17219,
5-
"a.js.gz": 7814,
4+
"a.js": 17267,
5+
"a.js.gz": 7813,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 20909,
9-
"total_gz": 10886
8+
"total": 20957,
9+
"total_gz": 10885
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8408
1+
8403
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23069
1+
23059
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7238
1+
7232
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19693
1+
19683
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58237
1+
58227

test/test_browser.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
2525
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
26-
from common import read_file, also_with_minimal_runtime, EMRUN, no_wasm64, no_4gb
26+
from common import read_file, also_with_minimal_runtime, EMRUN, no_wasm64, no_2gb, no_4gb
2727
from tools import shared
2828
from tools import ports
2929
from tools import utils
@@ -5572,6 +5572,7 @@ def test_wasm_worker_proxied_function(self):
55725572
self.btest('wasm_worker/proxied_function.c', expected='0', args=['--js-library', test_file('wasm_worker/proxied_function.js'), '-sWASM_WORKERS', '-sASSERTIONS=0'])
55735573

55745574
@no_firefox('no 4GB support yet')
5575+
@no_2gb('uses MAXIMUM_MEMORY')
55755576
@no_4gb('uses MAXIMUM_MEMORY')
55765577
def test_4gb(self):
55775578
# TODO Convert to an actual browser test when it reaches stable.
@@ -5668,6 +5669,7 @@ def test_emmalloc_memgrowth(self, *args):
56685669
self.btest('emmalloc_memgrowth.cpp', expected='0', args=['-sMALLOC=emmalloc', '-sALLOW_MEMORY_GROWTH=1', '-sABORTING_MALLOC=0', '-sASSERTIONS=2', '-sMINIMAL_RUNTIME=1', '-sMAXIMUM_MEMORY=4GB'])
56695670

56705671
@no_firefox('no 4GB support yet')
5672+
@no_2gb('uses MAXIMUM_MEMORY')
56715673
@no_4gb('uses MAXIMUM_MEMORY')
56725674
def test_2gb_fail(self):
56735675
# TODO Convert to an actual browser test when it reaches stable.
@@ -5682,6 +5684,7 @@ def test_2gb_fail(self):
56825684
self.do_run_in_out_file_test('browser/test_2GB_fail.cpp')
56835685

56845686
@no_firefox('no 4GB support yet')
5687+
@no_2gb('uses MAXIMUM_MEMORY')
56855688
@no_4gb('uses MAXIMUM_MEMORY')
56865689
def test_4gb_fail(self):
56875690
# TODO Convert to an actual browser test when it reaches stable.
@@ -5901,6 +5904,13 @@ def test_emrun(self):
59015904
self.assertContained('hello, error stream!', stderr)
59025905

59035906

5907+
class browser2gb(browser):
5908+
def setUp(self):
5909+
super().setUp()
5910+
self.set_setting('INITIAL_MEMORY', '2200mb')
5911+
self.set_setting('GLOBAL_BASE', '2gb')
5912+
5913+
59045914
class browser64(browser):
59055915
def setUp(self):
59065916
super().setUp()

0 commit comments

Comments
 (0)