Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@wenjieshen
Copy link
Collaborator

@wenjieshen wenjieshen commented Nov 22, 2025

Allows the engine to render directly to the screen's back buffer, bypassing intermediate framebuffers when possible.

This change introduces a new mDirectTarget flag to indicate whether the rendering target is the back buffer. When rendering directly, it uses a compose task instead of a blit task and avoids unnecessary framebuffer operations.

This improves rendering performance and reduces memory consumption in scenarios where direct rendering is feasible.

The WASM binding requires modification to enable this feature.

        attrs.depth = true;
        attrs.stencil = true;
        attrs.antialias = true;

Related issues: #3951

Evaluation

Summary

  • No regressions in any example.
  • Large animation: +0.3% overall FPS, +1.2% steady-state FPS.
  • Lottie animations: +3.4% overall FPS, +4.6% steady-state FPS (with higher jitter).
  • Simple animation (normal resolution): +3.0% overall FPS, steady-state is the same.
  • Simple animation (4K): +44% overall FPS, +36% steady-state FPS (with slightly lower jitter).
  • WebGL multi-animation test: After a 1-minute run, both builds stabilize at 60 FPS with similar memory ranges. No meaningful difference observed.

Overall, the feature branch is performance-safe and shows significant improvements at high resolutions, especially in 4K scenarios.


1. Large Animation

image

Overall FPS

  • Origin: 25.66
  • Feature: 25.74
  • Change: +0.31%

Steady-State FPS (last 20 intervals)

  • Origin: 25.49
  • Feature: 25.79
  • Change: +1.18%

Jitter (stddev/mean)

  • Origin: 1.71%
  • Feature: 2.18%
  • Relative change: +27%

Conclusion: Tiny gain, effectively identical to origin. No regression.


2. Lottie Animation

image

Overall FPS

  • Origin: 34.28
  • Feature: 35.45
  • Change: +3.41%

Steady-State FPS

  • Origin: 34.75
  • Feature: 36.36
  • Change: +4.62%

Jitter

  • Origin: 3.21%
  • Feature: 5.51%
  • Relative change: +72%

Conclusion: Clear 3–5% FPS gain with higher variability. Still stable.


3. Small Animation (Normal Resolution)

image

Overall FPS

  • Origin: 187.20
  • Feature: 192.72
  • Change: +2.95%

Steady-State FPS

  • Origin: 239.55
  • Feature: 239.33
  • Change: −0.09%

Jitter

  • Origin: 0.10%
  • Feature: 0.14%
  • Relative change: +43%

Conclusion: +3% overall from faster warm-up; steady-state identical.


4. Small Animation (4K Resolution)

Screenshot 2025-11-23 011229

Overall FPS

  • Origin: 120.01
  • Feature: 173.07
  • Change: +44.21%

Steady-State FPS

  • Origin: 119.04
  • Feature: 161.46
  • Change: +35.64%

Jitter

  • Origin: 0.85%
  • Feature: 0.67%
  • Change: −21%

Conclusion: Major performance uplift at 4K — both average and steady-state FPS improve significantly.


5. Resolution Scaling (Normal → 4K)

Origin Branch

  • Overall FPS: −35.89%
  • Steady-State FPS: −50.31%

Feature Branch

  • Overall FPS: −10.20%
  • Steady-State FPS: −32.54%

Conclusion: The feature branch is far more resolution-robust.
Origin loses half its steady-state FPS, while the feature retains much more performance.


6. WebGL Multi-Animation Test (Qualitative)

Screenshot 2025-11-22 at 8 48 52 PM

Tested using the WebGL/DevTools HUD for 1 minute.

Feature Build

  • FPS: 60 (range 29–60)
  • Memory counter: ~20 MB (range 19–25 MB)

Origin Build

  • FPS: 60 (range 29–60)
  • Memory counter: ~23 MB (range 19–25 MB)

Conclusion:

  • FPS stabilizes at 60 on both builds.
  • The HUD memory number fluctuates and stays in the same range for both builds.
  • Treat this as no meaningful difference and, importantly, no regression.

Notes

  • I also make sure that direct rendering is enabled in WebGL with a tool, but the performance remains exactly the same.

image image


