Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a3xx/fd3_resource.c
4574 views
/*1* Copyright (C) 2012 Rob Clark <[email protected]>2* Copyright (C) 2019 Khaled Emara <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include "fd3_resource.h"25#include "fd3_format.h"2627static uint32_t28setup_slices(struct fd_resource *rsc, uint32_t alignment,29enum pipe_format format)30{31struct pipe_resource *prsc = &rsc->b.b;32uint32_t level, size = 0;33uint32_t width0 = prsc->width0;3435if (rsc->layout.tile_mode && prsc->target != PIPE_TEXTURE_CUBE)36width0 = util_next_power_of_two(width0);3738/* 32 pixel alignment */39fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);4041for (level = 0; level <= prsc->last_level; level++) {42struct fdl_slice *slice = fd_resource_slice(rsc, level);43uint32_t pitch = fdl_pitch(&rsc->layout, level);44uint32_t height = u_minify(prsc->height0, level);45if (rsc->layout.tile_mode) {46height = align(height, 4);47if (prsc->target != PIPE_TEXTURE_CUBE)48height = util_next_power_of_two(height);49}5051uint32_t nblocksy = util_format_get_nblocksy(format, height);5253slice->offset = size;54/* 1d array and 2d array textures must all have the same layer size55* for each miplevel on a3xx. 3d textures can have different layer56* sizes for high levels, but the hw auto-sizer is buggy (or at least57* different than what this code does), so as soon as the layer size58* range gets into range, we stop reducing it.59*/60if (prsc->target == PIPE_TEXTURE_3D &&61(level == 1 ||62(level > 1 && fd_resource_slice(rsc, level - 1)->size0 > 0xf000)))63slice->size0 = align(nblocksy * pitch, alignment);64else if (level == 0 || alignment == 1)65slice->size0 = align(nblocksy * pitch, alignment);66else67slice->size0 = fd_resource_slice(rsc, level - 1)->size0;6869size += slice->size0 * u_minify(prsc->depth0, level) * prsc->array_size;70}7172return size;73}7475uint32_t76fd3_setup_slices(struct fd_resource *rsc)77{78uint32_t alignment;7980switch (rsc->b.b.target) {81case PIPE_TEXTURE_3D:82case PIPE_TEXTURE_1D_ARRAY:83case PIPE_TEXTURE_2D_ARRAY:84alignment = 4096;85break;86default:87alignment = 1;88break;89}9091return setup_slices(rsc, alignment, rsc->b.b.format);92}9394static bool95ok_format(enum pipe_format pfmt)96{97enum a3xx_color_fmt fmt = fd3_pipe2color(pfmt);9899if (fmt == RB_NONE)100return false;101102switch (pfmt) {103case PIPE_FORMAT_R8_UINT:104case PIPE_FORMAT_R8_SINT:105case PIPE_FORMAT_Z32_FLOAT:106return false;107default:108break;109}110111return true;112}113114unsigned115fd3_tile_mode(const struct pipe_resource *tmpl)116{117if (ok_format(tmpl->format))118return TILE_4X4;119return LINEAR;120}121122123