Skip to content
Snippets Groups Projects
Commit dcbf2423 authored by Pierre-Eric Pelloux-Prayer's avatar Pierre-Eric Pelloux-Prayer Committed by Marge Bot
Browse files

vbo/dlist: add vertices to incomplete primitives

If a primitive is added with missing vertices, this will shift all
the vertices and produce incorrect rendering.

In issue #5786 the app uses GL_LINE_STRIPS with a single vertex.

Adding extra vertices can make the initial estimation for the index
buffer size incorrect, so this buffer can now be growed if needed.

Fixes: ac3d4c76 ("vbo/dlist: convert LINE_STRIPS to LINES")
Closes: mesa/mesa#5786


Acked-by: default avatarMarek Olšák <marek.olsak@amd.com>
Part-of: <mesa/mesa!14243>
parent 7a1d3d3a
No related branches found
No related tags found
No related merge requests found
......@@ -117,6 +117,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "util/u_memory.h"
#include "util/hash_table.h"
#include "util/indices/u_indices.h"
#include "util/u_prim.h"
#include "gallium/include/pipe/p_state.h"
......@@ -599,10 +600,8 @@ compile_vertex_list(struct gl_context *ctx)
/* converting primitive types may result in many more indices */
bool all_prims_supported = (ctx->Const.DriverSupportedPrimMask & BITFIELD_MASK(PIPE_PRIM_MAX)) == BITFIELD_MASK(PIPE_PRIM_MAX);
int max_index_count = total_vert_count * (all_prims_supported ? 2 : 3);
int size = max_index_count * sizeof(uint32_t);
uint32_t* indices = (uint32_t*) malloc(size);
void *tmp_indices = all_prims_supported ? NULL : malloc(size);
uint32_t* indices = (uint32_t*) malloc(max_index_count * sizeof(uint32_t));
void *tmp_indices = all_prims_supported ? NULL : malloc(max_index_count * sizeof(uint32_t));
struct _mesa_prim *merged_prims = NULL;
int idx = 0;
......@@ -632,6 +631,13 @@ compile_vertex_list(struct gl_context *ctx)
continue;
}
/* Increase indices storage if the original estimation was too small. */
if (idx + 3 * vertex_count > max_index_count) {
max_index_count = max_index_count + 3 * vertex_count;
indices = (uint32_t*) realloc(indices, max_index_count * sizeof(uint32_t));
tmp_indices = all_prims_supported ? NULL : realloc(tmp_indices, max_index_count * sizeof(uint32_t));
}
/* Line strips may get converted to lines */
if (mode == GL_LINE_STRIP)
mode = GL_LINES;
......@@ -719,6 +725,16 @@ compile_vertex_list(struct gl_context *ctx)
temp_vertices_buffer, &max_index);
}
}
/* Duplicate the last vertex for incomplete primitives */
unsigned min_vert = u_prim_vertex_count(mode)->min;
for (unsigned j = vertex_count; j < min_vert; j++) {
indices[idx++] = add_vertex(save, vertex_to_index,
converted_prim ? CAST_INDEX(tmp_indices, index_size, vertex_count - 1) :
original_prims[i].start + vertex_count - 1,
temp_vertices_buffer, &max_index);
}
#undef CAST_INDEX
if (merge_prims) {
/* Update vertex count. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment