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

feat(perf): 🎸 enable thorvg multi threaded rendering #159

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

theashraf
Copy link
Member

@theashraf theashraf commented May 28, 2024

Fixes #141

Copy link

changeset-bot bot commented May 28, 2024

⚠️ No Changeset found

Latest commit: c3dc9dc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@theashraf
Copy link
Member Author

@hermet after enabling thorvg multi threaded rendering, i'm not getting the frame buffer updated anymore and getting a blank canvas.

in thorvg.rs module, i'm passing the threads count to tvg_engine_init, am i missing something ?

impl Canvas {
    pub fn new(engine_method: TvgEngine, threads: u32) -> Self {
        let engine = match engine_method {
            TvgEngine::TvgEngineSw => Tvg_Engine_TVG_ENGINE_SW,
            TvgEngine::TvgEngineGl => Tvg_Engine_TVG_ENGINE_GL,
        };

        let init_result = unsafe { tvg_engine_init(engine, threads) };

        if init_result != Tvg_Result_TVG_RESULT_SUCCESS {
            panic!("Failed to initialize ThorVG engine");
        }

        Canvas {
            raw_canvas: unsafe { tvg_swcanvas_create() },
            engine_method: engine,
        }
    }
  ....

@hermet
Copy link
Member

hermet commented May 28, 2024

@theashraf What value did you use for the thread number, and which platform did you test it on? Please note that SharedArrayBuffer, required in web, would have a security issue now, the thorvg intrinsic thread feature might not be proper for the web (let me double check it) but other platforms such as android and iOS should be ok.

+ @tinyjin

@theashraf
Copy link
Member Author

@hermet, I've tested it on Rust on my macOS, not on the web. I set the number of threads to 1, as shown in this rust example.

I'm not trying to test it on the web for now. I want to ship this for platforms with native threading capability, like iOS and Android.

@tinyjin
Copy link
Member

tinyjin commented Jun 3, 2024

@theashraf Hello, Ashraf. I've only tested the native threading in web. It required enabling a few options

  • -pthread
  • -sUSE_PTHREADS=1
  • -sPTHREAD_POOL_SIZE

Of course, they're part of Emscripten flags, I'm not sure it'd help even in Android, iOS and Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable API for ThorVG Threading Control in dotLottie Player
3 participants