diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2015-04-17 18:25:37 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2015-04-17 18:25:37 +0300 |
commit | 394c5318c6fe981f94fc78f312fc0295209288dc (patch) | |
tree | d58e99fa5e27fe283c3f44621a093e4889148b3f /intern | |
parent | 45e929dc127e5b037c9e073ad84c3d76ca11ac50 (diff) |
Bake-API: reduce memory footprint when baking more than one object (Fix T41092)
Combine all the highpoly pixel arrays into a single array with a lookup
object_id for each of the highpoly objects.
Note: This changes the Bake API, external engines should refer to the
bake_api.c for the latest API.
Many thanks for Sergey Sharybin for the complete review, changes
suggestion and feedback. (you rock!)
Reviewers: sergey
Subscribers: pildanovak, marcclintdion, monio, metalliandy, brecht
Maniphest Tasks: T41092
Differential Revision: https://developer.blender.org/D772
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/blender/addon/__init__.py | 4 | ||||
-rw-r--r-- | intern/cycles/blender/addon/engine.py | 4 | ||||
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 6 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 12 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/bake.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/render/bake.h | 1 |
7 files changed, 22 insertions, 12 deletions
diff --git a/intern/cycles/blender/addon/__init__.py b/intern/cycles/blender/addon/__init__.py index 5b0c6a84bb5..9c78e0c9a62 100644 --- a/intern/cycles/blender/addon/__init__.py +++ b/intern/cycles/blender/addon/__init__.py @@ -65,8 +65,8 @@ class CyclesRender(bpy.types.RenderEngine): def render(self, scene): engine.render(self) - def bake(self, scene, obj, pass_type, pixel_array, num_pixels, depth, result): - engine.bake(self, obj, pass_type, pixel_array, num_pixels, depth, result) + def bake(self, scene, obj, pass_type, object_id, pixel_array, num_pixels, depth, result): + engine.bake(self, obj, pass_type, object_id, pixel_array, num_pixels, depth, result) # viewport render def view_update(self, context): diff --git a/intern/cycles/blender/addon/engine.py b/intern/cycles/blender/addon/engine.py index e50a8e45b52..4187e2381ac 100644 --- a/intern/cycles/blender/addon/engine.py +++ b/intern/cycles/blender/addon/engine.py @@ -59,11 +59,11 @@ def render(engine): _cycles.render(engine.session) -def bake(engine, obj, pass_type, pixel_array, num_pixels, depth, result): +def bake(engine, obj, pass_type, object_id, pixel_array, num_pixels, depth, result): import _cycles session = getattr(engine, "session", None) if session is not None: - _cycles.bake(engine.session, obj.as_pointer(), pass_type, pixel_array.as_pointer(), num_pixels, depth, result.as_pointer()) + _cycles.bake(engine.session, obj.as_pointer(), pass_type, object_id, pixel_array.as_pointer(), num_pixels, depth, result.as_pointer()) def reset(engine, data, scene): diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index b9521090c93..200003fbf70 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -189,9 +189,9 @@ static PyObject *bake_func(PyObject * /*self*/, PyObject *args) PyObject *pysession, *pyobject; PyObject *pypixel_array, *pyresult; const char *pass_type; - int num_pixels, depth; + int num_pixels, depth, object_id; - if(!PyArg_ParseTuple(args, "OOsOiiO", &pysession, &pyobject, &pass_type, &pypixel_array, &num_pixels, &depth, &pyresult)) + if(!PyArg_ParseTuple(args, "OOsiOiiO", &pysession, &pyobject, &pass_type, &object_id, &pypixel_array, &num_pixels, &depth, &pyresult)) return NULL; BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession); @@ -208,7 +208,7 @@ static PyObject *bake_func(PyObject * /*self*/, PyObject *args) python_thread_state_save(&session->python_thread_state); - session->bake(b_object, pass_type, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result); + session->bake(b_object, pass_type, object_id, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result); python_thread_state_restore(&session->python_thread_state); diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index bdacea0cd7e..897514668f6 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -511,18 +511,22 @@ void BlenderSession::render() sync = NULL; } -static void populate_bake_data(BakeData *data, BL::BakePixel pixel_array, const int num_pixels) +static void populate_bake_data(BakeData *data, const int object_id, BL::BakePixel pixel_array, const int num_pixels) { BL::BakePixel bp = pixel_array; int i; for(i=0; i < num_pixels; i++) { - data->set(i, bp.primitive_id(), bp.uv(), bp.du_dx(), bp.du_dy(), bp.dv_dx(), bp.dv_dy()); + if(bp.object_id() == object_id) { + data->set(i, bp.primitive_id(), bp.uv(), bp.du_dx(), bp.du_dy(), bp.dv_dx(), bp.dv_dy()); + } else { + data->set_null(i); + } bp = bp.next(); } } -void BlenderSession::bake(BL::Object b_object, const string& pass_type, BL::BakePixel pixel_array, const size_t num_pixels, const int /*depth*/, float result[]) +void BlenderSession::bake(BL::Object b_object, const string& pass_type, const int object_id, BL::BakePixel pixel_array, const size_t num_pixels, const int /*depth*/, float result[]) { ShaderEvalType shader_type = get_shader_type(pass_type); size_t object_index = OBJECT_NONE; @@ -578,7 +582,7 @@ void BlenderSession::bake(BL::Object b_object, const string& pass_type, BL::Bake BakeData *bake_data = scene->bake_manager->init(object, tri_offset, num_pixels); - populate_bake_data(bake_data, pixel_array, num_pixels); + populate_bake_data(bake_data, object_id, pixel_array, num_pixels); /* set number of samples */ session->tile_manager.set_samples(session_params.samples); diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index b6fc709b92e..708776dc8ca 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -52,7 +52,7 @@ public: /* offline render */ void render(); - void bake(BL::Object b_object, const string& pass_type, BL::BakePixel pixel_array, const size_t num_pixels, const int depth, float pixels[]); + void bake(BL::Object b_object, const string& pass_type, const int object_id, BL::BakePixel pixel_array, const size_t num_pixels, const int depth, float pixels[]); void write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile); void write_render_tile(RenderTile& rtile); diff --git a/intern/cycles/render/bake.cpp b/intern/cycles/render/bake.cpp index c5201366bb2..4bbac0f91d1 100644 --- a/intern/cycles/render/bake.cpp +++ b/intern/cycles/render/bake.cpp @@ -55,6 +55,11 @@ void BakeData::set(int i, int prim, float uv[2], float dudx, float dudy, float d m_dvdy[i] = dvdy; } +void BakeData::set_null(int i) +{ + m_primitive[i] = -1; +} + int BakeData::object() { return m_object; diff --git a/intern/cycles/render/bake.h b/intern/cycles/render/bake.h index 9ff10dafa0e..14d975a4b4e 100644 --- a/intern/cycles/render/bake.h +++ b/intern/cycles/render/bake.h @@ -31,6 +31,7 @@ public: ~BakeData(); void set(int i, int prim, float uv[2], float dudx, float dudy, float dvdx, float dvdy); + void set_null(int i); int object(); size_t size(); uint4 data(int i); |