Unverified Commit 9b150f13 authored by gaaclarke's avatar gaaclarke Committed by GitHub

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.
parent 0d0af315
...@@ -16,7 +16,9 @@ Future<void> beginFrame(Duration timeStamp) async { ...@@ -16,7 +16,9 @@ Future<void> beginFrame(Duration timeStamp) async {
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white; final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white;
canvas.drawRect(paintBounds, backgroundPaint); 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(); final ui.Picture picture = recorder.endRecording();
// COMPOSITE // COMPOSITE
......
...@@ -56,12 +56,12 @@ abstract class ShaderWarmUp { ...@@ -56,12 +56,12 @@ abstract class ShaderWarmUp {
/// The size of the warm up image. /// 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 exact size shouldn't matter much as long as all draws are onscreen.
/// the target device's screen. 1024x1024 is a good choice as it is within an /// 100x100 is an arbitrary small size that's easy to fit significant draw
/// order of magnitude of most devices. /// calls onto.
/// ///
/// A custom shader warm up can override this based on targeted devices. /// 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 /// Trigger draw operations on a given canvas to warm up GPU shader
/// compilation cache. /// compilation cache.
...@@ -99,7 +99,20 @@ abstract class ShaderWarmUp { ...@@ -99,7 +99,20 @@ abstract class ShaderWarmUp {
/// issues seen so far. /// issues seen so far.
class DefaultShaderWarmUp extends ShaderWarmUp { class DefaultShaderWarmUp extends ShaderWarmUp {
/// Allow [DefaultShaderWarmUp] to be used as the default value of parameters. /// 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 /// Trigger common draw operations on a canvas to warm up GPU shader
/// compilation cache. /// compilation cache.
...@@ -157,22 +170,22 @@ class DefaultShaderWarmUp extends ShaderWarmUp { ...@@ -157,22 +170,22 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
canvas.save(); canvas.save();
for (ui.Paint paint in paints) { for (ui.Paint paint in paints) {
canvas.drawPath(paths[i], paint); canvas.drawPath(paths[i], paint);
canvas.translate(80.0, 0.0); canvas.translate(drawCallSpacing, 0.0);
} }
canvas.restore(); canvas.restore();
canvas.translate(0.0, 80.0); canvas.translate(0.0, drawCallSpacing);
} }
// Warm up shadow shaders. // Warm up shadow shaders.
const ui.Color black = ui.Color(0xFF000000); const ui.Color black = ui.Color(0xFF000000);
canvas.save(); canvas.save();
canvas.drawShadow(rrectPath, black, 10.0, true); 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.drawShadow(rrectPath, black, 10.0, false);
canvas.restore(); canvas.restore();
// Warm up text shaders. // Warm up text shaders.
canvas.translate(0.0, 80.0); canvas.translate(0.0, drawCallSpacing);
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder( final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr), ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
)..pushStyle(ui.TextStyle(color: black))..addText('_'); )..pushStyle(ui.TextStyle(color: black))..addText('_');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment