Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_resource.c
4574 views
/*1* Copyright (C) 2012 Rob Clark <[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* Rob Clark <[email protected]>24* Jonathan Marek <[email protected]>25*/2627#include "fd4_resource.h"2829uint32_t30fd4_setup_slices(struct fd_resource *rsc)31{32struct pipe_resource *prsc = &rsc->b.b;33enum pipe_format format = prsc->format;34uint32_t level, size = 0;35uint32_t width = prsc->width0;36uint32_t height = prsc->height0;37uint32_t depth = prsc->depth0;38/* in layer_first layout, the level (slice) contains just one39* layer (since in fact the layer contains the slices)40*/41uint32_t layers_in_level, alignment;4243if (prsc->target == PIPE_TEXTURE_3D) {44rsc->layout.layer_first = false;45layers_in_level = prsc->array_size;46alignment = 4096;47} else {48rsc->layout.layer_first = true;49layers_in_level = 1;50alignment = 1;51}5253/* 32 pixel alignment */54fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);5556for (level = 0; level <= prsc->last_level; level++) {57struct fdl_slice *slice = fd_resource_slice(rsc, level);58uint32_t pitch = fdl_pitch(&rsc->layout, level);59uint32_t nblocksy = util_format_get_nblocksy(format, height);6061slice->offset = size;6263/* 3d textures can have different layer sizes for high levels, but the64* hw auto-sizer is buggy (or at least different than what this code65* does), so as soon as the layer size range gets into range, we stop66* reducing it.67*/68if (prsc->target == PIPE_TEXTURE_3D &&69(level > 1 && fd_resource_slice(rsc, level - 1)->size0 <= 0xf000))70slice->size0 = fd_resource_slice(rsc, level - 1)->size0;71else72slice->size0 = align(nblocksy * pitch, alignment);7374size += slice->size0 * depth * layers_in_level;7576width = u_minify(width, 1);77height = u_minify(height, 1);78depth = u_minify(depth, 1);79}8081return size;82}838485