Skip to content

Commit

Permalink
Fix glDrawElements under CAN_ADDRESS_2GB
Browse files Browse the repository at this point in the history
This is partially a workround for emscripten-core#21250
  • Loading branch information
sbc100 committed Feb 2, 2024
1 parent e279a10 commit 129e0f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/library_glemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 129e0f0

Please sign in to comment.