1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci/** 29bf215546Sopenharmony_ci * Functions for converting tiled data to linear and vice versa. 30bf215546Sopenharmony_ci */ 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "util/u_debug.h" 34bf215546Sopenharmony_ci#include "u_linear.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_civoid 37bf215546Sopenharmony_cipipe_linear_to_tile(size_t src_stride, const void *src_ptr, 38bf215546Sopenharmony_ci struct pipe_tile_info *t, void *dst_ptr) 39bf215546Sopenharmony_ci{ 40bf215546Sopenharmony_ci unsigned x, y, z; 41bf215546Sopenharmony_ci char *ptr; 42bf215546Sopenharmony_ci size_t bytes = t->cols * t->block.size; 43bf215546Sopenharmony_ci char *dst_ptr2 = (char *) dst_ptr; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci assert(pipe_linear_check_tile(t)); 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci /* lets write linearly to the tiled buffer */ 48bf215546Sopenharmony_ci for (y = 0; y < t->tiles_y; y++) { 49bf215546Sopenharmony_ci for (x = 0; x < t->tiles_x; x++) { 50bf215546Sopenharmony_ci /* this inner loop could be replace with SSE magic */ 51bf215546Sopenharmony_ci ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x; 52bf215546Sopenharmony_ci for (z = 0; z < t->rows; z++) { 53bf215546Sopenharmony_ci memcpy(dst_ptr2, ptr, bytes); 54bf215546Sopenharmony_ci dst_ptr2 += bytes; 55bf215546Sopenharmony_ci ptr += src_stride; 56bf215546Sopenharmony_ci } 57bf215546Sopenharmony_ci } 58bf215546Sopenharmony_ci } 59bf215546Sopenharmony_ci} 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_civoid pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, 62bf215546Sopenharmony_ci size_t dst_stride, void *dst_ptr) 63bf215546Sopenharmony_ci{ 64bf215546Sopenharmony_ci unsigned x, y, z; 65bf215546Sopenharmony_ci char *ptr; 66bf215546Sopenharmony_ci size_t bytes = t->cols * t->block.size; 67bf215546Sopenharmony_ci const char *src_ptr2 = (const char *) src_ptr; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci /* lets read linearly from the tiled buffer */ 70bf215546Sopenharmony_ci for (y = 0; y < t->tiles_y; y++) { 71bf215546Sopenharmony_ci for (x = 0; x < t->tiles_x; x++) { 72bf215546Sopenharmony_ci /* this inner loop could be replace with SSE magic */ 73bf215546Sopenharmony_ci ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x; 74bf215546Sopenharmony_ci for (z = 0; z < t->rows; z++) { 75bf215546Sopenharmony_ci memcpy(ptr, src_ptr2, bytes); 76bf215546Sopenharmony_ci src_ptr2 += bytes; 77bf215546Sopenharmony_ci ptr += dst_stride; 78bf215546Sopenharmony_ci } 79bf215546Sopenharmony_ci } 80bf215546Sopenharmony_ci } 81bf215546Sopenharmony_ci} 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_civoid 84bf215546Sopenharmony_cipipe_linear_fill_info(struct pipe_tile_info *t, 85bf215546Sopenharmony_ci const struct u_linear_format_block *block, 86bf215546Sopenharmony_ci unsigned tile_width, unsigned tile_height, 87bf215546Sopenharmony_ci unsigned tiles_x, unsigned tiles_y) 88bf215546Sopenharmony_ci{ 89bf215546Sopenharmony_ci t->block = *block; 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci t->tile.width = tile_width; 92bf215546Sopenharmony_ci t->tile.height = tile_height; 93bf215546Sopenharmony_ci t->cols = t->tile.width / t->block.width; 94bf215546Sopenharmony_ci t->rows = t->tile.height / t->block.height; 95bf215546Sopenharmony_ci t->tile.size = t->cols * t->rows * t->block.size; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci t->tiles_x = tiles_x; 98bf215546Sopenharmony_ci t->tiles_y = tiles_y; 99bf215546Sopenharmony_ci t->stride = t->cols * t->tiles_x * t->block.size; 100bf215546Sopenharmony_ci t->size = t->tiles_x * t->tiles_y * t->tile.size; 101bf215546Sopenharmony_ci} 102