Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] switch Pipeline to use raw ptr instead of shared ptr for recorded references. #57015

Merged
merged 6 commits into from
Dec 9, 2024

Conversation

jonahwilliams
Copy link
Member

Fixes flutter/flutter#159566

We don't need recorded commands to keep pipelines alive as the context does that already.

@jonahwilliams jonahwilliams changed the title [Impeller] ptrs baby. [Impeller] switch Pipeline to use raw ptr instead of shared ptr for recorded references. Dec 6, 2024
@@ -377,338 +377,338 @@ class ContentContext {

Tessellator& GetTessellator() const;

std::shared_ptr<Pipeline<PipelineDescriptor>> GetFastGradientPipeline(
const Pipeline<PipelineDescriptor>* GetFastGradientPipeline(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of wrapping this up in a raw_ptr class. That way in debug builds we could actually assert we aren't using dangling pointers.

template<typename T>
class raw_ptr {
public:
  raw_ptr(const std::shared_ptr<T>& ptr) 
     : ptr_(ptr.get())
#if !NDEBUG
      , weak_ptr_(ptr)
#endif
     {}
  T* get() {
#if !NDEBUG
   FML_CHECK(weak_ptr_.lock());
#endif
    return ptr_;
   }
private: 
  T* ptr_;
#if !NDEBUG
  std::weak_ptr<T> weak_ptr_;
#endif
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will never use the class as I never run unopt builds. I don't think we should add infrastructure for the one or two people who do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is executed by CI though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so are things like ASAN

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than writing our own ASAN code, can we just use ASAN on our tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to. There is some weirdness when executing on linux. You have to make a fake X instance. Looks like we have something in run_tests.py that does this already: https://github.com/gaaclarke/engine/blob/9fff75d9364fb3eafb62240ac1ab04f76ef914cd/testing/run_tests.py#L1220

You have to specify "impeller" as the variant though (we are just specifying engine). I don't know if it works. It might not if there are no builders executing it. I think this goes back all the way to when kaushik hooked up it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try adding "impeller" to the variant in linux_unopt.json and see if it works 🤞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried just throwing in impeller with the asan target, it didn't work: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8729261574606027697/+/u/test:_test:_Host_Tests_for_host_debug_unopt/stdout

The virtual display doesn't seem to be working. This is the same sort of issues I ran into when trying to get golden tests running on linux. We should have ASAN as an option on macos. That may be the easier approach.

Copy link
Member

@gaaclarke gaaclarke Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get things compiling with ASAN on macos:

$ ./flutter/tools/gn --unoptimized --runtime-mode=debug --no-rbe --no-goma --asan --mac-cpu=arm64
$ ninja -j8 -C out/host_debug_unopt_arm64 impeller_golden_tests
[5/2329] ACTION //flutter/impeller/runtime_stage:flatc_runtime_stage_flatbuffers(//build/toolchain/mac:clang_arm64)
FAILED: gen/flutter/impeller/runtime_stage/runtime_stage_flatbuffers.h 
vpython3 ../../build/gn_run_binary.py flatc --warnings-as-errors --cpp --cpp-std c++17 --cpp-static-reflection --gen-object-api --filename-suffix _flatbuffers -o gen/flutter/impeller/runtime_stage ../../flutter/impeller/runtime_stage/runtime_stage.fbs
Command failed: ./flatc --warnings-as-errors --cpp --cpp-std c++17 --cpp-static-reflection --gen-object-api --filename-suffix _flatbuffers -o gen/flutter/impeller/runtime_stage ../../flutter/impeller/runtime_stage/runtime_stage.fbs
exitCode: -6
dyld[61885]: missing symbol called

edit: looks like ASAN wants a runtime library and it's creating a weird link in the macho file

$ otool -L flatc 
flatc:
	@rpath/libclang_rt.asan_osx_dynamic.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed an issue for ASAN: flutter/flutter#159985

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea going this way sounds easier for now. I'd still like to get ASAN working at some point. I'll file an issue. LGTM modulo a place where I think there is a typo.

const Pipeline<PipelineDescriptor>* GetPipeline(
Variants<TypedPipeline>& container,
ContentContextOptions opts) const {
PipelineRef GetPipeline(Variants<TypedPipeline>& container,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a comment somewhere that says why we are able to pass around raw_ptrs. This is the best place I can think of. Or maybe at the typedef?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, on the typedef.

@@ -1696,7 +1697,7 @@ TEST_P(EntityTest, RuntimeEffect) {
ASSERT_TRUE(runtime_stage->IsDirty());

bool expect_dirty = true;
const Pipeline<PipelineDescriptor>* first_pipeline;
const raw_ptr<Pipeline<PipelineDescriptor>*> first_pipeline;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, you have a pointer to a pointer here. It should be raw_ptr<PipelineDescriptor>>, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an outdated diff...

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks! I'll continue to poke around at asan.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 9, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 9, 2024
Copy link
Contributor

auto-submit bot commented Dec 9, 2024

auto label is removed for flutter/engine/57015, due to - The status or check suite Linux linux_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

Remove FML_CHECK on == so we can make comparison to nullptr.
@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 9, 2024
@auto-submit auto-submit bot merged commit 4d0e9ac into flutter:main Dec 9, 2024
33 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 9, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Dec 9, 2024
…160000)

flutter/engine@37a7a14...4d0e9ac

2024-12-09 [email protected] [Impeller] switch Pipeline to use
raw ptr instead of shared ptr for recorded references.
(flutter/engine#57015)
2024-12-09 [email protected] [Impeller] disable all Adrenos older
than 630 (flutter/engine#57069)
2024-12-09 [email protected] Roll Skia to 14f8f6d984ff
(flutter/engine#57068)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gaaclarke added a commit that referenced this pull request Dec 10, 2024
auto-submit bot pushed a commit that referenced this pull request Dec 10, 2024
…tr for recorded references. (#57086)

Prev: #57015

There is a unit test that is clearing out the pipeline storage, manually null out captured PipelineRef.
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…ecorded references. (flutter/engine#57015)

Fixes flutter#159566

We don't need recorded commands to keep pipelines alive as the context does that already.
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…tr for recorded references. (flutter/engine#57086)

Prev: flutter/engine#57015

There is a unit test that is clearing out the pipeline storage, manually null out captured PipelineRef.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[impeller] move Command::pipeline to Pipeline<PipelineDescriptor>*
2 participants