diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index ecebcccf3bc77..bd4dfb7ad3d47 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -96,149 +96,165 @@ namespace impeller { #ifdef IMPELLER_DEBUG using CheckerboardPipeline = - RenderPipelineT; + RenderPipelineHandle; #endif // IMPELLER_DEBUG using LinearGradientFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using SolidFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using RadialGradientFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using ConicalGradientFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using SweepGradientFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using LinearGradientSSBOFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using ConicalGradientSSBOFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using RadialGradientSSBOFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using SweepGradientSSBOFillPipeline = - RenderPipelineT; + RenderPipelineHandle; using RRectBlurPipeline = - RenderPipelineT; -using BlendPipeline = RenderPipelineT; + RenderPipelineHandle; +using BlendPipeline = + RenderPipelineHandle; using TexturePipeline = - RenderPipelineT; + RenderPipelineHandle; using TextureStrictSrcPipeline = - RenderPipelineT; -using PositionUVPipeline = - RenderPipelineT; + RenderPipelineHandle; +using PositionUVPipeline = RenderPipelineHandle; using TiledTexturePipeline = - RenderPipelineT; + RenderPipelineHandle; using KernelDecalPipeline = - RenderPipelineT; + RenderPipelineHandle; using KernelPipeline = - RenderPipelineT; + RenderPipelineHandle; using BorderMaskBlurPipeline = - RenderPipelineT; + RenderPipelineHandle; using MorphologyFilterPipeline = - RenderPipelineT; + RenderPipelineHandle; using ColorMatrixColorFilterPipeline = - RenderPipelineT; + RenderPipelineHandle; using LinearToSrgbFilterPipeline = - RenderPipelineT; + RenderPipelineHandle; using SrgbToLinearFilterPipeline = - RenderPipelineT; + RenderPipelineHandle; using GlyphAtlasPipeline = - RenderPipelineT; + RenderPipelineHandle; using GlyphAtlasColorPipeline = - RenderPipelineT; + RenderPipelineHandle; using PorterDuffBlendPipeline = - RenderPipelineT; -using ClipPipeline = RenderPipelineT; + RenderPipelineHandle; +using ClipPipeline = RenderPipelineHandle; using GeometryColorPipeline = - RenderPipelineT; + RenderPipelineHandle; using YUVToRGBFilterPipeline = - RenderPipelineT; + RenderPipelineHandle; // Advanced blends -using BlendColorPipeline = - RenderPipelineT; +using BlendColorPipeline = RenderPipelineHandle; using BlendColorBurnPipeline = - RenderPipelineT; + RenderPipelineHandle; using BlendColorDodgePipeline = - RenderPipelineT; -using BlendDarkenPipeline = - RenderPipelineT; + RenderPipelineHandle; +using BlendDarkenPipeline = RenderPipelineHandle; using BlendDifferencePipeline = - RenderPipelineT; + RenderPipelineHandle; using BlendExclusionPipeline = - RenderPipelineT; + RenderPipelineHandle; using BlendHardLightPipeline = - RenderPipelineT; -using BlendHuePipeline = - RenderPipelineT; -using BlendLightenPipeline = - RenderPipelineT; + RenderPipelineHandle; +using BlendHuePipeline = RenderPipelineHandle; +using BlendLightenPipeline = RenderPipelineHandle; using BlendLuminosityPipeline = - RenderPipelineT; -using BlendMultiplyPipeline = - RenderPipelineT; -using BlendOverlayPipeline = - RenderPipelineT; + RenderPipelineHandle; +using BlendMultiplyPipeline = RenderPipelineHandle; +using BlendOverlayPipeline = RenderPipelineHandle; using BlendSaturationPipeline = - RenderPipelineT; -using BlendScreenPipeline = - RenderPipelineT; + RenderPipelineHandle; +using BlendScreenPipeline = RenderPipelineHandle; using BlendSoftLightPipeline = - RenderPipelineT; + RenderPipelineHandle; // Framebuffer Advanced Blends using FramebufferBlendColorPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendColorBurnPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendColorDodgePipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendDarkenPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendDifferencePipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendExclusionPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendHardLightPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendHuePipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendLightenPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendLuminosityPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendMultiplyPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendOverlayPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendSaturationPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendScreenPipeline = - RenderPipelineT; + RenderPipelineHandle; using FramebufferBlendSoftLightPipeline = - RenderPipelineT; + RenderPipelineHandle; /// Geometry Pipelines using PointsComputeShaderPipeline = ComputePipelineBuilder; @@ -246,11 +262,12 @@ using UvComputeShaderPipeline = ComputePipelineBuilder; #ifdef IMPELLER_ENABLE_OPENGLES using TextureExternalPipeline = - RenderPipelineT; + RenderPipelineHandle; using TiledTextureExternalPipeline = - RenderPipelineT; + RenderPipelineHandle; #endif // IMPELLER_ENABLE_OPENGLES // A struct used to isolate command buffer storage from the content @@ -836,18 +853,31 @@ class ContentContext { RuntimeEffectPipelineKey::Equal> runtime_effect_pipelines_; - template + /// Holds multiple Pipelines associated with the same PipelineHandle types. + /// + /// For example, it may have multiple + /// RenderPipelineHandle + /// instances for different blend modes. From them you can access the + /// Pipeline. + /// + /// See also: + /// - impeller::ContentContextOptions - options from which variants are + /// created. + /// - impeller::Pipeline::CreateVariant + /// - impeller::RenderPipelineHandle<> - The type of objects this typically + /// contains. + template class Variants { public: Variants() = default; void Set(const ContentContextOptions& options, - std::unique_ptr pipeline) { + std::unique_ptr pipeline) { pipelines_[options] = std::move(pipeline); } void SetDefault(const ContentContextOptions& options, - std::unique_ptr pipeline) { + std::unique_ptr pipeline) { default_options_ = options; Set(options, std::move(pipeline)); } @@ -855,24 +885,24 @@ class ContentContext { void CreateDefault(const Context& context, const ContentContextOptions& options, const std::initializer_list& constants = {}) { - auto desc = - PipelineT::Builder::MakeDefaultPipelineDescriptor(context, constants); + auto desc = PipelineHandleT::Builder::MakeDefaultPipelineDescriptor( + context, constants); if (!desc.has_value()) { VALIDATION_LOG << "Failed to create default pipeline."; return; } options.ApplyToPipelineDescriptor(*desc); - SetDefault(options, std::make_unique(context, desc)); + SetDefault(options, std::make_unique(context, desc)); } - PipelineT* Get(const ContentContextOptions& options) const { + PipelineHandleT* Get(const ContentContextOptions& options) const { if (auto found = pipelines_.find(options); found != pipelines_.end()) { return found->second.get(); } return nullptr; } - PipelineT* GetDefault() const { + PipelineHandleT* GetDefault() const { if (!default_options_.has_value()) { return nullptr; } @@ -884,7 +914,7 @@ class ContentContext { private: std::optional default_options_; std::unordered_map, + std::unique_ptr, ContentContextOptions::Hash, ContentContextOptions::Equal> pipelines_; @@ -1004,9 +1034,10 @@ class ContentContext { return pipeline->WaitAndGet(); } - template - TypedPipeline* CreateIfNeeded(Variants& container, - ContentContextOptions opts) const { + template + RenderPipelineHandleT* CreateIfNeeded( + Variants& container, + ContentContextOptions opts) const { if (!IsValid()) { return nullptr; } @@ -1015,17 +1046,17 @@ class ContentContext { opts.wireframe = true; } - if (TypedPipeline* found = container.Get(opts)) { + if (RenderPipelineHandleT* found = container.Get(opts)) { return found; } - TypedPipeline* prototype = container.GetDefault(); + RenderPipelineHandleT* default_handle = container.GetDefault(); - // The prototype must always be initialized in the constructor. - FML_CHECK(prototype != nullptr); + // The default must always be initialized in the constructor. + FML_CHECK(default_handle != nullptr); std::shared_ptr> pipeline = - prototype->WaitAndGet(); + default_handle->WaitAndGet(); if (!pipeline) { return nullptr; } @@ -1037,8 +1068,8 @@ class ContentContext { desc.SetLabel( SPrintF("%s V#%zu", desc.GetLabel().c_str(), variants_count)); }); - std::unique_ptr variant = - std::make_unique(std::move(variant_future)); + std::unique_ptr variant = + std::make_unique(std::move(variant_future)); container.Set(opts, std::move(variant)); return container.Get(opts); } diff --git a/impeller/renderer/pipeline.h b/impeller/renderer/pipeline.h index 7bed0902d2b48..c6b407467c67a 100644 --- a/impeller/renderer/pipeline.h +++ b/impeller/renderer/pipeline.h @@ -88,8 +88,14 @@ PipelineFuture CreatePipelineFuture( const Context& context, std::optional desc); +/// Holds a reference to a Pipeline used for rendering while also maintaining +/// the vertex shader and fragment shader types at compile-time. +/// +/// See also: +/// - impeller::ContentContext::Variants - the typical container for +/// RenderPipelineHandles. template -class RenderPipelineT { +class RenderPipelineHandle { static_assert( ShaderStageCompatibilityChecker::Check(), "The output slots for the fragment shader don't have matches in the " @@ -100,16 +106,16 @@ class RenderPipelineT { using FragmentShader = FragmentShader_; using Builder = PipelineBuilder; - explicit RenderPipelineT(const Context& context) - : RenderPipelineT(CreatePipelineFuture( + explicit RenderPipelineHandle(const Context& context) + : RenderPipelineHandle(CreatePipelineFuture( context, Builder::MakeDefaultPipelineDescriptor(context))) {} - explicit RenderPipelineT(const Context& context, - std::optional desc) - : RenderPipelineT(CreatePipelineFuture(context, desc)) {} + explicit RenderPipelineHandle(const Context& context, + std::optional desc) + : RenderPipelineHandle(CreatePipelineFuture(context, desc)) {} - explicit RenderPipelineT(PipelineFuture future) + explicit RenderPipelineHandle(PipelineFuture future) : pipeline_future_(std::move(future)) {} std::shared_ptr> WaitAndGet() { @@ -132,28 +138,29 @@ class RenderPipelineT { std::shared_ptr> pipeline_; bool did_wait_ = false; - RenderPipelineT(const RenderPipelineT&) = delete; + RenderPipelineHandle(const RenderPipelineHandle&) = delete; - RenderPipelineT& operator=(const RenderPipelineT&) = delete; + RenderPipelineHandle& operator=(const RenderPipelineHandle&) = delete; }; template -class ComputePipelineT { +class ComputePipelineHandle { public: using ComputeShader = ComputeShader_; using Builder = ComputePipelineBuilder; - explicit ComputePipelineT(const Context& context) - : ComputePipelineT(CreatePipelineFuture( + explicit ComputePipelineHandle(const Context& context) + : ComputePipelineHandle(CreatePipelineFuture( context, Builder::MakeDefaultPipelineDescriptor(context))) {} - explicit ComputePipelineT( + explicit ComputePipelineHandle( const Context& context, std::optional compute_desc) - : ComputePipelineT(CreatePipelineFuture(context, compute_desc)) {} + : ComputePipelineHandle(CreatePipelineFuture(context, compute_desc)) {} - explicit ComputePipelineT(PipelineFuture future) + explicit ComputePipelineHandle( + PipelineFuture future) : pipeline_future_(std::move(future)) {} std::shared_ptr> WaitAndGet() { @@ -172,9 +179,9 @@ class ComputePipelineT { std::shared_ptr> pipeline_; bool did_wait_ = false; - ComputePipelineT(const ComputePipelineT&) = delete; + ComputePipelineHandle(const ComputePipelineHandle&) = delete; - ComputePipelineT& operator=(const ComputePipelineT&) = delete; + ComputePipelineHandle& operator=(const ComputePipelineHandle&) = delete; }; } // namespace impeller diff --git a/impeller/scene/scene_context.h b/impeller/scene/scene_context.h index 4c99e99867213..48ff7b8ec9458 100644 --- a/impeller/scene/scene_context.h +++ b/impeller/scene/scene_context.h @@ -125,13 +125,13 @@ class SceneContext { /// If a pipeline could not be created, returns nullptr. std::unique_ptr MakePipelineVariants(Context& context) { auto pipeline = - PipelineVariantsT>( + PipelineVariantsT>( context); if (!pipeline.IsValid()) { return nullptr; } return std::make_unique< - PipelineVariantsT>>( + PipelineVariantsT>>( std::move(pipeline)); }