Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPU Feature Support #138

Closed
mattleibow opened this issue Aug 17, 2016 · 15 comments
Closed

Add GPU Feature Support #138

mattleibow opened this issue Aug 17, 2016 · 15 comments

Comments

@mattleibow
Copy link
Contributor

mattleibow commented Aug 17, 2016

This is going to be the root issue where we discuss how and what we put forward to get the GPU / hardware accelerated drawing in place. Our aim is to make sure everything that needs to be is here, but not adding too much more just because we can.

The idea behind SkiaSharp is to make sure that we wrap the C++ as nicely as we can, but not create a new engine. If we add lots of code, when Google makes a change, we will then have to go and update all that code. SkiaSharp is supposed to be thin. We can always create a set of extension APIs or packages that make everything awesome.

First things first, we are working in the gpu-support branch for the C#/managed section and the gpu-support branch for the native C++ Skia.

You can view the managed diff and the native diff.

If you think we need an API, just leave a comment and we can make sure that we add it. If you created another issue already, just add a link so we can have everything in one place. If your feature is too big for normal support, just create another issue and leave a comment. It doesn't matter what you do, we will make sure that everything gets organized for you!

@mattleibow
Copy link
Contributor Author

So far, we have these types:

  • GRContext
    • static GRContext Create(GRBackend)
    • static GRContext Create(GRBackend, IntPtr)
    • static GRContext Create(GRBackend, GRGlInterface)
  • GRGlInterface
    • static GRGlInterface CreateDefaultInterface()
    • static GRGlInterface CreateNativeInterface()
  • SKCanvas
    • static SKSurface Create(GRContext, GRBackendRenderTargetDesc, SKSurfaceProps)
    • static SKSurface Create(GRContext, GRBackendTextureDesc, SKSurfaceProps)
    • static SKSurface CreateAsRenderTarget(GRContext, GRBackendTextureDesc, SKSurfaceProps)
    • static SKSurface Create(GRContext, bool, SKImageInfo, int, SKSurfaceProps)
  • GRBackendRenderTargetDesc
  • GRBackendTextureDesc

And these enums:

  • SKSurfacePropsFlags
  • GRSurfaceOrigin
  • GRPixelConfig
  • GRBackend
  • GRBackendTextureDescFlags

@mattleibow
Copy link
Contributor Author

I just noticed that although Skia can have an OpenGL backend or a DirectX (through ANGLE) backend, it cannot have both. This is sort of a "problem" on Windows desktop as which is best?

There is a way to have "both" and that is to have two sets of dlls, one with OpenGL and the other DirectX. Then, as a developer, you can set either a MSBuild property (or something similar) and select the desired backend, without having to change the code.

We could also split the NuGet into per-platform packages, and just have two packages for Windows.

@kekekeks
Copy link
Contributor

@mattleibow Actually you can create GrContext with needed opengl interface using GrGLAssembleGLInterface by passing a pointer to glGetProcAddress from corresponding opengl implementation.
See https://github.com/AvaloniaUI/libperspesk/blob/master/src/gl.cpp#L200

@kekekeks
Copy link
Contributor

It may be worth to allow user to manually initialize that from C# code (by passing glGetProcAddress pointer)

@mattleibow
Copy link
Contributor Author

mattleibow commented Aug 21, 2016

@kekekeks Thanks! I did some work and added code so you could do this:

var openGLES = ObjCRuntime.Dlfcn.dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", 0);
var glInterface = GRGlInterface.AssembleGlesInterface((ctx, name) => {
    return ObjCRuntime.Dlfcn.dlsym(openGLES, name);
});

Which is similar to what GrGLCreateNativeInterface() does under the hood.

The value which is returned inside the delegate/callback is the pointer to the function that was requested using the name parameter. In this case, we do a lookup in the GL library.

@jazzay
Copy link

jazzay commented Aug 25, 2016

Hello. I have tried the latest Windows GL demo app with latest SkiaSharp 1.53.2-gpu2 nuget and vector drawing operations are all messed up. Simple operations like DrawCircle do not work when bound to a GL Backend. I also tried previous gpu1 nuget and it does not work either. The Shader based demos all work fine. Any eta on when this could be fixed?

@mattleibow
Copy link
Contributor Author

@jazzay I am not able to reproduce any issues. All the demos work on both Mac and Windows. Are you able to indicate which demo and send a screenshot?

@kekekeks
Copy link
Contributor

That might be related to particular OpenGL drivers. I'd recommend to use ANGLE on windows instead of relying on proper OpenGL support.

@jazzay
Copy link

jazzay commented Aug 25, 2016

Hey @kekekeks! I assume that is something I must configure on my machine? And then SkiaSharp will just pick up that driver configuration?

Update: I investigated ANGLE, but see no way to install/use it within the OS. This appears to be a application linked solution, which is not accessible from SkiaSharp. Correct me if i'm wrong @kekekeks

@jazzay
Copy link

jazzay commented Aug 26, 2016

Hey I installed the latest NVidia GTX 660 TI driver (my video card), ran GL Bench passing with flying colors. Then build/run exact copy of the source from here: https://github.com/mono/SkiaSharp/tree/gpu-support/samples/Skia.WindowsDesktop.GLDemo. This is what I see for first demo, note how there is no logo (vector path) visible:

image

Perlin noise demo runs fine, and fast indicating HW acceleration:

image

Fonts also work fine:

image

I doubt this is an issue w my driver/hw setup.

Also note that I did code up a custom drawing method with simple circle - filled/stroked combinations. The fills never showed up. I could get the Stroke to show up only if the StrokeWidth = 1. Greater than 1 and it disappeared. Seems like some issue with the fill/stroke code path on Open GL.

@mattleibow mattleibow modified the milestones: 1.53.2, 1.54.0, 1.54.1 Aug 30, 2016
@mattleibow
Copy link
Contributor Author

mattleibow commented Sep 2, 2016

This appears to be working for most cases, so I am merging this into master and see what happens :)

@DanWBR
Copy link

DanWBR commented Sep 3, 2016

@mattleibow , where can I find a sample showing how to enable gpu acceleration on Android? thanks.

@mattleibow
Copy link
Contributor Author

Check out this issue #148, it had info and a branch with code

@DanWBR
Copy link

DanWBR commented Sep 8, 2016

@mattleibow thanks a lot, got it working after commenting this line (Flush() not found): https://github.com/mono/SkiaSharp/blob/skiasharp-views/views/SkiaSharp.Views.Android/SKGLSurfaceViewRenderer.cs#L28

@mattleibow
Copy link
Contributor Author

@DanWBR that one is not yet released to 1.54.x. Once I get the Windows views done, I will update the SkiaSharp NuGet to v1.54.1 and see if I can get a beta out for the views.

Just a note: I reworked all the iOS views/layers (and I think they are better for it)

@ghost ghost locked as resolved and limited conversation to collaborators Aug 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants