-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Move BufferView/Texture/Sampler when binding. #48628
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
gaaclarke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a std::unique_ptr too.
Imagine this case:
size_t Foo::bar() {
BufferView view = GenerateBufferView();
binder_->BindResource(stage_, slot_, metadata_, view);
return view.GetSize();
}The linter won't complain about an accidental copy because it is used after the copy. That wouldn't be possible with the std::unique_ptr.
size_t Foo::bar() {
std::unique_ptr<BufferView> view = GenerateBufferView();
binder_->BindResource(stage_, slot_, metadata_, std::move(view)); // move required
return view->GetSize(); // crash!
}| case ShaderStage::kVertex: | ||
| vertex_bindings.buffers[slot.ext_res_0] = { | ||
| .slot = slot, .view = BufferResource(metadata, view)}; | ||
| .slot = slot, .view = BufferResource(metadata, std::move(view))}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading the code correctly, this used to be a copy here, but now is a move which should be faster.
gaaclarke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you just want to follow the pattern you had in the other PR of having explicit Clone for BufferView?
|
I do not want to use unique_ptr because adding more heap allocations is going to be counter productive to performance. But making the type (mostly) move only seems like a good idea. I will give that a shot |
|
I tried making it move only in #48630 The problem is that BufferView is placed directly on a VertexBuffer and directly in Command. So all of those types need to be made move only as wel. That's a bit more than I want to do at once, though making Cmd move only would eventually let us fix the style guide violation of add command - so its probably worth doing. |
gaaclarke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming we have help from the linter if we introduce accidental copies and we are seeing performance benefits in some microbenchmarks.
The references made it impossible to get copies wrong, but also were suboptimal in the case where we could actually pass ownership. I'm willing to give this a shot.
| case ShaderStage::kFragment: | ||
| fragment_bindings.buffers[slot.ext_res_0] = { | ||
| .slot = slot, .view = BufferResource(metadata, view)}; | ||
| .slot = slot, .view = BufferResource(metadata, std::move(view))}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you accidentally omit the std::move here, we get a linter failure right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not :(
|
I think for move only, we should start with Command and work our way down, that would be easier than going bottom up. |
|
test-exempt: code refactor with no semantic change |
…139536) flutter/engine@de0ba84...f43ef6c 2023-12-05 [email protected] Roll Dart SDK from a1b67665b3a3 to 9c74645153ca (1 revision) (flutter/engine#48648) 2023-12-05 [email protected] [Impeller] Remove impeller::Path copy constructor. (flutter/engine#48616) 2023-12-04 [email protected] [Impeller] Move BufferView/Texture/Sampler when binding. (flutter/engine#48628) 2023-12-04 [email protected] Roll Skia from cbd2cf40d63b to d37625f80ac0 (1 revision) (flutter/engine#48643) 2023-12-04 [email protected] Add `flutter` prefix to import (flutter/engine#48617) 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],[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
Most of the time we are passing an rvalue into this functions anyway, so in theory moving should be faster. Right?