Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
29 changed files with 301 additions and 186 deletions
Showing only changes of commit 91a17bd55b - Show all commits

View File

@ -1305,9 +1305,7 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
break;
}
}
# if OPENPGL_VERSION_MINOR >= 4
field_args.deterministic = guiding_params.deterministic;
# endif
reinterpret_cast<PGLKDTreeArguments *>(field_args.spatialSturctureArguments)->maxDepth = 16;
openpgl::cpp::Device *guiding_device = static_cast<openpgl::cpp::Device *>(
device_->get_guiding_device());
@ -1374,12 +1372,7 @@ void PathTrace::guiding_update_structures()
/* we wait until we have at least 1024 samples */
if (num_valid_samples >= 1024) {
# if OPENPGL_VERSION_MINOR < 4
const size_t num_samples = 1;
guiding_field_->Update(*guiding_sample_data_storage_, num_samples);
# else
guiding_field_->Update(*guiding_sample_data_storage_);
# endif
guiding_update_count++;
VLOG_DEBUG << "Path guiding field valid: " << guiding_field_->Validate();

View File

@ -358,12 +358,7 @@ void PathTraceWorkCPU::guiding_push_sample_data_to_global_storage(
# if PATH_GUIDING_LEVEL >= 2
const bool use_direct_light = kernel_data.integrator.use_guiding_direct_light;
const bool use_mis_weights = kernel_data.integrator.use_guiding_mis_weights;
# if OPENPGL_VERSION_MINOR >= 5
kg->opgl_path_segment_storage->PrepareSamples(use_mis_weights, use_direct_light, false);
# else
kg->opgl_path_segment_storage->PrepareSamples(
false, nullptr, use_mis_weights, use_direct_light, false);
# endif
# endif
# ifdef WITH_CYCLES_DEBUG

View File

@ -7,10 +7,6 @@
#include "kernel/closure/bsdf.h"
#include "kernel/film/write.h"
#if OPENPGL_VERSION_MINOR >= 5
# define RIS_INCOMING_RADIANCE
#endif
CCL_NAMESPACE_BEGIN
/* Utilities. */
@ -27,11 +23,7 @@ struct GuidingRISSample {
float ris_pdf{0.0f};
float ris_weight{0.0f};
#ifdef RIS_INCOMING_RADIANCE
float incoming_radiance_pdf{0.0f};
#else
float cosine{0.0f};
#endif
BsdfEval bsdf_eval;
float avg_bsdf_eval{0.0f};
Spectrum eval{zero_spectrum()};
@ -45,16 +37,9 @@ ccl_device_forceinline bool calculate_ris_target(ccl_private GuidingRISSample *r
if (ris_sample->avg_bsdf_eval > 0.0f && ris_sample->bsdf_pdf > 1e-10f &&
ris_sample->guide_pdf > 0.0f)
{
# ifdef RIS_INCOMING_RADIANCE
ris_sample->ris_target = (ris_sample->avg_bsdf_eval *
((((1.0f - guiding_sampling_prob) * (1.0f / (pi_factor * M_PI_F))) +
(guiding_sampling_prob * ris_sample->incoming_radiance_pdf))));
# else
ris_sample->ris_target = (ris_sample->avg_bsdf_eval / ris_sample->cosine *
((((1.0f - guiding_sampling_prob) * (1.0f / (pi_factor * M_PI_F))) +
(guiding_sampling_prob * ris_sample->guide_pdf))));
# endif
ris_sample->ris_pdf = (0.5f * (ris_sample->bsdf_pdf + ris_sample->guide_pdf));
ris_sample->ris_weight = ris_sample->ris_target / ris_sample->ris_pdf;
return true;
@ -511,14 +496,8 @@ ccl_device_forceinline bool guiding_bsdf_init(KernelGlobals kg,
ccl_private float &rand)
{
#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
# if OPENPGL_VERSION_MINOR >= 5
if (kg->opgl_surface_sampling_distribution->Init(
kg->opgl_guiding_field, guiding_point3f(P), rand)) {
# else
if (kg->opgl_surface_sampling_distribution->Init(
kg->opgl_guiding_field, guiding_point3f(P), rand, true))
{
# endif
kg->opgl_surface_sampling_distribution->ApplyCosineProduct(guiding_point3f(N));
return true;
}
@ -558,7 +537,7 @@ ccl_device_forceinline float guiding_surface_incoming_radiance_pdf(KernelGlobals
IntegratorState state,
const float3 wo)
{
#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4 && OPENPGL_VERSION_MINOR >= 5
#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
return kg->opgl_surface_sampling_distribution->IncomingRadiancePDF(guiding_vec3f(wo));
#else
return 0.0f;
@ -580,14 +559,8 @@ ccl_device_forceinline bool guiding_phase_init(KernelGlobals kg,
return false;
}
# if OPENPGL_VERSION_MINOR >= 5
if (kg->opgl_volume_sampling_distribution->Init(
kg->opgl_guiding_field, guiding_point3f(P), rand)) {
# else
if (kg->opgl_volume_sampling_distribution->Init(
kg->opgl_guiding_field, guiding_point3f(P), rand, true))
{
# endif
kg->opgl_volume_sampling_distribution->ApplySingleLobeHenyeyGreensteinProduct(guiding_vec3f(D),
g);
return true;

View File

@ -620,12 +620,7 @@ ccl_device_forceinline void volume_integrate_heterogeneous(
const Spectrum emission = volume_emission_integrate(
&coeff, closure_flag, transmittance, dt);
accum_emission += result.indirect_throughput * emission;
# if OPENPGL_VERSION_MINOR < 5 // WORKAROUND #104329
if (kernel_data.integrator.max_volume_bounce > 1)
# endif
{
guiding_record_volume_emission(kg, state, emission);
}
guiding_record_volume_emission(kg, state, emission);
}
}
@ -969,13 +964,9 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
const Spectrum phase_weight = bsdf_eval_sum(&phase_eval) / phase_pdf;
/* Add phase function sampling data to the path segment. */
# if OPENPGL_VERSION_MINOR < 5 // WORKAROUND #104329
if (kernel_data.integrator.max_volume_bounce > 1)
# endif
{
guiding_record_volume_bounce(
kg, state, sd, phase_weight, phase_pdf, normalize(phase_wo), sampled_roughness);
}
guiding_record_volume_bounce(
kg, state, sd, phase_weight, phase_pdf, normalize(phase_wo), sampled_roughness);
/* Update throughput. */
const Spectrum throughput = INTEGRATOR_STATE(state, path, throughput);
const Spectrum throughput_phase = throughput * phase_weight;
@ -1070,11 +1061,7 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg,
const float3 direct_P = ray->P + result.direct_t * ray->D;
# ifdef __PATH_GUIDING__
# if OPENPGL_VERSION_MINOR < 5 // WORKAROUND #104329
if (kernel_data.integrator.use_guiding && kernel_data.integrator.max_volume_bounce > 1) {
# else
if (kernel_data.integrator.use_guiding) {
# endif
# if PATH_GUIDING_LEVEL >= 1
if (result.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
/* If the direct scatter event is generated using VOLUME_SAMPLE_DISTANCE the direct event
@ -1147,12 +1134,7 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg,
# if defined(__PATH_GUIDING__)
# if PATH_GUIDING_LEVEL >= 1
if (!guiding_generated_new_segment) {
# if OPENPGL_VERSION_MINOR < 5 // WORKAROUND #104329
if (kernel_data.integrator.max_volume_bounce > 1)
# endif
{
guiding_record_volume_segment(kg, state, sd.P, sd.wi);
}
guiding_record_volume_segment(kg, state, sd.P, sd.wi);
}
# endif
# if PATH_GUIDING_LEVEL >= 4

View File

@ -670,12 +670,8 @@ ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg,
ris_samples[0].avg_bsdf_eval = average(ris_samples[0].bsdf_eval.sum);
ris_samples[0].guide_pdf = guiding_bsdf_pdf(kg, state, ris_samples[0].wo);
ris_samples[0].guide_pdf *= (1.0f - bssrdf_sampling_prob);
# ifdef RIS_INCOMING_RADIANCE
ris_samples[0].incoming_radiance_pdf = guiding_surface_incoming_radiance_pdf(
kg, state, ris_samples[0].wo);
# else
ris_samples[0].cosine = max(0.01f, fabsf(dot(sd->N, ris_samples[0].wo)));
# endif
ris_samples[0].bsdf_pdf = max(0.0f, ris_samples[0].bsdf_pdf);
}
@ -687,12 +683,8 @@ ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg,
ris_samples[1].guide_pdf = guiding_bsdf_sample(
kg, state, float3_to_float2(ris_samples[1].rand), &ris_samples[1].wo);
ris_samples[1].guide_pdf *= (1.0f - bssrdf_sampling_prob);
# ifdef RIS_INCOMING_RADIANCE
ris_samples[1].incoming_radiance_pdf = guiding_surface_incoming_radiance_pdf(
kg, state, ris_samples[1].wo);
# else
ris_samples[1].cosine = max(0.01f, fabsf(dot(sd->N, ris_samples[1].wo)));
# endif
ris_samples[1].bsdf_pdf = surface_shader_bsdf_eval_pdfs(
kg, sd, ris_samples[1].wo, &ris_samples[1].bsdf_eval, unguided_bsdf_pdfs, 0);
ris_samples[1].label = ris_samples[0].label;

View File

@ -18,11 +18,9 @@ static int guiding_device_type()
# if defined(__ARM_NEON)
return 8;
# else
# if OPENPGL_VERSION_MINOR >= 4
if (system_cpu_support_avx2()) {
return 8;
}
# endif
if (system_cpu_support_sse41()) {
return 4;
}

View File

@ -30,7 +30,17 @@
/* Set to 0 to allow devices that do not have the required features.
* This allows development on OSX until we really needs these features. */
#define STRICT_REQUIREMENTS 1
#define STRICT_REQUIREMENTS true
/*
* Should we only select surfaces that are known to be compatible. Or should we in case no
* compatible surfaces have been found select the first one.
*
* Currently we also select incompatible surfaces as Vulkan is still experimental. Assuming we get
* reports of color differences between OpenGL and Vulkan to narrow down if there are other
* configurations we need to support.
*/
#define SELECT_COMPATIBLE_SURFACES_ONLY false
using namespace std;
@ -796,6 +806,49 @@ GHOST_TSuccess GHOST_ContextVK::createGraphicsCommandBuffers()
return GHOST_kSuccess;
}
static bool surfaceFormatSupported(const VkSurfaceFormatKHR &surface_format)
{
if (surface_format.colorSpace != VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
return false;
}
if (surface_format.format == VK_FORMAT_R8G8B8A8_UNORM ||
surface_format.format == VK_FORMAT_B8G8R8A8_UNORM)
{
return true;
}
return false;
}
/**
* Select the surface format that we will use.
*
* We will select any 8bit unorm surface.
*/
static bool selectSurfaceFormat(const VkPhysicalDevice physical_device,
const VkSurfaceKHR surface,
VkSurfaceFormatKHR &r_surfaceFormat)
{
uint32_t format_count;
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, NULL);
vector<VkSurfaceFormatKHR> formats(format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, formats.data());
for (VkSurfaceFormatKHR &format : formats) {
if (surfaceFormatSupported(format)) {
r_surfaceFormat = format;
return true;
}
}
#if !SELECT_COMPATIBLE_SURFACES_ONLY
r_surfaceFormat = formats[0];
#endif
return false;
}
GHOST_TSuccess GHOST_ContextVK::createSwapchain()
{
assert(vulkan_device.has_value() && vulkan_device->device != VK_NULL_HANDLE);
@ -803,13 +856,14 @@ GHOST_TSuccess GHOST_ContextVK::createSwapchain()
VkPhysicalDevice physical_device = vulkan_device->physical_device;
uint32_t format_count;
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, m_surface, &format_count, NULL);
vector<VkSurfaceFormatKHR> formats(format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, m_surface, &format_count, formats.data());
/* TODO choose appropriate format. */
VkSurfaceFormatKHR format = formats[0];
VkSurfaceFormatKHR format = {};
#if SELECT_COMPATIBLE_SURFACES_ONLY
if (!selectSurfaceFormat(physical_device, m_surface, format)) {
return GHOST_kFailure;
}
#else
selectSurfaceFormat(physical_device, m_surface, format);
#endif
VkPresentModeKHR present_mode;
if (!selectPresentMode(physical_device, m_surface, &present_mode)) {
@ -1066,9 +1120,7 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
/* According to the Vulkan specs, when `VK_KHR_portability_subset` is available it should be
* enabled. See
* https://vulkan.lunarg.com/doc/view/1.2.198.1/mac/1.2-extensions/vkspec.html#VUID-VkDeviceCreateInfo-pProperties-04451*/
if (device_extensions_support(vulkan_device->physical_device,
{VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME}))
{
if (vulkan_device->extensions_support({VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME})) {
extensions_device.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME);
}
#endif

View File

@ -1402,7 +1402,7 @@ bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Objec
BKE_main_collection_sync(bmain);
}
DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY);
DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY | ID_RECALC_HIERARCHY);
return true;
}
@ -1470,7 +1470,7 @@ bool BKE_collection_object_remove(Main *bmain,
BKE_main_collection_sync(bmain);
}
DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY);
DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY | ID_RECALC_HIERARCHY);
return true;
}

View File

@ -86,7 +86,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator {
}
/* This is ignored since we query using our own GPU capabilities system. */
void setTextureMaxWidth(unsigned max_width) override {}
void setTextureMaxWidth(unsigned /*max_width*/) override {}
unsigned getTextureMaxWidth() const noexcept override
{
@ -255,7 +255,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator {
/* This gets called before the finalize() method to construct the shader code. We just
* concatenate the code except for the declarations section. That's because the ShaderCreateInfo
* will add the declaration itself. */
void createShaderText(const char *declarations,
void createShaderText(const char * /*declarations*/,
const char *helper_methods,
const char *function_header,
const char *function_body,

View File

@ -132,7 +132,6 @@ DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain,
scene_(nullptr),
view_layer_(nullptr),
view_layer_index_(-1),
collection_(nullptr),
is_parent_collection_visible_(true)
{
}
@ -325,6 +324,13 @@ bool DepsgraphNodeBuilder::has_operation_node(ID *id,
return find_operation_node(id, comp_type, comp_name, opcode, name, name_tag) != nullptr;
}
bool DepsgraphNodeBuilder::has_operation_node(ID *id,
const NodeType comp_type,
const OperationCode opcode)
{
return find_operation_node(id, comp_type, opcode) != nullptr;
}
OperationNode *DepsgraphNodeBuilder::find_operation_node(const ID *id,
NodeType comp_type,
const char *comp_name,
@ -704,7 +710,10 @@ void DepsgraphNodeBuilder::build_collection(LayerCollection *from_layer_collecti
id_node = add_id_node(&collection->id);
id_node->is_visible_on_build = is_collection_visible;
add_operation_node(&collection->id, NodeType::HIERARCHY, OperationCode::HIERARCHY);
build_idproperties(collection->id.properties);
build_parameters(&collection->id);
add_operation_node(&collection->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE);
}
if (from_layer_collection != nullptr) {
@ -713,10 +722,8 @@ void DepsgraphNodeBuilder::build_collection(LayerCollection *from_layer_collecti
return;
}
/* Backup state. */
Collection *current_state_collection = collection_;
const bool is_current_parent_collection_visible = is_parent_collection_visible_;
/* Modify state as we've entered new collection/ */
collection_ = collection;
is_parent_collection_visible_ = is_collection_visible;
/* Build collection objects. */
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
@ -727,7 +734,6 @@ void DepsgraphNodeBuilder::build_collection(LayerCollection *from_layer_collecti
build_collection(nullptr, child->collection);
}
/* Restore state. */
collection_ = current_state_collection;
is_parent_collection_visible_ = is_current_parent_collection_visible;
id_node->is_collection_fully_expanded = true;
}
@ -774,6 +780,9 @@ void DepsgraphNodeBuilder::build_object(int base_index,
id_node->is_visible_on_build = is_visible;
}
id_node->has_base |= (base_index != -1);
add_operation_node(&object->id, NodeType::HIERARCHY, OperationCode::HIERARCHY);
/* Various flags, flushing from bases/collections. */
build_object_from_layer(base_index, object, linked_state);
/* Transform. */
@ -824,6 +833,7 @@ void DepsgraphNodeBuilder::build_object(int base_index,
{
build_texture(object->pd->tex);
}
/* Object dupligroup. */
if (object->instance_collection != nullptr) {
build_object_instance_collection(object, is_visible);
@ -831,6 +841,7 @@ void DepsgraphNodeBuilder::build_object(int base_index,
&object->id, NodeType::DUPLI, OperationCode::DUPLI);
op_node->flag |= OperationFlag::DEPSOP_FLAG_PINNED;
}
/* Synchronization back to original object. */
add_operation_node(&object->id,
NodeType::SYNCHRONIZATION,

View File

@ -139,6 +139,7 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
OperationCode opcode,
const char *name = "",
int name_tag = -1);
bool has_operation_node(ID *id, NodeType comp_type, OperationCode opcode);
OperationNode *find_operation_node(const ID *id,
NodeType comp_type,
@ -193,6 +194,7 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
virtual void build_object_transform(Object *object);
virtual void build_object_constraints(Object *object);
virtual void build_object_pointcache(Object *object);
virtual void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
virtual void build_rigidbody(Scene *scene);
virtual void build_particle_systems(Object *object, bool is_object_visible);
@ -307,7 +309,6 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
int view_layer_index_;
/* NOTE: Collection are possibly built recursively, so be careful when
* setting the current state. */
Collection *collection_;
/* Accumulated flag over the hierarchy of currently building collections.
* Denotes whether all the hierarchy from parent of `collection_` to the
* very root is visible (aka not restricted.). */

View File

@ -78,6 +78,9 @@ void DepsgraphNodeBuilder::build_view_layer(Scene *scene,
/* Scene ID block. */
IDNode *id_node = add_id_node(&scene->id);
id_node->linked_state = linked_state;
add_operation_node(&scene->id, NodeType::HIERARCHY, OperationCode::HIERARCHY);
/* Time source. */
add_time_source();
/* Setup currently building context. */

View File

@ -282,6 +282,15 @@ Node *DepsgraphRelationBuilder::get_node(const RNAPathKey &key)
return rna_node_query_.find_node(&key.ptr, key.prop, key.source);
}
ComponentNode *DepsgraphRelationBuilder::find_node(const ComponentKey &key) const
{
IDNode *id_node = graph_->find_id_node(key.id);
if (!id_node) {
return nullptr;
}
return id_node->find_component(key.type, key.name);
}
OperationNode *DepsgraphRelationBuilder::find_node(const OperationKey &key) const
{
IDNode *id_node = graph_->find_id_node(key.id);
@ -300,6 +309,11 @@ bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const
return find_node(key) != nullptr;
}
bool DepsgraphRelationBuilder::has_node(const ComponentKey &key) const
{
return find_node(key) != nullptr;
}
void DepsgraphRelationBuilder::add_depends_on_transform_relation(const DepsNodeHandle *handle,
const char *description)
{
@ -504,7 +518,7 @@ void DepsgraphRelationBuilder::build_id(ID *id)
build_camera((Camera *)id);
break;
case ID_GR:
build_collection(nullptr, nullptr, (Collection *)id);
build_collection(nullptr, (Collection *)id);
break;
case ID_OB:
build_object((Object *)id);
@ -616,76 +630,85 @@ void DepsgraphRelationBuilder::build_idproperties(IDProperty *id_property)
}
void DepsgraphRelationBuilder::build_collection(LayerCollection *from_layer_collection,
Object *object,
Collection *collection)
{
const ComponentKey collection_hierarchy_key{&collection->id, NodeType::HIERARCHY};
if (from_layer_collection != nullptr) {
/* If we came from layer collection we don't go deeper, view layer
* builder takes care of going deeper.
/* If we came from layer collection we don't go deeper, view layer builder takes care of going
* deeper.
*
* NOTE: Do early output before tagging build as done, so possible
* subsequent builds from outside of the layer collection properly
* recurses into all the nested objects and collections. */
* NOTE: Do early output before tagging build as done, so possible subsequent builds from
* outside of the layer collection properly recurses into all the nested objects and
* collections. */
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
Object *object = cob->ob;
/* Ensure that the hierarchy relations always exists, even for the layer collection.
*
* Note that the view layer builder can skip bases if they are constantly excluded from the
* collections. In order to avoid noisy output check that the target node exists before
* adding the relation. */
const ComponentKey object_hierarchy_key{&object->id, NodeType::HIERARCHY};
if (has_node(object_hierarchy_key)) {
add_relation(collection_hierarchy_key,
object_hierarchy_key,
"Collection -> Object hierarchy",
RELATION_CHECK_BEFORE_ADD);
}
}
return;
}
if (built_map_.checkIsBuiltAndTag(collection)) {
return;
}
build_idproperties(collection->id.properties);
build_parameters(&collection->id);
const BuilderStack::ScopedEntry stack_entry = stack_.trace(collection->id);
const bool group_done = built_map_.checkIsBuiltAndTag(collection);
OperationKey object_transform_final_key(object != nullptr ? &object->id : nullptr,
NodeType::TRANSFORM,
OperationCode::TRANSFORM_FINAL);
ComponentKey duplicator_key(object != nullptr ? &object->id : nullptr, NodeType::DUPLI);
if (!group_done) {
build_idproperties(collection->id.properties);
OperationKey collection_geometry_key{
&collection->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
build_object(cob->ob);
const OperationKey collection_geometry_key{
&collection->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
/* The geometry of a collection depends on the positions of the elements in it. */
OperationKey object_transform_key{
&cob->ob->id, NodeType::TRANSFORM, OperationCode::TRANSFORM_FINAL};
add_relation(object_transform_key, collection_geometry_key, "Collection Geometry");
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
Object *object = cob->ob;
/* Only create geometry relations to child objects, if they have a geometry component. */
OperationKey object_geometry_key{
&cob->ob->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL};
if (find_node(object_geometry_key) != nullptr) {
add_relation(object_geometry_key, collection_geometry_key, "Collection Geometry");
}
build_object(object);
/* An instance is part of the geometry of the collection. */
if (cob->ob->type == OB_EMPTY) {
Collection *collection_instance = cob->ob->instance_collection;
if (collection_instance != nullptr) {
OperationKey collection_instance_key{
&collection_instance->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
add_relation(collection_instance_key, collection_geometry_key, "Collection Geometry");
}
}
const ComponentKey object_hierarchy_key{&object->id, NodeType::HIERARCHY};
add_relation(collection_hierarchy_key, object_hierarchy_key, "Collection -> Object hierarchy");
/* The geometry of a collection depends on the positions of the elements in it. */
const OperationKey object_transform_key{
&object->id, NodeType::TRANSFORM, OperationCode::TRANSFORM_FINAL};
add_relation(object_transform_key, collection_geometry_key, "Collection Geometry");
/* Only create geometry relations to child objects, if they have a geometry component. */
const OperationKey object_geometry_key{
&object->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL};
if (find_node(object_geometry_key) != nullptr) {
add_relation(object_geometry_key, collection_geometry_key, "Collection Geometry");
}
LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
build_collection(nullptr, nullptr, child->collection);
OperationKey child_collection_geometry_key{
&child->collection->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
add_relation(child_collection_geometry_key, collection_geometry_key, "Collection Geometry");
/* An instance is part of the geometry of the collection. */
if (object->type == OB_EMPTY) {
Collection *collection_instance = cob->ob->instance_collection;
if (collection_instance != nullptr) {
const OperationKey collection_instance_key{
&collection_instance->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
add_relation(collection_instance_key, collection_geometry_key, "Collection Geometry");
}
}
}
if (object != nullptr) {
FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (collection, ob, graph_->mode) {
ComponentKey dupli_transform_key(&ob->id, NodeType::TRANSFORM);
add_relation(dupli_transform_key, object_transform_final_key, "Dupligroup");
/* Hook to special component, to ensure proper visibility/evaluation
* optimizations. */
add_relation(dupli_transform_key, duplicator_key, "Dupligroup");
const NodeType dupli_geometry_component_type = geometry_tag_to_component(&ob->id);
if (dupli_geometry_component_type != NodeType::UNDEFINED) {
ComponentKey dupli_geometry_component_key(&ob->id, dupli_geometry_component_type);
add_relation(dupli_geometry_component_key, duplicator_key, "Dupligroup");
}
}
FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END;
LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
build_collection(nullptr, child->collection);
const OperationKey child_collection_geometry_key{
&child->collection->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL_DONE};
add_relation(child_collection_geometry_key, collection_geometry_key, "Collection Geometry");
}
}
@ -797,12 +820,7 @@ void DepsgraphRelationBuilder::build_object(Object *object)
build_texture(object->pd->tex);
}
/* Object dupligroup. */
if (object->instance_collection != nullptr) {
build_collection(nullptr, object, object->instance_collection);
}
/* Point caches. */
build_object_instance_collection(object);
build_object_pointcache(object);
/* Synchronization back to original object. */
@ -1212,6 +1230,35 @@ void DepsgraphRelationBuilder::build_object_pointcache(Object *object)
BLI_freelistN(&ptcache_id_list);
}
void DepsgraphRelationBuilder::build_object_instance_collection(Object *object)
{
if (object->instance_collection == nullptr) {
return;
}
Collection *instance_collection = object->instance_collection;
build_collection(nullptr, instance_collection);
const OperationKey object_transform_final_key(
&object->id, NodeType::TRANSFORM, OperationCode::TRANSFORM_FINAL);
const ComponentKey duplicator_key(&object->id, NodeType::DUPLI);
FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (instance_collection, ob, graph_->mode) {
const ComponentKey dupli_transform_key(&ob->id, NodeType::TRANSFORM);
add_relation(dupli_transform_key, object_transform_final_key, "Dupligroup");
/* Hook to special component, to ensure proper visibility/evaluation optimizations. */
add_relation(dupli_transform_key, duplicator_key, "Dupligroup");
const NodeType dupli_geometry_component_type = geometry_tag_to_component(&ob->id);
if (dupli_geometry_component_type != NodeType::UNDEFINED) {
ComponentKey dupli_geometry_component_key(&ob->id, dupli_geometry_component_type);
add_relation(dupli_geometry_component_key, duplicator_key, "Dupligroup");
}
}
FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END;
}
void DepsgraphRelationBuilder::build_constraints(ID *id,
NodeType component_type,
const char *component_subdata,
@ -2014,7 +2061,7 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
}
/* Objects. */
if (rbw->group != nullptr) {
build_collection(nullptr, nullptr, rbw->group);
build_collection(nullptr, rbw->group);
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, object) {
if (object->type != OB_MESH) {
continue;
@ -2170,7 +2217,7 @@ void DepsgraphRelationBuilder::build_particle_systems(Object *object)
break;
case PART_DRAW_GR:
if (part->instance_collection != nullptr) {
build_collection(nullptr, nullptr, part->instance_collection);
build_collection(nullptr, part->instance_collection);
LISTBASE_FOREACH (CollectionObject *, go, &part->instance_collection->gobject) {
build_particle_system_visualization_object(object, psys, go->ob);
}
@ -2636,7 +2683,7 @@ void DepsgraphRelationBuilder::build_nodetree_socket(bNodeSocket *socket)
else if (socket->type == SOCK_COLLECTION) {
Collection *collection = ((bNodeSocketValueCollection *)socket->default_value)->value;
if (collection != nullptr) {
build_collection(nullptr, nullptr, collection);
build_collection(nullptr, collection);
}
}
else if (socket->type == SOCK_TEXTURE) {
@ -3252,6 +3299,11 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node)
if (ELEM(comp_node->type, NodeType::PARAMETERS, NodeType::LAYER_COLLECTIONS)) {
rel_flag &= ~RELATION_FLAG_NO_FLUSH;
}
/* Compatibility with the legacy tagging: groups are only tagged for Copy-on-Write when their
* hierarchy changes, and it needs to be flushed downstream. */
if (id_type == ID_GR && comp_node->type == NodeType::HIERARCHY) {
rel_flag &= ~RELATION_FLAG_NO_FLUSH;
}
/* All entry operations of each component should wait for a proper
* copy of ID. */
OperationNode *op_entry = comp_node->get_entry_operation();

View File

@ -129,13 +129,13 @@ class DepsgraphRelationBuilder : public DepsgraphBuilder {
virtual void build_scene_parameters(Scene *scene);
virtual void build_scene_compositor(Scene *scene);
virtual void build_layer_collections(ListBase *lb);
virtual bool build_layer_collection(LayerCollection *layer_collection);
virtual void build_view_layer_collections(ViewLayer *view_layer);
virtual void build_view_layer(Scene *scene,
ViewLayer *view_layer,
eDepsNode_LinkedState_Type linked_state);
virtual void build_collection(LayerCollection *from_layer_collection,
Object *object,
Collection *collection);
virtual void build_collection(LayerCollection *from_layer_collection, Collection *collection);
virtual void build_object(Object *object);
virtual void build_object_from_view_layer_base(Object *object);
virtual void build_object_layer_component_relations(Object *object);
@ -149,6 +149,8 @@ class DepsgraphRelationBuilder : public DepsgraphBuilder {
virtual void build_object_data_speaker(Object *object);
virtual void build_object_parent(Object *object);
virtual void build_object_pointcache(Object *object);
virtual void build_object_instance_collection(Object *object);
virtual void build_constraints(ID *id,
NodeType component_type,
const char *component_subdata,
@ -263,6 +265,8 @@ class DepsgraphRelationBuilder : public DepsgraphBuilder {
Node *get_node(const RNAPathKey &key);
OperationNode *find_node(const OperationKey &key) const;
ComponentNode *find_node(const ComponentKey &key) const;
bool has_node(const ComponentKey &key) const;
bool has_node(const OperationKey &key) const;
Relation *add_time_relation(TimeSourceNode *timesrc,

View File

@ -43,26 +43,55 @@
namespace blender::deg {
void DepsgraphRelationBuilder::build_layer_collections(ListBase *lb)
bool DepsgraphRelationBuilder::build_layer_collection(LayerCollection *layer_collection)
{
const int visibility_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? COLLECTION_HIDE_VIEWPORT :
COLLECTION_HIDE_RENDER;
const int hide_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? COLLECTION_HIDE_VIEWPORT :
COLLECTION_HIDE_RENDER;
for (LayerCollection *lc = (LayerCollection *)lb->first; lc; lc = lc->next) {
if (lc->collection->flag & visibility_flag) {
continue;
Collection *collection = layer_collection->collection;
const bool is_collection_hidden = collection->flag & hide_flag;
const bool is_layer_collection_excluded = layer_collection->flag & LAYER_COLLECTION_EXCLUDE;
if (is_collection_hidden || is_layer_collection_excluded) {
return false;
}
build_collection(layer_collection, collection);
const ComponentKey collection_hierarchy_key{&collection->id, NodeType::HIERARCHY};
LISTBASE_FOREACH (
LayerCollection *, child_layer_collection, &layer_collection->layer_collections) {
if (build_layer_collection(child_layer_collection)) {
Collection *child_collection = child_layer_collection->collection;
const ComponentKey child_collection_hierarchy_key{&child_collection->id,
NodeType::HIERARCHY};
add_relation(
collection_hierarchy_key, child_collection_hierarchy_key, "Collection hierarchy");
}
if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
build_collection(lc, nullptr, lc->collection);
}
return true;
}
void DepsgraphRelationBuilder::build_view_layer_collections(ViewLayer *view_layer)
{
const ComponentKey scene_hierarchy_key{&scene_->id, NodeType::HIERARCHY};
LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) {
if (build_layer_collection(layer_collection)) {
Collection *collection = layer_collection->collection;
const ComponentKey collection_hierarchy_key{&collection->id, NodeType::HIERARCHY};
add_relation(scene_hierarchy_key, collection_hierarchy_key, "Scene -> Collection hierarchy");
}
build_layer_collections(&lc->layer_collections);
}
}
void DepsgraphRelationBuilder::build_freestyle_lineset(FreestyleLineSet *fls)
{
if (fls->group != nullptr) {
build_collection(nullptr, nullptr, fls->group);
build_collection(nullptr, fls->group);
}
if (fls->linestyle != nullptr) {
build_freestyle_linestyle(fls->linestyle);
@ -86,7 +115,7 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene,
}
}
build_layer_collections(&view_layer->layer_collections);
build_view_layer_collections(view_layer);
if (scene->camera != nullptr) {
build_object(scene->camera);

View File

@ -400,6 +400,7 @@ static void deg_debug_graphviz_node(DotExportContext &ctx,
case NodeType::PARTICLE_SETTINGS:
case NodeType::COPY_ON_WRITE:
case NodeType::OBJECT_FROM_LAYER:
case NodeType::HIERARCHY:
case NodeType::BATCH_CACHE:
case NodeType::DUPLI:
case NodeType::SYNCHRONIZATION:

View File

@ -217,7 +217,11 @@ void depsgraph_tag_to_component_opcode(const ID *id,
*operation_code = OperationCode::NTREE_OUTPUT;
break;
case ID_RECALC_PROVISION_26:
case ID_RECALC_HIERARCHY:
*component_type = NodeType::HIERARCHY;
*operation_code = OperationCode::HIERARCHY;
break;
case ID_RECALC_PROVISION_27:
case ID_RECALC_PROVISION_28:
case ID_RECALC_PROVISION_29:
@ -752,7 +756,9 @@ const char *DEG_update_tag_as_string(IDRecalcFlag flag)
case ID_RECALC_NTREE_OUTPUT:
return "ID_RECALC_NTREE_OUTPUT";
case ID_RECALC_PROVISION_26:
case ID_RECALC_HIERARCHY:
return "ID_RECALC_HIERARCHY";
case ID_RECALC_PROVISION_27:
case ID_RECALC_PROVISION_28:
case ID_RECALC_PROVISION_29:

View File

@ -124,6 +124,7 @@ void ObjectRuntimeBackup::restore_to_object(Object *object)
object->base_flag = base_flag;
object->base_local_view_bits = base_local_view_bits;
/* Restore modifier's runtime data.
* NOTE: Data of unused modifiers will be freed there. */
restore_modifier_runtime_data(object);

View File

@ -65,6 +65,8 @@ const char *nodeTypeAsString(NodeType type)
return "COPY_ON_WRITE";
case NodeType::OBJECT_FROM_LAYER:
return "OBJECT_FROM_LAYER";
case NodeType::HIERARCHY:
return "HIERARCHY";
/* **** Evaluation-Related Outer Types (with Subdata) **** */
case NodeType::EVAL_POSE:
return "EVAL_POSE";
@ -140,6 +142,7 @@ eDepsSceneComponentType nodeTypeToSceneComponent(NodeType type)
case NodeType::LAYER_COLLECTIONS:
case NodeType::COPY_ON_WRITE:
case NodeType::OBJECT_FROM_LAYER:
case NodeType::HIERARCHY:
case NodeType::AUDIO:
case NodeType::ARMATURE:
case NodeType::GENERIC_DATABLOCK:
@ -223,6 +226,7 @@ eDepsObjectComponentType nodeTypeToObjectComponent(NodeType type)
case NodeType::LAYER_COLLECTIONS:
case NodeType::COPY_ON_WRITE:
case NodeType::OBJECT_FROM_LAYER:
case NodeType::HIERARCHY:
case NodeType::AUDIO:
case NodeType::ARMATURE:
case NodeType::GENERIC_DATABLOCK:

View File

@ -77,6 +77,8 @@ enum class NodeType {
/* Used by all operations which are updating object when something is
* changed in view layer. */
OBJECT_FROM_LAYER,
/* Hierarchy of objects and collections */
HIERARCHY,
/* Audio-related evaluation. */
AUDIO,
ARMATURE,

View File

@ -331,6 +331,7 @@ DEG_COMPONENT_NODE_DEFINE(Sequencer, SEQUENCER, 0);
DEG_COMPONENT_NODE_DEFINE(Shading, SHADING, ID_RECALC_SHADING);
DEG_COMPONENT_NODE_DEFINE(Transform, TRANSFORM, ID_RECALC_TRANSFORM);
DEG_COMPONENT_NODE_DEFINE(ObjectFromLayer, OBJECT_FROM_LAYER, 0);
DEG_COMPONENT_NODE_DEFINE(Hierarchy, HIERARCHY, 0);
DEG_COMPONENT_NODE_DEFINE(Dupli, DUPLI, 0);
DEG_COMPONENT_NODE_DEFINE(Synchronization, SYNCHRONIZATION, 0);
DEG_COMPONENT_NODE_DEFINE(Audio, AUDIO, 0);
@ -366,6 +367,7 @@ void deg_register_component_depsnodes()
register_node_typeinfo(&DNTI_SHADING);
register_node_typeinfo(&DNTI_TRANSFORM);
register_node_typeinfo(&DNTI_OBJECT_FROM_LAYER);
register_node_typeinfo(&DNTI_HIERARCHY);
register_node_typeinfo(&DNTI_DUPLI);
register_node_typeinfo(&DNTI_SYNCHRONIZATION);
register_node_typeinfo(&DNTI_AUDIO);

View File

@ -200,6 +200,7 @@ DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(Shading);
DEG_COMPONENT_NODE_DECLARE_GENERIC(ShadingParameters);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Transform);
DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(ObjectFromLayer);
DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(Hierarchy);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Dupli);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Synchronization);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Audio);

View File

@ -152,6 +152,7 @@ ComponentNode *IDNode::add_component(NodeType type, const char *name)
ComponentNode *comp_node = find_component(type, name);
if (!comp_node) {
DepsNodeFactory *factory = type_get_factory(type);
BLI_assert(factory);
comp_node = (ComponentNode *)factory->create_node(this->id_orig, "", name);
/* Register. */

View File

@ -34,6 +34,9 @@ const char *operationCodeAsString(OperationCode opcode)
return "PARAMETERS_EXIT";
case OperationCode::VISIBILITY:
return "VISIBILITY";
/* Hierarchy. */
case OperationCode::HIERARCHY:
return "HIERARCHY";
/* Animation, Drivers, etc. */
case OperationCode::ANIMATION_ENTRY:
return "ANIMATION_ENTRY";

View File

@ -28,13 +28,16 @@ enum class OperationCode {
/* Placeholder for operations which don't need special mention */
OPERATION = 0,
/* Generic parameters evaluation. */
/* Generic parameters evaluation. --------------------------------------- */
ID_PROPERTY,
PARAMETERS_ENTRY,
PARAMETERS_EVAL,
PARAMETERS_EXIT,
VISIBILITY,
/* Hierarchy. ----------------------------------------------------------- */
HIERARCHY,
/* Animation, Drivers, etc. --------------------------------------------- */
/* NLA + Action */
ANIMATION_ENTRY,

View File

@ -355,7 +355,7 @@ enum eVelocityStep : uint32_t {
struct VelocityObjectIndex {
/** Offset inside #VelocityObjectBuf for each timestep. Indexed using eVelocityStep. */
int3 ofs;
packed_int3 ofs;
/** Temporary index to copy this to the #VelocityIndexBuf. */
uint resource_id;
@ -367,11 +367,11 @@ BLI_STATIC_ASSERT_ALIGN(VelocityObjectIndex, 16)
struct VelocityGeometryIndex {
/** Offset inside #VelocityGeometryBuf for each timestep. Indexed using eVelocityStep. */
int3 ofs;
packed_int3 ofs;
/** If true, compute deformation motion blur. */
bool1 do_deform;
/** Length of data inside #VelocityGeometryBuf for each timestep. Indexed using eVelocityStep. */
int3 len;
packed_int3 len;
int _pad0;

View File

@ -396,14 +396,14 @@ static void unlink_collection_fn(bContext *C,
if (GS(tsep->id->name) == ID_OB) {
Object *ob = (Object *)tsep->id;
ob->instance_collection = nullptr;
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
}
else if (GS(tsep->id->name) == ID_GR) {
Collection *parent = (Collection *)tsep->id;
id_fake_user_set(&collection->id);
BKE_collection_child_remove(bmain, parent, collection);
DEG_id_tag_update(&parent->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&parent->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
}
else if (GS(tsep->id->name) == ID_SCE) {
@ -411,7 +411,7 @@ static void unlink_collection_fn(bContext *C,
Collection *parent = scene->master_collection;
id_fake_user_set(&collection->id);
BKE_collection_child_remove(bmain, parent, collection);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
}
}
@ -458,14 +458,15 @@ static void unlink_object_fn(bContext *C,
if (GS(tsep->id->name) == ID_GR) {
Collection *parent = (Collection *)tsep->id;
BKE_collection_object_remove(bmain, parent, ob, true);
DEG_id_tag_update(&parent->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&parent->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_HIERARCHY);
DEG_id_tag_update(&ob->id, ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
}
else if (GS(tsep->id->name) == ID_SCE) {
Scene *scene = (Scene *)tsep->id;
Collection *parent = scene->master_collection;
BKE_collection_object_remove(bmain, parent, ob, true);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
}
}
@ -2558,7 +2559,7 @@ static int outliner_delete_exec(bContext *C, wmOperator *op)
* cleanup tree here to prevent such cases. */
outliner_cleanup_tree(space_outliner);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
BKE_view_layer_synced_ensure(scene, view_layer);

View File

@ -60,6 +60,7 @@
# define bool3 bvec3
# define bool4 bvec4
# define packed_float3 vec3
# define packed_int3 int3
# endif
#else /* C / C++ */
@ -85,6 +86,7 @@ using bool2 = blender::int2;
using bool3 = blender::int3;
using bool4 = blender::int4;
using packed_float3 = blender::float3;
using packed_int3 = blender::int3;
# else /* C */
typedef float float2[2];
@ -102,6 +104,7 @@ typedef int bool2[2];
typedef int bool3[2];
typedef int bool4[4];
typedef float3 packed_float3;
typedef int3 packed_int3;
# endif
#endif

View File

@ -1071,11 +1071,13 @@ typedef enum IDRecalcFlag {
/* The node tree has changed in a way that affects its output nodes. */
ID_RECALC_NTREE_OUTPUT = (1 << 25),
/* Hierarchy of collection and object within collection changed. */
ID_RECALC_HIERARCHY = (1 << 26),
/* Provisioned flags.
*
* Not for actual use. The idea of them is to have all bits of the `IDRecalcFlag` defined to a
* known value, silencing sanitizer warnings when checking bits of the ID_RECALC_ALL. */
ID_RECALC_PROVISION_26 = (1 << 26),
ID_RECALC_PROVISION_27 = (1 << 27),
ID_RECALC_PROVISION_28 = (1 << 28),
ID_RECALC_PROVISION_29 = (1 << 29),