-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] add additional setup method that caches more pipelines, warms internal shader code #50521
[Impeller] add additional setup method that caches more pipelines, warms internal shader code #50521
Changes from all commits
feb06b1
8b87f81
bcaccf7
ceb507d
4b2a94d
28cbe74
bfac8ef
db9f306
1999b73
8637a03
ed8638e
420900b
a7a3bd2
bc0dc3c
5858d51
4a90497
aa95c14
db4e2ed
c9ad39b
f25a1a7
3fcc074
db01e6e
6b44cda
b2a06fa
7c595cb
ada402b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
|
|
||
| #include <memory> | ||
|
|
||
| #include "fml/trace_event.h" | ||
| #include "impeller/base/strings.h" | ||
| #include "impeller/base/validation.h" | ||
| #include "impeller/core/formats.h" | ||
| #include "impeller/entity/contents/framebuffer_blend_contents.h" | ||
| #include "impeller/entity/entity.h" | ||
|
|
@@ -460,6 +462,7 @@ ContentContext::ContentContext( | |
| *context_, clip_pipeline_descriptor)); | ||
|
|
||
| is_valid_ = true; | ||
| InitializeCommonlyUsedShadersIfNeeded(); | ||
| } | ||
|
|
||
| ContentContext::~ContentContext() = default; | ||
|
|
@@ -608,4 +611,64 @@ void ContentContext::FlushCommandBuffers() const { | |
| GetContext()->GetCommandQueue()->Submit(buffers); | ||
| } | ||
|
|
||
| void ContentContext::InitializeCommonlyUsedShadersIfNeeded() const { | ||
| if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) { | ||
| // TODO(jonahwilliams): The OpenGL Embedder Unittests hang if this code | ||
| // runs. | ||
| return; | ||
| } | ||
| TRACE_EVENT0("flutter", "InitializeCommonlyUsedShadersIfNeeded"); | ||
|
|
||
| // Initialize commonly used shaders that aren't defaults. These settings were | ||
| // chosen based on the knowledge that we mix and match triangle and | ||
| // triangle-strip geometry, and also have fairly agressive srcOver to src | ||
| // blend mode conversions. | ||
| auto options = ContentContextOptions{ | ||
| .sample_count = SampleCount::kCount4, | ||
| .color_attachment_pixel_format = | ||
| context_->GetCapabilities()->GetDefaultColorFormat()}; | ||
|
|
||
| for (const auto mode : {BlendMode::kSource, BlendMode::kSourceOver}) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the proceedings of the last go/impeller-weekly, my understanding was that PSO variant construction time did not show up in traces yet. What gives for the need for this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two traces posted are also unrelated to PSO variant construction and the linked bug makes no mention of PSO variants being slow to initialize. This bit seems unrelated to the linked issue or any problem we've discussed in the past. |
||
| for (const auto geometry : | ||
| {PrimitiveType::kTriangle, PrimitiveType::kTriangleStrip}) { | ||
| options.blend_mode = mode; | ||
| options.primitive_type = geometry; | ||
| CreateIfNeeded(solid_fill_pipelines_, options); | ||
| CreateIfNeeded(texture_pipelines_, options); | ||
| if (GetContext()->GetCapabilities()->SupportsSSBO()) { | ||
| CreateIfNeeded(linear_gradient_ssbo_fill_pipelines_, options); | ||
| CreateIfNeeded(radial_gradient_ssbo_fill_pipelines_, options); | ||
| CreateIfNeeded(sweep_gradient_ssbo_fill_pipelines_, options); | ||
| CreateIfNeeded(conical_gradient_ssbo_fill_pipelines_, options); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| options.blend_mode = BlendMode::kDestination; | ||
| options.primitive_type = PrimitiveType::kTriangleStrip; | ||
| for (const auto stencil_mode : | ||
| {ContentContextOptions::StencilMode::kLegacyClipIncrement, | ||
| ContentContextOptions::StencilMode::kLegacyClipDecrement, | ||
| ContentContextOptions::StencilMode::kLegacyClipRestore}) { | ||
| options.stencil_mode = stencil_mode; | ||
| CreateIfNeeded(clip_pipelines_, options); | ||
| } | ||
|
|
||
| // On ARM devices, the initial usage of vkCmdCopyBufferToImage has been | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't completely in the dark about the reasons as to why this is happening. And we haven't fully convinced ourselves this isn't user error yet. |
||
| // observed to take 10s of ms as an internal shader is compiled to perform | ||
| // the operation. Similarly, the initial render pass can also take 10s of ms | ||
| // for a similar reason. Because the context object is initialized far | ||
| // before the first frame, create a trivial texture and render pass to force | ||
| // the driver to compiler these shaders before the frame begins. | ||
| TextureDescriptor desc; | ||
| desc.size = {1, 1}; | ||
| desc.storage_mode = StorageMode::kHostVisible; | ||
| desc.format = context_->GetCapabilities()->GetDefaultColorFormat(); | ||
| auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc); | ||
| uint32_t color = 0; | ||
| if (!texture->SetContents(reinterpret_cast<uint8_t*>(&color), 4u)) { | ||
| VALIDATION_LOG << "Failed to set bootstrap texture."; | ||
| } | ||
| } | ||
|
|
||
| } // namespace impeller | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For accuracy,
CommonlyUsedPipelinesIfNeededsince the shaders are already in their libraries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose even that isn't entirely accurate since the render pass is being initialized. lol, just
DoOneTimeVoodoo?