InterleavedTypedArray type

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

InterleavedTypedArray type

J Decker

I would like to open a discussion to propose that an extension to http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects should be defined that would allow defintiion of interleaved typed data.

Support for interleaved vertex data is one use...


Defines how OpenGL describes interleaved data.

This could also be used to interop with native code as an array of packed (C) structs.

I don't really know what the definition mechanics might be, but for usage I might like to see...

var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' }, ... probably an array of objects defining the fields in an element ], <element count> );

arr[x].fieldName = value.



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

Isiah Meadows-2
I'm not sure this belongs in the spec. There exists a similar thing on
npm [1] which deals with Buffers instead, but you could adapt it
similarly to work with ArrayBuffers (via a DataView). In reality, this
really only would have two uses: native C interop (in Node/etc.) and
WebAssembly interop (which is better addressed by separate
`foo_create` and `foo_destroy` exports with raw pointers and creating
a JS wrapper to manage them more idiomatically).

[1]: https://www.npmjs.com/package/ref-struct
-----

Isiah Meadows
[hidden email]

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sun, Jul 2, 2017 at 9:42 AM, J Decker <[hidden email]> wrote:

>
> I would like to open a discussion to propose that an extension to
> http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects
> should be defined that would allow defintiion of interleaved typed data.
>
> Support for interleaved vertex data is one use...
>
> https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
>  section Use Interleaved Vertex Data
>
>
> https://www.khronos.org/opengl/wiki/Vertex_Specification
> Defines how OpenGL describes interleaved data.
>
> This could also be used to interop with native code as an array of packed
> (C) structs.
>
> I don't really know what the definition mechanics might be, but for usage I
> might like to see...
>
> var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' },
> ... probably an array of objects defining the fields in an element ],
> <element count> );
>
> arr[x].fieldName = value.
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

J Decker

On Sun, Jul 2, 2017 at 6:50 AM, Isiah Meadows <[hidden email]> wrote:
I'm not sure this belongs in the spec.

Typed arrays are in the spec....
 
There exists a similar thing on
npm [1] which deals with Buffers instead, but you could adapt it
similarly to work with ArrayBuffers (via a DataView). In reality, this
really only would have two uses: native C interop (in Node/etc.) and
WebAssembly interop (which is better addressed by separate
`foo_create` and `foo_destroy` exports with raw pointers and creating
a JS wrapper to manage them more idiomatically).

[1]: https://www.npmjs.com/package/ref-struct
-----

Isiah Meadows
[hidden email]

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sun, Jul 2, 2017 at 9:42 AM, J Decker <[hidden email]> wrote:
>
> I would like to open a discussion to propose that an extension to
> http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects
> should be defined that would allow defintiion of interleaved typed data.
>
> Support for interleaved vertex data is one use...
>
> https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
>  section Use Interleaved Vertex Data
>
>
> https://www.khronos.org/opengl/wiki/Vertex_Specification
> Defines how OpenGL describes interleaved data.
>
> This could also be used to interop with native code as an array of packed
> (C) structs.
>
> I don't really know what the definition mechanics might be, but for usage I
> might like to see...
>
> var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' },
> ... probably an array of objects defining the fields in an element ],
> <element count> );
>
> arr[x].fieldName = value.
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

Lars Hansen
The TypedObjects proposal does this, for what it calls non-opaque types (you can define types and then map them onto an ArrayBuffer in various ways).  I'm not 100% sure what the latest text is, I expect it is here: https://github.com/tschneidereit/typed-objects-explainer but it could also be here: https://github.com/nikomatsakis/typed-objects-explainer.

TypedObjects is currently a stalled proposal.  I expect it may be revived when WebAssembly integration into JS becomes a more seriously discussed topic.

--lars

On Sun, Jul 2, 2017 at 6:53 AM, J Decker <[hidden email]> wrote:

On Sun, Jul 2, 2017 at 6:50 AM, Isiah Meadows <[hidden email]> wrote:
I'm not sure this belongs in the spec.

Typed arrays are in the spec....
 
There exists a similar thing on
npm [1] which deals with Buffers instead, but you could adapt it
similarly to work with ArrayBuffers (via a DataView). In reality, this
really only would have two uses: native C interop (in Node/etc.) and
WebAssembly interop (which is better addressed by separate
`foo_create` and `foo_destroy` exports with raw pointers and creating
a JS wrapper to manage them more idiomatically).

[1]: https://www.npmjs.com/package/ref-struct
-----

