Point cache: Pass EvaluationContext for all the related functions

Now the only missing bit seems to be in Cycles to pass depsgraph to
builtin_image_float_pixels().

Ideally we could get evaluation context instead of using depsgraph + settings.
But for the other rna EvaluationContext functions this is how we are doing.

Reviewers: sergey, brecht

Differential Revision: https://developer.blender.org/D3087
This commit is contained in:
Dalai Felinto 2018-02-28 13:54:00 -03:00
parent 4a892adac5
commit 382218beb2
10 changed files with 95 additions and 84 deletions

View File

@ -1280,9 +1280,8 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
else {
/* TODO: fix point density to work with new view layer depsgraph */
#if 0
/* We originally were passing view_layer here but in reality we need a whole EvaluationContext
* in the RE_point_density_minmax() function.
* Note: There is not a single EvaluationContext for the entire render. They are per RenderLayer now.
/* We originally were passing view_layer here but in reality we need a whole EvaluationContext or at the
* very least a dpesgraph to pass to the RE_point_density_minmax() function.
*/
/* TODO(sergey): Check we're indeed in shader node tree. */
PointerRNA ptr;
@ -1292,7 +1291,7 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
int length;
int settings = background ? 1 : 0; /* 1 - render settings, 0 - vewport settings. */
b_point_density_node.calc_point_density(b_scene, b_view_layer, settings, &length, &pixels);
b_point_density_node.calc_point_density(b_depsgraph, settings, &length, &pixels);
}
#endif
}

View File

@ -234,8 +234,8 @@ static void get_tex_mapping(TextureMapping *mapping,
static ShaderNode *add_node(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
BL::ViewLayer& b_view_layer,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree& b_ntree,
@ -848,7 +848,7 @@ static ShaderNode *add_node(Scene *scene,
/* TODO(sergey): Use more proper update flag. */
if(true) {
b_point_density_node.cache_point_density(b_scene, b_view_layer, settings);
b_point_density_node.cache_point_density(b_depsgraph, settings);
scene->image_manager->tag_reload_image(
point_density->filename.string(),
point_density->builtin_data,
@ -866,7 +866,7 @@ static ShaderNode *add_node(Scene *scene,
BL::Object b_ob(b_point_density_node.object());
if(b_ob) {
float3 loc, size;
point_density_texture_space(b_scene, b_view_layer,
point_density_texture_space(b_depsgraph,
b_point_density_node,
settings,
loc,
@ -1006,8 +1006,8 @@ static BL::ShaderNode find_output_node(BL::ShaderNodeTree& b_ntree)
static void add_nodes(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
BL::ViewLayer& b_view_layer,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree& b_ntree,
@ -1093,8 +1093,8 @@ static void add_nodes(Scene *scene,
add_nodes(scene,
b_engine,
b_data,
b_depsgraph,
b_scene,
b_view_layer,
background,
graph,
b_group_ntree,
@ -1141,8 +1141,8 @@ static void add_nodes(Scene *scene,
node = add_node(scene,
b_engine,
b_data,
b_depsgraph,
b_scene,
b_view_layer,
background,
graph,
b_ntree,
@ -1205,8 +1205,8 @@ static void add_nodes(Scene *scene,
static void add_nodes(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
BL::ViewLayer& b_view_layer,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree& b_ntree)
@ -1215,8 +1215,8 @@ static void add_nodes(Scene *scene,
add_nodes(scene,
b_engine,
b_data,
b_depsgraph,
b_scene,
b_view_layer,
background,
graph,
b_ntree,
@ -1228,7 +1228,6 @@ static void add_nodes(Scene *scene,
void BlenderSync::sync_materials(BL::Depsgraph& b_depsgraph, bool update_all)
{
BL::ViewLayer b_view_layer(b_depsgraph.view_layer());
shader_map.set_default(scene->default_surface);
TaskPool pool;
@ -1256,7 +1255,7 @@ void BlenderSync::sync_materials(BL::Depsgraph& b_depsgraph, bool update_all)
if(b_mat->use_nodes() && b_mat->node_tree()) {
BL::ShaderNodeTree b_ntree(b_mat->node_tree());
add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
}
else {
DiffuseBsdfNode *diffuse = new DiffuseBsdfNode();
@ -1314,7 +1313,6 @@ void BlenderSync::sync_materials(BL::Depsgraph& b_depsgraph, bool update_all)
void BlenderSync::sync_world(BL::Depsgraph& b_depsgraph, bool update_all)
{
BL::ViewLayer b_view_layer(b_depsgraph.view_layer());
Background *background = scene->background;
Background prevbackground = *background;
@ -1328,7 +1326,7 @@ void BlenderSync::sync_world(BL::Depsgraph& b_depsgraph, bool update_all)
if(b_world && b_world.use_nodes() && b_world.node_tree()) {
BL::ShaderNodeTree b_ntree(b_world.node_tree());
add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
/* volume */
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
@ -1407,7 +1405,6 @@ void BlenderSync::sync_world(BL::Depsgraph& b_depsgraph, bool update_all)
void BlenderSync::sync_lamps(BL::Depsgraph& b_depsgraph, bool update_all)
{
BL::ViewLayer b_view_layer(b_depsgraph.view_layer());
shader_map.set_default(scene->default_light);
/* lamp loop */
@ -1431,7 +1428,7 @@ void BlenderSync::sync_lamps(BL::Depsgraph& b_depsgraph, bool update_all)
BL::ShaderNodeTree b_ntree(b_lamp->node_tree());
add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree);
add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
}
else {
float strength = 1.0f;

View File

@ -34,7 +34,7 @@ void density_texture_space_invert(float3& loc,
} /* namespace */
void point_density_texture_space(BL::Scene& b_scene, BL::ViewLayer& b_view_layer,
void point_density_texture_space(BL::Depsgraph& b_depsgraph,
BL::ShaderNodeTexPointDensity& b_point_density_node,
int settings,
float3& loc,
@ -47,8 +47,7 @@ void point_density_texture_space(BL::Scene& b_scene, BL::ViewLayer& b_view_layer
return;
}
float3 min, max;
b_point_density_node.calc_point_density_minmax(b_scene,
b_view_layer,
b_point_density_node.calc_point_density_minmax(b_depsgraph,
settings,
&min[0],
&max[0]);

View File

@ -22,7 +22,7 @@
CCL_NAMESPACE_BEGIN
void point_density_texture_space(BL::Scene& b_scene, BL::ViewLayer& b_view_layer,
void point_density_texture_space(BL::Depsgraph& b_depsgraph,
BL::ShaderNodeTexPointDensity& b_point_density_node,
const int settings,
float3& loc,

View File

@ -230,6 +230,11 @@ void DEG_evaluation_context_init_from_view_layer_for_render(
struct Scene *scene,
struct ViewLayer *view_layer);
void DEG_evaluation_context_init_from_depsgraph(
struct EvaluationContext *eval_ctx,
struct Depsgraph *depsgraph,
eEvaluationMode mode);
/* Free evaluation context. */
void DEG_evaluation_context_free(struct EvaluationContext *eval_ctx);

View File

@ -39,10 +39,12 @@
extern "C" {
#include "BKE_scene.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
} /* extern "C" */
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "intern/eval/deg_eval.h"
#include "intern/eval/deg_eval_flush.h"
@ -111,6 +113,20 @@ void DEG_evaluation_context_init_from_view_layer_for_render(
eval_ctx->engine_type = NULL;
}
void DEG_evaluation_context_init_from_depsgraph(
EvaluationContext *eval_ctx,
Depsgraph *depsgraph,
eEvaluationMode mode)
{
Scene *scene = DEG_get_evaluated_scene(depsgraph);
DEG_evaluation_context_init(eval_ctx, mode);
eval_ctx->ctime = (float)scene->r.cfra + scene->r.subframe;
eval_ctx->object_mode = OB_MODE_OBJECT;
eval_ctx->depsgraph = depsgraph;
eval_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph);
eval_ctx->engine_type = NULL;
}
/* Free evaluation context. */
void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
{

View File

@ -3134,16 +3134,22 @@ static int point_density_vertex_color_source_from_shader(NodeShaderTexPointDensi
}
void rna_ShaderNodePointDensity_density_cache(bNode *self,
Scene *scene,
ViewLayer *view_layer,
Depsgraph *depsgraph,
int settings)
{
NodeShaderTexPointDensity *shader_point_density = self->storage;
PointDensity *pd = &shader_point_density->pd;
if (scene == NULL) {
if (depsgraph == NULL) {
return;
}
EvaluationContext eval_ctx;
DEG_evaluation_context_init_from_depsgraph(&eval_ctx,
depsgraph,
settings == 1 ? DAG_EVAL_RENDER :
DAG_EVAL_VIEWPORT);
/* Make sure there's no cached data. */
BKE_texture_pointdensity_free_data(pd);
RE_point_density_free(pd);
@ -3172,14 +3178,12 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self,
shader_point_density->cached_resolution = shader_point_density->resolution;
/* Single-threaded sampling of the voxel domain. */
RE_point_density_cache(scene,
view_layer, pd,
settings == 1);
RE_point_density_cache(&eval_ctx,
pd);
}
void rna_ShaderNodePointDensity_density_calc(bNode *self,
Scene *scene,
ViewLayer *view_layer,
Depsgraph *depsgraph,
int settings,
int *length,
float **values)
@ -3188,11 +3192,17 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
PointDensity *pd = &shader_point_density->pd;
const int resolution = shader_point_density->cached_resolution;
if (scene == NULL) {
if (depsgraph == NULL) {
*length = 0;
return;
}
EvaluationContext eval_ctx;
DEG_evaluation_context_init_from_depsgraph(&eval_ctx,
depsgraph,
settings == 1 ? DAG_EVAL_RENDER :
DAG_EVAL_VIEWPORT);
/* TODO(sergey): Will likely overflow, but how to pass size_t via RNA? */
*length = 4 * resolution * resolution * resolution;
@ -3201,9 +3211,9 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
}
/* Single-threaded sampling of the voxel domain. */
RE_point_density_sample(scene, view_layer, pd,
RE_point_density_sample(&eval_ctx,
pd,
resolution,
settings == 1,
*values);
/* We're done, time to clean up. */
@ -3213,20 +3223,27 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
}
void rna_ShaderNodePointDensity_density_minmax(bNode *self,
Scene *scene,
ViewLayer *view_layer,
Depsgraph *depsgraph,
int settings,
float r_min[3],
float r_max[3])
{
NodeShaderTexPointDensity *shader_point_density = self->storage;
PointDensity *pd = &shader_point_density->pd;
if (scene == NULL) {
if (depsgraph == NULL) {
zero_v3(r_min);
zero_v3(r_max);
return;
}
RE_point_density_minmax(scene, view_layer, pd, settings == 1, r_min, r_max);
EvaluationContext eval_ctx;
DEG_evaluation_context_init_from_depsgraph(&eval_ctx,
depsgraph,
settings == 1 ? DAG_EVAL_RENDER :
DAG_EVAL_VIEWPORT);
RE_point_density_minmax(&eval_ctx, pd, r_min, r_max);
}
#else
@ -4216,14 +4233,12 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
func = RNA_def_function(srna, "cache_point_density", "rna_ShaderNodePointDensity_density_cache");
RNA_def_function_ui_description(func, "Cache point density data for later calculation");
RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_pointer(func, "view_layer", "ViewLayer", "", "");
RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
func = RNA_def_function(srna, "calc_point_density", "rna_ShaderNodePointDensity_density_calc");
RNA_def_function_ui_description(func, "Calculate point density");
RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_pointer(func, "view_layer", "ViewLayer", "", "");
RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
/* TODO, See how array size of 0 works, this shouldnt be used. */
parm = RNA_def_float_array(func, "rgba_values", 1, NULL, 0, 0, "", "RGBA Values", 0, 0);
@ -4232,8 +4247,7 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
func = RNA_def_function(srna, "calc_point_density_minmax", "rna_ShaderNodePointDensity_density_minmax");
RNA_def_function_ui_description(func, "Calculate point density");
RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_pointer(func, "view_layer", "ViewLayer", "", "");
RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
parm = RNA_def_property(func, "min", PROP_FLOAT, PROP_COORDS);
RNA_def_property_array(parm, 3);

View File

@ -72,24 +72,18 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove);
struct PointDensity;
void RE_point_density_cache(
struct Scene *scene,
struct ViewLayer *view_layer,
struct PointDensity *pd,
const bool use_render_params);
const struct EvaluationContext *eval_ctx,
struct PointDensity *pd);
void RE_point_density_minmax(
struct Scene *scene,
struct ViewLayer *view_layer,
const struct EvaluationContext *eval_ctx,
struct PointDensity *pd,
const bool use_render_params,
float r_min[3], float r_max[3]);
void RE_point_density_sample(
struct Scene *scene,
struct ViewLayer *view_layer,
const struct EvaluationContext *eval_ctx,
struct PointDensity *pd,
const int resolution,
const bool use_render_params,
float *values);
void RE_point_density_free(struct PointDensity *pd);

View File

@ -59,6 +59,7 @@
#include "BKE_colortools.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "render_types.h"
#include "texture.h"
@ -882,7 +883,7 @@ static void sample_dummy_point_density(int resolution, float *values)
memset(values, 0, sizeof(float) * 4 * resolution * resolution * resolution);
}
static void particle_system_minmax(EvaluationContext *eval_ctx,
static void particle_system_minmax(const EvaluationContext *eval_ctx,
Scene *scene,
Object *object,
ParticleSystem *psys,
@ -945,33 +946,30 @@ static void particle_system_minmax(EvaluationContext *eval_ctx,
}
void RE_point_density_cache(
Scene *scene,
ViewLayer *view_layer,
PointDensity *pd,
const bool use_render_params)
const struct EvaluationContext *eval_ctx,
PointDensity *pd)
{
EvaluationContext eval_ctx = {0};
float mat[4][4];
const bool use_render_params = (eval_ctx->mode == DAG_EVAL_RENDER);
DEG_evaluation_context_init(&eval_ctx, use_render_params ? DAG_EVAL_RENDER
: DAG_EVAL_VIEWPORT);
eval_ctx.view_layer = view_layer;
Depsgraph *depsgraph = eval_ctx->depsgraph;
Scene *scene = DEG_get_evaluated_scene(depsgraph);
/* Same matricies/resolution as dupli_render_particle_set(). */
unit_m4(mat);
BLI_mutex_lock(&sample_mutex);
cache_pointdensity_ex(&eval_ctx, scene, pd, mat, mat, 1, 1, use_render_params);
cache_pointdensity_ex(eval_ctx, scene, pd, mat, mat, 1, 1, use_render_params);
BLI_mutex_unlock(&sample_mutex);
}
void RE_point_density_minmax(
struct Scene *scene,
ViewLayer *view_layer,
const struct EvaluationContext *eval_ctx,
struct PointDensity *pd,
const bool use_render_params,
float r_min[3], float r_max[3])
{
const bool use_render_params = (eval_ctx->mode == DAG_EVAL_RENDER);
Depsgraph *depsgraph = eval_ctx->depsgraph;
Scene *scene = DEG_get_evaluated_scene(depsgraph);
Object *object = pd->object;
if (object == NULL) {
zero_v3(r_min);
@ -980,7 +978,6 @@ void RE_point_density_minmax(
}
if (pd->source == TEX_PD_PSYS) {
ParticleSystem *psys;
EvaluationContext eval_ctx = {0};
if (pd->psys == 0) {
zero_v3(r_min);
@ -994,13 +991,7 @@ void RE_point_density_minmax(
return;
}
DEG_evaluation_context_init(&eval_ctx, use_render_params ? DAG_EVAL_RENDER :
DAG_EVAL_VIEWPORT);
eval_ctx.ctime = (float)scene->r.cfra + scene->r.subframe;
eval_ctx.view_layer = view_layer;
particle_system_minmax(&eval_ctx,
particle_system_minmax(eval_ctx,
scene,
object,
psys,
@ -1073,11 +1064,9 @@ static void point_density_sample_func(
* NOTE 2: Frees point density structure after sampling.
*/
void RE_point_density_sample(
Scene *scene,
ViewLayer *view_layer,
const EvaluationContext *eval_ctx,
PointDensity *pd,
const int resolution,
const bool use_render_params,
float *values)
{
Object *object = pd->object;
@ -1093,10 +1082,8 @@ void RE_point_density_sample(
}
BLI_mutex_lock(&sample_mutex);
RE_point_density_minmax(scene,
view_layer,
RE_point_density_minmax(eval_ctx,
pd,
use_render_params,
min,
max);
BLI_mutex_unlock(&sample_mutex);

View File

@ -766,9 +766,9 @@ void RE_engine_update_memory_stats(struct RenderEngine *engine, float mem_used,
struct RenderEngine *RE_engine_create(struct RenderEngineType *type) RET_NULL
void RE_engine_frame_set(struct RenderEngine *engine, int frame, float subframe) RET_NONE
void RE_FreePersistentData(void) RET_NONE
void RE_point_density_cache(struct Scene *scene, struct ViewLayer *view_layer, struct PointDensity *pd, const bool use_render_params) RET_NONE
void RE_point_density_minmax(struct Scene *scene, struct ViewLayer *view_layer, struct PointDensity *pd, const bool use_render_params, float r_min[3], float r_max[3]) RET_NONE
void RE_point_density_sample(struct Scene *scene, struct ViewLayer *view_layer, struct PointDensity *pd, const int resolution, const bool use_render_params, float *values) RET_NONE
void RE_point_density_cache(const struct EvaluationContext *eval_ctx, struct PointDensity *pd) RET_NONE
void RE_point_density_minmax(const struct EvaluationContext *eval_ctx, struct PointDensity *pd, float r_min[3], float r_max[3]) RET_NONE
void RE_point_density_sample(const struct EvaluationContext *eval_ctx, struct PointDensity *pd, const int resolution, float *values) RET_NONE
void RE_point_density_free(struct PointDensity *pd) RET_NONE
void RE_instance_get_particle_info(struct ObjectInstanceRen *obi, float *index, float *random, float *age, float *lifetime, float co[3], float *size, float vel[3], float angvel[3]) RET_NONE
void RE_FreeAllPersistentData(void) RET_NONE