[Bf-blender-cvs] [24e74f8bef8] blender-v3.2-release: Fix T98449: Cycles crash changing frame after recent changes

Brecht Van Lommel noreply at git.blender.org
Mon May 30 14:09:06 CEST 2022


Commit: 24e74f8bef813820076cce08635e7c4cb3f2da13
Author: Brecht Van Lommel
Date:   Mon May 30 13:28:38 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB24e74f8bef813820076cce08635e7c4cb3f2da13

Fix T98449: Cycles crash changing frame after recent changes

Subdivision did not properly update when evaluating first without and then with
orco coordinates. Now update the subdivision evaluator settings every time, and
reallocate the vertex data buffer when needed.

there is an additional issue in this file where orco coordinates are not
available immediately on the first frame when they should be, and only appear
on the second frame. However that is an old limitation related to the depsgraph
not getting re-evaluated on viewport display mode changes, here we just fix the
crash.

===================================================================

M	intern/opensubdiv/internal/evaluator/eval_output.h
M	intern/opensubdiv/internal/evaluator/eval_output_cpu.h
M	intern/opensubdiv/internal/evaluator/eval_output_gpu.cc
M	intern/opensubdiv/internal/evaluator/eval_output_gpu.h
M	intern/opensubdiv/internal/evaluator/evaluator_capi.cc
M	intern/opensubdiv/internal/evaluator/evaluator_impl.cc
M	intern/opensubdiv/internal/evaluator/evaluator_impl.h
M	intern/opensubdiv/opensubdiv_evaluator_capi.h
M	source/blender/blenkernel/intern/subdiv_eval.c

===================================================================

diff --git a/intern/opensubdiv/internal/evaluator/eval_output.h b/intern/opensubdiv/internal/evaluator/eval_output.h
index cff7c8d18c9..57a9fab490f 100644
--- a/intern/opensubdiv/internal/evaluator/eval_output.h
+++ b/intern/opensubdiv/internal/evaluator/eval_output.h
@@ -27,6 +27,8 @@
 #include "internal/base/type.h"
 #include "internal/evaluator/evaluator_impl.h"
 
+#include "opensubdiv_evaluator_capi.h"
+
 using OpenSubdiv::Far::PatchTable;
 using OpenSubdiv::Far::StencilTable;
 using OpenSubdiv::Osd::BufferDescriptor;
