2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
3 * Copyright (C) 2019 Khaled Emara <ekhaled1836@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include "fd3_resource.h"
26 #include "fd3_format.h"
29 setup_slices(struct fd_resource
*rsc
, uint32_t alignment
, enum pipe_format format
)
31 struct pipe_resource
*prsc
= &rsc
->base
;
32 uint32_t level
, size
= 0;
33 uint32_t width0
= prsc
->width0
;
35 if (rsc
->layout
.tile_mode
&& prsc
->target
!= PIPE_TEXTURE_CUBE
)
36 width0
= util_next_power_of_two(width0
);
38 /* 32 pixel alignment */
39 fdl_set_pitchalign(&rsc
->layout
, fdl_cpp_shift(&rsc
->layout
) + 5);
41 for (level
= 0; level
<= prsc
->last_level
; level
++) {
42 struct fdl_slice
*slice
= fd_resource_slice(rsc
, level
);
43 uint32_t pitch
= fdl_pitch(&rsc
->layout
, level
);
44 uint32_t height
= u_minify(prsc
->height0
, level
);
45 if (rsc
->layout
.tile_mode
) {
46 height
= align(height
, 4);
47 if (prsc
->target
!= PIPE_TEXTURE_CUBE
)
48 height
= util_next_power_of_two(height
);
51 uint32_t nblocksy
= util_format_get_nblocksy(format
, height
);
54 /* 1d array and 2d array textures must all have the same layer size
55 * for each miplevel on a3xx. 3d textures can have different layer
56 * sizes for high levels, but the hw auto-sizer is buggy (or at least
57 * different than what this code does), so as soon as the layer size
58 * range gets into range, we stop reducing it.
60 if (prsc
->target
== PIPE_TEXTURE_3D
&& (
62 (level
> 1 && fd_resource_slice(rsc
, level
- 1)->size0
> 0xf000)))
63 slice
->size0
= align(nblocksy
* pitch
, alignment
);
64 else if (level
== 0 || alignment
== 1)
65 slice
->size0
= align(nblocksy
* pitch
, alignment
);
67 slice
->size0
= fd_resource_slice(rsc
, level
- 1)->size0
;
69 size
+= slice
->size0
* u_minify(prsc
->depth0
, level
) * prsc
->array_size
;
76 fd3_setup_slices(struct fd_resource
*rsc
)
80 switch (rsc
->base
.target
) {
82 case PIPE_TEXTURE_1D_ARRAY
:
83 case PIPE_TEXTURE_2D_ARRAY
:
91 return setup_slices(rsc
, alignment
, rsc
->base
.format
);
95 ok_format(enum pipe_format pfmt
)
97 enum a3xx_color_fmt fmt
= fd3_pipe2color(pfmt
);
103 case PIPE_FORMAT_R8_UINT
:
104 case PIPE_FORMAT_R8_SINT
:
105 case PIPE_FORMAT_Z32_FLOAT
:
115 fd3_tile_mode(const struct pipe_resource
*tmpl
)
117 if (ok_format(tmpl
->format
))