Skip to content

Commit

Permalink
Fix integer underflow when rounding up in VoxelGI
Browse files Browse the repository at this point in the history
The code wanted to divide and round up:
 - 0 / 64 = 0
 - 63 / 64 = 1
 - 64 / 64 = 1
 - 65 / 64 = 2

However when the dividend was exactly 0 it would underflow and produce
67108864 instead.

This caused TDRs on empty scenes or extremely slow performance

Fix godotengine#80286

(cherry picked from commit e783e32)
  • Loading branch information
darksylinc authored and YuriSizov committed Sep 21, 2023
1 parent a90aac5 commit efbe923
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/environment/gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
push_constant.cell_offset = mipmaps[i].cell_offset;
push_constant.cell_count = mipmaps[i].cell_count;

int64_t wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1;
int64_t wg_todo = (mipmaps[i].cell_count + wg_size - 1) / wg_size;
while (wg_todo) {
int64_t wg_count = MIN(wg_todo, wg_limit_x);
RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(VoxelGIPushConstant));
Expand All @@ -2987,7 +2987,7 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
push_constant.cell_offset = mipmaps[i].cell_offset;
push_constant.cell_count = mipmaps[i].cell_count;

int64_t wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1;
int64_t wg_todo = (mipmaps[i].cell_count + wg_size - 1) / wg_size;
while (wg_todo) {
int64_t wg_count = MIN(wg_todo, wg_limit_x);
RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(VoxelGIPushConstant));
Expand Down

0 comments on commit efbe923

Please sign in to comment.