Open
Description
a.cpp
#include <emscripten.h>
struct options
{
int x;
};
extern "C" int navigator_gpu_request_adapter_sync(options *opts);
int main()
{
options opts = { 100 };
int adapter = navigator_gpu_request_adapter_sync(&opts);
EM_ASM(console.log(`Got adapter ${0}`), adapter);
}
lib_a.js
mergeInto(LibraryManager.library, {
navigator_gpu_request_adapter_sync__sig: 'ip',
navigator_gpu_request_adapter_sync__async: true,
navigator_gpu_request_adapter_sync: function(opts) {
console.error(`navigator_gpu_request_adapter_sync: opts: ${opts}`);
if (!opts) throw 'opts cannot be null';
var promise = navigator.gpu.requestAdapter().then(a => { return 42; });
return Asyncify.handleAsync(() => {
return promise;
});
}
});
em++ a.cpp --js-library lib_a.js -sASYNCIFY=1 -sASYNCIFY_IMPORTS=['navigator_gpu_request_adapter_sync'] -o a.html
works as expected, but
em++ a.cpp --js-library lib_a.js -sASYNCIFY=2 -sASYNCIFY_IMPORTS=['navigator_gpu_request_adapter_sync'] -o a.html
doesn't, and instead raises the exception opts cannot be null
.
Tested in Chrome Canary 120.0.6076.0 (Official Build) canary (64-bit) on Windows.
I find there's not much documentation on JSPI, but based on the test suite code, it looks like it should work by just replacing -sASYNCIFY=1
with -sASYNCIFY=2
(and adding the __sig
directives)?
Metadata
Metadata
Assignees
Labels
No labels