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 093b875 to bcafa5c Compare December 1, 2025 23:33
@wenjieshen
Copy link
Collaborator Author

wenjieshen commented Dec 2, 2025

A framebuffer object (FBO) is similar to a drawable object, except a drawable object is a window-system-specific object, whereas a framebuffer object is a window-agnostic object that's defined in the OpenGL standard.

  • They are window-system independent, which makes porting code easier.
  • You can switch between them faster since there is no context switch as with pixel buffers. Because all commands are rendered by a single context, no additional serialization is required.
    1

When we render to an FBO, we are completely bypassed the macOS Window System until the final display.

Removing FBO is a macOS pessimization. The FBO must be restored for macOS to decouple the render thread from the WindowServer.

Footnotes

  1. https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_offscreen/opengl_offscreen.html

@hermet
Copy link
Member

hermet commented Dec 2, 2025

@wenjieshen Hello, Mac is not our primary target for OpenGL. It's deprecated. Rather windows or linux system is more practical test for us.

@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch 2 times, most recently from 3d21d53 to 9f4632d Compare December 2, 2025 18:56
@wenjieshen
Copy link
Collaborator Author

wenjieshen commented Dec 2, 2025

In the previous version, I made two mistakes. First, I used a non-strict method to determine whether the stencil and depth features were available, which likely caused many machines, including the reviewer's, to fall back to offscreen rendering. Second, I may have used incorrect FPS data files for my statistics. This time, I captured the screen to ensure accuracy.


The sample animation is running at a resolution of 3840 x 2160 with direct rendering, achieving a frame rate by $50$%.

Screenshot 2025-12-03 025551
Screenshot 2025-12-03 025303

It is an extremely rare edge case, so the result is exaggerated. In complex samples, like samurai, there have already been many blit operations. As a result, saving only one blit operation is not significant.

@wenjieshen wenjieshen marked this pull request as ready for review December 2, 2025 19:25
Copilot AI review requested due to automatic review settings December 2, 2025 19: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 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 9f4632d to bd6284e Compare December 2, 2025 19:35
Copilot AI review requested due to automatic review settings December 4, 2025 08:03
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from bd6284e to 63001ee Compare December 4, 2025 08:03
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 1 comment.


💡 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 63001ee to 0084897 Compare December 4, 2025 09:22
Copilot AI review requested due to automatic review settings December 4, 2025 13:48
@wenjieshen wenjieshen force-pushed the jay/exp/directly-draw-on-back-buffer branch from 0084897 to 2233f7c Compare December 4, 2025 13:48
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 1 comment.


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

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 2233f7c to b5fb343 Compare December 8, 2025 23:12
@hermet
Copy link
Member

hermet commented Dec 9, 2025

@SergeyLebedkin Hello, please confirm the performance beneficial on your side. Thanks.

@SergeyLebedkin SergeyLebedkin self-requested a review December 9, 2025 08:17
@SergeyLebedkin
Copy link
Member

Large animation:
main: 25.30
PR: 20.10

Lottie:
main: 13.30
PR: 11.50

As I can see we have performance degradation

@wenjieshen
Copy link
Collaborator Author

@SergeyLebedkin Thanks for reviewing. Could you please share your device and OS information with me? It would also be great if you could share the log as well.

@SergeyLebedkin
Copy link
Member

@SergeyLebedkin Thanks for reviewing. Could you please share your device and OS information with me? It would also be great if you could share the log as well.

      System Manufacturer: ASUSTeK COMPUTER INC.
             System Model: NUC15JNLU7X4
                     BIOS: JNARL579.0027.2025.0526.1812 (type: UEFI)
                Processor: Intel(R) Core(TM) Ultra 7 255HX (20 CPUs), ~2.4GHz

                   Memory: 32768MB RAM
      Available OS Memory: 32062MB RAM

           Card name: NVIDIA GeForce RTX 5060 Laptop GPU
        Manufacturer: NVIDIA
           Chip type: NVIDIA GeForce RTX 5060 Laptop GPU
            DAC type: Integrated RAMDAC
         Device Type: Full Device
      Display Memory: 26174 MB
    Dedicated Memory: 7899 MB
       Shared Memory: 18275 MB
        Current Mode: 1920 x 1080 (32 bit) (60Hz)

@SergeyLebedkin
Copy link
Member

macos/intel
Lottie, gl
main vs gl
image

@hermet
Copy link
Member

hermet commented Dec 9, 2025

macos/intel Lottie, gl main vs gl image

@SergeyLebedkin Could you please test on windows machine? Thanks.

@hermet
Copy link
Member

hermet commented Dec 18, 2025

@wenjieshen please rebase & update the thorvg.example

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