[Bf-blender-cvs] [aa32e7a2f31] master: Cleanup: GPUVertBuf: Replace TRUST_NO_ONE by BLI_asserts and ifdef DEBUG

Clément Foucault noreply at git.blender.org
Mon Sep 7 14:03:19 CEST 2020


Commit: aa32e7a2f31486503edb430b15ce31a819e02702
Author: Clément Foucault
Date:   Mon Sep 7 02:12:59 2020 +0200
Branches: master
https://developer.blender.org/rBaa32e7a2f31486503edb430b15ce31a819e02702

Cleanup: GPUVertBuf: Replace TRUST_NO_ONE by BLI_asserts and ifdef DEBUG

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

M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/intern/gpu_vertex_buffer.cc

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

diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index e42d6c47b58..80f0501edc0 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -107,7 +107,7 @@ typedef struct GPUVertBufRaw {
   uint stride;
   unsigned char *data;
   unsigned char *data_init;
-#if TRUST_NO_ONE
+#ifdef DEBUG
   /* Only for overflow check */
   unsigned char *_data_end;
 #endif
@@ -117,9 +117,7 @@ GPU_INLINE void *GPU_vertbuf_raw_step(GPUVertBufRaw *a)
 {
   unsigned char *data = a->data;
   a->data += a->stride;
-#if TRUST_NO_ONE
-  assert(data < a->_data_end);
-#endif
+  BLI_assert(data < a->_data_end);
   return (void *)data;
 }
 
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.cc b/source/blender/gpu/intern/gpu_vertex_buffer.cc
index 62c07761b4c..4cc2af889e6 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.cc
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.cc
@@ -193,7 +193,6 @@ void GPU_vertbuf_data_len_set(GPUVertBuf *verts_, uint v_len)
   VertBuf *verts = unwrap(verts_);
   BLI_assert(verts->data != NULL); /* Only for dynamic data. */
   BLI_assert(v_len <= verts->vertex_alloc);
-
   verts->vertex_len = v_len;
 }
 
@@ -202,28 +201,21 @@ void GPU_vertbuf_attr_set(GPUVertBuf *verts_, uint a_idx, uint v_idx, const void
   VertBuf *verts = unwrap(verts_);
   const GPUVertFormat *format = &verts->format;
   const GPUVertAttr *a = &format->attrs[a_idx];
-
-#if TRUST_NO_ONE
-  assert(a_idx < format->attr_len);
-  assert(v_idx < verts->vertex_alloc);
-  assert(verts->data != NULL);
-#endif
+  BLI_assert(v_idx < verts->vertex_alloc);
+  BLI_assert(a_idx < format->attr_len);
+  BLI_assert(verts->data != NULL);
   verts->flag |= GPU_VERTBUF_DATA_DIRTY;
-  memcpy((uchar *)verts->data + a->offset + v_idx * format->stride, data, a->sz);
+  memcpy(verts->data + a->offset + v_idx * format->stride, data, a->sz);
 }
 
 void GPU_vertbuf_attr_fill(GPUVertBuf *verts_, uint a_idx, const void *data)
 {
   VertBuf *verts = unwrap(verts_);
   const GPUVertFormat *format = &verts->format;
+  BLI_assert(a_idx < format->attr_len);
   const GPUVertAttr *a = &format->attrs[a_idx];
-
-#if TRUST_NO_ONE
-  assert(a_idx < format->attr_len);
-#endif
   const uint stride = a->sz; /* tightly packed input data */
   verts->flag |= GPU_VERTBUF_DATA_DIRTY;
-
   GPU_vertbuf_attr_fill_stride(verts_, a_idx, stride, data);
 }
 
@@ -232,13 +224,10 @@ void GPU_vertbuf_vert_set(GPUVertBuf *verts_, uint v_idx, const void *data)
 {
   VertBuf *verts = unwrap(verts_);
   const GPUVertFormat *format = &verts->format;
-
-#if TRUST_NO_ONE
-  assert(v_idx < verts->vertex_alloc);
-  assert(verts->data != NULL);
-#endif
+  BLI_assert(v_idx < verts->vertex_alloc);
+  BLI_assert(verts->data != NULL);
   verts->flag |= GPU_VERTBUF_DATA_DIRTY;
-  memcpy((uchar *)verts->data + v_idx * format->stride, data, format->stride);
+  memcpy(verts->data + v_idx * format->stride, data, format->stride);
 }
 
 void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts_, uint a_idx, uint stride, const void *data)
@@ -246,11 +235,8 @@ void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts_, uint a_idx, uint stride, c
   VertBuf *verts = unwrap(verts_);
   const GPUVertFormat *format = &verts->format;
   const GPUVertAttr *a = &format->attrs[a_idx];
-
-#if TRUST_NO_ONE
-  assert(a_idx < format->attr_len);
-  assert(verts->data != NULL);
-#endif
+  BLI_assert(a_idx < format->attr_len);
+  BLI_assert(verts->data != NULL);
   verts->flag |= GPU_VERTBUF_DATA_DIRTY;
   const uint vertex_len = verts->vertex_len;
 
@@ -261,9 +247,8 @@ void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts_, uint a_idx, uint stride, c
   else {
     /* we must copy it per vertex */
     for (uint v = 0; v < vertex_len; v++) {
-      memcpy((uchar *)verts->data + a->offset + v * format->stride,
-             (const uchar *)data + v * stride,
-             a->sz);
+      memcpy(
+          verts->data + a->offset + v * format->stride, (const uchar *)data + v * stride, a->sz);
     }
   }
 }
@@ -273,11 +258,8 @@ void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *verts_, uint a_idx, GPUVertBufRaw
   VertBuf *verts = unwrap(verts_);
   const GPUVertFormat *format = &verts->format;
   const GPUVertAttr *a = &format->attrs[a_idx];
-
-#if TRUST_NO_ONE
-  assert(a_idx < format->attr_len);
-  assert(verts->data != NULL);
-#endif
+  BLI_assert(a_idx < format->attr_len);
+  BLI_assert(verts->data != NULL);
 
   verts->flag |= GPU_VERTBUF_DATA_DIRTY;
   verts->flag &= ~GPU_VERTBUF_DATA_UPLOADED;
@@ -285,7 +267,7 @@ void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *verts_, uint a_idx, GPUVertBufRaw
   access->stride = format->stride;
   access->data = (uchar *)verts->data + a->offset;
   access->data_init = access->data;
-#if TRUST_NO_ONE
+#ifdef DEBUG
   access->_data_end = access->data_init + (size_t)(verts->vertex_alloc * format->stride);
 #endif
 }



More information about the Bf-blender-cvs mailing list