Skip to content

Commit

Permalink
Merge pull request #86852 from pkdawson/fix-index-offsets-again
Browse files Browse the repository at this point in the history
Fix usage of index offsets in RenderingDevice
  • Loading branch information
akien-mga committed Jan 9, 2024
2 parents b7f7ca1 + a0f9bcc commit 476cbbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
12 changes: 6 additions & 6 deletions servers/rendering/rendering_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3557,10 +3557,10 @@ void RenderingDevice::draw_list_bind_index_array(DrawListID p_list, RID p_index_
#ifdef DEBUG_ENABLED
dl->validation.index_array_max_index = index_array->max_index;
#endif
dl->validation.index_array_size = index_array->indices;
dl->validation.index_array_offset = index_array->offset;
dl->validation.index_array_count = index_array->indices;

draw_graph.add_draw_list_bind_index_buffer(index_array->driver_id, index_array->format, index_array->offset);
const uint64_t offset_bytes = index_array->offset * (index_array->format == INDEX_BUFFER_FORMAT_UINT16 ? sizeof(uint16_t) : sizeof(uint32_t));
draw_graph.add_draw_list_bind_index_buffer(index_array->driver_id, index_array->format, offset_bytes);

if (index_array->draw_tracker != nullptr) {
draw_graph.add_draw_list_usage(index_array->draw_tracker, RDG::RESOURCE_USAGE_INDEX_BUFFER_READ);
Expand Down Expand Up @@ -3667,13 +3667,13 @@ void RenderingDevice::draw_list_draw(DrawListID p_list, bool p_use_indices, uint
ERR_FAIL_COND_MSG(p_procedural_vertices > 0,
"Procedural vertices can't be used together with indices.");

ERR_FAIL_COND_MSG(!dl->validation.index_array_size,
ERR_FAIL_COND_MSG(!dl->validation.index_array_count,
"Draw command requested indices, but no index buffer was set.");

ERR_FAIL_COND_MSG(dl->validation.pipeline_uses_restart_indices != dl->validation.index_buffer_uses_restart_indices,
"The usage of restart indices in index buffer does not match the render primitive in the pipeline.");
#endif
uint32_t to_draw = dl->validation.index_array_size;
uint32_t to_draw = dl->validation.index_array_count;

#ifdef DEBUG_ENABLED
ERR_FAIL_COND_MSG(to_draw < dl->validation.pipeline_primitive_minimum,
Expand All @@ -3683,7 +3683,7 @@ void RenderingDevice::draw_list_draw(DrawListID p_list, bool p_use_indices, uint
"Index amount (" + itos(to_draw) + ") must be a multiple of the amount of indices required by the render primitive (" + itos(dl->validation.pipeline_primitive_divisor) + ").");
#endif

draw_graph.add_draw_list_draw_indexed(to_draw, p_instances, dl->validation.index_array_offset);
draw_graph.add_draw_list_draw_indexed(to_draw, p_instances, 0);
} else {
uint32_t to_draw;

Expand Down
6 changes: 2 additions & 4 deletions servers/rendering/rendering_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,8 @@ class RenderingDevice : public RenderingDeviceCommons {
uint32_t vertex_array_size = 0;
uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;
bool index_buffer_uses_restart_indices = false;
uint32_t index_array_size = 0;
uint32_t index_array_count = 0;
uint32_t index_array_max_index = 0;
uint32_t index_array_offset = 0;
Vector<uint32_t> set_formats;
Vector<bool> set_bound;
Vector<RID> set_rids;
Expand All @@ -1095,8 +1094,7 @@ class RenderingDevice : public RenderingDeviceCommons {
#else
struct Validation {
uint32_t vertex_array_size = 0;
uint32_t index_array_size = 0;
uint32_t index_array_offset;
uint32_t index_array_count = 0;
} validation;
#endif
};
Expand Down

0 comments on commit 476cbbd

Please sign in to comment.