Sped up shader warmup by only drawing on a 100x100 surface (#36482)
Sped up shader warmup by only drawing on a 100x100 surface and doing the draw calls on top of each other.
This commit is contained in:
@@ -16,7 +16,9 @@ Future<void> beginFrame(Duration timeStamp) async {
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white;
|
||||
canvas.drawRect(paintBounds, backgroundPaint);
|
||||
await const DefaultShaderWarmUp().warmUpOnCanvas(canvas);
|
||||
await const DefaultShaderWarmUp(
|
||||
drawCallSpacing: 80.0, canvasSize: ui.Size(1024, 1024))
|
||||
.warmUpOnCanvas(canvas);
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
|
||||
// COMPOSITE
|
||||
|
||||
@@ -56,12 +56,12 @@ abstract class ShaderWarmUp {
|
||||
|
||||
/// The size of the warm up image.
|
||||
///
|
||||
/// The exact size shouldn't matter much as long as it's not too far away from
|
||||
/// the target device's screen. 1024x1024 is a good choice as it is within an
|
||||
/// order of magnitude of most devices.
|
||||
/// The exact size shouldn't matter much as long as all draws are onscreen.
|
||||
/// 100x100 is an arbitrary small size that's easy to fit significant draw
|
||||
/// calls onto.
|
||||
///
|
||||
/// A custom shader warm up can override this based on targeted devices.
|
||||
ui.Size get size => const ui.Size(1024.0, 1024.0);
|
||||
ui.Size get size => const ui.Size(100.0, 100.0);
|
||||
|
||||
/// Trigger draw operations on a given canvas to warm up GPU shader
|
||||
/// compilation cache.
|
||||
@@ -99,7 +99,20 @@ abstract class ShaderWarmUp {
|
||||
/// issues seen so far.
|
||||
class DefaultShaderWarmUp extends ShaderWarmUp {
|
||||
/// Allow [DefaultShaderWarmUp] to be used as the default value of parameters.
|
||||
const DefaultShaderWarmUp();
|
||||
const DefaultShaderWarmUp(
|
||||
{this.drawCallSpacing = 0.0,
|
||||
this.canvasSize = const ui.Size(100.0, 100.0)});
|
||||
|
||||
/// Constant that can be used to space out draw calls for visualizing the draws
|
||||
/// for debugging purposes (example: 80.0). Be sure to also change your canvas
|
||||
/// size.
|
||||
final double drawCallSpacing;
|
||||
|
||||
/// Value that returned by this.size to control canvas size where draws happen.
|
||||
final ui.Size canvasSize;
|
||||
|
||||
@override
|
||||
ui.Size get size => canvasSize;
|
||||
|
||||
/// Trigger common draw operations on a canvas to warm up GPU shader
|
||||
/// compilation cache.
|
||||
@@ -157,22 +170,22 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
|
||||
canvas.save();
|
||||
for (ui.Paint paint in paints) {
|
||||
canvas.drawPath(paths[i], paint);
|
||||
canvas.translate(80.0, 0.0);
|
||||
canvas.translate(drawCallSpacing, 0.0);
|
||||
}
|
||||
canvas.restore();
|
||||
canvas.translate(0.0, 80.0);
|
||||
canvas.translate(0.0, drawCallSpacing);
|
||||
}
|
||||
|
||||
// Warm up shadow shaders.
|
||||
const ui.Color black = ui.Color(0xFF000000);
|
||||
canvas.save();
|
||||
canvas.drawShadow(rrectPath, black, 10.0, true);
|
||||
canvas.translate(80.0, 0.0);
|
||||
canvas.translate(drawCallSpacing, 0.0);
|
||||
canvas.drawShadow(rrectPath, black, 10.0, false);
|
||||
canvas.restore();
|
||||
|
||||
// Warm up text shaders.
|
||||
canvas.translate(0.0, 80.0);
|
||||
canvas.translate(0.0, drawCallSpacing);
|
||||
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)..pushStyle(ui.TextStyle(color: black))..addText('_');
|
||||
|
||||
Reference in New Issue
Block a user