CEF performance improvements - #4634
Conversation
|
Good job! |
|
Would it be possible to add the codecs to this CEF version? I’m thinking of the fact that, for example, YouTube live streams currently don’t work for this reason. These codec packs are not included in minimal CEF build. (H.264 & AAC) |
This is unlikely due to licensing, we can't distribute those codecs. |
|
Good job, I can't wait for this to be implemented in new versions. |
Dirty rect 'optimizations' were actually lowering performance, and causing edge case issues with device restoration and partial updates - removed this functionality. Also improved device reset/restore handling (force repaint)
You need to have some patience. This goes in when the time is right (and merge conflicts are resolved). That said, I, and others also work on projects with large usages of CEF without crashes. Thus, there might be something in your setup that could be contributing to it. This PR is unlikely to resolve it, instead identify what part of your implementation leads to the crash and report accordingly. We are an open source project. Community involvement and reporting is at the core of such projects. |
|
Good job! ((btw I watched GTA VI trailer in 1440p lmao) |
@dsFejerA Did you use https://frameratetest.com/mouse-polling-rate-test/ for testing? |
Yup. I set my mouse first to 125HZ https://frameratetest.com/mouse-polling-rate-test/ showed me 75+hz |
Potential fix for regressions in #4634
…#4876) #### Summary Relax the non-rendertarget branch in `CPixelsManager::GetTexturePixels` and `CPixelsManager::SetTexturePixels` from `Desc.Usage == 0` to `(Desc.Usage & D3DUSAGE_RENDERTARGET) == 0`, so that `D3DUSAGE_DYNAMIC` textures are routed through the existing lockable-surface path instead of silently returning `false`. #### Motivation PR #4634 (CEF performance improvements, commit ddb9249) switched browser textures in `CWebBrowserItem::CreateUnderlyingData` from `D3DPOOL_MANAGED` (Usage == 0) to `D3DPOOL_DEFAULT + D3DUSAGE_DYNAMIC` in order to remove the duplicate system-RAM copy. As a side effect, `CPixelsManager` no longer recognised the browser texture's usage flag, so `dxGetTexturePixels(browser, ...)` and `dxSetTexturePixels(browser, ...)` started returning `false`. This change is scoped narrowly: textures created with `Usage == 0` (e.g. `dxCreateTexture` from file/raw pixels, shader/RwTexture wrappers) and `D3DUSAGE_RENDERTARGET` (e.g. `dxCreateRenderTarget`, `dxCreateScreenSource`) continue to take exactly the same branches they did before. Only previously-unhandled non-rendertarget usages (notably `D3DUSAGE_DYNAMIC` browsers) now reach the lock path that was always intended to handle them. #### Test plan **Before the fix:** all three image formats (jpg, png, plain) reported `false` / `len=nil` from `dxGetTexturePixels` against an actively-rendering browser **After the fix:** all three formats return non-empty data with the expected dimensions. Existing render-target and managed-texture callers (`dxCreateRenderTarget`, `dxCreateTexture` from file) were also smoke-tested via existing scripts to confirm no regression in those code paths. #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
`setBrowserRenderingPaused(false)` did not properly resume CEF painting in 1.7. After #4634 browsers use external begin-frame scheduling, so `WasHidden(false)` alone does not produce `OnPaint`. Interactive CSS (hover) stayed on the last cached texture even though JavaScript still ran. On resume the host now calls `WasResized()`, `Invalidate(PET_VIEW)` and `SendExternalBeginFrame()` so the compositor uploads a fresh frame.
Summary
This update significantly improves the performance and memory efficiency of MTA's CEF browser implementation.
Non-blocking render thread synchronization
The most impactful change is replacing the old blocking synchronization model, where CEF's render thread would wait up to 250ms for the main thread, with External Begin Frame scheduling that allows MTA to request frames on-demand in sync with the game loop.
Memory optimizations
Memory consumption is reduced by switching browser textures from D3DPOOL_MANAGED to D3DPOOL_DEFAULT with D3DUSAGE_DYNAMIC, eliminating the duplicate system RAM copy that managed textures require.
Resource allocation improvements
Lazy browser creation defers CEF subprocess spawning until the first URL is actually loaded, avoiding resource allocation for unused browser instances.
Enable GPU compositing
GPU compositing and hardware video decoding are now properly enabled when the GPU setting is on, which drastically improves YouTube and video playback performance.
This also adds a new setting "Enable video acceleration" to the web browser settings menu.
!! IMPORTANT NOTE !!
Previously GPU compositing was unconditionally disabled due to previous stability concerns in release builds - this must be thoroughly tested in both nightly and official release streams
Mouse input/polling throttle
Additionally, mouse input throttling limits move events from being completely unbounded, to around 60 per second, reducing unnecessary CEF repaints while maintaining smooth cursor tracking.
Together, these changes reduce CPU overhead, lower memory footprint, improve video playback, and provide more stable frame rates.
Additionally, I've provided a more detailed summary of each change below.
The "changes made" sections provide a detailed/technical overview of the notable changes.
The "benefits" sections provide a higher level summary of what has changed, and why.
External Begin Frame Scheduling
Changes made:
CWebView.h:
CWebView.cpp:
CWebCore.cpp:
Benefits:
Use D3DPOOL_DEFAULT with D3DUSAGE_DYNAMIC
Changes made to CRenderItem.WebBrowser.cpp:
CreateUnderlyingData():
OnLostDevice():
OnResetDevice():
Changes made to CWebView.cpp:
Benefits:
Lazy Browser Creation
Changes made:
CWebView.h:
CWebView.cpp:
Benefits:
Video Decode Acceleration & GPU Compositing
Changes made:
CClientVariables.cpp:
CSettings.h:
CSettings.cpp:
CWebApp.cpp:
Benefits:
Mouse Input Throttling
Changes made:
CWebView.h:
CWebView.cpp:
Benefits:
Motivation
After some recent discussions surrounding main menu revamp / GUI changes in the development discord (see #main-menu-revamp), and testing CEF myself, I noticed the performance in certain areas was quite poor (e.g YouTube videos choppy, inconsistent framerates, etc).
Many servers already rely on CEF for the majority of their UI, so we must ensure it runs as smooth as possible, especially if we're even going to consider using CEF ourselves for main menu UI (which some users do seem interested in).
Test plan
Here's a small CEF test resource which implements a tiny CEGUI-based browser window, with the ability to go back/forward, refresh & enter URLs directly into the 'address bar': cef.zip
Just load the resource, and you'll see instructions in chat. This also tests the lazy loading functionality.
Compared to builds without these improvements, I'm seeing a 10-20% FPS improvement in some cases, frame times are more consistent, and video playback is much smoother.
There are some really good tests on this site which actually cover some specific test cases based on the changes made above: https://frameratetest.com/
For example https://frameratetest.com/mouse-polling-rate-test/ can be used to ensure the mouse polling changes are properly enforcing the 60hz limit.
There's various sites like this out there anyway - just have a browse around and compare to builds without these changes and you're sure to see improvements.
Well, if you're still not convinced, check out the video examples below. The first is from MTA's official release (latest) - and the second is from my custom build with these changes (both fps_limit 999 on server + client). Even after multiple compressions of the video files you can still clearly see the difference - it's even easier to notice when you test the changes yourself!
MTA official release
https://www.youtube.com/watch?v=mGIOUSHIFGQ
Custom build
https://www.youtube.com/watch?v=hZljFFxa2H0
Checklist