35#define ALLOC_DEPTHS 200
38#define DEPTH_MAX 0xffffffff
89 return (*prev != *curr) && (*curr !=
DEPTH_MAX);
119 for (
uint i = 0; i < rect_len; i++, curr++) {
133 for (; curr < curr_end; curr++, curr++) {
138 curr += sub_rect->
skip;
148 return memcmp(rect_depth_a->buf, rect_depth_b->buf, rect_len *
sizeof(
depth_t)) != 0;
152 for (
uint i = 0; i < rect_len; i++, curr++, prev++) {
173 for (; curr < curr_end; prev++, curr++) {
178 prev += sub_rect->
skip;
179 curr += sub_rect->
skip;
200 if (d1->
id < d2->id) {
203 if (d1->
id > d2->id) {
213 if (d1->
depth < d2->depth) {
216 if (d1->
depth > d2->depth) {
271 ListBaseT<DepthBufCache>
bufs;
303 printf(
"%s: mode=%d, use_cache=%d, is_cache=%d\n",
316 ps->
dst.clip_rect = *input;
317 ps->
dst.rect_len = rect_len;
337 ps->
src.clip_rect = *input;
338 ps->
src.rect_len = rect_len;
340 ps->
gpu.clip_readpixels[0] = int(viewport[0]);
341 ps->
gpu.clip_readpixels[1] = int(viewport[1]);
356 for (
uint i = 0; i < rect_len; i++) {
360 ps->
gpu.is_init =
false;
373 ps->all.hits_len = 0;
379 memset(ps->nearest.rect_id, 0xff,
sizeof(
uint) * ps->
dst.rect_len);
390 const uint id = rect_curr->
id;
395 if (depth_best > *curr) { \
396 depth_best = *curr; \
403 const uint rect_len = ps->
src.rect_len;
404 for (
uint i = 0; i < rect_len; i++, curr++) {
411 for (
uint i = 0; i < ps->
cache.sub_rect.span_len; i++) {
412 const depth_t *curr_end = curr + ps->
cache.sub_rect.span;
413 for (; curr < curr_end; curr++) {
416 curr += ps->
cache.sub_rect.skip;
423 if (ps->all.hits_len == ps->all.hits_len_alloc) [[unlikely]] {
425 ps->all.hits =
static_cast<DepthID *
>(
428 DepthID *d = &ps->all.hits[ps->all.hits_len++];
430 d->
depth = depth_best;
437 const uint id = rect_curr->
id;
440 uint *id_ptr = ps->nearest.rect_id;
446 if (depth_is_filled(prev, curr)) { \
455 const uint rect_len = ps->
src.rect_len;
456 for (
uint i = 0; i < rect_len; i++, curr++, prev++, id_ptr++) {
464 for (
uint i = 0; i < ps->
cache.sub_rect.span_len; i++) {
465 const depth_t *curr_end = curr + ps->
cache.sub_rect.span;
466 for (; curr < curr_end; prev++, curr++, id_ptr++) {
469 prev += ps->
cache.sub_rect.skip;
470 curr += ps->
cache.sub_rect.skip;
482 if (ps->
gpu.is_init) {
483 if (
id == ps->
gpu.prev_id && !end) {
489 const uint rect_len = ps->
src.rect_len;
495 bool do_pass =
false;
498 ps->
gpu.rect_depth_test->id = ps->
gpu.prev_id;
505 ps->
gpu.rect_depth_test->id = ps->
gpu.prev_id;
518 std::swap(ps->
gpu.rect_depth, ps->
gpu.rect_depth_test);
532 ps->
gpu.is_init =
true;
533 ps->
gpu.prev_id =
id;
547 if (ps->
gpu.is_init) {
564 ps->
gpu.rect_depth =
nullptr;
565 rect_depth_final = ps->
cache.bufs.last();
568 rect_depth_final = ps->
cache.bufs.last();
572 rect_depth_final = ps->
gpu.rect_depth;
576 uint depth_data_len = 0;
579 depth_data = ps->all.hits;
580 depth_data_len = ps->all.hits_len;
582 ps->all.hits =
nullptr;
583 ps->all.hits_len = 0;
584 ps->all.hits_len_alloc = 0;
590 uint depth_data_len_first_pass = 0;
597#define EVAL_TEST(i_src, i_dst) \
599 const uint id = ps->nearest.rect_id[i_dst]; \
600 if (id != SELECT_ID_NONE) { \
601 const depth_t depth = rect_depth_final->buf[i_src]; \
602 if (depth_last == nullptr || depth_last->id != id) { \
603 DepthID *d = &depth_data[depth_data_len_first_pass++]; \
607 else if (depth_last->depth > depth) { \
608 depth_last->depth = depth; \
617 for (
uint i = 0; i < ps->
src.rect_len; i++) {
623 uint i_src = ps->
cache.sub_rect.start, i_dst = 0;
624 for (
uint j = 0; j < ps->
cache.sub_rect.span_len; j++) {
625 const uint i_src_end = i_src + ps->
cache.sub_rect.span;
626 for (; i_src < i_src_end; i_src++, i_dst++) {
629 i_src += ps->
cache.sub_rect.skip;
642 for (
uint i = 0; i < depth_data_len_first_pass; i++) {
643 if (depth_last ==
nullptr || depth_last->
id != depth_data[i].
id) {
644 depth_last = &depth_data[depth_data_len++];
645 *depth_last = depth_data[i];
647 else if (depth_last->
depth > depth_data[i].
depth) {
662 for (
uint i = 0; i < depth_data_len; i++) {
664 printf(
" hit: %u: depth %u\n", depth_data[i].
id, depth_data[i].depth);
667 hit_result.
id = depth_data[i].
id;
673 MEM_delete(depth_data);
675 MEM_SAFE_DELETE(ps->
gpu.rect_depth);
676 MEM_SAFE_DELETE(ps->
gpu.rect_depth_test);
682 MEM_delete(ps->nearest.rect_id);
683 ps->nearest.rect_id =
nullptr;
732 printf(
"%s (building depth from cache)\n", __func__);
735 if (rect_depth.
next !=
nullptr) {
Read Blender memory allocation and freeing.
#define MEM_realloc_uninitialized(vmemh, len)
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BLI_INLINE bool depth_is_filled(const depth_t *prev, const depth_t *curr)
gpu::FrameBuffer * GPU_framebuffer_active_get()
GPUWriteMask GPU_write_mask_get()
void gpu_select_pick_begin(GPUSelectBuffer *buffer, const rcti *input, GPUSelectMode mode)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
GPUDepthTest GPU_depth_test_get()
bool gpu_select_pick_load_id(uint id, bool end)
BLI_INLINE float fb(float length, float L)
void gpu_select_pick_cache_begin()
static bool depth_buf_subrect_depth_any_filled(const DepthBufCache *rect_src, const DepthBufCache *rect_dst, const SubRectStride *sub_rect)
void GPU_clear_depth(float depth)
static int depth_id_cmp(const void *v1, const void *v2)
void GPU_depth_mask(bool depth)
void gpu_select_pick_cache_end()
static int depth_cmp(const void *v1, const void *v2)
static bool depth_buf_rect_depth_any(const DepthBufCache *rect_depth, uint rect_len)
static bool depth_buf_rect_depth_any_filled(const DepthBufCache *rect_prev, const DepthBufCache *rect_curr, uint rect_len)
static GPUPickState g_pick_state
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void GPU_viewport_size_get_f(float coords[4])
static void gpu_select_load_id_pass_nearest(const DepthBufCache *rect_prev, const DepthBufCache *rect_curr)
void GPU_scissor_get(int coords[4])
bool GPU_depth_mask_get()
void GPU_color_mask(bool r, bool g, bool b, bool a)
static bool depth_buf_subrect_depth_any(const DepthBufCache *rect_depth, const SubRectStride *sub_rect)
uint gpu_select_pick_end()
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void GPU_debug_group_end()
static DepthBufCache * depth_buf_malloc(uint rect_len)
bool gpu_select_pick_is_cached()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void gpu_select_pick_cache_load_id()
static void gpu_select_load_id_pass_all(const DepthBufCache *rect_curr)
void GPU_viewport(int x, int y, int width, int height)
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void GPU_depth_test(GPUDepthTest test)
static void rect_subregion_stride_calc(const rcti *src, const rcti *dst, SubRectStride *r_sub)
void GPU_write_mask(GPUWriteMask mask)
void GPU_debug_group_begin(const char *name)
ListBaseT< DepthBufCache > bufs
DepthBufCache * rect_depth
DepthBufCache * rect_depth_test
struct blender::GPUPickState::@237160012157103054135253154261345100325061036241 gpu
struct blender::GPUPickState::@341047125372111172251217223051052316337032215273 dst
struct blender::GPUPickState::@341047125372111172251217223051052316337032215273 src
struct blender::GPUPickState::@051005354226036273374115173066131237112043103074 cache
struct blender::GPUPickState::@364023105341251130237061015042314333367143353064::@036170307022304230102310351335062032200332310226 all
struct blender::GPUPickState::@364023105341251130237061015042314333367143353064::@370040275105014177254277343216324033054106174152 nearest