[graphite] Optimize UniformManager and fix layout bugs in std430
Consolidates the variations across Layouts into policies described by
a new LayoutRules namespace holding rule functions.
Moves allocation logic into an append(alignment, size) function in the
header so it can be inlined.
Consolidates the write logic into a write<N,Half> and
writeArray<N,Half> template. Branching logic is based on both the
compile-time dimensions/Half-ness and the LayoutRules. In many cases
these LayoutRule checks are skipped due to the compile-time checks.
Shared logic in write() and writeArray() is extracted into a
LayoutTraits struct to define shared constants and conversion
functions.
Lastly, there are helpers to write[Array]<SkSLType> used by the public
type-safe functions. Looking at `objdump`, it appears most functions
are successfully inlined with mainly the more complex array-writing
and the general write(Uniform) variant existing as its own function.
The layout alignment and offset are now calculated directly from the
UniformManager's storage instead of doing a dry-run through
UniformOffsetCalculator that doesn't write, and then repeating the
logic but with an actual dst pointer. UniformOffsetCalculator has
been updated to apply the LayoutRules based on the various
SkSLTypeFoo helper functions.
Simplifying the logic and allowing the writes to appears to lead to
some improvements in overall frametime in MotionMark scenes with high
draw counts: On my M1 mini, when running the Paths SKP in viewer
before this change, uniform extraction took 18% of the total time,
split 10% in ExtractPaintData and 8% in ExtractRenderStepData.
With this change, uniform extraction shrunk to about 9% of the frame
time. ExtractPaintData went to 7.5% and ExtractRenderStepData went to
1.5%. There's additional streamlining we can do in KeyHelpers to
make ExtractPaintData() less of a hot spot too.
Running nanobench has the Paths SKP drop from 2.55ms to 2.31ms, which
is commensurate with the Instruments hotspot reduction above. Other
improvements in MotionMark:
Paths: 2.5 -> 2.3 in grmtl
Arcs: 4.5 -> 4.2 ""
Suits: 6.1 -> 5.8 ""
Leaves: .6 -> .55 ""
Bug: b/317233287
Bug: b/317233303
Change-Id: Ie2659c4766ae4fa043b85961e2efe8147e460cee
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/793356
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
6 files changed