mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.54k stars 542 forks source link

[FEATURE] Support Direct3D #2817

Open Kation opened 7 months ago

Kation commented 7 months ago

Is your feature request related to a problem?

  1. Some GPU or its driver doesn't support Vulkan. For example, Intel Xe Graphics currently driver will return null ptr when get procedure address for some name. Then GRContext.CreateVulkan will return null.
  2. Some environment only support OpenGL 1.1. For example, Virtual Machine without GPU. Or remote control without RDP with Intel Xe Graphics. Then GRContext.CreateGl will return null.

Without Vulkan and OpenGL, we can only use CPU to render images.

Describe the solution you would like

Add D3D support with Windows os.

Describe alternatives you have considered

Add define SK_Direct3D when compile native skia so that I can use it with pinvoke and reflection.

Additional context

No response

Code of Conduct

Kation commented 7 months ago

I have tried to use SharpDX to create backend. But I found there is no api define in libSkiaSharp because compile without define SK_Direct3D.

996666925 commented 7 months ago

👍👍👍

Shunfeng88 commented 7 months ago

The code demonstrates a deep understanding of the domain, incorporating relevant design patterns and domain-specific optimizations that reflect your expertise and intimate familiarity with the subject matter

Kation commented 7 months ago

@mgood7123

Skia have define D3D functions: https://github.com/mono/skia/blob/a0008792c861228872a0a21f5f3422c4c8824720/include/gpu/GrDirectContext.h#L105-L112

But our SkiaSharp does not add those define: https://github.com/mono/skia/blob/a0008792c861228872a0a21f5f3422c4c8824720/include/c/gr_context.h#L28-L33

gmurray81 commented 6 months ago

Just as a warning here. Over the years I've run into various areas where Direct2D performs in degraded ways compared to Skia software or Skia OpenGL/Vulkan backends. Mostly this has to do with conversion of Path geometry into tessellated meshes. If you have paths with high frequency changes in direction, this seems to be a terrible performance case for Direct2D.

Now, maybe the Direct3D backend for skia sidesteps this stuff if it is using lower level primitives and skipping all the Direct2D stuff. But I'd keep an eye out for degraded path rendering scenarios if the backend touches any of the high level stuff.