Go to file
Mike Klein 19cb22e3d4 expand float peepholes
I started adding more _imm Ops like mul_f32_imm and noticed that there
was some low hanging peephole fruit here that we can harvest first.

Each of these peepholes I've added is sound in the way that I've
documented, and the div_f32 and mul_f32 peepholes are actively being
hit.  I think it's inevitable that the add_f32 and sub_f32 ones will be
hit eventually too as we expand how skvm is used.

The easiest place to see this in action is
when SkColorFilter_Matrix::program() is passed an opaque color:

    skvm::F32 invA = p->div(p->splat(1.0f), *a)

now leaves invA as splat(1.0f) directly, skipping the premul divide.
We still do the next part checking to see if invA is infinity; more
on that at the end of the CL description.

In this way I think we ought to never need to thread through a
shader_is_opaque parameter to color filters, instead letting the program
builder simply look and see if it is, among any number of other similar
optimizations.

Interestingly, though we may know sometimes the input to
SkColorFilter_Matrix::program() is opaque, as written today we'll never
know if the output is.  Since we don't specialize the code based on the
0/1 values of the matrix, we lose the knowledge that alpha is 1.0f as it
goes through the matrix.  There are two good ways to fix this:

   1) do specialize on 0/1 values of the matrix so that the program
      sees alpha is not changed when alpha is not changed;

   2) wrap today's virtual program() with a base-class non-virtual
      that queries getFlags() & kAlphaUnchanged_Flag to save and restore
      the input alpha, essentially marking any code that changes alpha
      as dead code.

2) is kind of the brute force, trusting version of 1), but does have
the advantage that the generated code need not change.  Still, in this
case of a matrix, I think we'll want to look at 0/1 values anyway...
they'll come up more often than just for the alpha channel.

You can see a mul_f32 peephole happen when the blitter goes to store any
known-opaque color to memory.  We go through some logic like

     alpha_as_byte = round(mul(alpha, splat(255.0f)))

and if alpha is known to be splat(1.0f), we'll now skip that mul(),

     alpha_as_byte = round(splat(255.0f))

I think this is all the strictly viable float peepholes where one
argument is a constant.  Obviously there are lots of peepholes we can
write for int32, int16, and bitwise instructions, and then there's a
whole untapped world of peepholes to explore when _all_ arguments are
constant.  These all-constant peepholes let our program notice that,
e.g., 1.0f < infinity and we can skip that part of the unpremul too, or
that round(splat(255.0f)) == 0xff and we can skip that work.

These all-constant peepholes may not be super important, as anywhere
they can trigger, the instruction must be hoistable: since all arguments
are constant, none depend on loop variables.  But still, nicer to run
once ever at compile time than once per invocation at runtime.  And it's
less code to analzye, less code to JIT, fewer instructions to interpret,
etc.

Change-Id: Ia2dc5af2cfff71a12693a2903f579a57c9302d12
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255616
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2019-11-21 16:23:33 +00:00
animations first cut at a checkbox 2009-10-21 19:41:10 +00:00
bench No longer ref count GrGeometryProcessors 2019-11-20 21:36:52 +00:00
bin [infra] Fix bin/try 2019-11-15 19:44:04 +00:00
build/fuchsia Use system-temp storage. 2019-11-20 20:47:42 +00:00
build_overrides Update Dawn backend to ToT. This is about 3 months of changes. 2019-10-15 22:26:38 +00:00
dm remove unused (by clients) SkMultiPictureDraw 2019-11-15 18:18:36 +00:00
docker Fix usage of depot_tools in containers. 2019-10-14 19:38:40 +00:00
docs/examples docs/fiddle: add "incomplete" fiddle. 2019-10-11 18:22:34 +00:00
example Revert "add guard to switch to SkPathTypes" 2019-09-14 19:13:44 +00:00
experimental Reland "Minimal iOS app: Perform present subsequent to flush" 2019-10-14 18:32:37 +00:00
fuzz [fuzzing] Fix skdescriptor deserialize compile 2019-10-23 11:54:14 +00:00
gm No longer ref count GrGeometryProcessors 2019-11-20 21:36:52 +00:00
gn Replace third_party/gif: Preflight changes 2019-11-21 15:19:41 +00:00
include Fix windows DLL builds with shaper included 2019-11-19 14:50:12 +00:00
infra Roll recipe dependencies (trivial). 2019-11-21 01:33:03 +00:00
modules Find and cache font family lists and the typeface lists that they map to 2019-11-20 20:23:51 +00:00
platform_tools android_gdbserver: Don't fail when trying to locate nonexistent files 2019-09-16 16:28:33 +00:00
resources [skottie] One-node camera support 2019-11-14 18:45:18 +00:00
samplecode Specialize vertex writing function for common quad VertexSpecs 2019-11-20 19:58:11 +00:00
site [infra] Update docs with respect to Go modules. 2019-11-18 18:04:19 +00:00
specs [img-decode] Start on proposed new spec 2019-05-06 17:39:19 +00:00
src expand float peepholes 2019-11-21 16:23:33 +00:00
tests No longer ref count GrGeometryProcessors 2019-11-20 21:36:52 +00:00
third_party Roll skia/third_party/skcms 2914b63d6886..68d3f3a95f1b (1 commits) 2019-11-20 20:59:02 +00:00
tools Replace third_party/gif: Preflight changes 2019-11-21 15:19:41 +00:00
.clang-format restore .clang-format 2019-03-21 15:52:32 +00:00
.clang-tidy add google-build-namespaces to clang-tidy checks 2018-12-12 16:33:59 +00:00
.gitignore clean up some .gitignores 2019-05-15 19:55:45 +00:00
.gn Basic standalone GN configs. 2016-07-21 12:25:45 -07:00
AUTHORS Issue- >Skia tiled bitmap rendering is too slow when tildmodeX is not same as tileModeY. 2019-11-14 20:52:18 +00:00
BUILD.gn Replace third_party/gif: Preflight changes 2019-11-21 15:19:41 +00:00
codereview.settings Make uploading to Gerrit the default for Skia 2016-11-09 19:07:56 +00:00
CONTRIBUTING Fix references to https://sites.google.com/site/skiadocs/. 2015-02-03 13:12:54 -02:00
CQ_COMMITTERS Moved committer list to chrome-infra-auth and deleted it from the repo 2015-09-02 13:37:54 -07:00
DEPS Roll third_party/externals/angle2 99bd10b70422..b8e748be6b94 (17 commits) 2019-11-21 06:23:53 +00:00
go.mod [infra] Use CIPD packages from infra repo 2019-11-20 14:02:48 +00:00
go.sum [infra] Use CIPD packages from infra repo 2019-11-20 14:02:48 +00:00
LICENSE BUG=skia:5602 2016-09-02 11:19:34 -07:00
OWNERS add OWNERS file 2017-12-01 19:50:19 +00:00
PRESUBMIT.py Use urllib_request instead of urllib2 in PRESUBMIT. 2019-10-22 20:30:56 +00:00
public.bzl Revert "public.bzl: update to replace Gif with Wuffs" 2019-11-20 21:44:04 +00:00
README Fix references to https://sites.google.com/site/skiadocs/. 2015-02-03 13:12:54 -02:00
README.chromium Update README.chromium. 2015-06-11 13:19:24 -07:00
RELEASE_NOTES.txt Clamp RGB outputs of GrYUVtoRGBEffect. 2019-11-11 20:04:15 +00:00
whitespace.txt Whitespace test 2019-05-18 13:05:29 +00:00

Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.

See full details, and build instructions, at https://skia.org.