Fix T85440: crash with displacement shaders and updating geometry in viewport

When primitive offsets change we need to rebuild or refit BVHs, however this
was also tagging other data as modified too late in the geometry update process.
Now ensure only the BVHs are updated.

Ref D10441
This commit is contained in:
Brecht Van Lommel 2021-02-16 20:45:19 +01:00
parent 6ce06957c9
commit 2217719feb
Notes: blender-bot 2023-02-14 08:24:03 +01:00
Referenced by issue #85440, 2.92 Beta - Viewport rendering crash/bugs when changing subdiv modifier when there is another object with a displacement shader node
2 changed files with 8 additions and 2 deletions

View File

@ -61,6 +61,7 @@ Geometry::Geometry(const NodeType *node_type, const Type type)
: Node(node_type), geometry_type(type), attributes(this, ATTR_PRIM_GEOMETRY)
{
need_update_rebuild = false;
need_update_bvh_for_offset = false;
transform_applied = false;
transform_negative_scaled = false;
@ -242,6 +243,7 @@ void Geometry::compute_bvh(
clear_modified();
need_update_rebuild = false;
need_update_bvh_for_offset = false;
}
bool Geometry::has_motion_blur() const
@ -944,7 +946,8 @@ void GeometryManager::mesh_calc_offset(Scene *scene, BVHLayout bvh_layout)
const bool has_optix_bvh = bvh_layout == BVH_LAYOUT_OPTIX ||
bvh_layout == BVH_LAYOUT_MULTI_OPTIX ||
bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE;
geom->tag_bvh_update(has_optix_bvh);
geom->need_update_rebuild |= has_optix_bvh;
geom->need_update_bvh_for_offset = true;
}
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
@ -1590,7 +1593,9 @@ void GeometryManager::device_update(Device *device,
displacement_done = true;
}
}
}
if (geom->is_modified() || geom->need_update_bvh_for_offset) {
if (geom->need_build_bvh(bvh_layout)) {
num_bvh++;
}
@ -1632,7 +1637,7 @@ void GeometryManager::device_update(Device *device,
size_t i = 0;
foreach (Geometry *geom, scene->geometry) {
if (geom->is_modified()) {
if (geom->is_modified() || geom->need_update_bvh_for_offset) {
pool.push(function_bind(
&Geometry::compute_bvh, geom, device, dscene, &scene->params, &progress, i, num_bvh));
if (geom->need_build_bvh(bvh_layout)) {

View File

@ -90,6 +90,7 @@ class Geometry : public Node {
/* Update Flags */
bool need_update_rebuild;
bool need_update_bvh_for_offset;
/* Index into scene->geometry (only valid during update) */
size_t index;