Isiah Meadows
[hidden email]

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sun, Jul 2, 2017 at 9:42 AM, J Decker <[hidden email]> wrote:
>
> I would like to open a discussion to propose that an extension to
> http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects
> should be defined that would allow defintiion of interleaved typed data.
>
> Support for interleaved vertex data is one use...
>
> https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
>  section Use Interleaved Vertex Data
>
>
> https://www.khronos.org/opengl/wiki/Vertex_Specification
> Defines how OpenGL describes interleaved data.
>
> This could also be used to interop with native code as an array of packed
> (C) structs.
>
> I don't really know what the definition mechanics might be, but for usage I
> might like to see...
>
> var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' },
> ... probably an array of objects defining the fields in an element ],
> <element count> );
>
> arr[x].fieldName = value.
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

J Decker


On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <[hidden email]> wrote:
The TypedObjects proposal does this, for what it calls non-opaque types (you can define types and then map them onto an ArrayBuffer in various ways).  I'm not 100% sure what the latest text is, I expect it is here: https://github.com/tschneidereit/typed-objects-explainer but it could also be here: https://github.com/nikomatsakis/typed-objects-explainer.

 
That's about a single structure; as is the thing Isiah suggested (ref-struct) and not an array of packed structures such as would be used for interleaved vertex data.
 
TypedObjects is currently a stalled proposal.  I expect it may be revived when WebAssembly integration into JS becomes a more seriously discussed topic.

--lars

On Sun, Jul 2, 2017 at 6:53 AM, J Decker <[hidden email]> wrote:

On Sun, Jul 2, 2017 at 6:50 AM, Isiah Meadows <[hidden email]> wrote:
I'm not sure this belongs in the spec.

Typed arrays are in the spec....
 
There exists a similar thing on
npm [1] which deals with Buffers instead, but you could adapt it
similarly to work with ArrayBuffers (via a DataView). In reality, this
really only would have two uses: native C interop (in Node/etc.) and
WebAssembly interop (which is better addressed by separate
`foo_create` and `foo_destroy` exports with raw pointers and creating
a JS wrapper to manage them more idiomatically).

[1]: https://www.npmjs.com/package/ref-struct
-----

Isiah Meadows
[hidden email]

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sun, Jul 2, 2017 at 9:42 AM, J Decker <[hidden email]> wrote:
>
> I would like to open a discussion to propose that an extension to
> http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects
> should be defined that would allow defintiion of interleaved typed data.
>
> Support for interleaved vertex data is one use...
>
> https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
>  section Use Interleaved Vertex Data
>
>
> https://www.khronos.org/opengl/wiki/Vertex_Specification
> Defines how OpenGL describes interleaved data.
>
> This could also be used to interop with native code as an array of packed
> (C) structs.
>
> I don't really know what the definition mechanics might be, but for usage I
> might like to see...
>
> var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' },
> ... probably an array of objects defining the fields in an element ],
> <element count> );
>
> arr[x].fieldName = value.
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

Lars Hansen
On Sun, Jul 2, 2017 at 9:12 AM, J Decker <[hidden email]> wrote:


On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <[hidden email]> wrote:
The TypedObjects proposal does this, for what it calls non-opaque types (you can define types and then map them onto an ArrayBuffer in various ways).  I'm not 100% sure what the latest text is, I expect it is here: https://github.com/tschneidereit/typed-objects-explainer but it could also be here: https://github.com/nikomatsakis/typed-objects-explainer.

 
That's about a single structure; as is the thing Isiah suggested (ref-struct) and not an array of packed structures such as would be used for interleaved vertex data.

​No, the TypedObjects proposal allows for packed arrays of structures, without references.  See https://github.com/tschneidereit/typed-objects-explainer/blob/master/core.md#struct-arrays.

--lars​
 
TypedObjects is currently a stalled proposal.  I expect it may be revived when WebAssembly integration into JS becomes a more seriously discussed topic.

--lars

On Sun, Jul 2, 2017 at 6:53 AM, J Decker <[hidden email]> wrote:

On Sun, Jul 2, 2017 at 6:50 AM, Isiah Meadows <[hidden email]> wrote:
I'm not sure this belongs in the spec.

Typed arrays are in the spec....
 
There exists a similar thing on
npm [1] which deals with Buffers instead, but you could adapt it
similarly to work with ArrayBuffers (via a DataView). In reality, this
really only would have two uses: native C interop (in Node/etc.) and
WebAssembly interop (which is better addressed by separate
`foo_create` and `foo_destroy` exports with raw pointers and creating
a JS wrapper to manage them more idiomatically).

[1]: https://www.npmjs.com/package/ref-struct
-----

Isiah Meadows
[hidden email]

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sun, Jul 2, 2017 at 9:42 AM, J Decker <[hidden email]> wrote:
>
> I would like to open a discussion to propose that an extension to
> http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects
> should be defined that would allow defintiion of interleaved typed data.
>
> Support for interleaved vertex data is one use...
>
> https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
>  section Use Interleaved Vertex Data
>
>
> https://www.khronos.org/opengl/wiki/Vertex_Specification
> Defines how OpenGL describes interleaved data.
>
> This could also be used to interop with native code as an array of packed
> (C) structs.
>
> I don't really know what the definition mechanics might be, but for usage I
> might like to see...
>
> var arr = new InterleavedTypeArray( [ { name: "fieldName", type:"uint32' },
> ... probably an array of objects defining the fields in an element ],
> <element count> );
>
> arr[x].fieldName = value.
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

Steve Fink
On 07/02/2017 11:20 AM, Lars Hansen wrote:
On Sun, Jul 2, 2017 at 9:12 AM, J Decker <[hidden email]> wrote:


On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <[hidden email]> wrote:
The TypedObjects proposal does this, for what it calls non-opaque types (you can define types and then map them onto an ArrayBuffer in various ways).  I'm not 100% sure what the latest text is, I expect it is here: https://github.com/tschneidereit/typed-objects-explainer but it could also be here: https://github.com/nikomatsakis/typed-objects-explainer.

 
That's about a single structure; as is the thing Isiah suggested (ref-struct) and not an array of packed structures such as would be used for interleaved vertex data.

​No, the TypedObjects proposal allows for packed arrays of structures, without references.  See https://github.com/tschneidereit/typed-objects-explainer/blob/master/core.md#struct-arrays.

--lars​
 
TypedObjects is currently a stalled proposal.  I expect it may be revived when WebAssembly integration into JS becomes a more seriously discussed topic.


TypedObjects are exactly what you want for this sort of use case, and are really quite nice. I'm no expert, but TypedArrays probably ought to be subsumed by the TypedObject spec since AFAICT they are a proper subset of TypedObject arrays, at least for practical purposes.

Spidermonkey has had them implemented since sometime in 2013, though we haven't used them much and the constructors are of course not exposed to the Web. (And the implementation of TypedArrays is still separate, and has better JIT support.) They're really quite nice when you have the sorts of problems they're meant for. For other problems, I would guess they would be quite an attractive nuisance. ;-)


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

Till Schneidereit-2
On Mon, Jul 3, 2017 at 8:10 PM, Steve Fink <[hidden email]> wrote:
TypedObjects are exactly what you want for this sort of use case, and are really quite nice. I'm no expert, but TypedArrays probably ought to be subsumed by the TypedObject spec since AFAICT they are a proper subset of TypedObject arrays, at least for practical purposes.

I looked into whether this is feasible, and unfortunately I'm not optimistic. For one, the current TypedObjects proposal has __proto__ read-only, which we could certainly not do for TypedArray classes. But ok, they might be exceptional in that regard, I guess. Even if you strip away everything else, simply the change in prototype chains might not be web-compatible, though.

Still, it's certainly something that should be tried if and when the proposal gets un-stalled.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: InterleavedTypedArray type

J Decker
In reply to this post by Steve Fink


On Mon, Jul 3, 2017 at 11:10 AM, Steve Fink <[hidden email]> wrote:
On 07/02/2017 11:20 AM, Lars Hansen wrote:
On Sun, Jul 2, 2017 at 9:12 AM, J Decker <[hidden email]> wrote:


On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <[hidden email]> wrote:
The TypedObjects proposal does this, for what it calls non-opaque types (you can define types and then map them onto an ArrayBuffer in various ways).  I'm not 100% sure what the latest text is, I expect it is here: https://github.com/tschneidereit/typed-objects-explainer but it could also be here: https://github.com/nikomatsakis/typed-objects-explainer.

 
That's about a single structure; as is the thing Isiah suggested (ref-struct) and not an array of packed structures such as would be used for interleaved vertex data.

​No, the TypedObjects proposal allows for packed arrays of structures, without references.  See https://github.com/tschneidereit/typed-objects-explainer/blob/master/core.md#struct-arrays.

--lars​
 
TypedObjects is currently a stalled proposal.  I expect it may be revived when WebAssembly integration into JS becomes a more seriously discussed topic.


TypedObjects are exactly what you want for this sort of use case, and are really quite nice. I'm no expert, but TypedArrays probably ought to be subsumed by the TypedObject spec since AFAICT they are a proper subset of TypedObject arrays, at least for practical purposes.


Yes; I read the proposal more and found that unfortunately the typed objects are padded. https://github.com/tschneidereit/typed-objects-explainer/blob/master/core.md#alignment-and-padding-examples
and there's no way to specify unpadded.  (although optimal vertex buffers should be arranged so multibyte members are aligned)



 
Spidermonkey has had them implemented since sometime in 2013, though we haven't used them much and the constructors are of course not exposed to the Web. (And the implementation of TypedArrays is still separate, and has better JIT support.) They're really quite nice when you have the sorts of problems they're meant for. For other problems, I would guess they would be quite an attractive nuisance. ;-)


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Loading...