-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Store Buffer/Texture bindings in vector instead of map. #48719
Conversation
static constexpr auto kResource{{camel_case(sampled_image.name)}} = ShaderUniformSlot { // {{sampled_image.name}} | ||
"{{sampled_image.name}}", // name | ||
{{sampled_image.ext_res_0}}u, // texture | ||
{{sampled_image.ext_res_1}}u, // sampler |
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 was unused
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, this is a step backwards in readability where people used to use texture_index
and are now using ext_res_0
. It would be nice if we could come up with a better name there.
std::vector<vk::DescriptorImageInfo>& images, | ||
std::vector<vk::WriteDescriptorSet>& writes) { | ||
for (const auto& [index, data] : bindings.sampled_images) { | ||
for (const auto& data : bindings.sampled_images) { |
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.
remove auto please
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.
Done
barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal; | ||
|
||
for (const auto& [_, data] : bindings.sampled_images) { | ||
for (const auto& data : bindings.sampled_images) { |
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.
auto
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.
Done
barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal; | ||
|
||
for (const auto& [_, data] : bindings.sampled_images) { | ||
for (const auto& data : bindings.sampled_images) { |
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.
auto
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.
Done
template <typename T> | ||
typename T::FragInfo* GetFragInfo(const Command& command) { | ||
auto resource = command.fragment_bindings.buffers.find(0u); | ||
auto resource = std::find_if(command.fragment_bindings.buffers.begin(), |
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.
So we are getting linear search here hopefully? This should be faster for the small sizes we have.
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 is just for testing, so performance doesnt matter as much
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 dont ever have to look up particular bindings, we just iterate through the set of bindings and bind each one.
{{sampled_image.ext_res_0}}u, // texture | ||
{{sampled_image.ext_res_1}}u, // sampler | ||
{{sampled_image.binding}}u, // binding | ||
{{sampled_image.ext_res_0}}u, // ext_res_0 |
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.
Can we have a better name for this? This represents which texture unit this will be bound to right? ext_res_0
doesn't mean anything to me and seems to be a Metal-ism?
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.
Back to texture_index, with a note that this is ext_res_0
RE: ext_res_0 being a terrible name, I agree. I could call it |
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.
Okay, I looked through this a bit more. I don't like us removing SampledImageSlot
and using ShaderUniformSlot
instead, it's weird and the names don't match up. If we wanted to unify them we should create something that has more generic names.
What I do like in this change though is switching to a vector for storage and removing the unused field. I would prefer we keep those changes but also keep SampledImageSlot
.
SG, will do that |
My only problem was the previous names was that |
I mean if we wanted to be super efficient this could be a uniform since a backend will only ever use one of them. |
The index/binding are the values we set to configure the uniforms. It is technically a constant per backend, but since we support multiple backends on the same platform we'd need to content with some kind of runtime look up for the value. The current approach solves the problem by making the shader metadata just be the union of all backend specific binding values, which works OK for now. |
By the current approach I don't mean this PR, just the overall design. |
Sorry, i said uniform but I meant union. This is what I was thinking. struct VulkanSampledImageIndices {
size_t texture_and_sampler_index;
size_t descriptor_set_index;
};
struct SampledImageSlot {
const char* name;
union {
size_t metal_texture_index;
VulkanSampledImageIndices vulkan_indices;
}
}; BTW, it looks like |
Right, that is more or less what this data is. the caveat is that the command code doesn't know what backend its running from. Also for a bonus caveat, the GLES binding number has to be looked up at runtime, and requires us to use the separate ShaderMetaData struct + name. |
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!
@gaaclarke maybe next year when I'm feeling more ambitious we can sit down and figure out how to make the binding code ... better 😆 |
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. |
test-exempt: code refactor with no semantic change |
…139716) flutter/engine@347f506...82de334 2023-12-07 jason-simmons@users.noreply.github.com Revert "Replace use of Fontmgr::RefDefault with explicit creation calls" (flutter/engine#48755) 2023-12-07 skia-flutter-autoroll@skia.org Roll Skia from 2abb01e18ab3 to 8ebf43ba1c09 (1 revision) (flutter/engine#48761) 2023-12-07 skia-flutter-autoroll@skia.org Roll Dart SDK from dbfe4e3f867e to be8a95b6717d (1 revision) (flutter/engine#48757) 2023-12-06 godofredoc@google.com Remove obsolete properties. (flutter/engine#48753) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 7ff0103760d0 to 2abb01e18ab3 (1 revision) (flutter/engine#48751) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 570103e08087 to 7ff0103760d0 (1 revision) (flutter/engine#48748) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 326bdc97ac40 to 570103e08087 (1 revision) (flutter/engine#48746) 2023-12-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 6eb13603c212 to dbfe4e3f867e (1 revision) (flutter/engine#48745) 2023-12-06 jonahwilliams@google.com [Impeller] Store Buffer/Texture bindings in vector instead of map. (flutter/engine#48719) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 33cba437bf70 to 326bdc97ac40 (2 revisions) (flutter/engine#48743) 2023-12-06 jason-simmons@users.noreply.github.com [Impeller] Provide the clear color to an advanced blend if it was optimized out (flutter/engine#48646) 2023-12-06 737941+loic-sharma@users.noreply.github.com [Windows] Set swap interval on raster thread after startup (flutter/engine#47787) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 384d14063dc1 to 33cba437bf70 (3 revisions) (flutter/engine#48740) 2023-12-06 737941+loic-sharma@users.noreply.github.com [Windows] Refactor the GLES proc table (flutter/engine#48688) 2023-12-06 kjlubick@users.noreply.github.com Replace use of Fontmgr::RefDefault with explicit creation calls (flutter/engine#48571) 2023-12-06 jonahwilliams@google.com [Impeller] disable entity culling by default. (flutter/engine#48717) 2023-12-06 skia-flutter-autoroll@skia.org Roll Skia from 23e1cb20a6b5 to 384d14063dc1 (1 revision) (flutter/engine#48738) 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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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
Places the binding data in a vector, since they key was only meaningful on metal but not used anywhere. I don't think that we need to specificially handle the case where our own contents bind the same contents multiple times, but interested to discuss if folks disagree.