Skip to content

Commit 089caaf

Browse files
committed
Fix glUniform with WEBGL2 + CAN_ADDRESS_2GB
1 parent 833448b commit 089caaf

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ jobs:
819819
browser_2gb.test_cubegeom*
820820
browser_2gb.test_html5_webgl_create_context*
821821
browser_2gb.test_main_thread_async_em_asm
822+
browser_2gb.test_webgl2_garbage_free_entrypoints*
823+
browser_2gb.test_webgl2_sokol*
822824
"
823825
test-browser-chrome-wasm64-4gb:
824826
executor: bionic

src/library_webgl.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,14 +2672,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26722672
#if GL_ASSERTIONS
26732673
assert(GL.currentContext.version >= 2);
26742674
#endif
2675-
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*2);
2675+
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
26762676
#else
26772677

26782678
#if MAX_WEBGL_VERSION >= 2
26792679
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use
26802680
// those always when possible.
26812681
if ({{{ isCurrentContextWebGL2() }}}) {
2682-
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*2);
2682+
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
26832683
return;
26842684
}
26852685
#endif
@@ -2709,21 +2709,21 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27092709
glUniform3fv: (location, count, value) => {
27102710
#if GL_ASSERTIONS
27112711
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform3fv', 'location');
2712-
assert((value & 3) == 0, 'Pointer to float data passed to glUniform3fv must be aligned to four bytes!' + value);
2712+
assert((value % 4) == 0, 'Pointer to float data passed to glUniform3fv must be aligned to four bytes!' + value);
27132713
#endif
27142714

27152715
#if MIN_WEBGL_VERSION >= 2
27162716
#if GL_ASSERTIONS
27172717
assert(GL.currentContext.version >= 2);
27182718
#endif
2719-
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*3);
2719+
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value'. 'float') }}}, count*3);
27202720
#else
27212721

27222722
#if MAX_WEBGL_VERSION >= 2
27232723
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use
27242724
// those always when possible.
27252725
if ({{{ isCurrentContextWebGL2() }}}) {
2726-
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*3);
2726+
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*3);
27272727
return;
27282728
}
27292729
#endif

src/library_webgl2.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,23 +622,23 @@ var LibraryWebGL2 = {
622622
assert((value & 3) == 0, 'Pointer to integer data passed to glClearBufferiv must be aligned to four bytes!');
623623
#endif
624624

625-
GLctx.clearBufferiv(buffer, drawbuffer, HEAP32, value>>2);
625+
GLctx.clearBufferiv(buffer, drawbuffer, HEAP32, {{{ getHeapOffset('value', 'float') }}});
626626
},
627627

628628
glClearBufferuiv: (buffer, drawbuffer, value) => {
629629
#if GL_ASSERTIONS
630630
assert((value & 3) == 0, 'Pointer to integer data passed to glClearBufferuiv must be aligned to four bytes!');
631631
#endif
632632

633-
GLctx.clearBufferuiv(buffer, drawbuffer, HEAPU32, value>>2);
633+
GLctx.clearBufferuiv(buffer, drawbuffer, HEAPU32, {{{ getHeapOffset('value', 'float') }}});
634634
},
635635

636636
glClearBufferfv: (buffer, drawbuffer, value) => {
637637
#if GL_ASSERTIONS
638638
assert((value & 3) == 0, 'Pointer to float data passed to glClearBufferfv must be aligned to four bytes!');
639639
#endif
640640

641-
GLctx.clearBufferfv(buffer, drawbuffer, HEAPF32, value>>2);
641+
GLctx.clearBufferfv(buffer, drawbuffer, HEAPF32, {{{ getHeapOffset('value', 'float') }}});
642642
},
643643

644644
glFenceSync: (condition, flags) => {
@@ -776,7 +776,7 @@ var LibraryWebGL2 = {
776776
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform1uiv', 'location');
777777
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform1uiv must be aligned to four bytes!');
778778
#endif
779-
count && GLctx.uniform1uiv(webglGetUniformLocation(location), HEAPU32, value>>2, count);
779+
count && GLctx.uniform1uiv(webglGetUniformLocation(location), HEAPU32, {{{ getHeapOffset('value', 'float') }}}, count);
780780
},
781781

782782
glUniform2uiv__deps: ['$webglGetUniformLocation'],
@@ -785,7 +785,7 @@ var LibraryWebGL2 = {
785785
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform2uiv', 'location');
786786
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform2uiv must be aligned to four bytes!');
787787
#endif
788-
count && GLctx.uniform2uiv(webglGetUniformLocation(location), HEAPU32, value>>2, count*2);
788+
count && GLctx.uniform2uiv(webglGetUniformLocation(location), HEAPU32, {{{ getHeapOffset('value', 'float') }}}, count*2);
789789
},
790790

791791
glUniform3uiv__deps: ['$webglGetUniformLocation'],
@@ -794,7 +794,7 @@ var LibraryWebGL2 = {
794794
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform3uiv', 'location');
795795
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform3uiv must be aligned to four bytes!');
796796
#endif
797-
count && GLctx.uniform3uiv(webglGetUniformLocation(location), HEAPU32, value>>2, count*3);
797+
count && GLctx.uniform3uiv(webglGetUniformLocation(location), HEAPU32, {{{ getHeapOffset('value', 'float') }}}, count*3);
798798
},
799799

800800
glUniform4uiv__deps: ['$webglGetUniformLocation'],
@@ -803,7 +803,7 @@ var LibraryWebGL2 = {
803803
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform4uiv', 'location');
804804
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform4uiv must be aligned to four bytes!');
805805
#endif
806-
count && GLctx.uniform4uiv(webglGetUniformLocation(location), HEAPU32, value>>2, count*4);
806+
count && GLctx.uniform4uiv(webglGetUniformLocation(location), HEAPU32, {{{ getHeapOffset('value', 'float') }}}, count*4);
807807
},
808808

809809
glUniformMatrix2x3fv__deps: ['$webglGetUniformLocation'],
@@ -812,7 +812,7 @@ var LibraryWebGL2 = {
812812
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix2x3fv', 'location');
813813
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix2x3fv must be aligned to four bytes!');
814814
#endif
815-
count && GLctx.uniformMatrix2x3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*6);
815+
count && GLctx.uniformMatrix2x3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*6);
816816
},
817817

