33 <<
" as a pipeline blend.";
45 switch (pipeline_blend) {
144 desc.SetColorAttachmentDescriptor(0u, color0);
147 desc.ClearDepthAttachment();
148 desc.ClearStencilAttachments();
151 auto maybe_stencil =
desc.GetFrontStencilAttachmentDescriptor();
152 auto maybe_depth =
desc.GetDepthStencilAttachmentDescriptor();
154 <<
"Depth attachment doesn't match expected pipeline state. "
155 "has_depth_stencil_attachments="
158 <<
"Stencil attachment doesn't match expected pipeline state. "
159 "has_depth_stencil_attachments="
161 if (maybe_stencil.has_value()) {
169 desc.SetStencilAttachmentDescriptors(front_stencil);
177 desc.SetStencilAttachmentDescriptors(front_stencil, back_stencil);
184 desc.SetStencilAttachmentDescriptors(front_stencil);
191 desc.SetStencilAttachmentDescriptors(front_stencil);
197 desc.SetStencilAttachmentDescriptors(front_stencil);
202 desc.SetStencilAttachmentDescriptors(front_stencil);
208 desc.SetStencilAttachmentDescriptors(front_stencil);
212 if (maybe_depth.has_value()) {
216 desc.SetDepthStencilAttachmentDescriptor(depth);
224template <
typename PipelineT>
227 auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
228 if (!
desc.has_value()) {
232 const auto default_color_format =
236 .color_attachment_pixel_format = default_color_format}
237 .ApplyToPipelineDescriptor(*
desc);
238 return std::make_unique<PipelineT>(context,
desc);
242 std::shared_ptr<Context> context,
243 std::shared_ptr<TypographerContext> typographer_context,
244 std::shared_ptr<RenderTargetAllocator> render_target_allocator)
245 : context_(
std::move(context)),
249#
if IMPELLER_ENABLE_3D
250 scene_context_(
std::make_shared<scene::SceneContext>(context_)),
252 render_target_cache_(render_target_allocator == nullptr
254 context_->GetResourceAllocator())
255 :
std::move(render_target_allocator)),
257 if (!context_ || !context_->IsValid()) {
266 empty_texture_ =
GetContext()->GetResourceAllocator()->CreateTexture(
desc);
268 auto cmd_buffer =
GetContext()->CreateCommandBuffer();
269 auto blit_pass = cmd_buffer->CreateBlitPass();
274 if (!blit_pass->EncodeCommands(
GetContext()->GetResourceAllocator()) ||
277 ->Submit({std::move(cmd_buffer)})
285 .color_attachment_pixel_format =
286 context_->GetCapabilities()->GetDefaultColorFormat()};
290 .color_attachment_pixel_format =
291 context_->GetCapabilities()->GetDefaultColorFormat()};
292 const auto supports_decal =
static_cast<Scalar>(
293 context_->GetCapabilities()->SupportsDecalSamplerAddressMode());
296 solid_fill_pipelines_.CreateDefault(*context_,
options);
297 texture_pipelines_.CreateDefault(*context_,
options);
298 fast_gradient_pipelines_.CreateDefault(*context_,
options);
300 if (context_->GetCapabilities()->SupportsSSBO()) {
301 linear_gradient_ssbo_fill_pipelines_.CreateDefault(*context_,
options);
302 radial_gradient_ssbo_fill_pipelines_.CreateDefault(*context_,
options);
303 conical_gradient_ssbo_fill_pipelines_.CreateDefault(*context_,
options);
304 sweep_gradient_ssbo_fill_pipelines_.CreateDefault(*context_,
options);
306 linear_gradient_fill_pipelines_.CreateDefault(*context_,
options);
307 radial_gradient_fill_pipelines_.CreateDefault(*context_,
options);
308 conical_gradient_fill_pipelines_.CreateDefault(*context_,
options);
309 sweep_gradient_fill_pipelines_.CreateDefault(*context_,
options);
314 auto clip_pipeline_descriptor =
316 if (!clip_pipeline_descriptor.has_value()) {
321 .color_attachment_pixel_format =
322 context_->GetCapabilities()->GetDefaultColorFormat()}
323 .ApplyToPipelineDescriptor(*clip_pipeline_descriptor);
325 auto clip_color_attachments =
326 clip_pipeline_descriptor->GetColorAttachmentDescriptors();
327 for (
auto& color_attachment : clip_color_attachments) {
330 clip_pipeline_descriptor->SetColorAttachmentDescriptors(
331 std::move(clip_color_attachments));
332 clip_pipelines_.SetDefault(
334 std::make_unique<ClipPipeline>(*context_, clip_pipeline_descriptor));
337 if (context_->GetCapabilities()->SupportsFramebufferFetch()) {
338 framebuffer_blend_color_pipelines_.CreateDefault(
339 *context_, options_trianglestrip,
341 framebuffer_blend_colorburn_pipelines_.CreateDefault(
342 *context_, options_trianglestrip,
344 framebuffer_blend_colordodge_pipelines_.CreateDefault(
345 *context_, options_trianglestrip,
347 framebuffer_blend_darken_pipelines_.CreateDefault(
348 *context_, options_trianglestrip,
350 framebuffer_blend_difference_pipelines_.CreateDefault(
351 *context_, options_trianglestrip,
353 framebuffer_blend_exclusion_pipelines_.CreateDefault(
354 *context_, options_trianglestrip,
356 framebuffer_blend_hardlight_pipelines_.CreateDefault(
357 *context_, options_trianglestrip,
359 framebuffer_blend_hue_pipelines_.CreateDefault(
360 *context_, options_trianglestrip,
362 framebuffer_blend_lighten_pipelines_.CreateDefault(
363 *context_, options_trianglestrip,
365 framebuffer_blend_luminosity_pipelines_.CreateDefault(
366 *context_, options_trianglestrip,
368 framebuffer_blend_multiply_pipelines_.CreateDefault(
369 *context_, options_trianglestrip,
371 framebuffer_blend_overlay_pipelines_.CreateDefault(
372 *context_, options_trianglestrip,
374 framebuffer_blend_saturation_pipelines_.CreateDefault(
375 *context_, options_trianglestrip,
377 framebuffer_blend_screen_pipelines_.CreateDefault(
378 *context_, options_trianglestrip,
380 framebuffer_blend_softlight_pipelines_.CreateDefault(
381 *context_, options_trianglestrip,
384 blend_color_pipelines_.CreateDefault(
385 *context_, options_trianglestrip,
387 blend_colorburn_pipelines_.CreateDefault(
388 *context_, options_trianglestrip,
390 blend_colordodge_pipelines_.CreateDefault(
391 *context_, options_trianglestrip,
393 blend_darken_pipelines_.CreateDefault(
394 *context_, options_trianglestrip,
396 blend_difference_pipelines_.CreateDefault(
397 *context_, options_trianglestrip,
399 blend_exclusion_pipelines_.CreateDefault(
400 *context_, options_trianglestrip,
402 blend_hardlight_pipelines_.CreateDefault(
403 *context_, options_trianglestrip,
405 blend_hue_pipelines_.CreateDefault(
406 *context_, options_trianglestrip,
408 blend_lighten_pipelines_.CreateDefault(
409 *context_, options_trianglestrip,
411 blend_luminosity_pipelines_.CreateDefault(
412 *context_, options_trianglestrip,
414 blend_multiply_pipelines_.CreateDefault(
415 *context_, options_trianglestrip,
417 blend_overlay_pipelines_.CreateDefault(
418 *context_, options_trianglestrip,
420 blend_saturation_pipelines_.CreateDefault(
421 *context_, options_trianglestrip,
423 blend_screen_pipelines_.CreateDefault(
424 *context_, options_trianglestrip,
426 blend_softlight_pipelines_.CreateDefault(
427 *context_, options_trianglestrip,
431 rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
432 texture_strict_src_pipelines_.CreateDefault(*context_,
options);
433 tiled_texture_pipelines_.CreateDefault(*context_,
options, {supports_decal});
434 gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip,
436 border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
437 morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip,
439 color_matrix_color_filter_pipelines_.CreateDefault(*context_,
440 options_trianglestrip);
441 linear_to_srgb_filter_pipelines_.CreateDefault(*context_,
442 options_trianglestrip);
443 srgb_to_linear_filter_pipelines_.CreateDefault(*context_,
444 options_trianglestrip);
445 glyph_atlas_pipelines_.CreateDefault(
448 GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
450 yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip);
451 porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
453 vertices_uber_shader_.CreateDefault(*context_,
options, {supports_decal});
455#if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX)
457 tiled_texture_external_pipelines_.CreateDefault(*context_,
options);
462 InitializeCommonlyUsedShadersIfNeeded();
472 return empty_texture_;
476 std::string_view label,
478 const std::shared_ptr<CommandBuffer>& command_buffer,
481 bool depth_stencil_enabled,
482 int32_t mip_count)
const {
483 const std::shared_ptr<Context>& context =
GetContext();
486 std::optional<RenderTarget::AttachmentConfig> depth_stencil_config =
488 : std::optional<RenderTarget::AttachmentConfig>();
490 if (context->GetCapabilities()->SupportsOffscreenMSAA() && msaa_enabled) {
492 *context, texture_size,
493 mip_count,
SPrintF(
"%s Offscreen", label.data()),
497 *context, texture_size,
498 mip_count,
SPrintF(
"%s Offscreen", label.data()),
501 return MakeSubpass(label, subpass_target, command_buffer, subpass_callback);
505 std::string_view label,
507 const std::shared_ptr<CommandBuffer>& command_buffer,
509 const std::shared_ptr<Context>& context =
GetContext();
512 if (!subpass_texture) {
516 auto sub_renderpass = command_buffer->CreateRenderPass(subpass_target);
517 if (!sub_renderpass) {
520 sub_renderpass->SetLabel(
SPrintF(
"%s RenderPass", label.data()));
522 if (!subpass_callback(*
this, *sub_renderpass)) {
526 if (!sub_renderpass->EncodeCommands()) {
530 const std::shared_ptr<Texture>& target_texture =
532 if (target_texture->GetMipCount() > 1) {
535 if (!mipmap_status.
ok()) {
536 return mipmap_status;
540 return subpass_target;
543#if IMPELLER_ENABLE_3D
544std::shared_ptr<scene::SceneContext> ContentContext::GetSceneContext()
const {
545 return scene_context_;
558 return *context_->GetCapabilities();
562 wireframe_ = wireframe;
565std::shared_ptr<Pipeline<PipelineDescriptor>>
567 const std::string& unique_entrypoint_name,
570 create_callback)
const {
571 RuntimeEffectPipelineKey
key{unique_entrypoint_name,
options};
572 auto it = runtime_effect_pipelines_.find(
key);
573 if (it == runtime_effect_pipelines_.end()) {
574 it = runtime_effect_pipelines_.insert(it, {
key, create_callback()});
580 const std::string& unique_entrypoint_name)
const {
581 for (
auto it = runtime_effect_pipelines_.begin();
582 it != runtime_effect_pipelines_.end();) {
583 if (it->first.unique_entrypoint_name == unique_entrypoint_name) {
584 it = runtime_effect_pipelines_.erase(it);
591void ContentContext::InitializeCommonlyUsedShadersIfNeeded()
const {
592 TRACE_EVENT0(
"flutter",
"InitializeCommonlyUsedShadersIfNeeded");
593 GetContext()->InitializeCommonlyUsedShadersIfNeeded();
static sk_sp< Effect > Create()
static bool ok(int result)
void ClearCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name) const
std::shared_ptr< Tessellator > GetTessellator() const
std::shared_ptr< Texture > GetEmptyTexture() const
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
ContentContext(std::shared_ptr< Context > context, std::shared_ptr< TypographerContext > typographer_context, std::shared_ptr< RenderTargetAllocator > render_target_allocator=nullptr)
fml::StatusOr< RenderTarget > MakeSubpass(std::string_view label, ISize texture_size, const std::shared_ptr< CommandBuffer > &command_buffer, const SubpassCallback &subpass_callback, bool msaa_enabled=true, bool depth_stencil_enabled=false, int32_t mip_count=1) const
Creates a new texture of size texture_size and calls subpass_callback with a RenderPass for drawing t...
const Capabilities & GetDeviceCapabilities() const
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
void SetWireframe(bool wireframe)
std::shared_ptr< Pipeline< PipelineDescriptor > > GetCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name, const ContentContextOptions &options, const std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >()> &create_callback) const
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
std::shared_ptr< Context > GetContext() const
To do anything rendering related with Impeller, you need a context.
virtual const std::shared_ptr< const Capabilities > & GetCapabilities() const =0
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
static constexpr BlendMode kLastPipelineBlendMode
An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame...
std::shared_ptr< Texture > GetRenderTargetTexture() const
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
Dart_NativeFunction function
@ kOneMinusDestinationAlpha
std::string SPrintF(const char *format,...)
@ kEqual
Comparison test passes if new_value == current_value.
@ kAlways
Comparison test passes always passes.
@ kLess
Comparison test passes if new_value < current_value.
@ kNotEqual
Comparison test passes if new_value != current_value.
fml::Status AddMipmapGeneration(const std::shared_ptr< CommandBuffer > &command_buffer, const std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
Adds a blit command to the render pass.
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
@ kSetToReferenceValue
Reset the stencil value to the reference value.
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
@ kKeep
Don't modify the current stencil value.
static std::unique_ptr< PipelineT > CreateDefaultPipeline(const Context &context)
Describe the color attachment that will be used with this pipeline.
BlendOperation color_blend_op
BlendFactor dst_color_blend_factor
ColorWriteMask write_mask
BlendFactor src_alpha_blend_factor
BlendOperation alpha_blend_op
BlendFactor src_color_blend_factor
BlendFactor dst_alpha_blend_factor
constexpr std::array< uint8_t, 4 > ToR8G8B8A8() const
Convert to R8G8B8A8 representation.
static constexpr Color BlackTransparent()
PrimitiveType primitive_type
bool has_depth_stencil_attachments
void ApplyToPipelineDescriptor(PipelineDescriptor &desc) const
PixelFormat color_attachment_pixel_format
@ kOverdrawPreventionRestore
@ kOverdrawPreventionIncrement
bool is_for_rrect_blur_clear
CompareFunction depth_compare
CompareFunction depth_compare
static std::optional< PipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context, const std::vector< Scalar > &constants={})
Create a default pipeline descriptor using the combination reflected shader information....
StencilOperation stencil_failure
CompareFunction stencil_compare
StencilOperation depth_stencil_pass
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)