Added compilation failure if a max ubo size is exceeded (#164038)

issue: https://github.com/flutter/flutter/issues/163580

## 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].

<!-- 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
This commit is contained in:
gaaclarke 2025-02-26 09:36:00 -08:00 committed by GitHub
parent e039a911c5
commit 8b3f5f4a2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,6 +32,11 @@ constexpr const char* kEGLImageExternalExtension300 =
"GL_OES_EGL_image_external_essl3";
} // namespace
// This value should be <= 7372. UBOs can be larger on some devices but a
// performance cost will be paid.
// https://docs.qualcomm.com/bundle/publicresource/topics/80-78185-2/best_practices.html?product=1601111740035277#buffer-best-practices
static const uint32_t kMaxUniformBufferSize = 6208;
static uint32_t ParseMSLVersion(const std::string& msl_version) {
std::stringstream sstream(msl_version);
std::string version_part;
@ -257,6 +262,21 @@ static CompilerBackend CreateCompiler(const spirv_cross::ParsedIR& ir,
return compiler;
}
namespace {
uint32_t CalculateUBOSize(const spirv_cross::Compiler* compiler) {
spirv_cross::ShaderResources resources = compiler->get_shader_resources();
uint32_t result = 0;
for (const spirv_cross::Resource& ubo : resources.uniform_buffers) {
const spirv_cross::SPIRType& ubo_type =
compiler->get_type(ubo.base_type_id);
uint32_t size = compiler->get_declared_struct_size(ubo_type);
result += size;
}
return result;
}
} // namespace
Compiler::Compiler(const std::shared_ptr<const fml::Mapping>& source_mapping,
const SourceOptions& source_options,
Reflector::Options reflector_options)
@ -410,6 +430,13 @@ Compiler::Compiler(const std::shared_ptr<const fml::Mapping>& source_mapping,
return;
}
uint32_t ubo_size = CalculateUBOSize(sl_compiler.GetCompiler());
if (ubo_size > kMaxUniformBufferSize) {
COMPILER_ERROR(error_stream_) << "Uniform buffer size exceeds max ("
<< kMaxUniformBufferSize << "): " << ubo_size;
return;
}
// We need to invoke the compiler even if we don't use the SL mapping later
// for Vulkan. The reflector needs information that is only valid after a
// successful compilation call.