Support SharedArrayBuffers#2387
Conversation
This annotates all ArrayBuffer or ArrayBufferView types with [AllowShared], per the proto-specification at https://tc39.github.io/ecmascript_sharedmem/dom_shmem.html#webgl, extended to also modify the Web GL 2.0 entrypoints. This allows the backing data to be a SharedArrayBuffer, instead of only non-shared ArrayBuffers, per whatwg/webidl#353. This also makes some related editorial changes, removing the redundant BufferDataSource typedef in favor of the defined-in-Web IDL BufferSource type, and consolidating two overloads of bufferData (one accepting ArrayBuffer? and the other accepting ArrayBufferView) into a single overload accepting BufferSource?.
|
When I enabled this in Chrome, I also added the |
|
Ah, great to know. That wasn't suggested in https://tc39.github.io/ecmascript_sharedmem/dom_shmem.html#webgl, but it does seem like the principal is to be maximal rather than minimal. I'll upload another commit to add those. /cc @lars-t-hansen |
|
What about the functions like getUniform and getVertexAttrib that return typed arrays? Are they backed by SABs, or still normal ABs? |
|
Just scanning the code in Chrome, these seem to generally return new non-shared typed arrays w/ new backing stores. The one exception seems to be calling But I'm no expert here, so I may have missed something. |
|
@domenic, there was no grand principle at work, I think. @juj provided for shared memory on APIs that were essential to make WebGL work with shared memory from compiled asm.js code (now webassembly code). Note that adding EDIT: Fixed typo. |
|
Some offline discussion between WebAssembly/SharedArrayBuffer implementers concluded that the more maximal scope in this PR is good to go, but we should carefully review any further additions for the reasons @lars-t-hansen states. |
|
The prerequisite Web IDL pull request has been merged. So this is ready for editor review. |
| void bufferData(GLenum target, ArrayBuffer? data, GLenum usage); | ||
| void bufferData(GLenum target, ArrayBufferView data, GLenum usage); | ||
| void bufferSubData(GLenum target, GLintptr offset, BufferDataSource data); | ||
| void bufferData(GLenum target, [AllowShared] BufferSource? data, GLenum usage); |
There was a problem hiding this comment.
I assume that passing null for this union type to bufferData won't cause a failure to resolve the overload -- that it will still generate an INVALID_OPERATION OpenGL error per the spec.
There was a problem hiding this comment.
Indeed, null is a valid value of type [AllowShared] BufferSource? data, so it'll still end up hitting the prose which causes the error.
| void bufferData(GLenum target, ArrayBuffer? srcData, GLenum usage); | ||
| void bufferData(GLenum target, ArrayBufferView srcData, GLenum usage); | ||
| void bufferSubData(GLenum target, GLintptr dstByteOffset, BufferDataSource srcData); | ||
| void bufferData(GLenum target, [AllowShared] BufferSource? srcData, GLenum usage); |
|
Since the spec editors haven't commented, let's merge this now. Thanks @domenic for adding this support. |
Parallels changes made in KhronosGroup#2387 to the core WebGL 1.0 and 2.0 specifications to support SharedArrayBuffer, and implicitly, multithreaded WebAssembly. Fixes KhronosGroup#3219 .
This annotates all ArrayBuffer or ArrayBufferView types with [AllowShared], per the proto-specification at https://tc39.github.io/ecmascript_sharedmem/dom_shmem.html#webgl, extended to also modify the Web GL 2.0 entrypoints. This allows the backing data to be a SharedArrayBuffer, instead of only non-shared ArrayBuffers, per whatwg/webidl#353.
This also makes some related editorial changes, removing the redundant BufferDataSource typedef in favor of the defined-in-Web IDL BufferSource type, and consolidating two overloads of bufferData (one accepting ArrayBuffer? and the other accepting ArrayBufferView) into a single overload accepting BufferSource?.
This is my first time contributing to the Web GL spec, so help appreciated with any policies, procedures, or style issues.
I also imagine we'll want to update the conformance test suite as well, but that's outside my capabilities. @binji or @flagxor may be able to help with that. I've left "allow edits from maintainers" checked so that others can push such test additions directly to this PR, if they like.
This should not be merged until whatwg/webidl#353 is.