[Bf-blender-cvs] [53025e9] soc-2013-paint: Use spinlocks for tile initialization.

Antony Riakiotakis noreply at git.blender.org
Wed Jul 9 22:29:07 CEST 2014


Commit: 53025e92604c8749332ad17d8b8b24f989923b0e
Author: Antony Riakiotakis
Date:   Wed Jul 9 23:28:28 2014 +0300
https://developer.blender.org/rB53025e92604c8749332ad17d8b8b24f989923b0e

Use spinlocks for tile initialization.

===================================================================

M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_intern.h

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 2a206e1..9524a94 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -122,6 +122,17 @@ typedef struct UndoImageTile {
  * Maybe it should be exposed as part of the
  * paint operation, but for now just give a public interface */
 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
+static SpinLock undolock;
+
+void image_undo_init_locks()
+{
+	BLI_spin_init(&undolock);
+}
+
+void image_undo_end_locks()
+{
+	BLI_spin_end(&undolock);
+}
 
 ImagePaintPartialRedraw *get_imapaintpartial(void)
 {
@@ -259,13 +270,13 @@ void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int x_tile,
 	undo_copy_tile(tile, *tmpibuf, ibuf, COPY);
 
 	if (proj)
-		BLI_lock_thread(LOCK_CUSTOM1);
+		BLI_spin_lock(&undolock);
 
 	undo_paint_push_count_alloc(UNDO_PAINT_IMAGE, allocsize);
 	BLI_addtail(lb, tile);
 
 	if (proj)
-		BLI_unlock_thread(LOCK_CUSTOM1);
+		BLI_spin_unlock(&undolock);
 
 	return tile->rect.pt;
 }
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 570cf32..80c4d45 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -295,6 +295,8 @@ typedef struct ProjPaintState {
 	bool need_redraw;
 
 	BlurKernel *blurkernel;
+
+	SpinLock *tile_lock;
 } ProjPaintState;
 
 typedef union pixelPointer {
@@ -340,7 +342,7 @@ typedef struct ProjPixelClone {
 
 /* undo tile pushing */
 typedef struct {
-	bool threaded;
+	SpinLock *lock;
 	bool masked;
 	unsigned short tile_width;
 	ImBuf **tmpibuf;
@@ -1343,14 +1345,14 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
 
 	/* double check lock to avoid locking */
 	if (UNLIKELY(!pjIma->undoRect[tile_index])) {
-		if (tinf->threaded)
-			BLI_lock_thread(LOCK_CUSTOM1);
+		if (tinf->lock)
+			BLI_spin_lock(tinf->lock);
 		if (LIKELY(!pjIma->undoRect[tile_index])) {
 			pjIma->undoRect[tile_index] = TILE_PENDING;
 			generate_tile = true;
 		}
-		if (tinf->threaded)
-			BLI_unlock_thread(LOCK_CUSTOM1);
+		if (tinf->lock)
+			BLI_spin_unlock(tinf->lock);
 	}
 
 
@@ -1365,7 +1367,12 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
 
 		pjIma->ibuf->userflags |= IB_BITMAPDIRTY;
 		/* tile ready, publish */
+		if (tinf->lock)
+			BLI_spin_lock(tinf->lock);
 		pjIma->undoRect[tile_index] = undorect;
+		if (tinf->lock)
+			BLI_spin_unlock(tinf->lock);
+
 	}
 
 	return tile_index;
@@ -2238,9 +2245,10 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i
 	MemArena *arena = ps->arena_mt[thread_index];
 	LinkNode **bucketPixelNodes = ps->bucketRect + bucket_index;
 	LinkNode *bucketFaceNodes = ps->bucketFaces[bucket_index];
+	bool threaded = (ps->thread_tot > 1);
 
 	TileInfo tinf = {
-		(ps->thread_tot > 1),
+		ps->tile_lock,
 		ps->do_masking,
 		IMAPAINT_TILE_NUMBER(ibuf->x),
 		tmpibuf,
@@ -2267,7 +2275,6 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i
 	float pixelScreenCo[4];
 	bool do_3d_mapping = ps->brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D;
 
-	bool threaded = (ps->thread_tot > 1);
 	rcti bounds_px; /* ispace bounds */
 	/* vars for getting uvspace bounds */
 
@@ -3210,6 +3217,13 @@ static void project_paint_begin(ProjPaintState *ps)
 	if (reset_threads)
 		ps->thread_tot = 1;
 
+	if (ps->thread_tot > 1) {
+		ps->tile_lock = MEM_mallocN(sizeof(SpinLock), "projpaint_tile_lock");
+		BLI_spin_init(ps->tile_lock);
+	}
+
+	image_undo_init_locks();
+
 	for (a = 0; a < ps->thread_tot; a++) {
 		ps->arena_mt[a] = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "project paint arena");
 	}
@@ -3464,6 +3478,11 @@ static void project_paint_end(ProjPaintState *ps)
 	MEM_freeN(ps->dm_mtface);
 	if (ps->do_layer_clone)
 		MEM_freeN(ps->dm_mtface_clone);
+	if (ps->thread_tot > 1) {
+		BLI_spin_end(ps->tile_lock);
+		MEM_freeN((void *)ps->tile_lock);
+	}
+	image_undo_end_locks();
 
 #ifndef PROJ_DEBUG_NOSEAMBLEED
 	if (ps->seam_bleed_px > 0.0f) {
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 97ed1c8..0d82294 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -150,6 +150,9 @@ int image_texture_paint_poll(struct bContext *C);
 void *image_undo_find_tile(struct Image *ima, struct ImBuf *ibuf, int x_tile, int y_tile, unsigned short **mask, bool validate);
 void *image_undo_push_tile(struct Image *ima, struct ImBuf *ibuf, struct ImBuf **tmpibuf, int x_tile, int y_tile,  unsigned short **, bool **valid, bool proj);
 void image_undo_remove_masks(void);
+void image_undo_init_locks(void);
+void image_undo_end_locks(void);
+
 void imapaint_image_update(struct SpaceImage *sima, struct Image *image, struct ImBuf *ibuf, short texpaint);
 struct ImagePaintPartialRedraw *get_imapaintpartial(void);
 void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr);




More information about the Bf-blender-cvs mailing list