Skip to content

Support SharedArrayBuffers#2387

Merged
kenrussell merged 2 commits into
KhronosGroup:masterfrom
domenic:webidl-sab
May 10, 2017
Merged

Support SharedArrayBuffers#2387
kenrussell merged 2 commits into
KhronosGroup:masterfrom
domenic:webidl-sab

Conversation

@domenic

@domenic domenic commented May 1, 2017

Copy link
Copy Markdown
Contributor

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.

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?.
@binji

binji commented May 1, 2017

Copy link
Copy Markdown

When I enabled this in Chrome, I also added the [AllowShared] attribute to Float32Array (e.g. uniformMatrix2fv, among many others) , Int32Array (vertexAttribI4iv), and Uint32Array (vertexAttribI4uiv) parameters.

@domenic

domenic commented May 1, 2017

Copy link
Copy Markdown
Contributor Author

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

@domenic

domenic commented May 1, 2017

Copy link
Copy Markdown
Contributor Author

What about the functions like getUniform and getVertexAttrib that return typed arrays? Are they backed by SABs, or still normal ABs?

@binji

binji commented May 1, 2017

Copy link
Copy Markdown

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 getVertexAttrib with ARRAY_BUFFER_BINDING, which seems to return an existing non-shared ArrayBuffer.

But I'm no expert here, so I may have missed something.

@lars-t-hansen

lars-t-hansen commented May 2, 2017

Copy link
Copy Markdown

@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 [AllowShared] is likely to lead to situations where memory might be accessed racily by the implementation. It is important to consider the security consequences of that, esp time-of-check-to-time-of-use consequences. IMO the principle should be to be closer to minimal, not closer to maximal.

EDIT: Fixed typo.

@domenic

domenic commented May 2, 2017

Copy link
Copy Markdown
Contributor Author

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.

@domenic

domenic commented May 3, 2017

Copy link
Copy Markdown
Contributor Author

The prerequisite Web IDL pull request has been merged. So this is ready for editor review.

@kenrussell kenrussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Domenic, these changes look good overall. Any reviews from the spec editors @grorg and @jdashg ?

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

@kenrussell

Copy link
Copy Markdown
Member

Since the spec editors haven't commented, let's merge this now. Thanks @domenic for adding this support.

@kenrussell
kenrussell merged commit 6517159 into KhronosGroup:master May 10, 2017
@domenic
domenic deleted the webidl-sab branch May 10, 2017 21:40
kenrussell added a commit to kenrussell/WebGL that referenced this pull request May 18, 2021
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 .
kdashg pushed a commit that referenced this pull request May 18, 2021
…3286)

Parallels changes made in #2387 to the core WebGL 1.0 and 2.0
specifications to support SharedArrayBuffer, and implicitly,
multithreaded WebAssembly.

Fixes #3219 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants