freedreno: Make the slice pitch be bytes, not pixels.
[mesa.git] / src / gallium / drivers / freedreno / a2xx / fd2_resource.c
1 /*
2 * Copyright (C) 2018 Jonathan Marek <jonathan@marek.ca>
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 * Jonathan Marek <jonathan@marek.ca>
25 */
26
27 #include "fd2_resource.h"
28
29 uint32_t
30 fd2_setup_slices(struct fd_resource *rsc)
31 {
32 struct pipe_resource *prsc = &rsc->base;
33 enum pipe_format format = rsc->base.format;
34 uint32_t level, size = 0;
35 uint32_t width = prsc->width0;
36 uint32_t height = prsc->height0;
37 uint32_t depth = prsc->depth0;
38
39 for (level = 0; level <= prsc->last_level; level++) {
40 struct fdl_slice *slice = fd_resource_slice(rsc, level);
41 uint32_t blocks;
42
43 /* 32 * 32 block alignment */
44 switch (prsc->target) {
45 default: assert(0);
46 case PIPE_TEXTURE_2D:
47 case PIPE_TEXTURE_2D_ARRAY:
48 case PIPE_TEXTURE_RECT:
49 case PIPE_TEXTURE_CUBE:
50 height = align(height, 32 * util_format_get_blockheight(format));
51 case PIPE_TEXTURE_1D:
52 case PIPE_TEXTURE_1D_ARRAY:
53 width = align(width, 32 * util_format_get_blockwidth(format));
54 case PIPE_BUFFER:
55 break;
56 }
57
58 /* mipmaps have power of two sizes in memory */
59 if (level) {
60 width = util_next_power_of_two(width);
61 height = util_next_power_of_two(height);
62 }
63
64 slice->pitch = util_format_get_nblocksx(format, width) * rsc->layout.cpp;
65 slice->offset = size;
66
67 blocks = util_format_get_nblocks(format, width, height);
68
69 /* 4k aligned size */
70 slice->size0 = align(blocks * rsc->layout.cpp, 4096);
71
72 size += slice->size0 * depth * prsc->array_size;
73
74 width = u_minify(width, 1);
75 height = u_minify(height, 1);
76 depth = u_minify(depth, 1);
77 }
78 return size;
79 }
80
81 unsigned
82 fd2_tile_mode(const struct pipe_resource *tmpl)
83 {
84 /* disable tiling for cube maps, freedreno uses a 2D array for the staging texture,
85 * (a2xx supports 2D arrays but it is not implemented)
86 */
87 if (tmpl->target == PIPE_TEXTURE_CUBE)
88 return 0;
89 /* we can enable tiling for any resource we can render to */
90 return (tmpl->bind & PIPE_BIND_RENDER_TARGET) ? 1 : 0;
91 }