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

[BUG] SKRuntimeEffect doesn't work on Bitmap Canvas #1822

Closed
substanc3-dev opened this issue Oct 4, 2021 · 12 comments · Fixed by #2547
Closed

[BUG] SKRuntimeEffect doesn't work on Bitmap Canvas #1822

substanc3-dev opened this issue Oct 4, 2021 · 12 comments · Fixed by #2547

Comments

@substanc3-dev
Copy link

Description

When attempting to use SKSL effects on bitmap canvases, there is a native exception raised.

Code

var bitmap = new SKBitmap(100, 100, false);
using var canvas = new SKCanvas(bitmap);

var src = @"
half4 main(float2 fragCoord) {
  return half4(0.5, 0.5, 0.5, 1);
}";

using var effect = SKRuntimeEffect.Create(src, out var error);

using (SKPaint bgPaint = new SKPaint { IsAntialias = true, Shader = effect.ToShader(false) })
    canvas.DrawRoundRect(0, 0, 100, 100, 15, 15, bgPaint); // This raises an exception

Expected Behavior

SKSL runtime effect is successfully used on drawing operation.

Actual Behavior

An exception occurs on attempting a draw operation:
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in SkiaSharp.dll
External component has thrown an exception.

Basic Information

  • Version with issue: 2.88.0-preview.145
  • Last known good version: None that I'm aware of
  • IDE: Visual Studio
  • Platform Target Frameworks:
    • Windows 10 (21H1 19043.1237) running .NET 6.0.0-rc.1.21451.13
@AnarchyMob
Copy link

AnarchyMob commented Oct 7, 2021

SkVM is not integrated (for official build) into Skia 88th milestone, support starts at 90th milestone.

@mgood7123
Copy link
Contributor

specifically the issue is the SK_ENABLE_SKSL_INTERPRETER is undefined when skia is being compiled

std::unique_ptr<ByteCode> Compiler::toByteCode(Program& program) {
#if defined(SK_ENABLE_SKSL_INTERPRETER)
    AutoSource as(this, program.fSource.get());
    std::unique_ptr<ByteCode> result(new ByteCode());
    ByteCodeGenerator cg(fContext.get(), &program, this, result.get());
    bool success = cg.generateCode();
    if (success) {
        return result;
    }
#else
    ABORT("ByteCode interpreter not enabled");
#endif
    return nullptr;
}

@mgood7123
Copy link
Contributor

enabling this in the CPP file directly enables SKSL to work on CPU

@mgood7123
Copy link
Contributor

mgood7123 commented Sep 3, 2022

specifically

 // required to enable CPU support for SKSL, this enables SKSL to work in a CPU canvas
#define SK_ENABLE_SKSL_INTERPRETER

in SkiaSharp\externals\skia\src\sksl\SkSLByteCode.cpp and SkiaSharp\externals\skia\src\sksl\SkSLCompiler.cpp

also

// enable JIT if possible
#define SKVM_JIT_WHEN_POSSIBLE

in SkiaSharp\externals\skia\src\core\SkVM.h (doesnt hurt to JIT :) )

@xtu
Copy link

xtu commented Feb 22, 2023

@mgood7123 did those changes work for you? I am still seeing the exception after applying those changes. Could you please help? Here are my changes.

image

@mgood7123
Copy link
Contributor

mgood7123 commented Feb 22, 2023

it should work, did you try recompiling from scratch?

if not then you will need to try to debug the exception

@xtu
Copy link

xtu commented Feb 22, 2023

I used the same azure-pipelines.yml from this repo to create an Azure pipeline, so I think it is recompiling from scratch.

I cannot debug yet. It would take some time to setup the build environment.

Do you have a copy of the libSkiaSharp.dll that have these changes for me to try?

@mattleibow
Copy link
Contributor

Just been testing this in the new Skia update and it is looking so good. This shaders thing looks like a game changer. GPU and CPU surfaces are all fast!

@mattleibow mattleibow linked a pull request Aug 16, 2023 that will close this issue
5 tasks
@Gobra
Copy link

Gobra commented Aug 29, 2023

@mattleibow Is there any documentation and/or samples about this update that brings custom shaders support? I've been trying a piece of simplest code with SkiaSharp 2.88.5, which is the latest one available, and it still crashes the same way.

I've tried both bitmap canvas and rendering onscreen through SKCanvasView, both crash.

@mattleibow
Copy link
Contributor

Have you tried the v3 alphas? The v2 is still using the same version of skia that does not yet support this.

@Gobra
Copy link

Gobra commented Aug 29, 2023

Have you tried the v3 alphas? The v2 is still using the same version of skia that does not yet support this.

I'm a bit lost here, which v3 alphas are you referring to? NuGet offset not pre-release versions and 2.88.5 is the freshest one, I've checked tags and branches within this project to no result and I've googled around for both SkiaSharp and more general MAUI alpha builds to no avail again.

What am I missing?

@ghost ghost locked as resolved and limited conversation to collaborators Sep 28, 2023
@mattleibow
Copy link
Contributor

They are on the preview feed: https://aka.ms/skiasharp-eap/index.json

However, I am hoping to release a preview of v3 to nuget soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants