diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-03-15 17:52:27 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-03-15 18:00:01 +0300 |
commit | c44cdd5905d3112a46a984b8d49710fb1c1546a0 (patch) | |
tree | 14ca93c9d06f76c7042be2583833a07064abf24b /intern/cycles/blender | |
parent | c5dba540d73ec664ac3bfff02f73413906d66273 (diff) |
Cycles: Allow rendering a range of resumable chunks
The range is controlled using the following command line arguments:
--cycles-resumable-start-chunk
--cycles-resumable-end-chunk
Those are 1-based index of range for rendering.
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/addon/engine.py | 25 | ||||
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 52 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 20 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 4 |
4 files changed, 90 insertions, 11 deletions
diff --git a/intern/cycles/blender/addon/engine.py b/intern/cycles/blender/addon/engine.py index c9ee827aeeb..ab57dd44bdb 100644 --- a/intern/cycles/blender/addon/engine.py +++ b/intern/cycles/blender/addon/engine.py @@ -59,6 +59,12 @@ def _configure_argument_parser(): parser.add_argument("--cycles-resumable-current-chunk", help="Current chunk of samples range to render", default=None) + parser.add_argument("--cycles-resumable-start-chunk", + help="Start chunk to render", + default=None) + parser.add_argument("--cycles-resumable-end-chunk", + help="End chunk to render", + default=None) return parser @@ -72,12 +78,19 @@ def _parse_command_line(): parser = _configure_argument_parser() args, unknown = parser.parse_known_args(argv[argv.index("--") + 1:]) - if args.cycles_resumable_num_chunks is not None and \ - args.cycles_resumable_current_chunk is not None: - import _cycles - _cycles.set_resumable_chunks( - int(args.cycles_resumable_num_chunks), - int(args.cycles_resumable_current_chunk)) + if args.cycles_resumable_num_chunks is not None: + if args.cycles_resumable_current_chunk is not None: + import _cycles + _cycles.set_resumable_chunk( + int(args.cycles_resumable_num_chunks), + int(args.cycles_resumable_current_chunk)) + elif args.cycles_resumable_start_chunk is not None and \ + args.cycles_resumable_end_chunk: + import _cycles + _cycles.set_resumable_chunk_range( + int(args.cycles_resumable_num_chunks), + int(args.cycles_resumable_start_chunk), + int(args.cycles_resumable_end_chunk)) def init(): diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index fc0df3410c6..557c4e8c5f0 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -644,7 +644,7 @@ static PyObject *debug_flags_reset_func(PyObject * /*self*/, PyObject * /*args*/ Py_RETURN_NONE; } -static PyObject *set_resumable_chunks_func(PyObject * /*self*/, PyObject *args) +static PyObject *set_resumable_chunk_func(PyObject * /*self*/, PyObject *args) { int num_resumable_chunks, current_resumable_chunk; if(!PyArg_ParseTuple(args, "ii", @@ -679,6 +679,53 @@ static PyObject *set_resumable_chunks_func(PyObject * /*self*/, PyObject *args) Py_RETURN_NONE; } +static PyObject *set_resumable_chunk_range_func(PyObject * /*self*/, PyObject *args) +{ + int num_chunks, start_chunk, end_chunk; + if(!PyArg_ParseTuple(args, "iii", + &num_chunks, + &start_chunk, + &end_chunk)) { + Py_RETURN_NONE; + } + + if(num_chunks <= 0) { + fprintf(stderr, "Cycles: Bad value for number of resumable chunks.\n"); + abort(); + Py_RETURN_NONE; + } + if(start_chunk < 1 || start_chunk > num_chunks) { + fprintf(stderr, "Cycles: Bad value for start chunk number.\n"); + abort(); + Py_RETURN_NONE; + } + if(end_chunk < 1 || end_chunk > num_chunks) { + fprintf(stderr, "Cycles: Bad value for start chunk number.\n"); + abort(); + Py_RETURN_NONE; + } + if(start_chunk > end_chunk) { + fprintf(stderr, "Cycles: End chunk should be higher than start one.\n"); + abort(); + Py_RETURN_NONE; + } + + VLOG(1) << "Initialized resumable render: " + << "num_resumable_chunks=" << num_chunks << ", " + << "start_resumable_chunk=" << start_chunk + << "end_resumable_chunk=" << end_chunk; + BlenderSession::num_resumable_chunks = num_chunks; + BlenderSession::start_resumable_chunk = start_chunk; + BlenderSession::end_resumable_chunk = end_chunk; + + printf("Cycles: Will render chunks %d to %d of %d\n", + start_chunk, + end_chunk, + num_chunks); + + Py_RETURN_NONE; +} + static PyObject *get_device_types_func(PyObject * /*self*/, PyObject * /*args*/) { vector<DeviceInfo>& devices = Device::available_devices(); @@ -718,7 +765,8 @@ static PyMethodDef methods[] = { {"debug_flags_reset", debug_flags_reset_func, METH_NOARGS, ""}, /* Resumable render */ - {"set_resumable_chunks", set_resumable_chunks_func, METH_VARARGS, ""}, + {"set_resumable_chunk", set_resumable_chunk_func, METH_VARARGS, ""}, + {"set_resumable_chunk_range", set_resumable_chunk_range_func, METH_VARARGS, ""}, /* Compute Device selection */ {"get_device_types", get_device_types_func, METH_VARARGS, ""}, diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 2f30cbd961f..c5f5ffe9928 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -46,6 +46,8 @@ CCL_NAMESPACE_BEGIN bool BlenderSession::headless = false; int BlenderSession::num_resumable_chunks = 0; int BlenderSession::current_resumable_chunk = 0; +int BlenderSession::start_resumable_chunk = 0; +int BlenderSession::end_resumable_chunk = 0; BlenderSession::BlenderSession(BL::RenderEngine& b_engine, BL::UserPreferences& b_userpref, @@ -1342,9 +1344,21 @@ void BlenderSession::update_resumable_tile_manager(int num_samples) return; } - int num_samples_per_chunk = (int)ceilf((float)num_samples / num_resumable_chunks); - int range_start_sample = num_samples_per_chunk * (current_resumable_chunk - 1); - int range_num_samples = num_samples_per_chunk; + const int num_samples_per_chunk = (int)ceilf((float)num_samples / num_resumable_chunks); + + int range_start_sample, range_num_samples; + if(current_resumable_chunk != 0) { + /* Single chunk rendering. */ + range_start_sample = num_samples_per_chunk * (current_resumable_chunk - 1); + range_num_samples = num_samples_per_chunk; + } + else { + /* Ranged-chunks. */ + const int num_chunks = end_resumable_chunk - start_resumable_chunk + 1; + range_start_sample = num_samples_per_chunk * (start_resumable_chunk - 1); + range_num_samples = num_chunks * num_samples_per_chunk; + } + /* Make sure we don't overshoot. */ if(range_start_sample + range_num_samples > num_samples) { range_num_samples = num_samples - range_num_samples; } diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index 82fe218b4ce..700b8acec1b 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -137,6 +137,10 @@ public: /* Current resumable chunk index to render. */ static int current_resumable_chunk; + /* Alternative to single-chunk rendering to render a range of chunks. */ + static int start_resumable_chunk; + static int end_resumable_chunk; + protected: void do_write_update_render_result(BL::RenderResult& b_rr, BL::RenderLayer& b_rlay, |