[Bf-blender-cvs] [77f5210f223] master: GPU: Remove GPU_INDEX_U8

Clément Foucault noreply at git.blender.org
Thu May 30 13:45:45 CEST 2019


Commit: 77f5210f22332b3594fabe08bee5809fc8333dba
Author: Clément Foucault
Date:   Wed May 29 00:08:10 2019 +0200
Branches: master
https://developer.blender.org/rB77f5210f22332b3594fabe08bee5809fc8333dba

GPU: Remove GPU_INDEX_U8

This type of indices is not natively supported on modern GPU and
gives warning on some implementation. The memory savings it
provides is also quite minimal and unlikely to be visible on
nowadays hardware.

This remove some uneeded struct members and makes primitive
restart always enabled by default. This can be broken by addons
if they are not careful enough but many other states have this
problem.

Also leverage GL_PRIMITIVE_RESTART_FIXED_INDEX if
ARB_ES3_compatibility is supported. This removes all API calls
to change restart index depending on indices length.

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/gpu/GPU_element.h
M	source/blender/gpu/intern/gpu_batch.c
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/gpu/intern/gpu_element.c

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index c40e9772340..88125e884d5 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -2707,7 +2707,7 @@ GPUBatch *DRW_cache_bone_stick_get(void)
     GPU_vertbuf_data_alloc(vbo, vcount);
 
     GPUIndexBufBuilder elb;
-    GPU_indexbuf_init_ex(&elb, GPU_PRIM_TRI_FAN, (CIRCLE_RESOL + 2) * 2 + 6 + 2, vcount, true);
+    GPU_indexbuf_init_ex(&elb, GPU_PRIM_TRI_FAN, (CIRCLE_RESOL + 2) * 2 + 6 + 2, vcount);
 
     /* head/tail points */
     for (int i = 0; i < 2; ++i) {
@@ -3931,7 +3931,7 @@ GPUBatch *DRW_cache_cursor_get(bool crosshair_lines)
     }
 
     GPUIndexBufBuilder elb;
