Skip to content

Conversation

@Hellomik2002
Copy link

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). 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.

@google-cla
Copy link

google-cla bot commented May 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added the engine flutter/engine related. See also e: labels. label May 4, 2025
@Hellomik2002 Hellomik2002 force-pushed the runtime_shaders_upload branch from c48d01c to 3c47ece Compare May 4, 2025 16:26
@Hellomik2002 Hellomik2002 force-pushed the runtime_shaders_upload branch from c497f75 to 918e581 Compare May 8, 2025 16:27
@chinmaygarde
Copy link
Member

@Hellomik2002 Can you please address the bots comments about the CLA? I am unable to review the patch unfortunately.

@Hellomik2002
Copy link
Author

@Hellomik2002 Can you please address the bots comments about the CLA? I am unable to review the patch unfortunately.

I already signed the contributor license agreement. Can you send link if I forget something.

@chinmaygarde
Copy link
Member

Interesting. Usually, contributors say "I signed it" and the CLA bot says "all good". But I do see the CLA check being successful in the presubmits. Sorry about that, I'll review it!

@Hellomik2002
Copy link
Author

Interesting. Usually, contributors say "I signed it" and the CLA bot says "all good". But I do see the CLA check being successful in the presubmits. Sorry about that, I'll review it!

You are welcome. I will be happy to fix if something needed.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Barring some construction issues, I think the big thing missing here is that fact that the shader blobs contain no versioning or validity metadata. We could get into a situation where users persist these blobs but ImpellerC updates its assumptions about layout and such. We cannot guarantee that the old blobs will keep working and users will run into runtime errors.

The same issue is faced by the fragment program API and we need to address this sooner rather than later. Can you file an issue for this? Perhaps we can fix this once and for all in impellerc so both this API and the fragment program API can accept shaders via blobs and we aren't concerned about users accidentally running into runtime crashes and corruption.

std::unordered_map<std::string, UniformBinding> uniform_structs_;
std::unordered_map<std::string, TextureBinding> uniform_textures_;
std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts_;
bool is_first_time_;
Copy link
Member

Choose a reason for hiding this comment

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

Initialize scalars in the header in case the ctor misses them (or we add a new ctor).

return tonic::ToDart(out_error.value());
}

auto mapping = std::make_unique<fml::NonOwnedMapping>(buffer, bufferLength);
Copy link
Member

Choose a reason for hiding this comment

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

A NonOwnedMapping without a release callback will make the library reference data that can be deleted at any point and will lead to a dangling reference (presumably till the VM collects the bytedata). There must be a copy here.

@Hellomik2002
Copy link
Author

Okay At the current moment I need just wait discussion about Shaders Metadata Issue ? And only after that It will be possible add runtime shaders in Flutter ?

@chinmaygarde
Copy link
Member

Yeah, I am not comfortable getting us into a situation where persisted shaders can cause corruption or crashers in future engines. Is there already an issue filed for it? If not, I can file one and prioritize it.

@Hellomik2002
Copy link
Author

I created already #172899 . But yeap it is better you create. I will close my Issue

@Hellomik2002
Copy link
Author

@timmaffett I see your code is cleaner and I see that you solved a similar problem. I would be happy get some advise or solutions from you.

@Piinks
Copy link
Contributor

Piinks commented Nov 24, 2025

Hi @Hellomik2002, thanks for contributing. Is this a change you would like to continue working on?

@Hellomik2002
Copy link
Author

Hellomik2002 commented Nov 25, 2025

Hi @Hellomik2002, thanks for contributing. Is this a change you would like to continue working on?

I need more details what need to be done. I can already upload shaders but also need to add versioning. It means I need write something special in shaderbundle and come up with a format. This topic should be disscussed firstly by flutter team

github-merge-queue bot pushed a commit that referenced this pull request Dec 2, 2025
Fixes #172899

This PR adds a format_version number to the root table of the 3 flat
buffer formats that impellerc creates; runtime stages, shader bundles
and shader archives.
It also adds a 'format_version' key to the root table of the shader
bundle json format for completeness (Though it could be argued that the
json format does not require this, I feel it may still be useful there).

This allows for format compatibility checks with future versions of the
table as @chinmaygarde expressed concerns about in #168294 and
@jonahwilliams mentions in #166944 .
The current code only checks for compatibility with the current version,
but this mechanism allows for backwards compatibility in the future and
not handling flat buffers with formats with new version number.
The big win here is that format_version numbers allow us to abort
parsing anything that we may not understand that could possible cause
problems, corruptions or crashes. The changes are simple and
straightforward and I feel they lay a reasonable foundation for version
handling for any future changes.

The version numbers themselves are defined within the
`runtime_stage_types.fbs`, `shader_bundle.fbs` and `shader_archive.fbs`
where I feel they should be as they can directly be incremented if any
changes to the flat buffer format are made. Mechanisms for handling of
backwards compatibility in the future should be straightforward to make
in the corresponding c++ code allowing for the continued support of
older (lower) version numbers if so desired.

This addresses #172899 and the other concerns mentioned in the
issues/pr's mentioned above.

I plan on including my tests for exclusion of non-matching versions -
Existing test verify that the version checking confirms matching
versions. I wanted to get this out there for discussion before spending
more time on this in case this approach is rejected outright.
   
I have a companion PR which adds FragmentProgram.fromBytes() to the
engine (c++ and canvaskit/wasm). I wanted to separate the impellerc
output versioning into it's own (this) PR.

  
## 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 `///`).
- [FORTHCOMING] 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.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gaaclarke <[email protected]>
Co-authored-by: Aaron Clarke <[email protected]>
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Fixes flutter#172899

This PR adds a format_version number to the root table of the 3 flat
buffer formats that impellerc creates; runtime stages, shader bundles
and shader archives.
It also adds a 'format_version' key to the root table of the shader
bundle json format for completeness (Though it could be argued that the
json format does not require this, I feel it may still be useful there).

This allows for format compatibility checks with future versions of the
table as @chinmaygarde expressed concerns about in flutter#168294 and
@jonahwilliams mentions in flutter#166944 .
The current code only checks for compatibility with the current version,
but this mechanism allows for backwards compatibility in the future and
not handling flat buffers with formats with new version number.
The big win here is that format_version numbers allow us to abort
parsing anything that we may not understand that could possible cause
problems, corruptions or crashes. The changes are simple and
straightforward and I feel they lay a reasonable foundation for version
handling for any future changes.

The version numbers themselves are defined within the
`runtime_stage_types.fbs`, `shader_bundle.fbs` and `shader_archive.fbs`
where I feel they should be as they can directly be incremented if any
changes to the flat buffer format are made. Mechanisms for handling of
backwards compatibility in the future should be straightforward to make
in the corresponding c++ code allowing for the continued support of
older (lower) version numbers if so desired.

This addresses flutter#172899 and the other concerns mentioned in the
issues/pr's mentioned above.

I plan on including my tests for exclusion of non-matching versions -
Existing test verify that the version checking confirms matching
versions. I wanted to get this out there for discussion before spending
more time on this in case this approach is rejected outright.
   
I have a companion PR which adds FragmentProgram.fromBytes() to the
engine (c++ and canvaskit/wasm). I wanted to separate the impellerc
output versioning into it's own (this) PR.

  
## 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 `///`).
- [FORTHCOMING] 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.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gaaclarke <[email protected]>
Co-authored-by: Aaron Clarke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants