Alex Deucher | 2784904 | 2010-09-09 11:31:13 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 26 | #include "drmP.h" |
| 27 | #include "drm.h" |
| 28 | #include "radeon_drm.h" |
| 29 | #include "radeon.h" |
| 30 | |
| 31 | #include "r600d.h" |
| 32 | #include "r600_blit_shaders.h" |
Ilija Hadzic | 86a4d69 | 2012-02-01 11:42:38 -0500 | [diff] [blame] | 33 | #include "radeon_blit_common.h" |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 34 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 35 | /* emits 21 on rv770+, 23 on r600 */ |
| 36 | static void |
| 37 | set_render_target(struct radeon_device *rdev, int format, |
| 38 | int w, int h, u64 gpu_addr) |
| 39 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 40 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 41 | u32 cb_color_info; |
| 42 | int pitch, slice; |
| 43 | |
Matt Turner | d964fc5 | 2010-02-25 04:23:31 +0000 | [diff] [blame] | 44 | h = ALIGN(h, 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 45 | if (h < 8) |
| 46 | h = 8; |
| 47 | |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 48 | cb_color_info = CB_FORMAT(format) | |
| 49 | CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM) | |
| 50 | CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 51 | pitch = (w / 8) - 1; |
| 52 | slice = ((w * h) / 64) - 1; |
| 53 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 54 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 55 | radeon_ring_write(ring, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 56 | radeon_ring_write(ring, gpu_addr >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 57 | |
| 58 | if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 59 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_BASE_UPDATE, 0)); |
| 60 | radeon_ring_write(ring, 2 << 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 61 | } |
| 62 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 63 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 64 | radeon_ring_write(ring, (CB_COLOR0_SIZE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 65 | radeon_ring_write(ring, (pitch << 0) | (slice << 10)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 66 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 67 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 68 | radeon_ring_write(ring, (CB_COLOR0_VIEW - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 69 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 70 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 71 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 72 | radeon_ring_write(ring, (CB_COLOR0_INFO - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 73 | radeon_ring_write(ring, cb_color_info); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 74 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 75 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 76 | radeon_ring_write(ring, (CB_COLOR0_TILE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 77 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 78 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 79 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 80 | radeon_ring_write(ring, (CB_COLOR0_FRAG - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 81 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 82 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 83 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 84 | radeon_ring_write(ring, (CB_COLOR0_MASK - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 85 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* emits 5dw */ |
| 89 | static void |
| 90 | cp_set_surface_sync(struct radeon_device *rdev, |
| 91 | u32 sync_type, u32 size, |
| 92 | u64 mc_addr) |
| 93 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 94 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 95 | u32 cp_coher_size; |
| 96 | |
| 97 | if (size == 0xffffffff) |
| 98 | cp_coher_size = 0xffffffff; |
| 99 | else |
| 100 | cp_coher_size = ((size + 255) >> 8); |
| 101 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 102 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3)); |
| 103 | radeon_ring_write(ring, sync_type); |
| 104 | radeon_ring_write(ring, cp_coher_size); |
| 105 | radeon_ring_write(ring, mc_addr >> 8); |
| 106 | radeon_ring_write(ring, 10); /* poll interval */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* emits 21dw + 1 surface sync = 26dw */ |
| 110 | static void |
| 111 | set_shaders(struct radeon_device *rdev) |
| 112 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 113 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 114 | u64 gpu_addr; |
| 115 | u32 sq_pgm_resources; |
| 116 | |
| 117 | /* setup shader regs */ |
| 118 | sq_pgm_resources = (1 << 0); |
| 119 | |
| 120 | /* VS */ |
| 121 | gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 122 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 123 | radeon_ring_write(ring, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 124 | radeon_ring_write(ring, gpu_addr >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 125 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 126 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 127 | radeon_ring_write(ring, (SQ_PGM_RESOURCES_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 128 | radeon_ring_write(ring, sq_pgm_resources); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 129 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 130 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 131 | radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 132 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 133 | |
| 134 | /* PS */ |
| 135 | gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.ps_offset; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 136 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 137 | radeon_ring_write(ring, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 138 | radeon_ring_write(ring, gpu_addr >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 139 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 140 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 141 | radeon_ring_write(ring, (SQ_PGM_RESOURCES_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 142 | radeon_ring_write(ring, sq_pgm_resources | (1 << 28)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 143 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 144 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 145 | radeon_ring_write(ring, (SQ_PGM_EXPORTS_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 146 | radeon_ring_write(ring, 2); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 147 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 148 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1)); |
| 149 | radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 150 | radeon_ring_write(ring, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 151 | |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 152 | gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 153 | cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr); |
| 154 | } |
| 155 | |
| 156 | /* emits 9 + 1 sync (5) = 14*/ |
| 157 | static void |
| 158 | set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr) |
| 159 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 160 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 161 | u32 sq_vtx_constant_word2; |
| 162 | |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 163 | sq_vtx_constant_word2 = SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr) & 0xff) | |
| 164 | SQ_VTXC_STRIDE(16); |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 165 | #ifdef __BIG_ENDIAN |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 166 | sq_vtx_constant_word2 |= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32); |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 167 | #endif |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 168 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 169 | radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7)); |
| 170 | radeon_ring_write(ring, 0x460); |
| 171 | radeon_ring_write(ring, gpu_addr & 0xffffffff); |
| 172 | radeon_ring_write(ring, 48 - 1); |
| 173 | radeon_ring_write(ring, sq_vtx_constant_word2); |
| 174 | radeon_ring_write(ring, 1 << 0); |
| 175 | radeon_ring_write(ring, 0); |
| 176 | radeon_ring_write(ring, 0); |
| 177 | radeon_ring_write(ring, SQ_TEX_VTX_VALID_BUFFER << 30); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 178 | |
| 179 | if ((rdev->family == CHIP_RV610) || |
| 180 | (rdev->family == CHIP_RV620) || |
| 181 | (rdev->family == CHIP_RS780) || |
| 182 | (rdev->family == CHIP_RS880) || |
| 183 | (rdev->family == CHIP_RV710)) |
| 184 | cp_set_surface_sync(rdev, |
| 185 | PACKET3_TC_ACTION_ENA, 48, gpu_addr); |
| 186 | else |
| 187 | cp_set_surface_sync(rdev, |
| 188 | PACKET3_VC_ACTION_ENA, 48, gpu_addr); |
| 189 | } |
| 190 | |
| 191 | /* emits 9 */ |
| 192 | static void |
| 193 | set_tex_resource(struct radeon_device *rdev, |
| 194 | int format, int w, int h, int pitch, |
Alex Deucher | 9bb7703 | 2011-10-22 10:07:09 -0400 | [diff] [blame] | 195 | u64 gpu_addr, u32 size) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 196 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 197 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 198 | uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4; |
| 199 | |
| 200 | if (h < 1) |
| 201 | h = 1; |
| 202 | |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 203 | sq_tex_resource_word0 = S_038000_DIM(V_038000_SQ_TEX_DIM_2D) | |
| 204 | S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1); |
| 205 | sq_tex_resource_word0 |= S_038000_PITCH((pitch >> 3) - 1) | |
| 206 | S_038000_TEX_WIDTH(w - 1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 207 | |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 208 | sq_tex_resource_word1 = S_038004_DATA_FORMAT(format); |
| 209 | sq_tex_resource_word1 |= S_038004_TEX_HEIGHT(h - 1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 210 | |
Ilija Hadzic | 3a38612 | 2011-10-12 23:29:37 -0400 | [diff] [blame] | 211 | sq_tex_resource_word4 = S_038010_REQUEST_SIZE(1) | |
| 212 | S_038010_DST_SEL_X(SQ_SEL_X) | |
| 213 | S_038010_DST_SEL_Y(SQ_SEL_Y) | |
| 214 | S_038010_DST_SEL_Z(SQ_SEL_Z) | |
| 215 | S_038010_DST_SEL_W(SQ_SEL_W); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 216 | |
Alex Deucher | 9bb7703 | 2011-10-22 10:07:09 -0400 | [diff] [blame] | 217 | cp_set_surface_sync(rdev, |
| 218 | PACKET3_TC_ACTION_ENA, size, gpu_addr); |
| 219 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 220 | radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7)); |
| 221 | radeon_ring_write(ring, 0); |
| 222 | radeon_ring_write(ring, sq_tex_resource_word0); |
| 223 | radeon_ring_write(ring, sq_tex_resource_word1); |
| 224 | radeon_ring_write(ring, gpu_addr >> 8); |
| 225 | radeon_ring_write(ring, gpu_addr >> 8); |
| 226 | radeon_ring_write(ring, sq_tex_resource_word4); |
| 227 | radeon_ring_write(ring, 0); |
| 228 | radeon_ring_write(ring, SQ_TEX_VTX_VALID_TEXTURE << 30); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* emits 12 */ |
| 232 | static void |
| 233 | set_scissors(struct radeon_device *rdev, int x1, int y1, |
| 234 | int x2, int y2) |
| 235 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 236 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
| 237 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2)); |
| 238 | radeon_ring_write(ring, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 239 | radeon_ring_write(ring, (x1 << 0) | (y1 << 16)); |
| 240 | radeon_ring_write(ring, (x2 << 0) | (y2 << 16)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 241 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 242 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2)); |
| 243 | radeon_ring_write(ring, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 244 | radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31)); |
| 245 | radeon_ring_write(ring, (x2 << 0) | (y2 << 16)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 246 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 247 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2)); |
| 248 | radeon_ring_write(ring, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2); |
| 249 | radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31)); |
| 250 | radeon_ring_write(ring, (x2 << 0) | (y2 << 16)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* emits 10 */ |
| 254 | static void |
| 255 | draw_auto(struct radeon_device *rdev) |
| 256 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 257 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
| 258 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 259 | radeon_ring_write(ring, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_OFFSET) >> 2); |
| 260 | radeon_ring_write(ring, DI_PT_RECTLIST); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 261 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 262 | radeon_ring_write(ring, PACKET3(PACKET3_INDEX_TYPE, 0)); |
| 263 | radeon_ring_write(ring, |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 264 | #ifdef __BIG_ENDIAN |
| 265 | (2 << 2) | |
| 266 | #endif |
| 267 | DI_INDEX_SIZE_16_BIT); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 268 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 269 | radeon_ring_write(ring, PACKET3(PACKET3_NUM_INSTANCES, 0)); |
| 270 | radeon_ring_write(ring, 1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 271 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 272 | radeon_ring_write(ring, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1)); |
| 273 | radeon_ring_write(ring, 3); |
| 274 | radeon_ring_write(ring, DI_SRC_SEL_AUTO_INDEX); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 275 | |
| 276 | } |
| 277 | |
| 278 | /* emits 14 */ |
| 279 | static void |
| 280 | set_default_state(struct radeon_device *rdev) |
| 281 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 282 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 283 | u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2; |
| 284 | u32 sq_thread_resource_mgmt, sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2; |
| 285 | int num_ps_gprs, num_vs_gprs, num_temp_gprs, num_gs_gprs, num_es_gprs; |
| 286 | int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads; |
| 287 | int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries; |
| 288 | u64 gpu_addr; |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 289 | int dwords; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 290 | |
| 291 | switch (rdev->family) { |
| 292 | case CHIP_R600: |
| 293 | num_ps_gprs = 192; |
| 294 | num_vs_gprs = 56; |
| 295 | num_temp_gprs = 4; |
| 296 | num_gs_gprs = 0; |
| 297 | num_es_gprs = 0; |
| 298 | num_ps_threads = 136; |
| 299 | num_vs_threads = 48; |
| 300 | num_gs_threads = 4; |
| 301 | num_es_threads = 4; |
| 302 | num_ps_stack_entries = 128; |
| 303 | num_vs_stack_entries = 128; |
| 304 | num_gs_stack_entries = 0; |
| 305 | num_es_stack_entries = 0; |
| 306 | break; |
| 307 | case CHIP_RV630: |
| 308 | case CHIP_RV635: |
| 309 | num_ps_gprs = 84; |
| 310 | num_vs_gprs = 36; |
| 311 | num_temp_gprs = 4; |
| 312 | num_gs_gprs = 0; |
| 313 | num_es_gprs = 0; |
| 314 | num_ps_threads = 144; |
| 315 | num_vs_threads = 40; |
| 316 | num_gs_threads = 4; |
| 317 | num_es_threads = 4; |
| 318 | num_ps_stack_entries = 40; |
| 319 | num_vs_stack_entries = 40; |
| 320 | num_gs_stack_entries = 32; |
| 321 | num_es_stack_entries = 16; |
| 322 | break; |
| 323 | case CHIP_RV610: |
| 324 | case CHIP_RV620: |
| 325 | case CHIP_RS780: |
| 326 | case CHIP_RS880: |
| 327 | default: |
| 328 | num_ps_gprs = 84; |
| 329 | num_vs_gprs = 36; |
| 330 | num_temp_gprs = 4; |
| 331 | num_gs_gprs = 0; |
| 332 | num_es_gprs = 0; |
| 333 | num_ps_threads = 136; |
| 334 | num_vs_threads = 48; |
| 335 | num_gs_threads = 4; |
| 336 | num_es_threads = 4; |
| 337 | num_ps_stack_entries = 40; |
| 338 | num_vs_stack_entries = 40; |
| 339 | num_gs_stack_entries = 32; |
| 340 | num_es_stack_entries = 16; |
| 341 | break; |
| 342 | case CHIP_RV670: |
| 343 | num_ps_gprs = 144; |
| 344 | num_vs_gprs = 40; |
| 345 | num_temp_gprs = 4; |
| 346 | num_gs_gprs = 0; |
| 347 | num_es_gprs = 0; |
| 348 | num_ps_threads = 136; |
| 349 | num_vs_threads = 48; |
| 350 | num_gs_threads = 4; |
| 351 | num_es_threads = 4; |
| 352 | num_ps_stack_entries = 40; |
| 353 | num_vs_stack_entries = 40; |
| 354 | num_gs_stack_entries = 32; |
| 355 | num_es_stack_entries = 16; |
| 356 | break; |
| 357 | case CHIP_RV770: |
| 358 | num_ps_gprs = 192; |
| 359 | num_vs_gprs = 56; |
| 360 | num_temp_gprs = 4; |
| 361 | num_gs_gprs = 0; |
| 362 | num_es_gprs = 0; |
| 363 | num_ps_threads = 188; |
| 364 | num_vs_threads = 60; |
| 365 | num_gs_threads = 0; |
| 366 | num_es_threads = 0; |
| 367 | num_ps_stack_entries = 256; |
| 368 | num_vs_stack_entries = 256; |
| 369 | num_gs_stack_entries = 0; |
| 370 | num_es_stack_entries = 0; |
| 371 | break; |
| 372 | case CHIP_RV730: |
| 373 | case CHIP_RV740: |
| 374 | num_ps_gprs = 84; |
| 375 | num_vs_gprs = 36; |
| 376 | num_temp_gprs = 4; |
| 377 | num_gs_gprs = 0; |
| 378 | num_es_gprs = 0; |
| 379 | num_ps_threads = 188; |
| 380 | num_vs_threads = 60; |
| 381 | num_gs_threads = 0; |
| 382 | num_es_threads = 0; |
| 383 | num_ps_stack_entries = 128; |
| 384 | num_vs_stack_entries = 128; |
| 385 | num_gs_stack_entries = 0; |
| 386 | num_es_stack_entries = 0; |
| 387 | break; |
| 388 | case CHIP_RV710: |
| 389 | num_ps_gprs = 192; |
| 390 | num_vs_gprs = 56; |
| 391 | num_temp_gprs = 4; |
| 392 | num_gs_gprs = 0; |
| 393 | num_es_gprs = 0; |
| 394 | num_ps_threads = 144; |
| 395 | num_vs_threads = 48; |
| 396 | num_gs_threads = 0; |
| 397 | num_es_threads = 0; |
| 398 | num_ps_stack_entries = 128; |
| 399 | num_vs_stack_entries = 128; |
| 400 | num_gs_stack_entries = 0; |
| 401 | num_es_stack_entries = 0; |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | if ((rdev->family == CHIP_RV610) || |
| 406 | (rdev->family == CHIP_RV620) || |
| 407 | (rdev->family == CHIP_RS780) || |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 408 | (rdev->family == CHIP_RS880) || |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 409 | (rdev->family == CHIP_RV710)) |
| 410 | sq_config = 0; |
| 411 | else |
| 412 | sq_config = VC_ENABLE; |
| 413 | |
| 414 | sq_config |= (DX9_CONSTS | |
| 415 | ALU_INST_PREFER_VECTOR | |
| 416 | PS_PRIO(0) | |
| 417 | VS_PRIO(1) | |
| 418 | GS_PRIO(2) | |
| 419 | ES_PRIO(3)); |
| 420 | |
| 421 | sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) | |
| 422 | NUM_VS_GPRS(num_vs_gprs) | |
| 423 | NUM_CLAUSE_TEMP_GPRS(num_temp_gprs)); |
| 424 | sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) | |
| 425 | NUM_ES_GPRS(num_es_gprs)); |
| 426 | sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) | |
| 427 | NUM_VS_THREADS(num_vs_threads) | |
| 428 | NUM_GS_THREADS(num_gs_threads) | |
| 429 | NUM_ES_THREADS(num_es_threads)); |
| 430 | sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) | |
| 431 | NUM_VS_STACK_ENTRIES(num_vs_stack_entries)); |
| 432 | sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) | |
| 433 | NUM_ES_STACK_ENTRIES(num_es_stack_entries)); |
| 434 | |
| 435 | /* emit an IB pointing at default state */ |
Matt Turner | d964fc5 | 2010-02-25 04:23:31 +0000 | [diff] [blame] | 436 | dwords = ALIGN(rdev->r600_blit.state_len, 0x10); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 437 | gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.state_offset; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 438 | radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2)); |
| 439 | radeon_ring_write(ring, |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 440 | #ifdef __BIG_ENDIAN |
| 441 | (2 << 0) | |
| 442 | #endif |
| 443 | (gpu_addr & 0xFFFFFFFC)); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 444 | radeon_ring_write(ring, upper_32_bits(gpu_addr) & 0xFF); |
| 445 | radeon_ring_write(ring, dwords); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 446 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 447 | /* SQ config */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 448 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 6)); |
| 449 | radeon_ring_write(ring, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_OFFSET) >> 2); |
| 450 | radeon_ring_write(ring, sq_config); |
| 451 | radeon_ring_write(ring, sq_gpr_resource_mgmt_1); |
| 452 | radeon_ring_write(ring, sq_gpr_resource_mgmt_2); |
| 453 | radeon_ring_write(ring, sq_thread_resource_mgmt); |
| 454 | radeon_ring_write(ring, sq_stack_resource_mgmt_1); |
| 455 | radeon_ring_write(ring, sq_stack_resource_mgmt_2); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 456 | } |
| 457 | |
Ilija Hadzic | 52b53a0 | 2012-02-02 10:26:24 -0500 | [diff] [blame] | 458 | #define I2F_MAX_BITS 15 |
| 459 | #define I2F_MAX_INPUT ((1 << I2F_MAX_BITS) - 1) |
| 460 | #define I2F_SHIFT (24 - I2F_MAX_BITS) |
| 461 | |
| 462 | /* |
| 463 | * Converts unsigned integer into 32-bit IEEE floating point representation. |
| 464 | * Conversion is not universal and only works for the range from 0 |
| 465 | * to 2^I2F_MAX_BITS-1. Currently we only use it with inputs between |
| 466 | * 0 and 16384 (inclusive), so I2F_MAX_BITS=15 is enough. If necessary, |
| 467 | * I2F_MAX_BITS can be increased, but that will add to the loop iterations |
| 468 | * and slow us down. Conversion is done by shifting the input and counting |
| 469 | * down until the first 1 reaches bit position 23. The resulting counter |
| 470 | * and the shifted input are, respectively, the exponent and the fraction. |
| 471 | * The sign is always zero. |
| 472 | */ |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 473 | static uint32_t i2f(uint32_t input) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 474 | { |
| 475 | u32 result, i, exponent, fraction; |
| 476 | |
Ilija Hadzic | 52b53a0 | 2012-02-02 10:26:24 -0500 | [diff] [blame] | 477 | WARN_ON_ONCE(input > I2F_MAX_INPUT); |
| 478 | |
| 479 | if ((input & I2F_MAX_INPUT) == 0) |
| 480 | result = 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 481 | else { |
Ilija Hadzic | 52b53a0 | 2012-02-02 10:26:24 -0500 | [diff] [blame] | 482 | exponent = 126 + I2F_MAX_BITS; |
| 483 | fraction = (input & I2F_MAX_INPUT) << I2F_SHIFT; |
| 484 | |
| 485 | for (i = 0; i < I2F_MAX_BITS; i++) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 486 | if (fraction & 0x800000) |
| 487 | break; |
| 488 | else { |
Ilija Hadzic | 52b53a0 | 2012-02-02 10:26:24 -0500 | [diff] [blame] | 489 | fraction = fraction << 1; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 490 | exponent = exponent - 1; |
| 491 | } |
| 492 | } |
Ilija Hadzic | 52b53a0 | 2012-02-02 10:26:24 -0500 | [diff] [blame] | 493 | result = exponent << 23 | (fraction & 0x7fffff); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 494 | } |
| 495 | return result; |
| 496 | } |
| 497 | |
| 498 | int r600_blit_init(struct radeon_device *rdev) |
| 499 | { |
| 500 | u32 obj_size; |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 501 | int i, r, dwords; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 502 | void *ptr; |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 503 | u32 packet2s[16]; |
| 504 | int num_packet2s = 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 505 | |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 506 | rdev->r600_blit.primitives.set_render_target = set_render_target; |
| 507 | rdev->r600_blit.primitives.cp_set_surface_sync = cp_set_surface_sync; |
| 508 | rdev->r600_blit.primitives.set_shaders = set_shaders; |
| 509 | rdev->r600_blit.primitives.set_vtx_resource = set_vtx_resource; |
| 510 | rdev->r600_blit.primitives.set_tex_resource = set_tex_resource; |
| 511 | rdev->r600_blit.primitives.set_scissors = set_scissors; |
| 512 | rdev->r600_blit.primitives.draw_auto = draw_auto; |
| 513 | rdev->r600_blit.primitives.set_default_state = set_default_state; |
| 514 | |
| 515 | rdev->r600_blit.ring_size_common = 40; /* shaders + def state */ |
Jerome Glisse | 77b1bad | 2011-10-26 11:41:22 -0400 | [diff] [blame] | 516 | rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */ |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 517 | rdev->r600_blit.ring_size_common += 5; /* done copy */ |
Jerome Glisse | 77b1bad | 2011-10-26 11:41:22 -0400 | [diff] [blame] | 518 | rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */ |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 519 | |
| 520 | rdev->r600_blit.ring_size_per_loop = 76; |
| 521 | /* set_render_target emits 2 extra dwords on rv6xx */ |
| 522 | if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770) |
| 523 | rdev->r600_blit.ring_size_per_loop += 2; |
| 524 | |
| 525 | rdev->r600_blit.max_dim = 8192; |
| 526 | |
Alex Deucher | b70d6bb | 2010-08-06 21:36:58 -0400 | [diff] [blame] | 527 | /* pin copy shader into vram if already initialized */ |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 528 | if (rdev->r600_blit.shader_obj) |
Alex Deucher | b70d6bb | 2010-08-06 21:36:58 -0400 | [diff] [blame] | 529 | goto done; |
| 530 | |
Jerome Glisse | ff82f05 | 2010-01-22 15:19:00 +0100 | [diff] [blame] | 531 | mutex_init(&rdev->r600_blit.mutex); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 532 | rdev->r600_blit.state_offset = 0; |
| 533 | |
| 534 | if (rdev->family >= CHIP_RV770) |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 535 | rdev->r600_blit.state_len = r7xx_default_size; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 536 | else |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 537 | rdev->r600_blit.state_len = r6xx_default_size; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 538 | |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 539 | dwords = rdev->r600_blit.state_len; |
| 540 | while (dwords & 0xf) { |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 541 | packet2s[num_packet2s++] = cpu_to_le32(PACKET2(0)); |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 542 | dwords++; |
| 543 | } |
| 544 | |
| 545 | obj_size = dwords * 4; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 546 | obj_size = ALIGN(obj_size, 256); |
| 547 | |
| 548 | rdev->r600_blit.vs_offset = obj_size; |
| 549 | obj_size += r6xx_vs_size * 4; |
| 550 | obj_size = ALIGN(obj_size, 256); |
| 551 | |
| 552 | rdev->r600_blit.ps_offset = obj_size; |
| 553 | obj_size += r6xx_ps_size * 4; |
| 554 | obj_size = ALIGN(obj_size, 256); |
| 555 | |
Daniel Vetter | 441921d | 2011-02-18 17:59:16 +0100 | [diff] [blame] | 556 | r = radeon_bo_create(rdev, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 557 | &rdev->r600_blit.shader_obj); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 558 | if (r) { |
| 559 | DRM_ERROR("r600 failed to allocate shader\n"); |
| 560 | return r; |
| 561 | } |
| 562 | |
Dave Airlie | bc1a631 | 2009-09-15 11:07:52 +1000 | [diff] [blame] | 563 | DRM_DEBUG("r6xx blit allocated bo %08x vs %08x ps %08x\n", |
| 564 | obj_size, |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 565 | rdev->r600_blit.vs_offset, rdev->r600_blit.ps_offset); |
| 566 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 567 | 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 Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 571 | if (r) { |
| 572 | DRM_ERROR("failed to map blit object %d\n", r); |
| 573 | return r; |
| 574 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 575 | if (rdev->family >= CHIP_RV770) |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 576 | memcpy_toio(ptr + rdev->r600_blit.state_offset, |
| 577 | r7xx_default_state, rdev->r600_blit.state_len * 4); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 578 | else |
Alex Deucher | 119e20d | 2009-09-10 02:53:50 -0400 | [diff] [blame] | 579 | 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 Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 584 | 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 Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 588 | radeon_bo_kunmap(rdev->r600_blit.shader_obj); |
| 589 | radeon_bo_unreserve(rdev->r600_blit.shader_obj); |
Alex Deucher | b70d6bb | 2010-08-06 21:36:58 -0400 | [diff] [blame] | 590 | |
| 591 | done: |
| 592 | r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false); |
| 593 | if (unlikely(r != 0)) |
| 594 | return r; |
| 595 | r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM, |
| 596 | &rdev->r600_blit.shader_gpu_addr); |
| 597 | radeon_bo_unreserve(rdev->r600_blit.shader_obj); |
| 598 | if (r) { |
| 599 | dev_err(rdev->dev, "(%d) pin blit object failed\n", r); |
| 600 | return r; |
| 601 | } |
Dave Airlie | 5359533 | 2011-03-14 09:47:24 +1000 | [diff] [blame] | 602 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | void r600_blit_fini(struct radeon_device *rdev) |
| 607 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 608 | int r; |
| 609 | |
Dave Airlie | 5359533 | 2011-03-14 09:47:24 +1000 | [diff] [blame] | 610 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); |
Jerome Glisse | 30d2d9a | 2010-01-13 10:29:27 +0100 | [diff] [blame] | 611 | if (rdev->r600_blit.shader_obj == NULL) |
| 612 | return; |
| 613 | /* If we can't reserve the bo, unref should be enough to destroy |
| 614 | * it when it becomes idle. |
| 615 | */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 616 | r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false); |
Jerome Glisse | 30d2d9a | 2010-01-13 10:29:27 +0100 | [diff] [blame] | 617 | if (!r) { |
| 618 | radeon_bo_unpin(rdev->r600_blit.shader_obj); |
| 619 | radeon_bo_unreserve(rdev->r600_blit.shader_obj); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 620 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 621 | radeon_bo_unref(&rdev->r600_blit.shader_obj); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 622 | } |
| 623 | |
Jerome Glisse | 69e130a | 2011-12-21 12:13:46 -0500 | [diff] [blame] | 624 | static int r600_vb_ib_get(struct radeon_device *rdev, unsigned size) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 625 | { |
| 626 | int r; |
Jerome Glisse | 69e130a | 2011-12-21 12:13:46 -0500 | [diff] [blame] | 627 | r = radeon_ib_get(rdev, RADEON_RING_TYPE_GFX_INDEX, |
| 628 | &rdev->r600_blit.vb_ib, size); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 629 | if (r) { |
| 630 | DRM_ERROR("failed to get IB for vertex buffer\n"); |
| 631 | return r; |
| 632 | } |
| 633 | |
Jerome Glisse | 69e130a | 2011-12-21 12:13:46 -0500 | [diff] [blame] | 634 | rdev->r600_blit.vb_total = size; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 635 | rdev->r600_blit.vb_used = 0; |
| 636 | return 0; |
| 637 | } |
| 638 | |
Alex Deucher | d7ccd8f | 2010-09-09 11:33:36 -0400 | [diff] [blame] | 639 | static void r600_vb_ib_put(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 640 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 641 | radeon_fence_emit(rdev, rdev->r600_blit.vb_ib->fence); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 642 | radeon_ib_free(rdev, &rdev->r600_blit.vb_ib); |
| 643 | } |
| 644 | |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 645 | static unsigned r600_blit_create_rect(unsigned num_gpu_pages, |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 646 | int *width, int *height, int max_dim) |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 647 | { |
| 648 | unsigned max_pages; |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 649 | unsigned pages = num_gpu_pages; |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 650 | int w, h; |
| 651 | |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 652 | if (num_gpu_pages == 0) { |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 653 | /* not supposed to be called with no pages, but just in case */ |
| 654 | h = 0; |
| 655 | w = 0; |
| 656 | pages = 0; |
| 657 | WARN_ON(1); |
| 658 | } else { |
| 659 | int rect_order = 2; |
| 660 | h = RECT_UNIT_H; |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 661 | while (num_gpu_pages / rect_order) { |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 662 | h *= 2; |
| 663 | rect_order *= 4; |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 664 | if (h >= max_dim) { |
| 665 | h = max_dim; |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 666 | break; |
| 667 | } |
| 668 | } |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 669 | max_pages = (max_dim * h) / (RECT_UNIT_W * RECT_UNIT_H); |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 670 | if (pages > max_pages) |
| 671 | pages = max_pages; |
| 672 | w = (pages * RECT_UNIT_W * RECT_UNIT_H) / h; |
| 673 | w = (w / RECT_UNIT_W) * RECT_UNIT_W; |
| 674 | pages = (w * h) / (RECT_UNIT_W * RECT_UNIT_H); |
| 675 | BUG_ON(pages == 0); |
| 676 | } |
| 677 | |
| 678 | |
| 679 | DRM_DEBUG("blit_rectangle: h=%d, w=%d, pages=%d\n", h, w, pages); |
| 680 | |
| 681 | /* return width and height only of the caller wants it */ |
| 682 | if (height) |
| 683 | *height = h; |
| 684 | if (width) |
| 685 | *width = w; |
| 686 | |
| 687 | return pages; |
| 688 | } |
| 689 | |
| 690 | |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 691 | int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 692 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 693 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 694 | int r; |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 695 | int ring_size; |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 696 | int num_loops = 0; |
| 697 | int dwords_per_loop = rdev->r600_blit.ring_size_per_loop; |
Dave Airlie | 7cbb355 | 2009-09-17 16:11:31 +1000 | [diff] [blame] | 698 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 699 | /* num loops */ |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 700 | while (num_gpu_pages) { |
| 701 | num_gpu_pages -= |
| 702 | r600_blit_create_rect(num_gpu_pages, NULL, NULL, |
| 703 | rdev->r600_blit.max_dim); |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 704 | num_loops++; |
| 705 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 706 | |
Jerome Glisse | 69e130a | 2011-12-21 12:13:46 -0500 | [diff] [blame] | 707 | /* 48 bytes for vertex per loop */ |
| 708 | r = r600_vb_ib_get(rdev, (num_loops*48)+256); |
| 709 | if (r) |
| 710 | return r; |
| 711 | |
Dave Airlie | 7cbb355 | 2009-09-17 16:11:31 +1000 | [diff] [blame] | 712 | /* calculate number of loops correctly */ |
| 713 | ring_size = num_loops * dwords_per_loop; |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 714 | ring_size += rdev->r600_blit.ring_size_common; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 715 | r = radeon_ring_lock(rdev, ring, ring_size); |
Jerome Glisse | ff82f05 | 2010-01-22 15:19:00 +0100 | [diff] [blame] | 716 | if (r) |
| 717 | return r; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 718 | |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 719 | rdev->r600_blit.primitives.set_default_state(rdev); |
| 720 | rdev->r600_blit.primitives.set_shaders(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence) |
| 725 | { |
| 726 | int r; |
| 727 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 728 | if (rdev->r600_blit.vb_ib) |
| 729 | r600_vb_ib_put(rdev); |
| 730 | |
| 731 | if (fence) |
| 732 | r = radeon_fence_emit(rdev, fence); |
| 733 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 734 | radeon_ring_unlock_commit(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | void r600_kms_blit_copy(struct radeon_device *rdev, |
| 738 | u64 src_gpu_addr, u64 dst_gpu_addr, |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 739 | unsigned num_gpu_pages) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 740 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 741 | u64 vb_gpu_addr; |
| 742 | u32 *vb; |
| 743 | |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 744 | DRM_DEBUG("emitting copy %16llx %16llx %d %d\n", |
| 745 | src_gpu_addr, dst_gpu_addr, |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 746 | num_gpu_pages, rdev->r600_blit.vb_used); |
Dave Airlie | ceeb502 | 2009-10-12 13:54:10 +1000 | [diff] [blame] | 747 | vb = (u32 *)(rdev->r600_blit.vb_ib->ptr + rdev->r600_blit.vb_used); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 748 | |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 749 | while (num_gpu_pages) { |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 750 | int w, h; |
| 751 | unsigned size_in_bytes; |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 752 | unsigned pages_per_loop = |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 753 | r600_blit_create_rect(num_gpu_pages, &w, &h, |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 754 | rdev->r600_blit.max_dim); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 755 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 756 | size_in_bytes = pages_per_loop * RADEON_GPU_PAGE_SIZE; |
| 757 | DRM_DEBUG("rectangle w=%d h=%d\n", w, h); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 758 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 759 | if ((rdev->r600_blit.vb_used + 48) > rdev->r600_blit.vb_total) { |
| 760 | WARN_ON(1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 761 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 762 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 763 | vb[0] = 0; |
| 764 | vb[1] = 0; |
| 765 | vb[2] = 0; |
| 766 | vb[3] = 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 767 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 768 | vb[4] = 0; |
| 769 | vb[5] = i2f(h); |
| 770 | vb[6] = 0; |
| 771 | vb[7] = i2f(h); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 772 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 773 | vb[8] = i2f(w); |
| 774 | vb[9] = i2f(h); |
| 775 | vb[10] = i2f(w); |
| 776 | vb[11] = i2f(h); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 777 | |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 778 | rdev->r600_blit.primitives.set_tex_resource(rdev, FMT_8_8_8_8, |
Alex Deucher | 9bb7703 | 2011-10-22 10:07:09 -0400 | [diff] [blame] | 779 | w, h, w, src_gpu_addr, size_in_bytes); |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 780 | rdev->r600_blit.primitives.set_render_target(rdev, COLOR_8_8_8_8, |
| 781 | w, h, dst_gpu_addr); |
| 782 | rdev->r600_blit.primitives.set_scissors(rdev, 0, 0, w, h); |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 783 | vb_gpu_addr = rdev->r600_blit.vb_ib->gpu_addr + rdev->r600_blit.vb_used; |
Ilija Hadzic | 8eec9d6 | 2011-10-12 23:29:40 -0400 | [diff] [blame] | 784 | rdev->r600_blit.primitives.set_vtx_resource(rdev, vb_gpu_addr); |
| 785 | rdev->r600_blit.primitives.draw_auto(rdev); |
| 786 | rdev->r600_blit.primitives.cp_set_surface_sync(rdev, |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 787 | PACKET3_CB_ACTION_ENA | PACKET3_CB0_DEST_BASE_ENA, |
| 788 | size_in_bytes, dst_gpu_addr); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 789 | |
Alex Deucher | 7dbf41d | 2011-05-17 05:09:43 -0400 | [diff] [blame] | 790 | vb += 12; |
| 791 | rdev->r600_blit.vb_used += 4*12; |
| 792 | src_gpu_addr += size_in_bytes; |
| 793 | dst_gpu_addr += size_in_bytes; |
Ilija Hadzic | b353096 | 2011-10-12 23:29:42 -0400 | [diff] [blame] | 794 | num_gpu_pages -= pages_per_loop; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 795 | } |
| 796 | } |