Turns on most of fragment_shader_test.dart for opengles#182229
Conversation
|
Failing here now: |
|
Addressed previous problem, now we have: |
We'll fix those in a different PR, skipped for now. |
There was a problem hiding this comment.
Code Review
This pull request enables the fragment_shader_test.dart for the OpenGL ES backend by upgrading the test environment to GLES 3.0 and refactors uniform binding to use specific uniform types (e.g., vec4, mat2) instead of byte size, resolving ambiguities. While this change addresses functional issues, it introduces two security vulnerabilities: a Denial of Service (crash) due to unvalidated access to an optional value when encountering unsupported shader dimensions, and an out-of-bounds read due to the removal of member size validation. Both issues can be triggered by malformed or malicious shader assets. Additionally, the review includes suggestions to handle non-square matrices and to correct the sizes used in a unit test for better accuracy and clarity.
| switch (member.float_type.value()) { | ||
| case ShaderFloatType::kFloat: | ||
| gl.Uniform1fv(location, element_count, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kVec2: | ||
| gl.Uniform2fv(location, element_count, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kVec3: | ||
| gl.Uniform3fv(location, element_count, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kVec4: | ||
| gl.Uniform4fv(location, element_count, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kMat2: | ||
| gl.UniformMatrix2fv(location, element_count, GL_FALSE, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kMat3: | ||
| gl.UniformMatrix3fv(location, element_count, GL_FALSE, buffer_data); | ||
| break; | ||
| case ShaderFloatType::kMat4: | ||
| gl.UniformMatrix4fv(location, element_count, GL_FALSE, buffer_data); | ||
| break; | ||
| } |
There was a problem hiding this comment.
The PR removed the size-based validation of uniform members that was present in the previous implementation. The new implementation blindly calls gl.UniformNfv (and other variants) based on the float_type without verifying that the actual member size (member.size) is sufficient for the type. If a malicious shader asset specifies a kFloat type with a small bit_width (e.g., 0), member.size will be 0, but gl.UniformNfv will still attempt to read data from the buffer, leading to an out-of-bounds read from the heap. This can cause a crash or potentially leak sensitive information from the engine process to the GPU.
| return false; | ||
| FML_DCHECK(member.float_type.has_value()); | ||
|
|
||
| switch (member.float_type.value()) { |
There was a problem hiding this comment.
The code assumes that all kFloat uniforms will have a valid float_type set. However, MakeShaderMetadata in runtime_effect_contents.cc only sets float_type for a specific set of dimensions (scalars, vectors, and square matrices). If a shader asset (.iplr) contains a kFloat uniform with other dimensions (e.g., a non-square matrix like mat3x2), float_type will be nullopt. Calling .value() on this nullopt in BindUniformBufferV2 will cause a crash in release builds, leading to a Denial of Service (DoS) vulnerability when loading malformed or malicious shader assets.
| if (shader_type == ShaderType::kFloat) { | ||
| if (uniform.dimensions.cols == 1) { | ||
| switch (uniform.dimensions.rows) { | ||
| case 1: | ||
| float_type = ShaderFloatType::kFloat; | ||
| break; | ||
| case 2: | ||
| float_type = ShaderFloatType::kVec2; | ||
| break; | ||
| case 3: | ||
| float_type = ShaderFloatType::kVec3; | ||
| break; | ||
| case 4: | ||
| float_type = ShaderFloatType::kVec4; | ||
| break; | ||
| } | ||
| } else if (uniform.dimensions.rows == uniform.dimensions.cols) { | ||
| switch (uniform.dimensions.rows) { | ||
| case 2: | ||
| float_type = ShaderFloatType::kMat2; | ||
| break; | ||
| case 3: | ||
| float_type = ShaderFloatType::kMat3; | ||
| break; | ||
| case 4: | ||
| float_type = ShaderFloatType::kMat4; | ||
| break; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This logic for determining ShaderFloatType only handles vectors (cols == 1) and square matrices (rows == cols). It doesn't account for non-square matrices (e.g., mat2x3, mat3x2). If such a uniform is used, float_type will remain uninitialized, leading to a DCHECK failure in BufferBindingsGLES::BindUniformBufferV2.
Consider adding support for non-square matrices or, if they are not intended to be supported, add a FML_DCHECK here to validate that only supported uniform dimensions are processed. This would provide an earlier and clearer failure.
| make_metadata( | ||
| ShaderFloatType::kMat2, "mat2", | ||
| sizeof(Matrix)), // Simplification: Render logic usually passes | ||
| // full matrix size or appropriate data | ||
| make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(Matrix)), | ||
| make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)), |
There was a problem hiding this comment.
The use of sizeof(Matrix) for mat2 and mat3 uniform sizes is incorrect and misleading. sizeof(Matrix) corresponds to a 4x4 matrix (64 bytes), while mat2 is 16 bytes and mat3 is 36 bytes.
While this may not fail the current test, it makes the test setup inaccurate and hard to understand. Please use the correct sizes for these matrix types to improve correctness and clarity. The comment on line 133 is also confusing and should probably be removed or clarified.
| make_metadata( | |
| ShaderFloatType::kMat2, "mat2", | |
| sizeof(Matrix)), // Simplification: Render logic usually passes | |
| // full matrix size or appropriate data | |
| make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(Matrix)), | |
| make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)), | |
| make_metadata(ShaderFloatType::kMat2, "mat2", sizeof(float) * 4), | |
| make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(float) * 9), | |
| make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)), |
3a67852 to
df9230f
Compare
b-luk
left a comment
There was a problem hiding this comment.
All the changes locally make sense to me. But I admit that I don't really have a great idea of how all the different classes and methods involved here fit together.
| make_metadata( | ||
| ShaderFloatType::kMat2, "mat2", | ||
| sizeof(Matrix)), // Simplification: Render logic usually passes | ||
| // full matrix size or appropriate data | ||
| make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(Matrix)), | ||
| make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)), |
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
note: I walked benson through this pr on gvc |
|
autosubmit label was removed for flutter/flutter/182229, because - The status or check suite Linux linux_host_engine_test has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/182229, 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 9bda20a11f1e to 6e4a481bdf27 (103 revisions) flutter/flutter@9bda20a...6e4a481 2026-02-17 [email protected] Fix iOS CI tests for Xcode 26 Swift compatibility (flutter/flutter#182132) 2026-02-17 [email protected] Revert "[Android] Add mechanism for setting Android engine flags via … (flutter/flutter#182388) 2026-02-17 [email protected] Roll Skia from 4ed9faf843e6 to dfe78d132e24 (1 revision) (flutter/flutter#182485) 2026-02-17 [email protected] Roll Skia from ff0af46bf172 to 4ed9faf843e6 (2 revisions) (flutter/flutter#182483) 2026-02-17 [email protected] Roll Skia from 24c7b6f5760f to ff0af46bf172 (1 revision) (flutter/flutter#182481) 2026-02-16 [email protected] Roll Dart SDK from ff57548fcf54 to 44895e617182 (1 revision) (flutter/flutter#182479) 2026-02-16 [email protected] Roll Fuchsia Linux SDK from YND8TyaxKkkkEvlD9... to mcN42vw48OPH3JDNm... (flutter/flutter#182478) 2026-02-16 [email protected] Roll Dart SDK from c819ebe0cbe3 to ff57548fcf54 (1 revision) (flutter/flutter#182472) 2026-02-16 [email protected] feat: add routes support in TestWidgetsApp (flutter/flutter#181695) 2026-02-16 [email protected] Roll Skia from 5c8a6641902f to 24c7b6f5760f (1 revision) (flutter/flutter#182467) 2026-02-16 [email protected] Roll Skia from 94d5d5e5f785 to 5c8a6641902f (6 revisions) (flutter/flutter#182463) 2026-02-16 [email protected] Roll Dart SDK from f2289e13a20a to c819ebe0cbe3 (1 revision) (flutter/flutter#182462) 2026-02-15 [email protected] Roll Dart SDK from 294e6e248512 to f2289e13a20a (1 revision) (flutter/flutter#182448) 2026-02-15 [email protected] Roll Skia from b7cea4cbe546 to 94d5d5e5f785 (1 revision) (flutter/flutter#182446) 2026-02-15 [email protected] Roll Fuchsia Linux SDK from pkyhAZ3sQZDzeNZym... to YND8TyaxKkkkEvlD9... (flutter/flutter#182445) 2026-02-15 [email protected] Roll Skia from a3a82d359a7b to b7cea4cbe546 (1 revision) (flutter/flutter#182439) 2026-02-15 [email protected] Roll Skia from a147ae2d4adc to a3a82d359a7b (1 revision) (flutter/flutter#182435) 2026-02-15 [email protected] Roll Dart SDK from f82ec89435f5 to 294e6e248512 (1 revision) (flutter/flutter#182432) 2026-02-14 [email protected] Roll Skia from 91d158b0a61e to a147ae2d4adc (2 revisions) (flutter/flutter#182424) 2026-02-14 [email protected] Roll Fuchsia Linux SDK from V30FBkJySjFKXwVjW... to pkyhAZ3sQZDzeNZym... (flutter/flutter#182423) 2026-02-14 [email protected] Roll Skia from e5a18f8f0d4a to 91d158b0a61e (1 revision) (flutter/flutter#182422) 2026-02-14 [email protected] Roll Dart SDK from 7a2a28dbd0d4 to f82ec89435f5 (2 revisions) (flutter/flutter#182414) 2026-02-14 [email protected] Roll Skia from befeec673f1b to e5a18f8f0d4a (1 revision) (flutter/flutter#182412) 2026-02-14 [email protected] Roll Skia from 7dc3ba9b1d90 to befeec673f1b (1 revision) (flutter/flutter#182408) 2026-02-14 [email protected] [Web] Fix IME and selection by syncing more text styles (flutter/flutter#180436) 2026-02-14 [email protected] Roll Skia from bb69b5b71b4f to 7dc3ba9b1d90 (2 revisions) (flutter/flutter#182401) 2026-02-14 [email protected] Disable multithread opengles, enables remaining fragment shader tests (flutter/flutter#182384) 2026-02-14 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Standardize on Test* widgets in *_tester.dart files (#182395)" (flutter/flutter#182406) 2026-02-14 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix cross imports for all Cupertino tests (#181634)" (flutter/flutter#182404) 2026-02-13 [email protected] Add await to tester.pump callsites (flutter/flutter#182398) 2026-02-13 [email protected] refactor: Centralize table formatting logic into a new `formatTable` utility function. (flutter/flutter#182196) 2026-02-13 [email protected] Adds impeller backend to golden workspace name (flutter/flutter#182387) 2026-02-13 [email protected] Standardize on Test* widgets in *_tester.dart files (flutter/flutter#182395) 2026-02-13 [email protected] Remove Material dependency from transformed_scrollable_test.dart (flutter/flutter#182141) 2026-02-13 [email protected] Fix cross imports for all Cupertino tests (flutter/flutter#181634) 2026-02-13 [email protected] remove MaterialApp import from raw_radio_test.dart (flutter/flutter#181721) 2026-02-13 [email protected] Roll Skia from e2991aa99710 to bb69b5b71b4f (37 revisions) (flutter/flutter#182390) 2026-02-13 [email protected] Turns on most of fragment_shader_test.dart for opengles (flutter/flutter#182229) 2026-02-13 [email protected] Update `CHANGELOG` for 3.41.1 release (flutter/flutter#182393) 2026-02-13 [email protected] Remove Material dependency from semantics_keep_alive_offstage_test.dart (flutter/flutter#182211) 2026-02-13 [email protected] Update iOS/macOS plugin template to add dependency on FlutterFramework (flutter/flutter#181416) 2026-02-13 [email protected] Add plugin dependencies to Add to App FlutterPluginRegistrant (flutter/flutter#182304) 2026-02-13 [email protected] Preparation to add contentTextStyle flag to SimpleDialog. (flutter/flutter#182200) 2026-02-13 [email protected] Roll Packages from af1d610 to 09104b0 (4 revisions) (flutter/flutter#182383) 2026-02-13 [email protected] Roll Dart SDK from de5915148fde to 7a2a28dbd0d4 (2 revisions) (flutter/flutter#182380) 2026-02-13 [email protected] [Impeller] Dispose thread local caches on each frame when using GPUSurfaceVulkanImpeller with a delegate (flutter/flutter#182265) ...
fixes flutter#182106 Changes: - started running the tests against opengles 3, which matches the version of the test shaders - fixed binging uniforms on opengles so it's based on it's type, not it's size (since vec4 and mat2 have the same size for instance) - fixed for builtin shaders - fixed for runtime shaders - expands our opengles mocking to include more uniform setters - skips the handful of tests that still don't work Now builtin shader headers look something like this. You can see this information didn't exist and was not derivable based on the existing information in all cases: ```c++ ShaderMetadata Shader::kMetadataFrameInfo = { "FrameInfo", // name std::vector<ShaderStructMemberMetadata> { ShaderStructMemberMetadata { /*type=*/ShaderType::kFloat, /*name=*/"mvp", /*offset=*/0, /*size=*/64, /*byte_length=*/64, /*array_elements=*/std::nullopt, /*float_type=*/ShaderFloatType::kMat4, // <-- new }, ``` ## Pre-launch Checklist - [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
…er#11041) Roll Flutter from 9bda20a11f1e to 6e4a481bdf27 (103 revisions) flutter/flutter@9bda20a...6e4a481 2026-02-17 [email protected] Fix iOS CI tests for Xcode 26 Swift compatibility (flutter/flutter#182132) 2026-02-17 [email protected] Revert "[Android] Add mechanism for setting Android engine flags via … (flutter/flutter#182388) 2026-02-17 [email protected] Roll Skia from 4ed9faf843e6 to dfe78d132e24 (1 revision) (flutter/flutter#182485) 2026-02-17 [email protected] Roll Skia from ff0af46bf172 to 4ed9faf843e6 (2 revisions) (flutter/flutter#182483) 2026-02-17 [email protected] Roll Skia from 24c7b6f5760f to ff0af46bf172 (1 revision) (flutter/flutter#182481) 2026-02-16 [email protected] Roll Dart SDK from ff57548fcf54 to 44895e617182 (1 revision) (flutter/flutter#182479) 2026-02-16 [email protected] Roll Fuchsia Linux SDK from YND8TyaxKkkkEvlD9... to mcN42vw48OPH3JDNm... (flutter/flutter#182478) 2026-02-16 [email protected] Roll Dart SDK from c819ebe0cbe3 to ff57548fcf54 (1 revision) (flutter/flutter#182472) 2026-02-16 [email protected] feat: add routes support in TestWidgetsApp (flutter/flutter#181695) 2026-02-16 [email protected] Roll Skia from 5c8a6641902f to 24c7b6f5760f (1 revision) (flutter/flutter#182467) 2026-02-16 [email protected] Roll Skia from 94d5d5e5f785 to 5c8a6641902f (6 revisions) (flutter/flutter#182463) 2026-02-16 [email protected] Roll Dart SDK from f2289e13a20a to c819ebe0cbe3 (1 revision) (flutter/flutter#182462) 2026-02-15 [email protected] Roll Dart SDK from 294e6e248512 to f2289e13a20a (1 revision) (flutter/flutter#182448) 2026-02-15 [email protected] Roll Skia from b7cea4cbe546 to 94d5d5e5f785 (1 revision) (flutter/flutter#182446) 2026-02-15 [email protected] Roll Fuchsia Linux SDK from pkyhAZ3sQZDzeNZym... to YND8TyaxKkkkEvlD9... (flutter/flutter#182445) 2026-02-15 [email protected] Roll Skia from a3a82d359a7b to b7cea4cbe546 (1 revision) (flutter/flutter#182439) 2026-02-15 [email protected] Roll Skia from a147ae2d4adc to a3a82d359a7b (1 revision) (flutter/flutter#182435) 2026-02-15 [email protected] Roll Dart SDK from f82ec89435f5 to 294e6e248512 (1 revision) (flutter/flutter#182432) 2026-02-14 [email protected] Roll Skia from 91d158b0a61e to a147ae2d4adc (2 revisions) (flutter/flutter#182424) 2026-02-14 [email protected] Roll Fuchsia Linux SDK from V30FBkJySjFKXwVjW... to pkyhAZ3sQZDzeNZym... (flutter/flutter#182423) 2026-02-14 [email protected] Roll Skia from e5a18f8f0d4a to 91d158b0a61e (1 revision) (flutter/flutter#182422) 2026-02-14 [email protected] Roll Dart SDK from 7a2a28dbd0d4 to f82ec89435f5 (2 revisions) (flutter/flutter#182414) 2026-02-14 [email protected] Roll Skia from befeec673f1b to e5a18f8f0d4a (1 revision) (flutter/flutter#182412) 2026-02-14 [email protected] Roll Skia from 7dc3ba9b1d90 to befeec673f1b (1 revision) (flutter/flutter#182408) 2026-02-14 [email protected] [Web] Fix IME and selection by syncing more text styles (flutter/flutter#180436) 2026-02-14 [email protected] Roll Skia from bb69b5b71b4f to 7dc3ba9b1d90 (2 revisions) (flutter/flutter#182401) 2026-02-14 [email protected] Disable multithread opengles, enables remaining fragment shader tests (flutter/flutter#182384) 2026-02-14 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Standardize on Test* widgets in *_tester.dart files (#182395)" (flutter/flutter#182406) 2026-02-14 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix cross imports for all Cupertino tests (#181634)" (flutter/flutter#182404) 2026-02-13 [email protected] Add await to tester.pump callsites (flutter/flutter#182398) 2026-02-13 [email protected] refactor: Centralize table formatting logic into a new `formatTable` utility function. (flutter/flutter#182196) 2026-02-13 [email protected] Adds impeller backend to golden workspace name (flutter/flutter#182387) 2026-02-13 [email protected] Standardize on Test* widgets in *_tester.dart files (flutter/flutter#182395) 2026-02-13 [email protected] Remove Material dependency from transformed_scrollable_test.dart (flutter/flutter#182141) 2026-02-13 [email protected] Fix cross imports for all Cupertino tests (flutter/flutter#181634) 2026-02-13 [email protected] remove MaterialApp import from raw_radio_test.dart (flutter/flutter#181721) 2026-02-13 [email protected] Roll Skia from e2991aa99710 to bb69b5b71b4f (37 revisions) (flutter/flutter#182390) 2026-02-13 [email protected] Turns on most of fragment_shader_test.dart for opengles (flutter/flutter#182229) 2026-02-13 [email protected] Update `CHANGELOG` for 3.41.1 release (flutter/flutter#182393) 2026-02-13 [email protected] Remove Material dependency from semantics_keep_alive_offstage_test.dart (flutter/flutter#182211) 2026-02-13 [email protected] Update iOS/macOS plugin template to add dependency on FlutterFramework (flutter/flutter#181416) 2026-02-13 [email protected] Add plugin dependencies to Add to App FlutterPluginRegistrant (flutter/flutter#182304) 2026-02-13 [email protected] Preparation to add contentTextStyle flag to SimpleDialog. (flutter/flutter#182200) 2026-02-13 [email protected] Roll Packages from af1d610 to 09104b0 (4 revisions) (flutter/flutter#182383) 2026-02-13 [email protected] Roll Dart SDK from de5915148fde to 7a2a28dbd0d4 (2 revisions) (flutter/flutter#182380) 2026-02-13 [email protected] [Impeller] Dispose thread local caches on each frame when using GPUSurfaceVulkanImpeller with a delegate (flutter/flutter#182265) ...
fixes flutter#182106 Changes: - started running the tests against opengles 3, which matches the version of the test shaders - fixed binging uniforms on opengles so it's based on it's type, not it's size (since vec4 and mat2 have the same size for instance) - fixed for builtin shaders - fixed for runtime shaders - expands our opengles mocking to include more uniform setters - skips the handful of tests that still don't work Now builtin shader headers look something like this. You can see this information didn't exist and was not derivable based on the existing information in all cases: ```c++ ShaderMetadata Shader::kMetadataFrameInfo = { "FrameInfo", // name std::vector<ShaderStructMemberMetadata> { ShaderStructMemberMetadata { /*type=*/ShaderType::kFloat, /*name=*/"mvp", /*offset=*/0, /*size=*/64, /*byte_length=*/64, /*array_elements=*/std::nullopt, /*float_type=*/ShaderFloatType::kMat4, // <-- new }, ``` ## Pre-launch Checklist - [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
Flutter GPU shader bundles serialize uniform struct field metadata via a flatbuffer schema (`shader_bundle.fbs`) that carries per-field type and size information, but does not carry the underlying vector/column dimensions. This is enough to bind uniforms on Metal and Vulkan, but it isn't enough to distinguish shapes that share the same `element_size_in_bytes`, most notably `vec4` vs `mat2`. The GLES backend uses `ShaderStructMemberMetadata::float_type` to pick the right `glUniform*` call, and the bundle loader had no way to populate it. PR flutter#182229 ("Turns on most of fragment_shader_test.dart for opengles") introduced `ShaderFloatType`, the GLES validation that requires it, and the fix for runtime effect shaders (`runtime_effect_contents.cc`), but the equivalent fix for the Flutter GPU shader bundle loader (`lib/gpu/shader_library.cc`) was not made. As a result, every flutter_gpu app with a uniform block crashes the GLES backend on all platforms (Windows ANGLE, Linux GLES, Android GLES) with: Float uniform should have a float type. The size-only signal carried by the bundle is not sufficient to derive `float_type` correctly for `mat2` and `mat3`, which would otherwise collide with `vec2` arrays and `vec3` arrays. To fix this without regressing matrix-typed uniforms, this change extends the schema to carry `vec_size` and `columns` (matching what `ShaderInput` already does for vertex inputs), and uses them to derive `float_type` in the bundle loader via the same shape-based dispatch that runtime effects already use. The shader bundle format version is bumped from 1 to 2 because old bundles do not carry the new fields. Old bundles loaded against a new engine fail with a clear error pointing at the impellerc/SDK version mismatch, rather than silently rendering with the wrong glUniform call. Tests: - `shader_bundle_unittests.cc`: verify the bundle now carries `vec_size` and `columns` for the existing `mvp` (mat4) and `color` (vec4) test fixtures, and exhaustively cover `DeriveShaderFloatType` for float scalars, all vector sizes, all square matrices, non-square shapes, non-float types, and zero (legacy bundle) values. - `buffer_bindings_gles_unittests.cc`: add a regression guard asserting that the GLES backend rejects a float uniform that arrives without `float_type` populated, so a future change that forgets to populate it (in any code path) fails at unit test time. - `gpu_test.dart`: re-enable the eight Flutter GPU tests that were disabled for the opengles backend pending this fix (triangle, MSAA triangle, polygon mode, indexed triangle, stencil, cull mode, scissor, viewport). Fixes flutter#184953 Fixes flutter#183530 May also resolve flutter#176875, flutter#164438, and possibly flutter#164745. To be verified against the linked reproducers after merge.
Flutter GPU shader bundles serialize uniform struct field metadata via a flatbuffer schema (`shader_bundle.fbs`) that carries per-field type and size information, but does not carry the underlying vector/column dimensions. This is enough to bind uniforms on Metal and Vulkan, but it isn't enough to distinguish shapes that share the same `element_size_in_bytes`, most notably `vec4` vs `mat2`. The GLES backend uses `ShaderStructMemberMetadata::float_type` to pick the right `glUniform*` call, and the bundle loader had no way to populate it. PR flutter#182229 ("Turns on most of fragment_shader_test.dart for opengles") introduced `ShaderFloatType`, the GLES validation that requires it, and the fix for runtime effect shaders (`runtime_effect_contents.cc`), but the equivalent fix for the Flutter GPU shader bundle loader (`lib/gpu/shader_library.cc`) was not made. As a result, every flutter_gpu app with a uniform block crashes the GLES backend on all platforms (Windows ANGLE, Linux GLES, Android GLES) with: Float uniform should have a float type. The size-only signal carried by the bundle is not sufficient to derive `float_type` correctly for `mat2` and `mat3`, which would otherwise collide with `vec2` arrays and `vec3` arrays. To fix this without regressing matrix-typed uniforms, this change extends the schema to carry `vec_size` and `columns` (matching what `ShaderInput` already does for vertex inputs), and uses them to derive `float_type` in the bundle loader via the same shape-based dispatch that runtime effects already use. The shader bundle format version is bumped from 1 to 2 because old bundles do not carry the new fields. Old bundles loaded against a new engine fail with a clear error pointing at the impellerc/SDK version mismatch, rather than silently rendering with the wrong glUniform call. Tests: - `shader_bundle_unittests.cc`: verify the bundle now carries `vec_size` and `columns` for the existing `mvp` (mat4) and `color` (vec4) test fixtures, and exhaustively cover `DeriveShaderFloatType` for float scalars, all vector sizes, all square matrices, non-square shapes, non-float types, and zero (legacy bundle) values. - `buffer_bindings_gles_unittests.cc`: add a regression guard asserting that the GLES backend rejects a float uniform that arrives without `float_type` populated, so a future change that forgets to populate it (in any code path) fails at unit test time. - `gpu_test.dart`: re-enable the eight Flutter GPU tests that were disabled for the opengles backend pending this fix (triangle, MSAA triangle, polygon mode, indexed triangle, stencil, cull mode, scissor, viewport). Fixes flutter#184953 Fixes flutter#183530 May also resolve flutter#176875, flutter#164438, and possibly flutter#164745. To be verified against the linked reproducers after merge.
…ata (flutter#185879) Flutter GPU shader bundles serialize uniform struct field metadata via a flatbuffer schema (`shader_bundle.fbs`) that carries per-field type and size information, but does not carry the underlying vector/column dimensions. This is enough to bind uniforms on Metal and Vulkan, but it isn't enough to distinguish shapes that share the same `element_size_in_bytes`, most notably `vec4` vs `mat2`. The GLES backend uses `ShaderStructMemberMetadata::float_type` to pick the right `glUniform*` call, and the bundle loader had no way to populate it. PR flutter#182229 ("Turns on most of fragment_shader_test.dart for opengles") introduced `ShaderFloatType`, the GLES validation that requires it, and the fix for runtime effect shaders (`runtime_effect_contents.cc`), but the equivalent fix for the Flutter GPU shader bundle loader (`lib/gpu/shader_library.cc`) was not made. As a result, every flutter_gpu app with a uniform block crashes the GLES backend on all platforms (Windows ANGLE, Linux GLES, Android GLES) with: ``` [ERROR:flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc(409)] Break on 'ImpellerValidationBreak' to inspect point of failure: Float uniform should have a float type. ``` ## Approach The size-only signal already carried by the bundle is not sufficient to derive `float_type` correctly for `mat2` and `mat3`, which would otherwise collide with `vec2` arrays and `vec3` arrays. (impellerc serializes a `mat2` uniform with `element_size_in_bytes = 8` and `array_elements = 2`, which is the same shape as a length-2 `vec2` array. Same story for `mat3`.) To fix this without regressing matrix-typed uniforms, this PR extends the schema to carry `vec_size` and `columns` (matching what `ShaderInput` already does for vertex inputs), and uses them to derive `float_type` in the bundle loader via the same shape-based dispatch that runtime effects already use. The shader bundle format version is bumped from 1 to 2 because old bundles do not carry the new fields. Old bundles loaded against a new engine fail with a clear error pointing at the impellerc/SDK version mismatch, rather than silently rendering with the wrong `glUniform*` call. ## Tests - `shader_bundle_unittests.cc`: verify the bundle carries `vec_size` and `columns` for the existing `mvp` (mat4) and `color` (vec4) test fixtures. Exhaustively cover `DeriveShaderFloatType` for float scalars, all vector sizes, all square matrices, non-square shapes, non-float types, and zero (legacy bundle) values. - `buffer_bindings_gles_unittests.cc`: regression guard asserting that the GLES backend rejects a float uniform that arrives without `float_type` populated. If a future change forgets to populate `float_type` in any code path (shader bundle loader, runtime effects, or anything else), this test catches it at unit-test time instead of at runtime. - `gpu_test.dart`: the eight re-enabled tests cover triangle rendering, polygon mode, MSAA, indexed draw, stencil, cull mode, scissor, and viewport on the opengles backend, end-to-end through the bundle loader. ## Issues Fixes flutter#184953 Fixes flutter#183530 May also resolve the following issues, all of which surface as GLES uniform binding failures and share the same root-cause family. To be verified against the linked reproducers after merge: - flutter#176875 - flutter#164438 - flutter#164745 This supersedes the smaller fix in [`bdero/flutter-gpu-float-types`](https://github.com/bdero/flutter/tree/bdero/flutter-gpu-float-types) (draft flutter#185874), which derived `float_type` from `element_size_in_bytes` only and would have misclassified `mat2`/`mat3` as `vec2`/`vec3`.
fixes #182106
Changes:
Now builtin shader headers look something like this. You can see this information didn't exist and was not derivable based on the existing information in all cases:
Pre-launch Checklist
///).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. Comments from the
gemini-code-assistbot 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.