Cycles refactoring: put external engine code into separate file.

This commit is contained in:
Brecht Van Lommel 2011-05-05 09:43:45 +00:00
parent 6778ea39d5
commit 61fdadbb2e
16 changed files with 333 additions and 211 deletions

@ -139,7 +139,7 @@
#include "BLO_undofile.h" #include "BLO_undofile.h"
#include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory #include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory
#include "RE_pipeline.h" #include "RE_engine.h"
#include "readfile.h" #include "readfile.h"

@ -238,7 +238,7 @@ static void scene_changed(Main *bmain, Scene *UNUSED(scene))
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_view3d_types.h" #include "DNA_view3d_types.h"
#include "RE_pipeline.h" #include "RE_engine.h"
static void update_render_engines(Main *bmain, int tagged_only) static void update_render_engines(Main *bmain, int tagged_only)
{ {

@ -58,7 +58,7 @@
#include "WM_api.h" #include "WM_api.h"
#include "WM_types.h" #include "WM_types.h"
#include "RE_pipeline.h" #include "RE_engine.h"
#include "RNA_access.h" #include "RNA_access.h"

@ -63,6 +63,7 @@
#include "BKE_scene.h" #include "BKE_scene.h"
#include "BKE_unit.h" #include "BKE_unit.h"
#include "RE_engine.h"
#include "RE_pipeline.h" // make_stars #include "RE_pipeline.h" // make_stars
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"

@ -35,6 +35,7 @@
#include "rna_internal.h" #include "rna_internal.h"
#include "RE_engine.h"
#include "RE_pipeline.h" #include "RE_pipeline.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"

@ -41,6 +41,7 @@
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
/* Include for Bake Options */ /* Include for Bake Options */
#include "RE_engine.h"
#include "RE_pipeline.h" #include "RE_pipeline.h"
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME

@ -77,7 +77,9 @@ set(SRC
intern/source/volumetric.c intern/source/volumetric.c
intern/source/voxeldata.c intern/source/voxeldata.c
intern/source/zbuf.c intern/source/zbuf.c
intern/pipeline/engine.c
extern/include/RE_engine.h
extern/include/RE_pipeline.h extern/include/RE_pipeline.h
extern/include/RE_render_ext.h extern/include/RE_render_ext.h
extern/include/RE_shader_ext.h extern/include/RE_shader_ext.h

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
Import ('env') Import ('env')
sources = env.Glob('intern/source/*.c') sources = env.Glob('intern/source/*.c') + env.Glob('intern/pipeline/*.c')
raysources = env.Glob('intern/raytrace/*.cpp') raysources = env.Glob('intern/raytrace/*.cpp')
incs = 'intern/include #/intern/guardedalloc ../blenlib ../makesdna ../makesrna' incs = 'intern/include #/intern/guardedalloc ../blenlib ../makesdna ../makesrna'

@ -0,0 +1,102 @@
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file RE_engine.h
* \ingroup render
*/
#ifndef RE_ENGINE_H
#define RE_ENGINE_H
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
#include "RNA_types.h"
struct Render;
struct RenderEngine;
struct RenderEngineType;
struct RenderLayer;
struct RenderResult;
struct ReportList;
struct Scene;
/* External Engine */
#define RE_INTERNAL 1
#define RE_GAME 2
#define RE_DO_PREVIEW 4
#define RE_DO_ALL 8
extern ListBase R_engines;
typedef struct RenderEngineType {
struct RenderEngineType *next, *prev;
/* type info */
char idname[64]; // best keep the same size as BKE_ST_MAXNAME
char name[64];
int flag;
void (*render)(struct RenderEngine *engine, struct Scene *scene);
void (*draw)(struct RenderEngine *engine, struct Scene *scene);
void (*update)(struct RenderEngine *engine, struct Scene *scene);
/* RNA integration */
ExtensionRNA ext;
} RenderEngineType;
typedef struct RenderEngine {
RenderEngineType *type;
struct Render *re;
ListBase fullresult;
void *py_instance;
int do_draw;
int do_update;
} RenderEngine;
RenderEngine *RE_engine_create(RenderEngineType *type);
void RE_engine_free(RenderEngine *engine);
void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y);
void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename);
LIBEXPORT struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h);
LIBEXPORT void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
LIBEXPORT void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
LIBEXPORT int RE_engine_test_break(RenderEngine *engine);
LIBEXPORT void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info);
int RE_engine_render(struct Render *re, int do_all);
void RE_engines_init(void);
void RE_engines_exit(void);
#endif /* RE_ENGINE_H */

