> On Jul 14, 2020, at 12:00, Beuc <[email protected]> wrote: > >> >> XMLHttpRequest most definitely supports receiving responses into >> ArrayBuffers. You set responseType=‘arrayBuffer’. However now I look more >> closely at the API there doesn’t seem to be any way to provide it with the >> destination ArrayBuffer. It looks like XMLHttpRequest always creates it >> itself which makes my question moot. > One optimization I did for RenPyWeb was importing XMLHttpRequest's buffer > into the filesystem (FS): > https://github.com/renpy/renpy/blob/8b0d3dd4986a5a8656b3a5ad634c62bd52b1afbd/renpy/webloader.py#L64 > > <https://github.com/renpy/renpy/blob/8b0d3dd4986a5a8656b3a5ad634c62bd52b1afbd/renpy/webloader.py#L64> > FS.writeFile(path, new Uint8Array(xhr.response), {canOwn:true}); > I'm not sure what's your use case is, it might help. > >
My use case is an inflater and transcoder for universal supercompressed
textures. the incoming texture file, received by XMLHttpRequest into am
ArrayBuffer, is parsed in JS from which a typed array with the data for a mip
level is created. That has, maybe, it’s file dependent, to be passed to a Zstd
decoder compiled with Emscripten. Back in JS-land, JS identifies the position
and length of each image and then must pass the image data to the transcoder,
also compiled with Emscripten.
My goal is to reduce data copies to the minimum so I don’t think saving in the
filesystem will help. Thanks for the suggestion though.
I have some further questions to help guide me on the right path w.r.t WebIDL
binder vs Embind and moving the data.
1. Is it possible for 2 separately compiled .wasm packages to use the same
HEAP8, possibly by not modularizing them? My initial plan was to make a
separate Zstd module but a different HEAP8 from that used by the transcoder
means a data copy.
2. If I use WebIDL binder then to pass data into, e.g. the Zstd decoder, I will
have to do in Javascript:
var levelData = new Uint8Array( this.arrayBuffer, this.levels[ level
].byteOffs, this.levels[ level ].byteLength);
var deflatedData = this.zstdModule._malloc(this.levels[ level
].byteLength);
var inflatedData = this.zstdModule._malloc(this.levels[ level
].uncompressedByteLength);
this.zstdModule.HEAPU8.set(levelData, deflatedData);
var byteCount = zstdDecoder.decompress(inflatedData,
this.levels[ level
].uncompressedByteLength,
deflatedData,
this.levels[ level ].byteLength);
I have a c++ wrapper around the Zstd decoder, which is c code. This class is
called ZstdDecoder. Is it possible to add JS to this class so instead of users
of the decoder doing the above they could just call something more in the
spirit of JS that hides the mallocs and takes a typed array in?
var byteCount = zstdDecoder.decompress(i
this.levels[ level
].uncompressedByteLength,
levelData,
);
var inflatedData = zstdDecoder.getInflatedData();
Regards
-Mark
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/8128FE9C-6D80-4292-B240-0D74B364AA8D%40callow.im.
signature.asc
Description: Message signed with OpenPGP
