Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental threading feature #329

Merged
merged 18 commits into from
Sep 24, 2023
Merged

Experimental threading feature #329

merged 18 commits into from
Sep 24, 2023

Conversation

kalwalt
Copy link
Member

@kalwalt kalwalt commented Aug 25, 2023

Emscripten Pthread feature

I'm experimenting a threaded version of the lib, i want to test if we have an improvement in performances within. I will provide two version: a simle simple wasm version and another with ES6 to be used in the Typescript version.

Note for testing

Because the code use pthreads it's necessary to enable COOP and COEP as mentioned in the Emscripten article. You can try in localhost running the provided python script python-server.py

@kalwalt kalwalt added enhancement New feature or request C/C++ emscripten labels Aug 25, 2023
@kalwalt kalwalt self-assigned this Aug 25, 2023
- the example load the nft marker but raise errors while tracking
@kalwalt
Copy link
Member Author

kalwalt commented Aug 28, 2023

I have commited a simple example with the new threaded version of the lib, for now only the wasm version, it load the nft marker and it track but it not show up anything. I need to check what is wrong. In the console i receive also this message:
artoolkitNFT_thread.js:1 Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread
and sometimes another warning complain that threading and allow memory growth is a bad idea.

Post edit in reference of the last sentence: when compiling with emscripten this message is printed:
emcc: warning: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]

@kalwalt
Copy link
Member Author

kalwalt commented Aug 28, 2023

sometimes instead i get an error like this:

001d5996:0x6464 Uncaught RuntimeError: null function or function signature mismatch
    at 001d5996:0x6464
    at 001d5996:0x1fee1
    at 001d5996:0x628f8
    at 001d5996:0x5bef7
    at Object.detectNFTMarker (eval at new_ (artoolkitNFT_thread.js:1:752608), <anonymous>:8:10)
    at ARControllerNFT.detectNFTMarker (artoolkitNFT_thread.js:1:3358)
    at ARControllerNFT.process (artoolkitNFT_thread.js:1:2397)
    at process (threejs_wasm_thread.js:150:10)
$func161 @ 001d5996:0x6464
$func584 @ 001d5996:0x1fee1
$func1193 @ 001d5996:0x628f8
$func1153 @ 001d5996:0x5bef7
detectNFTMarker @ VM157:8
ARControllerNFT.detectNFTMarker @ artoolkitNFT_thread.js:1
ARControllerNFT.process @ artoolkitNFT_thread.js:1
process @ threejs_wasm_thread.js:150
requestAnimationFrame (asinc)
process @ threejs_wasm_thread.js:153

- the code in this method is already initialized in the threaded func
@kalwalt
Copy link
Member Author

kalwalt commented Aug 28, 2023

With the latest commit it seems that some errors are gone.
The sphere is not displayed because i missed to update the camera projection matrix coming from the ARControllerNFT initialization, i need to send the camera matrix to the threejs camera, will do when i have time.

- required functions for a correct render of models
@kalwalt kalwalt changed the base branch from master to dev September 1, 2023 21:09
@kalwalt
Copy link
Member Author

kalwalt commented Sep 13, 2023

I'm working now on the >Typescript code, it can load the nft markers and instantiate the threaded workers but after i got tis error several times:

GET http://localhost:8000/dist/artoolkitNFT_ES6_wasm_td.worker.js 404 (File not found)
ARToolkitNFT_td.js:2 worker sent an error! undefined:undefined: undefined
I.onerror @ ARToolkitNFT_td.js:2
error (asinc)
(anonimo) @ ARToolkitNFT_td.js:2
loadWasmModuleToWorker @ ARToolkitNFT_td.js:2
getNewWorker @ ARToolkitNFT_td.js:2
hA @ ARToolkitNFT_td.js:2
lA @ ARToolkitNFT_td.js:2
$func708 @ 001d49a2:0x2c631
$func1188 @ 001d49a2:0x62679
$func371 @ 001d49a2:0xdb4d
ARToolKitNFT$setupAR2 @ VM858:8
value @ ARToolkitNFT_td.js:2
value @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
G @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
A @ ARToolkitNFT_td.js:2
i @ ARToolkitNFT_td.js:2
Promise.then (asinc)
A @ ARToolkitNFT_td.js:2
i @ ARToolkitNFT_td.js:2
Promise.then (asinc)
A @ ARToolkitNFT_td.js:2
i @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
value @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
G @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
A @ ARToolkitNFT_td.js:2
i @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
(anonimo) @ ARToolkitNFT_td.js:2
value @ ARToolkitNFT_td.js:2
load_thread @ load_ES6_thread.js:52
load @ threejs_wasm_thread.js:99
start @ threejs_wasm_thread.js:184
(anonimo) @ ARToolkitNFT_ES6_threading_example.html:88
Promise.then (asinc)
(anonimo) @ ARToolkitNFT_ES6_threading_example.html:86
load (asinc)
(anonimo) @ ARToolkitNFT_ES6_threading_example.html:65
ARToolkitNFT_td.js:2 Uncaught Event {isTrusted: true, type: 'error', target: Worker, currentTarget: Worker, eventPhase: 2, …}

Probabaly a webpack issue. webapck worker-loader seems to not doing nothing, or maybe a missed something.

@kalwalt
Copy link
Member Author

kalwalt commented Sep 13, 2023

The dist lib ARToolkitNFT_td.js need to find the artoolkitNFT_ES6_wasm_td.js and artoolkitNFT_ES6_wasm_td.worker.js files. This is a bit cumbersome since webpack should provide these files, anyway i solved this issue placing these three files in a separate folder all toghether. So the example can load correctly load all the files and after that i was able to track the pinball marker.

@kalwalt kalwalt merged commit 16b6060 into dev Sep 24, 2023
3 checks passed
@kalwalt kalwalt mentioned this pull request Sep 24, 2023
@kalwalt kalwalt deleted the feature-threading branch January 5, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant