1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2009 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * Functions for converting tiled data to linear and vice versa. 30848b8605Smrg */ 31848b8605Smrg 32848b8605Smrg 33848b8605Smrg#include "util/u_debug.h" 34848b8605Smrg#include "u_linear.h" 35848b8605Smrg 36848b8605Smrgvoid 37848b8605Smrgpipe_linear_to_tile(size_t src_stride, const void *src_ptr, 38848b8605Smrg struct pipe_tile_info *t, void *dst_ptr) 39848b8605Smrg{ 40b8e80941Smrg unsigned x, y, z; 41848b8605Smrg char *ptr; 42848b8605Smrg size_t bytes = t->cols * t->block.size; 43848b8605Smrg char *dst_ptr2 = (char *) dst_ptr; 44848b8605Smrg 45848b8605Smrg assert(pipe_linear_check_tile(t)); 46848b8605Smrg 47b8e80941Smrg /* lets write linearly to the tiled buffer */ 48848b8605Smrg for (y = 0; y < t->tiles_y; y++) { 49848b8605Smrg for (x = 0; x < t->tiles_x; x++) { 50848b8605Smrg /* this inner loop could be replace with SSE magic */ 51848b8605Smrg ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x; 52848b8605Smrg for (z = 0; z < t->rows; z++) { 53848b8605Smrg memcpy(dst_ptr2, ptr, bytes); 54848b8605Smrg dst_ptr2 += bytes; 55848b8605Smrg ptr += src_stride; 56848b8605Smrg } 57848b8605Smrg } 58848b8605Smrg } 59848b8605Smrg} 60848b8605Smrg 61848b8605Smrgvoid pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, 62848b8605Smrg size_t dst_stride, void *dst_ptr) 63848b8605Smrg{ 64b8e80941Smrg unsigned x, y, z; 65848b8605Smrg char *ptr; 66848b8605Smrg size_t bytes = t->cols * t->block.size; 67848b8605Smrg const char *src_ptr2 = (const char *) src_ptr; 68848b8605Smrg 69b8e80941Smrg /* lets read linearly from the tiled buffer */ 70848b8605Smrg for (y = 0; y < t->tiles_y; y++) { 71848b8605Smrg for (x = 0; x < t->tiles_x; x++) { 72848b8605Smrg /* this inner loop could be replace with SSE magic */ 73848b8605Smrg ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x; 74848b8605Smrg for (z = 0; z < t->rows; z++) { 75848b8605Smrg memcpy(ptr, src_ptr2, bytes); 76848b8605Smrg src_ptr2 += bytes; 77848b8605Smrg ptr += dst_stride; 78848b8605Smrg } 79848b8605Smrg } 80848b8605Smrg } 81848b8605Smrg} 82848b8605Smrg 83848b8605Smrgvoid 84848b8605Smrgpipe_linear_fill_info(struct pipe_tile_info *t, 85848b8605Smrg const struct u_linear_format_block *block, 86848b8605Smrg unsigned tile_width, unsigned tile_height, 87848b8605Smrg unsigned tiles_x, unsigned tiles_y) 88848b8605Smrg{ 89848b8605Smrg t->block = *block; 90848b8605Smrg 91848b8605Smrg t->tile.width = tile_width; 92848b8605Smrg t->tile.height = tile_height; 93848b8605Smrg t->cols = t->tile.width / t->block.width; 94848b8605Smrg t->rows = t->tile.height / t->block.height; 95848b8605Smrg t->tile.size = t->cols * t->rows * t->block.size; 96848b8605Smrg 97848b8605Smrg t->tiles_x = tiles_x; 98848b8605Smrg t->tiles_y = tiles_y; 99848b8605Smrg t->stride = t->cols * t->tiles_x * t->block.size; 100848b8605Smrg t->size = t->tiles_x * t->tiles_y * t->tile.size; 101848b8605Smrg} 102