@ -36,7 +36,6 @@
#include "DNA_listBase.h" #include "DNA_listBase.h"
#include "DNA_vec_types.h" #include "DNA_vec_types.h"
#include "RNA_types.h"
struct bNodeTree; struct bNodeTree;
struct Image; struct Image;
@ -44,11 +43,8 @@ struct Main;
struct NodeBlurData; struct NodeBlurData;
struct Object; struct Object;
struct RenderData; struct RenderData;
struct RenderEngine;
struct RenderEngineType;
struct RenderResult; struct RenderResult;
struct ReportList; struct ReportList;
struct ReportList;
struct Scene; struct Scene;
struct SceneRenderLayer; struct SceneRenderLayer;
@ -263,56 +259,6 @@ void RE_DataBase_GetView(struct Render *re, float mat[][4]);
void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]); void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]);
struct Scene *RE_GetScene(struct Render *re); struct Scene *RE_GetScene(struct Render *re);
/* External Engine */
#define RE_INTERNAL 1
#define RE_GAME 2
#define RE_DO_PREVIEW 4
#define RE_DO_ALL 8
extern ListBase R_engines;
typedef struct RenderEngineType {
struct RenderEngineType *next, *prev;
/* type info */
char idname[64]; // best keep the same size as BKE_ST_MAXNAME
char name[64];
int flag;
void (*render)(struct RenderEngine *engine, struct Scene *scene);
void (*draw)(struct RenderEngine *engine, struct Scene *scene);
void (*update)(struct RenderEngine *engine, struct Scene *scene);
/* RNA integration */
ExtensionRNA ext;
} RenderEngineType;
typedef struct RenderEngine {
RenderEngineType *type;
struct Render *re;
ListBase fullresult;
void *py_instance;
int do_draw;
int do_update;
} RenderEngine;
RenderEngine *RE_engine_create(RenderEngineType *type);
void RE_engine_free(RenderEngine *engine);
void RE_layer_load_from_file(RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y);
void RE_result_load_from_file(RenderResult *result, struct ReportList *reports, const char *filename);
LIBEXPORT struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h);
LIBEXPORT void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
LIBEXPORT void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
LIBEXPORT int RE_engine_test_break(RenderEngine *engine);
LIBEXPORT void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info);
void RE_engines_init(void);
void RE_engines_exit(void);
int RE_is_rendering_allowed(struct Scene *scene, void *erh, void (*error)(void *handle, const char *str)); int RE_is_rendering_allowed(struct Scene *scene, void *erh, void (*error)(void *handle, const char *str));
#endif /* RE_PIPELINE_H */ #endif /* RE_PIPELINE_H */

@ -35,14 +35,22 @@
#ifndef PIPELINE_H #ifndef PIPELINE_H
#define PIPELINE_H #define PIPELINE_H
struct ListBase;
struct Render; struct Render;
struct RenderResult; struct RenderResult;
struct RenderLayer; struct RenderLayer;
struct rcti;
struct RenderLayer *render_get_active_layer(struct Render *re, struct RenderResult *rr); struct RenderLayer *render_get_active_layer(struct Render *re, struct RenderResult *rr);
float panorama_pixel_rot(struct Render *re); float panorama_pixel_rot(struct Render *re);
#define PASS_VECTOR_MAX 10000.0f #define PASS_VECTOR_MAX 10000.0f
#define RR_USEMEM 0
struct RenderResult *new_render_result(struct Render *re, struct rcti *partrct, int crop, int savebuffers);
void merge_render_result(struct RenderResult *rr, struct RenderResult *rrpart);
void free_render_result(struct ListBase *lb, struct RenderResult *rr);
#endif /* PIPELINE_H */ #endif /* PIPELINE_H */

@ -0,0 +1,205 @@
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/render/intern/pipeline/engine.c
* \ingroup render
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BKE_report.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "intern/openexr/openexr_multi.h"
#ifdef WITH_PYTHON
#include "BPY_extern.h"
#endif
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "render_types.h"
#include "renderpipeline.h"
/* Create, Free */
RenderEngine *RE_engine_create(RenderEngineType *type)
{
RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine");
engine->type= type;
return engine;
}
void RE_engine_free(RenderEngine *engine)
{
#ifdef WITH_PYTHON
if(engine->py_instance) {
BPY_DECREF(engine->py_instance);
}
#endif
MEM_freeN(engine);
}
/* Render Results */
RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h)
{
Render *re= engine->re;
RenderResult *result;
rcti disprect;
/* ensure the coordinates are within the right limits */
CLAMP(x, 0, re->result->rectx);
CLAMP(y, 0, re->result->recty);
CLAMP(w, 0, re->result->rectx);
CLAMP(h, 0, re->result->recty);
if(x + w > re->result->rectx)
w= re->result->rectx - x;
if(y + h > re->result->recty)
h= re->result->recty - y;
/* allocate a render result */
disprect.xmin= x;
disprect.xmax= x+w;
disprect.ymin= y;
disprect.ymax= y+h;
result= new_render_result(re, &disprect, 0, RR_USEMEM);
BLI_addtail(&engine->fullresult, result);
return result;
}
void RE_engine_update_result(RenderEngine *engine, RenderResult *result)
{
Render *re= engine->re;
if(result) {
result->renlay= result->layers.first; // weak, draws first layer always
re->display_draw(re->ddh, result, NULL);
}
}
void RE_engine_end_result(RenderEngine *engine, RenderResult *result)
{
Render *re= engine->re;
if(!result)
return;
/* merge. on break, don't merge in result for preview renders, looks nicer */
if(!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS)))
merge_render_result(re->result, result);
/* draw */
if(!re->test_break(re->tbh)) {
result->renlay= result->layers.first; // weak, draws first layer always
re->display_draw(re->ddh, result, NULL);
}
/* free */
free_render_result(&engine->fullresult, result);
}
/* Cancel */
int RE_engine_test_break(RenderEngine *engine)
{
Render *re= engine->re;
return re->test_break(re->tbh);
}
/* Statistics */
void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
{
Render *re= engine->re;
re->i.statstr= stats;
re->i.infostr= info;
re->stats_draw(re->sdh, &re->i);
re->i.infostr= NULL;
re->i.statstr= NULL;
}
/* Render */
int RE_engine_render(Render *re, int do_all)
{
RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname));
RenderEngine *engine;
/* verify if we can render */
if(!(type && type->render))
return 0;
if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
return 0;
if(do_all && !(type->flag & RE_DO_ALL))
return 0;
if(!do_all && (type->flag & RE_DO_ALL))
return 0;
/* create render result */
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
RE_FreeRenderResult(re->result);
re->result= new_render_result(re, &re->disprect, 0, 0);
}
BLI_rw_mutex_unlock(&re->resultmutex);
if(re->result==NULL)
return 1;
/* render */
engine = RE_engine_create(type);
engine->re= re;
type->render(engine, re->scene);
free_render_result(&engine->fullresult, engine->fullresult.first);
RE_engine_free(engine);
return 1;
}

