49a7e0babec06f93c54876a1772294ea5abf35c8
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 struct fd_screen
*screen
= fd_screen(prsc
->screen
);
33 uint32_t pitchalign
= screen
->gmem_alignw
;
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 fdl_slice
*slice
= fd_resource_slice(rsc
, level
);
43 if (rsc
->layout
.tile_mode
) {
44 if (prsc
->target
!= PIPE_TEXTURE_CUBE
) {
46 width
= util_next_power_of_two(width
);
47 height
= util_next_power_of_two(height
);
49 width
= MAX2(width
, 8);
50 height
= MAX2(height
, 4);
51 // Multiplying by 4 is the result of the 4x4 tiling pattern.
52 slice
->pitch
= width
* 4;
53 blocks
= util_format_get_nblocks(format
, width
, height
);
55 uint32_t twidth
, theight
;
56 twidth
= align(width
, 8);
57 theight
= align(height
, 4);
58 // Multiplying by 4 is the result of the 4x4 tiling pattern.
59 slice
->pitch
= twidth
* 4;
60 blocks
= util_format_get_nblocks(format
, twidth
, theight
);
63 slice
->pitch
= width
= align(width
, pitchalign
);
64 blocks
= util_format_get_nblocks(format
, slice
->pitch
, height
);
66 slice
->pitch
= util_format_get_nblocksx(format
, slice
->pitch
) *
70 /* 1d array and 2d array textures must all have the same layer size
71 * for each miplevel on a3xx. 3d textures can have different layer
72 * sizes for high levels, but the hw auto-sizer is buggy (or at least
73 * different than what this code does), so as soon as the layer size
74 * range gets into range, we stop reducing it.
76 if (prsc
->target
== PIPE_TEXTURE_3D
&& (
78 (level
> 1 && fd_resource_slice(rsc
, level
- 1)->size0
> 0xf000)))
79 slice
->size0
= align(blocks
* rsc
->layout
.cpp
, alignment
);
80 else if (level
== 0 || alignment
== 1)
81 slice
->size0
= align(blocks
* rsc
->layout
.cpp
, alignment
);
83 slice
->size0
= fd_resource_slice(rsc
, level
- 1)->size0
;
85 size
+= slice
->size0
* depth
* prsc
->array_size
;
87 width
= u_minify(width
, 1);
88 height
= u_minify(height
, 1);
89 depth
= u_minify(depth
, 1);
96 fd3_setup_slices(struct fd_resource
*rsc
)
100 switch (rsc
->base
.target
) {
101 case PIPE_TEXTURE_3D
:
102 case PIPE_TEXTURE_1D_ARRAY
:
103 case PIPE_TEXTURE_2D_ARRAY
:
111 return setup_slices(rsc
, alignment
, rsc
->base
.format
);
115 ok_format(enum pipe_format pfmt
)
117 enum a3xx_color_fmt fmt
= fd3_pipe2color(pfmt
);
123 case PIPE_FORMAT_R8_UINT
:
124 case PIPE_FORMAT_R8_SINT
:
125 case PIPE_FORMAT_Z32_FLOAT
:
135 fd3_tile_mode(const struct pipe_resource
*tmpl
)
137 if (ok_format(tmpl
->format
))