i965/draw: Use the real size for index buffers

Previously, we were using the size of the whole BO which may be
substantially larger than the actual index buffer size.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Jason Ekstrand 2016-05-17 15:34:40 -07:00
parent 7c8dfa78b9
commit aec10a1d5b
3 changed files with 8 additions and 3 deletions

View file

@ -991,6 +991,7 @@ struct brw_context
/* Updates are signaled by BRW_NEW_INDEX_BUFFER. */ /* Updates are signaled by BRW_NEW_INDEX_BUFFER. */
drm_intel_bo *bo; drm_intel_bo *bo;
uint32_t size;
GLuint type; GLuint type;
/* Offset to index buffer index to use in CMD_3D_PRIM so that we can /* Offset to index buffer index to use in CMD_3D_PRIM so that we can

View file

@ -1018,7 +1018,8 @@ brw_upload_indices(struct brw_context *brw)
return; return;
ib_type_size = _mesa_sizeof_type(index_buffer->type); ib_type_size = _mesa_sizeof_type(index_buffer->type);
ib_size = ib_type_size * index_buffer->count; ib_size = index_buffer->count ? ib_type_size * index_buffer->count :
index_buffer->obj->Size;
bufferobj = index_buffer->obj; bufferobj = index_buffer->obj;
/* Turn into a proper VBO: /* Turn into a proper VBO:
@ -1028,6 +1029,7 @@ brw_upload_indices(struct brw_context *brw)
*/ */
intel_upload_data(brw, index_buffer->ptr, ib_size, ib_type_size, intel_upload_data(brw, index_buffer->ptr, ib_size, ib_type_size,
&brw->ib.bo, &offset); &brw->ib.bo, &offset);
brw->ib.size = brw->ib.bo->size;
} else { } else {
offset = (GLuint) (unsigned long) index_buffer->ptr; offset = (GLuint) (unsigned long) index_buffer->ptr;
@ -1047,6 +1049,7 @@ brw_upload_indices(struct brw_context *brw)
intel_upload_data(brw, map, ib_size, ib_type_size, intel_upload_data(brw, map, ib_size, ib_type_size,
&brw->ib.bo, &offset); &brw->ib.bo, &offset);
brw->ib.size = brw->ib.bo->size;
ctx->Driver.UnmapBuffer(ctx, bufferobj, MAP_INTERNAL); ctx->Driver.UnmapBuffer(ctx, bufferobj, MAP_INTERNAL);
} else { } else {
@ -1056,6 +1059,7 @@ brw_upload_indices(struct brw_context *brw)
if (bo != brw->ib.bo) { if (bo != brw->ib.bo) {
drm_intel_bo_unreference(brw->ib.bo); drm_intel_bo_unreference(brw->ib.bo);
brw->ib.bo = bo; brw->ib.bo = bo;
brw->ib.size = bufferobj->Size;
drm_intel_bo_reference(bo); drm_intel_bo_reference(bo);
} }
} }
@ -1110,7 +1114,7 @@ brw_emit_index_buffer(struct brw_context *brw)
0); 0);
OUT_RELOC(brw->ib.bo, OUT_RELOC(brw->ib.bo,
I915_GEM_DOMAIN_VERTEX, 0, I915_GEM_DOMAIN_VERTEX, 0,
brw->ib.bo->size - 1); brw->ib.size - 1);
ADVANCE_BATCH(); ADVANCE_BATCH();
} }

View file

@ -384,7 +384,7 @@ gen8_emit_index_buffer(struct brw_context *brw)
OUT_BATCH(CMD_INDEX_BUFFER << 16 | (5 - 2)); OUT_BATCH(CMD_INDEX_BUFFER << 16 | (5 - 2));
OUT_BATCH(brw_get_index_type(index_buffer->type) | mocs_wb); OUT_BATCH(brw_get_index_type(index_buffer->type) | mocs_wb);
OUT_RELOC64(brw->ib.bo, I915_GEM_DOMAIN_VERTEX, 0, 0); OUT_RELOC64(brw->ib.bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
OUT_BATCH(brw->ib.bo->size); OUT_BATCH(brw->ib.size);
ADVANCE_BATCH(); ADVANCE_BATCH();
} }