u_linear.c revision ea4bf267e4b023b08043f91ac44592fed1736e7f
1 2#include "util/u_debug.h" 3#include "u_linear.h" 4 5void 6pipe_linear_to_tile(size_t src_stride, const void *src_ptr, 7 struct pipe_tile_info *t, void *dst_ptr) 8{ 9 int x, y, z; 10 char *ptr; 11 size_t bytes = t->cols * t->block.size; 12 char *dst_ptr2 = (char *) dst_ptr; 13 14 assert(pipe_linear_check_tile(t)); 15 16 /* lets write lineary to the tiled buffer */ 17 for (y = 0; y < t->tiles_y; y++) { 18 for (x = 0; x < t->tiles_x; x++) { 19 /* this inner loop could be replace with SSE magic */ 20 ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x; 21 for (z = 0; z < t->rows; z++) { 22 memcpy(dst_ptr2, ptr, bytes); 23 dst_ptr2 += bytes; 24 ptr += src_stride; 25 } 26 } 27 } 28} 29 30void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, 31 size_t dst_stride, void *dst_ptr) 32{ 33 int x, y, z; 34 char *ptr; 35 size_t bytes = t->cols * t->block.size; 36 const char *src_ptr2 = (const char *) src_ptr; 37 38 /* lets read lineary from the tiled buffer */ 39 for (y = 0; y < t->tiles_y; y++) { 40 for (x = 0; x < t->tiles_x; x++) { 41 /* this inner loop could be replace with SSE magic */ 42 ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x; 43 for (z = 0; z < t->rows; z++) { 44 memcpy(ptr, src_ptr2, bytes); 45 src_ptr2 += bytes; 46 ptr += dst_stride; 47 } 48 } 49 } 50} 51 52void 53pipe_linear_fill_info(struct pipe_tile_info *t, 54 const struct pipe_format_block *block, 55 unsigned tile_width, unsigned tile_height, 56 unsigned tiles_x, unsigned tiles_y) 57{ 58 t->block = *block; 59 60 t->tile.width = tile_width; 61 t->tile.height = tile_height; 62 t->cols = t->tile.width / t->block.width; 63 t->rows = t->tile.height / t->block.height; 64 t->tile.size = t->cols * t->rows * t->block.size; 65 66 t->tiles_x = tiles_x; 67 t->tiles_y = tiles_y; 68 t->stride = t->cols * t->tiles_x * t->block.size; 69 t->size = t->tiles_x * t->tiles_y * t->tile.size; 70} 71