Revision: 70033 http://sourceforge.net/p/brlcad/code/70033 Author: mdtwenty Date: 2017-08-01 00:16:31 +0000 (Tue, 01 Aug 2017) Log Message: ----------- skipping unevaluated partitions
Modified Paths: -------------- brlcad/branches/opencl/include/rt/shoot.h brlcad/branches/opencl/src/librt/primitives/bool.cl brlcad/branches/opencl/src/librt/primitives/common.cl brlcad/branches/opencl/src/librt/primitives/primitive_util.c brlcad/branches/opencl/src/librt/primitives/rt.cl Modified: brlcad/branches/opencl/include/rt/shoot.h =================================================================== --- brlcad/branches/opencl/include/rt/shoot.h 2017-07-31 21:14:26 UTC (rev 70032) +++ brlcad/branches/opencl/include/rt/shoot.h 2017-08-01 00:16:31 UTC (rev 70033) @@ -183,8 +183,8 @@ cl_uint outseg; cl_uint forw_pp; /* index to the next partition */ cl_uint back_pp; /* index to the previous partition */ + cl_uint next_evalpp; /* index to the next evaluated partition */ cl_uint region_id; /* id of the "owning" region */ - cl_short evaluated; /* holds the result of boolean evaluation */ cl_char inflip; /* flip inhit->hit_normal */ cl_char outflip; /* flip outhit->hit_normal */ }; Modified: brlcad/branches/opencl/src/librt/primitives/bool.cl =================================================================== --- brlcad/branches/opencl/src/librt/primitives/bool.cl 2017-07-31 21:14:26 UTC (rev 70032) +++ brlcad/branches/opencl/src/librt/primitives/bool.cl 2017-08-01 00:16:31 UTC (rev 70033) @@ -108,6 +108,17 @@ } } +inline void +initialize_partition(global struct partition *partitions, const uint pp_idx) +{ + if (pp_idx != UINT_MAX) { + partitions[pp_idx].inflip = 0; + partitions[pp_idx].outflip = 0; + partitions[pp_idx].next_evalpp = UINT_MAX; + partitions[pp_idx].region_id = UINT_MAX; + } +} + /** * If a zero thickness segment abuts another partition, it will be * fused in, later. @@ -129,14 +140,12 @@ /* See if this segment ends before start of first partition */ if (segp->seg_out.hit_dist < partitions[*head].inhit.hit_dist) { newpp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); newpp->inseg = k; newpp->inhit = segp->seg_in; newpp->outseg = k; newpp->outhit = segp->seg_out; - newpp->inflip = 0; - newpp->outflip = 0; - newpp->evaluated = 0; set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); insert_partition_pp(partitions, ipartition, id, head, start_index + ipartition[id], *head); ipartition[id]++; @@ -169,13 +178,12 @@ if (pp->forw_pp != UINT_MAX && segp->seg_out.hit_dist < partitions[pp->forw_pp].inhit.hit_dist) { //0-len segment after existing partition, but before next partition. newpp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); + newpp->inseg = k; newpp->inhit = segp->seg_in; newpp->outseg = k; newpp->outhit = segp->seg_out; - newpp->inflip = 0; - newpp->outflip = 0; - newpp->evaluated = 0; set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); insert_partition_pp(partitions, ipartition, id, head, start_index + ipartition[id], pp->forw_pp); ipartition[id]++; @@ -187,7 +195,7 @@ __kernel void rt_boolweave(global struct partition *partitions, global uint *ipartition, RESULT_TYPE segs, global uint *h, global uint *segs_bv, const int cur_pixel, - const int last_pixel, const int max_depth) + const int last_pixel, const int max_depth, global uint *head_partition) { const size_t id = get_global_size(0)*get_global_id(1)+get_global_id(0); @@ -199,6 +207,8 @@ global struct partition *pp; double diff, diff_se; + head_partition[id] = UINT_MAX; + uint start_index = 2 * h[id]; uint head_pp = start_index; uint tail_pp = start_index; @@ -238,14 +248,12 @@ if (ipartition[id] == 0) { /* No partitions yet, simple! */ pp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); + pp->inseg = k; pp->inhit = segp->seg_in; pp->outseg = k; pp->outhit = segp->seg_out; - pp->inflip = 0; - pp->outflip = 0; - pp->evaluated = 0; - pp->region_id = UINT_MAX; set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); append_partition_pp(partitions, ipartition, id, start_index + ipartition[id], &tail_pp); ipartition[id]++; @@ -258,14 +266,12 @@ * beyond last partitions end. Make new partition. */ pp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); + pp->inseg = k; pp->inhit = segp->seg_in; pp->outseg = k; pp->outhit = segp->seg_out; - pp->inflip = 0; - pp->outflip = 0; - pp->evaluated = 0; - pp->region_id = UINT_MAX; set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); append_partition_pp(partitions, ipartition, id, start_index + ipartition[id], &tail_pp); ipartition[id]++; @@ -336,8 +342,6 @@ newpp->outseg = k; newpp->outhit = segp->seg_in; newpp->outflip = 1; - newpp->evaluated = 0; - newpp->region_id = UINT_MAX; insert_partition_pp(partitions, ipartition, id, &head_pp, start_index + ipartition[id], j); ipartition[id]++; } else if (diff > -(rti_tol_dist)) { @@ -375,13 +379,12 @@ * newpp|pp */ newpp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); newpp->inseg = lastseg; newpp->inhit = *lasthit; newpp->inflip = lastflip; - newpp->evaluated = 0; - newpp->region_id = UINT_MAX; diff = segp->seg_out.hit_dist - pp->inhit.hit_dist; if (diff < -(rti_tol_dist)) { /* @@ -490,8 +493,6 @@ newpp->outseg = k; newpp->outhit = segp->seg_out; newpp->outflip = 0; - newpp->evaluated = 0; - newpp->region_id = UINT_MAX; pp->inseg = k; pp->inhit = segp->seg_out; pp->inflip = 1; @@ -509,6 +510,8 @@ */ if (ipartition[id] > 0 && j == UINT_MAX) { newpp = &partitions[start_index + ipartition[id]]; + initialize_partition(partitions, start_index + ipartition[id]); + set(segs_bv, (start_index + ipartition[id]) * bv_index, k-h[id]); newpp->inseg = lastseg; newpp->inhit = *lasthit; @@ -515,9 +518,6 @@ newpp->inflip = lastflip; newpp->outseg = k; newpp->outhit = segp->seg_out; - newpp->outflip = 0; - newpp->evaluated = 0; - newpp->region_id = UINT_MAX; append_partition_pp(partitions, ipartition, id, start_index + ipartition[id], &tail_pp); ipartition[id]++; } @@ -526,7 +526,7 @@ if (ipartition[id] > 0) { /* Store the head index of the first partition in this ray */ - ipartition[id] = head_pp; + head_partition[id] = head_pp; } } @@ -815,7 +815,7 @@ global uint *h, global uint *segs_bv, const int max_depth, global struct bool_region *bregions, const uint total_regions, global union tree_rpn *rtree, global uint *regiontable, const int cur_pixel, const int last_pixel, - global uint *regions_table, const uint regions_table_size) + global uint *regions_table, const uint regions_table_size, global uint *head_partition) { const size_t id = get_global_size(0)*get_global_id(1)+get_global_id(0); @@ -832,12 +832,13 @@ uint lastpp_eval_idx = UINT_MAX; //No partitions - if (ipartition[id] == 0) { + if (head_partition[id] == UINT_MAX) { return; } //Get first partition of the ray - head = ipartition[id]; + head = head_partition[id]; + head_partition[id] = UINT_MAX; //iterate over partitions for (uint current_index = head; current_index != UINT_MAX; current_index = partitions[current_index].forw_pp) { @@ -939,6 +940,13 @@ { global struct partition *lastpp; + if (head_partition[id] == UINT_MAX) { + /* First partition evaluated for this ray + * Start shading at this partition index + */ + head_partition[id] = current_index; + } + /* Record the "owning" region. */ pp->region_id = lastregion_idx; @@ -948,6 +956,7 @@ if (lastpp_eval_idx != UINT_MAX) { /* there is one last partition evaluated for this ray */ lastpp = &partitions[lastpp_eval_idx]; + lastpp->next_evalpp = current_index; } if (lastpp_eval_idx != UINT_MAX && lastregion_idx == lastpp->region_id && @@ -963,7 +972,6 @@ set(segs_bv, lastpp_eval_idx + (bv_index - 1), pp->inseg - h[id]); set(segs_bv, lastpp_eval_idx + (bv_index - 1), pp->outseg - h[id]); } else { - pp->evaluated = 1; lastpp_eval_idx = current_index; } } Modified: brlcad/branches/opencl/src/librt/primitives/common.cl =================================================================== --- brlcad/branches/opencl/src/librt/primitives/common.cl 2017-07-31 21:14:26 UTC (rev 70032) +++ brlcad/branches/opencl/src/librt/primitives/common.cl 2017-08-01 00:16:31 UTC (rev 70033) @@ -69,8 +69,8 @@ uint outseg; uint forw_pp; /* index to the next partition */ uint back_pp; /* index to the previous partition */ + uint next_evalpp; /* index to the next evaluated partition */ uint region_id; /* id of the "owning" region */ - short evaluated; /* holds the result of boolean evaluation */ char inflip; /* flip inhit->hit_normal */ char outflip; /* flip outhit->hit_normal */ }; Modified: brlcad/branches/opencl/src/librt/primitives/primitive_util.c =================================================================== --- brlcad/branches/opencl/src/librt/primitives/primitive_util.c 2017-07-31 21:14:26 UTC (rev 70032) +++ brlcad/branches/opencl/src/librt/primitives/primitive_util.c 2017-08-01 00:16:31 UTC (rev 70033) @@ -890,6 +890,7 @@ size_t sz_ipartitions; cl_uint *ipart; cl_mem ipartitions; + cl_mem head_partition; size_t sz_partitions; cl_mem ppartitions; cl_int max_depth; @@ -987,6 +988,9 @@ ipartitions = clCreateBuffer(clt_context, CL_MEM_READ_WRITE|CL_MEM_COPY_HOST_PTR, sz_ipartitions, ipart, &error); if (error != CL_SUCCESS) bu_bomb("failed to create OpenCL index partitions buffer"); + + head_partition = clCreateBuffer(clt_context, CL_MEM_READ_WRITE|CL_MEM_COPY_HOST_PTR, sz_ipartitions, ipart, &error); + if (error != CL_SUCCESS) bu_bomb("failed to create OpenCL head partitions buffer"); bu_free(ipart, "ipart"); segs_bv = clCreateBuffer(clt_context, CL_MEM_READ_WRITE|CL_MEM_COPY_HOST_PTR, sz_bv, bv, &error); @@ -1010,6 +1014,7 @@ error |= clSetKernelArg(clt_boolweave_kernel, 5, sizeof(cl_int), &p.cur_pixel); error |= clSetKernelArg(clt_boolweave_kernel, 6, sizeof(cl_int), &p.last_pixel); error |= clSetKernelArg(clt_boolweave_kernel, 7, sizeof(cl_int), &max_depth); + error |= clSetKernelArg(clt_boolweave_kernel, 8, sizeof(cl_mem), &head_partition); if (error != CL_SUCCESS) bu_bomb("failed to set OpenCL kernel arguments"); error = clEnqueueNDRangeKernel(clt_queue, clt_boolweave_kernel, 1, NULL, &npix, &snpix, 0, NULL, NULL); @@ -1033,6 +1038,7 @@ error |= clSetKernelArg(clt_boolfinal_kernel, 11, sizeof(cl_int), &p.last_pixel); error |= clSetKernelArg(clt_boolfinal_kernel, 12, sizeof(cl_mem), &clt_db_regions_table); error |= clSetKernelArg(clt_boolfinal_kernel, 13, sizeof(cl_uint), &clt_db_regions_table_size); + error |= clSetKernelArg(clt_boolfinal_kernel, 14, sizeof(cl_mem), &head_partition); if (error != CL_SUCCESS) bu_bomb("failed to set OpenCL kernel arguments"); error = clEnqueueNDRangeKernel(clt_queue, clt_boolfinal_kernel, 1, NULL, &npix, &snpix, 0, NULL, NULL); @@ -1068,6 +1074,7 @@ error |= clSetKernelArg(clt_shade_segs_kernel, 26, sizeof(cl_mem), &ipartitions); error |= clSetKernelArg(clt_shade_segs_kernel, 27, sizeof(cl_mem), &segs_bv); error |= clSetKernelArg(clt_shade_segs_kernel, 28, sizeof(cl_int), &max_depth); + error |= clSetKernelArg(clt_shade_segs_kernel, 29, sizeof(cl_mem), &head_partition); if (error != CL_SUCCESS) bu_bomb("failed to set OpenCL kernel arguments"); error = clEnqueueNDRangeKernel(clt_queue, clt_shade_segs_kernel, 1, NULL, &npix, &snpix, 0, NULL, NULL); @@ -1079,6 +1086,7 @@ clReleaseMemObject(ppartitions); clReleaseMemObject(segs_bv); clReleaseMemObject(regiontable_bv); + clReleaseMemObject(head_partition); } break; default: Modified: brlcad/branches/opencl/src/librt/primitives/rt.cl =================================================================== --- brlcad/branches/opencl/src/librt/primitives/rt.cl 2017-07-31 21:14:26 UTC (rev 70032) +++ brlcad/branches/opencl/src/librt/primitives/rt.cl 2017-08-01 00:16:31 UTC (rev 70033) @@ -603,7 +603,7 @@ const double aspect, const int lightmodel, const uint nprims, global uchar *ids, global struct linear_bvh_node *nodes, global uint *indexes, global uchar *prims, global struct region *regions, global struct partition *partitions, global uint *ipartition, - global uint *segs_bv, const int max_depth) + global uint *segs_bv, const int max_depth, global uint *head_partition) { const size_t id = get_global_size(0)*get_global_id(1)+get_global_id(0); @@ -625,7 +625,7 @@ double3 a_color; uchar3 rgb; struct hit hitp; - uint pp_eval, head; + uint head; bool flipflag; uint region_id; @@ -632,91 +632,80 @@ a_color = 0.0; hitp.hit_dist = INFINITY; region_id = 0; - if (ipartition[id] > 0) { + if (head_partition[id] != UINT_MAX) { uint idx; idx = UINT_MAX; /* Get first partition of the ray */ - head = ipartition[id]; + head = head_partition[id]; flipflag = 0; - pp_eval = 0; - for (uint index = head; index != UINT_MAX; index = partitions[index].forw_pp) { + for (uint index = head; index != UINT_MAX; index = partitions[index].next_evalpp) { global struct partition *pp = &partitions[index]; + RESULT_TYPE segp = &segs[pp->inseg]; - if (pp->evaluated) { - RESULT_TYPE segp = &segs[pp->inseg]; - - if (segp->seg_in.hit_dist < hitp.hit_dist) { - hitp = pp->inhit; - idx = segp->seg_sti; - region_id = pp->region_id; - flipflag = pp->inflip; - } - pp_eval = 1; - } + if (segp->seg_in.hit_dist < hitp.hit_dist) { + hitp = pp->inhit; + idx = segp->seg_sti; + region_id = pp->region_id; + flipflag = pp->inflip; + } } - if (pp_eval) { - double3 normal; - if (hitp.hit_dist < 0.0) { - /* Eye inside solid, orthoview */ - normal = -r_dir; - } else { - norm(&hitp, r_pt, r_dir, ids[idx], prims + indexes[idx]); - hitp.hit_normal = flipflag ? -hitp.hit_normal : hitp.hit_normal; - normal = hitp.hit_normal; - } + double3 normal; - /* - * Diffuse reflectance from each light source - */ - a_color = shade(r_pt, r_dir, &hitp, lt_pos, region_id, regions); + if (hitp.hit_dist < 0.0) { + /* Eye inside solid, orthoview */ + normal = -r_dir; + } else { + norm(&hitp, r_pt, r_dir, ids[idx], prims + indexes[idx]); + hitp.hit_normal = flipflag ? -hitp.hit_normal : hitp.hit_normal; + normal = hitp.hit_normal; + } - /* - * e ^(-density * distance) - */ - if (!ZERO(airdensity)) { - double g; - double f = exp(-hitp.hit_dist * airdensity); - g = (1.0 - f); - a_color = a_color * f + haze * g; - } + /* + * Diffuse reflectance from each light source + */ + a_color = shade(r_pt, r_dir, &hitp, lt_pos, region_id, regions); - double3 t_color; + /* + * e ^(-density * distance) + */ + if (!ZERO(airdensity)) { + double g; + double f = exp(-hitp.hit_dist * airdensity); + g = (1.0 - f); + a_color = a_color * f + haze * g; + } - /* - * To prevent bad color aliasing, add some color dither. Be - * certain to NOT output the background color here. Random - * numbers in the range 0 to 1 are used, so that integer - * valued colors (e.g., from texture maps) retain their original - * values. - */ - if (!ZERO(gamma)) { - /* - * Perform gamma correction in floating-point space, and - * avoid nasty mach bands in dark areas from doing it in - * 0..255 space later. - */ - const double ex = 1.0/gamma; - t_color = floor(pow(a_color, ex) * DOUBLE_C(255.) + - bu_rand0to1(id, rand_halftab, randhalftabsize) + DOUBLE_C(0.5)); - } else { - t_color = a_color * DOUBLE_C(255.) + bu_rand0to1(id, rand_halftab, randhalftabsize); - } - rgb = convert_uchar3_sat(t_color); + double3 t_color; - rgb = (uchar3)all(rgb == background) ? nonbackground : rgb; - // make sure it's never perfect black - rgb = (uchar3)all(!rgb) ? (uchar3){rgb.x, rgb.y, 1} : rgb; - } else { - /* partition not evaluated, don't dither */ - rgb = background; - a_color = -1e-20; // background flag - hitp.hit_dist = INFINITY; - } + /* + * To prevent bad color aliasing, add some color dither. Be + * certain to NOT output the background color here. Random + * numbers in the range 0 to 1 are used, so that integer + * valued colors (e.g., from texture maps) retain their original + * values. + */ + if (!ZERO(gamma)) { + /* + * Perform gamma correction in floating-point space, and + * avoid nasty mach bands in dark areas from doing it in + * 0..255 space later. + */ + const double ex = 1.0/gamma; + t_color = floor(pow(a_color, ex) * DOUBLE_C(255.) + + bu_rand0to1(id, rand_halftab, randhalftabsize) + DOUBLE_C(0.5)); + } else { + t_color = a_color * DOUBLE_C(255.) + bu_rand0to1(id, rand_halftab, randhalftabsize); + } + rgb = convert_uchar3_sat(t_color); + + rgb = (uchar3)all(rgb == background) ? nonbackground : rgb; + // make sure it's never perfect black + rgb = (uchar3)all(!rgb) ? (uchar3){rgb.x, rgb.y, 1} : rgb; } else { - /* shot missed the model, don't dither */ + /* no partition evaluated, don't dither */ rgb = background; a_color = -1e-20; // background flag hitp.hit_dist = INFINITY; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits