diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-17 21:42:38 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-17 21:42:38 +0400 |
commit | c5d7ea091fa5a291b270565e456612df1e37b50c (patch) | |
tree | 4322fffdf299ec35afe86030b49fdda9d0f38c8a /source/blender/editors | |
parent | 04eb24a33737b9d9e29ec758c3db8fb81d140fc1 (diff) |
Changes to partial update during rendering
Summary:
Mainly addressed to solve old TODO with color managed fallback
to CPU mode when displaying render result during rendering.
That fallback was caused by the fact that partial image update
was always acquiring image buffer for composite output and was
only modifying display buffer directly.
This was a big issue for Cycles rendering which renders layers
one by one and wanted to display progress of each individual
layer. This lead to situations when display buffer was based on
what Cycles passes via RenderResult and didn't take layer/pass
from image editor header into account.
Now made it so image buffer which partial update is operating
with always corresponds to what is set in image editor header.
To make Cycles displaying progress of all the layers one by one
made it so image_rect_update switches image editor user to
newly rendering render layer. It happens only once when render
engine starts rendering next render layer, so should not be
annoying for navigation during rendering.
Additional change to render engines was done to make it so
they're able to merge composite output to final result
without marking tile as done. This is done via do_merge_result
argument to end_result() callback. This argument is optional
so should not break script compatibility.
Additional changes:
- Partial display update for Blender Internal now happens from
the same thread as tile rendering. This makes it so display
conversion (which could be pretty heavy actually) is done in
separate threads. Also gives better UI feedback when rendering
easy scene with small tiles.
- Avoid freeing/allocating byte buffer for render result
if it's owned by the image buffer. Only mark it as invalid
for color management.
Saves loads of buffer re-allocations in cases when having
several image editors opened with render result. This change
in conjunction with the rest of the patch gave around
50%-100% speedup of render time when displaying non-combined
pass during rendering on my laptop.
- Partial display buffer update was wrong for buffers with number
of channels different from 4.
- Remove unused window from RenderJob.
- Made image_buffer_rect_update static since it's only used
in single file.
Reviewers: brecht
Reviewed By: brecht
CC: dingto
Differential Revision: http://developer.blender.org/D98
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/render/render_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/render/render_internal.c | 190 | ||||
-rw-r--r-- | source/blender/editors/render/render_preview.c | 4 | ||||
-rw-r--r-- | source/blender/editors/render/render_view.c | 6 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 33 |
5 files changed, 168 insertions, 71 deletions
diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index eb09606e57e..8f8cc542821 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -35,6 +35,7 @@ struct wmOperatorType; struct RenderResult; struct Scene; +struct ScrArea; /* render_shading.c */ void OBJECT_OT_material_slot_add(struct wmOperatorType *ot); @@ -86,11 +87,8 @@ void RENDER_OT_render(struct wmOperatorType *ot); void render_view3d_update(struct RenderEngine *engine, const struct bContext *C); void render_view3d_draw(struct RenderEngine *engine, const struct bContext *C); -/* render_opengl.c uses this */ -void image_buffer_rect_update(struct Scene *scene, struct RenderResult *rr, struct ImBuf *ibuf, volatile struct rcti *renrect); - /* render_view.c */ -void render_view_open(struct bContext *C, int mx, int my); +struct ScrArea *render_view_open(struct bContext *C, int mx, int my); void RENDER_OT_view_show(struct wmOperatorType *ot); void RENDER_OT_view_cancel(struct wmOperatorType *ot); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 1b090cb16ec..7ecada993e2 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -94,11 +94,17 @@ static int render_break(void *rjv); /* called inside thread! */ -void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect) +static void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, ImageUser *iuser, volatile rcti *renrect) { float *rectf = NULL; int ymin, ymax, xmin, xmax; int rymin, rxmin; + int linear_stride, linear_offset_x, linear_offset_y; + + if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) { + /* The whole image buffer it so be color managed again anyway. */ + return; + } /* if renrect argument, we only refresh scanlines */ if (renrect) { @@ -138,33 +144,55 @@ void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volat if (xmax < 1 || ymax < 1) return; - /* find current float rect for display, first case is after composite... still weak */ - if (rr->rectf) - rectf = rr->rectf; - else { - if (rr->rect32) { - /* special case, currently only happens with sequencer rendering, - * which updates the whole frame, so we can only mark display buffer - * as invalid here (sergey) - */ - ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; - return; - } + /* The thing here is, the logic below (which was default behavior + * of how rectf is acquiring since forever) gives float buffer for + * composite output only. This buffer can not be used for other + * passes obviously. + * + * We might try finding corresponding for pass buffer in render result + * (which is actually missing when rendering with Cycles, who only + * writes all the passes when the tile is finished) or use float + * buffer from image buffer as reference, which is easier to use and + * contains all the data we need anyway. + * - sergey - + */ + /* TODO(sergey): Need to check has_combined here? */ + if (iuser->pass == 0) { + /* find current float rect for display, first case is after composite... still weak */ + if (rr->rectf) + rectf = rr->rectf; else { - if (rr->renlay == NULL || rr->renlay->rectf == NULL) return; - rectf = rr->renlay->rectf; + if (rr->rect32) { + /* special case, currently only happens with sequencer rendering, + * which updates the whole frame, so we can only mark display buffer + * as invalid here (sergey) + */ + ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; + return; + } + else { + if (rr->renlay == NULL || rr->renlay->rectf == NULL) return; + rectf = rr->renlay->rectf; + } } - } - if (rectf == NULL) return; + if (rectf == NULL) return; - if (ibuf->rect == NULL) - imb_addrectImBuf(ibuf); - - rectf += 4 * (rr->rectx * ymin + xmin); + rectf += 4 * (rr->rectx * ymin + xmin); + linear_stride = rr->rectx; + linear_offset_x = rxmin; + linear_offset_y = rymin; + } + else { + rectf = ibuf->rect_float; + linear_stride = ibuf->x; + linear_offset_x = 0; + linear_offset_y = 0; + } - IMB_partial_display_buffer_update(ibuf, rectf, NULL, rr->rectx, rxmin, rymin, + IMB_partial_display_buffer_update(ibuf, rectf, NULL, + linear_stride, linear_offset_x, linear_offset_y, &scene->view_settings, &scene->display_settings, - rxmin, rymin, rxmin + xmax, rymin + ymax, true); + rxmin, rymin, rxmin + xmax, rymin + ymax, false); } /* ****************************** render invoking ***************** */ @@ -262,7 +290,6 @@ typedef struct RenderJob { Main *main; Scene *scene; Render *re; - wmWindow *win; SceneRenderLayer *srl; struct Object *camera_override; int lay_override; @@ -275,6 +302,9 @@ typedef struct RenderJob { short *do_update; float *progress; ReportList *reports; + int orig_layer; + int last_layer; + ScrArea *sa; } RenderJob; static void render_freejob(void *rjv) @@ -402,6 +432,64 @@ static void render_progress_update(void *rjv, float progress) } } +/* Not totally reliable, but works fine in most of cases and + * in worst case would just make it so extra color management + * for the whole render result is applied (which was already + * happening already). + */ +static void render_image_update_pass_and_layer(RenderJob *rj, RenderResult *rr, ImageUser *iuser) +{ + wmWindowManager *wm; + ScrArea *first_sa = NULL, *matched_sa = NULL; + + /* image window, compo node users */ + for (wm = rj->main->wm.first; wm && matched_sa == NULL; wm = wm->id.next) { /* only 1 wm */ + wmWindow *win; + for (win = wm->windows.first; win && matched_sa == NULL; win = win->next) { + ScrArea *sa; + for (sa = win->screen->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_IMAGE) { + SpaceImage *sima = sa->spacedata.first; + if (sima->image == rj->image) { + if (first_sa == NULL) { + first_sa = sa; + } + if (sa == rj->sa) { + matched_sa = sa; + break; + } + } + } + } + } + } + + if (matched_sa == NULL) { + matched_sa = first_sa; + } + + if (matched_sa) { + SpaceImage *sima = matched_sa->spacedata.first; + RenderResult *main_rr = RE_AcquireResultRead(rj->re); + + /* TODO(sergey): is there faster way to get the layer index? */ + if (rr->renlay) { + int layer = BLI_findstringindex(&main_rr->layers, + (char *)rr->renlay->name, + offsetof(RenderLayer, name)); + if (layer != rj->last_layer) { + sima->iuser.layer = layer; + rj->last_layer = layer; + } + } + + iuser->pass = sima->iuser.pass; + iuser->layer = sima->iuser.layer; + + RE_ReleaseResult(rj->re); + } +} + static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect) { RenderJob *rj = rjv; @@ -423,9 +511,17 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec } /* update part of render */ + render_image_update_pass_and_layer(rj, rr, &rj->iuser); ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock); if (ibuf) { - image_buffer_rect_update(rj->scene, rr, ibuf, renrect); + /* Don't waste time on CPU side color management if + * image will be displayed using GLSL. + */ + if (ibuf->channels == 1 || + U.image_draw_method != IMAGE_DRAW_METHOD_GLSL) + { + image_buffer_rect_update(rj->scene, rr, ibuf, &rj->iuser, renrect); + } /* make jobs timer to send notifier */ *(rj->do_update) = TRUE; @@ -451,6 +547,28 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro RE_SetReports(rj->re, NULL); } +static void render_image_restore_layer(RenderJob *rj) +{ + wmWindowManager *wm; + + /* image window, compo node users */ + for (wm = rj->main->wm.first; wm; wm = wm->id.next) { /* only 1 wm */ + wmWindow *win; + for (win = wm->windows.first; win; win = win->next) { + ScrArea *sa; + for (sa = win->screen->areabase.first; sa; sa = sa->next) { + if (sa == rj->sa) { + if (sa->spacetype == SPACE_IMAGE) { + SpaceImage *sima = sa->spacedata.first; + sima->iuser.layer = rj->orig_layer; + } + return; + } + } + } + } +} + static void render_endjob(void *rjv) { RenderJob *rj = rjv; @@ -481,6 +599,10 @@ static void render_endjob(void *rjv) WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene); } + if (rj->sa) { + render_image_restore_layer(rj); + } + /* XXX render stability hack */ G.is_rendering = FALSE; WM_main_add_notifier(NC_SCENE | ND_RENDER_RESULT, NULL); @@ -592,6 +714,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL; const char *name; Object *active_object = CTX_data_active_object(C); + ScrArea *sa; /* only one render job at a time */ if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) @@ -644,7 +767,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even // store spare /* ensure at least 1 area shows result */ - render_view_open(C, event->x, event->y); + sa = render_view_open(C, event->x, event->y); jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS; @@ -658,7 +781,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj = MEM_callocN(sizeof(RenderJob), "render job"); rj->main = mainp; rj->scene = scene; - rj->win = CTX_wm_window(C); rj->srl = srl; rj->camera_override = camera_override; rj->lay_override = 0; @@ -667,6 +789,14 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj->iuser.scene = scene; rj->iuser.ok = 1; rj->reports = op->reports; + rj->orig_layer = 0; + rj->last_layer = 0; + rj->sa = sa; + + if (sa) { + SpaceImage *sima = sa->spacedata.first; + rj->orig_layer = sima->iuser.layer; + } if (v3d) { if (scene->lay != v3d->lay) { @@ -699,7 +829,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even re = RE_NewRender(scene->id.name); RE_test_break_cb(re, rj, render_breakjob); RE_draw_lock_cb(re, rj, render_drawlock); - RE_display_draw_cb(re, rj, image_rect_update); + RE_display_update_cb(re, rj, image_rect_update); RE_stats_draw_cb(re, rj, image_renderinfo_cb); RE_progress_cb(re, rj, render_progress_update); @@ -850,7 +980,7 @@ static int render_view3d_break(void *rpv) return *(rp->stop); } -static void render_view3d_draw_update(void *rpv, RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) +static void render_view3d_display_update(void *rpv, RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) { RenderPreview *rp = rpv; @@ -908,7 +1038,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda /* set this always, rp is different for each job */ RE_test_break_cb(re, rp, render_view3d_break); - RE_display_draw_cb(re, rp, render_view3d_draw_update); + RE_display_update_cb(re, rp, render_view3d_display_update); RE_stats_draw_cb(re, rp, render_view3d_renderinfo_cb); rstats = RE_GetStats(re); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 081187ef1d8..99f86371eb3 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -625,7 +625,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r /* **************************** new shader preview system ****************** */ /* inside thread, called by renderer, sets job update value */ -static void shader_preview_draw(void *spv, RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) +static void shader_preview_update(void *spv, RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) { ShaderPreview *sp = spv; @@ -734,7 +734,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs /* callbacs are cleared on GetRender() */ if (ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) { - RE_display_draw_cb(re, sp, shader_preview_draw); + RE_display_update_cb(re, sp, shader_preview_update); } /* set this for all previews, default is react to G.is_break still */ RE_test_break_cb(re, sp, shader_preview_break); diff --git a/source/blender/editors/render/render_view.c b/source/blender/editors/render/render_view.c index 1103f956f78..9f72ddc179f 100644 --- a/source/blender/editors/render/render_view.c +++ b/source/blender/editors/render/render_view.c @@ -132,7 +132,7 @@ static ScrArea *find_area_image_empty(bContext *C) /********************** open image editor for render *************************/ /* new window uses x,y to set position */ -void render_view_open(bContext *C, int mx, int my) +ScrArea *render_view_open(bContext *C, int mx, int my) { wmWindow *win = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); @@ -141,7 +141,7 @@ void render_view_open(bContext *C, int mx, int my) int area_was_image = 0; if (scene->r.displaymode == R_OUTPUT_NONE) - return; + return NULL; if (scene->r.displaymode == R_OUTPUT_WINDOW) { rcti rect; @@ -226,6 +226,8 @@ void render_view_open(bContext *C, int mx, int my) * full screen to the original tiled setup */ } } + + return sa; } /*************************** cancel render viewer **********************/ diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index af5f9d3c875..230c3a11108 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -1050,39 +1050,6 @@ void glaDrawImBuf_glsl(ImBuf *ibuf, float x, float y, int zoomfilter, /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); - /* This is actually lots of crap, but currently not sure about - * more clear way to bypass partial buffer update crappyness - * while rendering. - * - * The thing is -- render engines are only updating byte and - * display buffers for active render result opened in image - * editor. This works fine to show render progress without - * switching render layers in image editor user, but this is - * completely useless for GLSL display, where we need to have - * original buffer which we could color manage. - * - * For the time of rendering, we'll stick back to slower CPU - * display buffer update. GLSL could be used as soon as some - * fixes (?) are done in render itself, so we'll always have - * image buffer with relevant float buffer opened while - * rendering. - * - * On the other hand, when using Cycles, stressing GPU with - * GLSL could backfire on a performance. - * - sergey - - */ - if (G.is_rendering) { - /* Try to detect whether we're drawing render result, - * other images could have both rect and rect_float - * but they'll be synchronized - */ - if (ibuf->rect_float && ibuf->rect && - ((ibuf->mall & IB_rectfloat) == 0)) - { - force_fallback = true; - } - } - /* Try to draw buffer using GLSL display transform */ if (force_fallback == false) { int ok; |