[vlc-commits] opengl: fix buffer alignment for direct rendering

Thomas Guillem git at videolan.org
Wed Nov 7 14:44:05 CET 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Nov  7 11:53:50 2018 +0100| [87f5ba69007bf7b14623c76fc8dab122878ce171] | committer: Thomas Guillem

opengl: fix buffer alignment for direct rendering

We don't need to align the buffer size. It seems that I confused memory
alignment and pitch alignment.

Make sure that glMapBuffer return memory aligned buffer pointers (64 is the
minimum for OpenGL).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=87f5ba69007bf7b14623c76fc8dab122878ce171
---

 modules/video_output/opengl/converter_sw.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/modules/video_output/opengl/converter_sw.c b/modules/video_output/opengl/converter_sw.c
index b23a65e15d..ae37d4929f 100644
--- a/modules/video_output/opengl/converter_sw.c
+++ b/modules/video_output/opengl/converter_sw.c
@@ -29,6 +29,10 @@
 #include <vlc_common.h>
 #include "internal.h"
 
+#ifndef GL_MIN_MAP_BUFFER_ALIGNMENT
+# define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC
+#endif
+
 #ifndef GL_UNPACK_ROW_LENGTH
 # define GL_UNPACK_ROW_LENGTH 0x0CF2
 #endif
@@ -160,7 +164,7 @@ pbo_picture_create(const opengl_tex_converter_t *tc, bool direct_rendering)
             picture_Release(pic);
             return NULL;
         }
-        picsys->bytes[i] = (p->i_pitch * p->i_lines) + 15 / 16 * 16;
+        picsys->bytes[i] = p->i_pitch * p->i_lines;
     }
     return pic;
 }
@@ -263,7 +267,7 @@ persistent_map(const opengl_tex_converter_t *tc, picture_t *pic)
 
         pic->p[i].p_pixels =
             tc->vt->MapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, picsys->bytes[i],
-                                    access | GL_MAP_FLUSH_EXPLICIT_BIT);
+                                   access | GL_MAP_FLUSH_EXPLICIT_BIT);
 
         if (pic->p[i].p_pixels == NULL)
         {
@@ -278,6 +282,11 @@ persistent_map(const opengl_tex_converter_t *tc, picture_t *pic)
             memset(picsys->buffers, 0, PICTURE_PLANE_MAX * sizeof(GLuint));
             return VLC_EGENERIC;
         }
+#ifndef NDEBUG
+        GLint min_align = 0;
+        tc->vt->GetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &min_align);
+        assert(((uintptr_t)pic->p[i].p_pixels) % min_align == 0);
+#endif
     }
     return VLC_SUCCESS;
 }
@@ -609,7 +618,9 @@ opengl_tex_converter_generic_init(opengl_tex_converter_t *tc, bool allow_dr)
             (vlc_gl_StrHasToken(tc->glexts, "GL_ARB_buffer_storage") ||
              vlc_gl_StrHasToken(tc->glexts, "GL_EXT_buffer_storage"));
 
-        supports_map_persistent = has_bs && tc->gl->module
+        GLint min_align = 0;
+        tc->vt->GetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &min_align);
+        supports_map_persistent = min_align >= 64 && has_bs && tc->gl->module
             && tc->vt->BufferStorage && tc->vt->MapBufferRange && tc->vt->FlushMappedBufferRange
             && tc->vt->UnmapBuffer && tc->vt->FenceSync && tc->vt->DeleteSync
             && tc->vt->ClientWaitSync;



More information about the vlc-commits mailing list