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

[Impeller] simplify text shaders by moving UV computation to contents #39989

Merged
merged 6 commits into from Mar 3, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Mar 1, 2023

This should improve performance without dramatically changing the raster thread cost - additionally allows us to upload less data.

Changes found in shader flutter/impeller/entity/gles/glyph_atlas.frag.gles on core Mali-G78:
has_uniform_computation:
  True <- before
  False <- after
In variant Main:
  fp16_arithmetic: 45 <- before
  fp16_arithmetic: 100 <- after
longest_path_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.125000    0.125000    0.093750    0.000000    0.000000    0.875000    0.250000    varying
after   0.093750    0.031250    0.093750    0.000000    0.000000    0.375000    0.250000    varying

shortest_path_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.125000    0.125000    0.046875    0.000000    0.000000    0.875000    0.250000    varying
after   0.062500    0.031250    0.062500    0.000000    0.000000    0.375000    0.250000    varying

total_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.156250    0.156250    0.093750    0.000000    0.000000    0.875000    0.500000    varying
after   0.093750    0.031250    0.093750    0.000000    0.000000    0.375000    0.250000    varying


For a full report, run:
  $ malioc --fragment --core Mali-G78 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas.frag.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas.frag.gles on core Mali-T880:
longest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  1.650000    2.000000    1.000000    load_store
after   1.000000    1.000000    1.000000    arithmetic,load_store,texture

shortest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  1.650000    2.000000    1.000000    load_store
after   1.000000    1.000000    1.000000    arithmetic,load_store,texture

total_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.000000    2.000000    2.000000    arithmetic
after   1.333333    1.000000    1.000000    arithmetic

In variant Main:
  work_registers_used: 3 <- before
  work_registers_used: 2 <- after

For a full report, run:
  $ malioc --fragment --core Mali-T880 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas.frag.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas.vert.gles on core Mali-G78:
In variant Position:
  fp16_arithmetic: 0 <- before
  fp16_arithmetic: 88 <- after
longest_path_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.296875    0.296875    0.000000    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

shortest_path_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.296875    0.296875    0.000000    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

total_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.296875    0.296875    0.000000    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

In variant Position:
  uniform_registers_used: 18 <- before
  uniform_registers_used: 16 <- after
In variant Varying:
  fp16_arithmetic: 100 <- before
  fp16_arithmetic: None <- after
longest_path_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.078125    0.015625    0.078125    0.000000    7.000000    0.000000    load_store
after   0.031250    0.000000    0.031250    0.000000    4.000000    0.000000    load_store

shortest_path_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.078125    0.015625    0.078125    0.000000    7.000000    0.000000    load_store
after   0.031250    0.000000    0.031250    0.000000    4.000000    0.000000    load_store

total_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.078125    0.015625    0.078125    0.000000    7.000000    0.000000    load_store
after   0.031250    0.000000    0.031250    0.000000    4.000000    0.000000    load_store

In variant Varying:
  work_registers_used: 12 <- before
  work_registers_used: 9 <- after

For a full report, run:
  $ malioc --vertex --core Mali-G78 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas.vert.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas.vert.gles on core Mali-T880:
longest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.960000    12.000000   0.000000    load_store
after   2.970000    7.000000    0.000000    load_store

shortest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.960000    12.000000   0.000000    load_store
after   2.970000    7.000000    0.000000    load_store

total_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  4.000000    12.000000   0.000000    load_store
after   3.000000    7.000000    0.000000    load_store

In variant Main:
  work_registers_used: 3 <- before
  work_registers_used: 2 <- after

For a full report, run:
  $ malioc --vertex --core Mali-T880 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas.vert.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas_sdf.frag.gles on core Mali-G78:
has_uniform_computation:
  True <- before
  False <- after
In variant Main:
  fp16_arithmetic: 60 <- before
  fp16_arithmetic: 77 <- after
longest_path_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.406250    0.406250    0.046875    0.312500    0.000000    0.750000    0.250000    varying
after   0.312500    0.312500    0.046875    0.312500    0.000000    0.250000    0.250000    arith_total,arith_fma,arith_sfu

shortest_path_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.406250    0.406250    0.015625    0.312500    0.000000    0.750000    0.250000    varying
after   0.312500    0.312500    0.015625    0.312500    0.000000    0.250000    0.250000    arith_total,arith_fma,arith_sfu

total_cycles in variant Main
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  varying     texture     bound       
before  0.406250    0.406250    0.046875    0.312500    0.000000    0.750000    0.250000    varying
after   0.312500    0.312500    0.046875    0.312500    0.000000    0.250000    0.250000    arith_total,arith_fma,arith_sfu

In variant Main:
  uniform_registers_used: 10 <- before
  uniform_registers_used: 8 <- after
In variant Main:
  work_registers_used: 22 <- before
  work_registers_used: 20 <- after

For a full report, run:
  $ malioc --fragment --core Mali-G78 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas_sdf.frag.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas_sdf.frag.gles on core Mali-T880:
longest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  4.620000    2.000000    3.000000    arithmetic
after   3.300000    1.000000    3.000000    arithmetic

shortest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  4.620000    2.000000    3.000000    arithmetic
after   3.300000    1.000000    3.000000    arithmetic

total_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  5.000000    2.000000    3.000000    arithmetic
after   3.666667    1.000000    3.000000    arithmetic

In variant Main:
  uniform_registers_used: 2 <- before
  uniform_registers_used: 1 <- after

For a full report, run:
  $ malioc --fragment --core Mali-T880 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas_sdf.frag.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas_sdf.vert.gles on core Mali-G78:
In variant Position:
  fp16_arithmetic: 90 <- before
  fp16_arithmetic: 88 <- after
longest_path_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.171875    0.171875    0.046875    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

shortest_path_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.171875    0.171875    0.046875    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

total_cycles in variant Position
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.171875    0.171875    0.046875    0.000000    4.000000    0.000000    load_store
after   0.140625    0.140625    0.046875    0.000000    2.000000    0.000000    load_store

In variant Position:
  uniform_registers_used: 14 <- before
  uniform_registers_used: 16 <- after
longest_path_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.000000    0.000000    0.000000    0.000000    5.000000    0.000000    load_store
after   0.000000    0.000000    0.000000    0.000000    3.000000    0.000000    load_store

shortest_path_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.000000    0.000000    0.000000    0.000000    5.000000    0.000000    load_store
after   0.000000    0.000000    0.000000    0.000000    3.000000    0.000000    load_store

total_cycles in variant Varying
        arith_total arith_fma   arith_cvt   arith_sfu   load_store  texture     bound       
before  0.000000    0.000000    0.000000    0.000000    5.000000    0.000000    load_store
after   0.000000    0.000000    0.000000    0.000000    3.000000    0.000000    load_store

In variant Varying:
  work_registers_used: 8 <- before
  work_registers_used: 6 <- after

For a full report, run:
  $ malioc --vertex --core Mali-G78 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas_sdf.vert.gles

Changes found in shader flutter/impeller/entity/gles/glyph_atlas_sdf.vert.gles on core Mali-T880:
longest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.300000    10.000000   0.000000    load_store
after   2.970000    5.000000    0.000000    load_store

shortest_path_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.300000    10.000000   0.000000    load_store
after   2.970000    5.000000    0.000000    load_store

total_cycles in variant Main
        arithmetic  load_store  texture     bound       
before  3.333333    10.000000   0.000000    load_store
after   3.000000    5.000000    0.000000    load_store


For a full report, run:
  $ malioc --vertex --core Mali-T880 /b/s/w/ir/cache/builder/src/out/android_debug_unopt/gen/flutter/impeller/entity/gles/glyph_atlas_sdf.vert.gles

Part of flutter/flutter#121732

@flutter-dashboard
Copy link

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 Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on 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.

.aaaa *
frag_info.text_color;
vec4 value = texture(glyph_atlas_sampler, v_uv);
if (v_has_color != 1.0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to get rid of this too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this wouldn't be an issue if we just had separate atlases. Leaving for another day.

@jonahwilliams
Copy link
Member Author

This shader is also almost what I need for flutter/flutter#121650

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Super minor comments.

auto position = PositionForGlyphPosition(
translation, point, glyph_position.glyph.bounds.size);
vtx.uv = point * uv_scaler_a + uv_scaler_b;
vtx.position = position;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we're not passing as much needlessly interpolated data to the fragment shader anymore (🤢), but I wonder if the 16 byte savings per vertex is worth the extra per character CPU work. My guess is that it's worth it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also have to pay the CPU cost of copying that extra data too. Its probably slightly more expensive on the raster side of things but hard to tell exactly.

Matrix(1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
offset_glyph_position.x, offset_glyph_position.y, 0, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matrix::MakeTranslation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Size destination_size) {
return translation * Vector4(unit_position.x * destination_size.width,
unit_position.y * destination_size.height, 0.0,
1.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't translation * (unit_position * destination_size) work fine for this, or are we missing an overload somewhere? Size should get coerced to Point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller needs tests
Projects
No open projects
Archived in project
3 participants