Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a2xx/fd2_resource.c
4574 views
/*1* Copyright (C) 2018 Jonathan Marek <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Jonathan Marek <[email protected]>24*/2526#include "fd2_resource.h"2728uint32_t29fd2_setup_slices(struct fd_resource *rsc)30{31struct pipe_resource *prsc = &rsc->b.b;32enum pipe_format format = prsc->format;33uint32_t height0 = util_format_get_nblocksy(format, prsc->height0);34uint32_t level, size = 0;3536/* 32 pixel alignment */37fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);3839for (level = 0; level <= prsc->last_level; level++) {40struct fdl_slice *slice = fd_resource_slice(rsc, level);41uint32_t pitch = fdl2_pitch(&rsc->layout, level);42uint32_t nblocksy = align(u_minify(height0, level), 32);4344/* mipmaps have power of two sizes in memory */45if (level)46nblocksy = util_next_power_of_two(nblocksy);4748slice->offset = size;49slice->size0 = align(pitch * nblocksy, 4096);5051size += slice->size0 * u_minify(prsc->depth0, level) * prsc->array_size;52}5354return size;55}5657unsigned58fd2_tile_mode(const struct pipe_resource *tmpl)59{60/* disable tiling for cube maps, freedreno uses a 2D array for the staging61* texture, (a2xx supports 2D arrays but it is not implemented)62*/63if (tmpl->target == PIPE_TEXTURE_CUBE)64return 0;65/* we can enable tiling for any resource we can render to */66return (tmpl->bind & PIPE_BIND_RENDER_TARGET) ? 1 : 0;67}686970