Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions engine/src/flutter/impeller/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

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

The theory is that this isn't sufficient, but this is the max size right now and it's used by conical_gradient_uniform_fill.frag


static uint32_t ParseMSLVersion(const std::string& msl_version) {
std::stringstream sstream(msl_version);
std::string version_part;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down