Remove warning when project setting requests a larger global shader uniform buffer than the hardware supports.
Instead provide a better error message when the limit is exceeded and avoid crash with a small limit.
This commit is contained in:
parent
cae2f853dc
commit
27b040dc61
|
@ -1111,15 +1111,15 @@ MaterialStorage::MaterialStorage() {
|
||||||
|
|
||||||
global_shader_uniforms.buffer_size = MAX(16, (int)GLOBAL_GET("rendering/limits/global_shader_variables/buffer_size"));
|
global_shader_uniforms.buffer_size = MAX(16, (int)GLOBAL_GET("rendering/limits/global_shader_variables/buffer_size"));
|
||||||
if (global_shader_uniforms.buffer_size * sizeof(GlobalShaderUniforms::Value) > uint32_t(Config::get_singleton()->max_uniform_buffer_size)) {
|
if (global_shader_uniforms.buffer_size * sizeof(GlobalShaderUniforms::Value) > uint32_t(Config::get_singleton()->max_uniform_buffer_size)) {
|
||||||
|
// Limit to maximum support UBO size.
|
||||||
global_shader_uniforms.buffer_size = uint32_t(Config::get_singleton()->max_uniform_buffer_size) / sizeof(GlobalShaderUniforms::Value);
|
global_shader_uniforms.buffer_size = uint32_t(Config::get_singleton()->max_uniform_buffer_size) / sizeof(GlobalShaderUniforms::Value);
|
||||||
WARN_PRINT("Project setting \"rendering/limits/global_shader_variables/buffer_size\" exceeds maximum uniform buffer size of: " + itos(Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value)) + ". Falling back on maximum buffer size.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size);
|
global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size);
|
||||||
memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
||||||
global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size);
|
global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size);
|
||||||
global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE));
|
||||||
memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * (1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE)));
|
||||||
glGenBuffers(1, &global_shader_uniforms.buffer);
|
glGenBuffers(1, &global_shader_uniforms.buffer);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer);
|
glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, nullptr, GL_DYNAMIC_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
@ -1788,7 +1788,7 @@ void MaterialStorage::global_shader_parameter_add(const StringName &p_name, RS::
|
||||||
|
|
||||||
//is vector, allocate in buffer and update index
|
//is vector, allocate in buffer and update index
|
||||||
gv.buffer_index = _global_shader_uniform_allocate(gv.buffer_elements);
|
gv.buffer_index = _global_shader_uniform_allocate(gv.buffer_elements);
|
||||||
ERR_FAIL_COND_MSG(gv.buffer_index < 0, vformat("Failed allocating global variable '%s' out of buffer memory. Consider increasing it in the Project Settings.", String(p_name)));
|
ERR_FAIL_COND_MSG(gv.buffer_index < 0, vformat("Failed allocating global variable '%s' out of buffer memory. Consider increasing rendering/limits/global_shader_variables/buffer_size in the Project Settings. Maximum items supported by this hardware is: %d.", String(p_name), Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value)));
|
||||||
global_shader_uniforms.buffer_usage[gv.buffer_index].elements = gv.buffer_elements;
|
global_shader_uniforms.buffer_usage[gv.buffer_index].elements = gv.buffer_elements;
|
||||||
_global_shader_uniform_store_in_buffer(gv.buffer_index, gv.type, gv.value);
|
_global_shader_uniform_store_in_buffer(gv.buffer_index, gv.type, gv.value);
|
||||||
_global_shader_uniform_mark_buffer_dirty(gv.buffer_index, gv.buffer_elements);
|
_global_shader_uniform_mark_buffer_dirty(gv.buffer_index, gv.buffer_elements);
|
||||||
|
@ -1999,7 +1999,7 @@ int32_t MaterialStorage::global_shader_parameters_instance_allocate(RID p_instan
|
||||||
ERR_FAIL_COND_V(global_shader_uniforms.instance_buffer_pos.has(p_instance), -1);
|
ERR_FAIL_COND_V(global_shader_uniforms.instance_buffer_pos.has(p_instance), -1);
|
||||||
int32_t pos = _global_shader_uniform_allocate(ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES);
|
int32_t pos = _global_shader_uniform_allocate(ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES);
|
||||||
global_shader_uniforms.instance_buffer_pos[p_instance] = pos; //save anyway
|
global_shader_uniforms.instance_buffer_pos[p_instance] = pos; //save anyway
|
||||||
ERR_FAIL_COND_V_MSG(pos < 0, -1, "Too many instances using shader instance variables. Increase buffer size in Project Settings.");
|
ERR_FAIL_COND_V_MSG(pos < 0, -1, vformat("Too many instances using shader instance variables. Consider increasing rendering/limits/global_shader_variables/buffer_size in the Project Settings. Maximum items supported by this hardware is: %d.", Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value)));
|
||||||
global_shader_uniforms.buffer_usage[pos].elements = ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES;
|
global_shader_uniforms.buffer_usage[pos].elements = ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@ -2079,7 +2079,7 @@ void MaterialStorage::global_shader_parameters_instance_update(RID p_instance, i
|
||||||
void MaterialStorage::_update_global_shader_uniforms() {
|
void MaterialStorage::_update_global_shader_uniforms() {
|
||||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||||
if (global_shader_uniforms.buffer_dirty_region_count > 0) {
|
if (global_shader_uniforms.buffer_dirty_region_count > 0) {
|
||||||
uint32_t total_regions = global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE;
|
uint32_t total_regions = 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
||||||
if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) {
|
if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) {
|
||||||
// 25% of regions dirty, just update all buffer
|
// 25% of regions dirty, just update all buffer
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer);
|
glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer);
|
||||||
|
|
|
@ -1165,8 +1165,8 @@ MaterialStorage::MaterialStorage() {
|
||||||
global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size);
|
global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size);
|
||||||
memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
||||||
global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size);
|
global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size);
|
||||||
global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE));
|
||||||
memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * (1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE)));
|
||||||
global_shader_uniforms.buffer = RD::get_singleton()->storage_buffer_create(sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
global_shader_uniforms.buffer = RD::get_singleton()->storage_buffer_create(sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1769,7 +1769,7 @@ void MaterialStorage::global_shader_parameters_instance_update(RID p_instance, i
|
||||||
void MaterialStorage::_update_global_shader_uniforms() {
|
void MaterialStorage::_update_global_shader_uniforms() {
|
||||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||||
if (global_shader_uniforms.buffer_dirty_region_count > 0) {
|
if (global_shader_uniforms.buffer_dirty_region_count > 0) {
|
||||||
uint32_t total_regions = global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE;
|
uint32_t total_regions = 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE);
|
||||||
if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) {
|
if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) {
|
||||||
// 25% of regions dirty, just update all buffer
|
// 25% of regions dirty, just update all buffer
|
||||||
RD::get_singleton()->buffer_update(global_shader_uniforms.buffer, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, global_shader_uniforms.buffer_values);
|
RD::get_singleton()->buffer_update(global_shader_uniforms.buffer, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, global_shader_uniforms.buffer_values);
|
||||||
|
|
Loading…
Reference in New Issue