CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

DirectX rendering

Open alphamax opened this issue 9 years ago • 43 comments

Hello,

It is not a real Issue but a way to propose modifications. I have made changes on CefSharp in a multiple way :

  • On windows OSR, make a Direct X rendering instead of Bitmap rendering
    • Allow region partial rendering
    • Merge combobox inside rendering (and manage rotation)
  • On windows OSR, take touch natively
    • with this PR : https://bitbucket.org/chromiumembedded/cef/pull-requests/104/touch-processing-for-osr-different-api/diff
  • On windows OSR, enhanced rendering
    • with this PR : https://bitbucket.org/chromiumembedded/cef/pull-requests/96/osr-fix-gpu-cpu-readback-performance/diff

I think the two last points are now temporary work and Cef55 binaries are available on this repository : https://github.com/intuilab/CefSharp/tree/55-Touch-DirectX in Nuget folders. I want to know how to propose the first point. Do you prefer a new "Cef.WPF.DirectX" project and people can chose it ? do you prefer it in the already existing Cef.WPF project ? Another question, do you want an adaptative rendering system (if DirectX is to lame, switch on bitmap rendering) ?

Thanks for you ideas !

alphamax avatar Aug 11 '17 10:08 alphamax

This sounds like a great improvement.

Only my opinion but I would add it to the current wpf project, as CEFSharp doesn't have different projects for different technologies and default to bitmap rendering. Then you could have a enum that allows you to select directx.

GrabzIt avatar Aug 11 '17 12:08 GrabzIt

Hello guys! I'm using CefSharp in my project (big thanks for your work, it's great project!) for playing video from YouTube, but perfomance is so poor. I'm beginner in WPF and my question: is this trouble by bitmap rendering? Thank you for answer.

stanislav-suslov avatar Aug 12 '17 20:08 stanislav-suslov

@alphamax, does this behave properly when using DPI scaling?

bjarteskogoy avatar Sep 28 '17 07:09 bjarteskogoy

@alphamax @GrabzIt Hello, These changes sound awesome! Do you have any plans to create a PR and merge this?

Ratcha9 avatar Oct 18 '17 13:10 Ratcha9

@bjarteskogoy I have deactivated the "DPI" problem, i mean, in my company we do not need defferent rendering in case of DPI change. @Ratcha9 I will propose this PR when i have "free" time. I'll do my best...

alphamax avatar Oct 18 '17 14:10 alphamax

@alphamax Thank you. I would like to test the improvements. Could you provide some nuget package or something?

Ratcha9 avatar Oct 18 '17 14:10 Ratcha9

I have an ALTERNATE repo located here : https://github.com/intuilab/CefSharp/tree/55-Touch-DirectX You can download the "final" version of my dev before integrating it in my company solution.

Hope it helps you.

alphamax avatar Oct 18 '17 14:10 alphamax

I'm using CEFSharp for showing webGL inside my WPF project. For performance reason I can use only WinForms version but I have many problems with controls over browser and must use 2 windows. I've tried this alternative repo with DirectX rendering. Maybe I making something wrong or don't understand idea but with this repo I see the same performance as for WPF version. I as understand cef must render to texture in video memory and D3DImage just show it without memory copy but I see the same performance and CPU load as WPF.

mortalV avatar Oct 24 '17 14:10 mortalV

@alphamax Thanks for an interesting contribution. Would you care to outline some of the major improvements in the DirectX version? (like, 3-5 bulletpoints) Just so we know what was the main reason for you doing it; I'm sure there were good reasons but let's just be explicit here.

Especially since people seems to have given it a try and not really understood the main point of it, it could make sense.

perlun avatar Dec 02 '17 19:12 perlun

On windows OSR, enhanced rendering with this PR : https://bitbucket.org/chromiumembedded/cef/pull-requests/96/osr-fix-gpu-cpu-readback-performance/diff

The CEF issue was merged a little while ago and is available in the 63.0.0-pre01 (and all future versions).

With the changes I just committed as part of #2237 it's now possible to access the raw buffer exposed by the CefRenderHandler::OnPaint call.

I have an ALTERNATE repo located here : https://github.com/intuilab/CefSharp/tree/55-Touch-DirectX

With the new changes anyone should be able to subclass ChromiumWebBrowser and implement their own rendering method, or their own IBitmapFactory and add support for DirectX. An unnecessary memory copy can be eliminated. I'm not really expecting that you'll see a huge improvement in performance if you do implement DirectX as the memory copies are likely CPU bound.

