Skip to content

Some fixes for library_webgl.js in CAN_ADDRESS_GB mode #21220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,13 @@ jobs:
steps:
- run-tests-chrome:
title: "browser"
# skip test_4gb_fail as it OOMs on the current bot
test_targets: "browser skip:browser.test_4gb_fail"
# Skip test_4gb_fail as it OOMs on the current bot
# Include an representative selection of browser_2gb
test_targets: "
browser_2gb.test_gles2_uniform_arrays
browser_2gb.test_fetch_to_memory
browser skip:browser.test_4gb_fail
"
test-browser-chrome-wasm64:
executor: bionic
steps:
Expand Down
29 changes: 16 additions & 13 deletions src/library_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
return HEAPU16;
},

$heapAccessShiftForWebGLHeap: (heap) => 31 - Math.clz32(heap.BYTES_PER_ELEMENT),
$toTypedArrayIndex: (pointer, heap) =>
#if MEMORY64
pointer / heap.BYTES_PER_ELEMENT,
#else
pointer >>> (31 - Math.clz32(heap.BYTES_PER_ELEMENT)),
#endif

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

$emscriptenWebGLGetTexPixelData__deps: ['$computeUnpackAlignedImageSize', '$colorChannelsInGlTextureFormat', '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'],
$emscriptenWebGLGetTexPixelData__deps: ['$computeUnpackAlignedImageSize', '$colorChannelsInGlTextureFormat', '$heapObjectForWebGLType', '$toTypedArrayIndex'],
$emscriptenWebGLGetTexPixelData: (type, format, width, height, pixels, internalFormat) => {
var heap = heapObjectForWebGLType(type);
var shift = heapAccessShiftForWebGLHeap(heap);
var byteSize = 1<<shift;
var sizePerPixel = colorChannelsInGlTextureFormat(format) * byteSize;
var sizePerPixel = colorChannelsInGlTextureFormat(format) * heap.BYTES_PER_ELEMENT;
var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel, GL.unpackAlignment);
#if GL_ASSERTIONS
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!');
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!');
#endif
return heap.subarray(pixels >> shift, pixels + bytes >> shift);
return heap.subarray(toTypedArrayIndex(pixels, heap), toTypedArrayIndex(pixels + bytes, heap));
},

glTexImage2D__deps: ['$emscriptenWebGLGetTexPixelData'
#if MAX_WEBGL_VERSION >= 2
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
#endif
],
glTexImage2D: (target, level, internalFormat, width, height, border, format, type, pixels) => {
Expand Down Expand Up @@ -1641,7 +1644,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
} else if (pixels) {
var heap = heapObjectForWebGLType(type);
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, toTypedArrayIndex(pixels, heap));
} else {
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, null);
}
Expand All @@ -1653,7 +1656,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};

glTexSubImage2D__deps: ['$emscriptenWebGLGetTexPixelData'
#if MAX_WEBGL_VERSION >= 2
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
#endif
],
glTexSubImage2D: (target, level, xoffset, yoffset, width, height, format, type, pixels) => {
Expand All @@ -1674,7 +1677,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
} else if (pixels) {
var heap = heapObjectForWebGLType(type);
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
} else {
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, null);
}
Expand All @@ -1688,7 +1691,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};

glReadPixels__deps: ['$emscriptenWebGLGetTexPixelData'
#if MAX_WEBGL_VERSION >= 2
, '$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'
, '$heapObjectForWebGLType', '$toTypedArrayIndex'
#endif
],
glReadPixels: (x, y, width, height, format, type, pixels) => {
Expand All @@ -1700,7 +1703,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
GLctx.readPixels(x, y, width, height, format, type, pixels);
} else {
var heap = heapObjectForWebGLType(type);
GLctx.readPixels(x, y, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
GLctx.readPixels(x, y, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
}
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/library_webgl2.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ var LibraryWebGL2 = {
GLctx.invalidateSubFramebuffer(target, list, x, y, width, height);
},

glTexImage3D__deps: ['$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'],
glTexImage3D__deps: ['$heapObjectForWebGLType', '$toTypedArrayIndex'],
glTexImage3D: (target, level, internalFormat, width, height, depth, border, format, type, pixels) => {
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, pixels);
} else if (pixels) {
var heap = heapObjectForWebGLType(type);
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, heap, toTypedArrayIndex(pixels, heap));
} else {
GLctx.texImage3D(target, level, internalFormat, width, height, depth, border, format, type, null);
}
},

glTexSubImage3D__deps: ['$heapObjectForWebGLType', '$heapAccessShiftForWebGLHeap'],
glTexSubImage3D__deps: ['$heapObjectForWebGLType', '$toTypedArrayIndex'],
glTexSubImage3D: (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) => {
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
} else if (pixels) {
var heap = heapObjectForWebGLType(type);
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, heap, toTypedArrayIndex(pixels, heap));
} else {
GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, null);
}
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl2_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 569,
"a.html.gz": 379,
"a.js": 4540,
"a.js.gz": 2345,
"a.js": 4589,
"a.js.gz": 2341,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15560,
"total_gz": 9448
"total": 15609,
"total_gz": 9444
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl2_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 567,
"a.html.gz": 379,
"a.js": 17746,
"a.js.gz": 7982,
"a.js": 17795,
"a.js.gz": 7978,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 21436,
"total_gz": 11054
"total": 21485,
"total_gz": 11050
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 569,
"a.html.gz": 379,
"a.js": 4027,
"a.js.gz": 2173,
"a.js": 4075,
"a.js.gz": 2170,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15047,
"total_gz": 9276
"total": 15095,
"total_gz": 9273
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 567,
"a.html.gz": 379,
"a.js": 17219,
"a.js.gz": 7814,
"a.js": 17267,
"a.js.gz": 7813,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 20909,
"total_gz": 10886
"total": 20957,
"total_gz": 10885
}
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58197
58187
1 change: 1 addition & 0 deletions test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
'bigint',
'browser64',
'browser64_4gb',
'browser_2gb',
]


Expand Down
12 changes: 11 additions & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

@no_firefox('no 4GB support yet')
@no_2gb('uses MAXIMUM_MEMORY')
@no_4gb('uses MAXIMUM_MEMORY')
def test_4gb(self):
# TODO Convert to an actual browser test when it reaches stable.
Expand Down Expand Up @@ -5668,6 +5669,7 @@ def test_emmalloc_memgrowth(self, *args):
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'])

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

@no_firefox('no 4GB support yet')
@no_2gb('uses MAXIMUM_MEMORY')
@no_4gb('uses MAXIMUM_MEMORY')
def test_4gb_fail(self):
# TODO Convert to an actual browser test when it reaches stable.
Expand Down Expand Up @@ -5917,3 +5920,10 @@ def setUp(self):
self.set_setting('GLOBAL_BASE', '4gb')
self.emcc_args.append('-Wno-experimental')
self.require_wasm64()


class browser_2gb(browser):
def setUp(self):
super().setUp()
self.set_setting('INITIAL_MEMORY', '2200mb')
self.set_setting('GLOBAL_BASE', '2gb')