2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 * Copyright 2015 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
29 static unsigned minify_as_blocks(unsigned width
, unsigned level
, unsigned blk_w
)
31 width
= u_minify(width
, level
);
32 return DIV_ROUND_UP(width
, blk_w
);
35 static unsigned encode_tile_info(struct si_context
*sctx
, struct si_texture
*tex
, unsigned level
,
38 struct radeon_info
*info
= &sctx
->screen
->info
;
39 unsigned tile_index
= tex
->surface
.u
.legacy
.tiling_index
[level
];
40 unsigned macro_tile_index
= tex
->surface
.u
.legacy
.macro_tile_index
;
41 unsigned tile_mode
= info
->si_tile_mode_array
[tile_index
];
42 unsigned macro_tile_mode
= info
->cik_macrotile_mode_array
[macro_tile_index
];
44 return (set_bpp
? util_logbase2(tex
->surface
.bpe
) : 0) | (G_009910_ARRAY_MODE(tile_mode
) << 3) |
45 (G_009910_MICRO_TILE_MODE_NEW(tile_mode
) << 8) |
46 /* Non-depth modes don't have TILE_SPLIT set. */
47 ((util_logbase2(tex
->surface
.u
.legacy
.tile_split
>> 6)) << 11) |
48 (G_009990_BANK_WIDTH(macro_tile_mode
) << 15) |
49 (G_009990_BANK_HEIGHT(macro_tile_mode
) << 18) |
50 (G_009990_NUM_BANKS(macro_tile_mode
) << 21) |
51 (G_009990_MACRO_TILE_ASPECT(macro_tile_mode
) << 24) |
52 (G_009910_PIPE_CONFIG(tile_mode
) << 26);
55 static bool si_sdma_v4_copy_texture(struct si_context
*sctx
, struct pipe_resource
*dst
,
56 unsigned dst_level
, unsigned dstx
, unsigned dsty
, unsigned dstz
,
57 struct pipe_resource
*src
, unsigned src_level
,
58 const struct pipe_box
*src_box
)
60 struct si_texture
*ssrc
= (struct si_texture
*)src
;
61 struct si_texture
*sdst
= (struct si_texture
*)dst
;
63 unsigned bpp
= sdst
->surface
.bpe
;
64 uint64_t dst_address
= sdst
->buffer
.gpu_address
+ sdst
->surface
.u
.gfx9
.surf_offset
;
65 uint64_t src_address
= ssrc
->buffer
.gpu_address
+ ssrc
->surface
.u
.gfx9
.surf_offset
;
66 unsigned dst_pitch
= sdst
->surface
.u
.gfx9
.surf_pitch
;
67 unsigned src_pitch
= ssrc
->surface
.u
.gfx9
.surf_pitch
;
68 uint64_t dst_slice_pitch
= ((uint64_t)sdst
->surface
.u
.gfx9
.surf_slice_size
) / bpp
;
69 uint64_t src_slice_pitch
= ((uint64_t)ssrc
->surface
.u
.gfx9
.surf_slice_size
) / bpp
;
70 unsigned srcx
= src_box
->x
/ ssrc
->surface
.blk_w
;
71 unsigned srcy
= src_box
->y
/ ssrc
->surface
.blk_h
;
72 unsigned srcz
= src_box
->z
;
73 unsigned copy_width
= DIV_ROUND_UP(src_box
->width
, ssrc
->surface
.blk_w
);
74 unsigned copy_height
= DIV_ROUND_UP(src_box
->height
, ssrc
->surface
.blk_h
);
75 unsigned copy_depth
= src_box
->depth
;
76 unsigned xalign
= MAX2(1, 4 / bpp
);
78 assert(src_level
<= src
->last_level
);
79 assert(dst_level
<= dst
->last_level
);
80 assert(sdst
->surface
.u
.gfx9
.surf_offset
+ dst_slice_pitch
* bpp
* (dstz
+ src_box
->depth
) <=
81 sdst
->buffer
.buf
->size
);
82 assert(ssrc
->surface
.u
.gfx9
.surf_offset
+ src_slice_pitch
* bpp
* (srcz
+ src_box
->depth
) <=
83 ssrc
->buffer
.buf
->size
);
85 if (!si_prepare_for_dma_blit(sctx
, sdst
, dst_level
, dstx
, dsty
, dstz
, ssrc
, src_level
, src_box
))
88 dstx
/= sdst
->surface
.blk_w
;
89 dsty
/= sdst
->surface
.blk_h
;
91 if (srcx
>= (1 << 14) || srcy
>= (1 << 14) || srcz
>= (1 << 11) || dstx
>= (1 << 14) ||
92 dsty
>= (1 << 14) || dstz
>= (1 << 11))
95 /* Linear -> linear sub-window copy. */
96 if (ssrc
->surface
.is_linear
&& sdst
->surface
.is_linear
) {
97 struct radeon_cmdbuf
*cs
= sctx
->sdma_cs
;
99 /* Check if everything fits into the bitfields */
100 if (!(src_pitch
<= (1 << 19) && dst_pitch
<= (1 << 19) && src_slice_pitch
<= (1 << 28) &&
101 dst_slice_pitch
<= (1 << 28) && copy_width
<= (1 << 14) && copy_height
<= (1 << 14) &&
102 copy_depth
<= (1 << 11)))
105 si_need_dma_space(sctx
, 13, &sdst
->buffer
, &ssrc
->buffer
);
107 src_address
+= ssrc
->surface
.u
.gfx9
.offset
[src_level
];
108 dst_address
+= sdst
->surface
.u
.gfx9
.offset
[dst_level
];
110 /* Check alignments */
111 if ((src_address
% 4) != 0 || (dst_address
% 4) != 0 || (src_pitch
% xalign
) != 0)
115 cs
, CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY
, CIK_SDMA_COPY_SUB_OPCODE_LINEAR_SUB_WINDOW
, 0) |
116 (util_logbase2(bpp
) << 29));
117 radeon_emit(cs
, src_address
);
118 radeon_emit(cs
, src_address
>> 32);
119 radeon_emit(cs
, srcx
| (srcy
<< 16));
120 radeon_emit(cs
, srcz
| ((src_pitch
- 1) << 13));
121 radeon_emit(cs
, src_slice_pitch
- 1);
122 radeon_emit(cs
, dst_address
);
123 radeon_emit(cs
, dst_address
>> 32);
124 radeon_emit(cs
, dstx
| (dsty
<< 16));
125 radeon_emit(cs
, dstz
| ((dst_pitch
- 1) << 13));
126 radeon_emit(cs
, dst_slice_pitch
- 1);
127 radeon_emit(cs
, (copy_width
- 1) | ((copy_height
- 1) << 16));
128 radeon_emit(cs
, (copy_depth
- 1));
132 /* Linear <-> Tiled sub-window copy */
133 if (ssrc
->surface
.is_linear
!= sdst
->surface
.is_linear
) {
134 struct si_texture
*tiled
= ssrc
->surface
.is_linear
? sdst
: ssrc
;
135 struct si_texture
*linear
= tiled
== ssrc
? sdst
: ssrc
;
136 unsigned tiled_level
= tiled
== ssrc
? src_level
: dst_level
;
137 unsigned linear_level
= linear
== ssrc
? src_level
: dst_level
;
138 unsigned tiled_x
= tiled
== ssrc
? srcx
: dstx
;
139 unsigned linear_x
= linear
== ssrc
? srcx
: dstx
;
140 unsigned tiled_y
= tiled
== ssrc
? srcy
: dsty
;
141 unsigned linear_y
= linear
== ssrc
? srcy
: dsty
;
142 unsigned tiled_z
= tiled
== ssrc
? srcz
: dstz
;
143 unsigned linear_z
= linear
== ssrc
? srcz
: dstz
;
144 unsigned tiled_width
= tiled
== ssrc
145 ? DIV_ROUND_UP(ssrc
->buffer
.b
.b
.width0
, ssrc
->surface
.blk_w
)
146 : DIV_ROUND_UP(sdst
->buffer
.b
.b
.width0
, sdst
->surface
.blk_w
);
147 unsigned tiled_height
= tiled
== ssrc
148 ? DIV_ROUND_UP(ssrc
->buffer
.b
.b
.height0
, ssrc
->surface
.blk_h
)
149 : DIV_ROUND_UP(sdst
->buffer
.b
.b
.height0
, sdst
->surface
.blk_h
);
150 unsigned tiled_depth
= tiled
== ssrc
? ssrc
->buffer
.b
.b
.depth0
: sdst
->buffer
.b
.b
.depth0
;
151 unsigned linear_pitch
= linear
== ssrc
? src_pitch
: dst_pitch
;
152 unsigned linear_slice_pitch
= linear
== ssrc
? src_slice_pitch
: dst_slice_pitch
;
153 uint64_t tiled_address
= tiled
== ssrc
? src_address
: dst_address
;
154 uint64_t linear_address
= linear
== ssrc
? src_address
: dst_address
;
155 struct radeon_cmdbuf
*cs
= sctx
->sdma_cs
;
157 linear_address
+= linear
->surface
.u
.gfx9
.offset
[linear_level
];
159 /* Check if everything fits into the bitfields */
160 if (!(tiled_x
<= (1 << 14) && tiled_y
<= (1 << 14) && tiled_z
<= (1 << 11) &&
161 tiled_width
<= (1 << 14) && tiled_height
<= (1 << 14) && tiled_depth
<= (1 << 11) &&
162 tiled
->surface
.u
.gfx9
.surf
.epitch
<= (1 << 16) && linear_x
<= (1 << 14) &&
163 linear_y
<= (1 << 14) && linear_z
<= (1 << 11) && linear_pitch
<= (1 << 14) &&
164 linear_slice_pitch
<= (1 << 28) && copy_width
<= (1 << 14) &&
165 copy_height
<= (1 << 14) && copy_depth
<= (1 << 11)))
168 /* Check alignments */
169 if ((tiled_address
% 256 != 0) || (linear_address
% 4 != 0) || (linear_pitch
% xalign
!= 0) ||
170 (linear_slice_pitch
% xalign
!= 0))
173 si_need_dma_space(sctx
, 14, &sdst
->buffer
, &ssrc
->buffer
);
176 cs
, CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY
, CIK_SDMA_COPY_SUB_OPCODE_TILED_SUB_WINDOW
, 0) |
177 tiled
->buffer
.b
.b
.last_level
<< 20 | tiled_level
<< 24 |
178 (linear
== sdst
? 1u : 0) << 31);
179 radeon_emit(cs
, (uint32_t)tiled_address
);
180 radeon_emit(cs
, (uint32_t)(tiled_address
>> 32));
181 radeon_emit(cs
, tiled_x
| (tiled_y
<< 16));
182 radeon_emit(cs
, tiled_z
| ((tiled_width
- 1) << 16));
183 radeon_emit(cs
, (tiled_height
- 1) | (tiled_depth
- 1) << 16);
184 radeon_emit(cs
, util_logbase2(bpp
) | tiled
->surface
.u
.gfx9
.surf
.swizzle_mode
<< 3 |
185 tiled
->surface
.u
.gfx9
.resource_type
<< 9 |
186 tiled
->surface
.u
.gfx9
.surf
.epitch
<< 16);
187 radeon_emit(cs
, (uint32_t)linear_address
);
188 radeon_emit(cs
, (uint32_t)(linear_address
>> 32));
189 radeon_emit(cs
, linear_x
| (linear_y
<< 16));
190 radeon_emit(cs
, linear_z
| ((linear_pitch
- 1) << 16));
191 radeon_emit(cs
, linear_slice_pitch
- 1);
192 radeon_emit(cs
, (copy_width
- 1) | ((copy_height
- 1) << 16));
193 radeon_emit(cs
, (copy_depth
- 1));
200 static bool cik_sdma_copy_texture(struct si_context
*sctx
, struct pipe_resource
*dst
,
201 unsigned dst_level
, unsigned dstx
, unsigned dsty
, unsigned dstz
,
202 struct pipe_resource
*src
, unsigned src_level
,
203 const struct pipe_box
*src_box
)
205 struct radeon_info
*info
= &sctx
->screen
->info
;
206 struct si_texture
*ssrc
= (struct si_texture
*)src
;
207 struct si_texture
*sdst
= (struct si_texture
*)dst
;
208 unsigned bpp
= sdst
->surface
.bpe
;
209 uint64_t dst_address
= sdst
->buffer
.gpu_address
+ sdst
->surface
.u
.legacy
.level
[dst_level
].offset
;
210 uint64_t src_address
= ssrc
->buffer
.gpu_address
+ ssrc
->surface
.u
.legacy
.level
[src_level
].offset
;
211 unsigned dst_mode
= sdst
->surface
.u
.legacy
.level
[dst_level
].mode
;
212 unsigned src_mode
= ssrc
->surface
.u
.legacy
.level
[src_level
].mode
;
213 unsigned dst_tile_index
= sdst
->surface
.u
.legacy
.tiling_index
[dst_level
];
214 unsigned src_tile_index
= ssrc
->surface
.u
.legacy
.tiling_index
[src_level
];
215 unsigned dst_tile_mode
= info
->si_tile_mode_array
[dst_tile_index
];
216 unsigned src_tile_mode
= info
->si_tile_mode_array
[src_tile_index
];
217 unsigned dst_micro_mode
= G_009910_MICRO_TILE_MODE_NEW(dst_tile_mode
);
218 unsigned src_micro_mode
= G_009910_MICRO_TILE_MODE_NEW(src_tile_mode
);
219 unsigned dst_tile_swizzle
= dst_mode
== RADEON_SURF_MODE_2D
? sdst
->surface
.tile_swizzle
: 0;
220 unsigned src_tile_swizzle
= src_mode
== RADEON_SURF_MODE_2D
? ssrc
->surface
.tile_swizzle
: 0;
221 unsigned dst_pitch
= sdst
->surface
.u
.legacy
.level
[dst_level
].nblk_x
;
222 unsigned src_pitch
= ssrc
->surface
.u
.legacy
.level
[src_level
].nblk_x
;
223 uint64_t dst_slice_pitch
=
224 ((uint64_t)sdst
->surface
.u
.legacy
.level
[dst_level
].slice_size_dw
* 4) / bpp
;
225 uint64_t src_slice_pitch
=
226 ((uint64_t)ssrc
->surface
.u
.legacy
.level
[src_level
].slice_size_dw
* 4) / bpp
;
227 unsigned dst_width
= minify_as_blocks(sdst
->buffer
.b
.b
.width0
, dst_level
, sdst
->surface
.blk_w
);
228 unsigned src_width
= minify_as_blocks(ssrc
->buffer
.b
.b
.width0
, src_level
, ssrc
->surface
.blk_w
);
229 unsigned dst_height
= minify_as_blocks(sdst
->buffer
.b
.b
.height0
, dst_level
, sdst
->surface
.blk_h
);
230 unsigned src_height
= minify_as_blocks(ssrc
->buffer
.b
.b
.height0
, src_level
, ssrc
->surface
.blk_h
);
231 unsigned srcx
= src_box
->x
/ ssrc
->surface
.blk_w
;
232 unsigned srcy
= src_box
->y
/ ssrc
->surface
.blk_h
;
233 unsigned srcz
= src_box
->z
;
234 unsigned copy_width
= DIV_ROUND_UP(src_box
->width
, ssrc
->surface
.blk_w
);
235 unsigned copy_height
= DIV_ROUND_UP(src_box
->height
, ssrc
->surface
.blk_h
);
236 unsigned copy_depth
= src_box
->depth
;
238 assert(src_level
<= src
->last_level
);
239 assert(dst_level
<= dst
->last_level
);
240 assert(sdst
->surface
.u
.legacy
.level
[dst_level
].offset
+
241 dst_slice_pitch
* bpp
* (dstz
+ src_box
->depth
) <=
242 sdst
->buffer
.buf
->size
);
243 assert(ssrc
->surface
.u
.legacy
.level
[src_level
].offset
+
244 src_slice_pitch
* bpp
* (srcz
+ src_box
->depth
) <=
245 ssrc
->buffer
.buf
->size
);
247 if (!si_prepare_for_dma_blit(sctx
, sdst
, dst_level
, dstx
, dsty
, dstz
, ssrc
, src_level
, src_box
))
250 dstx
/= sdst
->surface
.blk_w
;
251 dsty
/= sdst
->surface
.blk_h
;
253 if (srcx
>= (1 << 14) || srcy
>= (1 << 14) || srcz
>= (1 << 11) || dstx
>= (1 << 14) ||
254 dsty
>= (1 << 14) || dstz
>= (1 << 11))
257 dst_address
|= dst_tile_swizzle
<< 8;
258 src_address
|= src_tile_swizzle
<< 8;
260 /* Linear -> linear sub-window copy. */
261 if (dst_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
&& src_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
&&
262 /* check if everything fits into the bitfields */
263 src_pitch
<= (1 << 14) && dst_pitch
<= (1 << 14) && src_slice_pitch
<= (1 << 28) &&
264 dst_slice_pitch
<= (1 << 28) && copy_width
<= (1 << 14) && copy_height
<= (1 << 14) &&
265 copy_depth
<= (1 << 11) &&
266 /* HW limitation - GFX7: */
267 (sctx
->chip_class
!= GFX7
||
268 (copy_width
< (1 << 14) && copy_height
< (1 << 14) && copy_depth
< (1 << 11))) &&
269 /* HW limitation - some GFX7 parts: */
270 ((sctx
->family
!= CHIP_BONAIRE
&& sctx
->family
!= CHIP_KAVERI
) ||
271 (srcx
+ copy_width
!= (1 << 14) && srcy
+ copy_height
!= (1 << 14)))) {
272 struct radeon_cmdbuf
*cs
= sctx
->sdma_cs
;
274 si_need_dma_space(sctx
, 13, &sdst
->buffer
, &ssrc
->buffer
);
277 cs
, CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY
, CIK_SDMA_COPY_SUB_OPCODE_LINEAR_SUB_WINDOW
, 0) |
278 (util_logbase2(bpp
) << 29));
279 radeon_emit(cs
, src_address
);
280 radeon_emit(cs
, src_address
>> 32);
281 radeon_emit(cs
, srcx
| (srcy
<< 16));
282 radeon_emit(cs
, srcz
| ((src_pitch
- 1) << 16));
283 radeon_emit(cs
, src_slice_pitch
- 1);
284 radeon_emit(cs
, dst_address
);
285 radeon_emit(cs
, dst_address
>> 32);
286 radeon_emit(cs
, dstx
| (dsty
<< 16));
287 radeon_emit(cs
, dstz
| ((dst_pitch
- 1) << 16));
288 radeon_emit(cs
, dst_slice_pitch
- 1);
289 if (sctx
->chip_class
== GFX7
) {
290 radeon_emit(cs
, copy_width
| (copy_height
<< 16));
291 radeon_emit(cs
, copy_depth
);
293 radeon_emit(cs
, (copy_width
- 1) | ((copy_height
- 1) << 16));
294 radeon_emit(cs
, (copy_depth
- 1));
299 /* Tiled <-> linear sub-window copy. */
300 if ((src_mode
>= RADEON_SURF_MODE_1D
) != (dst_mode
>= RADEON_SURF_MODE_1D
)) {
301 struct si_texture
*tiled
= src_mode
>= RADEON_SURF_MODE_1D
? ssrc
: sdst
;
302 struct si_texture
*linear
= tiled
== ssrc
? sdst
: ssrc
;
303 unsigned tiled_level
= tiled
== ssrc
? src_level
: dst_level
;
304 unsigned linear_level
= linear
== ssrc
? src_level
: dst_level
;
305 unsigned tiled_x
= tiled
== ssrc
? srcx
: dstx
;
306 unsigned linear_x
= linear
== ssrc
? srcx
: dstx
;
307 unsigned tiled_y
= tiled
== ssrc
? srcy
: dsty
;
308 unsigned linear_y
= linear
== ssrc
? srcy
: dsty
;
309 unsigned tiled_z
= tiled
== ssrc
? srcz
: dstz
;
310 unsigned linear_z
= linear
== ssrc
? srcz
: dstz
;
311 unsigned tiled_width
= tiled
== ssrc
? src_width
: dst_width
;
312 unsigned linear_width
= linear
== ssrc
? src_width
: dst_width
;
313 unsigned tiled_pitch
= tiled
== ssrc
? src_pitch
: dst_pitch
;
314 unsigned linear_pitch
= linear
== ssrc
? src_pitch
: dst_pitch
;
315 unsigned tiled_slice_pitch
= tiled
== ssrc
? src_slice_pitch
: dst_slice_pitch
;
316 unsigned linear_slice_pitch
= linear
== ssrc
? src_slice_pitch
: dst_slice_pitch
;
317 uint64_t tiled_address
= tiled
== ssrc
? src_address
: dst_address
;
318 uint64_t linear_address
= linear
== ssrc
? src_address
: dst_address
;
319 unsigned tiled_micro_mode
= tiled
== ssrc
? src_micro_mode
: dst_micro_mode
;
321 assert(tiled_pitch
% 8 == 0);
322 assert(tiled_slice_pitch
% 64 == 0);
323 unsigned pitch_tile_max
= tiled_pitch
/ 8 - 1;
324 unsigned slice_tile_max
= tiled_slice_pitch
/ 64 - 1;
325 unsigned xalign
= MAX2(1, 4 / bpp
);
326 unsigned copy_width_aligned
= copy_width
;
328 /* If the region ends at the last pixel and is unaligned, we
329 * can copy the remainder of the line that is not visible to
332 if (copy_width
% xalign
!= 0 && linear_x
+ copy_width
== linear_width
&&
333 tiled_x
+ copy_width
== tiled_width
&&
334 linear_x
+ align(copy_width
, xalign
) <= linear_pitch
&&
335 tiled_x
+ align(copy_width
, xalign
) <= tiled_pitch
)
336 copy_width_aligned
= align(copy_width
, xalign
);
338 /* HW limitations. */
339 if ((sctx
->family
== CHIP_BONAIRE
|| sctx
->family
== CHIP_KAVERI
) &&
340 linear_pitch
- 1 == 0x3fff && bpp
== 16)
343 if (sctx
->chip_class
== GFX7
&&
344 (copy_width_aligned
== (1 << 14) || copy_height
== (1 << 14) || copy_depth
== (1 << 11)))
347 if ((sctx
->family
== CHIP_BONAIRE
|| sctx
->family
== CHIP_KAVERI
||
348 sctx
->family
== CHIP_KABINI
) &&
349 (tiled_x
+ copy_width
== (1 << 14) || tiled_y
+ copy_height
== (1 << 14)))
352 /* The hw can read outside of the given linear buffer bounds,
353 * or access those pages but not touch the memory in case
354 * of writes. (it still causes a VM fault)
356 * Out-of-bounds memory access or page directory access must
359 int64_t start_linear_address
, end_linear_address
;
360 unsigned granularity
;
362 /* Deduce the size of reads from the linear surface. */
363 switch (tiled_micro_mode
) {
364 case V_009910_ADDR_SURF_DISPLAY_MICRO_TILING
:
365 granularity
= bpp
== 1 ? 64 / (8 * bpp
) : 128 / (8 * bpp
);
367 case V_009910_ADDR_SURF_THIN_MICRO_TILING
:
368 case V_009910_ADDR_SURF_DEPTH_MICRO_TILING
:
369 if (0 /* TODO: THICK microtiling */)
371 bpp
== 1 ? 32 / (8 * bpp
)
372 : bpp
== 2 ? 64 / (8 * bpp
) : bpp
<= 8 ? 128 / (8 * bpp
) : 256 / (8 * bpp
);
374 granularity
= bpp
<= 2 ? 64 / (8 * bpp
) : bpp
<= 8 ? 128 / (8 * bpp
) : 256 / (8 * bpp
);
380 /* The linear reads start at tiled_x & ~(granularity - 1).
381 * If linear_x == 0 && tiled_x % granularity != 0, the hw
382 * starts reading from an address preceding linear_address!!!
384 start_linear_address
=
385 linear
->surface
.u
.legacy
.level
[linear_level
].offset
+
386 bpp
* (linear_z
* linear_slice_pitch
+ linear_y
* linear_pitch
+ linear_x
);
387 start_linear_address
-= (int)(bpp
* (tiled_x
% granularity
));
390 linear
->surface
.u
.legacy
.level
[linear_level
].offset
+
391 bpp
* ((linear_z
+ copy_depth
- 1) * linear_slice_pitch
+
392 (linear_y
+ copy_height
- 1) * linear_pitch
+ (linear_x
+ copy_width
));
394 if ((tiled_x
+ copy_width
) % granularity
)
395 end_linear_address
+= granularity
- (tiled_x
+ copy_width
) % granularity
;
397 if (start_linear_address
< 0 || end_linear_address
> linear
->surface
.surf_size
)
400 /* Check requirements. */
401 if (tiled_address
% 256 == 0 && linear_address
% 4 == 0 && linear_pitch
% xalign
== 0 &&
402 linear_x
% xalign
== 0 && tiled_x
% xalign
== 0 && copy_width_aligned
% xalign
== 0 &&
403 tiled_micro_mode
!= V_009910_ADDR_SURF_ROTATED_MICRO_TILING
&&
404 /* check if everything fits into the bitfields */
405 tiled
->surface
.u
.legacy
.tile_split
<= 4096 && pitch_tile_max
< (1 << 11) &&
406 slice_tile_max
< (1 << 22) && linear_pitch
<= (1 << 14) &&
407 linear_slice_pitch
<= (1 << 28) && copy_width_aligned
<= (1 << 14) &&
408 copy_height
<= (1 << 14) && copy_depth
<= (1 << 11)) {
409 struct radeon_cmdbuf
*cs
= sctx
->sdma_cs
;
410 uint32_t direction
= linear
== sdst
? 1u << 31 : 0;
412 si_need_dma_space(sctx
, 14, &sdst
->buffer
, &ssrc
->buffer
);
414 radeon_emit(cs
, CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY
,
415 CIK_SDMA_COPY_SUB_OPCODE_TILED_SUB_WINDOW
, 0) |
417 radeon_emit(cs
, tiled_address
);
418 radeon_emit(cs
, tiled_address
>> 32);
419 radeon_emit(cs
, tiled_x
| (tiled_y
<< 16));
420 radeon_emit(cs
, tiled_z
| (pitch_tile_max
<< 16));
421 radeon_emit(cs
, slice_tile_max
);
422 radeon_emit(cs
, encode_tile_info(sctx
, tiled
, tiled_level
, true));
423 radeon_emit(cs
, linear_address
);
424 radeon_emit(cs
, linear_address
>> 32);
425 radeon_emit(cs
, linear_x
| (linear_y
<< 16));
426 radeon_emit(cs
, linear_z
| ((linear_pitch
- 1) << 16));
427 radeon_emit(cs
, linear_slice_pitch
- 1);
428 if (sctx
->chip_class
== GFX7
) {
429 radeon_emit(cs
, copy_width_aligned
| (copy_height
<< 16));
430 radeon_emit(cs
, copy_depth
);
432 radeon_emit(cs
, (copy_width_aligned
- 1) | ((copy_height
- 1) << 16));
433 radeon_emit(cs
, (copy_depth
- 1));
439 /* Tiled -> Tiled sub-window copy. */
440 if (dst_mode
>= RADEON_SURF_MODE_1D
&& src_mode
>= RADEON_SURF_MODE_1D
&&
441 /* check if these fit into the bitfields */
442 src_address
% 256 == 0 && dst_address
% 256 == 0 &&
443 ssrc
->surface
.u
.legacy
.tile_split
<= 4096 && sdst
->surface
.u
.legacy
.tile_split
<= 4096 &&
444 dstx
% 8 == 0 && dsty
% 8 == 0 && srcx
% 8 == 0 && srcy
% 8 == 0 &&
445 /* this can either be equal, or display->rotated (GFX8+ only) */
446 (src_micro_mode
== dst_micro_mode
||
447 (sctx
->chip_class
>= GFX8
&& src_micro_mode
== V_009910_ADDR_SURF_DISPLAY_MICRO_TILING
&&
448 dst_micro_mode
== V_009910_ADDR_SURF_ROTATED_MICRO_TILING
))) {
449 assert(src_pitch
% 8 == 0);
450 assert(dst_pitch
% 8 == 0);
451 assert(src_slice_pitch
% 64 == 0);
452 assert(dst_slice_pitch
% 64 == 0);
453 unsigned src_pitch_tile_max
= src_pitch
/ 8 - 1;
454 unsigned dst_pitch_tile_max
= dst_pitch
/ 8 - 1;
455 unsigned src_slice_tile_max
= src_slice_pitch
/ 64 - 1;
456 unsigned dst_slice_tile_max
= dst_slice_pitch
/ 64 - 1;
457 unsigned copy_width_aligned
= copy_width
;
458 unsigned copy_height_aligned
= copy_height
;
460 /* If the region ends at the last pixel and is unaligned, we
461 * can copy the remainder of the tile that is not visible to
464 if (copy_width
% 8 != 0 && srcx
+ copy_width
== src_width
&& dstx
+ copy_width
== dst_width
)
465 copy_width_aligned
= align(copy_width
, 8);
467 if (copy_height
% 8 != 0 && srcy
+ copy_height
== src_height
&&
468 dsty
+ copy_height
== dst_height
)
469 copy_height_aligned
= align(copy_height
, 8);
471 /* check if these fit into the bitfields */
472 if (src_pitch_tile_max
< (1 << 11) && dst_pitch_tile_max
< (1 << 11) &&
473 src_slice_tile_max
< (1 << 22) && dst_slice_tile_max
< (1 << 22) &&
474 copy_width_aligned
<= (1 << 14) && copy_height_aligned
<= (1 << 14) &&
475 copy_depth
<= (1 << 11) && copy_width_aligned
% 8 == 0 && copy_height_aligned
% 8 == 0 &&
476 /* HW limitation - GFX7: */
477 (sctx
->chip_class
!= GFX7
||
478 (copy_width_aligned
< (1 << 14) && copy_height_aligned
< (1 << 14) &&
479 copy_depth
< (1 << 11))) &&
480 /* HW limitation - some GFX7 parts: */
481 ((sctx
->family
!= CHIP_BONAIRE
&& sctx
->family
!= CHIP_KAVERI
&&
482 sctx
->family
!= CHIP_KABINI
) ||
483 (srcx
+ copy_width_aligned
!= (1 << 14) && srcy
+ copy_height_aligned
!= (1 << 14) &&
484 dstx
+ copy_width
!= (1 << 14)))) {
485 struct radeon_cmdbuf
*cs
= sctx
->sdma_cs
;
487 si_need_dma_space(sctx
, 15, &sdst
->buffer
, &ssrc
->buffer
);
490 cs
, CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY
, CIK_SDMA_COPY_SUB_OPCODE_T2T_SUB_WINDOW
, 0));
491 radeon_emit(cs
, src_address
);
492 radeon_emit(cs
, src_address
>> 32);
493 radeon_emit(cs
, srcx
| (srcy
<< 16));
494 radeon_emit(cs
, srcz
| (src_pitch_tile_max
<< 16));
495 radeon_emit(cs
, src_slice_tile_max
);
496 radeon_emit(cs
, encode_tile_info(sctx
, ssrc
, src_level
, true));
497 radeon_emit(cs
, dst_address
);
498 radeon_emit(cs
, dst_address
>> 32);
499 radeon_emit(cs
, dstx
| (dsty
<< 16));
500 radeon_emit(cs
, dstz
| (dst_pitch_tile_max
<< 16));
501 radeon_emit(cs
, dst_slice_tile_max
);
502 radeon_emit(cs
, encode_tile_info(sctx
, sdst
, dst_level
, false));
503 if (sctx
->chip_class
== GFX7
) {
504 radeon_emit(cs
, copy_width_aligned
| (copy_height_aligned
<< 16));
505 radeon_emit(cs
, copy_depth
);
507 radeon_emit(cs
, (copy_width_aligned
- 8) | ((copy_height_aligned
- 8) << 16));
508 radeon_emit(cs
, (copy_depth
- 1));
517 static void cik_sdma_copy(struct pipe_context
*ctx
, struct pipe_resource
*dst
, unsigned dst_level
,
518 unsigned dstx
, unsigned dsty
, unsigned dstz
, struct pipe_resource
*src
,
519 unsigned src_level
, const struct pipe_box
*src_box
)
521 struct si_context
*sctx
= (struct si_context
*)ctx
;
523 assert(src
->target
!= PIPE_BUFFER
);
525 if (!sctx
->sdma_cs
|| src
->flags
& PIPE_RESOURCE_FLAG_SPARSE
||
526 dst
->flags
& PIPE_RESOURCE_FLAG_SPARSE
)
529 /* SDMA causes corruption. See:
530 * https://bugs.freedesktop.org/show_bug.cgi?id=110575
531 * https://bugs.freedesktop.org/show_bug.cgi?id=110635
533 * Keep SDMA enabled on APUs.
535 if (sctx
->screen
->debug_flags
& DBG(FORCE_SDMA
) ||
536 (!sctx
->screen
->info
.has_dedicated_vram
&&
537 !(sctx
->screen
->debug_flags
& DBG(NO_SDMA_COPY_IMAGE
)))) {
538 if ((sctx
->chip_class
== GFX7
|| sctx
->chip_class
== GFX8
) &&
539 cik_sdma_copy_texture(sctx
, dst
, dst_level
, dstx
, dsty
, dstz
, src
, src_level
, src_box
))
541 else if (sctx
->chip_class
== GFX9
&& si_sdma_v4_copy_texture(sctx
, dst
, dst_level
, dstx
, dsty
,
542 dstz
, src
, src_level
, src_box
))
547 si_resource_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
, src
, src_level
, src_box
);
550 void cik_init_sdma_functions(struct si_context
*sctx
)
552 sctx
->dma_copy
= cik_sdma_copy
;