Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions impeller/compiler/shader_lib/impeller/gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#define GRADIENT_GLSL_

#include <impeller/texture.glsl>
#include <impeller/transform.glsl>

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) *
inverse(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
Expand Down
31 changes: 30 additions & 1 deletion impeller/compiler/shader_lib/impeller/transform.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,33 @@ vec4 IPPositionForGlyphPosition(mat4 mvp,
unit_position.y * destination_size.y, 0.0, 1.0);
}

#endif
#ifdef IMPELLER_TARGET_OPENGLES
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Member

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?

Copy link
Contributor

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


// Shim matrix `inverse` for versions that lack it.
// TODO: This could be gated on GLSL < 1.4.
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];

float b01 = a22 * a11 - a12 * a21;
float b11 = -a22 * a10 + a12 * a20;
float b21 = a21 * a10 - a11 * a20;

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;
}

#else // IMPELLER_TARGET_OPENGLES

mat3 IPMat3Inverse(mat3 m) {
return inverse(m);
}

#endif // IMPELLER_TARGET_OPENGLES

#endif // TRANSFORM_GLSL_