Validate varying count when compiling shaders

This avoids crashing on devices when a number of varyings greater than the device limit is used.

For now this accurately prints an error when compiling the shader, but the error text only pops up in the editor if the number of user varyings is above the limit.
This commit is contained in:
clayjohn 2025-02-12 16:12:46 -08:00
parent 296de7da83
commit 35100396e4
17 changed files with 92 additions and 27 deletions

View file

@ -686,30 +686,14 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
vcode += _prestr(varying.precision, ShaderLanguage::is_float_type(varying.type));
vcode += _typestr(varying.type);
vcode += " " + _mkid(varying_name);
uint32_t inc = 1U;
uint32_t inc = varying.get_size();
if (varying.array_size > 0) {
inc = (uint32_t)varying.array_size;
vcode += "[";
vcode += itos(varying.array_size);
vcode += "]";
}
switch (varying.type) {
case SL::TYPE_MAT2:
inc *= 2U;
break;
case SL::TYPE_MAT3:
inc *= 3U;
break;
case SL::TYPE_MAT4:
inc *= 4U;
break;
default:
break;
}
vcode += ";\n";
// GLSL ES 3.0 does not allow layout qualifiers for varyings
if (!RS::get_singleton()->is_low_end()) {
@ -1481,6 +1465,7 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident
info.render_modes = ShaderTypes::get_singleton()->get_modes(p_mode);
info.shader_types = ShaderTypes::get_singleton()->get_types();
info.global_shader_uniform_type_func = _get_global_shader_uniform_type;
info.base_varying_index = actions.base_varying_index;
Error err = parser.compile(p_code, info);