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