2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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:
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
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
24 * Rob Clark <robclark@freedesktop.org>
27 #include "fd4_resource.h"
30 setup_slices(struct fd_resource
*rsc
, uint32_t alignment
, enum pipe_format format
)
32 struct pipe_resource
*prsc
= &rsc
->base
;
33 struct fd_screen
*screen
= fd_screen(prsc
->screen
);
34 enum util_format_layout layout
= util_format_description(format
)->layout
;
35 uint32_t pitchalign
= screen
->gmem_alignw
;
36 uint32_t level
, size
= 0;
37 uint32_t width
= prsc
->width0
;
38 uint32_t height
= prsc
->height0
;
39 uint32_t depth
= prsc
->depth0
;
40 /* in layer_first layout, the level (slice) contains just one
41 * layer (since in fact the layer contains the slices)
43 uint32_t layers_in_level
= rsc
->layout
.layer_first
? 1 : prsc
->array_size
;
45 for (level
= 0; level
<= prsc
->last_level
; level
++) {
46 struct fdl_slice
*slice
= fd_resource_slice(rsc
, level
);
49 if (layout
== UTIL_FORMAT_LAYOUT_ASTC
)
50 width
= util_align_npot(width
, pitchalign
* util_format_get_blockwidth(format
));
52 width
= align(width
, pitchalign
);
53 slice
->pitch
= util_format_get_nblocksx(format
, width
) * rsc
->layout
.cpp
;
55 blocks
= util_format_get_nblocks(format
, width
, height
);
56 /* 1d array and 2d array textures must all have the same layer size
57 * for each miplevel on a3xx. 3d textures can have different layer
58 * sizes for high levels, but the hw auto-sizer is buggy (or at least
59 * different than what this code does), so as soon as the layer size
60 * range gets into range, we stop reducing it.
62 if (prsc
->target
== PIPE_TEXTURE_3D
&& (
64 (level
> 1 && fd_resource_slice(rsc
, level
- 1)->size0
> 0xf000)))
65 slice
->size0
= align(blocks
* rsc
->layout
.cpp
, alignment
);
66 else if (level
== 0 || rsc
->layout
.layer_first
|| alignment
== 1)
67 slice
->size0
= align(blocks
* rsc
->layout
.cpp
, alignment
);
69 slice
->size0
= fd_resource_slice(rsc
, level
- 1)->size0
;
71 size
+= slice
->size0
* depth
* layers_in_level
;
73 width
= u_minify(width
, 1);
74 height
= u_minify(height
, 1);
75 depth
= u_minify(depth
, 1);
82 slice_alignment(enum pipe_texture_target target
)
84 /* on a3xx, 2d array and 3d textures seem to want their
85 * layers aligned to page boundaries:
89 case PIPE_TEXTURE_1D_ARRAY
:
90 case PIPE_TEXTURE_2D_ARRAY
:
97 /* cross generation texture layout to plug in to screen->setup_slices()..
98 * replace with generation specific one as-needed.
100 * TODO for a4xx probably can extract out the a4xx specific logic int
101 * a small fd4_setup_slices() wrapper that sets up layer_first, and then
105 fd4_setup_slices(struct fd_resource
*rsc
)
109 alignment
= slice_alignment(rsc
->base
.target
);
111 struct fd_screen
*screen
= fd_screen(rsc
->base
.screen
);
112 if (is_a4xx(screen
)) {
113 switch (rsc
->base
.target
) {
114 case PIPE_TEXTURE_3D
:
115 rsc
->layout
.layer_first
= false;
118 rsc
->layout
.layer_first
= true;
124 return setup_slices(rsc
, alignment
, rsc
->base
.format
);