When CEF adds support for a shared texture/surface then it's likely performance can be improved, the upstream issue is https://bitbucket.org/chromiumembedded/cef/issues/1006/cef3-support-rendering-to-a-hardware-gl

amaitland avatar Jan 18 '18 01:01 amaitland

@perlun , sorry for my late response :) We are using Cef/CefSharp as a html widget in our product. In some cases, we may have many web browsers and we could also have 4k web browsers. Those web browsers may display kind of 3D animations (100% time refreshing). We have experienced that writable bitmap copy are fairly slowing down the rendering process on a big resolution. On the other hand, we have tried to optimize it and we have found that a DirectX texture can receive frames and can "give it to WPF". Using this process and helped with the CEF pull request #96, we reach 60fps rendering on recent computers. Don't hesitate to reach me it you have further questions :)

@amaitland This is a great news, this will improve the rendering process and i think it will be easier to inject data in textures with this changes. I need to update our code and propose a fully packaged pull request now.

alphamax avatar Jan 27 '18 08:01 alphamax

@perlun do i try to propose a pull request ?

alphamax avatar Mar 07 '18 08:03 alphamax

Anyone interested ? :)

alphamax avatar Apr 03 '18 08:04 alphamax

Yes

bjarteskogoy avatar Apr 03 '18 08:04 bjarteskogoy

Yes

GrabzIt avatar Apr 03 '18 08:04 GrabzIt

There is a new CEF PR that adds actual directx support at https://bitbucket.org/chromiumembedded/cef/pull-requests/158/support-external-textures-in-osr-mode/diff

If/when that is merged we can look at adding support to CefSharp main repository, as no extra libs should be required, just expose a couple of extra methods.

Short term if you are committed to support and maintenance then we can create a CefSharp.Wpf.DirectX repository within the overarching CefSharp project here on GitHib. I think the added dependencies and the specialized knowledge required make it ideal to host as a subproject and be published as a separate Nuget package that depends on the current set of Nuget packages.

amaitland avatar Apr 03 '18 21:04 amaitland

Sounds like a good plan. Do you think the new nuget package also add be able to add directx to offscreen?

GrabzIt avatar Apr 03 '18 22:04 GrabzIt

Do you think the new nuget package also add be able to add directx to offscreen?

@GrabzIt Not sure how the two are related? With the OffScreen package, you can render the image provided any way you like. What scenario are you thinking of? The changes I've made so far in https://github.com/cefsharp/CefSharp/issues/2237 will allow you access to the raw IntPtr, so you can effectively do whatever you like with the rendered bitmap.

There is a new CEF PR that adds actual directx support at https://bitbucket.org/chromiumembedded/cef/pull-requests/158/support-external-textures-in-osr-mode/diff

This PR will provide the ability to render directly to a shared texture/surface. Exposing that in the OffScreen version will be trivial.

https://github.com/intuilab/CefSharp/tree/55-Touch-DirectX

My comment above relates this branch, where the bitmap is coped into memory, then copied into a texture/surface. I haven't done any performance analysis, I'm somewhat skeptical that it will actually yield amazing performance improvements, it's still limited by the same OSR rendering implementation that CEF provides currently. WPF already renders using hardware acceleration where possible. We are bound by memory copy functions, some improvements can be made on that front, e.g. only copy the dirty rect changes into the backbuffer.

I've also seen one report that WPF doesn't render as efficiently as it could, see #2275 for details.

amaitland avatar Apr 04 '18 00:04 amaitland

Yesterday i had a look on the separated rendering system. It is a great.

I have created a DirectXBitmapRenderHandler & tested it. Seems to work great on my side. To be 100% sure about perf gain, you must set WindowlessFrameRate to 60. In this case i was able to gain 5 fps to a threejs demo on my computer.

Once again, It is a great improvement and the PR 158 is very interesting !

alphamax avatar Apr 04 '18 10:04 alphamax

Hi, @alphamax I've tried to downloads and compile the brach https://github.com/intuilab/CefSharp/tree/55-Touch-DirectX, but compilation of CefSharp.Core fails with the following message:

found incorrect match for 'RuntimeLibrary': value 'MTd_StaticDebug' does not match 'MDd_DynamicDebug' in AssemblyInfo.obj CefSharp.Core in ...\libcef_dll_wrapper. lib

Any suggestions? Thanks in advance

cristiancarli avatar May 09 '18 11:05 cristiancarli