-    GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len, true);
+    GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len);
 
     GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
     GPU_vertbuf_data_alloc(vbo, vert_len);
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 0904027ebce..1d6f2aaa070 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -601,7 +601,7 @@ static void curve_create_curves_lines(CurveRenderData *rdata, GPUIndexBuf *ibo_c
   const int index_len = edge_len + curve_len * 2;
 
   GPUIndexBufBuilder elb;
-  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len, true);
+  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len);
 
   int v_idx = 0;
   for (const BevList *bl = rdata->ob_curve_cache->bev.first; bl; bl = bl->next) {
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 9fb9f9713d1..27956f1b808 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -3802,7 +3802,7 @@ static void mesh_create_loops_line_strips(MeshRenderData *rdata,
   const int poly_len = mesh_render_data_polys_len_get(rdata);
 
   GPUIndexBufBuilder elb;
-  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, loop_len + poly_len * 2, loop_len, true);
+  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, loop_len + poly_len * 2, loop_len);
 
   uint v_index = 0;
   if (rdata->mapped.use == false) {
@@ -4842,13 +4842,13 @@ static void mesh_create_uvedit_buffers(MeshRenderData *rdata,
 
   GPUIndexBufBuilder elb_vert, elb_edge, elb_face;
   if (DRW_TEST_ASSIGN_IBO(ibo_vert)) {
-    GPU_indexbuf_init_ex(&elb_vert, GPU_PRIM_POINTS, loop_len, loop_len, false);
+    GPU_indexbuf_init_ex(&elb_vert, GPU_PRIM_POINTS, loop_len, loop_len);
   }
   if (DRW_TEST_ASSIGN_IBO(ibo_edge)) {
-    GPU_indexbuf_init_ex(&elb_edge, GPU_PRIM_LINES, loop_len * 2, loop_len, false);
+    GPU_indexbuf_init_ex(&elb_edge, GPU_PRIM_LINES, loop_len * 2, loop_len);
   }
   if (DRW_TEST_ASSIGN_IBO(ibo_face)) {
-    GPU_indexbuf_init_ex(&elb_face, GPU_PRIM_TRI_FAN, idx_len, loop_len, true);
+    GPU_indexbuf_init_ex(&elb_face, GPU_PRIM_TRI_FAN, idx_len, loop_len);
   }
 
   uvedit_fill_buffer_data(rdata,
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 9a15c51598f..5b1916447a6 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -1053,7 +1053,7 @@ static void particle_batch_cache_ensure_procedural_indices(PTCacheEdit *edit,
   GPU_vertbuf_data_alloc(vbo, 1);
 
   GPUIndexBufBuilder elb;
-  GPU_indexbuf_init_ex(&elb, prim_type, element_count, element_count, true);
+  GPU_indexbuf_init_ex(&elb, prim_type, element_count, element_count);
 
   if (edit != NULL && edit->pathcache != NULL) {
     particle_batch_cache_fill_segments_indices(
@@ -1194,8 +1194,7 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
   GPU_vertbuf_data_alloc(hair_cache->pos, hair_cache->point_len);
 
   GPUIndexBufBuilder elb;
-  GPU_indexbuf_init_ex(
-      &elb, GPU_PRIM_LINE_STRIP, hair_cache->elems_len, hair_cache->point_len, true);
+  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, hair_cache->elems_len, hair_cache->point_len);
 
   if (num_uv_layers || num_col_layers) {
     BKE_mesh_tessface_ensure(psmd->mesh_final);
@@ -1499,8 +1498,7 @@ static void particle_batch_cache_ensure_edit_pos_and_seg(PTCacheEdit *edit,
   GPU_vertbuf_data_alloc(hair_cache->pos, hair_cache->point_len);
   GPU_vertbuf_attr_get_raw_data(hair_cache->pos, pos_id, &data_step);
 
-  GPU_indexbuf_init_ex(
-      &elb, GPU_PRIM_LINE_STRIP, hair_cache->elems_len, hair_cache->point_len, true);
+  GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, hair_cache->elems_len, hair_cache->point_len);
 
   if (edit != NULL && edit->pathcache != NULL) {
     particle_batch_cache_fill_segments_edit(
diff --git a/source/blender/gpu/GPU_element.h b/source/blender/gpu/GPU_element.h
index d1a199f8193..4ac89d2658b 100644
--- a/source/blender/gpu/GPU_element.h
+++ b/source/blender/gpu/GPU_element.h
@@ -30,10 +30,7 @@
 
 #define GPU_TRACK_INDEX_RANGE 1
 
-#define GPU_PRIM_RESTART 0xFFFFFFFF
-
 typedef enum {
-  GPU_INDEX_U8, /* GL has this, Vulkan does not */
   GPU_INDEX_U16,
   GPU_INDEX_U32,
 } GPUIndexBufType;
@@ -43,13 +40,10 @@ typedef struct GPUIndexBuf {
 #if GPU_TRACK_INDEX_RANGE
   GPUIndexBufType index_type;
   uint32_t gl_index_type;
-  uint min_index;
-  uint max_index;
   uint base_index;
 #endif
   uint32_t ibo_id; /* 0 indicates not yet sent to VRAM */
   void *data;      /* non-NULL indicates not yet sent to VRAM */
-  bool use_prim_restart;
 } GPUIndexBuf;
 
 void GPU_indexbuf_use(GPUIndexBuf *);
@@ -61,12 +55,10 @@ typedef struct GPUIndexBufBuilder {
   uint index_len;
   GPUPrimType prim_type;
   uint *data;
-  bool use_prim_restart;
 } GPUIndexBufBuilder;
 
 /* supports all primitive types. */
-void GPU_indexbuf_init_ex(
-    GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len, bool use_prim_restart);
+void GPU_indexbuf_init_ex(GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len);
 
 /* supports only GPU_PRIM_POINTS, GPU_PRIM_LINES and GPU_PRIM_TRIS. */
 void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len);
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index d1cfd5c337d..fb2a87fc8d1 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -545,36 +545,26 @@ void GPU_batch_uniform_mat4(GPUBatch *batch, const char *name, const float data[
   glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (const float *)data);
 }
 
-static void primitive_restart_enable(const GPUIndexBuf *el)
+static void primitive_restart_index(const GPUIndexBuf *el)
 {
-  // TODO(fclem) Replace by GL_PRIMITIVE_RESTART_FIXED_INDEX when we have ogl 4.3
-  glEnable(GL_PRIMITIVE_RESTART);
-  GLuint restart_index = (GLuint)0xFFFFFFFF;
-
 #if GPU_TRACK_INDEX_RANGE
-  if (el->index_type == GPU_INDEX_U8) {
-    restart_index = (GLuint)0xFF;
-  }
-  else if (el->index_type == GPU_INDEX_U16) {
-    restart_index = (GLuint)0xFFFF;
+  /* Can be removed if GL 4.3 is available. */
+  if (!GLEW_ARB_ES3_compatibility) {
+    /* Stay sync with GPU_state_init(). */
+    static int last_type = GPU_INDEX_U32;
+    if (el->index_type != last_type) {
+      GLuint restart_index = (el->index_type == GPU_INDEX_U16) ? (GLuint)0xFFFF :
+                                                                 (GLuint)0xFFFFFFFF;
+      glPrimitiveRestartIndex(restart_index);
+    }
   }
 #endif
-
-  glPrimitiveRestartIndex(restart_index);
-}
-
-static void primitive_restart_disable(void)
-{
-  glDisable(GL_PRIMITIVE_RESTART);
 }
 
 static void *elem_offset(const GPUIndexBuf *el, int v_first)
 {
 #if GPU_TRACK_INDEX_RANGE
-  if (el->index_type == GPU_INDEX_U8) {
-    return (GLubyte *)0 + v_first;
-  }
-  else if (el->index_type == GPU_INDEX_U16) {
+  if (el->index_type == GPU_INDEX_U16) {
     return (GLushort *)0 + v_first;
   }
 #endif
@@ -641,9 +631,7 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
 #endif
     void *v_first_ofs = elem_offset(el, v_first);
 
-    if (el->use_prim_restart) {
-      primitive_restart_enable(el);
-    }
+    primitive_restart_index(el);
 
     if (GLEW_ARB_base_instance) {
       glDrawElementsInstancedBaseVertexBaseInstance(
@@ -653,10 +641,6 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
       glDrawElementsInstancedBaseVertex(
           batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index);
     }
-
-    if (el->use_prim_restart) {
-      primitive_restart_disable();
-    }
   }
   else {
     if (GLEW_ARB_base_instance) {
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 5f27a0e93cd..c3c05c39c00 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -1372,6 +1372,16 @@ void GPU_state_init(void)
   glDisable(GL_CULL_FACE);
 
   gpu_disable_multisample();
+
+  /* This is a bit dangerous since addons could change this. */
+  glEnable(GL_PRIMITIVE_RESTART);
+  glPrimitiveRestartIndex((GLuint)0xFFFFFFFF);
+
+  /* TODO: Should become default. But needs at least GL 4.3 */
+  if (GLEW_ARB_ES3_compatibility) {
+    /* Takes predecence over GL_PRIMITIVE_RESTART */
+    glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
+  }
 }
 
 /** \name Framebuffer color depth, for selection codes
diff --git a/source/blender/gpu/intern/gpu_element.c b/source/blender/gpu/intern/gpu_element.c
index 0b7f37af522..380de4c4e65 100644
--- a/source/blender/gpu/intern/gpu_element.c
+++ b/source/blender/gpu/intern/gpu_element.c
@@ -33,10 +33,11 @@
 
 #define KEEP_SINGLE_COPY 1
 
+#define RESTART_INDEX 0xFFFFFFFF
+
 static GLenum convert_index_type_to_gl(GPUIndexBufType type)
 {
   static const GLenum table[] = {
-      [GPU_INDEX_U8] = GL_UNSIGNED_BYTE, /* GL has this, Vulkan does not */
       [GPU_INDEX_U16] = GL_UNSIGNED_SHORT,
       [GPU_INDEX_U32] = GL_UNSIGNED_INT,
   };
@@ -47,7 +48,6 @@ uint GPU_indexbuf_size_get(const GPUIndexBuf *elem)
 {
 #if

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list