| 8 | namespace isa |
| 9 | { |
| 10 | GridSOA::GridSOA(const SubdivPatch1Base* patches, unsigned time_steps, |
| 11 | const unsigned x0, const unsigned x1, const unsigned y0, const unsigned y1, const unsigned swidth, const unsigned sheight, |
| 12 | const SubdivMesh* const geom, const size_t gridOffset, const size_t gridBytes, BBox3fa* bounds_o) |
| 13 | : troot(BVH4::emptyNode), |
| 14 | time_steps(time_steps), width(x1-x0+1), height(y1-y0+1), dim_offset(width*height), |
| 15 | _geomID(patches->geomID()), _primID(patches->primID()), |
| 16 | gridOffset(unsigned(gridOffset)), gridBytes(unsigned(gridBytes)), rootOffset(unsigned(gridOffset+time_steps*gridBytes)) |
| 17 | { |
| 18 | /* the generate loops need padded arrays, thus first store into these temporary arrays */ |
| 19 | unsigned temp_size = width*height+VSIZEX; |
| 20 | dynamic_large_stack_array(float,local_grid_u,temp_size,32*32*sizeof(float)); |
| 21 | dynamic_large_stack_array(float,local_grid_v,temp_size,32*32*sizeof(float)); |
| 22 | dynamic_large_stack_array(float,local_grid_x,temp_size,32*32*sizeof(float)); |
| 23 | dynamic_large_stack_array(float,local_grid_y,temp_size,32*32*sizeof(float)); |
| 24 | dynamic_large_stack_array(float,local_grid_z,temp_size,32*32*sizeof(float)); |
| 25 | dynamic_large_stack_array(int,local_grid_uv,temp_size,32*32*sizeof(int)); |
| 26 | |
| 27 | /* first create the grids for each time step */ |
| 28 | for (size_t t=0; t<time_steps; t++) |
| 29 | { |
| 30 | /* compute vertex grid (+displacement) */ |
| 31 | evalGrid(patches[t],x0,x1,y0,y1,swidth,sheight, |
| 32 | local_grid_x,local_grid_y,local_grid_z,local_grid_u,local_grid_v,geom); |
| 33 | |
| 34 | /* encode UVs */ |
| 35 | for (unsigned i=0; i<dim_offset; i+=VSIZEX) { |
| 36 | const vintx iu = (vintx) clamp(vfloatx::load(&local_grid_u[i])*(0x10000/8.0f), vfloatx(0.0f), vfloatx(0xFFFF)); |
| 37 | const vintx iv = (vintx) clamp(vfloatx::load(&local_grid_v[i])*(0x10000/8.0f), vfloatx(0.0f), vfloatx(0xFFFF)); |
| 38 | vintx::storeu(&local_grid_uv[i], (iv << 16) | iu); |
| 39 | } |
| 40 | |
| 41 | /* copy temporary data to compact grid */ |
| 42 | float* const grid_x = (float*)(gridData(t) + 0*dim_offset); |
| 43 | float* const grid_y = (float*)(gridData(t) + 1*dim_offset); |
| 44 | float* const grid_z = (float*)(gridData(t) + 2*dim_offset); |
| 45 | int * const grid_uv = (int* )(gridData(t) + 3*dim_offset); |
| 46 | |
| 47 | for (size_t i=0; i<width*height; i++) |
| 48 | { |
| 49 | grid_x[i] = local_grid_x[i]; |
| 50 | grid_y[i] = local_grid_y[i]; |
| 51 | grid_z[i] = local_grid_z[i]; |
| 52 | grid_uv[i] = local_grid_uv[i]; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /* create normal BVH when no motion blur is active */ |
| 57 | if (time_steps == 1) |
| 58 | root(0) = buildBVH(bounds_o).first; |
| 59 | |
| 60 | /* otherwise build MBlur BVH */ |
| 61 | else { |
| 62 | BBox3fa gbounds[RTC_MAX_TIME_STEP_COUNT]; |
| 63 | troot = buildMSMBlurBVH(make_range(0,int(time_steps-1)),gbounds).first; |
| 64 | |
| 65 | if (bounds_o) |
| 66 | for (size_t i=0; i<time_steps; i++) |
| 67 | bounds_o[i] = gbounds[i]; |