Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/tile.h
| 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. | ||||
| */ | */ | ||||
| #pragma once | #pragma once | ||||
| #include "render/buffers.h" | #include "render/buffers.h" | ||||
| #include "util/util_image.h" | |||||
| #include "util/util_string.h" | |||||
| #include "util/util_unique_ptr.h" | |||||
| #include "util/util_vector.h" | |||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* Tile */ | class Pass; | ||||
| /* -------------------------------------------------------------------- | |||||
| * Tile. | |||||
| */ | |||||
| class Tile { | class Tile { | ||||
| public: | public: | ||||
| int x = 0, y = 0; | int x = 0, y = 0; | ||||
| int width = 0, height = 0; | int width = 0, height = 0; | ||||
| Tile() | Tile() | ||||
| { | { | ||||
| } | } | ||||
| }; | }; | ||||
| /* Tile Manager */ | /* -------------------------------------------------------------------- | ||||
| * Tile Manager. | |||||
| */ | |||||
| /* XXX: Disambiguate "partial" here somehow. */ | |||||
brecht: In general I think it would be more clear to use "to disk", "from disk", and "on disk" instead… | |||||
| class TileManager { | class TileManager { | ||||
| public: | public: | ||||
| TileManager() = default; | TileManager(); | ||||
| ~TileManager(); | |||||
| TileManager(const TileManager &other) = delete; | |||||
| TileManager(TileManager &&other) noexcept = delete; | |||||
| TileManager &operator=(const TileManager &other) = delete; | |||||
| TileManager &operator=(TileManager &&other) = delete; | |||||
| /* Reset current progress and start new rendering of the full-frame parameters in tiles of the | /* Reset current progress and start new rendering of the full-frame parameters in tiles of the | ||||
| * given size. */ | * given size. */ | ||||
| /* TODO(sergey): Consider using tile area instead of exact size to help dealing with extreme | /* TODO(sergey): Consider using tile area instead of exact size to help dealing with extreme | ||||
| * cases of stretched renders. */ | * cases of stretched renders. */ | ||||
| void reset(const BufferParams ¶ms, int2 tile_size); | void reset(const BufferParams ¶ms, const vector<Pass *> &passes, int2 tile_size); | ||||
| inline int get_num_tiles() const | |||||
| { | |||||
| return tile_state_.num_tiles; | |||||
| } | |||||
| inline bool has_multiple_tiles() const | |||||
| { | |||||
| return tile_state_.num_tiles > 1; | |||||
| } | |||||
| bool next(); | bool next(); | ||||
| bool done(); | bool done(); | ||||
| const Tile &get_current_tile() const; | const Tile &get_current_tile() const; | ||||
| /* Write render buffer of a tile to the partial file. | |||||
| * | |||||
| * Opens partial file for write when first tile is written, and closes the file when the last | |||||
| * tile has been written. | |||||
| * | |||||
| * Returns true on success. */ | |||||
| bool write_tile(const RenderBuffers &tile_buffers); | |||||
| /* Inform the tile manager that no more tiles will be written to the partial file. | |||||
| * The partial file will be considered final, all handles to it will be closed. */ | |||||
| void finish_write_tiles(); | |||||
| bool has_partial_tiles() const; | |||||
| /* Read full frame render buffer from the partial file. | |||||
| * | |||||
| * The render buffer is reset to the full frame parameters. This means that the caller does not | |||||
| * need to worry about keeping track of the full frame parameters. | |||||
| * | |||||
| * Returns true on success. */ | |||||
| bool read_full_buffer(RenderBuffers *buffers); | |||||
| void remove_partial_file() const; | |||||
| protected: | protected: | ||||
| /* Get tile configuration for its index. | |||||
| * The tile index must be within [0, state_.tile_state_). */ | |||||
| Tile get_tile_for_index(int index) const; | |||||
| /* Configure image specification for partial tile file storage. | |||||
| * Note that this only configures meta information about the output without actually opening the | |||||
| * file for write. */ | |||||
| void configure_image_spec(const vector<Pass *> &passes); | |||||
| /* Get full filepath to the file which contains partial render tiles. */ | |||||
| string get_partial_filepath() const; | |||||
| bool open_tile_output(); | |||||
| bool close_tile_output(); | |||||
| /* Directory and file name used to store partial files. */ | |||||
| string storage_dir_; | |||||
| string partial_filename_; | |||||
| int2 tile_size_ = make_int2(0, 0); | int2 tile_size_ = make_int2(0, 0); | ||||
| int num_tiles_x_ = 0; | |||||
| int num_tiles_y_ = 0; | |||||
| BufferParams buffer_params_; | BufferParams buffer_params_; | ||||
| /* Tile scheduling state. */ | |||||
| struct { | struct { | ||||
| int num_tiles_x = 0; | |||||
| int num_tiles_y = 0; | |||||
| int num_tiles = 0; | |||||
| int next_tile_index; | int next_tile_index; | ||||
| int num_tiles; | |||||
| Tile current_tile; | Tile current_tile; | ||||
| } state_; | } tile_state_; | ||||
| /* Partial tile file state. */ | |||||
| struct { | |||||
| /* Specification of the partial tile image which corresponds to the buffer parameters. | |||||
| * Contains channels configured according to the passes configuration in the path traces. | |||||
| * | |||||
| * Output images are saved using this specification, input images are expected to have matched | |||||
| * specification. */ | |||||
| ImageSpec image_spec; | |||||
| /* Output handle for the partial tile file. | |||||
| * | |||||
| * This file can not be closed until all tiles has been provided, so the handle is stored in | |||||
| * the state and is created whenever writing is requested. */ | |||||
| unique_ptr<ImageOutput> tile_out; | |||||
| int num_tiles_written = 0; | |||||
| } partial_state_; | |||||
| }; | }; | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
In general I think it would be more clear to use "to disk", "from disk", and "on disk" instead of "partial".