@ -70,12 +70,9 @@
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"
#ifdef WITH_PYTHON
#include "BPY_extern.h"
#endif
#include "intern/openexr/openexr_multi.h" #include "intern/openexr/openexr_multi.h"
#include "RE_engine.h"
#include "RE_pipeline.h" #include "RE_pipeline.h"
/* internal */ /* internal */
@ -216,7 +213,7 @@ void RE_FreeRenderResult(RenderResult *res)
} }
/* version that's compatible with fullsample buffers */ /* version that's compatible with fullsample buffers */
static void free_render_result(ListBase *lb, RenderResult *rr) void free_render_result(ListBase *lb, RenderResult *rr)
{ {
RenderResult *rrnext; RenderResult *rrnext;
@ -539,12 +536,11 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name)
return NULL; return NULL;
} }
#define RR_USEMEM 0
/* called by main render as well for parts */ /* called by main render as well for parts */
/* will read info from Render *re to define layers */ /* will read info from Render *re to define layers */
/* called in threads */ /* called in threads */
/* re->winx,winy is coordinate space of entire image, partrct the part within */ /* re->winx,winy is coordinate space of entire image, partrct the part within */
static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int savebuffers) RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int savebuffers)
{ {
RenderResult *rr; RenderResult *rr;
RenderLayer *rl; RenderLayer *rl;
@ -721,7 +717,7 @@ static void do_merge_tile(RenderResult *rr, RenderResult *rrpart, float *target,
/* used when rendering to a full buffer, or when reading the exr part-layer-pass file */ /* used when rendering to a full buffer, or when reading the exr part-layer-pass file */
/* no test happens here if it fits... we also assume layers are in sync */ /* no test happens here if it fits... we also assume layers are in sync */
/* is used within threads */ /* is used within threads */
static void merge_render_result(RenderResult *rr, RenderResult *rrpart) void merge_render_result(RenderResult *rr, RenderResult *rrpart)
{ {
RenderLayer *rl, *rlp; RenderLayer *rl, *rlp;
RenderPass *rpass, *rpassp; RenderPass *rpass, *rpassp;
@ -1799,12 +1795,10 @@ void RE_TileProcessor(Render *re)
/* ************ This part uses API, for rendering Blender scenes ********** */ /* ************ This part uses API, for rendering Blender scenes ********** */
static int external_render_3d(Render *re, int do_all);
static void do_render_3d(Render *re) static void do_render_3d(Render *re)
{ {
/* try external */ /* try external */
if(external_render_3d(re, 0)) if(RE_engine_render(re, 0))
return; return;
/* internal */ /* internal */
@ -2632,7 +2626,7 @@ static void do_render_all_options(Render *re)
/* ensure no images are in memory from previous animated sequences */ /* ensure no images are in memory from previous animated sequences */
BKE_image_all_free_anim_ibufs(re->r.cfra); BKE_image_all_free_anim_ibufs(re->r.cfra);
if(external_render_3d(re, 1)) { if(RE_engine_render(re, 1)) {
/* in this case external render overrides all */ /* in this case external render overrides all */
} }
else if(seq_render_active(re)) { else if(seq_render_active(re)) {
@ -3223,110 +3217,6 @@ void RE_init_threadcount(Render *re)
} }
} }
/************************** External Engines ***************************/
RenderEngine *RE_engine_create(RenderEngineType *type)
{
RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine");
engine->type= type;
return engine;
}
void RE_engine_free(RenderEngine *engine)
{
#ifdef WITH_PYTHON
if(engine->py_instance) {
/* do this first incase there are any __del__ functions or
* similar that use properties */
BPY_DECREF(engine->py_instance);
}
#endif
MEM_freeN(engine);
}
RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h)
{
Render *re= engine->re;
RenderResult *result;
rcti disprect;
/* ensure the coordinates are within the right limits */
CLAMP(x, 0, re->result->rectx);
CLAMP(y, 0, re->result->recty);
CLAMP(w, 0, re->result->rectx);
CLAMP(h, 0, re->result->recty);
if(x + w > re->result->rectx)
w= re->result->rectx - x;
if(y + h > re->result->recty)
h= re->result->recty - y;
/* allocate a render result */
disprect.xmin= x;
disprect.xmax= x+w;
disprect.ymin= y;
disprect.ymax= y+h;
result= new_render_result(re, &disprect, 0, RR_USEMEM);
BLI_addtail(&engine->fullresult, result);
return result;
}
void RE_engine_update_result(RenderEngine *engine, RenderResult *result)
{
Render *re= engine->re;
if(result && render_display_draw_enabled(re)) {
result->renlay= result->layers.first; // weak
re->display_draw(re->ddh, result, NULL);
}
}
void RE_engine_end_result(RenderEngine *engine, RenderResult *result)
{
Render *re= engine->re;
if(!result)
return;
/* merge */
if(render_display_draw_enabled(re)) {
/* on break, don't merge in result for preview renders, looks nicer */
if(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS));
else merge_render_result(re->result, result);
}
/* draw */
if(!re->test_break(re->tbh) && render_display_draw_enabled(re)) {
result->renlay= result->layers.first; // weak
re->display_draw(re->ddh, result, NULL);
}
/* free */
free_render_result(&engine->fullresult, result);
}
int RE_engine_test_break(RenderEngine *engine)
{
Render *re= engine->re;
return re->test_break(re->tbh);
}
void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
{
Render *re= engine->re;
re->i.statstr= stats;
re->i.infostr= info;
re->stats_draw(re->sdh, &re->i);
re->i.infostr= NULL;
re->i.statstr= NULL;
}
/* loads in image into a result, size must match /* loads in image into a result, size must match
* x/y offsets are only used on a partial copy when dimensions dont match */ * x/y offsets are only used on a partial copy when dimensions dont match */
void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char *filename, int x, int y) void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char *filename, int x, int y)
@ -3389,40 +3279,4 @@ void RE_result_load_from_file(RenderResult *result, ReportList *reports, const c
#endif #endif
} }
static int external_render_3d(Render *re, int do_all)
{
RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname));
RenderEngine *engine;
if(!(type && type->render))
return 0;
if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
return 0;
if(do_all && !(type->flag & RE_DO_ALL))
return 0;
if(!do_all && (type->flag & RE_DO_ALL))
return 0;
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
RE_FreeRenderResult(re->result);
re->result= new_render_result(re, &re->disprect, 0, 0);
}
BLI_rw_mutex_unlock(&re->resultmutex);
if(re->result==NULL)
return 1;
/* external */
engine = RE_engine_create(type);
engine->re= re;
type->render(engine, re->scene);
free_render_result(&engine->fullresult, engine->fullresult.first);
RE_engine_free(engine);
return 1;
}

@ -57,7 +57,7 @@
#include "GPU_draw.h" #include "GPU_draw.h"
#include "GPU_extensions.h" #include "GPU_extensions.h"
#include "RE_pipeline.h" #include "RE_engine.h"
#include "WM_api.h" #include "WM_api.h"
#include "WM_types.h" #include "WM_types.h"

@ -65,6 +65,7 @@
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_winstuff.h" #include "BLI_winstuff.h"
#include "RE_engine.h"
#include "RE_pipeline.h" /* RE_ free stuff */ #include "RE_pipeline.h" /* RE_ free stuff */
#ifdef WITH_PYTHON #ifdef WITH_PYTHON

@ -90,6 +90,7 @@
#include "BPY_extern.h" #include "BPY_extern.h"
#endif #endif
#include "RE_engine.h"
#include "RE_pipeline.h" #include "RE_pipeline.h"
//XXX #include "playanim_ext.h" //XXX #include "playanim_ext.h"