Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/tile.cpp
| Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | bool operator()(Tile &a, Tile &b) | ||||
| } | } | ||||
| } | } | ||||
| protected: | protected: | ||||
| TileOrder order_; | TileOrder order_; | ||||
| int2 center_; | int2 center_; | ||||
| }; | }; | ||||
| inline int2 hilbert_index_to_pos(int n, int d) | |||||
| { | |||||
| int2 r, xy = make_int2(0, 0); | |||||
| for(int s = 1; s < n; s *= 2) { | |||||
| r.x = (d / 2) & 1; | |||||
sergey: `d >> 1` | |||||
| r.y = (d ^ r.x) & 1; | |||||
| if(!r.y) { | |||||
| if(r.x) | |||||
| xy = make_int2(s-1, s-1) - xy; | |||||
sergeyUnsubmitted Not Done Inline ActionsBraces. sergey: Braces. | |||||
| swap(xy.x, xy.y); | |||||
| } | |||||
| xy += r*make_int2(s, s); | |||||
| d /= 4; | |||||
sergeyUnsubmitted Not Done Inline Actionsd >>= 2 sergey: `d >>= 2` | |||||
| } | |||||
| return xy; | |||||
| } | |||||
| } /* namespace */ | } /* namespace */ | ||||
| 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_; | ||||
| tile_order = tile_order_; | tile_order = tile_order_; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | int TileManager::gen_tiles(bool sliced) | ||||
| int num = min(image_h, num_logical_devices); | int num = min(image_h, num_logical_devices); | ||||
| int slice_num = sliced? num: 1; | int slice_num = sliced? num: 1; | ||||
| int tile_index = 0; | int tile_index = 0; | ||||
| state.tiles.clear(); | state.tiles.clear(); | ||||
| state.tiles.resize(num); | state.tiles.resize(num); | ||||
| vector<list<Tile> >::iterator tile_list = state.tiles.begin(); | vector<list<Tile> >::iterator tile_list = state.tiles.begin(); | ||||
| if(tile_order == TILE_HILBERT_SPIRAL) { | |||||
| assert(!sliced); | |||||
Not Done Inline ActionsThis will fail for viewport renders, i.e. sergey: This will fail for viewport renders, i.e. | |||||
| const int hilbert_size = 4; /* Size of blocks in tiles, must be a power of 2 */ | |||||
| int tile_w = (tile_size.x >= image_w)? 1: (image_w + tile_size.x - 1)/tile_size.x; | |||||
| int tile_h = (tile_size.y >= image_h)? 1: (image_h + tile_size.y - 1)/tile_size.y; | |||||
| int tiles_per_device = (tile_w * tile_h + num - 1) / num; | |||||
| int cur_device = 0, cur_tiles = 0; | |||||
| int2 block_size = tile_size * make_int2(hilbert_size, hilbert_size); | |||||
| /* Number of blocks to fill the image */ | |||||
| int blocks_x = (block_size.x >= image_w)? 1: (image_w + block_size.x - 1)/block_size.x; | |||||
| int blocks_y = (block_size.y >= image_h)? 1: (image_h + block_size.y - 1)/block_size.y; | |||||
| int n = max(blocks_x, blocks_y) | 0x1; /* Side length of the spiral (must be odd) */ | |||||
| /* Offset of spiral (to keep it centered) */ | |||||
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. | |||||
| int2 offset = make_int2((image_w - n*block_size.x)/2, (image_h - n*block_size.y)/2); | |||||
| offset = (offset / tile_size) * tile_size; /* Round to tile border. */ | |||||
| int2 block = make_int2(0, 0); /* Current block */ | |||||
| int prev_dir = 0, dir = 0; | |||||
sergeyUnsubmitted 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… | |||||
| for(int i = 0;;) { | |||||
| /* Generate the tiles in the current block. */ | |||||
| for(int hilbert_index = 0; hilbert_index < hilbert_size*hilbert_size; hilbert_index++) { | |||||
| int2 tile, hilbert_pos = hilbert_index_to_pos(hilbert_size, hilbert_index); | |||||
| /* Rotate block according to spiral direction. */ | |||||
| if(prev_dir == 0 && dir == 0) { | |||||
Not Done Inline ActionsBraces around the block. sergey: Braces around the block. | |||||
| tile = make_int2(hilbert_pos.y, hilbert_pos.x); | |||||
| } | |||||
| else if(dir == 1 || prev_dir == 1) { | |||||
| tile = hilbert_pos; | |||||
| } | |||||
| else if(dir == 2) { | |||||
| tile = make_int2(hilbert_size-1-hilbert_pos.y, hilbert_size-1-hilbert_pos.x); | |||||
| } | |||||
| else { | |||||
| tile = make_int2(hilbert_size-1-hilbert_pos.x, hilbert_size-1-hilbert_pos.y); | |||||
| } | |||||
| int2 pos = block*block_size + tile*tile_size + offset; | |||||
| /* Is the tile inside the image? */ | |||||
| if(pos.x >= 0 && pos.y >= 0 && pos.x < image_w && pos.y < image_h) { | |||||
| int w = min(tile_size.x, image_w - pos.x); | |||||
| int h = min(tile_size.y, image_h - pos.y); | |||||
| tile_list->push_front(Tile(tile_index, pos.x, pos.y, w, h, cur_device)); | |||||
| cur_tiles++; | |||||
| tile_index++; | |||||
Not Done Inline ActionsCould also become an util_ function. sergey: Could also become an util_ function. | |||||
| if(cur_tiles == tiles_per_device) { | |||||
| tile_list++; | |||||
| cur_tiles = 0; | |||||
| cur_device++; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Have we reached the center of the spiral? */ | |||||
sergeyUnsubmitted 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… | |||||
| if(block.x == (n-1)/2 && block.y == (n-1)/2) | |||||
| break; | |||||
| /* Advance to next block. */ | |||||
| prev_dir = dir; | |||||
| switch(dir) { | |||||
| case 0: | |||||
sergeyUnsubmitted Not Done Inline ActionsThis doesn't follow code style. sergey: This doesn't follow code style. | |||||
| block.y++; | |||||
| if(block.y == (n-i-1)) dir = 1; | |||||
| break; | |||||
| case 1: | |||||
| block.x++; | |||||
| if(block.x == (n-i-1)) dir = 2; | |||||
| break; | |||||
| case 2: | |||||
| block.y--; | |||||
| if(block.y == i) dir = 3; | |||||
| break; | |||||
| case 3: | |||||
| block.x--; | |||||
| if(block.x == i+1) { | |||||
| dir = 0; | |||||
| i++; | |||||
| } | |||||
| break; | |||||
| } | |||||
| } | |||||
| return tile_index; | |||||
| } | |||||
| for(int slice = 0; slice < slice_num; slice++) { | for(int slice = 0; slice < slice_num; slice++) { | ||||
| int slice_y = (image_h/slice_num)*slice; | int slice_y = (image_h/slice_num)*slice; | ||||
| int slice_h = (slice == slice_num-1)? image_h - slice*(image_h/slice_num): image_h/slice_num; | int slice_h = (slice == slice_num-1)? image_h - slice*(image_h/slice_num): image_h/slice_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 >= slice_h)? 1: (slice_h + tile_size.y - 1)/tile_size.y; | int tile_h = (tile_size.y >= slice_h)? 1: (slice_h + tile_size.y - 1)/tile_size.y; | ||||
| int tiles_per_device = (tile_w * tile_h + num - 1) / num; | int tiles_per_device = (tile_w * tile_h + num - 1) / num; | ||||
| int cur_device = 0, cur_tiles = 0; | int cur_device = 0, cur_tiles = 0; | ||||
| 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; | ||||
| 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)? slice_h - y: tile_size.y; | int h = (tile_y == tile_h-1)? slice_h - y: tile_size.y; | ||||
| tile_list->push_back(Tile(tile_index, x, y + slice_y, w, h, sliced? slice: cur_device)); | tile_list->push_back(Tile(tile_index, x, y + slice_y, w, h, sliced? slice: cur_device)); | ||||
| if(!sliced) { | if(!sliced) { | ||||
| cur_tiles++; | cur_tiles++; | ||||
| if(cur_tiles == tiles_per_device) { | if(cur_tiles == tiles_per_device) { | ||||
| /* Tiles are generated in Bottom-to-Top order, so no sort is necessary. */ | |||||
| if(tile_order != TILE_BOTTOM_TO_TOP) | |||||
sergeyUnsubmitted 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 ;)… | |||||
| tile_list->sort(TileComparator(tile_order, center)); | tile_list->sort(TileComparator(tile_order, center)); | ||||
| tile_list++; | tile_list++; | ||||
| cur_tiles = 0; | cur_tiles = 0; | ||||
| cur_device++; | cur_device++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 13 Lines | void TileManager::set_tiles() | ||||
| state.buffer.height = image_h; | state.buffer.height = image_h; | ||||
| state.buffer.full_x = params.full_x/resolution; | state.buffer.full_x = params.full_x/resolution; | ||||
| state.buffer.full_y = params.full_y/resolution; | state.buffer.full_y = params.full_y/resolution; | ||||
| state.buffer.full_width = max(1, params.full_width/resolution); | state.buffer.full_width = max(1, params.full_width/resolution); | ||||
| state.buffer.full_height = max(1, params.full_height/resolution); | state.buffer.full_height = max(1, params.full_height/resolution); | ||||
| } | } | ||||
| bool TileManager::next_tile(Tile& tile, int device) | bool TileManager::next_tile(Tile& tile, int device) | ||||
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… | |||||
| { | { | ||||
| int logical_device = preserve_tile_device? device: 0; | int logical_device = preserve_tile_device? device: 0; | ||||
| if((logical_device >= state.tiles.size()) || state.tiles[logical_device].empty()) | if((logical_device >= state.tiles.size()) || state.tiles[logical_device].empty()) | ||||
| return false; | return false; | ||||
| tile = Tile(state.tiles[logical_device].front()); | tile = Tile(state.tiles[logical_device].front()); | ||||
| state.tiles[logical_device].pop_front(); | state.tiles[logical_device].pop_front(); | ||||
| Show All 37 Lines | |||||
d >> 1