From 503eb57a003f51c25687e9cf0ad6f7939a757f1b Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 8 Jun 2010 13:55:53 -0700 Subject: i965: Avoid calloc/free in the CURBE upload process. In exchange we end up with an extra memcpy, but that seems better than calloc/free. Each buffer is 4k maximum, and on the i965-streaming branch this allocation was showing up as the top entry in brw_validate_state profiling for cairo-gl. --- src/mesa/drivers/dri/i965/brw_curbe.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/mesa/drivers/dri/i965/brw_curbe.c') diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c index 06053d5bcb7..c79b0a79e5c 100644 --- a/src/mesa/drivers/dri/i965/brw_curbe.c +++ b/src/mesa/drivers/dri/i965/brw_curbe.c @@ -190,15 +190,11 @@ static void prepare_constant_buffer(struct brw_context *brw) GLuint i; if (sz == 0) { - if (brw->curbe.last_buf) { - free(brw->curbe.last_buf); - brw->curbe.last_buf = NULL; - brw->curbe.last_bufsz = 0; - } + brw->curbe.last_bufsz = 0; return; } - buf = (GLfloat *) calloc(1, bufsz); + buf = brw->curbe.next_buf; /* fragment shader constants */ if (brw->curbe.wm_size) { @@ -289,18 +285,15 @@ static void prepare_constant_buffer(struct brw_context *brw) } if (brw->curbe.curbe_bo != NULL && - brw->curbe.last_buf && bufsz == brw->curbe.last_bufsz && memcmp(buf, brw->curbe.last_buf, bufsz) == 0) { /* constants have not changed */ - free(buf); - } - else { - /* constants have changed */ - if (brw->curbe.last_buf) - free(brw->curbe.last_buf); - - brw->curbe.last_buf = buf; + } else { + /* Update the record of what our last set of constants was. We + * don't just flip the pointers because we don't fill in the + * data in the padding between the entries. + */ + memcpy(brw->curbe.last_buf, buf, bufsz); brw->curbe.last_bufsz = bufsz; if (brw->curbe.curbe_bo != NULL && @@ -319,6 +312,7 @@ static void prepare_constant_buffer(struct brw_context *brw) 4096, 1 << 6); brw->curbe.curbe_next_offset = 0; drm_intel_gem_bo_map_gtt(brw->curbe.curbe_bo); + assert(bufsz < 4096); } brw->curbe.curbe_offset = brw->curbe.curbe_next_offset; -- cgit v1.2.3