[Bf-blender-cvs] [81a5170d707] cycles_procedural_api: cleanup and fixes for crashes when interacting in the viewport
Kévin Dietrich
noreply at git.blender.org
Mon Nov 16 13:11:29 CET 2020
Commit: 81a5170d707ccae8e77a4b94f1e61872d65afc34
Author: Kévin Dietrich
Date: Thu Nov 12 12:27:07 2020 +0100
Branches: cycles_procedural_api
https://developer.blender.org/rB81a5170d707ccae8e77a4b94f1e61872d65afc34
cleanup and fixes for crashes when interacting in the viewport
===================================================================
M intern/cycles/blender/blender_curves.cpp
M intern/cycles/blender/blender_mesh.cpp
M intern/cycles/bvh/bvh.h
M intern/cycles/bvh/bvh_optix.cpp
M intern/cycles/bvh/bvh_optix.h
M intern/cycles/bvh/bvh_params.h
M intern/cycles/device/device_optix.cpp
M intern/cycles/render/attribute.cpp
M intern/cycles/render/attribute.h
M intern/cycles/render/geometry.cpp
M intern/cycles/render/geometry.h
M intern/cycles/render/mesh.cpp
M intern/cycles/render/object.cpp
===================================================================
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 2f0ffb3d16f..eb469674cdb 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -855,19 +855,7 @@ void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *ha
hair->set_value(socket, new_hair, socket);
}
- hair->attributes.clear();
- foreach (Attribute &attr, new_hair.attributes.attributes) {
- Attribute *nattr = nullptr;
-
- if (attr.std != ATTR_STD_NONE) {
- nattr = hair->attributes.add(attr.std, attr.name);
- }
- else {
- nattr = hair->attributes.add(attr.name, attr.type, attr.element);
- }
-
- nattr->set_data_from(attr);
- }
+ hair->attributes.update(new_hair.attributes);
/* tag update */
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index c477a7f82be..b4fba48b5ac 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1073,33 +1073,8 @@ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *me
mesh->set_value(socket, new_mesh, socket);
}
- mesh->attributes.clear();
- foreach (Attribute &attr, new_mesh.attributes.attributes) {
- Attribute *nattr = nullptr;
-
- if (attr.std != ATTR_STD_NONE) {
- nattr = mesh->attributes.add(attr.std, attr.name);
- }
- else {
- nattr = mesh->attributes.add(attr.name, attr.type, attr.element);
- }
-
- nattr->set_data_from(attr);
- }
-
- mesh->subd_attributes.clear();
- foreach (Attribute &attr, new_mesh.subd_attributes.attributes) {
- Attribute *nattr = nullptr;
-
- if (attr.std != ATTR_STD_NONE) {
- nattr = mesh->subd_attributes.add(attr.std, attr.name);
- }
- else {
- nattr = mesh->subd_attributes.add(attr.name, attr.type, attr.element);
- }
-
- nattr->set_data_from(attr);
- }
+ mesh->attributes.update(new_mesh.attributes);
+ mesh->subd_attributes.update(new_mesh.subd_attributes);
mesh->set_num_subd_faces(new_mesh.get_num_subd_faces());
diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h
index 7430ae45494..57fbe05f8dd 100644
--- a/intern/cycles/bvh/bvh.h
+++ b/intern/cycles/bvh/bvh.h
@@ -87,8 +87,6 @@ class BVH {
vector<Geometry *> geometry;
vector<Object *> objects;
- device_ptr prim_vert_pointer;
- size_t pack_verts_offset;
int num_refits;
static BVH *create(const BVHParams ¶ms,
diff --git a/intern/cycles/bvh/bvh_optix.cpp b/intern/cycles/bvh/bvh_optix.cpp
index f456906bd31..b5c7695516c 100644
--- a/intern/cycles/bvh/bvh_optix.cpp
+++ b/intern/cycles/bvh/bvh_optix.cpp
@@ -162,14 +162,16 @@ void BVHOptiX::pack_tlas()
foreach (Geometry *geom, geometry) {
PackedBVH &bvh_pack = geom->bvh->pack;
- geom->bvh->pack_verts_offset = pack_verts_offset;
-
// Merge visibility flags of all objects and fix object indices for non-instanced geometry
int object_index = 0; // Unused for instanced geometry
int object_visibility = 0;
+ bool visibility_modified = false;
foreach (Object *ob, objects) {
if (ob->get_geometry() == geom) {
object_visibility |= ob->visibility_for_tracing();
+ visibility_modified |= ob->visibility_is_modified();
+ visibility_modified |= ob->is_shadow_catcher_is_modified();
+
if (!geom->is_instanced()) {
object_index = ob->get_device_index();
break;
@@ -177,14 +179,16 @@ void BVHOptiX::pack_tlas()
}
}
- if (geom->is_modified()) {
+ if (geom->is_modified() || params.pack_all_data) {
pool.push(function_bind(&BVHOptiX::pack_instance,
this,
geom,
pack_offset,
pack_verts_offset,
object_index,
- object_visibility));
+ object_visibility,
+ params.pack_all_data,
+ visibility_modified));
}
if (!bvh_pack.prim_index.empty()) {
@@ -203,7 +207,9 @@ void BVHOptiX::pack_instance(Geometry *geom,
size_t pack_offset,
size_t pack_verts_offset_,
int object_index,
- int object_visibility)
+ int object_visibility,
+ bool force_pack,
+ bool visibility_modified)
{
int *pack_prim_type = pack.prim_type.data();
int *pack_prim_index = pack.prim_index.data();
@@ -222,16 +228,19 @@ void BVHOptiX::pack_instance(Geometry *geom,
uint *bvh_prim_tri_index = &bvh_pack.prim_tri_index[0];
uint *bvh_prim_visibility = &bvh_pack.prim_visibility[0];
+ /* default to true for volumes and curves */
bool prims_have_changed = true;
if (geom->is_mesh()) {
Mesh *mesh = static_cast<Mesh *>(geom);
- if (!mesh->triangles_is_modified()) {
+ if (!mesh->triangles_is_modified() && !force_pack) {
prims_have_changed = false;
}
}
+ prims_have_changed |= visibility_modified;
+
if (prims_have_changed) {
for (size_t i = 0; i < bvh_pack.prim_index.size(); i++, pack_offset++) {
if (bvh_pack.prim_type[i] & PRIMITIVE_ALL_CURVE) {
diff --git a/intern/cycles/bvh/bvh_optix.h b/intern/cycles/bvh/bvh_optix.h
index c69a4aa9932..1e8a1b8e5ff 100644
--- a/intern/cycles/bvh/bvh_optix.h
+++ b/intern/cycles/bvh/bvh_optix.h
@@ -53,7 +53,9 @@ class BVHOptiX : public BVH {
size_t pack_offset,
size_t pack_verts_offset,
int object_index,
- int object_visibility);
+ int object_visibility,
+ bool force_pack,
+ bool visibility_modified);
virtual void pack_nodes(const BVHNode *) override;
virtual void refit_nodes() override;
diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h
index 1a50742dc33..11ff35e948a 100644
--- a/intern/cycles/bvh/bvh_params.h
+++ b/intern/cycles/bvh/bvh_params.h
@@ -66,6 +66,9 @@ class BVHParams {
/* object or mesh level bvh */
bool top_level;
+ /* pack the data from all meshes even if they are not modified */
+ bool pack_all_data;
+
/* BVH layout to be built. */
BVHLayout bvh_layout;
@@ -113,6 +116,7 @@ class BVHParams {
max_motion_curve_leaf_size = 4;
top_level = false;
+ pack_all_data = false;
bvh_layout = BVH_LAYOUT_BVH2;
use_unaligned_nodes = false;
diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp
index 5ee2723893d..a5a8c8b54b9 100644
--- a/intern/cycles/device/device_optix.cpp
+++ b/intern/cycles/device/device_optix.cpp
@@ -1426,15 +1426,14 @@ class OptiXDevice : public CUDADevice {
continue;
}
+ const size_t num_verts = mesh->get_verts().size();
+
size_t num_motion_steps = 1;
Attribute *motion_keys = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (motion_blur && mesh->get_use_motion_blur() && motion_keys) {
num_motion_steps = mesh->get_motion_steps();
}
-# if 0
- const size_t num_verts = mesh->get_verts().size();
-
device_vector<int> index_data(this, "temp_index_data", MEM_READ_ONLY);
index_data.alloc(mesh->get_triangles().size());
memcpy(index_data.data(),
@@ -1484,31 +1483,6 @@ class OptiXDevice : public CUDADevice {
// one and rely on that having the same meaning in this case.
build_input.triangleArray.numSbtRecords = 1;
build_input.triangleArray.primitiveIndexOffset = mesh->optix_prim_offset;
-# else
- vector<device_ptr> vertex_ptrs;
- vertex_ptrs.reserve(num_motion_steps);
- vertex_ptrs.push_back(bvh->prim_vert_pointer +
- geom->bvh->pack_verts_offset * sizeof(float3));
-
- // Force a single any-hit call, so shadow record-all behavior works correctly
- unsigned int build_flags = OPTIX_GEOMETRY_FLAG_REQUIRE_SINGLE_ANYHIT_CALL;
- OptixBuildInput build_input = {};
- build_input.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES;
- build_input.triangleArray.vertexBuffers = (CUdeviceptr *)vertex_ptrs.data();
- build_input.triangleArray.numVertices = mesh->num_triangles() * 3;
- build_input.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3;
- build_input.triangleArray.vertexStrideInBytes = sizeof(float3);
- build_input.triangleArray.indexBuffer = 0;
- build_input.triangleArray.numIndexTriplets = 0;
- // build_input.triangleArray.indexFormat = OPTIX_INDICES_FORMAT_UNSIGNED_INT3;
- build_input.triangleArray.indexStrideInBytes = 0;
- build_input.triangleArray.flags = &build_flags;
- // The SBT does not store per primitive data since Cycles already allocates separate
- // buffers for that purpose. OptiX does not allow this to be zero though, so just pass in
- // one and rely on that having the same meaning in this case.
- build_input.triangleArray.numSbtRecords = 1;
- build_input.triangleArray.primitiveIndexOffset = mesh->optix_prim_offset;
-# endif
// Allocate memory for new BLAS and build it
if (build_optix_bvh(build_input, num_motion_steps, handle, out_data, operation)) {
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp
index 75cb2b24549..3a4ef90dd96 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -154,10 +154,15 @@ void Attribute::set_data_from(Attribute &other)
assert(other.type == type);
assert(other.element == element);
- if (memcmp(this->data(), other.data(), other.buffer.size()) != 0) {
+ this->flags = other.flags;
+
+ if (this->buffer.size() != other.buffer.size()) {
+ this->buffer = other.buffer;
modified = true;
+ }
+ else if (memcmp(this->data(), other.data(), other.buffer.size()) != 0) {
this->buffer = other
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list