@github-actions github-actions bot added example Sample Code binding CAPI / Wasm gl OpenGL/WebGL render backend labels Nov 22, 2025
@wenjieshen wenjieshen self-assigned this Nov 22, 2025
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from 64c4503 to bb77a02 Compare November 22, 2025 14:22
@wenjieshen wenjieshen linked an issue Nov 22, 2025 that may be closed by this pull request
@wenjieshen wenjieshen marked this pull request as ready for review November 22, 2025 14:33
Copilot AI review requested due to automatic review settings November 22, 2025 14:33
@wenjieshen wenjieshen requested a review from hermet as a code owner November 22, 2025 14:33
@wenjieshen wenjieshen marked this pull request as draft November 22, 2025 14:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables direct rendering to the back buffer in the OpenGL engine, bypassing intermediate framebuffers when the target is the default framebuffer (FBO ID 0). The implementation includes capability checks for stencil/depth buffers and MSAA support, falling back to offscreen rendering when requirements aren't met.

Key Changes:

  • Adds mDirectTarget flag to track whether rendering directly to the back buffer
  • Implements validation checks for framebuffer capabilities (stencil, depth, MSAA)
  • Switches from blit task to compose task when direct rendering is active
  • Updates WebAssembly and SDL example configurations to enable required depth, stencil, and MSAA attributes

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/renderer/gl_engine/tvgGlRenderer.h Adds mDirectTarget flag to track direct rendering state
src/renderer/gl_engine/tvgGlRenderer.cpp Implements direct rendering logic with capability validation and task selection
src/renderer/gl_engine/tvgGlRenderTask.cpp Conditionally calls onResolve() only for internal framebuffers
src/renderer/gl_engine/tvgGlRenderTarget.h Updates initialization signature and validity tracking to support external framebuffers
src/renderer/gl_engine/tvgGlRenderTarget.cpp Implements external framebuffer handling and improved cleanup logic
src/renderer/gl_engine/tvgGlCommon.h Defines minimum MSAA samples constant
src/renderer/gl_engine/tvgGl.h Uncomments typedef for framebuffer attachment parameter query function
src/renderer/gl_engine/tvgGl.cpp Enables GL function for querying framebuffer attachment parameters
src/bindings/wasm/tvgWasmLottieAnimation.cpp Enables depth, stencil, and antialiasing in WebGL context attributes
examples/MultiCanvas.cpp Configures SDL GL attributes for stencil and MSAA support
examples/Example.h Configures SDL GL attributes for stencil and MSAA support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from bb77a02 to 9a5cfb1 Compare November 22, 2025 14:37
@github-actions github-actions bot removed the binding CAPI / Wasm label Nov 22, 2025
@wenjieshen wenjieshen removed the request for review from tinyjin November 22, 2025 14:41
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch 2 times, most recently from 6069564 to 7b2c629 Compare November 22, 2025 14:54
@wenjieshen wenjieshen marked this pull request as ready for review November 22, 2025 14:58
Copilot AI review requested due to automatic review settings November 22, 2025 14:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from 7b2c629 to a8d392f Compare November 22, 2025 15:02
@hermet hermet added feature New feature additions optimization Enhance performance / Reduce memory usage or binary size labels Nov 24, 2025
Copilot AI review requested due to automatic review settings November 25, 2025 03:25
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from a8d392f to 093b875 Compare November 25, 2025 03:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from b5fb343 to b0b022e Compare December 26, 2025 03:13
@wenjieshen wenjieshen marked this pull request as ready for review December 26, 2025 07:34
Copilot AI review requested due to automatic review settings December 26, 2025 07:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen
Copy link
Collaborator Author

@wenjieshen please rebase & update the thorvg.example

Thank you for the reminder. I've rebased this branch and tested it on Windows.

@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from b0b022e to c7b380a Compare December 26, 2025 10:00
@hermet
Copy link
Member

hermet commented Dec 26, 2025

@wenjieshen Hello, I tested on Local Linux machine but I coudln't find any enhancement at fps in both Lottie & Simple animation (4K) with applying this. Any Opinion?

@wenjieshen
Copy link
Collaborator Author

@wenjieshen Hello, I tested on Local Linux machine but I coudln't find any enhancement at fps in both Lottie & Simple animation (4K) with applying this. Any Opinion?

I appreciate your help. Could you please enable the log build option and confirm whether this feature has been enabled? Thank you.

