[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Public WebGL] TypedArrays and mapped memory regions
- To: public webgl <email@example.com>
- Subject: [Public WebGL] TypedArrays and mapped memory regions
- From: Cedric Vivier <firstname.lastname@example.org>
- Date: Thu, 5 Aug 2010 11:46:15 +0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received:from:date :x-google-sender-auth:message-id:subject:to:content-type; bh=oXjRjDFs9d5yjMkJLZ0dD/GJciaxBM5+1J+GTMo84fM=; b=ucAUJTHMw2JUnVwVKXtiWCkUPgBg2sdAvtzcb0q8MZ31OTeH1qr7DB5eZUsIOPWoX6 cYsAs5eB/X4C6mRY8ISBrRaR0JRQUABXep71ZkOp0je0vK8Cf3D/5cm6wMNvRj19l/SA VZYuXzj9Z9B5MWJ9LqXCNddFBhMGQ/MwFxy8E=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; b=PTo50nK/drBsH+uczTioatyz7dPoUAfhV3sn/418Bg4sUTX+BYoNX1NkgdbRhLST4K cvFZwpa+/I225BWAvYgzFsi02cQXXVB02SwuPLOvM5mXdDfGuyHcJh1NECVGDI5iL2bQ uMpcD8RCsAqnsR4bLpbkkT76cGuavZ+Nvw2g8=
- Sender: email@example.com
TypedArrays and their underlying ArrayBuffer gives efficient native/direct access and interoperability with low-level languages to memory regions.
Native memory regions do not always have read/write access like assumed right now by the spec though, some native APIs give back read-only or write-only memory regions.
Potential users for this are WebGL extensions, File API, Node.JS(?), etc...
I propose a minimally intrusive addition to the spec to define behavior that makes TypedArrays usage compatible with any mapped memory region :
[addition to ArrayBuffer type spec]
readonly attribute boolean readable;
True if the the ArrayBuffer contents can be read from, false otherwise.
readonly attribute boolean writable;
True if the the ArrayBuffer contents can be written to, false otherwise.
[addition to ArrayBuffer constructor spec]
The contents of the ArrayBuffer are initialized to 0 and both readable and writable attributes are true.
[addition to TypedArray getter spec]
If the underlying ArrayBuffer is not readable (readable attribute set to false) an INVALID_ACCESS_ERR is raised.
[addition to TypedArray setter spec]
If the underlying ArrayBuffer is not writable (writable attribute set to false) an INVALID_ACCESS_ERR is raised.
- frontend APIs have consistent illegal access behavior and aren't required to implement/document custom types and behavior over existing TypedArray implementations.
- for some APIs memory usage and GC churning can be greatly reduced as this allows zero-copy mechanisms.
Prospective example with glMapBuffer : (NB: not the only potential user and I do not support its inclusion in WebGL 1.0 of course ;)
array = gl.mapBuffer(GL_ARRAY_BUFFER, GL_WRITEONLY);
//array is writable only
//fill the array with, say, procedurally generated data from an audio waveform
//array is now neither readable or writable as backend storage is unmapped
//any attempt to access its contents will raise an INVALID_ACCESS_ERR
Proposed patch to support this spec addition in Mozilla :
Proposed patch to add a helper for native JS code to create an ArrayBuffer from a mapped region :
(patch not required to support the spec addition of course)