From bf45a46f814092cf8b03909ad2d30f4a17b62f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 14 May 2019 13:45:55 +0200 Subject: GPU: Fixup and add assert to GPU_VERT_ATTR_NAMES_BUF_LEN --- source/blender/gpu/GPU_vertex_buffer.h | 2 +- source/blender/gpu/GPU_vertex_format.h | 7 +++++++ source/blender/gpu/intern/gpu_vertex_format.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'source/blender/gpu') 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; -- cgit v1.2.3