[Bf-blender-cvs] [bf45a46f814] master: GPU: Fixup and add assert to GPU_VERT_ATTR_NAMES_BUF_LEN

Clément Foucault noreply at git.blender.org
Tue May 14 13:58:00 CEST 2019


Commit: bf45a46f814092cf8b03909ad2d30f4a17b62f10
Author: Clément Foucault
Date:   Tue May 14 13:45:55 2019 +0200
Branches: master
https://developer.blender.org/rBbf45a46f814092cf8b03909ad2d30f4a17b62f10

GPU: Fixup and add assert to GPU_VERT_ATTR_NAMES_BUF_LEN

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

M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/GPU_vertex_format.h
M	source/blender/gpu/intern/gpu_vertex_format.c

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

diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index 3e178e193dc..58d48a18fc5 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -55,7 +55,7 @@ typedef struct GPUVertBuf {
   /** 0 indicates not yet allocated. */
   uint32_t vbo_id;
   /** Usage hint for GL optimisation. */
-  uint usage : 2;
+  GPUUsageType usage : 2;
   /** Data has been touched and need to be reuploaded to GPU. */
   uint dirty : 1;
   unsigned char *data; /* NULL indicates data in VRAM (unmapped) */
diff --git a/source/blender/gpu/GPU_vertex_format.h b/source/blender/gpu/GPU_vertex_format.h
index 74fad51f571..b0ff7c1820f 100644
--- a/source/blender/gpu/GPU_vertex_format.h
+++ b/source/blender/gpu/GPU_vertex_format.h
@@ -28,6 +28,7 @@
 
 #include "GPU_common.h"
 #include "BLI_compiler_compat.h"
+#include "BLI_assert.h"
 
 #define GPU_VERT_ATTR_MAX_LEN 16
 #define GPU_VERT_ATTR_MAX_NAMES 4
@@ -70,6 +71,12 @@ typedef struct GPUVertAttr {
   uchar names[GPU_VERT_ATTR_MAX_NAMES];
 } GPUVertAttr;
 
+BLI_STATIC_ASSERT(GPU_VERT_ATTR_NAMES_BUF_LEN <= 256,
+                  "We use uchar as index inside the name buffer "
+                  "so GPU_VERT_ATTR_NAMES_BUF_LEN needs to be be "
+                  "smaller than GPUVertFormat->name_offset and "
+                  "GPUVertAttr->names maximum value");
+
 typedef struct GPUVertFormat {
   /** 0 to 16 (GPU_VERT_ATTR_MAX_LEN). */
   uint attr_len : 5;
diff --git a/source/blender/gpu/intern/gpu_vertex_format.c b/source/blender/gpu/intern/gpu_vertex_format.c
index 34e46caae7e..37e1f9cf9da 100644
--- a/source/blender/gpu/intern/gpu_vertex_format.c
+++ b/source/blender/gpu/intern/gpu_vertex_format.c
@@ -116,7 +116,7 @@ uint vertex_buffer_size(const GPUVertFormat *format, uint vertex_len)
   return format->stride * vertex_len;
 }
 
-static char copy_attr_name(GPUVertFormat *format, const char *name)
+static uchar copy_attr_name(GPUVertFormat *format, const char *name)
 {
   /* strncpy does 110% of what we need; let's do exactly 100% */
   uchar name_offset = format->name_offset;



More information about the Bf-blender-cvs mailing list