The Dawn backend seems to be causing some problems

340 views
Skip to first unread message

guodong chen

unread,
Sep 26, 2022, 6:06:14 AM9/26/22
to skia-discuss

In short, my application supports both Opengl and Dawn backends.
When I open support for both Dawn and Opengl, it looks like this.
skia_enable_gpu = true
skia_use_metal = true
skia_use_gl = true
skia_use_dawn=true
skia_use_vulkan=false

application will fail when using Opengl to build SkSurface.
If I turn off the compile option on the Dawn backend, everything is fine

GrGLFramebufferInfo info;
info.fFBOID = (GLuint)framebuffer;
info.fFormat = format;
GrBackendRenderTarget target(width, height, 0, 0, info);
SkSurfaceProps surface_props;
auto surface = SkSurface::MakeFromBackendRenderTarget(
env->gr_context_.get(),
target,
kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
nullptr,
&surface_props);

I'm pretty sure info.fFormat= format; Is a valid value. 
But when I tracked down the Skia code, I realized
this file skia/src/gpu/ganesh/GrBackendSurface.cpp and In the following code

#ifdef SK_GL
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
const GrGLFramebufferInfo& glInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(std::max(1, sampleCnt))
, fStencilBits(stencilBits)
, fBackend(GrBackendApi::kOpenGL)
, fGLInfo(glInfo) {
fIsValid = SkToBool(glInfo.fFormat); // the glInfo must have a valid format
}
#endif

glInfo.fFormat It just magically becomes 0, so Is it a hidden memory error? 
My platform is MAC system M1 chip.

Greg Daniel

unread,
Sep 26, 2022, 7:07:27 AM9/26/22
to skia-discuss
Can you share your code where you are setting up the GrGLFramebufferInfo and GrGLBackendRenderTarget? Have you tried putting a breakpoint right before our in the GrGLBackendRenderTarget constructor to see what the value of the infos format is?

Also is you're just using GL and Dawn, you don't need skia_use_metal or skia_use_vulkan enabled.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/1a7f3f56-dc99-4b40-8fec-bbd4f18c3bf8n%40googlegroups.com.

guodong chen

unread,
Sep 26, 2022, 7:18:28 AM9/26/22
to skia-discuss
Can you share your code where you are setting up the GrGLFramebufferInfo and GrGLBackendRenderTarget?
After I initialize Opengl's environment with GLFW, I initialize GrGLFramebufferInfo and GrGLBackendRenderTarget.

Have you tried putting a breakpoint right before our in the GrGLBackendRenderTarget constructor to see what the value of the infos format is?
Instead of using single-step debugging, I directly modified the SKIA code to add printf, like this

// in my code
GrGLFramebufferInfo info;
info.fFBOID = (GLuint)framebuffer;
info.fFormat = format;
printf("%x %d\n", &info, info.fFormat);
GrBackendRenderTarget target(width, height, 0, 0, info);

// in skia code
#ifdef SK_GL
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
const GrGLFramebufferInfo& glInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(std::max(1, sampleCnt))
, fStencilBits(stencilBits)
, fBackend(GrBackendApi::kOpenGL)
, fGLInfo(glInfo) {
printf("%x %d\n", &glInfoglInfo.fFormat);
fIsValid = SkToBool(glInfo.fFormat); // the glInfo must have a valid format
}
#endif

I compared the addresses of the variables and found that they were same. But when passed to SKia, glinfo.fformat becomes 0.
When I turn off skia_use_dawn and keep Metal and GL everything will be fine.


That's all I got from debugging

Greg Daniel

unread,
Sep 26, 2022, 7:57:43 AM9/26/22
to skia-discuss
Can you share the code where you set up those two structs in your code? Can you add more printf statements throughout your code to see when the format goes to zero on the GrGLFramebufferInfo?

guodong chen

unread,
Sep 26, 2022, 8:25:49 AM9/26/22
to skia-discuss

This is the SKIA code I pulled this afternoon and added debugging information output with it

WX20220926-201926.png

This is my own code

WX20220926-202031.png

Debugging information output

WX20220926-202224.png

As you can see from the output

//in my code
start file:source/creator/gfx/ui/xw/x/opengl/backend_sk_surface.cc@32 6f0962a8 32856

//in skia code
debug file:../../src/gpu/ganesh/GrBackendSurface.cpp@1059 6f0962a8 0

//in my code
end  file:source/creator/gfx/ui/xw/x/opengl/backend_sk_surface.cc@34 6f0962a8 0


You can see that the address is the same, but the value has changed inexplicably
I tried it again and turned off Dawn's compile options and everything worked fine

guodong chen

unread,
Sep 26, 2022, 8:28:41 AM9/26/22
to skia-discuss
At first I wondered if SKia's header file didn't match the compiled library. But it soon became clear that was not the problem

guodong chen

unread,
Sep 26, 2022, 8:38:35 AM9/26/22
to skia-discuss
I tried to shut down Dawn again, and from the output everything was fine

WX20220926-203714.png

Greg Daniel

unread,
Sep 26, 2022, 8:56:17 AM9/26/22
to skia-discuss
Wow this is certainly a weird issue. At first I was wondering if it has something to do with initializing the value inside of a union and the compiler getting confused when Dawn was an option in the union. But as you can see here we don't actually even put the Dawn object into the union for GrBackendRenderTarget, https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/gpu/GrBackendSurface.h;l=650.

Out of curiosity does the fGLInfo on GrBackendRenderTarget end up with the right value? It seems really weird that the const ref that is passed into the constructor is getting modified. I wonder if something is going wrong with the default copy constructor of GrGLFramebuferrInfo. Can you test out adding a copy constructor here, https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/gpu/gl/GrGLTypes.h;drc=f97e7e130b02a0fee5a06aa9cdf25d3a0a3715d0;l=189, and see if that fixes anything?

Brian Salomon

unread,
Sep 26, 2022, 9:06:38 AM9/26/22
to skia-d...@googlegroups.com
On Mon, Sep 26, 2022 at 8:28 AM guodong chen <chenguodo...@gmail.com> wrote:
At first I wondered if SKia's header file didn't match the compiled library. But it soon became clear that was not the problem

It needs to be the same header but the including code must also be compiled with the same Skia preprocessor macro values. Is it possible that is not the case?

Brian

guodong chen

unread,
Sep 26, 2022, 10:07:20 AM9/26/22
to skia-discuss
Yes! your words woke me up, I tried it and it seems to be all right

Thank you very much @Brian Salomon @egda...@google.com

Reply all
Reply to author
Forward
0 new messages