1/* 2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * 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 THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robclark@freedesktop.org> 25 */ 26 27#include "fd5_resource.h" 28 29static void 30setup_lrz(struct fd_resource *rsc) 31{ 32 struct fd_screen *screen = fd_screen(rsc->b.b.screen); 33 unsigned lrz_pitch = align(DIV_ROUND_UP(rsc->b.b.width0, 8), 64); 34 unsigned lrz_height = DIV_ROUND_UP(rsc->b.b.height0, 8); 35 36 /* LRZ buffer is super-sampled: */ 37 switch (rsc->b.b.nr_samples) { 38 case 4: 39 lrz_pitch *= 2; 40 FALLTHROUGH; 41 case 2: 42 lrz_height *= 2; 43 } 44 45 unsigned size = lrz_pitch * lrz_height * 2; 46 47 size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */ 48 49 rsc->lrz_height = lrz_height; 50 rsc->lrz_width = lrz_pitch; 51 rsc->lrz_pitch = lrz_pitch; 52 rsc->lrz = fd_bo_new(screen->dev, size, FD_BO_NOMAP, "lrz"); 53} 54 55uint32_t 56fd5_setup_slices(struct fd_resource *rsc) 57{ 58 struct pipe_resource *prsc = &rsc->b.b; 59 60 if (FD_DBG(LRZ) && has_depth(rsc->b.b.format)) 61 setup_lrz(rsc); 62 63 fdl5_layout(&rsc->layout, prsc->format, fd_resource_nr_samples(prsc), 64 prsc->width0, prsc->height0, prsc->depth0, prsc->last_level + 1, 65 prsc->array_size, prsc->target == PIPE_TEXTURE_3D); 66 67 return rsc->layout.size; 68} 69