It seems the SkSL has a public API, and had GPU and CPU backends.
Although Google says it is likely to change a bit since it is under active development.
Since back in the days even good old Silverlight had such a feature, I think it would make sense to expose it in SkiaSharp.
If so, I would be happy to make a PR.
I don't think that this will be useful because you need to compile shaders alongside Skia itself. If it would be possible to compile shaders at runtime this would be a killer feature.
I _think_ I saw a demo where the shader was just a string... So maybe? I have been keeping an eye on that and I think a runtime compilation might actually be something. I'll have a closer look...
According to the reply I got from Google in Skia discuss, it now has an interpreter and JIT...
In the CanvasKit fiddle you just pass a string:
https://jsfiddle.skia.org/canvaskit/33ff9bed883cd5742b4770169da0b36fb0cbc18fd395ddd9563213e178362d30
But that one is running on the GPU, so not a good reference...
I will ask more questions in Skia discuss, but if you have to precompile shaders, it is indeed limited.
We could of course write a backend for SkSL that generates SIMD ILASM ;-)
Keep up the discussion there! Then I can see what needs to be done to make it work well in SkiaSharp
For those following along at home https://groups.google.com/forum/#!topic/skia-discuss/LNCQs-7b7rk
I think it was @kekekeks was asking about this in the past?
Y being able to compile shaders at runtime would allow us to introduce custom effects.
Our idea was to provide GLSL text and a pointer to software implementation func. Proper SkSL with JIT on the Skia side would be indeed way better.
My feeling from following the discussion in the skia mailing list, is that the CPU implementation is currently a bit behind the GPU one.
My customer's current server side renderer uses DirectX 11 WARP, a purely software implementation of DirectX 11, so it seems Skia is not yet at that level, but its catching up (in 2008, WARP could run Crysis on a Core i7!)
Nevertheless I think that most users will use the GPU for rendering with Skia, and then exposing SkSL might be a really nice feature?
It seems one just needs to expose the SkRuntimeShader class, with some small helper structs. To pass data, Span<byte> could be used. Of course a much higher level interface could be provided, using .NET marshalling to provide the values of the uniforms, like SharpDX does.
Having a look right now. going to get a very simple thing working and see what happens. I should be working on actual issues, but COVID-19, right?
That's the positive side of the Corona crisis. Some people have more time to spend on things they love.
Good news folks! Things seem to be working!!! At least on Windows x64. Just tweaking the bindings and adding a few tests and then I'll push a branch for folks to play around with. Seems all we need is a string and we are off to the races!
That is great news! So you couldn't resist, hehe, I know the feeling ;-)
I guess in the longer term we will need some methods to transfer/marshal uniform data and SkShader instances to the runtime shader?
Hehe, no I couldn't. We might be able to do something with a "dictionary" type of thing for the inputs. There is some iterable object.
The tests have a possible starting point: https://github.com/google/skia/blob/5f6b41e6d8aa1ead3cbdb94a483bc8bea32e0fb3/tests/SkRuntimeEffectTest.cpp#L74-L90
I have the code here for now (https://github.com/mono/SkiaSharp/pull/1221).
The GPU bits seem to work - 1 simple test. The CPU needs some compiler options but I think the GPU is fine for basic testing and experimentation. I need to do actual work now...
Overall, this looks both simple and powerful. Let me know what you think. Looks cool so far.
Moved the code and changes to a new PR which is much better and I hope to get a working GPU package out: #1321
I have been doing some work on this... Let me know what you think: https://github.com/mono/SkiaSharp/issues/1319#issuecomment-640529824
Most helpful comment
Good news folks! Things seem to be working!!! At least on Windows x64. Just tweaking the bindings and adding a few tests and then I'll push a branch for folks to play around with. Seems all we need is a string and we are off to the races!