2 * Copyright (C) 2018 Jonathan Marek <jonathan@marek.ca>
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 * Jonathan Marek <jonathan@marek.ca>
27 #include "fd2_resource.h"
30 fd2_setup_slices(struct fd_resource
*rsc
)
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
;
39 for (level
= 0; level
<= prsc
->last_level
; level
++) {
40 struct fd_resource_slice
*slice
= fd_resource_slice(rsc
, level
);
43 /* 32 * 32 block alignment */
44 switch (prsc
->target
) {
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
));
52 case PIPE_TEXTURE_1D_ARRAY
:
53 width
= align(width
, 32 * util_format_get_blockwidth(format
));
58 /* mipmaps have power of two sizes in memory */
60 width
= util_next_power_of_two(width
);
61 height
= util_next_power_of_two(height
);
67 blocks
= util_format_get_nblocks(format
, width
, height
);
70 slice
->size0
= align(blocks
* rsc
->cpp
, 4096);
72 size
+= slice
->size0
* depth
* prsc
->array_size
;
74 width
= u_minify(width
, 1);
75 height
= u_minify(height
, 1);
76 depth
= u_minify(depth
, 1);