From 87a031206853a7e37d7a475c985b621edd051c15 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 26 Sep 2006 10:44:52 +0000 Subject: [PATCH] Add asserts to catch primitives being emitted with state still dirty, or extended when there is no primitive to extend. Turn lock/unlock macros into proper functions and add a debug flag to print out their activity. --- src/mesa/drivers/dri/i915/i915_vtbl.c | 10 +++ src/mesa/drivers/dri/i915/intel_context.c | 49 ++++++++++++- src/mesa/drivers/dri/i915/intel_context.h | 85 ++--------------------- src/mesa/drivers/dri/i915/intel_tris.c | 12 ++++ 4 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c index 34350b1bb38..c927ec86373 100644 --- a/src/mesa/drivers/dri/i915/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915/i915_vtbl.c @@ -523,6 +523,15 @@ i915_flush_cmd(void) return MI_FLUSH | FLUSH_MAP_CACHE; } +static void +i915_assert_not_dirty( struct intel_context *intel ) +{ + struct i915_context *i915 = i915_context(&intel->ctx); + struct i915_hw_state *state = i915->current; + GLuint dirty = get_dirty(state); + assert(!dirty); +} + void i915InitVtbl(struct i915_context *i915) @@ -536,4 +545,5 @@ i915InitVtbl(struct i915_context *i915) i915->intel.vtbl.set_draw_region = i915_set_draw_region; i915->intel.vtbl.update_texture_state = i915UpdateTextureState; i915->intel.vtbl.flush_cmd = i915_flush_cmd; + i915->intel.vtbl.assert_not_dirty = i915_assert_not_dirty; } diff --git a/src/mesa/drivers/dri/i915/intel_context.c b/src/mesa/drivers/dri/i915/intel_context.c index 252c0d6f424..04bed35fe19 100644 --- a/src/mesa/drivers/dri/i915/intel_context.c +++ b/src/mesa/drivers/dri/i915/intel_context.c @@ -231,6 +231,7 @@ static const struct dri_debug_control debug_control[] = { {"buf", DEBUG_BUFMGR}, {"reg", DEBUG_REGION}, {"fbo", DEBUG_FBO}, + {"lock", DEBUG_LOCK}, {NULL, 0} }; @@ -595,8 +596,8 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv, return GL_TRUE; } -void -intelGetLock(struct intel_context *intel, GLuint flags) +static void +intelContendedLock(struct intel_context *intel, GLuint flags) { __DRIdrawablePrivate *dPriv = intel->driDrawable; __DRIscreenPrivate *sPriv = intel->driScreen; @@ -605,6 +606,9 @@ intelGetLock(struct intel_context *intel, GLuint flags) drmGetLock(intel->driFd, intel->hHWContext, flags); + if (INTEL_DEBUG & DEBUG_LOCK) + _mesa_printf("%s - got contended lock\n", __progname); + /* If the window moved, may need to set a new cliprect now. * * NOTE: This releases and regains the hw lock, so all state @@ -646,3 +650,44 @@ intelGetLock(struct intel_context *intel, GLuint flags) intel->lastStamp = dPriv->lastStamp; } } + + +extern _glthread_Mutex lockMutex; + + +/* Lock the hardware and validate our state. + */ +void LOCK_HARDWARE( struct intel_context *intel ) +{ + char __ret=0; + + _glthread_LOCK_MUTEX(lockMutex); + assert(!intel->locked); + + DRM_CAS(intel->driHwLock, intel->hHWContext, + (DRM_LOCK_HELD|intel->hHWContext), __ret); + + if (__ret) + intelContendedLock( intel, 0 ); + + if (INTEL_DEBUG & DEBUG_LOCK) + _mesa_printf("%s - locked\n", __progname); + + intel->locked = 1; +} + + + /* Unlock the hardware using the global current context + */ +void UNLOCK_HARDWARE( struct intel_context *intel ) +{ + intel->locked = 0; + + DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext); + + _glthread_UNLOCK_MUTEX(lockMutex); + + if (INTEL_DEBUG & DEBUG_LOCK) + _mesa_printf("%s - unlocked\n", __progname); +} + diff --git a/src/mesa/drivers/dri/i915/intel_context.h b/src/mesa/drivers/dri/i915/intel_context.h index 2e3097a905a..ef8993c69b5 100644 --- a/src/mesa/drivers/dri/i915/intel_context.h +++ b/src/mesa/drivers/dri/i915/intel_context.h @@ -173,6 +173,8 @@ struct intel_context void (*rotate_window) (struct intel_context * intel, __DRIdrawablePrivate * dPriv, GLuint srcBuf); + void (*assert_not_dirty) (struct intel_context *intel); + } vtbl; GLint refcount; @@ -285,86 +287,12 @@ struct intel_context }; - -#define DEBUG_LOCKING 1 - -#if DEBUG_LOCKING - -#define DEBUG_LOCK() \ - do { \ - intel->prevLockFile = (__FILE__); \ - intel->prevLockLine = (__LINE__); \ - } while (0) - -#define DEBUG_RESET() \ - do { \ - intel->prevLockFile = 0; \ - intel->prevLockLine = 0; \ - } while (0) - -/* Slightly less broken way of detecting recursive locking in a - * threaded environment. The right way to do this would be to make - * prevLockFile, prevLockLine thread-local. - * - * This technique instead checks to see if the same context is - * requesting the lock twice -- this will not catch application - * breakages where the same context is active in two different threads - * at once, but it will catch driver breakages (recursive locking) in - * threaded apps. +/* These are functions now: */ -#define DEBUG_CHECK_LOCK() \ - do { \ - if ( *((volatile int *)intel->driHwLock) == \ - (DRM_LOCK_HELD | intel->hHWContext) ) { \ - fprintf( stderr, \ - "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \ - intel->prevLockFile, intel->prevLockLine, \ - __FILE__, __LINE__ ); \ - abort(); \ - } \ - } while (0) +void LOCK_HARDWARE( struct intel_context *intel ); +void UNLOCK_HARDWARE( struct intel_context *intel ); -#else - -#define DEBUG_LOCK() -#define DEBUG_RESET() -#define DEBUG_CHECK_LOCK() - -#endif - -extern _glthread_Mutex lockMutex; - - -/* Lock the hardware and validate our state. - */ -#define LOCK_HARDWARE( intel ) \ -do { \ - char __ret=0; \ - _glthread_LOCK_MUTEX(lockMutex); \ - DEBUG_CHECK_LOCK(); \ - assert(!(intel)->locked); \ - DRM_CAS((intel)->driHwLock, (intel)->hHWContext, \ - (DRM_LOCK_HELD|(intel)->hHWContext), __ret); \ - if (__ret) \ - intelGetLock( (intel), 0 ); \ - DEBUG_LOCK(); \ - (intel)->locked = 1; \ -}while (0) - - - /* Unlock the hardware using the global current context - */ -#define UNLOCK_HARDWARE(intel) \ -do { \ - intel->locked = 0; \ - if (0) { \ - intel->perf_boxes |= intel->sarea->perf_boxes; \ - intel->sarea->perf_boxes = 0; \ - } \ - DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext); \ - DEBUG_RESET(); \ - _glthread_UNLOCK_MUTEX(lockMutex); \ -} while (0) +extern char *__progname; #define SUBPIXEL_X 0.125 @@ -444,6 +372,7 @@ extern int INTEL_DEBUG; #define DEBUG_BUFMGR 0x200 #define DEBUG_REGION 0x400 #define DEBUG_FBO 0x800 +#define DEBUG_LOCK 0x1000 #define DBG(...) do { if (INTEL_DEBUG & FILE_DEBUG_FLAG) _mesa_printf(__VA_ARGS__); } while(0) diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c index 7dbbaa65751..5ea7b7ffbe2 100644 --- a/src/mesa/drivers/dri/i915/intel_tris.c +++ b/src/mesa/drivers/dri/i915/intel_tris.c @@ -58,6 +58,8 @@ intel_flush_inline_primitive(struct intel_context *intel) assert(intel->prim.primitive != ~0); +/* _mesa_printf("/\n"); */ + if (used < 8) goto do_discard; @@ -94,6 +96,8 @@ intelStartInlinePrimitive(struct intel_context *intel, intel->vtbl.emit_state(intel); } +/* _mesa_printf("%s *", __progname); */ + /* Emit a slot which will be filled with the inline primitive * command later. */ @@ -106,6 +110,8 @@ intelStartInlinePrimitive(struct intel_context *intel, OUT_BATCH(0); ADVANCE_BATCH(); + +/* _mesa_printf(">"); */ } @@ -127,9 +133,15 @@ intelExtendInlinePrimitive(struct intel_context *intel, GLuint dwords) GLuint sz = dwords * sizeof(GLuint); GLuint *ptr; + assert(intel->prim.flush == intel_flush_inline_primitive); + if (intel_batchbuffer_space(intel->batch) < sz) intelWrapInlinePrimitive(intel); +/* _mesa_printf("."); */ + + intel->vtbl.assert_not_dirty(intel); + ptr = (GLuint *) intel->batch->ptr; intel->batch->ptr += sz;