Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_linear.c
4561 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* Functions for converting tiled data to linear and vice versa.29*/303132#include "util/u_debug.h"33#include "u_linear.h"3435void36pipe_linear_to_tile(size_t src_stride, const void *src_ptr,37struct pipe_tile_info *t, void *dst_ptr)38{39unsigned x, y, z;40char *ptr;41size_t bytes = t->cols * t->block.size;42char *dst_ptr2 = (char *) dst_ptr;4344assert(pipe_linear_check_tile(t));4546/* lets write linearly to the tiled buffer */47for (y = 0; y < t->tiles_y; y++) {48for (x = 0; x < t->tiles_x; x++) {49/* this inner loop could be replace with SSE magic */50ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x;51for (z = 0; z < t->rows; z++) {52memcpy(dst_ptr2, ptr, bytes);53dst_ptr2 += bytes;54ptr += src_stride;55}56}57}58}5960void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,61size_t dst_stride, void *dst_ptr)62{63unsigned x, y, z;64char *ptr;65size_t bytes = t->cols * t->block.size;66const char *src_ptr2 = (const char *) src_ptr;6768/* lets read linearly from the tiled buffer */69for (y = 0; y < t->tiles_y; y++) {70for (x = 0; x < t->tiles_x; x++) {71/* this inner loop could be replace with SSE magic */72ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x;73for (z = 0; z < t->rows; z++) {74memcpy(ptr, src_ptr2, bytes);75src_ptr2 += bytes;76ptr += dst_stride;77}78}79}80}8182void83pipe_linear_fill_info(struct pipe_tile_info *t,84const struct u_linear_format_block *block,85unsigned tile_width, unsigned tile_height,86unsigned tiles_x, unsigned tiles_y)87{88t->block = *block;8990t->tile.width = tile_width;91t->tile.height = tile_height;92t->cols = t->tile.width / t->block.width;93t->rows = t->tile.height / t->block.height;94t->tile.size = t->cols * t->rows * t->block.size;9596t->tiles_x = tiles_x;97t->tiles_y = tiles_y;98t->stride = t->cols * t->tiles_x * t->block.size;99t->size = t->tiles_x * t->tiles_y * t->tile.size;100}101102103