shithub: dav1d

Download patch

ref: 466b524bff228e0096c2a835d3c2abfbf92b825c
parent: 07f818fb12abb444651af71eaedf48da01131bba
author: Ronald S. Bultje <[email protected]>
date: Wed Feb 20 12:15:55 EST 2019

Slightly over-allocate picture buffers

Allows simplified SIMD function implementations that don't exactly
respect picture boundaries when reading picture data. Fixes #251 and
#250.

--- a/include/dav1d/picture.h
+++ b/include/dav1d/picture.h
@@ -34,6 +34,11 @@
 #include "common.h"
 #include "headers.h"
 
+/* Number of bytes to align AND pad picture memory buffers by, so that SIMD
+ * implementations can over-read by a few bytes, and use aligned read/write
+ * instructions. */
+#define DAV1D_PICTURE_ALIGNMENT 32
+
 typedef struct Dav1dPictureParameters {
     int w; ///< width (in pixels)
     int h; ///< height (in pixels)
@@ -85,8 +90,10 @@
     /**
      * Allocate the picture buffer based on the Dav1dPictureParameters.
      *
-     * The data[0], data[1] and data[2] must be 32 byte aligned and with a
-     * pixel width/height multiple of 128 pixels.
+     * The data[0], data[1] and data[2] must be DAV1D_PICTURE_ALIGNMENT byte
+     * aligned and with a pixel width/height multiple of 128 pixels. Any
+     * allocated memory area should also be padded by DAV1D_PICTURE_ALIGNMENT
+     * bytes.
      * data[1] and data[2] must share the same stride[1].
      *
      * This function will be called on the main thread (the thread which calls
--- a/src/picture.c
+++ b/src/picture.c
@@ -59,7 +59,8 @@
     const size_t uv_sz = p->stride[1] * (aligned_h >> ss_ver);
     const size_t pic_size = y_sz + 2 * uv_sz;
 
-    uint8_t *data = dav1d_alloc_aligned(pic_size, 32);
+    uint8_t *data = dav1d_alloc_aligned(pic_size + DAV1D_PICTURE_ALIGNMENT,
+                                        DAV1D_PICTURE_ALIGNMENT);
     if (data == NULL) {
         return -1;
     }