• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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  *    Jonathan Marek <jonathan@marek.ca>
26  */
27 
28 #include "fd4_resource.h"
29 
30 uint32_t
fd4_setup_slices(struct fd_resource * rsc)31 fd4_setup_slices(struct fd_resource *rsc)
32 {
33    struct pipe_resource *prsc = &rsc->b.b;
34    enum pipe_format format = prsc->format;
35    uint32_t level, size = 0;
36    uint32_t width = prsc->width0;
37    uint32_t height = prsc->height0;
38    uint32_t depth = prsc->depth0;
39    /* in layer_first layout, the level (slice) contains just one
40     * layer (since in fact the layer contains the slices)
41     */
42    uint32_t layers_in_level, alignment;
43 
44    if (prsc->target == PIPE_TEXTURE_3D) {
45       rsc->layout.layer_first = false;
46       layers_in_level = prsc->array_size;
47       alignment = 4096;
48    } else {
49       rsc->layout.layer_first = true;
50       layers_in_level = 1;
51       alignment = 1;
52    }
53 
54    /* 32 pixel alignment */
55    fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);
56 
57    for (level = 0; level <= prsc->last_level; level++) {
58       struct fdl_slice *slice = fd_resource_slice(rsc, level);
59       uint32_t pitch = fdl_pitch(&rsc->layout, level);
60       uint32_t nblocksy = util_format_get_nblocksy(format, height);
61 
62       slice->offset = size;
63 
64       /* 3d textures can have different layer sizes for high levels, but the
65        * hw auto-sizer is buggy (or at least different than what this code
66        * does), so as soon as the layer size range gets into range, we stop
67        * reducing it.
68        */
69       if (prsc->target == PIPE_TEXTURE_3D &&
70           (level > 1 && fd_resource_slice(rsc, level - 1)->size0 <= 0xf000))
71          slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
72       else
73          slice->size0 = align(nblocksy * pitch, alignment);
74 
75       size += slice->size0 * depth * layers_in_level;
76 
77       width = u_minify(width, 1);
78       height = u_minify(height, 1);
79       depth = u_minify(depth, 1);
80    }
81 
82    return size;
83 }
84