33#define ALLOC_DEPTHS 200
36#define DEPTH_MAX 0xffffffff
87 return (*prev != *curr) && (*curr !=
DEPTH_MAX);
117 for (
uint i = 0;
i < rect_len;
i++, curr++) {
131 for (; curr < curr_end; curr++, curr++) {
136 curr += sub_rect->
skip;
146 return memcmp(rect_depth_a->buf, rect_depth_b->buf, rect_len *
sizeof(
depth_t)) != 0;
150 for (
uint i = 0;
i < rect_len;
i++, curr++, prev++) {
171 for (; curr < curr_end; prev++, curr++) {
176 prev += sub_rect->
skip;
177 curr += sub_rect->
skip;
198 if (d1->
id < d2->id) {
201 if (d1->
id > d2->id) {
211 if (d1->
depth < d2->depth) {
214 if (d1->
depth > d2->depth) {
301 printf(
"%s: mode=%d, use_cache=%d, is_cache=%d\n",
315 ps->
dst.rect_len = rect_len;
336 ps->
src.rect_len = rect_len;
338 ps->
gpu.clip_readpixels[0] = int(viewport[0]);
339 ps->
gpu.clip_readpixels[1] = int(viewport[1]);
354 for (
uint i = 0;
i < rect_len;
i++) {
358 ps->
gpu.is_init =
false;
370 ps->all.hits =
static_cast<DepthID *
>(
372 ps->all.hits_len = 0;
378 memset(ps->nearest.rect_id, 0xff,
sizeof(
uint) * ps->
dst.rect_len);
389 const uint id = rect_curr->
id;
394 if (depth_best > *curr) { \
395 depth_best = *curr; \
402 const uint rect_len = ps->
src.rect_len;
403 for (
uint i = 0;
i < rect_len;
i++, curr++) {
410 for (
uint i = 0;
i < ps->
cache.sub_rect.span_len;
i++) {
411 const depth_t *curr_end = curr + ps->
cache.sub_rect.span;
412 for (; curr < curr_end; curr++) {
415 curr += ps->
cache.sub_rect.skip;
422 if (
UNLIKELY(ps->all.hits_len == ps->all.hits_len_alloc)) {
424 ps->all.hits =
static_cast<DepthID *
>(
425 MEM_reallocN(ps->all.hits, ps->all.hits_len_alloc *
sizeof(*ps->all.hits)));
427 DepthID *d = &ps->all.hits[ps->all.hits_len++];
429 d->
depth = depth_best;
436 const uint id = rect_curr->
id;
439 uint *id_ptr = ps->nearest.rect_id;
445 if (depth_is_filled(prev, curr)) { \
454 const uint rect_len = ps->
src.rect_len;
455 for (
uint i = 0;
i < rect_len;
i++, curr++, prev++, id_ptr++) {
463 for (
uint i = 0;
i < ps->
cache.sub_rect.span_len;
i++) {
464 const depth_t *curr_end = curr + ps->
cache.sub_rect.span;
465 for (; curr < curr_end; prev++, curr++, id_ptr++) {
468 prev += ps->
cache.sub_rect.skip;
469 curr += ps->
cache.sub_rect.skip;
481 if (ps->
gpu.is_init) {
482 if (
id == ps->
gpu.prev_id && !end) {
488 const uint rect_len = ps->
src.rect_len;
494 bool do_pass =
false;
497 ps->
gpu.rect_depth_test->id = ps->
gpu.prev_id;
504 ps->
gpu.rect_depth_test->id = ps->
gpu.prev_id;
517 std::swap(ps->
gpu.rect_depth, ps->
gpu.rect_depth_test);
531 ps->
gpu.is_init =
true;
532 ps->
gpu.prev_id = id;
546 if (ps->
gpu.is_init) {
563 ps->
gpu.rect_depth =
nullptr;
571 rect_depth_final = ps->
gpu.rect_depth;
575 uint depth_data_len = 0;
578 depth_data = ps->all.hits;
579 depth_data_len = ps->all.hits_len;
581 ps->all.hits =
nullptr;
582 ps->all.hits_len = 0;
583 ps->all.hits_len_alloc = 0;
589 uint depth_data_len_first_pass = 0;
590 depth_data =
static_cast<DepthID *
>(
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; \
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;
683 ps->nearest.rect_id =
nullptr;
732 printf(
"%s (building depth from cache)\n", __func__);
735 if (rect_depth->next !=
nullptr) {
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_read_depth(GPUFrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void GPU_clear_depth(float depth)
void GPU_write_mask(eGPUWriteMask mask)
void GPU_depth_mask(bool depth)
eGPUDepthTest GPU_depth_test_get()
void GPU_color_mask(bool r, bool g, bool b, bool a)
eGPUWriteMask GPU_write_mask_get()
void GPU_viewport(int x, int y, int width, int height)
void GPU_depth_test(eGPUDepthTest test)
void GPU_viewport_size_get_f(float coords[4])
bool GPU_depth_mask_get()
void GPU_scissor_get(int coords[4])
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
bool gpu_select_pick_load_id(uint id, bool end)
static DepthBufCache * depth_buf_malloc(uint rect_len)
static bool depth_buf_subrect_depth_any(const DepthBufCache *rect_depth, const SubRectStride *sub_rect)
static int depth_cmp(const void *v1, const void *v2)
uint gpu_select_pick_end()
void gpu_select_pick_cache_begin()
BLI_INLINE bool depth_is_filled(const depth_t *prev, const depth_t *curr)
static bool depth_buf_subrect_depth_any_filled(const DepthBufCache *rect_src, const DepthBufCache *rect_dst, const SubRectStride *sub_rect)
static void rect_subregion_stride_calc(const rcti *src, const rcti *dst, SubRectStride *r_sub)
bool gpu_select_pick_is_cached()
static int depth_id_cmp(const void *v1, const void *v2)
void gpu_select_pick_cache_load_id()
static GPUPickState g_pick_state
static void gpu_select_load_id_pass_all(const DepthBufCache *rect_curr)
static bool depth_buf_rect_depth_any_filled(const DepthBufCache *rect_prev, const DepthBufCache *rect_curr, uint rect_len)
static void gpu_select_load_id_pass_nearest(const DepthBufCache *rect_prev, const DepthBufCache *rect_curr)
void gpu_select_pick_begin(GPUSelectBuffer *buffer, const rcti *input, eGPUSelectMode mode)
void gpu_select_pick_cache_end()
static bool depth_buf_rect_depth_any(const DepthBufCache *rect_depth, uint rect_len)
#define MEM_reallocN(vmemh, len)
BLI_INLINE float fb(float length, float L)
void * MEM_mallocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
DepthBufCache * rect_depth
DepthBufCache * rect_depth_test
struct GPUPickState::@234213314316062174247134113307205375267261114227 dst
struct GPUPickState::@313127256056100134120231346173201245334242246175 cache
struct GPUPickState::@305343220325231166250147025075012126162015005272 gpu
struct GPUPickState::@234213314316062174247134113307205375267261114227 src
struct GPUPickState::@222047000042147126135231006054064345236121275126::@241275111371337277325054074226201064153135253057 all
struct GPUPickState::@222047000042147126135231006054064345236121275126::@224005161342255311323146063114277315032255345075 nearest