[Bf-blender-cvs] [5b87862ddca] master: Curves: Further split of curves draw code from particles

Hans Goudey noreply at git.blender.org
Fri Apr 22 17:45:31 CEST 2022


Commit: 5b87862ddca2cb1b9351a5e250e1743b7245f38b
Author: Hans Goudey
Date:   Fri Apr 22 10:43:48 2022 -0500
Branches: master
https://developer.blender.org/rB5b87862ddca2cb1b9351a5e250e1743b7245f38b

Curves: Further split of curves draw code from particles

Extends the changes started in f31c3f8114616bb to completely separate
much of the DRW curves code from the particle hair drawing. In the short
term this increases duplication, but the idea is to simplify development
by making it easier to do larger changes to the new code, and the new
system will replace the particle hair at some point.

After this, only the shaders themselves are shared.

Differential Revision: https://developer.blender.org/D14699

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee_lightcache.c
M	source/blender/draw/engines/eevee/eevee_motion_blur.c
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/workbench/workbench_render.c
M	source/blender/draw/intern/draw_cache_impl_curves.cc
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/intern/draw_common.h
A	source/blender/draw/intern/draw_curves.cc
A	source/blender/draw/intern/draw_curves_private.h
M	source/blender/draw/intern/draw_hair.c
M	source/blender/draw/intern/draw_hair_private.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_shader.c
M	source/blender/draw/intern/draw_shader.h

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index b196d56fae2..8c54c923476 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -82,6 +82,7 @@ set(SRC
   intern/draw_cache_impl_volume.c
   intern/draw_color_management.cc
   intern/draw_common.c
+  intern/draw_curves.cc
   intern/draw_debug.c
   intern/draw_fluid.c
   intern/draw_hair.c
@@ -195,6 +196,7 @@ set(SRC
   intern/draw_color_management.h
   intern/draw_common.h
   intern/draw_common_shader_shared.h
+  intern/draw_curves_private.h
   intern/draw_debug.h
   intern/draw_hair_private.h
   intern/draw_instance_data.h
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index f18e4db876b..4f562dd9804 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -965,7 +965,7 @@ static void eevee_lightbake_cache_create(EEVEE_Data *vedata, EEVEE_LightBake *lb
   txl->color = NULL;
 
   DRW_render_instance_buffer_finish();
-  DRW_hair_update();
+  DRW_curves_update();
 }
 
 static void eevee_lightbake_copy_irradiance(EEVEE_LightBake *lbake, LightCache *lcache)
diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c
index e3342508a14..2e0937dbe49 100644
--- a/source/blender/draw/engines/eevee/eevee_motion_blur.c
+++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c
@@ -440,9 +440,9 @@ void EEVEE_motion_blur_cache_finish(EEVEE_Data *vedata)
     DRW_render_instance_buffer_finish();
 
     /* Need to be called after #DRW_render_instance_buffer_finish() */
-    /* Also we weed to have a correct FBO bound for #DRW_hair_update. */
+    /* Also we weed to have a correct FBO bound for #DRW_curves_update. */
     GPU_framebuffer_bind(vedata->fbl->main_fb);
-    DRW_hair_update();
+    DRW_curves_update();
 
     DRW_cache_restart();
   }
diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c
index 47e2b95f367..bef19c589c2 100644
--- a/source/blender/draw/engines/eevee/eevee_render.c
+++ b/source/blender/draw/engines/eevee/eevee_render.c
@@ -538,9 +538,9 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl
   DRW_render_instance_buffer_finish();
 
   /* Need to be called after DRW_render_instance_buffer_finish() */
-  /* Also we weed to have a correct FBO bound for DRW_hair_update */
+  /* Also we weed to have a correct FBO bound for DRW_curves_update */
   GPU_framebuffer_bind(fbl->main_fb);
-  DRW_hair_update();
+  DRW_curves_update();
 
   /* Sort transparents before the loop. */
   DRW_pass_sort_shgroup_z(psl->transparent_pass);
diff --git a/source/blender/draw/engines/workbench/workbench_render.c b/source/blender/draw/engines/workbench/workbench_render.c
index 72de3fe298a..1279682e899 100644
--- a/source/blender/draw/engines/workbench/workbench_render.c
+++ b/source/blender/draw/engines/workbench/workbench_render.c
@@ -170,9 +170,9 @@ void workbench_render(void *ved, RenderEngine *engine, RenderLayer *render_layer
 
   DRW_render_instance_buffer_finish();
 
-  /* Also we weed to have a correct FBO bound for #DRW_hair_update */
+  /* Also we weed to have a correct FBO bound for #DRW_curves_update */
   GPU_framebuffer_bind(dfbl->default_fb);
-  DRW_hair_update();
+  DRW_curves_update();
 
   GPU_framebuffer_bind(dfbl->default_fb);
   GPU_framebuffer_clear_depth(dfbl->default_fb, 1.0f);
diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc
index b084a5e5945..f2e747cb276 100644
--- a/source/blender/draw/intern/draw_cache_impl_curves.cc
+++ b/source/blender/draw/intern/draw_cache_impl_curves.cc
@@ -29,9 +29,11 @@
 #include "GPU_material.h"
 #include "GPU_texture.h"
 
+#include "DRW_render.h"
+
 #include "draw_cache_impl.h" /* own include */
 #include "draw_cache_inline.h"
-#include "draw_hair_private.h" /* own include */
+#include "draw_curves_private.h" /* own include */
 
 using blender::float3;
 using blender::IndexRange;
@@ -41,7 +43,7 @@ using blender::Span;
 /* Curves GPUBatch Cache */
 
 struct CurvesBatchCache {
-  ParticleHairCache hair;
+  CurvesEvalCache curves_cache;
 
   GPUBatch *edit_points;
 
@@ -70,6 +72,33 @@ static void curves_batch_cache_init(Curves &curves)
   cache->is_dirty = false;
 }
 
+static void curves_batch_cache_clear_data(CurvesEvalCache &curves_cache)
+{
+  /* TODO: more granular update tagging. */
+  GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_point_buf);
+  GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_length_buf);
+  DRW_TEXTURE_FREE_SAFE(curves_cache.point_tex);
+  DRW_TEXTURE_FREE_SAFE(curves_cache.length_tex);
+
+  GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_strand_buf);
+  GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_strand_seg_buf);
+  DRW_TEXTURE_FREE_SAFE(curves_cache.strand_tex);
+  DRW_TEXTURE_FREE_SAFE(curves_cache.strand_seg_tex);
+
+  for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
+    GPU_VERTBUF_DISCARD_SAFE(curves_cache.final[i].proc_buf);
+    DRW_TEXTURE_FREE_SAFE(curves_cache.final[i].proc_tex);
+    for (int j = 0; j < MAX_THICKRES; j++) {
+      GPU_BATCH_DISCARD_SAFE(curves_cache.final[i].proc_hairs[j]);
+    }
+  }
+
+  /* "Normal" legacy hairs */
+  GPU_BATCH_DISCARD_SAFE(curves_cache.hairs);
+  GPU_VERTBUF_DISCARD_SAFE(curves_cache.pos);
+  GPU_INDEXBUF_DISCARD_SAFE(curves_cache.indices);
+}
+
 static void curves_batch_cache_clear(Curves &curves)
 {
   CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache);
@@ -77,7 +106,8 @@ static void curves_batch_cache_clear(Curves &curves)
     return;
   }
 
-  particle_batch_cache_clear_hair(&cache->hair);
+  curves_batch_cache_clear_data(cache->curves_cache);
+
   GPU_BATCH_DISCARD_SAFE(cache->edit_points);
 }
 
@@ -116,7 +146,7 @@ void DRW_curves_batch_cache_free(Curves *curves)
   MEM_SAFE_FREE(curves->batch_cache);
 }
 
-static void ensure_seg_pt_count(const Curves &curves, ParticleHairCache &curves_cache)
+static void ensure_seg_pt_count(const Curves &curves, CurvesEvalCache &curves_cache)
 {
   if ((curves_cache.pos != nullptr && curves_cache.indices != nullptr) ||
       (curves_cache.proc_point_buf != nullptr)) {
@@ -169,7 +199,7 @@ static void curves_batch_cache_fill_segments_proc_pos(const Curves &curves_id,
 }
 
 static void curves_batch_cache_ensure_procedural_pos(Curves &curves,
-                                                     ParticleHairCache &cache,
+                                                     CurvesEvalCache &cache,
                                                      GPUMaterial *gpu_material)
 {
   if (cache.proc_point_buf == nullptr || DRW_vbo_requested(cache.proc_point_buf)) {
@@ -229,7 +259,7 @@ static void curves_batch_cache_fill_strands_data(const Curves &curves_id,
 }
 
 static void curves_batch_cache_ensure_procedural_strand_data(Curves &curves,
-                                                             ParticleHairCache &cache)
+                                                             CurvesEvalCache &cache)
 {
   GPUVertBufRaw data_step, seg_step;
 
@@ -259,7 +289,7 @@ static void curves_batch_cache_ensure_procedural_strand_data(Curves &curves,
                                                          cache.proc_strand_seg_buf);
 }
 
-static void curves_batch_cache_ensure_procedural_final_points(ParticleHairCache &cache, int subdiv)
+static void curves_batch_cache_ensure_procedural_final_points(CurvesEvalCache &cache, int subdiv)
 {
   /* Same format as point_tex. */
   GPUVertFormat format = {0};
@@ -296,7 +326,7 @@ static void curves_batch_cache_fill_segments_indices(const Curves &curves,
 }
 
 static void curves_batch_cache_ensure_procedural_indices(Curves &curves,
-                                                         ParticleHairCache &cache,
+                                                         CurvesEvalCache &cache,
                                                          const int thickness_res,
                                                          const int subdiv)
 {
@@ -330,7 +360,7 @@ static void curves_batch_cache_ensure_procedural_indices(Curves &curves,
 }
 
 bool curves_ensure_procedural_data(Object *object,
-                                   ParticleHairCache **r_hair_cache,
+                                   CurvesEvalCache **r_hair_cache,
                                    GPUMaterial *gpu_material,
                                    const int subdiv,
                                    const int thickness_res)
@@ -339,30 +369,31 @@ bool curves_ensure_procedural_data(Object *object,
   Curves &curves = *static_cast<Curves *>(object->data);
 
   CurvesBatchCache &cache = curves_batch_cache_get(curves);
-  *r_hair_cache = &cache.hair;
+  *r_hair_cache = &cache.curves_cache;
 
   const int steps = 3; /* TODO: don't hard-code? */
   (*r_hair_cache)->final[subdiv].strands_res = 1 << (steps + subdiv);
 
   /* Refreshed on combing and simulation. */
   if ((*r_hair_cache)->proc_point_buf == nullptr) {
-    ensure_seg_pt_count(curves, cache.hair);
-    curves_batch_cache_ensure_procedural_pos(curves, cache.hair, gpu_material);
+    ensure_seg_pt_count(curves, cache.curves_cache);
+    curves_batch_cache_ensure_procedural_pos(curves, cache.curves_cache, gpu_material);
     need_ft_update = true;
   }
 
   /* Refreshed if active layer or custom data changes. */
   if ((*r_hair_cache)->strand_tex == nullptr) {
-    curves_batch_cache_ensure_procedural_strand_data(curves, cache.hair);
+    curves_batch_cache_ensure_procedural_strand_data(curves, cache.curves_cache);
   }
 
   /* Refreshed only on subdiv count change. */
   if ((*r_hair_cache)->final[subdiv].proc_buf == nullptr) {
-    curves_batch_cache_ensure_procedural_final_points(cache.hair, subdiv);
+    curves_batch_cache_ensure_procedural_final_points(cache.curves_cache, subdiv);
     need_ft_update = true;
   }
   if ((*r_hair_cache)->final[subdiv].proc_hairs[thickness_res - 1] == nullptr) {
-    curves_batch_cache_ensure_procedural_indices(curves, cache.hair, thickness_res, subdiv);
+    curves_batch_cache_ensure_procedural_in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list