Skip to content

Signed shift on memory access in library_webgl.js when using 4GB support #20137

@landersonfigma

Description

@landersonfigma

When using 4GB support, my understanding is that memory accesses are rewritten to use unsigned shifts. In library_webgl.js, glUniform4fv is rewritten from:

value >>= 2;
for (var i = 0; i < 4 * count; i += 4) {
  var dst = value + i;
  view[i] = heap[dst];
  view[i + 1] = heap[dst + 1];
  view[i + 2] = heap[dst + 2];
  view[i + 3] = heap[dst + 3];
}

to:

value >>= 2;
for (var i = 0; i < 4 * count; i += 4) {
  var dst = value + i;
  view[i] = heap[dst >>> 0];
  view[i + 1] = heap[dst + 1 >>> 0];
  view[i + 2] = heap[dst + 2 >>> 0];
  view[i + 3] = heap[dst + 3 >>> 0];
}

The memory accesses inside the loop look correct but should value >>= 2 be value >>>= 2? With value >>= 2, I get memory accesses that read out of bounds. Possibly the same issue here. Let me know if I'm misunderstanding the expected output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions