[Bf-blender-cvs] [b2ddacee5f1] temp-gpu-compute-shader-hair: Added memory barrier.

Jeroen Bakker noreply at git.blender.org
Fri Apr 23 15:45:38 CEST 2021


Commit: b2ddacee5f1009f584bbcb2bfefc75e6d09210d9
Author: Jeroen Bakker
Date:   Fri Apr 23 15:44:24 2021 +0200
Branches: temp-gpu-compute-shader-hair
https://developer.blender.org/rBb2ddacee5f1009f584bbcb2bfefc75e6d09210d9

Added memory barrier.

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

M	source/blender/draw/intern/draw_hair.c
M	source/blender/draw/intern/shaders/common_hair_lib.glsl
M	source/blender/gpu/GPU_state.h
M	source/blender/gpu/opengl/gl_state.hh

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

diff --git a/source/blender/draw/intern/draw_hair.c b/source/blender/draw/intern/draw_hair.c
index 70768273e1b..b08a2c09f60 100644
--- a/source/blender/draw/intern/draw_hair.c
+++ b/source/blender/draw/intern/draw_hair.c
@@ -51,7 +51,7 @@
 BLI_INLINE bool drw_hair_use_compute_shaders(void)
 {
 #ifdef USE_TRANSFORM_FEEDBACK
-  return false;  // GPU_compute_shader_support();
+  return GPU_compute_shader_support();
 #else
   return false;
 #endif
@@ -165,7 +165,7 @@ static void drw_hair_particle_cache_update_compute(ParticleHairCache *cache, con
     DRWShadingGroup *shgrp = DRW_shgroup_create(shader, g_tf_pass);
 
     drw_hair_particle_cache_shgrp_attach_resources(shgrp, cache, subdiv);
-    DRW_shgroup_uniform_image(shgrp, "hairPointOutputBuffer", cache->point_tex);
+    DRW_shgroup_uniform_image(shgrp, "hairPointOutputBuffer", cache->final[subdiv].proc_tex);
     DRW_shgroup_call_compute(shgrp, cache->strands_len, cache->final[subdiv].strands_res, 1);
   }
 }
@@ -218,7 +218,6 @@ static ParticleHairCache *drw_hair_particle_cache_get(
       drw_hair_particle_cache_update_compute(cache, subdiv);
     }
     else {
-
       drw_hair_particle_cache_update_transform_feedback(cache, subdiv);
     }
   }
@@ -424,6 +423,9 @@ void DRW_hair_update(void)
 #else
   /* Just render the pass when using compute shaders or transform feedback. */
   DRW_draw_pass(g_tf_pass);
+  if (drw_hair_use_compute_shaders()) {
+    GPU_memory_barrier(GPU_BARRIER_VERTEX_ATTRIB_ARRAY);
+  }
 #endif
   TIMEIT_END(DRW_hair_update);
 }
diff --git a/source/blender/draw/intern/shaders/common_hair_lib.glsl b/source/blender/draw/intern/shaders/common_hair_lib.glsl
index 09a9f6e323b..1f82fd341c9 100644
--- a/source/blender/draw/intern/shaders/common_hair_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_hair_lib.glsl
@@ -43,7 +43,7 @@ uniform usamplerBuffer hairStrandSegBuffer; /* R16UI */
 
 /* -- Subdivision stage -- */
 /**
- * We use a transform feedback to preprocess the strands and add more subdivision to it.
+ * We use a transform feedback or compute shader to preprocess the strands and add more subdivision to it.
  * For the moment these are simple smooth interpolation but one could hope to see the full
  * children particle modifiers being evaluated at this stage.
  *
@@ -119,9 +119,8 @@ void hair_get_interp_attrs(
  * For final drawing, the vertex index and the number of vertex per segment
  */
 
-#if !defined(HAIR_PHASE_SUBDIV) && (defined(GPU_VERTEX_SHADER) || defined(GPU_COMPUTE_SHADER))
+#if !defined(HAIR_PHASE_SUBDIV) && defined(GPU_VERTEX_SHADER)
 
-#  ifdef GPU_VERTEX_SHADER
 int hair_get_strand_id(void)
 {
   return gl_VertexID / (hairStrandsRes * hairThicknessRes);
@@ -129,22 +128,9 @@ int hair_get_strand_id(void)
 
 int hair_get_base_id(void)
 {
-  return gl_VertexID / hairStrandsRes;
-}
-#  endif
-
-#  ifdef GPU_COMPUTE_SHADER
-int hair_get_strand_id(void)
-{
-  return int(gl_GlobalInvocationID.x / hairThicknessRes));
+  return gl_VertexID / hairThicknessRes;
 }
 
-int hair_get_base_id(void)
-{
-  return int(gl_GlobalInvocationID.x);
-}
-#  endif
-
 /* Copied from cycles. */
 float hair_shaperadius(float shape, float root, float tip, float time)
 {
diff --git a/source/blender/gpu/GPU_state.h b/source/blender/gpu/GPU_state.h
index 0687f271670..e82e25bf37a 100644
--- a/source/blender/gpu/GPU_state.h
+++ b/source/blender/gpu/GPU_state.h
@@ -39,6 +39,7 @@ typedef enum eGPUBarrier {
   GPU_BARRIER_NONE = 0,
   GPU_BARRIER_SHADER_IMAGE_ACCESS = (1 << 0),
   GPU_BARRIER_TEXTURE_FETCH = (1 << 1),
+  GPU_BARRIER_VERTEX_ATTRIB_ARRAY = (1 << 2),
 } eGPUBarrier;
 
 ENUM_OPERATORS(eGPUBarrier, GPU_BARRIER_TEXTURE_FETCH)
diff --git a/source/blender/gpu/opengl/gl_state.hh b/source/blender/gpu/opengl/gl_state.hh
index 651c3c22afa..e19d9feb1f4 100644
--- a/source/blender/gpu/opengl/gl_state.hh
+++ b/source/blender/gpu/opengl/gl_state.hh
@@ -121,6 +121,9 @@ static inline GLbitfield to_gl(eGPUBarrier barrier_bits)
   if (barrier_bits & GPU_BARRIER_TEXTURE_FETCH) {
     barrier |= GL_TEXTURE_FETCH_BARRIER_BIT;
   }
+  if (barrier_bits & GPU_BARRIER_VERTEX_ATTRIB_ARRAY) {
+    barrier |= GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT;
+  }
   return barrier;
 }



More information about the Bf-blender-cvs mailing list