From 129e0f05b1d43949d06a34db663552929fa3b89c Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 2 Feb 2024 15:51:49 -0800 Subject: [PATCH] Fix glDrawElements under CAN_ADDRESS_2GB This is partially a workround for #21250 --- .circleci/config.yml | 1 + src/library_glemu.js | 14 ++++++++++---- src/parseTools.js | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b13bb169e4744..586e0f56386b1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -821,6 +821,7 @@ jobs: browser_2gb.test_cubegeom browser_2gb.test_cubegeom_normal browser_2gb.test_cubegeom_normal_dap + browser_2gb.test_cubegeom_normal_dap_far " test-browser-chrome-wasm64-4gb: executor: bionic diff --git a/src/library_glemu.js b/src/library_glemu.js index ddca86d6bce1b..9ebc0c9524773 100644 --- a/src/library_glemu.js +++ b/src/library_glemu.js @@ -2940,9 +2940,9 @@ var LibraryGLEmulation = { // Detect which case we are in by using a quick heuristic by examining the // strides of the buffers. If all the buffers have identical stride, we // assume we have case (2), otherwise we have something more complex. - var clientStartPointer = 0x7FFFFFFF; + var clientStartPointer = {{{ POINTER_MAX }}}; var bytes = 0; // Total number of bytes taken up by a single vertex. - var minStride = 0x7FFFFFFF; + var minStride = {{{ POINTER_MAX }}}; var maxStride = 0; var attributes = GLImmediate.liveClientAttributes; attributes.length = 0; @@ -3544,8 +3544,14 @@ var LibraryGLEmulation = { GLImmediate.firstVertex = end ? start : HEAP8.length; // if we don't know the start, set an invalid value and we will calculate it later from the indices GLImmediate.lastVertex = end ? end + 1 : 0; start = GLImmediate.vertexPointer; - end = end ? GLImmediate.vertexPointer + (end+1)*GLImmediate.stride : undefined; - GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}}, end ? {{{ getHeapOffset('end', 'float') }}} : undefined); + // TODO(sbc): Combine these two subarray calls back into a single one if + // we ever fix https://github.com/emscripten-core/emscripten/issues/21250. + if (end) { + end = GLImmediate.vertexPointer + (end +1 ) * GLImmediate.stride; + GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}}, {{{ getHeapOffset('end', 'float') }}}); + } else { + GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}}); + } } GLImmediate.flush(count, 0, indices); GLImmediate.mode = -1; diff --git a/src/parseTools.js b/src/parseTools.js index ef91fc93198bb..c56e6d9f5dd7b 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -176,6 +176,7 @@ function needsQuoting(ident) { } globalThis.POINTER_SIZE = MEMORY64 ? 8 : 4; +globalThis.POINTER_MAX = MEMORY64 ? 'Number.MAX_SAFE_INTEGER' : '2**32'; globalThis.STACK_ALIGN = 16; const POINTER_BITS = POINTER_SIZE * 8; const POINTER_TYPE = `u${POINTER_BITS}`;