alignment/pitch/width clean-ups
authorBrian <brian.paul@tungstengraphics.com>
Fri, 10 Aug 2007 18:37:20 +0000 (12:37 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 10 Aug 2007 19:03:57 +0000 (13:03 -0600)
src/mesa/pipe/i915simple/i915_regions.c
src/mesa/pipe/softpipe/sp_region.c

index b3bcae5..886b089 100644 (file)
@@ -75,6 +75,7 @@ i915_region_alloc(struct pipe_context *pipe,
 {
    struct i915_context *i915 = i915_context( pipe );
    struct pipe_region *region = calloc(sizeof(*region), 1);
+   const unsigned alignment = 64;
 
    /* Choose a pitch to match hardware requirements - requires 64 byte
     * alignment of render targets.  
@@ -96,7 +97,7 @@ i915_region_alloc(struct pipe_context *pipe,
    region->height = height;     /* needed? */
    region->refcount = 1;
 
-   region->buffer = i915->winsys->buffer_create( i915->winsys, 64 );
+   region->buffer = i915->winsys->buffer_create( i915->winsys, alignment );
 
    i915->winsys->buffer_data( i915->winsys,
                              region->buffer, 
index 1db508f..142d121 100644 (file)
 #include "sp_region.h"
 
 
+/**
+ * Round n up to next multiple.
+ */
+static INLINE unsigned
+round_up(unsigned n, unsigned multiple)
+{
+   return (n + multiple - 1) & ~(multiple - 1);
+}
+
+
 static void
 sp_region_idle(struct pipe_context *pipe, struct pipe_region *region)
 {
@@ -70,23 +80,24 @@ sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region)
 
 static struct pipe_region *
 sp_region_alloc(struct pipe_context *pipe,
-               GLuint cpp, GLuint pitch, GLuint height, GLbitfield flags)
+               GLuint cpp, GLuint width, GLuint height, GLbitfield flags)
 {
    struct softpipe_context *sp = softpipe_context( pipe );
    struct pipe_region *region = calloc(sizeof(*region), 1);
+   const unsigned alignment = 64;
 
    region->cpp = cpp;
-   region->pitch = pitch;
-   region->height = height;     /* needed? */
+   region->pitch = round_up(width, alignment / cpp);
+   region->height = height;
    region->refcount = 1;
 
-   region->buffer = sp->winsys->create_buffer( sp->winsys, 64 );
+   region->buffer = sp->winsys->create_buffer( sp->winsys, alignment );
 
+   /* NULL data --> just allocate the space */
    sp->winsys->buffer_data( sp->winsys,
                            region->buffer, 
-                           pitch * cpp * height, 
+                           region->pitch * cpp * height, 
                            NULL );
-
    return region;
 }