Account for vec3 padding in Metal#181563
Conversation
This reverts commit 686d632.
There was a problem hiding this comment.
Code Review
This pull request introduces changes to handle Metal's padding requirements for uniform buffers. The changes include adding target_platform to Reflector::Options, including runtime_stage_types_flatbuffers.h, adding padding layout logic for Metal, renaming struct_layout to padding_layout, introducing GetDartSize() and GetGPUSize() to RuntimeUniformDescription, and modifying EmplaceUniform to repack uniform data based on padding_layout. The reviewer notes that the introduction of GetDartSize() and GetGPUSize() improves clarity and correctness, and the updated EmplaceUniform function correctly implements the logic for repacking uniform data when a padding_layout is specified. The reviewer also points out that many tests are being skipped on Mac Metal and suggests that the root cause of these failures should be understood and addressed.
| size_t RuntimeUniformDescription::GetDartSize() const { | ||
| size_t size = 0; | ||
| if (!padding_layout.empty()) { | ||
| for (impeller::RuntimePaddingType byte_type : padding_layout) { | ||
| if (byte_type == RuntimePaddingType::kFloat) { | ||
| size += sizeof(float); | ||
| } | ||
| } | ||
| } else { | ||
| size = dimensions.rows * dimensions.cols * bit_width / 8u; | ||
| } | ||
| if (array_elements.value_or(0) > 0) { | ||
| // Covered by check on the line above. | ||
| // NOLINTNEXTLINE(bugprone-unchecked-optional-access) | ||
| size *= array_elements.value(); | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| size_t RuntimeUniformDescription::GetGPUSize() const { | ||
| size_t size = 0; | ||
| if (padding_layout.empty()) { | ||
| size = dimensions.rows * dimensions.cols * bit_width / 8u; | ||
| } else { | ||
| size = sizeof(float) * padding_layout.size(); | ||
| } | ||
| if (array_elements.value_or(0) > 0) { | ||
| // Covered by check on the line above. | ||
| // NOLINTNEXTLINE(bugprone-unchecked-optional-access) | ||
| size *= array_elements.value(); | ||
| } | ||
| size += sizeof(float) * struct_layout.size(); | ||
| return size; | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
Omg now please call me handsome as well
| // static | ||
| BufferView RuntimeEffectContents::EmplaceVulkanUniform( | ||
| const std::shared_ptr<const std::vector<uint8_t>>& input_data, | ||
| BufferView RuntimeEffectContents::EmplaceUniform( | ||
| const uint8_t* source_data, | ||
| HostBuffer& data_host_buffer, | ||
| const RuntimeUniformDescription& uniform, | ||
| size_t minimum_uniform_alignment) { | ||
| // TODO(jonahwilliams): rewrite this to emplace directly into | ||
| // HostBuffer. | ||
| std::vector<float> uniform_buffer; | ||
| uniform_buffer.reserve(uniform.struct_layout.size()); | ||
| size_t uniform_byte_index = 0u; | ||
| for (char byte_type : uniform.struct_layout) { | ||
| if (byte_type == kPaddingType) { | ||
| uniform_buffer.push_back(0.f); | ||
| } else { | ||
| FML_DCHECK(byte_type == kFloatType); | ||
| uniform_buffer.push_back(reinterpret_cast<const float*>( | ||
| input_data->data())[uniform_byte_index++]); | ||
| } | ||
| const RuntimeUniformDescription& uniform) { | ||
| size_t minimum_uniform_alignment = | ||
| data_host_buffer.GetMinimumUniformAlignment(); | ||
| size_t alignment = std::max(uniform.bit_width / 8, minimum_uniform_alignment); | ||
|
|
||
| if (uniform.padding_layout.empty()) { | ||
| return data_host_buffer.Emplace(source_data, uniform.GetGPUSize(), | ||
| alignment); | ||
| } | ||
|
|
||
| // If the uniform has a padding layout, we need to repack the data. | ||
| // We can do this by using the EmplaceProc to write directly to the | ||
| // HostBuffer. | ||
| return data_host_buffer.Emplace( | ||
| reinterpret_cast<const void*>(uniform_buffer.data()), | ||
| sizeof(float) * uniform_buffer.size(), minimum_uniform_alignment); | ||
| uniform.GetGPUSize(), alignment, | ||
| [&uniform, source_data](uint8_t* destination) { | ||
| size_t count = uniform.array_elements.value_or(1); | ||
| if (count == 0) { | ||
| // Make sure to run at least once. | ||
| count = 1; | ||
| } | ||
| size_t uniform_byte_index = 0u; | ||
| size_t struct_float_index = 0u; | ||
| auto* float_destination = reinterpret_cast<float*>(destination); | ||
| auto* float_source = reinterpret_cast<const float*>(source_data); | ||
|
|
||
| for (size_t i = 0; i < count; i++) { | ||
| for (RuntimePaddingType byte_type : uniform.padding_layout) { | ||
| if (byte_type == RuntimePaddingType::kPadding) { | ||
| float_destination[struct_float_index++] = 0.f; | ||
| } else { | ||
| FML_DCHECK(byte_type == RuntimePaddingType::kFloat); | ||
| float_destination[struct_float_index++] = | ||
| float_source[uniform_byte_index++]; | ||
| } | ||
| } | ||
| } | ||
| }); |
|
autosubmit label was removed for flutter/flutter/181563, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Roll Flutter from dfd92b773219 to da72d5936d69 (39 revisions) flutter/flutter@dfd92b7...da72d59 2026-01-29 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[ Tool / Engine ] Cleanup x86 references (#181152)" (flutter/flutter#181643) 2026-01-29 [email protected] Roll Skia from 174db42b7300 to 89df65f8324c (2 revisions) (flutter/flutter#181636) 2026-01-29 [email protected] [material/menu_anchor.dart] Add animations to MenuAnchor. (flutter/flutter#176494) 2026-01-28 [email protected] Roll Skia from 8e09f8a82251 to 174db42b7300 (6 revisions) (flutter/flutter#181627) 2026-01-28 [email protected] Send statusBarTouch events via dedicated messages (flutter/flutter#179643) 2026-01-28 [email protected] test: Improve DropdownMenuFormField tests (flutter/flutter#181369) 2026-01-28 [email protected] Account for vec3 padding in Metal (flutter/flutter#181563) 2026-01-28 [email protected] [ Tool / Engine ] Cleanup x86 references (flutter/flutter#181152) 2026-01-28 [email protected] Fix the issue on macOS where, after a hot restart with multiple windows, unresponsive windows are left behind. (flutter/flutter#180287) 2026-01-28 [email protected] Roll Skia from 675444e94bc9 to 8e09f8a82251 (7 revisions) (flutter/flutter#181606) 2026-01-28 [email protected] Roll Packages from e37af11 to 1cb2148 (5 revisions) (flutter/flutter#181608) 2026-01-28 [email protected] fix: swap app and engine version in vk::ApplicationInfo (flutter/flutter#181432) 2026-01-28 [email protected] Adds impeller backend to skia gold client (flutter/flutter#181503) 2026-01-28 [email protected] Remove chrome_and_driver dependency where it's not needed (flutter/flutter#178174) 2026-01-28 [email protected] chore: Windows_mokey basic_material_app_win__compile !bringup (flutter/flutter#180985) 2026-01-28 [email protected] Fix generating both `settings.gradle` and `settings.gradle.kts` for plugins (flutter/flutter#181592) 2026-01-28 [email protected] Roll Skia from 6614f89de521 to 675444e94bc9 (3 revisions) (flutter/flutter#181587) 2026-01-28 [email protected] Fix `todayBorder` todayBorder color is incorrectly overridden by `todayForegroundColor` in CalendarDatePicker (flutter/flutter#178792) 2026-01-28 [email protected] Roll Skia from 8f1695a4b328 to 6614f89de521 (2 revisions) (flutter/flutter#181583) 2026-01-28 [email protected] feat: add RoundedSuperellipseInputBorder (flutter/flutter#177220) 2026-01-28 [email protected] Roll Dart SDK from 38e351498549 to f10dcbfca98f (2 revisions) (flutter/flutter#181582) 2026-01-28 [email protected] Roll Skia from f424d58e37a3 to 8f1695a4b328 (6 revisions) (flutter/flutter#181577) 2026-01-28 [email protected] Remove unused code paths in `PlatformViewsController.java` (flutter/flutter#181393) 2026-01-28 [email protected] feat: add onEnd to AnimatedCrossFade (flutter/flutter#181455) 2026-01-28 [email protected] Don't pass bounds to saveLayer call when painting ImageFilter (flutter/flutter#181353) 2026-01-28 [email protected] test: Clarify failure messages on gestures/debug_test.dart (flutter/flutter#181109) 2026-01-27 [email protected] Roll Fuchsia Linux SDK from akraNGn2lw4T1msgZ... to adhoq9ouVRh0xzkm3... (flutter/flutter#181571) 2026-01-27 [email protected] Roll Dart SDK from 4c7cb0a1d07d to 38e351498549 (4 revisions) (flutter/flutter#181570) 2026-01-27 [email protected] Make sure that an AnimatedPadding doesn't crash in 0x0 environment (flutter/flutter#181235) 2026-01-27 [email protected] Make sure that an ImageFiltered doesn't crash at 0x0 environment (flutter/flutter#181067) 2026-01-27 [email protected] Marks firebase_release_smoke_test to be unflaky (flutter/flutter#181308) 2026-01-27 [email protected] Fix remove material import box decoration test (flutter/flutter#181253) 2026-01-27 [email protected] Roll Skia from c2754838b077 to f424d58e37a3 (8 revisions) (flutter/flutter#181564) 2026-01-27 [email protected] Make sure that an AnimatedAlign doesn't crash in 0x0 environment (flutter/flutter#181361) 2026-01-27 [email protected] Make sure that an ImageIcon doesn't crash in 0x0 environment (flutter/flutter#181099) 2026-01-27 [email protected] Make sure that an AnimatedContainer doesn't crash in 0x0 environment (flutter/flutter#181198) 2026-01-27 [email protected] Make sure that an AnimatedRotation doesn't crash in 0x0 environment (flutter/flutter#181486) 2026-01-27 [email protected] Make sure that an AnimatedPositionedDirectional doesn't crash in 0x0 … (flutter/flutter#181451) 2026-01-27 [email protected] Merge changelog for 3.38.8. (flutter/flutter#181558) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. ...
Re-landing of flutter#181340 incorporating flutter#181550. Vec3 uniforms on the metal backend are vec4-aligned. This PR accounts for that padding. --------- Co-authored-by: gaaclarke <[email protected]>
Re-landing of flutter#181340 incorporating flutter#181550. Vec3 uniforms on the metal backend are vec4-aligned. This PR accounts for that padding. --------- Co-authored-by: gaaclarke <[email protected]>
Reland `Enabled some disabled impeller fragment shader dart tests` (flutter#180788) relands flutter#180759 changes since revert: 1) waits for async tests now 1) keeps 2 tests that don't pass on impeller disabled - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Enables fragment shader test for impeller (fixes mat2 on vulkan) (flutter#181013) This rearranges the packing of mat2 fields in structs which was causing an existing fragment shader test to fail. The test still doesn't work on Metal, but this PR fixes it for Vulkan. I suspect the fix for metal may be similar but since the uniforms aren't in a virtual struct the code isn't hitting this fix. issue: flutter#180873 - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Account for vec3 padding in Metal (flutter#181563) Re-landing of flutter#181340 incorporating flutter#181550. Vec3 uniforms on the metal backend are vec4-aligned. This PR accounts for that padding. --------- Co-authored-by: gaaclarke <[email protected]> Fixes getUniformX for Vulkan (flutter#181286) Does what it says on the tin! This PR adds struct member information to the runtime flatbuffer format. This allows dart code to introspect structs at runtime. Also modifies the runtime_stage tests to verify formats for all supported uniform types. Bubbles up struct member information to dart, and uses that information to grab struct members in `getUniformX` related functions. This is necessary on Vulkan because all uniforms are packaged into a single struct. Also re-enables tests - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. Organize and update fragment shader uniform tests. (flutter#181822) Adds more comprehensive testing for setFloat and getUniform* on fragment shaders. Deletes redundant tests. Fixes getUniformVecX indexing errors. Update web ui fragment shader tests (flutter#181877) Adds a bunch of tests for uniform setting functionality for custom fragment shaders on the web. Deletes redundant tests. Fixes a discovered issue in the uniform offset calculation. We were previously using the `location`, which is the integer offset of the uniform, not the offset in floats.
Reland `Enabled some disabled impeller fragment shader dart tests` (flutter#180788) relands flutter#180759 changes since revert: 1) waits for async tests now 1) keeps 2 tests that don't pass on impeller disabled - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Enables fragment shader test for impeller (fixes mat2 on vulkan) (flutter#181013) This rearranges the packing of mat2 fields in structs which was causing an existing fragment shader test to fail. The test still doesn't work on Metal, but this PR fixes it for Vulkan. I suspect the fix for metal may be similar but since the uniforms aren't in a virtual struct the code isn't hitting this fix. issue: flutter#180873 - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Account for vec3 padding in Metal (flutter#181563) Re-landing of flutter#181340 incorporating flutter#181550. Vec3 uniforms on the metal backend are vec4-aligned. This PR accounts for that padding. --------- Co-authored-by: gaaclarke <[email protected]> Fixes getUniformX for Vulkan (flutter#181286) Does what it says on the tin! This PR adds struct member information to the runtime flatbuffer format. This allows dart code to introspect structs at runtime. Also modifies the runtime_stage tests to verify formats for all supported uniform types. Bubbles up struct member information to dart, and uses that information to grab struct members in `getUniformX` related functions. This is necessary on Vulkan because all uniforms are packaged into a single struct. Also re-enables tests - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. Organize and update fragment shader uniform tests. (flutter#181822) Adds more comprehensive testing for setFloat and getUniform* on fragment shaders. Deletes redundant tests. Fixes getUniformVecX indexing errors. Update web ui fragment shader tests (flutter#181877) Adds a bunch of tests for uniform setting functionality for custom fragment shaders on the web. Deletes redundant tests. Fixes a discovered issue in the uniform offset calculation. We were previously using the `location`, which is the integer offset of the uniform, not the offset in floats.
Re-landing of #181340 incorporating #181550.
Vec3 uniforms on the metal backend are vec4-aligned. This PR accounts for that padding.