Path: blob/21.2-virgl/src/freedreno/fdl/fd5_layout.c
4561 views
/*1* Copyright (C) 2018 Rob Clark <[email protected]>2* Copyright © 2018-2019 Google, Inc.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*23* Authors:24* Rob Clark <[email protected]>25*/2627#include <stdio.h>2829#include "freedreno_layout.h"3031void32fdl5_layout(struct fdl_layout *layout, enum pipe_format format,33uint32_t nr_samples, uint32_t width0, uint32_t height0,34uint32_t depth0, uint32_t mip_levels, uint32_t array_size,35bool is_3d)36{37assert(nr_samples > 0);38layout->width0 = width0;39layout->height0 = height0;40layout->depth0 = depth0;4142layout->cpp = util_format_get_blocksize(format);43layout->cpp *= nr_samples;44layout->cpp_shift = ffs(layout->cpp) - 1;4546layout->format = format;47layout->nr_samples = nr_samples;48layout->layer_first = !is_3d;4950uint32_t heightalign = layout->cpp == 1 ? 32 : 16;51/* in layer_first layout, the level (slice) contains just one52* layer (since in fact the layer contains the slices)53*/54uint32_t layers_in_level = layout->layer_first ? 1 : array_size;5556/* use 128 pixel alignment for cpp=1 and cpp=2 */57if (layout->cpp < 4 && layout->tile_mode)58fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 7);59else60fdl_set_pitchalign(layout, fdl_cpp_shift(layout) + 6);6162for (uint32_t level = 0; level < mip_levels; level++) {63struct fdl_slice *slice = &layout->slices[level];64uint32_t tile_mode = fdl_tile_mode(layout, level);65uint32_t pitch = fdl_pitch(layout, level);66uint32_t nblocksy =67util_format_get_nblocksy(format, u_minify(height0, level));6869if (tile_mode) {70nblocksy = align(nblocksy, heightalign);71} else {72/* The blits used for mem<->gmem work at a granularity of73* 32x32, which can cause faults due to over-fetch on the74* last level. The simple solution is to over-allocate a75* bit the last level to ensure any over-fetch is harmless.76* The pitch is already sufficiently aligned, but height77* may not be:78*/79if (level == mip_levels - 1)80nblocksy = align(nblocksy, 32);81}8283slice->offset = layout->size;8485const int alignment = is_3d ? 4096 : 1;8687/* 1d array and 2d array textures must all have the same layer size88* for each miplevel on a3xx. 3d textures can have different layer89* sizes for high levels, but the hw auto-sizer is buggy (or at least90* different than what this code does), so as soon as the layer size91* range gets into range, we stop reducing it.92*/93if (is_3d && (level == 1 ||94(level > 1 && layout->slices[level - 1].size0 > 0xf000)))95slice->size0 = align(nblocksy * pitch, alignment);96else if (level == 0 || layout->layer_first || alignment == 1)97slice->size0 = align(nblocksy * pitch, alignment);98else99slice->size0 = layout->slices[level - 1].size0;100101layout->size += slice->size0 * u_minify(depth0, level) * layers_in_level;102}103}104105106