From 3ba752d77737d817783eba87a5b1c0b3402f2d8a Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 6 Dec 2024 09:44:47 -0800 Subject: [PATCH 1/6] [Impeller] ptrs baby. --- .../entity/contents/color_source_contents.h | 3 +- impeller/entity/contents/content_context.cc | 4 +- impeller/entity/contents/content_context.h | 180 +++++++++--------- .../contents/filters/blend_filter_contents.cc | 4 +- .../contents/test/recording_render_pass.cc | 2 +- .../contents/test/recording_render_pass.h | 3 +- impeller/entity/entity_unittests.cc | 8 +- .../playground/imgui/imgui_impl_impeller.cc | 2 +- .../renderer/backend/metal/render_pass_mtl.h | 3 +- .../renderer/backend/metal/render_pass_mtl.mm | 3 +- .../renderer/backend/vulkan/render_pass_vk.cc | 5 +- .../renderer/backend/vulkan/render_pass_vk.h | 3 +- impeller/renderer/command.h | 2 +- impeller/renderer/render_pass.cc | 3 +- impeller/renderer/render_pass.h | 3 +- impeller/renderer/renderer_dart_unittests.cc | 2 +- impeller/renderer/renderer_unittests.cc | 38 ++-- lib/gpu/render_pass.cc | 2 +- 18 files changed, 131 insertions(+), 139 deletions(-) diff --git a/impeller/entity/contents/color_source_contents.h b/impeller/entity/contents/color_source_contents.h index 76a49ffe4a1db..d7886f03723f2 100644 --- a/impeller/entity/contents/color_source_contents.h +++ b/impeller/entity/contents/color_source_contents.h @@ -104,8 +104,7 @@ class ColorSourceContents : public Contents { using PipelineBuilderMethod = std::shared_ptr> ( impeller::ContentContext::*)(ContentContextOptions) const; using PipelineBuilderCallback = - std::function>( - ContentContextOptions)>; + std::function*(ContentContextOptions)>; using CreateGeometryCallback = std::function> +const Pipeline* ContentContext::GetCachedRuntimeEffectPipeline( const std::string& unique_entrypoint_name, const ContentContextOptions& options, @@ -580,7 +580,7 @@ ContentContext::GetCachedRuntimeEffectPipeline( if (it == runtime_effect_pipelines_.end()) { it = runtime_effect_pipelines_.insert(it, {key, create_callback()}); } - return it->second; + return it->second.get(); } void ContentContext::ClearCachedRuntimeEffectPipeline( diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 0cfb4a2623e3e..b086df2ca601c 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -377,102 +377,102 @@ class ContentContext { Tessellator& GetTessellator() const; - std::shared_ptr> GetFastGradientPipeline( + const Pipeline* GetFastGradientPipeline( ContentContextOptions opts) const { return GetPipeline(fast_gradient_pipelines_, opts); } - std::shared_ptr> GetLinearGradientFillPipeline( + const Pipeline* GetLinearGradientFillPipeline( ContentContextOptions opts) const { return GetPipeline(linear_gradient_fill_pipelines_, opts); } - std::shared_ptr> - GetLinearGradientUniformFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetLinearGradientUniformFillPipeline( + ContentContextOptions opts) const { return GetPipeline(linear_gradient_uniform_fill_pipelines_, opts); } - std::shared_ptr> - GetRadialGradientUniformFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetRadialGradientUniformFillPipeline( + ContentContextOptions opts) const { return GetPipeline(radial_gradient_uniform_fill_pipelines_, opts); } - std::shared_ptr> - GetConicalGradientUniformFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetConicalGradientUniformFillPipeline( + ContentContextOptions opts) const { return GetPipeline(conical_gradient_uniform_fill_pipelines_, opts); } - std::shared_ptr> - GetSweepGradientUniformFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetSweepGradientUniformFillPipeline( + ContentContextOptions opts) const { return GetPipeline(sweep_gradient_uniform_fill_pipelines_, opts); } - std::shared_ptr> - GetLinearGradientSSBOFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetLinearGradientSSBOFillPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(linear_gradient_ssbo_fill_pipelines_, opts); } - std::shared_ptr> - GetRadialGradientSSBOFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetRadialGradientSSBOFillPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(radial_gradient_ssbo_fill_pipelines_, opts); } - std::shared_ptr> - GetConicalGradientSSBOFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetConicalGradientSSBOFillPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(conical_gradient_ssbo_fill_pipelines_, opts); } - std::shared_ptr> - GetSweepGradientSSBOFillPipeline(ContentContextOptions opts) const { + const Pipeline* GetSweepGradientSSBOFillPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(sweep_gradient_ssbo_fill_pipelines_, opts); } - std::shared_ptr> GetRadialGradientFillPipeline( + const Pipeline* GetRadialGradientFillPipeline( ContentContextOptions opts) const { return GetPipeline(radial_gradient_fill_pipelines_, opts); } - std::shared_ptr> GetConicalGradientFillPipeline( + const Pipeline* GetConicalGradientFillPipeline( ContentContextOptions opts) const { return GetPipeline(conical_gradient_fill_pipelines_, opts); } - std::shared_ptr> GetRRectBlurPipeline( + const Pipeline* GetRRectBlurPipeline( ContentContextOptions opts) const { return GetPipeline(rrect_blur_pipelines_, opts); } - std::shared_ptr> GetSweepGradientFillPipeline( + const Pipeline* GetSweepGradientFillPipeline( ContentContextOptions opts) const { return GetPipeline(sweep_gradient_fill_pipelines_, opts); } - std::shared_ptr> GetSolidFillPipeline( + const Pipeline* GetSolidFillPipeline( ContentContextOptions opts) const { return GetPipeline(solid_fill_pipelines_, opts); } - std::shared_ptr> GetTexturePipeline( + const Pipeline* GetTexturePipeline( ContentContextOptions opts) const { return GetPipeline(texture_pipelines_, opts); } - std::shared_ptr> GetTextureStrictSrcPipeline( + const Pipeline* GetTextureStrictSrcPipeline( ContentContextOptions opts) const { return GetPipeline(texture_strict_src_pipelines_, opts); } #ifdef IMPELLER_ENABLE_OPENGLES - std::shared_ptr> - GetDownsampleTextureGlesPipeline(ContentContextOptions opts) const { + const Pipeline* GetDownsampleTextureGlesPipeline( + ContentContextOptions opts) const { return GetPipeline(texture_downsample_gles_pipelines_, opts); } - std::shared_ptr> GetTiledTextureExternalPipeline( + const Pipeline* GetTiledTextureExternalPipeline( ContentContextOptions opts) const { FML_DCHECK(GetContext()->GetBackendType() == Context::BackendType::kOpenGLES); @@ -480,235 +480,235 @@ class ContentContext { } #endif // IMPELLER_ENABLE_OPENGLES - std::shared_ptr> GetTiledTexturePipeline( + const Pipeline* GetTiledTexturePipeline( ContentContextOptions opts) const { return GetPipeline(tiled_texture_pipelines_, opts); } - std::shared_ptr> GetGaussianBlurPipeline( + const Pipeline* GetGaussianBlurPipeline( ContentContextOptions opts) const { return GetPipeline(gaussian_blur_pipelines_, opts); } - std::shared_ptr> GetBorderMaskBlurPipeline( + const Pipeline* GetBorderMaskBlurPipeline( ContentContextOptions opts) const { return GetPipeline(border_mask_blur_pipelines_, opts); } - std::shared_ptr> GetMorphologyFilterPipeline( + const Pipeline* GetMorphologyFilterPipeline( ContentContextOptions opts) const { return GetPipeline(morphology_filter_pipelines_, opts); } - std::shared_ptr> - GetColorMatrixColorFilterPipeline(ContentContextOptions opts) const { + const Pipeline* GetColorMatrixColorFilterPipeline( + ContentContextOptions opts) const { return GetPipeline(color_matrix_color_filter_pipelines_, opts); } - std::shared_ptr> GetLinearToSrgbFilterPipeline( + const Pipeline* GetLinearToSrgbFilterPipeline( ContentContextOptions opts) const { return GetPipeline(linear_to_srgb_filter_pipelines_, opts); } - std::shared_ptr> GetSrgbToLinearFilterPipeline( + const Pipeline* GetSrgbToLinearFilterPipeline( ContentContextOptions opts) const { return GetPipeline(srgb_to_linear_filter_pipelines_, opts); } - std::shared_ptr> GetClipPipeline( + const Pipeline* GetClipPipeline( ContentContextOptions opts) const { return GetPipeline(clip_pipelines_, opts); } - std::shared_ptr> GetGlyphAtlasPipeline( + const Pipeline* GetGlyphAtlasPipeline( ContentContextOptions opts) const { return GetPipeline(glyph_atlas_pipelines_, opts); } - std::shared_ptr> GetYUVToRGBFilterPipeline( + const Pipeline* GetYUVToRGBFilterPipeline( ContentContextOptions opts) const { return GetPipeline(yuv_to_rgb_filter_pipelines_, opts); } - std::shared_ptr> GetPorterDuffBlendPipeline( + const Pipeline* GetPorterDuffBlendPipeline( ContentContextOptions opts) const { return GetPipeline(porter_duff_blend_pipelines_, opts); } // Advanced blends. - std::shared_ptr> GetBlendColorPipeline( + const Pipeline* GetBlendColorPipeline( ContentContextOptions opts) const { return GetPipeline(blend_color_pipelines_, opts); } - std::shared_ptr> GetBlendColorBurnPipeline( + const Pipeline* GetBlendColorBurnPipeline( ContentContextOptions opts) const { return GetPipeline(blend_colorburn_pipelines_, opts); } - std::shared_ptr> GetBlendColorDodgePipeline( + const Pipeline* GetBlendColorDodgePipeline( ContentContextOptions opts) const { return GetPipeline(blend_colordodge_pipelines_, opts); } - std::shared_ptr> GetBlendDarkenPipeline( + const Pipeline* GetBlendDarkenPipeline( ContentContextOptions opts) const { return GetPipeline(blend_darken_pipelines_, opts); } - std::shared_ptr> GetBlendDifferencePipeline( + const Pipeline* GetBlendDifferencePipeline( ContentContextOptions opts) const { return GetPipeline(blend_difference_pipelines_, opts); } - std::shared_ptr> GetBlendExclusionPipeline( + const Pipeline* GetBlendExclusionPipeline( ContentContextOptions opts) const { return GetPipeline(blend_exclusion_pipelines_, opts); } - std::shared_ptr> GetBlendHardLightPipeline( + const Pipeline* GetBlendHardLightPipeline( ContentContextOptions opts) const { return GetPipeline(blend_hardlight_pipelines_, opts); } - std::shared_ptr> GetBlendHuePipeline( + const Pipeline* GetBlendHuePipeline( ContentContextOptions opts) const { return GetPipeline(blend_hue_pipelines_, opts); } - std::shared_ptr> GetBlendLightenPipeline( + const Pipeline* GetBlendLightenPipeline( ContentContextOptions opts) const { return GetPipeline(blend_lighten_pipelines_, opts); } - std::shared_ptr> GetBlendLuminosityPipeline( + const Pipeline* GetBlendLuminosityPipeline( ContentContextOptions opts) const { return GetPipeline(blend_luminosity_pipelines_, opts); } - std::shared_ptr> GetBlendMultiplyPipeline( + const Pipeline* GetBlendMultiplyPipeline( ContentContextOptions opts) const { return GetPipeline(blend_multiply_pipelines_, opts); } - std::shared_ptr> GetBlendOverlayPipeline( + const Pipeline* GetBlendOverlayPipeline( ContentContextOptions opts) const { return GetPipeline(blend_overlay_pipelines_, opts); } - std::shared_ptr> GetBlendSaturationPipeline( + const Pipeline* GetBlendSaturationPipeline( ContentContextOptions opts) const { return GetPipeline(blend_saturation_pipelines_, opts); } - std::shared_ptr> GetBlendScreenPipeline( + const Pipeline* GetBlendScreenPipeline( ContentContextOptions opts) const { return GetPipeline(blend_screen_pipelines_, opts); } - std::shared_ptr> GetBlendSoftLightPipeline( + const Pipeline* GetBlendSoftLightPipeline( ContentContextOptions opts) const { return GetPipeline(blend_softlight_pipelines_, opts); } - std::shared_ptr> GetDownsamplePipeline( + const Pipeline* GetDownsamplePipeline( ContentContextOptions opts) const { return GetPipeline(texture_downsample_pipelines_, opts); } // Framebuffer Advanced Blends - std::shared_ptr> - GetFramebufferBlendColorPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendColorPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_color_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendColorBurnPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendColorBurnPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_colorburn_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendColorDodgePipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendColorDodgePipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_colordodge_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendDarkenPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendDarkenPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_darken_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendDifferencePipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendDifferencePipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_difference_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendExclusionPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendExclusionPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_exclusion_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendHardLightPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendHardLightPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_hardlight_pipelines_, opts); } - std::shared_ptr> GetFramebufferBlendHuePipeline( + const Pipeline* GetFramebufferBlendHuePipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_hue_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendLightenPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendLightenPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_lighten_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendLuminosityPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendLuminosityPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_luminosity_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendMultiplyPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendMultiplyPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_multiply_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendOverlayPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendOverlayPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_overlay_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendSaturationPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendSaturationPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_saturation_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendScreenPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendScreenPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_screen_pipelines_, opts); } - std::shared_ptr> - GetFramebufferBlendSoftLightPipeline(ContentContextOptions opts) const { + const Pipeline* GetFramebufferBlendSoftLightPipeline( + ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_softlight_pipelines_, opts); } - std::shared_ptr> GetDrawVerticesUberShader( + const Pipeline* GetDrawVerticesUberShader( ContentContextOptions opts) const { return GetPipeline(vertices_uber_shader_, opts); } @@ -761,7 +761,7 @@ class ContentContext { /// /// The create_callback is synchronously invoked exactly once if a cached /// pipeline is not found. - std::shared_ptr> GetCachedRuntimeEffectPipeline( + const Pipeline* GetCachedRuntimeEffectPipeline( const std::string& unique_entrypoint_name, const ContentContextOptions& options, const std::function>()>& @@ -992,14 +992,14 @@ class ContentContext { mutable Variants vertices_uber_shader_; template - std::shared_ptr> GetPipeline( + const Pipeline* GetPipeline( Variants& container, ContentContextOptions opts) const { TypedPipeline* pipeline = CreateIfNeeded(container, opts); if (!pipeline) { return nullptr; } - return pipeline->WaitAndGet(); + return pipeline->WaitAndGet().get(); } template @@ -1023,7 +1023,7 @@ class ContentContext { // The default must always be initialized in the constructor. FML_CHECK(default_handle != nullptr); - std::shared_ptr> pipeline = + const std::shared_ptr>& pipeline = default_handle->WaitAndGet(); if (!pipeline) { return nullptr; diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index b427de9ab76e6..1580dc70087bc 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -71,7 +71,7 @@ BlendFilterContents::BlendFilterContents() { BlendFilterContents::~BlendFilterContents() = default; -using PipelineProc = std::shared_ptr> ( +using PipelineProc = const Pipeline* ( ContentContext::*)(ContentContextOptions) const; template @@ -170,7 +170,7 @@ static std::optional AdvancedBlend( auto options = OptionsFromPass(pass); options.primitive_type = PrimitiveType::kTriangleStrip; options.blend_mode = BlendMode::kSource; - std::shared_ptr> pipeline = + const Pipeline* pipeline = std::invoke(pipeline_proc, renderer, options); #ifdef IMPELLER_DEBUG diff --git a/impeller/entity/contents/test/recording_render_pass.cc b/impeller/entity/contents/test/recording_render_pass.cc index 9d7877e1a173d..c52f575a23083 100644 --- a/impeller/entity/contents/test/recording_render_pass.cc +++ b/impeller/entity/contents/test/recording_render_pass.cc @@ -16,7 +16,7 @@ RecordingRenderPass::RecordingRenderPass( // |RenderPass| void RecordingRenderPass::SetPipeline( - const std::shared_ptr>& pipeline) { + const Pipeline* pipeline) { pending_.pipeline = pipeline; if (delegate_) { delegate_->SetPipeline(pipeline); diff --git a/impeller/entity/contents/test/recording_render_pass.h b/impeller/entity/contents/test/recording_render_pass.h index 3fb9b34d344e1..4b7773b1b2789 100644 --- a/impeller/entity/contents/test/recording_render_pass.h +++ b/impeller/entity/contents/test/recording_render_pass.h @@ -20,8 +20,7 @@ class RecordingRenderPass : public RenderPass { const std::vector& GetCommands() const override { return commands_; } // |RenderPass| - void SetPipeline( - const std::shared_ptr>& pipeline) override; + void SetPipeline(const Pipeline* pipeline) override; void SetCommandLabel(std::string_view label) override; diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index ed4af453c0c32..8a932e54fffc0 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -1696,7 +1696,7 @@ TEST_P(EntityTest, RuntimeEffect) { ASSERT_TRUE(runtime_stage->IsDirty()); bool expect_dirty = true; - Pipeline* first_pipeline; + const Pipeline* first_pipeline; std::unique_ptr geom = Geometry::MakeCover(); auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { @@ -1723,10 +1723,10 @@ TEST_P(EntityTest, RuntimeEffect) { bool result = contents->Render(context, entity, pass); if (expect_dirty) { - EXPECT_NE(first_pipeline, pass.GetCommands().back().pipeline.get()); - first_pipeline = pass.GetCommands().back().pipeline.get(); + EXPECT_NE(first_pipeline, pass.GetCommands().back().pipeline); + first_pipeline = pass.GetCommands().back().pipeline; } else { - EXPECT_EQ(pass.GetCommands().back().pipeline.get(), first_pipeline); + EXPECT_EQ(pass.GetCommands().back().pipeline, first_pipeline); } expect_dirty = false; diff --git a/impeller/playground/imgui/imgui_impl_impeller.cc b/impeller/playground/imgui/imgui_impl_impeller.cc index caf346c8bcf38..d154376b283e3 100644 --- a/impeller/playground/imgui/imgui_impl_impeller.cc +++ b/impeller/playground/imgui/imgui_impl_impeller.cc @@ -256,7 +256,7 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data, "ImGui draw list %d (command %d)", draw_list_i, cmd_i)); render_pass.SetViewport(viewport); render_pass.SetScissor(impeller::IRect::RoundOut(clip_rect)); - render_pass.SetPipeline(bd->pipeline); + render_pass.SetPipeline(bd->pipeline.get()); VS::BindUniformBuffer(render_pass, vtx_uniforms); FS::BindTex(render_pass, bd->font_texture, bd->sampler); diff --git a/impeller/renderer/backend/metal/render_pass_mtl.h b/impeller/renderer/backend/metal/render_pass_mtl.h index ee244ce1e92b6..2ba619d78d08a 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.h +++ b/impeller/renderer/backend/metal/render_pass_mtl.h @@ -58,8 +58,7 @@ class RenderPassMTL final : public RenderPass { bool OnEncodeCommands(const Context& context) const override; // |RenderPass| - void SetPipeline( - const std::shared_ptr>& pipeline) override; + void SetPipeline(const Pipeline* pipeline) override; // |RenderPass| void SetCommandLabel(std::string_view label) override; diff --git a/impeller/renderer/backend/metal/render_pass_mtl.mm b/impeller/renderer/backend/metal/render_pass_mtl.mm index 203e97e36ec90..0ce7ea1fea38a 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -233,8 +233,7 @@ static bool Bind(PassBindingsCacheMTL& pass, } // |RenderPass| -void RenderPassMTL::SetPipeline( - const std::shared_ptr>& pipeline) { +void RenderPassMTL::SetPipeline(const Pipeline* pipeline) { const PipelineDescriptor& pipeline_desc = pipeline->GetDescriptor(); primitive_type_ = pipeline_desc.GetPrimitiveType(); pass_bindings_.SetRenderPipelineState( diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index f8a169adfb670..be95f0b209cd2 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -293,9 +293,8 @@ SharedHandleVK RenderPassVK::CreateVKFramebuffer( } // |RenderPass| -void RenderPassVK::SetPipeline( - const std::shared_ptr>& pipeline) { - pipeline_ = pipeline.get(); +void RenderPassVK::SetPipeline(const Pipeline* pipeline) { + pipeline_ = pipeline; if (!pipeline_) { return; } diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index d442e08882cd2..b4ea45ae3f14a 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -58,8 +58,7 @@ class RenderPassVK final : public RenderPass { std::shared_ptr command_buffer); // |RenderPass| - void SetPipeline( - const std::shared_ptr>& pipeline) override; + void SetPipeline(const Pipeline* pipeline) override; // |RenderPass| void SetCommandLabel(std::string_view label) override; diff --git a/impeller/renderer/command.h b/impeller/renderer/command.h index 13ee5663171e0..528efd4430343 100644 --- a/impeller/renderer/command.h +++ b/impeller/renderer/command.h @@ -81,7 +81,7 @@ struct Command { //---------------------------------------------------------------------------- /// The pipeline to use for this command. /// - std::shared_ptr> pipeline; + const Pipeline* pipeline; /// An offset into render pass storage where bound buffers/texture metadata is /// stored. diff --git a/impeller/renderer/render_pass.cc b/impeller/renderer/render_pass.cc index e498589021cde..956218921b1e2 100644 --- a/impeller/renderer/render_pass.cc +++ b/impeller/renderer/render_pass.cc @@ -81,8 +81,7 @@ const std::shared_ptr& RenderPass::GetContext() const { return context_; } -void RenderPass::SetPipeline( - const std::shared_ptr>& pipeline) { +void RenderPass::SetPipeline(const Pipeline* pipeline) { pending_.pipeline = pipeline; } diff --git a/impeller/renderer/render_pass.h b/impeller/renderer/render_pass.h index 2ef60aecf1cfe..4f0dded813637 100644 --- a/impeller/renderer/render_pass.h +++ b/impeller/renderer/render_pass.h @@ -45,8 +45,7 @@ class RenderPass : public ResourceBinder { //---------------------------------------------------------------------------- /// The pipeline to use for this command. - virtual void SetPipeline( - const std::shared_ptr>& pipeline); + virtual void SetPipeline(const Pipeline* pipeline); //---------------------------------------------------------------------------- /// The debugging label to use for the command. diff --git a/impeller/renderer/renderer_dart_unittests.cc b/impeller/renderer/renderer_dart_unittests.cc index 3368ae759e742..463c0cd514c9f 100644 --- a/impeller/renderer/renderer_dart_unittests.cc +++ b/impeller/renderer/renderer_dart_unittests.cc @@ -235,7 +235,7 @@ class RendererDartTest : public PlaygroundTest, TextureVS::BindUniformBuffer(pass, buffer->EmplaceUniform(uniforms)); TextureFS::BindTextureContents(pass, texture, sampler); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); if (!pass.Draw().ok()) { return false; diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index 0e84ea50cfd17..f98e7fd622dcb 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -93,7 +93,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { assert(pipeline && pipeline->IsValid()); pass.SetCommandLabel("Box"); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetVertexBuffer( vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator())); @@ -160,7 +160,7 @@ TEST_P(RendererTest, BabysFirstTriangle) { *context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetVertexBuffer(vertex_buffer); FS::FragInfo frag_info; @@ -255,7 +255,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { ImGui::End(); pass.SetCommandLabel("Perspective Cube"); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); std::array vertex_buffers = { BufferView(device_buffer, @@ -330,7 +330,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { for (size_t i = 0; i < 1; i++) { for (size_t j = 0; j < 1; j++) { pass.SetCommandLabel("Box"); - pass.SetPipeline(box_pipeline); + pass.SetPipeline(box_pipeline.get()); pass.SetVertexBuffer(vertex_buffer); FS::FrameInfo frame_info; @@ -445,7 +445,7 @@ TEST_P(RendererTest, CanRenderToTexture) { } r2t_pass->SetCommandLabel("Box"); - r2t_pass->SetPipeline(box_pipeline); + r2t_pass->SetPipeline(box_pipeline.get()); r2t_pass->SetVertexBuffer(vertex_buffer); FS::FrameInfo frame_info; @@ -504,7 +504,7 @@ TEST_P(RendererTest, CanRenderInstanced) { auto host_buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter()); ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool { - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetCommandLabel("InstancedDraw"); VS::FrameInfo frame_info; @@ -605,7 +605,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image"); - pass->SetPipeline(mipmaps_pipeline); + pass->SetPipeline(mipmaps_pipeline.get()); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -728,7 +728,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image"); - pass->SetPipeline(mipmaps_pipeline); + pass->SetPipeline(mipmaps_pipeline.get()); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -855,7 +855,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image LOD"); - pass->SetPipeline(mipmaps_pipeline); + pass->SetPipeline(mipmaps_pipeline.get()); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -923,7 +923,7 @@ TEST_P(RendererTest, TheImpeller) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetCommandLabel("Impeller SDF scene"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -987,7 +987,7 @@ TEST_P(RendererTest, Planet) { ImGui::InputFloat("Seed Value", &seed_value); ImGui::End(); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetCommandLabel("Planet scene"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -1039,7 +1039,7 @@ TEST_P(RendererTest, ArrayUniforms) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetCommandLabel("Google Dots"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -1097,7 +1097,7 @@ TEST_P(RendererTest, InactiveUniforms) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline); + pass.SetPipeline(pipeline.get()); pass.SetCommandLabel("Inactive Uniform"); VertexBufferBuilder builder; @@ -1329,7 +1329,7 @@ TEST_P(RendererTest, StencilMask) { assert(pipeline && pipeline->IsValid()); pass->SetCommandLabel("Box"); - pass->SetPipeline(pipeline); + pass->SetPipeline(pipeline.get()); pass->SetStencilReference(stencil_reference_read); pass->SetVertexBuffer(vertex_buffer); @@ -1477,7 +1477,7 @@ TEST_P(RendererTest, CanSepiaToneWithSubpasses) { // Draw the texture. { - pass.SetPipeline(texture_pipeline); + pass.SetPipeline(texture_pipeline.get()); pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); TextureVS::UniformBuffer uniforms; @@ -1492,7 +1492,7 @@ TEST_P(RendererTest, CanSepiaToneWithSubpasses) { // Draw the sepia toner. { - pass.SetPipeline(sepia_pipeline); + pass.SetPipeline(sepia_pipeline.get()); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SepiaVS::UniformBuffer uniforms; @@ -1571,7 +1571,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the texture. { - pass.SetPipeline(texture_pipeline); + pass.SetPipeline(texture_pipeline.get()); pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); TextureVS::UniformBuffer uniforms; @@ -1586,7 +1586,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the sepia toner. { - pass.SetPipeline(sepia_pipeline); + pass.SetPipeline(sepia_pipeline.get()); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SepiaVS::UniformBuffer uniforms; @@ -1600,7 +1600,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the swizzle. { - pass.SetPipeline(swizzle_pipeline); + pass.SetPipeline(swizzle_pipeline.get()); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SwizzleVS::UniformBuffer uniforms; diff --git a/lib/gpu/render_pass.cc b/lib/gpu/render_pass.cc index b2f43bc2db187..28ec6dc2a6b5f 100644 --- a/lib/gpu/render_pass.cc +++ b/lib/gpu/render_pass.cc @@ -177,7 +177,7 @@ RenderPass::GetOrCreatePipeline() { } bool RenderPass::Draw() { - render_pass_->SetPipeline(GetOrCreatePipeline()); + render_pass_->SetPipeline(GetOrCreatePipeline().get()); for (const auto& [_, buffer] : vertex_uniform_bindings) { render_pass_->BindDynamicResource( From 7ad67d7751a5dd5a66b6fc06a42b7d7164b1b536 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sat, 7 Dec 2024 13:23:10 -0800 Subject: [PATCH 2/6] use raw ptr wrapper. --- impeller/core/BUILD.gn | 2 + impeller/core/raw_ptr.cc | 11 ++ impeller/core/raw_ptr.h | 74 ++++++++ .../entity/contents/color_source_contents.h | 2 +- impeller/entity/contents/content_context.cc | 5 +- impeller/entity/contents/content_context.h | 172 +++++++----------- .../contents/filters/blend_filter_contents.cc | 7 +- .../contents/test/recording_render_pass.cc | 3 +- .../contents/test/recording_render_pass.h | 2 +- impeller/entity/entity_unittests.cc | 3 +- .../renderer/backend/metal/render_pass_mtl.h | 2 +- .../renderer/backend/metal/render_pass_mtl.mm | 2 +- .../renderer/backend/vulkan/render_pass_vk.cc | 10 +- .../renderer/backend/vulkan/render_pass_vk.h | 4 +- impeller/renderer/command.h | 2 +- impeller/renderer/pipeline.h | 3 + impeller/renderer/render_pass.cc | 2 +- impeller/renderer/render_pass.h | 2 +- lib/gpu/render_pass.cc | 2 +- 19 files changed, 180 insertions(+), 130 deletions(-) create mode 100644 impeller/core/raw_ptr.cc create mode 100644 impeller/core/raw_ptr.h diff --git a/impeller/core/BUILD.gn b/impeller/core/BUILD.gn index bb7ef28cf15ca..f88f90c205faa 100644 --- a/impeller/core/BUILD.gn +++ b/impeller/core/BUILD.gn @@ -23,6 +23,8 @@ impeller_component("core") { "platform.h", "range.cc", "range.h", + "raw_ptr.cc", + "raw_ptr.h", "resource_binder.cc", "resource_binder.h", "runtime_types.cc", diff --git a/impeller/core/raw_ptr.cc b/impeller/core/raw_ptr.cc new file mode 100644 index 0000000000000..314c2e06a892d --- /dev/null +++ b/impeller/core/raw_ptr.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/core/raw_ptr.h" + +namespace impeller { + +// + +} diff --git a/impeller/core/raw_ptr.h b/impeller/core/raw_ptr.h new file mode 100644 index 0000000000000..2f032984ec0bb --- /dev/null +++ b/impeller/core/raw_ptr.h @@ -0,0 +1,74 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_IMPELLER_CORE_RAW_PTR_H_ +#define FLUTTER_IMPELLER_CORE_RAW_PTR_H_ + +#include + +namespace impeller { + +/// @brief A wrapper around a raw ptr that adds additional unopt mode only +/// checks. +template +class raw_ptr { + public: + explicit raw_ptr(const std::shared_ptr& ptr) + : ptr_(ptr.get()) +#if !NDEBUG + , + weak_ptr_(ptr) +#endif + { + } + + raw_ptr() : ptr_(nullptr) {} + + T* operator->() { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); +#endif + return ptr_; + } + + const T* operator->() const { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); +#endif + return ptr_; + } + + T* get() { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); +#endif + return ptr_; + } + + T& operator*() { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); +#endif + return *ptr_; + } + + const T& operator*() const { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); +#endif + return *ptr_; + } + + explicit operator bool() const { return !!ptr_; } + + private: + T* ptr_; +#if !NDEBUG + std::weak_ptr weak_ptr_; +#endif +}; + +} // namespace impeller + +#endif // FLUTTER_IMPELLER_CORE_RAW_PTR_H_ diff --git a/impeller/entity/contents/color_source_contents.h b/impeller/entity/contents/color_source_contents.h index d7886f03723f2..17eba81f8930a 100644 --- a/impeller/entity/contents/color_source_contents.h +++ b/impeller/entity/contents/color_source_contents.h @@ -104,7 +104,7 @@ class ColorSourceContents : public Contents { using PipelineBuilderMethod = std::shared_ptr> ( impeller::ContentContext::*)(ContentContextOptions) const; using PipelineBuilderCallback = - std::function*(ContentContextOptions)>; + std::function; using CreateGeometryCallback = std::function* -ContentContext::GetCachedRuntimeEffectPipeline( +PipelineRef ContentContext::GetCachedRuntimeEffectPipeline( const std::string& unique_entrypoint_name, const ContentContextOptions& options, const std::function>()>& @@ -580,7 +579,7 @@ ContentContext::GetCachedRuntimeEffectPipeline( if (it == runtime_effect_pipelines_.end()) { it = runtime_effect_pipelines_.insert(it, {key, create_callback()}); } - return it->second.get(); + return raw_ptr(it->second); } void ContentContext::ClearCachedRuntimeEffectPipeline( diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index b086df2ca601c..0a0aee36262b9 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -377,102 +377,93 @@ class ContentContext { Tessellator& GetTessellator() const; - const Pipeline* GetFastGradientPipeline( - ContentContextOptions opts) const { + PipelineRef GetFastGradientPipeline(ContentContextOptions opts) const { return GetPipeline(fast_gradient_pipelines_, opts); } - const Pipeline* GetLinearGradientFillPipeline( - ContentContextOptions opts) const { + PipelineRef GetLinearGradientFillPipeline(ContentContextOptions opts) const { return GetPipeline(linear_gradient_fill_pipelines_, opts); } - const Pipeline* GetLinearGradientUniformFillPipeline( + PipelineRef GetLinearGradientUniformFillPipeline( ContentContextOptions opts) const { return GetPipeline(linear_gradient_uniform_fill_pipelines_, opts); } - const Pipeline* GetRadialGradientUniformFillPipeline( + PipelineRef GetRadialGradientUniformFillPipeline( ContentContextOptions opts) const { return GetPipeline(radial_gradient_uniform_fill_pipelines_, opts); } - const Pipeline* GetConicalGradientUniformFillPipeline( + PipelineRef GetConicalGradientUniformFillPipeline( ContentContextOptions opts) const { return GetPipeline(conical_gradient_uniform_fill_pipelines_, opts); } - const Pipeline* GetSweepGradientUniformFillPipeline( + PipelineRef GetSweepGradientUniformFillPipeline( ContentContextOptions opts) const { return GetPipeline(sweep_gradient_uniform_fill_pipelines_, opts); } - const Pipeline* GetLinearGradientSSBOFillPipeline( + PipelineRef GetLinearGradientSSBOFillPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(linear_gradient_ssbo_fill_pipelines_, opts); } - const Pipeline* GetRadialGradientSSBOFillPipeline( + PipelineRef GetRadialGradientSSBOFillPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(radial_gradient_ssbo_fill_pipelines_, opts); } - const Pipeline* GetConicalGradientSSBOFillPipeline( + PipelineRef GetConicalGradientSSBOFillPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(conical_gradient_ssbo_fill_pipelines_, opts); } - const Pipeline* GetSweepGradientSSBOFillPipeline( + PipelineRef GetSweepGradientSSBOFillPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsSSBO()); return GetPipeline(sweep_gradient_ssbo_fill_pipelines_, opts); } - const Pipeline* GetRadialGradientFillPipeline( - ContentContextOptions opts) const { + PipelineRef GetRadialGradientFillPipeline(ContentContextOptions opts) const { return GetPipeline(radial_gradient_fill_pipelines_, opts); } - const Pipeline* GetConicalGradientFillPipeline( - ContentContextOptions opts) const { + PipelineRef GetConicalGradientFillPipeline(ContentContextOptions opts) const { return GetPipeline(conical_gradient_fill_pipelines_, opts); } - const Pipeline* GetRRectBlurPipeline( - ContentContextOptions opts) const { + PipelineRef GetRRectBlurPipeline(ContentContextOptions opts) const { return GetPipeline(rrect_blur_pipelines_, opts); } - const Pipeline* GetSweepGradientFillPipeline( - ContentContextOptions opts) const { + PipelineRef GetSweepGradientFillPipeline(ContentContextOptions opts) const { return GetPipeline(sweep_gradient_fill_pipelines_, opts); } - const Pipeline* GetSolidFillPipeline( - ContentContextOptions opts) const { + PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const { return GetPipeline(solid_fill_pipelines_, opts); } - const Pipeline* GetTexturePipeline( - ContentContextOptions opts) const { + PipelineRef GetTexturePipeline(ContentContextOptions opts) const { return GetPipeline(texture_pipelines_, opts); } - const Pipeline* GetTextureStrictSrcPipeline( - ContentContextOptions opts) const { + PipelineRef GetTextureStrictSrcPipeline(ContentContextOptions opts) const { return GetPipeline(texture_strict_src_pipelines_, opts); } #ifdef IMPELLER_ENABLE_OPENGLES - const Pipeline* GetDownsampleTextureGlesPipeline( + PipelineRef GetDownsampleTextureGlesPipeline( ContentContextOptions opts) const { return GetPipeline(texture_downsample_gles_pipelines_, opts); } - const Pipeline* GetTiledTextureExternalPipeline( + PipelineRef GetTiledTextureExternalPipeline( ContentContextOptions opts) const { FML_DCHECK(GetContext()->GetBackendType() == Context::BackendType::kOpenGLES); @@ -480,236 +471,208 @@ class ContentContext { } #endif // IMPELLER_ENABLE_OPENGLES - const Pipeline* GetTiledTexturePipeline( - ContentContextOptions opts) const { + PipelineRef GetTiledTexturePipeline(ContentContextOptions opts) const { return GetPipeline(tiled_texture_pipelines_, opts); } - const Pipeline* GetGaussianBlurPipeline( - ContentContextOptions opts) const { + PipelineRef GetGaussianBlurPipeline(ContentContextOptions opts) const { return GetPipeline(gaussian_blur_pipelines_, opts); } - const Pipeline* GetBorderMaskBlurPipeline( - ContentContextOptions opts) const { + PipelineRef GetBorderMaskBlurPipeline(ContentContextOptions opts) const { return GetPipeline(border_mask_blur_pipelines_, opts); } - const Pipeline* GetMorphologyFilterPipeline( - ContentContextOptions opts) const { + PipelineRef GetMorphologyFilterPipeline(ContentContextOptions opts) const { return GetPipeline(morphology_filter_pipelines_, opts); } - const Pipeline* GetColorMatrixColorFilterPipeline( + PipelineRef GetColorMatrixColorFilterPipeline( ContentContextOptions opts) const { return GetPipeline(color_matrix_color_filter_pipelines_, opts); } - const Pipeline* GetLinearToSrgbFilterPipeline( - ContentContextOptions opts) const { + PipelineRef GetLinearToSrgbFilterPipeline(ContentContextOptions opts) const { return GetPipeline(linear_to_srgb_filter_pipelines_, opts); } - const Pipeline* GetSrgbToLinearFilterPipeline( - ContentContextOptions opts) const { + PipelineRef GetSrgbToLinearFilterPipeline(ContentContextOptions opts) const { return GetPipeline(srgb_to_linear_filter_pipelines_, opts); } - const Pipeline* GetClipPipeline( - ContentContextOptions opts) const { + PipelineRef GetClipPipeline(ContentContextOptions opts) const { return GetPipeline(clip_pipelines_, opts); } - const Pipeline* GetGlyphAtlasPipeline( - ContentContextOptions opts) const { + PipelineRef GetGlyphAtlasPipeline(ContentContextOptions opts) const { return GetPipeline(glyph_atlas_pipelines_, opts); } - const Pipeline* GetYUVToRGBFilterPipeline( - ContentContextOptions opts) const { + PipelineRef GetYUVToRGBFilterPipeline(ContentContextOptions opts) const { return GetPipeline(yuv_to_rgb_filter_pipelines_, opts); } - const Pipeline* GetPorterDuffBlendPipeline( - ContentContextOptions opts) const { + PipelineRef GetPorterDuffBlendPipeline(ContentContextOptions opts) const { return GetPipeline(porter_duff_blend_pipelines_, opts); } // Advanced blends. - const Pipeline* GetBlendColorPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendColorPipeline(ContentContextOptions opts) const { return GetPipeline(blend_color_pipelines_, opts); } - const Pipeline* GetBlendColorBurnPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendColorBurnPipeline(ContentContextOptions opts) const { return GetPipeline(blend_colorburn_pipelines_, opts); } - const Pipeline* GetBlendColorDodgePipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendColorDodgePipeline(ContentContextOptions opts) const { return GetPipeline(blend_colordodge_pipelines_, opts); } - const Pipeline* GetBlendDarkenPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendDarkenPipeline(ContentContextOptions opts) const { return GetPipeline(blend_darken_pipelines_, opts); } - const Pipeline* GetBlendDifferencePipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendDifferencePipeline(ContentContextOptions opts) const { return GetPipeline(blend_difference_pipelines_, opts); } - const Pipeline* GetBlendExclusionPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendExclusionPipeline(ContentContextOptions opts) const { return GetPipeline(blend_exclusion_pipelines_, opts); } - const Pipeline* GetBlendHardLightPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendHardLightPipeline(ContentContextOptions opts) const { return GetPipeline(blend_hardlight_pipelines_, opts); } - const Pipeline* GetBlendHuePipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendHuePipeline(ContentContextOptions opts) const { return GetPipeline(blend_hue_pipelines_, opts); } - const Pipeline* GetBlendLightenPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendLightenPipeline(ContentContextOptions opts) const { return GetPipeline(blend_lighten_pipelines_, opts); } - const Pipeline* GetBlendLuminosityPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendLuminosityPipeline(ContentContextOptions opts) const { return GetPipeline(blend_luminosity_pipelines_, opts); } - const Pipeline* GetBlendMultiplyPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendMultiplyPipeline(ContentContextOptions opts) const { return GetPipeline(blend_multiply_pipelines_, opts); } - const Pipeline* GetBlendOverlayPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendOverlayPipeline(ContentContextOptions opts) const { return GetPipeline(blend_overlay_pipelines_, opts); } - const Pipeline* GetBlendSaturationPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendSaturationPipeline(ContentContextOptions opts) const { return GetPipeline(blend_saturation_pipelines_, opts); } - const Pipeline* GetBlendScreenPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendScreenPipeline(ContentContextOptions opts) const { return GetPipeline(blend_screen_pipelines_, opts); } - const Pipeline* GetBlendSoftLightPipeline( - ContentContextOptions opts) const { + PipelineRef GetBlendSoftLightPipeline(ContentContextOptions opts) const { return GetPipeline(blend_softlight_pipelines_, opts); } - const Pipeline* GetDownsamplePipeline( - ContentContextOptions opts) const { + PipelineRef GetDownsamplePipeline(ContentContextOptions opts) const { return GetPipeline(texture_downsample_pipelines_, opts); } // Framebuffer Advanced Blends - const Pipeline* GetFramebufferBlendColorPipeline( + PipelineRef GetFramebufferBlendColorPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_color_pipelines_, opts); } - const Pipeline* GetFramebufferBlendColorBurnPipeline( + PipelineRef GetFramebufferBlendColorBurnPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_colorburn_pipelines_, opts); } - const Pipeline* GetFramebufferBlendColorDodgePipeline( + PipelineRef GetFramebufferBlendColorDodgePipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_colordodge_pipelines_, opts); } - const Pipeline* GetFramebufferBlendDarkenPipeline( + PipelineRef GetFramebufferBlendDarkenPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_darken_pipelines_, opts); } - const Pipeline* GetFramebufferBlendDifferencePipeline( + PipelineRef GetFramebufferBlendDifferencePipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_difference_pipelines_, opts); } - const Pipeline* GetFramebufferBlendExclusionPipeline( + PipelineRef GetFramebufferBlendExclusionPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_exclusion_pipelines_, opts); } - const Pipeline* GetFramebufferBlendHardLightPipeline( + PipelineRef GetFramebufferBlendHardLightPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_hardlight_pipelines_, opts); } - const Pipeline* GetFramebufferBlendHuePipeline( - ContentContextOptions opts) const { + PipelineRef GetFramebufferBlendHuePipeline(ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_hue_pipelines_, opts); } - const Pipeline* GetFramebufferBlendLightenPipeline( + PipelineRef GetFramebufferBlendLightenPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_lighten_pipelines_, opts); } - const Pipeline* GetFramebufferBlendLuminosityPipeline( + PipelineRef GetFramebufferBlendLuminosityPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_luminosity_pipelines_, opts); } - const Pipeline* GetFramebufferBlendMultiplyPipeline( + PipelineRef GetFramebufferBlendMultiplyPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_multiply_pipelines_, opts); } - const Pipeline* GetFramebufferBlendOverlayPipeline( + PipelineRef GetFramebufferBlendOverlayPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_overlay_pipelines_, opts); } - const Pipeline* GetFramebufferBlendSaturationPipeline( + PipelineRef GetFramebufferBlendSaturationPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_saturation_pipelines_, opts); } - const Pipeline* GetFramebufferBlendScreenPipeline( + PipelineRef GetFramebufferBlendScreenPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_screen_pipelines_, opts); } - const Pipeline* GetFramebufferBlendSoftLightPipeline( + PipelineRef GetFramebufferBlendSoftLightPipeline( ContentContextOptions opts) const { FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch()); return GetPipeline(framebuffer_blend_softlight_pipelines_, opts); } - const Pipeline* GetDrawVerticesUberShader( - ContentContextOptions opts) const { + PipelineRef GetDrawVerticesUberShader(ContentContextOptions opts) const { return GetPipeline(vertices_uber_shader_, opts); } @@ -761,7 +724,7 @@ class ContentContext { /// /// The create_callback is synchronously invoked exactly once if a cached /// pipeline is not found. - const Pipeline* GetCachedRuntimeEffectPipeline( + PipelineRef GetCachedRuntimeEffectPipeline( const std::string& unique_entrypoint_name, const ContentContextOptions& options, const std::function>()>& @@ -992,14 +955,13 @@ class ContentContext { mutable Variants vertices_uber_shader_; template - const Pipeline* GetPipeline( - Variants& container, - ContentContextOptions opts) const { + PipelineRef GetPipeline(Variants& container, + ContentContextOptions opts) const { TypedPipeline* pipeline = CreateIfNeeded(container, opts); if (!pipeline) { - return nullptr; + return raw_ptr>(); } - return pipeline->WaitAndGet().get(); + return raw_ptr(pipeline->WaitAndGet()); } template diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 1580dc70087bc..3f07150c3df3c 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -71,8 +71,8 @@ BlendFilterContents::BlendFilterContents() { BlendFilterContents::~BlendFilterContents() = default; -using PipelineProc = const Pipeline* ( - ContentContext::*)(ContentContextOptions) const; +using PipelineProc = + PipelineRef (ContentContext::*)(ContentContextOptions) const; template static std::optional AdvancedBlend( @@ -170,8 +170,7 @@ static std::optional AdvancedBlend( auto options = OptionsFromPass(pass); options.primitive_type = PrimitiveType::kTriangleStrip; options.blend_mode = BlendMode::kSource; - const Pipeline* pipeline = - std::invoke(pipeline_proc, renderer, options); + PipelineRef pipeline = std::invoke(pipeline_proc, renderer, options); #ifdef IMPELLER_DEBUG pass.SetCommandLabel( diff --git a/impeller/entity/contents/test/recording_render_pass.cc b/impeller/entity/contents/test/recording_render_pass.cc index c52f575a23083..baa7a8e14d68d 100644 --- a/impeller/entity/contents/test/recording_render_pass.cc +++ b/impeller/entity/contents/test/recording_render_pass.cc @@ -15,8 +15,7 @@ RecordingRenderPass::RecordingRenderPass( : RenderPass(context, render_target), delegate_(std::move(delegate)) {} // |RenderPass| -void RecordingRenderPass::SetPipeline( - const Pipeline* pipeline) { +void RecordingRenderPass::SetPipeline(PipelineRef pipeline) { pending_.pipeline = pipeline; if (delegate_) { delegate_->SetPipeline(pipeline); diff --git a/impeller/entity/contents/test/recording_render_pass.h b/impeller/entity/contents/test/recording_render_pass.h index 4b7773b1b2789..4172121c77104 100644 --- a/impeller/entity/contents/test/recording_render_pass.h +++ b/impeller/entity/contents/test/recording_render_pass.h @@ -20,7 +20,7 @@ class RecordingRenderPass : public RenderPass { const std::vector& GetCommands() const override { return commands_; } // |RenderPass| - void SetPipeline(const Pipeline* pipeline) override; + void SetPipeline(PipelineRef pipeline) override; void SetCommandLabel(std::string_view label) override; diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 8a932e54fffc0..59b3e45c716c0 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -15,6 +15,7 @@ #include "impeller/core/device_buffer.h" #include "impeller/core/formats.h" #include "impeller/core/host_buffer.h" +#include "impeller/core/raw_ptr.h" #include "impeller/core/texture_descriptor.h" #include "impeller/entity/contents/clip_contents.h" #include "impeller/entity/contents/conical_gradient_contents.h" @@ -1696,7 +1697,7 @@ TEST_P(EntityTest, RuntimeEffect) { ASSERT_TRUE(runtime_stage->IsDirty()); bool expect_dirty = true; - const Pipeline* first_pipeline; + const raw_ptr*> first_pipeline; std::unique_ptr geom = Geometry::MakeCover(); auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { diff --git a/impeller/renderer/backend/metal/render_pass_mtl.h b/impeller/renderer/backend/metal/render_pass_mtl.h index 2ba619d78d08a..6639de497c247 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.h +++ b/impeller/renderer/backend/metal/render_pass_mtl.h @@ -58,7 +58,7 @@ class RenderPassMTL final : public RenderPass { bool OnEncodeCommands(const Context& context) const override; // |RenderPass| - void SetPipeline(const Pipeline* pipeline) override; + void SetPipeline(PipelineRef pipeline) override; // |RenderPass| void SetCommandLabel(std::string_view label) override; diff --git a/impeller/renderer/backend/metal/render_pass_mtl.mm b/impeller/renderer/backend/metal/render_pass_mtl.mm index 0ce7ea1fea38a..73e20544006f4 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -233,7 +233,7 @@ static bool Bind(PassBindingsCacheMTL& pass, } // |RenderPass| -void RenderPassMTL::SetPipeline(const Pipeline* pipeline) { +void RenderPassMTL::SetPipeline(PipelineRef pipeline) { const PipelineDescriptor& pipeline_desc = pipeline->GetDescriptor(); primitive_type_ = pipeline_desc.GetPrimitiveType(); pass_bindings_.SetRenderPipelineState( diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index be95f0b209cd2..46315ffe0b8fc 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -293,7 +293,7 @@ SharedHandleVK RenderPassVK::CreateVKFramebuffer( } // |RenderPass| -void RenderPassVK::SetPipeline(const Pipeline* pipeline) { +void RenderPassVK::SetPipeline(PipelineRef pipeline) { pipeline_ = pipeline; if (!pipeline_) { return; @@ -304,7 +304,7 @@ void RenderPassVK::SetPipeline(const Pipeline* pipeline) { if (pipeline_uses_input_attachments_) { if (bound_image_offset_ >= kMaxBindings) { - pipeline_ = nullptr; + pipeline_ = PipelineRef(nullptr); return; } vk::DescriptorImageInfo image_info; @@ -463,7 +463,7 @@ fml::Status RenderPassVK::Draw() { /// Jank can be completely eliminated by pre-populating known YUV conversion /// pipelines. if (immutable_sampler_) { - std::shared_ptr pipeline_variant = + std::shared_ptr> pipeline_variant = PipelineVK::Cast(*pipeline_) .CreateVariantForImmutableSamplers(immutable_sampler_); if (!pipeline_variant) { @@ -471,7 +471,7 @@ fml::Status RenderPassVK::Draw() { fml::StatusCode::kAborted, "Could not create pipeline variant with immutable sampler."); } - pipeline_ = pipeline_variant.get(); + pipeline_ = raw_ptr(pipeline_variant); } const auto& context_vk = ContextVK::Cast(*context_); @@ -538,7 +538,7 @@ fml::Status RenderPassVK::Draw() { instance_count_ = 1u; base_vertex_ = 0u; element_count_ = 0u; - pipeline_ = nullptr; + pipeline_ = PipelineRef(nullptr); pipeline_uses_input_attachments_ = false; immutable_sampler_ = nullptr; return fml::Status(); diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index b4ea45ae3f14a..95219e5c0659a 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -49,7 +49,7 @@ class RenderPassVK final : public RenderPass { size_t element_count_ = 0u; bool has_index_buffer_ = false; bool has_label_ = false; - const Pipeline* pipeline_; + PipelineRef pipeline_ = PipelineRef(nullptr); bool pipeline_uses_input_attachments_ = false; std::shared_ptr immutable_sampler_; @@ -58,7 +58,7 @@ class RenderPassVK final : public RenderPass { std::shared_ptr command_buffer); // |RenderPass| - void SetPipeline(const Pipeline* pipeline) override; + void SetPipeline(PipelineRef pipeline) override; // |RenderPass| void SetCommandLabel(std::string_view label) override; diff --git a/impeller/renderer/command.h b/impeller/renderer/command.h index 528efd4430343..70a43814c6380 100644 --- a/impeller/renderer/command.h +++ b/impeller/renderer/command.h @@ -81,7 +81,7 @@ struct Command { //---------------------------------------------------------------------------- /// The pipeline to use for this command. /// - const Pipeline* pipeline; + PipelineRef pipeline; /// An offset into render pass storage where bound buffers/texture metadata is /// stored. diff --git a/impeller/renderer/pipeline.h b/impeller/renderer/pipeline.h index b3babc34a8537..79612e4273629 100644 --- a/impeller/renderer/pipeline.h +++ b/impeller/renderer/pipeline.h @@ -8,6 +8,7 @@ #include #include "compute_pipeline_descriptor.h" +#include "impeller/core/raw_ptr.h" #include "impeller/renderer/compute_pipeline_builder.h" #include "impeller/renderer/compute_pipeline_descriptor.h" #include "impeller/renderer/context.h" @@ -78,6 +79,8 @@ class Pipeline { Pipeline& operator=(const Pipeline&) = delete; }; +using PipelineRef = raw_ptr>; + extern template class Pipeline; extern template class Pipeline; diff --git a/impeller/renderer/render_pass.cc b/impeller/renderer/render_pass.cc index 956218921b1e2..d8a977d3243e8 100644 --- a/impeller/renderer/render_pass.cc +++ b/impeller/renderer/render_pass.cc @@ -81,7 +81,7 @@ const std::shared_ptr& RenderPass::GetContext() const { return context_; } -void RenderPass::SetPipeline(const Pipeline* pipeline) { +void RenderPass::SetPipeline(PipelineRef pipeline) { pending_.pipeline = pipeline; } diff --git a/impeller/renderer/render_pass.h b/impeller/renderer/render_pass.h index 4f0dded813637..566ef24b28306 100644 --- a/impeller/renderer/render_pass.h +++ b/impeller/renderer/render_pass.h @@ -45,7 +45,7 @@ class RenderPass : public ResourceBinder { //---------------------------------------------------------------------------- /// The pipeline to use for this command. - virtual void SetPipeline(const Pipeline* pipeline); + virtual void SetPipeline(PipelineRef pipeline); //---------------------------------------------------------------------------- /// The debugging label to use for the command. diff --git a/lib/gpu/render_pass.cc b/lib/gpu/render_pass.cc index 28ec6dc2a6b5f..3416ef1d0b8a1 100644 --- a/lib/gpu/render_pass.cc +++ b/lib/gpu/render_pass.cc @@ -177,7 +177,7 @@ RenderPass::GetOrCreatePipeline() { } bool RenderPass::Draw() { - render_pass_->SetPipeline(GetOrCreatePipeline().get()); + render_pass_->SetPipeline(impeller::PipelineRef(GetOrCreatePipeline())); for (const auto& [_, buffer] : vertex_uniform_bindings) { render_pass_->BindDynamicResource( From 3eb58d8da94134ce9829e57cae235a62a10a7a5f Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 8 Dec 2024 12:41:55 -0800 Subject: [PATCH 3/6] add equality implementations to raw_ptr. --- impeller/core/raw_ptr.h | 14 +++++++ impeller/entity/entity_unittests.cc | 2 +- .../playground/imgui/imgui_impl_impeller.cc | 3 +- impeller/renderer/render_pass.cc | 5 +++ impeller/renderer/render_pass.h | 5 +++ impeller/renderer/renderer_dart_unittests.cc | 2 +- impeller/renderer/renderer_unittests.cc | 38 +++++++++---------- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/impeller/core/raw_ptr.h b/impeller/core/raw_ptr.h index 2f032984ec0bb..12626d0a072ed 100644 --- a/impeller/core/raw_ptr.h +++ b/impeller/core/raw_ptr.h @@ -60,6 +60,20 @@ class raw_ptr { return *ptr_; } + template + inline bool operator==(raw_ptr const& other) const { +#if !NDEBUG + FML_CHECK(weak_ptr_.lock()); + FML_CHECK(other_.weak_ptr_.lock()); +#endif + return ptr_ == other.ptr_; + } + + template + inline bool operator!=(raw_ptr const& other) const { + return !(*this == other); + } + explicit operator bool() const { return !!ptr_; } private: diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 59b3e45c716c0..f7d84fce2e61c 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -1697,7 +1697,7 @@ TEST_P(EntityTest, RuntimeEffect) { ASSERT_TRUE(runtime_stage->IsDirty()); bool expect_dirty = true; - const raw_ptr*> first_pipeline; + PipelineRef first_pipeline; std::unique_ptr geom = Geometry::MakeCover(); auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { diff --git a/impeller/playground/imgui/imgui_impl_impeller.cc b/impeller/playground/imgui/imgui_impl_impeller.cc index d154376b283e3..1eb7657f93751 100644 --- a/impeller/playground/imgui/imgui_impl_impeller.cc +++ b/impeller/playground/imgui/imgui_impl_impeller.cc @@ -30,7 +30,6 @@ #include "impeller/geometry/point.h" #include "impeller/geometry/rect.h" #include "impeller/geometry/size.h" -#include "impeller/renderer/command.h" #include "impeller/renderer/context.h" #include "impeller/renderer/pipeline_builder.h" #include "impeller/renderer/pipeline_descriptor.h" @@ -256,7 +255,7 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data, "ImGui draw list %d (command %d)", draw_list_i, cmd_i)); render_pass.SetViewport(viewport); render_pass.SetScissor(impeller::IRect::RoundOut(clip_rect)); - render_pass.SetPipeline(bd->pipeline.get()); + render_pass.SetPipeline(bd->pipeline); VS::BindUniformBuffer(render_pass, vtx_uniforms); FS::BindTex(render_pass, bd->font_texture, bd->sampler); diff --git a/impeller/renderer/render_pass.cc b/impeller/renderer/render_pass.cc index d8a977d3243e8..a35817d8fd092 100644 --- a/impeller/renderer/render_pass.cc +++ b/impeller/renderer/render_pass.cc @@ -85,6 +85,11 @@ void RenderPass::SetPipeline(PipelineRef pipeline) { pending_.pipeline = pipeline; } +void RenderPass::SetPipeline( + const std::shared_ptr>& pipeline) { + SetPipeline(PipelineRef(pipeline)); +} + void RenderPass::SetCommandLabel(std::string_view label) { #ifdef IMPELLER_DEBUG pending_.label = std::string(label); diff --git a/impeller/renderer/render_pass.h b/impeller/renderer/render_pass.h index 566ef24b28306..554bf348ece39 100644 --- a/impeller/renderer/render_pass.h +++ b/impeller/renderer/render_pass.h @@ -47,6 +47,11 @@ class RenderPass : public ResourceBinder { /// The pipeline to use for this command. virtual void SetPipeline(PipelineRef pipeline); + //---------------------------------------------------------------------------- + /// The pipeline to use for this command. + void SetPipeline( + const std::shared_ptr>& pipeline); + //---------------------------------------------------------------------------- /// The debugging label to use for the command. virtual void SetCommandLabel(std::string_view label); diff --git a/impeller/renderer/renderer_dart_unittests.cc b/impeller/renderer/renderer_dart_unittests.cc index 463c0cd514c9f..3368ae759e742 100644 --- a/impeller/renderer/renderer_dart_unittests.cc +++ b/impeller/renderer/renderer_dart_unittests.cc @@ -235,7 +235,7 @@ class RendererDartTest : public PlaygroundTest, TextureVS::BindUniformBuffer(pass, buffer->EmplaceUniform(uniforms)); TextureFS::BindTextureContents(pass, texture, sampler); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); if (!pass.Draw().ok()) { return false; diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index f98e7fd622dcb..0e84ea50cfd17 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -93,7 +93,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { assert(pipeline && pipeline->IsValid()); pass.SetCommandLabel("Box"); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetVertexBuffer( vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator())); @@ -160,7 +160,7 @@ TEST_P(RendererTest, BabysFirstTriangle) { *context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetVertexBuffer(vertex_buffer); FS::FragInfo frag_info; @@ -255,7 +255,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { ImGui::End(); pass.SetCommandLabel("Perspective Cube"); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); std::array vertex_buffers = { BufferView(device_buffer, @@ -330,7 +330,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { for (size_t i = 0; i < 1; i++) { for (size_t j = 0; j < 1; j++) { pass.SetCommandLabel("Box"); - pass.SetPipeline(box_pipeline.get()); + pass.SetPipeline(box_pipeline); pass.SetVertexBuffer(vertex_buffer); FS::FrameInfo frame_info; @@ -445,7 +445,7 @@ TEST_P(RendererTest, CanRenderToTexture) { } r2t_pass->SetCommandLabel("Box"); - r2t_pass->SetPipeline(box_pipeline.get()); + r2t_pass->SetPipeline(box_pipeline); r2t_pass->SetVertexBuffer(vertex_buffer); FS::FrameInfo frame_info; @@ -504,7 +504,7 @@ TEST_P(RendererTest, CanRenderInstanced) { auto host_buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter()); ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool { - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetCommandLabel("InstancedDraw"); VS::FrameInfo frame_info; @@ -605,7 +605,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image"); - pass->SetPipeline(mipmaps_pipeline.get()); + pass->SetPipeline(mipmaps_pipeline); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -728,7 +728,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image"); - pass->SetPipeline(mipmaps_pipeline.get()); + pass->SetPipeline(mipmaps_pipeline); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -855,7 +855,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) { pass->SetLabel("Playground Render Pass"); { pass->SetCommandLabel("Image LOD"); - pass->SetPipeline(mipmaps_pipeline.get()); + pass->SetPipeline(mipmaps_pipeline); pass->SetVertexBuffer(vertex_buffer); VS::FrameInfo frame_info; @@ -923,7 +923,7 @@ TEST_P(RendererTest, TheImpeller) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetCommandLabel("Impeller SDF scene"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -987,7 +987,7 @@ TEST_P(RendererTest, Planet) { ImGui::InputFloat("Seed Value", &seed_value); ImGui::End(); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetCommandLabel("Planet scene"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -1039,7 +1039,7 @@ TEST_P(RendererTest, ArrayUniforms) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetCommandLabel("Google Dots"); VertexBufferBuilder builder; builder.AddVertices({{Point()}, @@ -1097,7 +1097,7 @@ TEST_P(RendererTest, InactiveUniforms) { SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); - pass.SetPipeline(pipeline.get()); + pass.SetPipeline(pipeline); pass.SetCommandLabel("Inactive Uniform"); VertexBufferBuilder builder; @@ -1329,7 +1329,7 @@ TEST_P(RendererTest, StencilMask) { assert(pipeline && pipeline->IsValid()); pass->SetCommandLabel("Box"); - pass->SetPipeline(pipeline.get()); + pass->SetPipeline(pipeline); pass->SetStencilReference(stencil_reference_read); pass->SetVertexBuffer(vertex_buffer); @@ -1477,7 +1477,7 @@ TEST_P(RendererTest, CanSepiaToneWithSubpasses) { // Draw the texture. { - pass.SetPipeline(texture_pipeline.get()); + pass.SetPipeline(texture_pipeline); pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); TextureVS::UniformBuffer uniforms; @@ -1492,7 +1492,7 @@ TEST_P(RendererTest, CanSepiaToneWithSubpasses) { // Draw the sepia toner. { - pass.SetPipeline(sepia_pipeline.get()); + pass.SetPipeline(sepia_pipeline); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SepiaVS::UniformBuffer uniforms; @@ -1571,7 +1571,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the texture. { - pass.SetPipeline(texture_pipeline.get()); + pass.SetPipeline(texture_pipeline); pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); TextureVS::UniformBuffer uniforms; @@ -1586,7 +1586,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the sepia toner. { - pass.SetPipeline(sepia_pipeline.get()); + pass.SetPipeline(sepia_pipeline); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SepiaVS::UniformBuffer uniforms; @@ -1600,7 +1600,7 @@ TEST_P(RendererTest, CanSepiaToneThenSwizzleWithSubpasses) { // Draw the swizzle. { - pass.SetPipeline(swizzle_pipeline.get()); + pass.SetPipeline(swizzle_pipeline); pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer( *context->GetResourceAllocator())); SwizzleVS::UniformBuffer uniforms; From 5e8c320ab1299479701729bc687e758e65ad5c17 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 8 Dec 2024 13:29:59 -0800 Subject: [PATCH 4/6] licenses. --- ci/licenses_golden/licenses_flutter | 4 ++++ impeller/core/raw_ptr.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 59228d96c8c24..20300dd074842 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -43017,6 +43017,8 @@ ORIGIN: ../../../flutter/impeller/core/platform.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/platform.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/range.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/range.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/core/raw_ptr.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/core/raw_ptr.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/resource_binder.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/resource_binder.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/core/runtime_types.cc + ../../../flutter/LICENSE @@ -45946,6 +45948,8 @@ FILE: ../../../flutter/impeller/core/platform.cc FILE: ../../../flutter/impeller/core/platform.h FILE: ../../../flutter/impeller/core/range.cc FILE: ../../../flutter/impeller/core/range.h +FILE: ../../../flutter/impeller/core/raw_ptr.cc +FILE: ../../../flutter/impeller/core/raw_ptr.h FILE: ../../../flutter/impeller/core/resource_binder.cc FILE: ../../../flutter/impeller/core/resource_binder.h FILE: ../../../flutter/impeller/core/runtime_types.cc diff --git a/impeller/core/raw_ptr.h b/impeller/core/raw_ptr.h index 12626d0a072ed..98c82c31dab43 100644 --- a/impeller/core/raw_ptr.h +++ b/impeller/core/raw_ptr.h @@ -64,7 +64,7 @@ class raw_ptr { inline bool operator==(raw_ptr const& other) const { #if !NDEBUG FML_CHECK(weak_ptr_.lock()); - FML_CHECK(other_.weak_ptr_.lock()); + FML_CHECK(other.weak_ptr_.lock()); #endif return ptr_ == other.ptr_; } From fb21887f1eb0b17e9f4791e873b81f51062fe873 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 9 Dec 2024 10:22:49 -0800 Subject: [PATCH 5/6] add comment. --- impeller/renderer/pipeline.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/impeller/renderer/pipeline.h b/impeller/renderer/pipeline.h index 79612e4273629..5c191c19b5f04 100644 --- a/impeller/renderer/pipeline.h +++ b/impeller/renderer/pipeline.h @@ -79,6 +79,10 @@ class Pipeline { Pipeline& operator=(const Pipeline&) = delete; }; +/// @brief A raw ptr to a pipeline object. +/// +/// These pipeline refs are safe to use as the context will keep the +/// pipelines alive throughout rendering. using PipelineRef = raw_ptr>; extern template class Pipeline; From 43f8e05b7c9220dff49bec194eb7c53efd9ee1e4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 9 Dec 2024 11:07:19 -0800 Subject: [PATCH 6/6] Update raw_ptr.h Remove FML_CHECK on == so we can make comparison to nullptr. --- impeller/core/raw_ptr.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/impeller/core/raw_ptr.h b/impeller/core/raw_ptr.h index 98c82c31dab43..9348cfe27e330 100644 --- a/impeller/core/raw_ptr.h +++ b/impeller/core/raw_ptr.h @@ -62,10 +62,6 @@ class raw_ptr { template inline bool operator==(raw_ptr const& other) const { -#if !NDEBUG - FML_CHECK(weak_ptr_.lock()); - FML_CHECK(other.weak_ptr_.lock()); -#endif return ptr_ == other.ptr_; }