@hermet
Copy link
Member

hermet commented Dec 28, 2025

@wenjieshen Hello, I tested on Local Linux machine but I coudln't find any enhancement at fps in both Lottie & Simple animation (4K) with applying this. Any Opinion?

I appreciate your help. Could you please enable the log build option and confirm whether this feature has been enabled? Thank you.

@wenjieshen it seems working.

 L] GL_ENGINE (../src/renderer/gl_engine/tvgGl.cpp 821): OpenGL/ES version = v4.6
[E] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 79): Maybe missing MakeCurrent() Call?
[L] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 956): Default framebuffer stencil/depth size: 8/24
[L] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 956): Default framebuffer stencil/depth size: 8/24

@wenjieshen
Copy link
Collaborator Author

wenjieshen commented Dec 28, 2025

@wenjieshen Hello, I tested on Local Linux machine but I coudln't find any enhancement at fps in both Lottie & Simple animation (4K) with applying this. Any Opinion?

I appreciate your help. Could you please enable the log build option and confirm whether this feature has been enabled? Thank you.

@wenjieshen it seems working.

 L] GL_ENGINE (../src/renderer/gl_engine/tvgGl.cpp 821): OpenGL/ES version = v4.6
[E] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 79): Maybe missing MakeCurrent() Call?
[L] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 956): Default framebuffer stencil/depth size: 8/24
[L] GL_ENGINE (../src/renderer/gl_engine/tvgGlRenderer.cpp 956): Default framebuffer stencil/depth size: 8/24

Could you please capture an apitrace for this and attach it on Linux? That will let us see exactly what GL calls are happening on your machine.

Install apitrace:

  • Ubuntu/Debian: sudo apt update && sudo apt install apitrace
  • Fedora: sudo dnf install apitrace
  • Arch: sudo pacman -S apitrace

Capture a short trace:
apitrace trace --api gl -o app.trace ./Animation gl
I will purchase a USB flash drive to install Linux as soon as possible.
Thanks!

@hermet
Copy link
Member

hermet commented Dec 29, 2025

macos/intel Lottie, gl main vs gl image

@wenjieshen jfyi, @SergeyLebedkin's test also shows no or lower performance, same as mine.

@hermet
Copy link
Member

hermet commented Dec 29, 2025

@wenjieshen + Tested Animation on Windows machine (Ryzen 7 5800X / RTX4700). No enhancement.

@hermet
Copy link
Member

hermet commented Dec 29, 2025

@wenjieshen Plz check it -> test.zip

@wenjieshen
Copy link
Collaborator Author

@wenjieshen jfyi, @SergeyLebedkin's test also shows no or lower performance, same as mine.

Yes, I believe direct rendering is enabled on your device. However, I suspect that the default framebuffer path on macOS/Linux may introduce additional overhead or stalls, which could make this pipeline appear slower. To investigate further, I would capture the time spent in the pipeline. That should help us tell whether enabling this introduces extra system overhead that cancels out the time we saved, or whether blitting is truly negligible on these systems.

@hermet
Copy link
Member

hermet commented Dec 29, 2025

@SergeyLebedkin Could you please confirm on your windows machine? (both Animation/Lottie) about performance diff?

@hermet hermet force-pushed the main branch 4 times, most recently from 882f621 to ee0ce46 Compare January 7, 2026 04:39
Copilot AI review requested due to automatic review settings January 8, 2026 12:01
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from c7b380a to 3dfe221 Compare January 8, 2026 12:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen wenjieshen marked this pull request as draft January 8, 2026 12:03
Allows the engine to render directly to the screen's back buffer, bypassing intermediate framebuffers when possible.

This change introduces a new `mDirectTarget` flag to indicate whether the rendering target is the back buffer.  When rendering directly, it uses a compose task instead of a blit task, and avoids unnecessary framebuffer operations.

This improves rendering performance and reduces memory consumption in scenarios where direct rendering is feasible.

Related issues: #3951
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from 3dfe221 to abbd001 Compare January 8, 2026 12:25
@wenjieshen wenjieshen marked this pull request as ready for review January 8, 2026 12:26
Copilot AI review requested due to automatic review settings January 8, 2026 12:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Sample Code feature New feature additions gl OpenGL/WebGL render backend optimization Enhance performance / Reduce memory usage or binary size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants