Skip to content

Commit 1bf9d8e

Browse files
committed
Merge pull request #105501 from darksylinc/graph-align-ubsan
Fix UBSAN alignment issues in the render graph
2 parents d3ee6af + 96bad4a commit 1bf9d8e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

servers/rendering/rendering_device_graph.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,12 @@ int32_t RenderingDeviceGraph::_add_to_write_list(int32_t p_command_index, Rect2i
279279
return next_index;
280280
}
281281

282+
// Ensures all commands are 8-byte aligned.
283+
#define GRAPH_ALIGN(x) (((x) + 7u) & 0xFFFFFFF8u)
284+
282285
RenderingDeviceGraph::RecordedCommand *RenderingDeviceGraph::_allocate_command(uint32_t p_command_size, int32_t &r_command_index) {
283286
uint32_t command_data_offset = command_data.size();
284-
command_data_offset = STEPIFY(command_data_offset, 8);
287+
command_data_offset = GRAPH_ALIGN(command_data_offset);
285288
command_data_offsets.push_back(command_data_offset);
286289
command_data.resize(command_data_offset + p_command_size);
287290
r_command_index = command_count++;
@@ -292,12 +295,14 @@ RenderingDeviceGraph::RecordedCommand *RenderingDeviceGraph::_allocate_command(u
292295

293296
RenderingDeviceGraph::DrawListInstruction *RenderingDeviceGraph::_allocate_draw_list_instruction(uint32_t p_instruction_size) {
294297
uint32_t draw_list_data_offset = draw_instruction_list.data.size();
298+
draw_list_data_offset = GRAPH_ALIGN(draw_list_data_offset);
295299
draw_instruction_list.data.resize(draw_list_data_offset + p_instruction_size);
296300
return reinterpret_cast<DrawListInstruction *>(&draw_instruction_list.data[draw_list_data_offset]);
297301
}
298302

299303
RenderingDeviceGraph::ComputeListInstruction *RenderingDeviceGraph::_allocate_compute_list_instruction(uint32_t p_instruction_size) {
300304
uint32_t compute_list_data_offset = compute_instruction_list.data.size();
305+
compute_list_data_offset = GRAPH_ALIGN(compute_list_data_offset);
301306
compute_instruction_list.data.resize(compute_list_data_offset + p_instruction_size);
302307
return reinterpret_cast<ComputeListInstruction *>(&compute_instruction_list.data[compute_list_data_offset]);
303308
}
@@ -786,6 +791,8 @@ void RenderingDeviceGraph::_run_compute_list_command(RDD::CommandBufferID p_comm
786791
DEV_ASSERT(false && "Unknown compute list instruction type.");
787792
return;
788793
}
794+
795+
instruction_data_cursor = GRAPH_ALIGN(instruction_data_cursor);
789796
}
790797
}
791798

@@ -925,6 +932,8 @@ void RenderingDeviceGraph::_run_draw_list_command(RDD::CommandBufferID p_command
925932
DEV_ASSERT(false && "Unknown draw list instruction type.");
926933
return;
927934
}
935+
936+
instruction_data_cursor = GRAPH_ALIGN(instruction_data_cursor);
928937
}
929938
}
930939

@@ -1484,6 +1493,8 @@ void RenderingDeviceGraph::_print_draw_list(const uint8_t *p_instruction_data, u
14841493
DEV_ASSERT(false && "Unknown draw list instruction type.");
14851494
return;
14861495
}
1496+
1497+
instruction_data_cursor = GRAPH_ALIGN(instruction_data_cursor);
14871498
}
14881499
}
14891500

@@ -1532,6 +1543,8 @@ void RenderingDeviceGraph::_print_compute_list(const uint8_t *p_instruction_data
15321543
DEV_ASSERT(false && "Unknown compute list instruction type.");
15331544
return;
15341545
}
1546+
1547+
instruction_data_cursor = GRAPH_ALIGN(instruction_data_cursor);
15351548
}
15361549
}
15371550

0 commit comments

Comments
 (0)