Fix API calls to WebGL where an optional size parameter is zero bytes#16837
Fix API calls to WebGL where an optional size parameter is zero bytes#16837juj merged 1 commit intoemscripten-core:mainfrom
Conversation
…, which would upload the whole WebAssembly heap since WebGL has a different semantics when zero size is passed. Fixes emscripten-core#16799.
|
We don't have tests for this, so recommend a careful review. |
kainino0x
left a comment
There was a problem hiding this comment.
Nice catch, and good example of sentinel 0 values being a footgun. Glad we removed them in WebGPU.
| assert(GL.currentContext.version >= 2); | ||
| #endif | ||
| GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, value>>2, count); | ||
| count && GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, value>>2, count); |
There was a problem hiding this comment.
Is this just another way of writing if (count) .... but saving two bytes?
Seems a little odd to do the micro-optimization here but not globally across the codebase.
There was a problem hiding this comment.
Is this just another way of writing if (count) .... but saving two bytes?
That's right.
Seems a little odd to do the micro-optimization here but not globally across the codebase.
Maybe. It is used consistently in WebGL library, and that is probably more on the hot code size path that some of the other libraries.
There was a problem hiding this comment.
Ah, ok. I didn't realize there was precedent for this.
There was a problem hiding this comment.
I think closure does this? If not, it would be easy to add a js optimizer pass. I think depending on the optimizer for this kind of thing is probably best (keeps code more readable and the optimization applies to more places).
|
It seems odd that we don't have tests for any of this .. are they hard to write? |
There are 26 API entry points that are affected, which is a lot of tests to write. Writing tests that check that the whole Wasm heap is not being serialized probably would require some kind of mocking/polyfilling on the ArrayBuffer. |
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. Fixes: emscripten-core#21567
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. Fixes: emscripten-core#21567
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. Fixes: emscripten-core#21567
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. As part of this change I resurrected `test_webgl_draw_triangle_with_uniform_color.c` which has not actually be used since emscripten-core#20925. Fixes: emscripten-core#21567
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. As part of this change I resurrected `test_webgl_draw_triangle_with_uniform_color.c` which has not actually be used since emscripten-core#20925. Fixes: emscripten-core#21567
The previous fix for this was in emscripten-core#16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. As part of this change I resurrected `test_webgl_draw_triangle_with_uniform_color.c` which has not actually be used since emscripten-core#20925. Fixes: emscripten-core#21567
The previous fix for this was in #16837, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. As part of this change I resurrected `test_webgl_draw_triangle_with_uniform_color.c` which has not actually be used since #20925. Fixes: #21567
Fix API calls to WebGL where an optional size parameter is zero bytes, which would upload the whole WebAssembly heap since WebGL has a different semantics when zero size is passed. Fixes #16799.