gallium: fix behavior of pipe_buffer_map_range
authorMarek Olšák <maraeo@gmail.com>
Sun, 1 Jan 2012 16:12:35 +0000 (17:12 +0100)
committerMarek Olšák <maraeo@gmail.com>
Thu, 5 Jan 2012 17:29:11 +0000 (18:29 +0100)
To match what transfer_map returns. Really, subtracting the offset leads
to bugs if someone expects it to work exactly like transfer_map.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_inlines.h
src/gallium/auxiliary/util/u_upload_mgr.c
src/gallium/drivers/svga/svga_state_vs.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_draw.c

index 44283909aec42559feaefa1f7d76b68faeeb20e7..9660cdc6eaeedebac1216b9d632e75075f99960a 100644 (file)
@@ -252,10 +252,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
       return NULL;
    }
 
-   /* Match old screen->buffer_map_range() behaviour, return pointer
-    * to where the beginning of the buffer would be:
-    */
-   return (void *)((char *)map - offset);
+   return map;
 }
 
 
@@ -374,7 +371,7 @@ pipe_buffer_read(struct pipe_context *pipe,
                                         &src_transfer);
 
    if (map)
-      memcpy(data, map + offset, size);
+      memcpy(data, map, size);
 
    pipe_buffer_unmap(pipe, src_transfer);
 }
index a2319d0c4361942e39c08ee4a0fbc11f5f9c0be0..936e881d9c01f2643addcff7629261c3bd4b3383 100644 (file)
@@ -192,6 +192,8 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
          *ptr = NULL;
          return PIPE_ERROR_OUT_OF_MEMORY;
       }
+
+      upload->map -= offset;
    }
 
    assert(offset < upload->buffer->width0);
@@ -261,7 +263,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
    ret = u_upload_data( upload,
                         min_out_offset,
                         size,
-                        map + offset,
+                        map,
                         out_offset,
                         outbuf, flushed );
 
index 3d3caea74495e093019aee4922486cad3a4d9f25..b82e68556e419242e21b794c1301c07f8683f74e 100644 (file)
@@ -228,6 +228,7 @@ update_zero_stride( struct svga_context *svga,
                                                util_format_get_blocksize(vel->src_format),
                                                PIPE_TRANSFER_READ,
                                               &transfer);
+         mapped_buffer = (uint8_t*)mapped_buffer - vel->src_offset;
 
          translate->set_buffer(translate, vel->vertex_buffer_index,
                                mapped_buffer,
index adac92f2c342bac334cd7e07485ea49c2e39c790..6d95d57c1b36ddde16bd6543f5e43c7e36141702 100644 (file)
@@ -290,10 +290,6 @@ st_bufferobj_map_range(struct gl_context *ctx,
                                         offset, length,
                                         flags,
                                         &st_obj->transfer);
-   if (obj->Pointer) {
-      obj->Pointer = (ubyte *) obj->Pointer + offset;
-   }
-
    if (obj->Pointer) {
       obj->Offset = offset;
       obj->Length = length;
index a21160c956d6cca70d9345b69fb1021fe2eb4236..6d6fc858de4633dd81f017cf801a131f7f879313 100644 (file)
@@ -824,16 +824,17 @@ handle_fallback_primitive_restart(struct pipe_context *pipe,
                                   start * ibuffer->index_size, /* start */
                                   count * ibuffer->index_size, /* length */
                                   PIPE_TRANSFER_READ, &transfer);
+      if (!ptr)
+         return;
+
+      ptr = (uint8_t*)ptr + (ibuffer->offset - start * ibuffer->index_size);
    }
    else {
       ptr = ib->ptr;
+      if (!ptr)
+         return;
    }
 
-   if (!ptr)
-      return;
-
-   ptr = ADD_POINTERS(ptr, ibuffer->offset);
-
    sub_prims = find_sub_primitives(ptr, ibuffer->index_size,
                                    0, count, orig_info->restart_index,
                                    &num_sub_prims);