-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Provide a matrix inverse shim for GLES 2.0. #50545
Provide a matrix inverse shim for GLES 2.0. #50545
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
||
// Shim matrix `inverse` for versions that lack it. | ||
// TODO: This could be gated on GLSL < 1.4. | ||
mat3 IPMat3Inverse( mat3 m) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler seems unhappy with this code
@@ -26,4 +26,32 @@ vec4 IPPositionForGlyphPosition(mat4 mvp, | |||
unit_position.y * destination_size.y, 0.0, 1.0); | |||
} | |||
|
|||
#endif | |||
#ifdef IMPELLER_TARGET_OPENGLES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not possible to leave a define unevaluated with our shader compiler pipeline. that is, any define must evaluate to a value during the engine build - so its only possible to use these to turn this on/off for an entire backend.
If there is a runtime capabilities check you'd need to use, you'll have to use a specialization constant - which must be defined in the shader entrypoint and provided during initialization in content_context.cc
For an example of that, grep for supports_decal.
In this particular case, that might not be worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Jonah. I'm in a lot of meetings this week but will try to update this when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think adding a second pipeline is worth the reduced flops of the O(1) invocation of this in conical gradient for on GLES only.
inverse
isn't supported until GLSL ES 3. This restores GLES 2 support (GLSL ES 1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words: I think this approach seems OK as-is for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, one ifdef for GLES
@@ -26,4 +26,32 @@ vec4 IPPositionForGlyphPosition(mat4 mvp, | |||
unit_position.y * destination_size.y, 0.0, 1.0); | |||
} | |||
|
|||
#endif | |||
#ifdef IMPELLER_TARGET_OPENGLES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think adding a second pipeline is worth the reduced flops of the O(1) invocation of this in conical gradient for on GLES only.
inverse
isn't supported until GLSL ES 3. This restores GLES 2 support (GLSL ES 1).
@johnoneil Thanks for this patch! @jonahwilliams @matanlurey WDYT about a test exemption for this given it's a shader-only refactor exercised by goldens using the conical gradient? |
Yeah I think this probably qualifies, as its unlikely we'll ever get GLES 2.0 only capable hardware. |
test-exempt: shader only change tested via goldens. |
625c55b
to
580777b
Compare
@johnoneil Looks like you just need to apply the formatter diff in the linux_unopt output and this will be good to go! git apply <<DONE
diff --git a/impeller/compiler/shader_lib/impeller/gradient.glsl b/impeller/compiler/shader_lib/impeller/gradient.glsl
index a33f4eb3c9..0000000000 100644
--- a/impeller/compiler/shader_lib/impeller/gradient.glsl
+++ b/impeller/compiler/shader_lib/impeller/gradient.glsl
@@ -12,8 +12,8 @@ mat3 IPMapToUnitX(vec2 p0, vec2 p1) {
// Returns a matrix that maps [p0, p1] to [(0, 0), (1, 0)]. Results are
// undefined if p0 = p1.
return mat3(0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0) *
- IPMat3Inverse(mat3(p1.y - p0.y, p0.x - p1.x, 0.0, p1.x - p0.x, p1.y - p0.y,
- 0.0, p0.x, p0.y, 1.0));
+ IPMat3Inverse(mat3(p1.y - p0.y, p0.x - p1.x, 0.0, p1.x - p0.x,
+ p1.y - p0.y, 0.0, p0.x, p0.y, 1.0));
}
/// Compute the t value for a conical gradient at point `p` between the 2
diff --git a/impeller/compiler/shader_lib/impeller/transform.glsl b/impeller/compiler/shader_lib/impeller/transform.glsl
index 12a140b116..0000000000 100644
--- a/impeller/compiler/shader_lib/impeller/transform.glsl
+++ b/impeller/compiler/shader_lib/impeller/transform.glsl
@@ -30,7 +30,7 @@ vec4 IPPositionForGlyphPosition(mat4 mvp,
// Shim matrix `inverse` for versions that lack it.
// TODO: This could be gated on GLSL < 1.4.
-mat3 IPMat3Inverse( mat3 m) {
+mat3 IPMat3Inverse(mat3 m) {
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
@@ -41,17 +41,18 @@ mat3 IPMat3Inverse( mat3 m) {
float det = a00 * b01 + a01 * b11 + a02 * b21;
- return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
- b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
- b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
+ return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11), b11,
+ (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10), b21,
+ (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) /
+ det;
}
-#else // IMPELLER_TARGET_OPENGLES
+#else // IMPELLER_TARGET_OPENGLES
mat3 IPMat3Inverse(mat3 m) {
return inverse(m);
}
-#endif // IMPELLER_TARGET_OPENGLES
+#endif // IMPELLER_TARGET_OPENGLES
-#endif // TRANSFORM_GLSL_
+#endif // TRANSFORM_GLSL_
DONE |
580777b
to
1002801
Compare
@bdero What's the best way to avoid similar format errors in the future? I don't know the local command to run those checks. |
1002801
to
3618421
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@johnoneil Shader files (.glsl, .frag, .vert) are run through clang-format on CI. So I autoformat shaders and cpp files in vscode using the // In local workspace settings
"clang-format.executable": "/absolute/path/to/my/engine/checkout/src/buildtools/mac-x64/clang/bin/clang-format", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2024-02-15 30870216+gaaclarke@users.noreply.github.com Added tool to easily check golden diffs locally. (flutter/engine#50654) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 4bbf2060b008 to 12d0b7fac4c3 (2 revisions) (flutter/engine#50689) 2024-02-15 johnoneil@users.noreply.github.com Provide a matrix inverse shim for GLES 2.0. (flutter/engine#50545) 2024-02-15 jonahwilliams@google.com [iOS] Ensure FlutterMetalLayer has correct backpressure. (flutter/engine#50486) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 682f0e1e7e77 to 4bbf2060b008 (3 revisions) (flutter/engine#50686) 2024-02-15 103135467+sealesj@users.noreply.github.com Pin OSV-Scanner reusable workflow (flutter/engine#50649) 2024-02-15 whesse@google.com Add support for dart_src GN variable to flutter_frontend_server build (flutter/engine#50685) 2024-02-15 6718144+renancaraujo@users.noreply.github.com fix: consider array size on canvaskit shader data (flutter/engine#49754) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 1277910beec9 to 682f0e1e7e77 (1 revision) (flutter/engine#50683) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 85ab600a9519 to 1277910beec9 (2 revisions) (flutter/engine#50682)
2024-02-15 30870216+gaaclarke@users.noreply.github.com Added tool to easily check golden diffs locally. (flutter/engine#50654) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 4bbf2060b008 to 12d0b7fac4c3 (2 revisions) (flutter/engine#50689) 2024-02-15 johnoneil@users.noreply.github.com Provide a matrix inverse shim for GLES 2.0. (flutter/engine#50545) 2024-02-15 jonahwilliams@google.com [iOS] Ensure FlutterMetalLayer has correct backpressure. (flutter/engine#50486) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 682f0e1e7e77 to 4bbf2060b008 (3 revisions) (flutter/engine#50686) 2024-02-15 103135467+sealesj@users.noreply.github.com Pin OSV-Scanner reusable workflow (flutter/engine#50649) 2024-02-15 whesse@google.com Add support for dart_src GN variable to flutter_frontend_server build (flutter/engine#50685) 2024-02-15 6718144+renancaraujo@users.noreply.github.com fix: consider array size on canvaskit shader data (flutter/engine#49754) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 1277910beec9 to 682f0e1e7e77 (1 revision) (flutter/engine#50683) 2024-02-15 skia-flutter-autoroll@skia.org Roll Skia from 85ab600a9519 to 1277910beec9 (2 revisions) (flutter/engine#50682)
This PR addresses Issue #141829.
We saw a shader compilation error after updating
flutter/impeller
due to the lack of a matrixinverse
implementation on GLSL 1.0 used on GLSL 2.0. This change provides one (for the current used case which is only format3
support.I think this change needs some discussion as gating the change on GLSL < 1.4 would be more effective. Also my knowledge of correctly managing these
.glsl
based shaders is still superficial.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.