@@ -42,6 +44,8 @@ class EvalOutputAPI::EvalOutput {
  public:
   virtual ~EvalOutput() = default;
 
+  virtual void updateSettings(const OpenSubdiv_EvaluatorSettings *settings) = 0;
+
   virtual void updateData(const float *src, int start_vertex, int num_vertices) = 0;
 
   virtual void updateVaryingData(const float *src, int start_vertex, int num_vertices) = 0;
@@ -338,13 +342,13 @@ class VolatileEvalOutput : public EvalOutputAPI::EvalOutput {
                      const StencilTable *varying_stencils,
                      const vector<const StencilTable *> &all_face_varying_stencils,
                      const int face_varying_width,
-                     const int vertex_data_width,
                      const PatchTable *patch_table,
                      EvaluatorCache *evaluator_cache = NULL,
                      DEVICE_CONTEXT *device_context = NULL)
-      : src_desc_(0, 3, 3),
+      : src_vertex_data_(NULL),
+        src_desc_(0, 3, 3),
         src_varying_desc_(0, 3, 3),
-        src_vertex_data_desc_(0, vertex_data_width, vertex_data_width),
+        src_vertex_data_desc_(0, 0, 0),
         face_varying_width_(face_varying_width),
         evaluator_cache_(evaluator_cache),
         device_context_(device_context)
@@ -362,15 +366,6 @@ class VolatileEvalOutput : public EvalOutputAPI::EvalOutput {
     varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(varying_stencils,
                                                                        device_context_);
 
-    // Optionally allocate additional data to be subdivided like vertex coordinates.
-    if (vertex_data_width > 0) {
-      src_vertex_data_ = SRC_VERTEX_BUFFER::Create(
-          vertex_data_width, num_total_vertices, device_context_);
-    }
-    else {
-      src_vertex_data_ = NULL;
-    }
-
     // Create evaluators for every face varying channel.
     face_varying_evaluators.reserve(all_face_varying_stencils.size());
     int face_varying_channel = 0;
@@ -398,6 +393,23 @@ class VolatileEvalOutput : public EvalOutputAPI::EvalOutput {
     }
   }
 
+  void updateSettings(const OpenSubdiv_EvaluatorSettings *settings) override
+  {
+    // Optionally allocate additional data to be subdivided like vertex coordinates.
+    if (settings->num_vertex_data != src_vertex_data_desc_.length) {
+      delete src_vertex_data_;
+      if (settings->num_vertex_data > 0) {
+        src_vertex_data_ = SRC_VERTEX_BUFFER::Create(
+            settings->num_vertex_data, src_data_->GetNumVertices(), device_context_);
+      }
+      else {
+        src_vertex_data_ = NULL;
+      }
+      src_vertex_data_desc_ = BufferDescriptor(
+          0, settings->num_vertex_data, settings->num_vertex_data);
+    }
+  }
+
   // TODO(sergey): Implement binding API.
 
   void updateData(const float *src, int start_vertex, int num_vertices) override
diff --git a/intern/opensubdiv/internal/evaluator/eval_output_cpu.h b/intern/opensubdiv/internal/evaluator/eval_output_cpu.h
index 2b3c738d6ab..58bae7a322e 100644
--- a/intern/opensubdiv/internal/evaluator/eval_output_cpu.h
+++ b/intern/opensubdiv/internal/evaluator/eval_output_cpu.h
@@ -44,7 +44,6 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
                 const StencilTable *varying_stencils,
                 const vector<const StencilTable *> &all_face_varying_stencils,
                 const int face_varying_width,
-                const int vertex_data_width,
                 const PatchTable *patch_table,
                 EvaluatorCache *evaluator_cache = NULL)
       : VolatileEvalOutput<CpuVertexBuffer,
@@ -55,7 +54,6 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
                                          varying_stencils,
                                          all_face_varying_stencils,
                                          face_varying_width,
-                                         vertex_data_width,
                                          patch_table,
                                          evaluator_cache)
   {
diff --git a/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc b/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc
index 566071d581b..b352ed2c014 100644
--- a/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc
+++ b/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc
@@ -45,7 +45,6 @@ GpuEvalOutput::GpuEvalOutput(const StencilTable *vertex_stencils,
                              const StencilTable *varying_stencils,
                              const vector<const StencilTable *> &all_face_varying_stencils,
                              const int face_varying_width,
-                             const int vertex_data_width,
                              const PatchTable *patch_table,
                              VolatileEvalOutput::EvaluatorCache *evaluator_cache)
     : VolatileEvalOutput<GLVertexBuffer,
@@ -56,7 +55,6 @@ GpuEvalOutput::GpuEvalOutput(const StencilTable *vertex_stencils,
                                              varying_stencils,
                                              all_face_varying_stencils,
                                              face_varying_width,
-                                             vertex_data_width,
                                              patch_table,
                                              evaluator_cache)
 {
diff --git a/intern/opensubdiv/internal/evaluator/eval_output_gpu.h b/intern/opensubdiv/internal/evaluator/eval_output_gpu.h
index 2306a87b87c..dc137e4322e 100644
--- a/intern/opensubdiv/internal/evaluator/eval_output_gpu.h
+++ b/intern/opensubdiv/internal/evaluator/eval_output_gpu.h
@@ -40,7 +40,6 @@ class GpuEvalOutput : public VolatileEvalOutput<GLVertexBuffer,
                 const StencilTable *varying_stencils,
                 const vector<const StencilTable *> &all_face_varying_stencils,
                 const int face_varying_width,
-                const int vertex_data_width,
                 const PatchTable *patch_table,
                 EvaluatorCache *evaluator_cache = NULL);
 
diff --git a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc
index 8a54ed653dc..b8d603ec380 100644
--- a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc
+++ b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc
@@ -28,6 +28,12 @@
 
 namespace {
 
+void setSettings(struct OpenSubdiv_Evaluator *evaluator,
+                 const OpenSubdiv_EvaluatorSettings *settings)
+{
+  evaluator->impl->eval_output->setSettings(settings);
+}
+
 void setCoarsePositions(OpenSubdiv_Evaluator *evaluator,
                         const float *positions,
                         const int start_vertex_index,
@@ -222,6 +228,8 @@ void wrapFVarSrcBuffer(struct OpenSubdiv_Evaluator *evaluator,
 
 void assignFunctionPointers(OpenSubdiv_Evaluator *evaluator)
 {
+  evaluator->setSettings = setSettings;
+
   evaluator->setCoarsePositions = setCoarsePositions;
   evaluator->setVertexData = setVertexData;
   evaluator->setVaryingData = setVaryingData;
@@ -258,16 +266,12 @@ void assignFunctionPointers(OpenSubdiv_Evaluator *evaluator)
 OpenSubdiv_Evaluator *openSubdiv_createEvaluatorFromTopologyRefiner(
     OpenSubdiv_TopologyRefiner *topology_refiner,
     eOpenSubdivEvaluator evaluator_type,
-    OpenSubdiv_EvaluatorCache *evaluator_cache,
-    const OpenSubdiv_EvaluatorSettings *settings)
+    OpenSubdiv_EvaluatorCache *evaluator_cache)
 {
   OpenSubdiv_Evaluator *evaluator = MEM_new<OpenSubdiv_Evaluator>(__func__);
   assignFunctionPointers(evaluator);
-  evaluator->impl = openSubdiv_createEvaluatorInternal(topology_refiner,
-                                                       evaluator_type,
-                                                       evaluator_cache ? evaluator_cache->impl :
-                                                                         nullptr,
-                                                       settings);
+  evaluator->impl = openSubdiv_createEvaluatorInternal(
+      topology_refiner, evaluator_type, evaluator_cache ? evaluator_cache->impl : nullptr);
   evaluator->type = evaluator->impl ? evaluator_type : static_cast<eOpenSubdivEvaluator>(0);
   return evaluator;
 }
diff --git a/intern/opensubdiv/internal/evaluator/evaluator_impl.cc b/intern/opensubdiv/internal/evaluator/evaluator_impl.cc
index bb9e6e7bd0d..0b8baa754d4 100644
--- a/intern/opensubdiv/internal/evaluator/evaluator_impl.cc
+++ b/intern/opensubdiv/internal/evaluator/evaluator_impl.cc
@@ -166,6 +166,11 @@ EvalOutputAPI::~EvalOutputAPI()
   delete implementation_;
 }
 
+void EvalOutputAPI::setSettings(const OpenSubdiv_EvaluatorSettings *settings)
+{
+  implementation_->updateSettings(settings);
+}
+
 void EvalOutputAPI::setCoarsePositions(const float *positions,
                                        const int start_vertex_index,
                                        const int num_vertices)
@@ -425,8 +430,7 @@ OpenSubdiv_EvaluatorImpl::~OpenSubdiv_EvaluatorImpl()
 OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal(
     OpenSubdiv_TopologyRefiner *topology_refiner,
     eOpenSubdivEvaluator evaluator_type,
-    OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr,
-    const OpenSubdiv_EvaluatorSettings *settings)
+    OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr)
 {
   // Only CPU and GLCompute are implemented at the moment.
   if (evaluator_type != OPENSUBDIV_EVALUATOR_CPU &&
@@ -445,7 +449,6 @@ OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal(
   const bool has_face_varying_data = (num_face_varying_channels != 0);
   const int level = topology_refiner->getSubdivisionLevel(topology_refiner);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list