diff options
Diffstat (limited to 'src/mesa/drivers/dri/r200')
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_cmdbuf.c | 14 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_context.h | 2 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_ioctl.c | 3 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_ioctl.h | 25 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_lock.h | 11 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_state_init.c | 2 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_swtcl.c | 2 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_tcl.c | 6 |
8 files changed, 53 insertions, 12 deletions
diff --git a/src/mesa/drivers/dri/r200/r200_cmdbuf.c b/src/mesa/drivers/dri/r200/r200_cmdbuf.c index 26812d50b6..fa0c62385b 100644 --- a/src/mesa/drivers/dri/r200/r200_cmdbuf.c +++ b/src/mesa/drivers/dri/r200/r200_cmdbuf.c @@ -183,7 +183,7 @@ extern void r200EmitVbufPrim( r200ContextPtr rmesa, fprintf(stderr, "%s cmd_used/4: %d prim %x nr %d\n", __FUNCTION__, rmesa->store.cmd_used/4, primitive, vertex_nr); - cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, 3 * sizeof(*cmd), + cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, VBUF_BUFSZ, __FUNCTION__ ); cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; @@ -236,8 +236,7 @@ GLushort *r200AllocEltsOpenEnded( r200ContextPtr rmesa, r200EmitState( rmesa ); - cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, - 12 + min_nr*2, + cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, ELTS_BUFSZ(min_nr), __FUNCTION__ ); cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; @@ -275,7 +274,7 @@ void r200EmitVertexAOS( r200ContextPtr rmesa, fprintf(stderr, "%s: vertex_size 0x%x offset 0x%x \n", __FUNCTION__, vertex_size, offset); - cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, 5 * sizeof(int), + cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, VERT_AOS_BUFSZ, __FUNCTION__ ); cmd[0].header.cmd_type = RADEON_CMD_PACKET3; @@ -292,18 +291,17 @@ void r200EmitAOS( r200ContextPtr rmesa, GLuint offset ) { drm_radeon_cmd_header_t *cmd; - int sz = 3 + ((nr/2)*3) + ((nr&1)*2); + int sz = AOS_BUFSZ(nr); int i; int *tmp; if (R200_DEBUG & DEBUG_IOCTL) fprintf(stderr, "%s nr arrays: %d\n", __FUNCTION__, nr); - cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, sz * sizeof(int), - __FUNCTION__ ); + cmd = (drm_radeon_cmd_header_t *)r200AllocCmdBuf( rmesa, sz, __FUNCTION__ ); cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3; - cmd[1].i = R200_CP_CMD_3D_LOAD_VBPNTR | ((sz-3) << 16); + cmd[1].i = R200_CP_CMD_3D_LOAD_VBPNTR | (((sz / sizeof(int)) - 3) << 16); cmd[2].i = nr; tmp = &cmd[0].i; cmd += 3; diff --git a/src/mesa/drivers/dri/r200/r200_context.h b/src/mesa/drivers/dri/r200/r200_context.h index 8f90c15831..f000e14330 100644 --- a/src/mesa/drivers/dri/r200/r200_context.h +++ b/src/mesa/drivers/dri/r200/r200_context.h @@ -528,6 +528,8 @@ struct r200_hw_state { struct r200_state_atom grd; /* guard band clipping */ struct r200_state_atom fog; struct r200_state_atom glt; + + int max_state_size; /* Number of bytes necessary for a full state emit. */ }; struct r200_state { diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.c b/src/mesa/drivers/dri/r200/r200_ioctl.c index 54875d5d22..5d084baf3e 100644 --- a/src/mesa/drivers/dri/r200/r200_ioctl.c +++ b/src/mesa/drivers/dri/r200/r200_ioctl.c @@ -132,7 +132,6 @@ int r200FlushCmdBufLocked( r200ContextPtr rmesa, const char * caller ) rmesa->store.statenr = 0; rmesa->store.cmd_used = 0; rmesa->dma.nr_released_bufs = 0; - rmesa->lost_context = 1; return ret; } @@ -564,8 +563,6 @@ static void r200Clear( GLcontext *ctx, GLbitfield mask, GLboolean all, return; } - r200EmitState( rmesa ); - /* Need to cope with lostcontext here as kernel relies on * some residual state: */ diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.h b/src/mesa/drivers/dri/r200/r200_ioctl.h index 011288161b..1503df7075 100644 --- a/src/mesa/drivers/dri/r200/r200_ioctl.h +++ b/src/mesa/drivers/dri/r200/r200_ioctl.h @@ -169,6 +169,31 @@ do { \ } \ } while (0) +/* Command lengths. Note that any time you ensure ELTS_BUFSZ or VBUF_BUFSZ + * are available, you will also be adding an rmesa->state.max_state_size because + * r200EmitState is called from within r200EmitVbufPrim and r200FlushElts. + */ +#define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int)) +#define VERT_AOS_BUFSZ (5 * sizeof(int)) +#define ELTS_BUFSZ(nr) (12 + nr * 2) +#define VBUF_BUFSZ (3 * sizeof(int)) + +/* Ensure that a minimum amount of space is available in the command buffer. + * This is used to ensure atomicity of state updates with the rendering requests + * that rely on them. + * + * An alternative would be to implement a "soft lock" such that when the buffer + * wraps at an inopportune time, we grab the lock, flush the current buffer, + * and hang on to the lock until the critical section is finished and we flush + * the buffer again and unlock. + */ +static __inline void r200EnsureCmdBufSpace( r200ContextPtr rmesa, int bytes ) +{ + if (rmesa->store.cmd_used + bytes > R200_CMD_BUF_SZ) + r200FlushCmdBuf( rmesa, __FUNCTION__ ); + assert( bytes <= R200_CMD_BUF_SZ ); +} + /* Alloc space in the command buffer */ static __inline char *r200AllocCmdBuf( r200ContextPtr rmesa, diff --git a/src/mesa/drivers/dri/r200/r200_lock.h b/src/mesa/drivers/dri/r200/r200_lock.h index 7a4dfcf15c..c913bd5f62 100644 --- a/src/mesa/drivers/dri/r200/r200_lock.h +++ b/src/mesa/drivers/dri/r200/r200_lock.h @@ -98,7 +98,15 @@ extern int prevLockLine; DEBUG_LOCK(); \ } while (0) -/* Unlock the hardware. +/* Unlock the hardware. We must assume that state has been lost when we unlock, + * because when we next grab the lock (to emit an accumulated cmdbuf), we don't + * have the information to recreate the context state as of the last unlock in + * in the case that we did lose the context state. + * + * The alternative to this would be to copy out the state on unlock + * (approximately) and if we did lose the context, dispatch a cmdbuf to reset + * the state to that old copy before continuing with the accumulated command + * buffer. */ #define UNLOCK_HARDWARE( rmesa ) \ do { \ @@ -106,6 +114,7 @@ extern int prevLockLine; rmesa->dri.hwLock, \ rmesa->dri.hwContext ); \ DEBUG_RESET(); \ + rmesa->lost_context = GL_TRUE; \ } while (0) #endif diff --git a/src/mesa/drivers/dri/r200/r200_state_init.c b/src/mesa/drivers/dri/r200/r200_state_init.c index ed53c5d2cf..3b6893aeee 100644 --- a/src/mesa/drivers/dri/r200/r200_state_init.c +++ b/src/mesa/drivers/dri/r200/r200_state_init.c @@ -205,6 +205,7 @@ void r200InitState( r200ContextPtr rmesa ) make_empty_list(&(rmesa->hw.dirty)); rmesa->hw.dirty.name = "DIRTY"; make_empty_list(&(rmesa->hw.clean)); rmesa->hw.clean.name = "CLEAN"; + rmesa->hw.max_state_size = 0; #define ALLOC_STATE( ATOM, CHK, SZ, NM, IDX ) \ do { \ @@ -215,6 +216,7 @@ void r200InitState( r200ContextPtr rmesa ) rmesa->hw.ATOM.idx = IDX; \ rmesa->hw.ATOM.check = check_##CHK; \ insert_at_head(&(rmesa->hw.dirty), &(rmesa->hw.ATOM)); \ + rmesa->hw.max_state_size += SZ * sizeof(int); \ } while (0) diff --git a/src/mesa/drivers/dri/r200/r200_swtcl.c b/src/mesa/drivers/dri/r200/r200_swtcl.c index d694ff1b9b..66662bb4d0 100644 --- a/src/mesa/drivers/dri/r200/r200_swtcl.c +++ b/src/mesa/drivers/dri/r200/r200_swtcl.c @@ -260,6 +260,8 @@ static void flush_last_swtcl_prim( r200ContextPtr rmesa ) current->ptr); if (rmesa->dma.current.start != rmesa->dma.current.ptr) { + r200EnsureCmdBufSpace( rmesa, VERT_AOS_BUFSZ + + rmesa->hw.max_state_size + VBUF_BUFSZ ); r200EmitVertexAOS( rmesa, rmesa->swtcl.vertex_size, current_offset); diff --git a/src/mesa/drivers/dri/r200/r200_tcl.c b/src/mesa/drivers/dri/r200/r200_tcl.c index 85f4bc1f7d..b613911b06 100644 --- a/src/mesa/drivers/dri/r200/r200_tcl.c +++ b/src/mesa/drivers/dri/r200/r200_tcl.c @@ -143,6 +143,9 @@ static GLushort *r200AllocElts( r200ContextPtr rmesa, GLuint nr ) if (rmesa->dma.flush) rmesa->dma.flush( rmesa ); + r200EnsureCmdBufSpace( rmesa, AOS_BUFSZ(rmesa->tcl.nr_aos_components) + + rmesa->hw.max_state_size + ELTS_BUFSZ(nr) ); + r200EmitAOS( rmesa, rmesa->tcl.aos_components, rmesa->tcl.nr_aos_components, 0 ); @@ -167,6 +170,9 @@ static void EMIT_PRIM( GLcontext *ctx, r200ContextPtr rmesa = R200_CONTEXT( ctx ); r200TclPrimitive( ctx, prim, hwprim ); + r200EnsureCmdBufSpace( rmesa, AOS_BUFSZ(rmesa->tcl.nr_aos_components) + + rmesa->hw.max_state_size + VBUF_BUFSZ ); + r200EmitAOS( rmesa, rmesa->tcl.aos_components, rmesa->tcl.nr_aos_components, |