Hi,

today I read an article on phoronix
(http://www.phoronix.com/scan.php?page=news_item&px=MTUyNDY) which
linked to a wiki page (http://wiki.freedesktop.org/dri/NewbieProjects/)
where easy projects to start with were listed. I gave it a shot and
tried to implement the ARB_map_buffer_alignment extensions for all
drivers. Long story short, here is the patch I've created. I'm not
completely sure whether everything I did was what the creator of the
wiki page had in mind. I am especially unsure about the last item. Ofc
it would be very great iff one of you  guys can provide some feedback :)

-Thomas

>From 34ef41b9755366d99610997b223a2a6aada163b1 Mon Sep 17 00:00:00 2001
From: Thomas Prescher <[email protected]>
Date: Tue, 26 Nov 2013 19:45:15 +0000
Subject: [PATCH] Enable ARB_map_buffer_alignment in all drivers

---
 src/gallium/drivers/i915/i915_resource_buffer.c    |  2 +-
 src/gallium/drivers/i915/i915_screen.c             |  1 +
 src/gallium/drivers/ilo/ilo_screen.c               |  2 +-
 src/gallium/drivers/llvmpipe/lp_screen.c           |  1 +
 src/gallium/drivers/llvmpipe/lp_texture.c          |  6 +++---
 src/gallium/drivers/softpipe/sp_screen.c           |  2 +-
 src/gallium/drivers/softpipe/sp_texture.c          |  4 ++--
 src/gallium/drivers/svga/svga_screen.c             |  1 +
 src/mesa/drivers/dri/i915/intel_buffer_objects.c   |  2 +-
 src/mesa/drivers/dri/i965/brw_context.c            |  2 ++
 src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c   |  2 +-
 .../drivers/dri/radeon/radeon_buffer_objects.c     |  2 +-
 src/mesa/main/bufferobj.c                          | 24 ++++++++++------------
 src/mesa/main/context.c                            |  3 +++
 src/mesa/main/extensions.c                         |  2 +-
 src/mesa/state_tracker/st_extensions.c             |  1 +
 16 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/src/gallium/drivers/i915/i915_resource_buffer.c b/src/gallium/drivers/i915/i915_resource_buffer.c
index 80ec43a..fd29524 100644
--- a/src/gallium/drivers/i915/i915_resource_buffer.c
+++ b/src/gallium/drivers/i915/i915_resource_buffer.c
@@ -135,7 +135,7 @@ i915_buffer_create(struct pipe_screen *screen,
    buf->b.vtbl = &i915_buffer_vtbl;
    pipe_reference_init(&buf->b.b.reference, 1);
    buf->b.b.screen = screen;
-   buf->data = align_malloc(template->width0, 16);
+   buf->data = align_malloc(template->width0, 64);
    buf->free_on_destroy = TRUE;
 
    if (!buf->data)
diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
index 77607d0..3bc6ecf 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -213,6 +213,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
    case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
    case PIPE_CAP_TEXTURE_MULTISAMPLE:
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
+      return 64;
    case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
       return 0;
    case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c b/src/gallium/drivers/ilo/ilo_screen.c
index a345b70..466b21c 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -406,7 +406,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_TEXTURE_MULTISAMPLE:
       return false; /* TODO */
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
-      return 0;
+      return 4096;
    case PIPE_CAP_CUBE_MAP_ARRAY:
    case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
       return true;
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
index f61df98..8be1779 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -220,6 +220,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_START_INSTANCE:
    case PIPE_CAP_TEXTURE_MULTISAMPLE:
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
+      return 64;
    case PIPE_CAP_CUBE_MAP_ARRAY:
       return 0;
    case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index 0088b6a..fa75df8 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -200,7 +200,7 @@ llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen,
                                           lpr->base.bind,
                                           lpr->base.format,
                                           width, height,
-                                          16,
+                                          64,
                                           &lpr->row_stride[0] );
 
    if (lpr->dt == NULL)
@@ -261,7 +261,7 @@ llvmpipe_resource_create(struct pipe_screen *_screen,
        * read/write always LP_RASTER_BLOCK_SIZE pixels, but the element
        * offset doesn't need to be aligned to LP_RASTER_BLOCK_SIZE.
        */
-      lpr->data = align_malloc(bytes + (LP_RASTER_BLOCK_SIZE - 1) * 4 * sizeof(float), 16);
+      lpr->data = align_malloc(bytes + (LP_RASTER_BLOCK_SIZE - 1) * 4 * sizeof(float), 64);
       /*
        * buffers don't really have stride but it's probably safer
        * (for code doing same calculations for buffers and textures)
@@ -746,7 +746,7 @@ llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
 static void
 alloc_image_data(struct llvmpipe_resource *lpr)
 {
-   uint alignment = MAX2(16, util_cpu_caps.cacheline);
+   uint alignment = MAX2(64, util_cpu_caps.cacheline);
    uint level;
    uint offset = 0;
 
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 47ef20e..022b5bf 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -169,7 +169,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_START_INSTANCE:
    case PIPE_CAP_TEXTURE_MULTISAMPLE:
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
-      return 0;
+      return 64;
    case PIPE_CAP_QUERY_TIMESTAMP:
    case PIPE_CAP_CUBE_MAP_ARRAY:
       return 1;
diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
index 370f2b4..d5d0d9d 100644
--- a/src/gallium/drivers/softpipe/sp_texture.c
+++ b/src/gallium/drivers/softpipe/sp_texture.c
@@ -88,7 +88,7 @@ softpipe_resource_layout(struct pipe_screen *screen,
       return FALSE;
 
    if (allocate) {
-      spr->data = align_malloc(buffer_size, 16);
+      spr->data = align_malloc(buffer_size, 64);
       return spr->data != NULL;
    }
    else {
@@ -128,7 +128,7 @@ softpipe_displaytarget_layout(struct pipe_screen *screen,
                                           spr->base.format,
                                           spr->base.width0, 
                                           spr->base.height0,
-                                          16,
+                                          64,
                                           &spr->stride[0] );
 
    return spr->dt != NULL;
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index c16be16..9e67aa0 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -262,6 +262,7 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_QUERY_TIMESTAMP:
    case PIPE_CAP_TEXTURE_MULTISAMPLE:
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
+      return 64;
    case PIPE_CAP_CUBE_MAP_ARRAY:
    case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
    case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
diff --git a/src/mesa/drivers/dri/i915/intel_buffer_objects.c b/src/mesa/drivers/dri/i915/intel_buffer_objects.c
index bc58c70..c6b08e0 100644
--- a/src/mesa/drivers/dri/i915/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/i915/intel_buffer_objects.c
@@ -137,7 +137,7 @@ intel_bufferobj_data(struct gl_context * ctx,
        * contents anyway.
        */
       if (target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER) {
-	 intel_obj->sys_buffer = malloc(size);
+	 intel_obj->sys_buffer = _mesa_align_malloc(size, ctx->Const.MinMapBufferAlignment);
 	 if (intel_obj->sys_buffer != NULL) {
 	    if (data != NULL)
 	       memcpy(intel_obj->sys_buffer, data, size);
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 6e09077..3eaa902 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -282,6 +282,8 @@ brw_initialize_context_constants(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
 
+   ctx->Const.MinMapBufferAlignment = 4096;
+
    ctx->Const.QueryCounterBits.Timestamp = 36;
 
    ctx->Const.StripTextureBorder = true;
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
index 717c0b8..ef41548 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
@@ -95,7 +95,7 @@ nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size
 	} else {
 		/* Get a hardware BO */
 		ret = nouveau_bo_new(context_dev(ctx),
-				     NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
+				     NOUVEAU_BO_GART | NOUVEAU_BO_MAP, ctx->Const.MinMapBufferAlignment,
 				     size, NULL, &nbo->bo);
 		assert(!ret);
 	}
diff --git a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
index 40a16c3..ba7ab37 100644
--- a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
+++ b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
@@ -103,7 +103,7 @@ radeonBufferData(struct gl_context * ctx,
         radeon_obj->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                         0,
                                         size,
-                                        32,
+                                        ctx->Const.MinMapBufferAlignment,
                                         RADEON_GEM_DOMAIN_GTT,
                                         0);
 
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 8b5ebc4..a40b5f2 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -424,21 +424,19 @@ _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
 
    (void) ctx; (void) target;
 
-   new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
-   if (new_data) {
-      bufObj->Data = (GLubyte *) new_data;
-      bufObj->Size = size;
-      bufObj->Usage = usage;
-
-      if (data) {
-	 memcpy( bufObj->Data, data, size );
-      }
-
-      return GL_TRUE;
+   new_data = _mesa_align_malloc(size, ctx->Const.MinMapBufferAlignment );
+   if(!new_data) {
+       return GL_FALSE;
    }
-   else {
-      return GL_FALSE;
+   bufObj->Data = (GLubyte *) new_data;
+   bufObj->Size = size;
+   bufObj->Usage = usage;
+
+   if (data) {
+       memcpy( bufObj->Data, data, size );
    }
+
+   return GL_TRUE;
 }
 
 
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 87a4a35..13295b1 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -587,6 +587,9 @@ _mesa_init_constants(struct gl_context *ctx)
    ctx->Const.MaxViewportWidth = MAX_VIEWPORT_WIDTH;
    ctx->Const.MaxViewportHeight = MAX_VIEWPORT_HEIGHT;
 
+   /** GL_ARB_map_buffer_alignment **/
+   ctx->Const.MinMapBufferAlignment = 64;
+
    /** GL_ARB_uniform_buffer_object */
    ctx->Const.MaxCombinedUniformBlocks = 36;
    ctx->Const.MaxUniformBufferBindings = 36;
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 42da905..eb978ed 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -108,7 +108,7 @@ static const struct extension extension_table[] = {
    { "GL_ARB_instanced_arrays",                    o(ARB_instanced_arrays),                    GL,             2008 },
    { "GL_ARB_internalformat_query",                o(ARB_internalformat_query),                GL,             2011 },
    { "GL_ARB_invalidate_subdata",                  o(dummy_true),                              GL,             2012 },
-   { "GL_ARB_map_buffer_alignment",                o(ARB_map_buffer_alignment),                GL,             2011 },
+   /* { "GL_ARB_map_buffer_alignment",                o(dummy_true),                              GL,             2011 }, */
    { "GL_ARB_map_buffer_range",                    o(ARB_map_buffer_range),                    GL,             2008 },
    { "GL_ARB_multi_draw_indirect",                 o(ARB_draw_indirect),                       GLC,            2012 },
    { "GL_ARB_multisample",                         o(dummy_true),                              GLL,            1994 },
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index cd10a0c..7aa8f75 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -532,6 +532,7 @@ void st_init_extensions(struct st_context *st)
    ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
    ctx->Extensions.ARB_internalformat_query = GL_TRUE;
    ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
+   ctx->Extensions.ARB_map_buffer_alignment = GL_TRUE;
    ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
    ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
    ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
-- 
1.8.3.2

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to