panfrost: Move checksum routines to root panfrost
[mesa.git] / src / panfrost / encoder / pan_texture.c
1 /*
2 * Copyright (C) 2008 VMware, Inc.
3 * Copyright (C) 2014 Broadcom
4 * Copyright (C) 2018-2019 Alyssa Rosenzweig
5 * Copyright (C) 2019-2020 Collabora, Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 */
27
28 #include "util/macros.h"
29 #include "pan_texture.h"
30
31 /* Computes sizes for checksumming, which is 8 bytes per 16x16 tile.
32 * Checksumming is believed to be a CRC variant (CRC64 based on the size?).
33 * This feature is also known as "transaction elimination". */
34
35 #define CHECKSUM_TILE_WIDTH 16
36 #define CHECKSUM_TILE_HEIGHT 16
37 #define CHECKSUM_BYTES_PER_TILE 8
38
39 unsigned
40 panfrost_compute_checksum_size(
41 struct panfrost_slice *slice,
42 unsigned width,
43 unsigned height)
44 {
45 unsigned aligned_width = ALIGN_POT(width, CHECKSUM_TILE_WIDTH);
46 unsigned aligned_height = ALIGN_POT(height, CHECKSUM_TILE_HEIGHT);
47
48 unsigned tile_count_x = aligned_width / CHECKSUM_TILE_WIDTH;
49 unsigned tile_count_y = aligned_height / CHECKSUM_TILE_HEIGHT;
50
51 slice->checksum_stride = tile_count_x * CHECKSUM_BYTES_PER_TILE;
52
53 return slice->checksum_stride * tile_count_y;
54 }