818818
glUniformMatrix3x2fv__deps: ['$webglGetUniformLocation'],
@@ -821,7 +821,7 @@ var LibraryWebGL2 = {
821821
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix3x2fv', 'location');
822822
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix3x2fv must be aligned to four bytes!');
823823
#endif
824-
count && GLctx.uniformMatrix3x2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*6);
824+
count && GLctx.uniformMatrix3x2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*6);
825825
},
826826

827827
glUniformMatrix2x4fv__deps: ['$webglGetUniformLocation'],
@@ -830,7 +830,7 @@ var LibraryWebGL2 = {
830830
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix2x4fv', 'location');
831831
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix2x4fv must be aligned to four bytes!');
832832
#endif
833-
count && GLctx.uniformMatrix2x4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*8);
833+
count && GLctx.uniformMatrix2x4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*8);
834834
},
835835

836836
glUniformMatrix4x2fv__deps: ['$webglGetUniformLocation'],
@@ -839,7 +839,7 @@ var LibraryWebGL2 = {
839839
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix4x2fv', 'location');
840840
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix4x2fv must be aligned to four bytes!');
841841
#endif
842-
count && GLctx.uniformMatrix4x2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*8);
842+
count && GLctx.uniformMatrix4x2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*8);
843843
},
844844

845845
glUniformMatrix3x4fv__deps: ['$webglGetUniformLocation'],
@@ -848,7 +848,7 @@ var LibraryWebGL2 = {
848848
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix3x4fv', 'location');
849849
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix3x4fv must be aligned to four bytes!');
850850
#endif
851-
count && GLctx.uniformMatrix3x4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*12);
851+
count && GLctx.uniformMatrix3x4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*12);
852852
},
853853

854854
glUniformMatrix4x3fv__deps: ['$webglGetUniformLocation'],
@@ -857,7 +857,7 @@ var LibraryWebGL2 = {
857857
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix4x3fv', 'location');
858858
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix4x3fv must be aligned to four bytes!');
859859
#endif
860-
count && GLctx.uniformMatrix4x3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*12);
860+
count && GLctx.uniformMatrix4x3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*12);
861861
},
862862

863863
glVertexAttribI4iv: (index, v) => {

test/browser/webgl2_garbage_free_entrypoints.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ int main(int argc, char *argv[])
5656
assert(glGetError() == GL_NO_ERROR && "Shader program link failed");
5757

5858
int color_loc = glGetUniformLocation(program, "color");
59+
assert(glGetError() == GL_NO_ERROR);
5960
assert(color_loc != -1);
6061

6162
glUseProgram(program);
63+
assert(glGetError() == GL_NO_ERROR);
6264
float col[3] = { 0.2f, 0.2f, 0.2f };
6365
glUniform3fv(color_loc, 1, col);
66+
assert(glGetError() == GL_NO_ERROR);
6467

6568
int loc2 = glGetUniformLocation(program, "colors[2]");
6669
int loc = glGetUniformLocation(program, "colors");
@@ -75,7 +78,10 @@ int main(int argc, char *argv[])
7578

7679
float colors[4*3] = { 1,0,0, 0,0.5,0, 0,0,0.2, 1,1,1 };
7780

78-
glUniform3fv(loc+1, 3, colors+3); // Pass the actual colors (testing a nonzero location offset), but do a mistake by setting one index too many. Spec says this should be gracefully handled, and that excess elements are ignored.
81+
// Pass the actual colors (testing a nonzero location offset), but do a
82+
// mistake by setting one index too many. Spec says this should be gracefully
83+
// handled, and that excess elements are ignored.
84+
glUniform3fv(loc+1, 3, colors+3);
7985
assert(glGetError() == GL_NO_ERROR);
8086
glUniform3fv(loc, 1, colors); // Set the first index as well.
8187
assert(glGetError() == GL_NO_ERROR);

test/test_browser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,9 +2802,12 @@ def test_webgl2_ubos(self):
28022802
self.btest_exit('webgl2_ubos.cpp', args=['-sMAX_WEBGL_VERSION=2', '-lGL'])
28032803

28042804
@requires_graphics_hardware
2805-
def test_webgl2_garbage_free_entrypoints(self):
2806-
self.btest_exit('webgl2_garbage_free_entrypoints.cpp', args=['-sMAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1'])
2807-
self.btest_exit('webgl2_garbage_free_entrypoints.cpp')
2805+
@parameterized({
2806+
'': ([],),
2807+
'webgl2': (['-sMAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1'],),
2808+
})
2809+
def test_webgl2_garbage_free_entrypoints(self, args):
2810+
self.btest_exit('webgl2_garbage_free_entrypoints.cpp', args=args)
28082811

28092812
@requires_graphics_hardware
28102813
def test_webgl2_backwards_compatibility_emulation(self):

0 commit comments

Comments
 (0)