[Bf-blender-cvs] [092962cf72e] master: GPU: Enforce Uniform buffer alignment to 16bytes

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


Commit: 092962cf72e77abb3693f9f337b341bfc066d711
Author: Clément Foucault
Date:   Wed May 29 16:57:09 2019 +0200
Branches: master
https://developer.blender.org/rB092962cf72e77abb3693f9f337b341bfc066d711

GPU: Enforce Uniform buffer alignment to 16bytes

This seems to be a requirement and remove some errors in
renderdoc.

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

M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/intern/gpu_uniformbuffer.c
M	source/blender/makesdna/DNA_lightprobe_types.h

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

diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index 2e652dff232..6b82c7aa915 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -401,8 +401,15 @@ typedef struct EEVEE_ShadowRender {
   int shadow_samples_len;
   float shadow_samples_len_inv;
   float exponent;
+  float pad2;
 } EEVEE_ShadowRender;
 
+BLI_STATIC_ASSERT_ALIGN(EEVEE_Light, 16)
+BLI_STATIC_ASSERT_ALIGN(EEVEE_Shadow, 16)
+BLI_STATIC_ASSERT_ALIGN(EEVEE_ShadowCube, 16)
+BLI_STATIC_ASSERT_ALIGN(EEVEE_ShadowCascade, 16)
+BLI_STATIC_ASSERT_ALIGN(EEVEE_ShadowRender, 16)
+
 /* This is just a really long bitflag with special function to access it. */
 #define MAX_LIGHTBITS_FIELDS (MAX_LIGHT / 8)
 typedef struct EEVEE_LightBits {
@@ -685,8 +692,12 @@ typedef struct EEVEE_CommonUniformBuffer {
   int hiz_mip_offset; /* int */
   int ray_type;       /* int */
   float ray_depth;    /* float */
+
+  float pad_common_ubo;
 } EEVEE_CommonUniformBuffer;
 
+BLI_STATIC_ASSERT_ALIGN(EEVEE_CommonUniformBuffer, 16)
+
 /* ray_type (keep in sync with rayType) */
 #define EEVEE_RAY_CAMERA 0
 #define EEVEE_RAY_SHADOW 1
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 007a13a06ef..f5051a1d767 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -262,8 +262,11 @@ typedef struct GPUSssKernelData {
   float kernel[SSS_SAMPLES][4];
   float param[3], max_radius;
   int samples;
+  int pad[3];
 } GPUSssKernelData;
 
+BLI_STATIC_ASSERT_ALIGN(GPUSssKernelData, 16)
+
 static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
 {
   float step = 2.0f / (float)(count - 1);
diff --git a/source/blender/gpu/intern/gpu_uniformbuffer.c b/source/blender/gpu/intern/gpu_uniformbuffer.c
index d7766c51f38..46dcc6c6f78 100644
--- a/source/blender/gpu/intern/gpu_uniformbuffer.c
+++ b/source/blender/gpu/intern/gpu_uniformbuffer.c
@@ -76,6 +76,9 @@ static void gpu_uniformbuffer_initialize(GPUUniformBuffer *ubo, const void *data
 
 GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_out[256])
 {
+  /* Make sure that UBO is padded to size of vec4 */
+  BLI_assert((size % 16) == 0);
+
   GPUUniformBuffer *ubo = MEM_callocN(sizeof(GPUUniformBufferStatic), "GPUUniformBufferStatic");
   ubo->size = size;
   ubo->bindpoint = -1;
@@ -149,6 +152,9 @@ GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(ListBase *inputs, char err_ou
     ubo->buffer.size += gputype * sizeof(float);
   }
 
+  /* Round up to size of vec4 */
+  ubo->buffer.size = ((ubo->buffer.size + 15) / 16) * 16;
+
   /* Allocate the data. */
   ubo->data = MEM_mallocN(ubo->buffer.size, __func__);
 
diff --git a/source/blender/makesdna/DNA_lightprobe_types.h b/source/blender/makesdna/DNA_lightprobe_types.h
index 92b343fbeb9..c5121481f88 100644
--- a/source/blender/makesdna/DNA_lightprobe_types.h
+++ b/source/blender/makesdna/DNA_lightprobe_types.h
@@ -25,6 +25,8 @@
 #include "DNA_listBase.h"
 #include "DNA_ID.h"
 
+#include "BLI_assert.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -141,6 +143,10 @@ typedef struct LightGridCache {
   float visibility_bias, visibility_bleed, visibility_range, _pad5;
 } LightGridCache;
 
+/* Theses are used as ubo data. They need to be aligned to size of vec4. */
+BLI_STATIC_ASSERT_ALIGN(LightProbeCache, 16)
+BLI_STATIC_ASSERT_ALIGN(LightGridCache, 16)
+
 /* ------ Eevee Lightcache ------- */
 
 typedef struct LightCacheTexture {



More information about the Bf-blender-cvs mailing list