[Bf-blender-cvs] [4605429be7] temp-select-pick: Debugging code to compare cached/uncached outcome

Campbell Barton noreply at git.blender.org
Wed Mar 8 12:01:19 CET 2017


Commit: 4605429be72ced435517c86baae2cda30c26b237
Author: Campbell Barton
Date:   Wed Mar 8 21:50:48 2017 +1100
Branches: temp-select-pick
https://developer.blender.org/rB4605429be72ced435517c86baae2cda30c26b237

Debugging code to compare cached/uncached outcome

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

M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/gpu/intern/gpu_select_pick.c

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

diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 73597ba0e6..6c5b13ec1c 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1240,7 +1240,13 @@ static int mixed_bones_object_selectbuffer(
 	int hits = 0;
 
 	/* we _must_ end cache before return, use 'goto finally' */
-	GPU_select_cache_begin();
+	static int A = 0;
+	A = !A;
+
+	if (A) {
+		GPU_select_cache_begin();
+	}
+	/* GPU_select_cache_begin(); */
 
 	BLI_rcti_init_pt_size(&rect, mval, 14);
 	hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
@@ -1479,8 +1485,8 @@ static bool ed_object_select_pick(
 		bool do_nearest;
 
 		/* if objects have posemode set, the bones are in the same selection buffer */
-		
-		hits = mixed_bones_object_selectbuffer(&vc, buffer, mval, true, enumerate, &do_nearest);
+		int mvalA[2] = {500, 500};
+		hits = mixed_bones_object_selectbuffer(&vc, buffer, mvalA, true, enumerate, &do_nearest);
 		
 		if (hits > 0) {
 			/* note: bundles are handling in the same way as bones */
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 0e060d4071..7c3989dce1 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -55,6 +55,36 @@
 /* Z-depth of cleared depth buffer */
 #define DEPTH_MAX 1.0
 
+#define SEED 5381
+
+static uint64_t hash_u8_r(const char *key, size_t n, uint64_t *r_h)
+{
+	const signed char *p;
+	uint64_t h = *r_h;
+	for (p = (const signed char *)key; n--; p++) {
+		h = (h << 5) + h + (unsigned int)*p;
+	}
+	*r_h = h;
+	return h;
+}
+static uint64_t hash_f32_r(const float *key, size_t n, uint64_t *r_h)
+{
+	return hash_u8_r((const char *)key, n * 4, r_h);
+}
+/*
+static uint64_t hash_u8(const char *key, size_t n)
+{
+	uint64_t h = SEED;
+	return hash_u8_r(key, n, &h);
+}
+*/
+static uint64_t hash_f32(const float *key, size_t n)
+{
+	uint64_t h = SEED;
+	return hash_f32_r(key, n, &h);
+}
+
+
 /* For looping over a sub-region of a rect, could be moved into 'rct.c'*/
 typedef struct SubRectStride {
 	unsigned int start;  /* start here */
@@ -101,6 +131,26 @@ static DepthBufCache *depth_buf_malloc(unsigned int rect_len)
 	return rect;
 }
 
+static bool depth_buf_subrect_equal(
+        const SubRectStride *sub_rect,
+        const DepthBufCache *rect_src, const DepthBufCache *rect_dst)
+{
+	/* same as above but different rect sizes */
+	const float *prev = rect_src->buf + sub_rect->start;
+	const float *curr = rect_dst->buf + sub_rect->start;
+	for (unsigned int i = 0; i < sub_rect->len; i++) {
+		const float *prev_end = prev + sub_rect->span;
+		for (; prev < prev_end; prev++, curr++) {
+			if (*prev != *curr) {
+				return false;
+			}
+		}
+		prev += sub_rect->skip;
+		curr += sub_rect->skip;
+	}
+	return true;
+}
+
 typedef struct DepthID {
 	unsigned int id;
 	float depth;
@@ -244,7 +294,7 @@ void gpu_select_pick_begin(
 		ps->gl.rect_depth = depth_buf_malloc(rect_len);
 
 		/* set initial 'far' value */
-#if 0
+#if 1
 		glReadPixels(UNPACK4(ps->gl.clip_readpixels), GL_DEPTH_COMPONENT, GL_FLOAT, ps->gl.rect_depth->buf);
 #else
 		copy_vn_fl(ps->gl.rect_depth->buf, rect_len, DEPTH_MAX);
@@ -292,6 +342,44 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const Depth
 {
 	GPUPickState *ps = &g_pick_state;
 	const unsigned int prev_id = rect_depth_test->id;
+
+#ifdef DEBUG_PRINT
+	if (ps->is_cached == false) {
+		printf("%s: (%llX, %llX)\n", __func__,
+		       hash_f32(rect_depth->buf, ps->src.rect_len),
+		       hash_f32(rect_depth_test->buf, ps->src.rect_len));
+	}
+	else {
+
+		uint64_t p = SEED;
+		uint64_t c = SEED;
+
+		/* same as above but different rect sizes */
+		const float *prev = rect_depth->buf + ps->cache.sub_rect.start;
+		const float *curr = rect_depth_test->buf + ps->cache.sub_rect.start;
+		bool diff_found = false;
+		for (unsigned int i = 0; i < ps->cache.sub_rect.len; i++) {
+			const float *prev_end = prev + ps->cache.sub_rect.span;
+			for (; prev < prev_end; prev++, curr++) {
+				hash_f32_r(prev, 1, &p);
+				hash_f32_r(curr, 1, &c);
+				if (*prev != *curr) {
+					diff_found = true;
+				}
+			}
+			prev += ps->cache.sub_rect.skip;
+			curr += ps->cache.sub_rect.skip;
+		}
+		if (!diff_found) {
+			return;
+		}
+		printf("%s: (%llX, %llX)\n", __func__,
+			   p,
+			   c);
+	}
+#endif
+
+
 	if (g_pick_state.mode == GPU_SELECT_PICK_SORT_ALL) {
 		/* find the best depth for this pass and store in 'all.hits' */
 		float depth_best = DEPTH_MAX;
@@ -604,7 +692,9 @@ void gpu_select_pick_cache_load_id(void)
 #endif
 	for (DepthBufCache *rect_depth = ps->cache.bufs.first; rect_depth; rect_depth = rect_depth->next) {
 		if (rect_depth->next != NULL) {
-			gpu_select_load_id_pass(rect_depth, rect_depth->next);
+			if (!depth_buf_subrect_equal(&ps->cache.sub_rect, rect_depth, rect_depth->next)) {
+				gpu_select_load_id_pass(rect_depth, rect_depth->next);
+			}
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list