X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fvbo%2Fvbo_primitive_restart.c;h=1349740249f513a47251a3c7d99e4b8129cfddc3;hb=f3cce7087a562f77be7306e70d4e62bc214bb5fa;hp=e0bd233eeb4549d39dd064fd322837b52de68454;hpb=093965f9e397aa9a06b3d40c265c35653184dd0c;p=mesa.git diff --git a/src/mesa/vbo/vbo_primitive_restart.c b/src/mesa/vbo/vbo_primitive_restart.c index e0bd233eeb4..1349740249f 100644 --- a/src/mesa/vbo/vbo_primitive_restart.c +++ b/src/mesa/vbo/vbo_primitive_restart.c @@ -1,5 +1,5 @@ /* - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 VMware, Inc. * All Rights Reserved. * * Copyright © 2012 Intel Corporation @@ -28,21 +28,21 @@ * */ -#include "main/imports.h" -#include "main/bufferobj.h" +#include "main/errors.h" +#include "util/imports.h" #include "main/macros.h" #include "main/varray.h" #include "vbo.h" -#include "vbo_context.h" + #define UPDATE_MIN2(a, b) (a) = MIN2((a), (b)) #define UPDATE_MAX2(a, b) (a) = MAX2((a), (b)) /* * Notes on primitive restart: - * The code below is used when the driver does not support primitive - * restart itself. (ctx->Const.PrimitiveRestartInSoftware == GL_TRUE) + * The code below is used when the driver does not fully support primitive + * restart (for example, if it only does restart index of ~0). * * We map the index buffer, find the restart indexes, unmap * the index buffer then draw the sub-primitives delineated by the restarts. @@ -164,29 +164,29 @@ vbo_sw_primitive_restart(struct gl_context *ctx, const struct _mesa_prim *prims, GLuint nr_prims, const struct _mesa_index_buffer *ib, - struct gl_buffer_object *indirect) + GLuint num_instances, GLuint base_instance, + struct gl_buffer_object *indirect, + GLsizeiptr indirect_offset) { GLuint prim_num; + struct _mesa_prim new_prim; + struct _mesa_index_buffer new_ib; struct sub_primitive *sub_prims; struct sub_primitive *sub_prim; GLuint num_sub_prims; GLuint sub_prim_num; GLuint end_index; GLuint sub_end_index; - GLuint restart_index = _mesa_primitive_restart_index(ctx, ib->type); + GLuint restart_index = _mesa_primitive_restart_index(ctx, 1 << ib->index_size_shift); struct _mesa_prim temp_prim; - struct vbo_context *vbo = vbo_context(ctx); - vbo_draw_func draw_prims_func = vbo->draw_prims; - GLboolean map_ib = ib->obj->Name && !ib->obj->Pointer; - void *ptr; + GLboolean map_ib = ib->obj && !ib->obj->Mappings[MAP_INTERNAL].Pointer; + const void *ptr; /* If there is an indirect buffer, map it and extract the draw params */ - if (indirect && prims[0].is_indirect) { - struct _mesa_prim new_prim = *prims; - struct _mesa_index_buffer new_ib = *ib; + if (indirect) { const uint32_t *indirect_params; if (!ctx->Driver.MapBufferRange(ctx, 0, indirect->Size, GL_MAP_READ_BIT, - indirect)) { + indirect, MAP_INTERNAL)) { /* something went wrong with mapping, give up */ _mesa_error(ctx, GL_OUT_OF_MEMORY, @@ -195,22 +195,25 @@ vbo_sw_primitive_restart(struct gl_context *ctx, } assert(nr_prims == 1); - indirect_params = (const uint32_t *) ADD_POINTERS(indirect->Pointer, - new_prim.indirect_offset); + new_prim = prims[0]; + indirect_params = (const uint32_t *) + ADD_POINTERS(indirect->Mappings[MAP_INTERNAL].Pointer, + indirect_offset); - new_prim.is_indirect = 0; new_prim.count = indirect_params[0]; - new_prim.num_instances = indirect_params[1]; new_prim.start = indirect_params[2]; new_prim.basevertex = indirect_params[3]; - new_prim.base_instance = indirect_params[4]; + num_instances = indirect_params[1]; + base_instance = indirect_params[4]; + + new_ib = *ib; new_ib.count = new_prim.count; prims = &new_prim; ib = &new_ib; - ctx->Driver.UnmapBuffer(ctx, indirect); + ctx->Driver.UnmapBuffer(ctx, indirect, MAP_INTERNAL); } /* Find the sub-primitives. These are regions in the index buffer which @@ -218,17 +221,20 @@ vbo_sw_primitive_restart(struct gl_context *ctx, */ if (map_ib) { ctx->Driver.MapBufferRange(ctx, 0, ib->obj->Size, GL_MAP_READ_BIT, - ib->obj); + ib->obj, MAP_INTERNAL); } - ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); + if (ib->obj) + ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr); + else + ptr = ib->ptr; - sub_prims = find_sub_primitives(ptr, vbo_sizeof_ib_type(ib->type), + sub_prims = find_sub_primitives(ptr, 1 << ib->index_size_shift, 0, ib->count, restart_index, &num_sub_prims); if (map_ib) { - ctx->Driver.UnmapBuffer(ctx, ib->obj); + ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL); } /* Loop over the primitives, and use the located sub-primitives to draw @@ -246,13 +252,15 @@ vbo_sw_primitive_restart(struct gl_context *ctx, temp_prim.count = MIN2(sub_end_index, end_index) - temp_prim.start; if ((temp_prim.start == sub_prim->start) && (temp_prim.count == sub_prim->count)) { - draw_prims_func(ctx, &temp_prim, 1, ib, - GL_TRUE, sub_prim->min_index, sub_prim->max_index, - NULL, NULL); + ctx->Driver.Draw(ctx, &temp_prim, 1, ib, GL_TRUE, + sub_prim->min_index, sub_prim->max_index, + num_instances, base_instance, + NULL, 0); } else { - draw_prims_func(ctx, &temp_prim, 1, ib, - GL_FALSE, -1, -1, - NULL, NULL); + ctx->Driver.Draw(ctx, &temp_prim, 1, ib, + GL_FALSE, -1, -1, + num_instances, base_instance, + NULL, 0); } } if (sub_end_index >= end_index) {