Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/tile.cpp
| Show All 11 Lines | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "tile.h" | #include "tile.h" | ||||
| #include "util_algorithm.h" | #include "util_algorithm.h" | ||||
| #include "util_hilbert.h" | |||||
| #include "util_types.h" | #include "util_types.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| TileManager::TileManager(bool progressive_, int num_samples_, int2 tile_size_, int start_resolution_, | TileManager::TileManager(bool progressive_, int num_samples_, int2 tile_size_, int start_resolution_, | ||||
| bool preserve_tile_device_, bool background_, TileOrder tile_order_, int num_devices_) | bool preserve_tile_device_, bool background_, TileOrder tile_order_, int num_devices_) | ||||
| { | { | ||||
| progressive = progressive_; | progressive = progressive_; | ||||
| tile_size = tile_size_; | tile_size = tile_size_; | ||||
sergey: `d >> 1` | |||||
| tile_order = tile_order_; | tile_order = tile_order_; | ||||
| start_resolution = start_resolution_; | start_resolution = start_resolution_; | ||||
| num_devices = num_devices_; | num_devices = num_devices_; | ||||
| preserve_tile_device = preserve_tile_device_; | preserve_tile_device = preserve_tile_device_; | ||||
Not Done Inline ActionsBraces. sergey: Braces. | |||||
| background = background_; | background = background_; | ||||
| BufferParams buffer_params; | BufferParams buffer_params; | ||||
| reset(buffer_params, 0); | reset(buffer_params, 0); | ||||
Not Done Inline Actionsd >>= 2 sergey: `d >>= 2` | |||||
| } | } | ||||
| TileManager::~TileManager() | TileManager::~TileManager() | ||||
| { | { | ||||
| } | } | ||||
| void TileManager::reset(BufferParams& params_, int num_samples_) | void TileManager::reset(BufferParams& params_, int num_samples_) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| int resolution = state.resolution_divider; | int resolution = state.resolution_divider; | ||||
| int image_w = max(1, params.width/resolution); | int image_w = max(1, params.width/resolution); | ||||
| int image_h = max(1, params.height/resolution); | int image_h = max(1, params.height/resolution); | ||||
| state.tiles.clear(); | state.tiles.clear(); | ||||
| int num_logical_devices = preserve_tile_device? num_devices: 1; | int num_logical_devices = preserve_tile_device? num_devices: 1; | ||||
| int num = min(image_h, num_logical_devices); | int num = min(image_h, num_logical_devices); | ||||
Not Done Inline ActionsThis will fail for viewport renders, i.e. sergey: This will fail for viewport renders, i.e. | |||||
| int tile_index = 0; | int tile_index = 0; | ||||
| for(int device = 0; device < num; device++) { | for(int device = 0; device < num; device++) { | ||||
| int device_y = (image_h/num)*device; | int device_y = (image_h/num)*device; | ||||
| int device_h = (device == num-1)? image_h - device*(image_h/num): image_h/num; | int device_h = (device == num-1)? image_h - device*(image_h/num): image_h/num; | ||||
| int tile_w = (tile_size.x >= image_w)? 1: (image_w + tile_size.x - 1)/tile_size.x; | int tile_w = (tile_size.x >= image_w)? 1: (image_w + tile_size.x - 1)/tile_size.x; | ||||
| int tile_h = (tile_size.y >= device_h)? 1: (device_h + tile_size.y - 1)/tile_size.y; | int tile_h = (tile_size.y >= device_h)? 1: (device_h + tile_size.y - 1)/tile_size.y; | ||||
| for(int tile_y = 0; tile_y < tile_h; tile_y++) { | for(int tile_y = 0; tile_y < tile_h; tile_y++) { | ||||
| for(int tile_x = 0; tile_x < tile_w; tile_x++, tile_index++) { | for(int tile_x = 0; tile_x < tile_w; tile_x++, tile_index++) { | ||||
| int x = tile_x * tile_size.x; | int x = tile_x * tile_size.x; | ||||
| int y = tile_y * tile_size.y; | int y = tile_y * tile_size.y; | ||||
Not Done Inline ActionsCan it be more meaningful name than just a single letter? Same applies to the cases below. sergey: Can it be more meaningful name than just a single letter? Same applies to the cases below. | |||||
| int w = (tile_x == tile_w-1)? image_w - x: tile_size.x; | int w = (tile_x == tile_w-1)? image_w - x: tile_size.x; | ||||
| int h = (tile_y == tile_h-1)? device_h - y: tile_size.y; | int h = (tile_y == tile_h-1)? device_h - y: tile_size.y; | ||||
| state.tiles.push_back(Tile(tile_index, x, y + device_y, w, h, device)); | state.tiles.push_back(Tile(tile_index, x, y + device_y, w, h, device)); | ||||
Not Done Inline ActionsPlease apply this separately. Can go to master now, but please always use mustage (curly ;) brackets. sergey: Please apply this separately. Can go to master now, but please always use mustage (curly ;)… | |||||
| } | } | ||||
Not Done Inline ActionsCan we have more readable names for the direction? Like, enum {
DIRECTION_LEFT,
DIRECTION_TOP,
};or something similar? sergey: Can we have more readable names for the direction? Like,
enum {
DIRECTION_LEFT… | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void TileManager::set_tiles() | void TileManager::set_tiles() | ||||
| { | { | ||||
Not Done Inline ActionsBraces around the block. sergey: Braces around the block. | |||||
| int resolution = state.resolution_divider; | int resolution = state.resolution_divider; | ||||
| int image_w = max(1, params.width/resolution); | int image_w = max(1, params.width/resolution); | ||||
| int image_h = max(1, params.height/resolution); | int image_h = max(1, params.height/resolution); | ||||
| if(background) | if(background) | ||||
| gen_tiles_global(); | gen_tiles_global(); | ||||
| else | else | ||||
| gen_tiles_sliced(); | gen_tiles_sliced(); | ||||
| Show All 13 Lines | |||||
| { | { | ||||
| list<Tile>::iterator iter; | list<Tile>::iterator iter; | ||||
| int logical_device = preserve_tile_device? device: 0; | int logical_device = preserve_tile_device? device: 0; | ||||
| for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { | for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { | ||||
| if(iter->device == logical_device && iter->rendering == false) | if(iter->device == logical_device && iter->rendering == false) | ||||
| return iter; | return iter; | ||||
| } | } | ||||
Not Done Inline ActionsPicky: Prefer not to have quesitons in comments, statements are usually cleaner to follow. Like, "Check whether center of spiral was reached.". Applies to few places here. sergey: Picky: Prefer not to have quesitons in comments, statements are usually cleaner to follow. Like… | |||||
| return state.tiles.end(); | return state.tiles.end(); | ||||
| } | } | ||||
| list<Tile>::iterator TileManager::next_background_tile(int device, TileOrder tile_order) | list<Tile>::iterator TileManager::next_background_tile(int device, TileOrder tile_order) | ||||
| { | { | ||||
| list<Tile>::iterator iter, best = state.tiles.end(); | list<Tile>::iterator iter, best = state.tiles.end(); | ||||
Not Done Inline ActionsThis doesn't follow code style. sergey: This doesn't follow code style. | |||||
| int resolution = state.resolution_divider; | int resolution = state.resolution_divider; | ||||
| int logical_device = preserve_tile_device? device: 0; | int logical_device = preserve_tile_device? device: 0; | ||||
| int64_t cordx = max(1, params.width/resolution); | int64_t cordx = max(1, params.width/resolution); | ||||
| int64_t cordy = max(1, params.height/resolution); | int64_t cordy = max(1, params.height/resolution); | ||||
| int64_t mindist = INT_MAX; | int64_t mindist = INT_MAX; | ||||
| int64_t centx = cordx / 2, centy = cordy / 2; | int64_t centx = cordx / 2, centy = cordy / 2; | ||||
| int64_t hilbert_n = hilbert_roundpow2(max((params.width + tile_size.x - 1) / tile_size.x, (params.height + tile_size.y - 1) / tile_size.y)); | |||||
sergeyUnsubmitted Not Done Inline ActionsThis is to be calculated for only TILE_HILBERT it seems, no need to calculate it for all the tile orders. sergey: This is to be calculated for only `TILE_HILBERT` it seems, no need to calculate it for all the… | |||||
| for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { | for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { | ||||
| if(iter->device == logical_device && iter->rendering == false) { | if(iter->device == logical_device && iter->rendering == false) { | ||||
Not Done Inline ActionsCould also become an util_ function. sergey: Could also become an util_ function. | |||||
| Tile &cur_tile = *iter; | Tile &cur_tile = *iter; | ||||
| int64_t distx = cordx; | int64_t distx = cordx; | ||||
| int64_t disty = cordy; | int64_t disty = cordy; | ||||
| switch (tile_order) { | switch (tile_order) { | ||||
| case TILE_CENTER: | case TILE_CENTER: | ||||
| distx = centx - (cur_tile.x + (cur_tile.w / 2)); | distx = centx - (cur_tile.x + (cur_tile.w / 2)); | ||||
| disty = centy - (cur_tile.y + (cur_tile.h / 2)); | disty = centy - (cur_tile.y + (cur_tile.h / 2)); | ||||
| distx = (int64_t)sqrt((double)(distx * distx + disty * disty)); | distx = (int64_t)sqrt((double)(distx * distx + disty * disty)); | ||||
| break; | break; | ||||
| case TILE_RIGHT_TO_LEFT: | case TILE_RIGHT_TO_LEFT: | ||||
| distx = cordx - cur_tile.x; | distx = cordx - cur_tile.x; | ||||
| break; | break; | ||||
| case TILE_LEFT_TO_RIGHT: | case TILE_LEFT_TO_RIGHT: | ||||
| distx = cordx + cur_tile.x; | distx = cordx + cur_tile.x; | ||||
| break; | break; | ||||
| case TILE_TOP_TO_BOTTOM: | case TILE_TOP_TO_BOTTOM: | ||||
| distx = cordx - cur_tile.y; | distx = cordx - cur_tile.y; | ||||
| break; | break; | ||||
| case TILE_BOTTOM_TO_TOP: | case TILE_BOTTOM_TO_TOP: | ||||
| distx = cordx + cur_tile.y; | distx = cordx + cur_tile.y; | ||||
| break; | break; | ||||
| case TILE_HILBERT: | |||||
| distx = hilbert_xy2d(hilbert_n, cur_tile.x / tile_size.x, cur_tile.y / tile_size.y); | |||||
| break; | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| if(distx < mindist) { | if(distx < mindist) { | ||||
| best = iter; | best = iter; | ||||
| mindist = distx; | mindist = distx; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines | |||||
d >> 1