Skip to content
Snippets Groups Projects
Commit f0595be9 authored by Pierre-Eric Pelloux-Prayer's avatar Pierre-Eric Pelloux-Prayer Committed by Eric Engestrom
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!14476>
(cherry picked from commit dcbf2423)
parent 4637a3bc
No related branches found
No related tags found
No related merge requests found
......@@ -1822,7 +1822,7 @@
"description": "vbo/dlist: add vertices to incomplete primitives",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "ac3d4c7635beab92cadada63f8c09fd12a2f7069"
},
......
......@@ -117,6 +117,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "util/bitscan.h"
#include "util/u_memory.h"
#include "util/hash_table.h"
#include "util/u_prim.h"
#include "gallium/include/pipe/p_state.h"
......@@ -607,9 +608,7 @@ compile_vertex_list(struct gl_context *ctx)
node->cold->max_index = end - 1;
int max_index_count = total_vert_count * 2;
int size = max_index_count * sizeof(uint32_t);
uint32_t* indices = (uint32_t*) malloc(size);
uint32_t* indices = (uint32_t*) malloc(max_index_count * sizeof(uint32_t));
struct _mesa_prim *merged_prims = NULL;
int idx = 0;
......@@ -637,6 +636,12 @@ 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));
}
/* Line strips may get converted to lines */
if (mode == GL_LINE_STRIP)
mode = GL_LINES;
......@@ -701,6 +706,14 @@ compile_vertex_list(struct gl_context *ctx)
}
}
/* 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,
original_prims[i].start + vertex_count - 1,
temp_vertices_buffer, &max_index);
}
if (merge_prims) {
/* Update vertex count. */
merged_prims[last_valid_prim].count += idx - start;
......
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