InterleavedTypedArray type

# J Decker (7 years ago)

I would like to open a discussion to propose that an extension to 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...

developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html section Use Interleaved Vertex Data

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.

# Isiah Meadows (7 years ago)

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


Isiah Meadows me at isiahmeadows.com

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

# J Decker (7 years ago)

On Sun, Jul 2, 2017 at 6:50 AM, Isiah Meadows <isiahmeadows at gmail.com>

wrote:

I'm not sure this belongs in the spec.

Typed arrays are in the spec.... www.ecma-international.org/ecma-262/6.0/#sec

# Lars Hansen (7 years ago)

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: tschneidereit/typed-objects-explainer but it could also be here: 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.

# J Decker (7 years ago)

On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <lhansen at mozilla.com> 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: tschneidereit/typed-objects-explainer but it could also be here: 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.

# Lars Hansen (7 years ago)

On Sun, Jul 2, 2017 at 9:12 AM, J Decker <d3ck0r at gmail.com> wrote:

On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <lhansen at mozilla.com> 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: tschneidereit/typed-objects-explainer but it could also be here: 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 tschneidereit/typed-objects-explainer/blob/master/core.md#struct-arrays .

--lars​

# Steve Fink (7 years ago)

On 07/02/2017 11:20 AM, Lars Hansen wrote:

On Sun, Jul 2, 2017 at 9:12 AM, J Decker <d3ck0r at gmail.com <mailto:d3ck0r at gmail.com>> wrote:

On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <lhansen at mozilla.com
<mailto:lhansen at mozilla.com>> 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
    <https://github.com/tschneidereit/typed-objects-explainer> but
    it could also be here:
    https://github.com/nikomatsakis/typed-objects-explainer
    <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 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. ;-)

# Till Schneidereit (7 years ago)

On Mon, Jul 3, 2017 at 8:10 PM, Steve Fink <sphink at gmail.com> 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.

# J Decker (7 years ago)

On Mon, Jul 3, 2017 at 11:10 AM, Steve Fink <sphink at gmail.com> wrote:

On 07/02/2017 11:20 AM, Lars Hansen wrote:

On Sun, Jul 2, 2017 at 9:12 AM, J Decker <d3ck0r at gmail.com> wrote:

On Sun, Jul 2, 2017 at 8:25 AM, Lars Hansen <lhansen at mozilla.com> 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: tschneidereit/typed-objects-explainer but it could also be here: 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 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. 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)