Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Nov 27, 2024

Should fix flutter/flutter#159520 but I still need to check locally. Seems to do the trick.

All cmd bindings were copying the shader metadata, which meant allocating/de-allocating a lot of strings per draw.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

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. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.


for (const auto& uniform : runtime_stage_->GetUniforms()) {
std::shared_ptr<ShaderMetadata> metadata = MakeShaderMetadata(uniform);
ShaderMetadata metadata = MakeShaderMetadata(uniform);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't need to be a shared_ptr since its going to be copied into the bindings object anyway.

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.

Looking good, just needs docstrings to show the difference between the overloaded calls, remove some duplication. I have a few suggestions for performance but they aren't important since they are for runtime effects.

Comment on lines 55 to 57
ShaderMetadata metadata;
metadata.name = uniform.name;
metadata.members.emplace_back(ShaderStructMemberMetadata{
Copy link
Member

Choose a reason for hiding this comment

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

nit: it would be nice to verify that we are getting the return value optimization here, an rvalue in the return statement would make this more likely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this unique_ptr anyway

}

static std::shared_ptr<ShaderMetadata> MakeShaderMetadata(
static ShaderMetadata MakeShaderMetadata(
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we should move this to std::unique_ptr<ShaderMetadata>. That way we can pass ownership to the Resource. We could use std::move with ShaderMetadata but that isn't enforced like unique_ptr is. It's only a nit since it only effects runtime effect's performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 187 to 191
virtual bool BindResource(ShaderStage stage,
DescriptorType type,
const ShaderUniformSlot& slot,
const ShaderMetadata& metadata,
BufferView view);
Copy link
Member

Choose a reason for hiding this comment

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

This is so close to the other BindResource, it's probably worth documenting.

Comment on lines 209 to 215
bool BindResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler);

Copy link
Member

Choose a reason for hiding this comment

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

Same thing here, worth documenting since it's not obvious the difference with the other one.

Comment on lines 130 to 159
if (!sampler) {
return false;
}
if (!texture || !texture->IsValid()) {
return false;
}

switch (stage) {
case ShaderStage::kVertex:
vertex_bindings.sampled_images.emplace_back(TextureAndSampler{
.slot = slot,
.texture = TextureResource::MakeDynamic(metadata, std::move(texture)),
.sampler = &sampler,
});
return true;
case ShaderStage::kFragment:
fragment_bindings.sampled_images.emplace_back(TextureAndSampler{
.slot = slot,
.texture = TextureResource::MakeDynamic(metadata, std::move(texture)),
.sampler = &sampler,
});
return true;
case ShaderStage::kCompute:
VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
case ShaderStage::kUnknown:
return false;
}

return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Please remove duplication with the above method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jonahwilliams
Copy link
Contributor Author

Changed the binding methods to BindDynamic* so its not just an overload anymore

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!

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 27, 2024
@auto-submit auto-submit bot merged commit ba112ad into flutter:main Nov 27, 2024
31 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 27, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 27, 2024
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…ers. (flutter/engine#56827)

Should fix flutter#159520 ~~but I still need to check locally.~~ Seems to do the trick.

All cmd bindings were copying the shader metadata, which meant allocating/de-allocating a lot of strings per draw.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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] gles spending a lot of time in ~basic_string

2 participants