Way to force OpenGL maximum version?

64 views
Skip to first unread message

Devin Kerr

unread,
Jul 6, 2022, 6:26:32 PMJul 6
to skia-discuss
Is there a strategy for forcing a specific maximum openGL version in Skia? 

We have to support some, unfortunately, very old hardware and are getting crashes deep in Skia Gr code on Radeon HD 5450's. We'd love to be able to try OpenGL 3.2, for example.

Chris Conover

unread,
Jul 21, 2022, 5:27:21 PMJul 21
to skia-discuss
+1, I’d love to be able to force a max version on OpenGL too. Is there any way to do that?

Brian Osman

unread,
Jul 21, 2022, 6:33:02 PMJul 21
to skia-d...@googlegroups.com
Skia itself just configures the features it uses based on the GL context that you provide/create. So this is partly up to the platform GL implementation, if it has a way to request a particular version of GL (eg, the major and minor version attributes of https://registry.khronos.org/EGL/sdk/docs/man/html/eglCreateContext.xhtml). Even if it doesn't, (or if the platform API provides a context with a higher version than what you request), you may be able to limit what features Skia uses by supplying your own version of the glGetString function pointer in the glInterface. Again, Skia always just uses GL via the function pointers you supply - so you can write your own implementation that calls the real version and filters the output, for example.

--
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/20d71897-9123-42e9-b0ae-256df306d403n%40googlegroups.com.

Jasper Duba

unread,
Jul 21, 2022, 7:09:06 PMJul 21
to skia-discuss
This bug with the Radeon 5450 turned out to be a SKSL -> GLSL problem with assuming you can construct a mat2 from a vec4. For some reason on this very old card the runtime shader compilation fails with ` ERROR: 0:32: error(#53) Built-in function parameter type check fail: an operation which requires matrix parameters is used on a non matrix type!`

It works fine on every other card / driver situation we can come up with. The patch is then in the generated sksl for the GrPathTessellationShader/GrStrokeTessellationShader to build the float2x2 eventual mat2 more directly by accessing xyzw.

the patch that works for us:


diff --git a/src/gpu/tessellate/shaders/GrPathTessellationShader.cpp b/src/gpu/tessellate/shaders/GrPathTessellationShader.cpp
index 439cf439e1..82771b92d0 100644
--- a/src/gpu/tessellate/shaders/GrPathTessellationShader.cpp
+++ b/src/gpu/tessellate/shaders/GrPathTessellationShader.cpp
@@ -124,7 +124,7 @@ void GrPathTessellationShader::Impl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs
                                                             &affineMatrix);
     fTranslateUniform = args.fUniformHandler->addUniform(nullptr, kVertex_GrShaderFlag,
                                                          kFloat2_GrSLType, "translate", &translate);
-    args.fVertBuilder->codeAppendf("float2x2 AFFINE_MATRIX = float2x2(%s);", affineMatrix);
+    args.fVertBuilder->codeAppendf("float2x2 AFFINE_MATRIX = float2x2(%s.x, %s.y, %s.z, %s.w);", affineMatrix, affineMatrix, affineMatrix, affineMatrix);
     args.fVertBuilder->codeAppendf("float2 TRANSLATE = %s;", translate);
     this->emitVertexCode(*args.fShaderCaps,
                          shader,
diff --git a/src/gpu/tessellate/shaders/GrStrokeTessellationShader_HardwareImpl.cpp b/src/gpu/tessellate/shaders/GrStrokeTessellationShader_HardwareImpl.cpp
index 4b558ec07c..37134192c3 100644
--- a/src/gpu/tessellate/shaders/GrStrokeTessellationShader_HardwareImpl.cpp
+++ b/src/gpu/tessellate/shaders/GrStrokeTessellationShader_HardwareImpl.cpp
@@ -99,7 +99,7 @@ void GrStrokeTessellationShader::HardwareImpl::onEmitCode(EmitArgs& args, GrGPAr
     fAffineMatrixUniform = uniHandler->addUniform(nullptr, affineMatrixVisibility, kFloat4_GrSLType,
                                                   "affineMatrix", &affineMatrixName);
     if (affineMatrixVisibility & kVertex_GrShaderFlag) {
-        v->codeAppendf("float2x2 AFFINE_MATRIX = float2x2(%s);\n", affineMatrixName);
+        v->codeAppendf("float2x2 AFFINE_MATRIX = float2x2(%s.x, %s.y, %s.z, %s.w);\n", affineMatrixName, affineMatrixName, affineMatrixName, affineMatrixName);
     }
 
     v->codeAppend(R"(



Hopefully this helps someone else that runs into this with the Radeon 5450

Cheers,
Jasper

John Stiles

unread,
Jul 22, 2022, 12:48:36 PMJul 22
to skia-discuss
Casting between vec4 and mat2 is allowed in GLSL, but some very old GPUs don't support it well. I'm guessing they are no longer releasing new drivers for this card, but it wouldn't hurt to check and see if there is a newer one, just in case.

At any rate, this cast doesn't seem like we need it at all—we can just upload the affine matrix as a mat2 directly. Please try this patch and see if it solves the issue on your machine: http://review.skia.org/561759

Devin Kerr

unread,
Jul 22, 2022, 1:10:13 PMJul 22
to skia-discuss
Thanks for the patch!

Yes, AMD officially designates it a "legacy" card with the last driver update in 2016. We had some customers try a couple different drivers, but there was no change in the behavior.

Jasper Duba

unread,
Jul 22, 2022, 1:28:50 PMJul 22
to skia-discuss

Thank you John!

We have heard direct from computer vendors that they are still shipping new (!!! can you imagine!!!) custom PCs with this very old Radeon 5450 card that is almost a decade out of driver updates so this great to support.

Cheers,
Jasper
Reply all
Reply to author
Forward
0 new messages