blob: 9fb5780a552ff99f580fd7021f5233273bab74a2 [file] [log] [blame]
Alex Deucher27849042010-09-09 11:31:13 -04001/*
2 * Copyright 2009 Advanced Micro Devices, Inc.
3 * Copyright 2009 Red Hat Inc.
4 *
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:
11 *
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
14 * Software.
15 *
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 COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drmP.h>
27#include <drm/radeon_drm.h>
Jerome Glisse3ce0a232009-09-08 10:10:24 +100028#include "radeon.h"
29
30#include "r600d.h"
31#include "r600_blit_shaders.h"
Ilija Hadzic86a4d692012-02-01 11:42:38 -050032#include "radeon_blit_common.h"
Alex Deucher7dbf41d2011-05-17 05:09:43 -040033
Christian König14adc892013-01-21 13:58:46 +010034/* 23 bits of float fractional data */
35#define I2F_FRAC_BITS 23
36#define I2F_MASK ((1 << I2F_FRAC_BITS) - 1)
37
38/*
39 * Converts unsigned integer into 32-bit IEEE floating point representation.
40 * Will be exact from 0 to 2^24. Above that, we round towards zero
41 * as the fractional bits will not fit in a float. (It would be better to
42 * round towards even as the fpu does, but that is slower.)
43 */
44__pure uint32_t int2float(uint32_t x)
45{
46 uint32_t msb, exponent, fraction;
47
48 /* Zero is special */
49 if (!x) return 0;
50
51 /* Get location of the most significant bit */
52 msb = __fls(x);
53
54 /*
55 * Use a rotate instead of a shift because that works both leftwards
56 * and rightwards due to the mod(32) behaviour. This means we don't
57 * need to check to see if we are above 2^24 or not.
58 */
59 fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
60 exponent = (127 + msb) << I2F_FRAC_BITS;
61
62 return fraction + exponent;
63}
64
Jerome Glisse3ce0a232009-09-08 10:10:24 +100065/* emits 21 on rv770+, 23 on r600 */
66static void
67set_render_target(struct radeon_device *rdev, int format,
68 int w, int h, u64 gpu_addr)
69{
Christian Könige32eb502011-10-23 12:56:27 +020070 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +100071 u32 cb_color_info;
72 int pitch, slice;
73
Matt Turnerd964fc52010-02-25 04:23:31 +000074 h = ALIGN(h, 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100075 if (h < 8)
76 h = 8;
77
Ilija Hadzic3a386122011-10-12 23:29:37 -040078 cb_color_info = CB_FORMAT(format) |
79 CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM) |
80 CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100081 pitch = (w / 8) - 1;
82 slice = ((w * h) / 64) - 1;
83
Christian Könige32eb502011-10-23 12:56:27 +020084 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
85 radeon_ring_write(ring, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
86 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100087
88 if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +020089 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_BASE_UPDATE, 0));
90 radeon_ring_write(ring, 2 << 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100091 }
92
Christian Könige32eb502011-10-23 12:56:27 +020093 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
94 radeon_ring_write(ring, (CB_COLOR0_SIZE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
95 radeon_ring_write(ring, (pitch << 0) | (slice << 10));
Jerome Glisse3ce0a232009-09-08 10:10:24 +100096
Christian Könige32eb502011-10-23 12:56:27 +020097 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
98 radeon_ring_write(ring, (CB_COLOR0_VIEW - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
99 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000100
Christian Könige32eb502011-10-23 12:56:27 +0200101 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
102 radeon_ring_write(ring, (CB_COLOR0_INFO - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
103 radeon_ring_write(ring, cb_color_info);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000104
Christian Könige32eb502011-10-23 12:56:27 +0200105 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
106 radeon_ring_write(ring, (CB_COLOR0_TILE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
107 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000108
Christian Könige32eb502011-10-23 12:56:27 +0200109 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
110 radeon_ring_write(ring, (CB_COLOR0_FRAG - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
111 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000112
Christian Könige32eb502011-10-23 12:56:27 +0200113 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
114 radeon_ring_write(ring, (CB_COLOR0_MASK - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
115 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000116}
117
118/* emits 5dw */
119static void
120cp_set_surface_sync(struct radeon_device *rdev,
121 u32 sync_type, u32 size,
122 u64 mc_addr)
123{
Christian Könige32eb502011-10-23 12:56:27 +0200124 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000125 u32 cp_coher_size;
126
127 if (size == 0xffffffff)
128 cp_coher_size = 0xffffffff;
129 else
130 cp_coher_size = ((size + 255) >> 8);
131
Christian Könige32eb502011-10-23 12:56:27 +0200132 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
133 radeon_ring_write(ring, sync_type);
134 radeon_ring_write(ring, cp_coher_size);
135 radeon_ring_write(ring, mc_addr >> 8);
136 radeon_ring_write(ring, 10); /* poll interval */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000137}
138
139/* emits 21dw + 1 surface sync = 26dw */
140static void
141set_shaders(struct radeon_device *rdev)
142{
Christian Könige32eb502011-10-23 12:56:27 +0200143 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000144 u64 gpu_addr;
145 u32 sq_pgm_resources;
146
147 /* setup shader regs */
148 sq_pgm_resources = (1 << 0);
149
150 /* VS */
151 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200152 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
153 radeon_ring_write(ring, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
154 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000155
Christian Könige32eb502011-10-23 12:56:27 +0200156 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
157 radeon_ring_write(ring, (SQ_PGM_RESOURCES_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
158 radeon_ring_write(ring, sq_pgm_resources);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000159
Christian Könige32eb502011-10-23 12:56:27 +0200160 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
161 radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
162 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000163
164 /* PS */
165 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.ps_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200166 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
167 radeon_ring_write(ring, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
168 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000169
Christian Könige32eb502011-10-23 12:56:27 +0200170 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
171 radeon_ring_write(ring, (SQ_PGM_RESOURCES_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
172 radeon_ring_write(ring, sq_pgm_resources | (1 << 28));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000173
Christian Könige32eb502011-10-23 12:56:27 +0200174 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
175 radeon_ring_write(ring, (SQ_PGM_EXPORTS_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
176 radeon_ring_write(ring, 2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000177
Christian Könige32eb502011-10-23 12:56:27 +0200178 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
179 radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
180 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000181
Alex Deucher119e20d2009-09-10 02:53:50 -0400182 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000183 cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr);
184}
185
186/* emits 9 + 1 sync (5) = 14*/
187static void
188set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
189{
Christian Könige32eb502011-10-23 12:56:27 +0200190 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000191 u32 sq_vtx_constant_word2;
192
Ilija Hadzic3a386122011-10-12 23:29:37 -0400193 sq_vtx_constant_word2 = SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr) & 0xff) |
194 SQ_VTXC_STRIDE(16);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500195#ifdef __BIG_ENDIAN
Ilija Hadzic3a386122011-10-12 23:29:37 -0400196 sq_vtx_constant_word2 |= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500197#endif
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000198
Christian Könige32eb502011-10-23 12:56:27 +0200199 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7));
200 radeon_ring_write(ring, 0x460);
201 radeon_ring_write(ring, gpu_addr & 0xffffffff);
202 radeon_ring_write(ring, 48 - 1);
203 radeon_ring_write(ring, sq_vtx_constant_word2);
204 radeon_ring_write(ring, 1 << 0);
205 radeon_ring_write(ring, 0);
206 radeon_ring_write(ring, 0);
207 radeon_ring_write(ring, SQ_TEX_VTX_VALID_BUFFER << 30);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000208
209 if ((rdev->family == CHIP_RV610) ||
210 (rdev->family == CHIP_RV620) ||
211 (rdev->family == CHIP_RS780) ||
212 (rdev->family == CHIP_RS880) ||
213 (rdev->family == CHIP_RV710))
214 cp_set_surface_sync(rdev,
215 PACKET3_TC_ACTION_ENA, 48, gpu_addr);
216 else
217 cp_set_surface_sync(rdev,
218 PACKET3_VC_ACTION_ENA, 48, gpu_addr);
219}
220
221/* emits 9 */
222static void
223set_tex_resource(struct radeon_device *rdev,
224 int format, int w, int h, int pitch,
Alex Deucher9bb77032011-10-22 10:07:09 -0400225 u64 gpu_addr, u32 size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000226{
Christian Könige32eb502011-10-23 12:56:27 +0200227 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000228 uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4;
229
230 if (h < 1)
231 h = 1;
232
Ilija Hadzic3a386122011-10-12 23:29:37 -0400233 sq_tex_resource_word0 = S_038000_DIM(V_038000_SQ_TEX_DIM_2D) |
234 S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1);
235 sq_tex_resource_word0 |= S_038000_PITCH((pitch >> 3) - 1) |
236 S_038000_TEX_WIDTH(w - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000237
Ilija Hadzic3a386122011-10-12 23:29:37 -0400238 sq_tex_resource_word1 = S_038004_DATA_FORMAT(format);
239 sq_tex_resource_word1 |= S_038004_TEX_HEIGHT(h - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000240
Ilija Hadzic3a386122011-10-12 23:29:37 -0400241 sq_tex_resource_word4 = S_038010_REQUEST_SIZE(1) |
242 S_038010_DST_SEL_X(SQ_SEL_X) |
243 S_038010_DST_SEL_Y(SQ_SEL_Y) |
244 S_038010_DST_SEL_Z(SQ_SEL_Z) |
245 S_038010_DST_SEL_W(SQ_SEL_W);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000246
Alex Deucher9bb77032011-10-22 10:07:09 -0400247 cp_set_surface_sync(rdev,
248 PACKET3_TC_ACTION_ENA, size, gpu_addr);
249
Christian Könige32eb502011-10-23 12:56:27 +0200250 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7));
251 radeon_ring_write(ring, 0);
252 radeon_ring_write(ring, sq_tex_resource_word0);
253 radeon_ring_write(ring, sq_tex_resource_word1);
254 radeon_ring_write(ring, gpu_addr >> 8);
255 radeon_ring_write(ring, gpu_addr >> 8);
256 radeon_ring_write(ring, sq_tex_resource_word4);
257 radeon_ring_write(ring, 0);
258 radeon_ring_write(ring, SQ_TEX_VTX_VALID_TEXTURE << 30);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000259}
260
261/* emits 12 */
262static void
263set_scissors(struct radeon_device *rdev, int x1, int y1,
264 int x2, int y2)
265{
Christian Könige32eb502011-10-23 12:56:27 +0200266 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
267 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
268 radeon_ring_write(ring, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
269 radeon_ring_write(ring, (x1 << 0) | (y1 << 16));
270 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000271
Christian Könige32eb502011-10-23 12:56:27 +0200272 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
273 radeon_ring_write(ring, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
274 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
275 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000276
Christian Könige32eb502011-10-23 12:56:27 +0200277 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
278 radeon_ring_write(ring, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
279 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
280 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000281}
282
283/* emits 10 */
284static void
285draw_auto(struct radeon_device *rdev)
286{
Christian Könige32eb502011-10-23 12:56:27 +0200287 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
288 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
289 radeon_ring_write(ring, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
290 radeon_ring_write(ring, DI_PT_RECTLIST);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000291
Christian Könige32eb502011-10-23 12:56:27 +0200292 radeon_ring_write(ring, PACKET3(PACKET3_INDEX_TYPE, 0));
293 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -0500294#ifdef __BIG_ENDIAN
295 (2 << 2) |
296#endif
297 DI_INDEX_SIZE_16_BIT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000298
Christian Könige32eb502011-10-23 12:56:27 +0200299 radeon_ring_write(ring, PACKET3(PACKET3_NUM_INSTANCES, 0));
300 radeon_ring_write(ring, 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000301
Christian Könige32eb502011-10-23 12:56:27 +0200302 radeon_ring_write(ring, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1));
303 radeon_ring_write(ring, 3);
304 radeon_ring_write(ring, DI_SRC_SEL_AUTO_INDEX);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000305
306}
307
308/* emits 14 */
309static void
310set_default_state(struct radeon_device *rdev)
311{
Christian Könige32eb502011-10-23 12:56:27 +0200312 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000313 u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2;
314 u32 sq_thread_resource_mgmt, sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2;
315 int num_ps_gprs, num_vs_gprs, num_temp_gprs, num_gs_gprs, num_es_gprs;
316 int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
317 int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
318 u64 gpu_addr;
Alex Deucher119e20d2009-09-10 02:53:50 -0400319 int dwords;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000320
321 switch (rdev->family) {
322 case CHIP_R600:
323 num_ps_gprs = 192;
324 num_vs_gprs = 56;
325 num_temp_gprs = 4;
326 num_gs_gprs = 0;
327 num_es_gprs = 0;
328 num_ps_threads = 136;
329 num_vs_threads = 48;
330 num_gs_threads = 4;
331 num_es_threads = 4;
332 num_ps_stack_entries = 128;
333 num_vs_stack_entries = 128;
334 num_gs_stack_entries = 0;
335 num_es_stack_entries = 0;
336 break;
337 case CHIP_RV630:
338 case CHIP_RV635:
339 num_ps_gprs = 84;
340 num_vs_gprs = 36;
341 num_temp_gprs = 4;
342 num_gs_gprs = 0;
343 num_es_gprs = 0;
344 num_ps_threads = 144;
345 num_vs_threads = 40;
346 num_gs_threads = 4;
347 num_es_threads = 4;
348 num_ps_stack_entries = 40;
349 num_vs_stack_entries = 40;
350 num_gs_stack_entries = 32;
351 num_es_stack_entries = 16;
352 break;
353 case CHIP_RV610:
354 case CHIP_RV620:
355 case CHIP_RS780:
356 case CHIP_RS880:
357 default:
358 num_ps_gprs = 84;
359 num_vs_gprs = 36;
360 num_temp_gprs = 4;
361 num_gs_gprs = 0;
362 num_es_gprs = 0;
363 num_ps_threads = 136;
364 num_vs_threads = 48;
365 num_gs_threads = 4;
366 num_es_threads = 4;
367 num_ps_stack_entries = 40;
368 num_vs_stack_entries = 40;
369 num_gs_stack_entries = 32;
370 num_es_stack_entries = 16;
371 break;
372 case CHIP_RV670:
373 num_ps_gprs = 144;
374 num_vs_gprs = 40;
375 num_temp_gprs = 4;
376 num_gs_gprs = 0;
377 num_es_gprs = 0;
378 num_ps_threads = 136;
379 num_vs_threads = 48;
380 num_gs_threads = 4;
381 num_es_threads = 4;
382 num_ps_stack_entries = 40;
383 num_vs_stack_entries = 40;
384 num_gs_stack_entries = 32;
385 num_es_stack_entries = 16;
386 break;
387 case CHIP_RV770:
388 num_ps_gprs = 192;
389 num_vs_gprs = 56;
390 num_temp_gprs = 4;
391 num_gs_gprs = 0;
392 num_es_gprs = 0;
393 num_ps_threads = 188;
394 num_vs_threads = 60;
395 num_gs_threads = 0;
396 num_es_threads = 0;
397 num_ps_stack_entries = 256;
398 num_vs_stack_entries = 256;
399 num_gs_stack_entries = 0;
400 num_es_stack_entries = 0;
401 break;
402 case CHIP_RV730:
403 case CHIP_RV740:
404 num_ps_gprs = 84;
405 num_vs_gprs = 36;
406 num_temp_gprs = 4;
407 num_gs_gprs = 0;
408 num_es_gprs = 0;
409 num_ps_threads = 188;
410 num_vs_threads = 60;
411 num_gs_threads = 0;
412 num_es_threads = 0;
413 num_ps_stack_entries = 128;
414 num_vs_stack_entries = 128;
415 num_gs_stack_entries = 0;
416 num_es_stack_entries = 0;
417 break;
418 case CHIP_RV710:
419 num_ps_gprs = 192;
420 num_vs_gprs = 56;
421 num_temp_gprs = 4;
422 num_gs_gprs = 0;
423 num_es_gprs = 0;
424 num_ps_threads = 144;
425 num_vs_threads = 48;
426 num_gs_threads = 0;
427 num_es_threads = 0;
428 num_ps_stack_entries = 128;
429 num_vs_stack_entries = 128;
430 num_gs_stack_entries = 0;
431 num_es_stack_entries = 0;
432 break;
433 }
434
435 if ((rdev->family == CHIP_RV610) ||
436 (rdev->family == CHIP_RV620) ||
437 (rdev->family == CHIP_RS780) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -0500438 (rdev->family == CHIP_RS880) ||
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000439 (rdev->family == CHIP_RV710))
440 sq_config = 0;
441 else
442 sq_config = VC_ENABLE;
443
444 sq_config |= (DX9_CONSTS |
445 ALU_INST_PREFER_VECTOR |
446 PS_PRIO(0) |
447 VS_PRIO(1) |
448 GS_PRIO(2) |
449 ES_PRIO(3));
450
451 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) |
452 NUM_VS_GPRS(num_vs_gprs) |
453 NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
454 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) |
455 NUM_ES_GPRS(num_es_gprs));
456 sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) |
457 NUM_VS_THREADS(num_vs_threads) |
458 NUM_GS_THREADS(num_gs_threads) |
459 NUM_ES_THREADS(num_es_threads));
460 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
461 NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
462 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
463 NUM_ES_STACK_ENTRIES(num_es_stack_entries));
464
465 /* emit an IB pointing at default state */
Matt Turnerd964fc52010-02-25 04:23:31 +0000466 dwords = ALIGN(rdev->r600_blit.state_len, 0x10);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000467 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.state_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200468 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
469 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -0500470#ifdef __BIG_ENDIAN
471 (2 << 0) |
472#endif
473 (gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +0200474 radeon_ring_write(ring, upper_32_bits(gpu_addr) & 0xFF);
475 radeon_ring_write(ring, dwords);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000476
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000477 /* SQ config */
Christian Könige32eb502011-10-23 12:56:27 +0200478 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 6));
479 radeon_ring_write(ring, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
480 radeon_ring_write(ring, sq_config);
481 radeon_ring_write(ring, sq_gpr_resource_mgmt_1);
482 radeon_ring_write(ring, sq_gpr_resource_mgmt_2);
483 radeon_ring_write(ring, sq_thread_resource_mgmt);
484 radeon_ring_write(ring, sq_stack_resource_mgmt_1);
485 radeon_ring_write(ring, sq_stack_resource_mgmt_2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000486}
487
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000488int r600_blit_init(struct radeon_device *rdev)
489{
490 u32 obj_size;
Cédric Cano4eace7f2011-02-11 19:45:38 -0500491 int i, r, dwords;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000492 void *ptr;
Alex Deucher119e20d2009-09-10 02:53:50 -0400493 u32 packet2s[16];
494 int num_packet2s = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000495
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400496 rdev->r600_blit.primitives.set_render_target = set_render_target;
497 rdev->r600_blit.primitives.cp_set_surface_sync = cp_set_surface_sync;
498 rdev->r600_blit.primitives.set_shaders = set_shaders;
499 rdev->r600_blit.primitives.set_vtx_resource = set_vtx_resource;
500 rdev->r600_blit.primitives.set_tex_resource = set_tex_resource;
501 rdev->r600_blit.primitives.set_scissors = set_scissors;
502 rdev->r600_blit.primitives.draw_auto = draw_auto;
503 rdev->r600_blit.primitives.set_default_state = set_default_state;
504
Christian König220907d2012-05-10 16:46:43 +0200505 rdev->r600_blit.ring_size_common = 8; /* sync semaphore */
506 rdev->r600_blit.ring_size_common += 40; /* shaders + def state */
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400507 rdev->r600_blit.ring_size_common += 5; /* done copy */
Jerome Glisse77b1bad2011-10-26 11:41:22 -0400508 rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400509
510 rdev->r600_blit.ring_size_per_loop = 76;
511 /* set_render_target emits 2 extra dwords on rv6xx */
512 if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770)
513 rdev->r600_blit.ring_size_per_loop += 2;
514
515 rdev->r600_blit.max_dim = 8192;
516
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000517 rdev->r600_blit.state_offset = 0;
518
519 if (rdev->family >= CHIP_RV770)
Alex Deucher119e20d2009-09-10 02:53:50 -0400520 rdev->r600_blit.state_len = r7xx_default_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000521 else
Alex Deucher119e20d2009-09-10 02:53:50 -0400522 rdev->r600_blit.state_len = r6xx_default_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000523
Alex Deucher119e20d2009-09-10 02:53:50 -0400524 dwords = rdev->r600_blit.state_len;
525 while (dwords & 0xf) {
Cédric Cano4eace7f2011-02-11 19:45:38 -0500526 packet2s[num_packet2s++] = cpu_to_le32(PACKET2(0));
Alex Deucher119e20d2009-09-10 02:53:50 -0400527 dwords++;
528 }
529
530 obj_size = dwords * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000531 obj_size = ALIGN(obj_size, 256);
532
533 rdev->r600_blit.vs_offset = obj_size;
534 obj_size += r6xx_vs_size * 4;
535 obj_size = ALIGN(obj_size, 256);
536
537 rdev->r600_blit.ps_offset = obj_size;
538 obj_size += r6xx_ps_size * 4;
539 obj_size = ALIGN(obj_size, 256);
540
Christian König6f72a632012-07-05 16:05:28 +0200541 /* pin copy shader into vram if not already initialized */
542 if (rdev->r600_blit.shader_obj == NULL) {
543 r = radeon_bo_create(rdev, obj_size, PAGE_SIZE, true,
544 RADEON_GEM_DOMAIN_VRAM,
545 NULL, &rdev->r600_blit.shader_obj);
546 if (r) {
547 DRM_ERROR("r600 failed to allocate shader\n");
548 return r;
549 }
550
551 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
552 if (unlikely(r != 0))
553 return r;
554 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
555 &rdev->r600_blit.shader_gpu_addr);
556 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
557 if (r) {
558 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
559 return r;
560 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000561 }
562
Dave Airliebc1a6312009-09-15 11:07:52 +1000563 DRM_DEBUG("r6xx blit allocated bo %08x vs %08x ps %08x\n",
564 obj_size,
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000565 rdev->r600_blit.vs_offset, rdev->r600_blit.ps_offset);
566
Jerome Glisse4c788672009-11-20 14:29:23 +0100567 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
568 if (unlikely(r != 0))
569 return r;
570 r = radeon_bo_kmap(rdev->r600_blit.shader_obj, &ptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000571 if (r) {
572 DRM_ERROR("failed to map blit object %d\n", r);
573 return r;
574 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000575 if (rdev->family >= CHIP_RV770)
Alex Deucher119e20d2009-09-10 02:53:50 -0400576 memcpy_toio(ptr + rdev->r600_blit.state_offset,
577 r7xx_default_state, rdev->r600_blit.state_len * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000578 else
Alex Deucher119e20d2009-09-10 02:53:50 -0400579 memcpy_toio(ptr + rdev->r600_blit.state_offset,
580 r6xx_default_state, rdev->r600_blit.state_len * 4);
581 if (num_packet2s)
582 memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
583 packet2s, num_packet2s * 4);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500584 for (i = 0; i < r6xx_vs_size; i++)
585 *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(r6xx_vs[i]);
586 for (i = 0; i < r6xx_ps_size; i++)
587 *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(r6xx_ps[i]);
Jerome Glisse4c788672009-11-20 14:29:23 +0100588 radeon_bo_kunmap(rdev->r600_blit.shader_obj);
589 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Alex Deucherb70d6bb2010-08-06 21:36:58 -0400590
Dave Airlie53595332011-03-14 09:47:24 +1000591 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000592 return 0;
593}
594
595void r600_blit_fini(struct radeon_device *rdev)
596{
Jerome Glisse4c788672009-11-20 14:29:23 +0100597 int r;
598
Dave Airlie53595332011-03-14 09:47:24 +1000599 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse30d2d9a2010-01-13 10:29:27 +0100600 if (rdev->r600_blit.shader_obj == NULL)
601 return;
602 /* If we can't reserve the bo, unref should be enough to destroy
603 * it when it becomes idle.
604 */
Jerome Glisse4c788672009-11-20 14:29:23 +0100605 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
Jerome Glisse30d2d9a2010-01-13 10:29:27 +0100606 if (!r) {
607 radeon_bo_unpin(rdev->r600_blit.shader_obj);
608 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Jerome Glisse4c788672009-11-20 14:29:23 +0100609 }
Jerome Glisse4c788672009-11-20 14:29:23 +0100610 radeon_bo_unref(&rdev->r600_blit.shader_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000611}
612
Ilija Hadzicb3530962011-10-12 23:29:42 -0400613static unsigned r600_blit_create_rect(unsigned num_gpu_pages,
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400614 int *width, int *height, int max_dim)
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400615{
616 unsigned max_pages;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400617 unsigned pages = num_gpu_pages;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400618 int w, h;
619
Ilija Hadzicb3530962011-10-12 23:29:42 -0400620 if (num_gpu_pages == 0) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400621 /* not supposed to be called with no pages, but just in case */
622 h = 0;
623 w = 0;
624 pages = 0;
625 WARN_ON(1);
626 } else {
627 int rect_order = 2;
628 h = RECT_UNIT_H;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400629 while (num_gpu_pages / rect_order) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400630 h *= 2;
631 rect_order *= 4;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400632 if (h >= max_dim) {
633 h = max_dim;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400634 break;
635 }
636 }
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400637 max_pages = (max_dim * h) / (RECT_UNIT_W * RECT_UNIT_H);
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400638 if (pages > max_pages)
639 pages = max_pages;
640 w = (pages * RECT_UNIT_W * RECT_UNIT_H) / h;
641 w = (w / RECT_UNIT_W) * RECT_UNIT_W;
642 pages = (w * h) / (RECT_UNIT_W * RECT_UNIT_H);
643 BUG_ON(pages == 0);
644 }
645
646
647 DRM_DEBUG("blit_rectangle: h=%d, w=%d, pages=%d\n", h, w, pages);
648
649 /* return width and height only of the caller wants it */
650 if (height)
651 *height = h;
652 if (width)
653 *width = w;
654
655 return pages;
656}
657
658
Christian Königf2377502012-05-09 15:35:01 +0200659int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
Christian König220907d2012-05-10 16:46:43 +0200660 struct radeon_fence **fence, struct radeon_sa_bo **vb,
661 struct radeon_semaphore **sem)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000662{
Christian Könige32eb502011-10-23 12:56:27 +0200663 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000664 int r;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400665 int ring_size;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400666 int num_loops = 0;
667 int dwords_per_loop = rdev->r600_blit.ring_size_per_loop;
Dave Airlie7cbb3552009-09-17 16:11:31 +1000668
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400669 /* num loops */
Ilija Hadzicb3530962011-10-12 23:29:42 -0400670 while (num_gpu_pages) {
671 num_gpu_pages -=
672 r600_blit_create_rect(num_gpu_pages, NULL, NULL,
673 rdev->r600_blit.max_dim);
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400674 num_loops++;
675 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000676
Jerome Glisse69e130a2011-12-21 12:13:46 -0500677 /* 48 bytes for vertex per loop */
Christian Königf2377502012-05-09 15:35:01 +0200678 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, vb,
679 (num_loops*48)+256, 256, true);
680 if (r) {
Jerome Glisse69e130a2011-12-21 12:13:46 -0500681 return r;
Christian Königf2377502012-05-09 15:35:01 +0200682 }
Jerome Glisse69e130a2011-12-21 12:13:46 -0500683
Christian König220907d2012-05-10 16:46:43 +0200684 r = radeon_semaphore_create(rdev, sem);
685 if (r) {
686 radeon_sa_bo_free(rdev, vb, NULL);
687 return r;
688 }
689
Dave Airlie7cbb3552009-09-17 16:11:31 +1000690 /* calculate number of loops correctly */
691 ring_size = num_loops * dwords_per_loop;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400692 ring_size += rdev->r600_blit.ring_size_common;
Christian Könige32eb502011-10-23 12:56:27 +0200693 r = radeon_ring_lock(rdev, ring, ring_size);
Christian Königf2377502012-05-09 15:35:01 +0200694 if (r) {
695 radeon_sa_bo_free(rdev, vb, NULL);
Christian König220907d2012-05-10 16:46:43 +0200696 radeon_semaphore_free(rdev, sem, NULL);
Jerome Glisseff82f052010-01-22 15:19:00 +0100697 return r;
Christian Königf2377502012-05-09 15:35:01 +0200698 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000699
Christian König220907d2012-05-10 16:46:43 +0200700 if (radeon_fence_need_sync(*fence, RADEON_RING_TYPE_GFX_INDEX)) {
701 radeon_semaphore_sync_rings(rdev, *sem, (*fence)->ring,
702 RADEON_RING_TYPE_GFX_INDEX);
703 radeon_fence_note_sync(*fence, RADEON_RING_TYPE_GFX_INDEX);
704 } else {
705 radeon_semaphore_free(rdev, sem, NULL);
706 }
707
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400708 rdev->r600_blit.primitives.set_default_state(rdev);
709 rdev->r600_blit.primitives.set_shaders(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000710 return 0;
711}
712
Christian König876dc9f2012-05-08 14:24:01 +0200713void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence,
Christian König220907d2012-05-10 16:46:43 +0200714 struct radeon_sa_bo *vb, struct radeon_semaphore *sem)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000715{
Christian Königf2377502012-05-09 15:35:01 +0200716 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000717 int r;
718
Christian König876dc9f2012-05-08 14:24:01 +0200719 r = radeon_fence_emit(rdev, fence, RADEON_RING_TYPE_GFX_INDEX);
Christian Königf2377502012-05-09 15:35:01 +0200720 if (r) {
721 radeon_ring_unlock_undo(rdev, ring);
722 return;
723 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000724
Christian Königf2377502012-05-09 15:35:01 +0200725 radeon_ring_unlock_commit(rdev, ring);
Christian König876dc9f2012-05-08 14:24:01 +0200726 radeon_sa_bo_free(rdev, &vb, *fence);
Christian König220907d2012-05-10 16:46:43 +0200727 radeon_semaphore_free(rdev, &sem, *fence);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000728}
729
730void r600_kms_blit_copy(struct radeon_device *rdev,
731 u64 src_gpu_addr, u64 dst_gpu_addr,
Christian Königf2377502012-05-09 15:35:01 +0200732 unsigned num_gpu_pages,
733 struct radeon_sa_bo *vb)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000734{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000735 u64 vb_gpu_addr;
Christian Königf2377502012-05-09 15:35:01 +0200736 u32 *vb_cpu_addr;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000737
Christian Königf2377502012-05-09 15:35:01 +0200738 DRM_DEBUG("emitting copy %16llx %16llx %d\n",
739 src_gpu_addr, dst_gpu_addr, num_gpu_pages);
740 vb_cpu_addr = (u32 *)radeon_sa_bo_cpu_addr(vb);
741 vb_gpu_addr = radeon_sa_bo_gpu_addr(vb);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000742
Ilija Hadzicb3530962011-10-12 23:29:42 -0400743 while (num_gpu_pages) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400744 int w, h;
745 unsigned size_in_bytes;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400746 unsigned pages_per_loop =
Ilija Hadzicb3530962011-10-12 23:29:42 -0400747 r600_blit_create_rect(num_gpu_pages, &w, &h,
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400748 rdev->r600_blit.max_dim);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000749
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400750 size_in_bytes = pages_per_loop * RADEON_GPU_PAGE_SIZE;
751 DRM_DEBUG("rectangle w=%d h=%d\n", w, h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000752
Christian Königf2377502012-05-09 15:35:01 +0200753 vb_cpu_addr[0] = 0;
754 vb_cpu_addr[1] = 0;
755 vb_cpu_addr[2] = 0;
756 vb_cpu_addr[3] = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000757
Christian Königf2377502012-05-09 15:35:01 +0200758 vb_cpu_addr[4] = 0;
Steven Fuerst7ff64fc2012-08-15 15:07:14 -0700759 vb_cpu_addr[5] = int2float(h);
Christian Königf2377502012-05-09 15:35:01 +0200760 vb_cpu_addr[6] = 0;
Steven Fuerst7ff64fc2012-08-15 15:07:14 -0700761 vb_cpu_addr[7] = int2float(h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000762
Steven Fuerst7ff64fc2012-08-15 15:07:14 -0700763 vb_cpu_addr[8] = int2float(w);
764 vb_cpu_addr[9] = int2float(h);
765 vb_cpu_addr[10] = int2float(w);
766 vb_cpu_addr[11] = int2float(h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000767
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400768 rdev->r600_blit.primitives.set_tex_resource(rdev, FMT_8_8_8_8,
Alex Deucher9bb77032011-10-22 10:07:09 -0400769 w, h, w, src_gpu_addr, size_in_bytes);
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400770 rdev->r600_blit.primitives.set_render_target(rdev, COLOR_8_8_8_8,
771 w, h, dst_gpu_addr);
772 rdev->r600_blit.primitives.set_scissors(rdev, 0, 0, w, h);
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400773 rdev->r600_blit.primitives.set_vtx_resource(rdev, vb_gpu_addr);
774 rdev->r600_blit.primitives.draw_auto(rdev);
775 rdev->r600_blit.primitives.cp_set_surface_sync(rdev,
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400776 PACKET3_CB_ACTION_ENA | PACKET3_CB0_DEST_BASE_ENA,
777 size_in_bytes, dst_gpu_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000778
Christian Königf2377502012-05-09 15:35:01 +0200779 vb_cpu_addr += 12;
780 vb_gpu_addr += 4*12;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400781 src_gpu_addr += size_in_bytes;
782 dst_gpu_addr += size_in_bytes;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400783 num_gpu_pages -= pages_per_loop;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000784 }
785}