r600_blit.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * Copyright 2009 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Alex Deucher <alexander.deucher@amd.com>
  25. *
  26. * ------------------------ This file is DEPRECATED! -------------------------
  27. */
  28. #include <drm/drmP.h>
  29. #include <drm/radeon_drm.h>
  30. #include "radeon_drv.h"
  31. #include "r600_blit_shaders.h"
  32. /* 23 bits of float fractional data */
  33. #define I2F_FRAC_BITS 23
  34. #define I2F_MASK ((1 << I2F_FRAC_BITS) - 1)
  35. /*
  36. * Converts unsigned integer into 32-bit IEEE floating point representation.
  37. * Will be exact from 0 to 2^24. Above that, we round towards zero
  38. * as the fractional bits will not fit in a float. (It would be better to
  39. * round towards even as the fpu does, but that is slower.)
  40. */
  41. static __pure uint32_t int2float(uint32_t x)
  42. {
  43. uint32_t msb, exponent, fraction;
  44. /* Zero is special */
  45. if (!x) return 0;
  46. /* Get location of the most significant bit */
  47. msb = __fls(x);
  48. /*
  49. * Use a rotate instead of a shift because that works both leftwards
  50. * and rightwards due to the mod(32) behaviour. This means we don't
  51. * need to check to see if we are above 2^24 or not.
  52. */
  53. fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
  54. exponent = (127 + msb) << I2F_FRAC_BITS;
  55. return fraction + exponent;
  56. }
  57. #define DI_PT_RECTLIST 0x11
  58. #define DI_INDEX_SIZE_16_BIT 0x0
  59. #define DI_SRC_SEL_AUTO_INDEX 0x2
  60. #define FMT_8 0x1
  61. #define FMT_5_6_5 0x8
  62. #define FMT_8_8_8_8 0x1a
  63. #define COLOR_8 0x1
  64. #define COLOR_5_6_5 0x8
  65. #define COLOR_8_8_8_8 0x1a
  66. static void
  67. set_render_target(drm_radeon_private_t *dev_priv, int format, int w, int h, u64 gpu_addr)
  68. {
  69. u32 cb_color_info;
  70. int pitch, slice;
  71. RING_LOCALS;
  72. DRM_DEBUG("\n");
  73. h = ALIGN(h, 8);
  74. if (h < 8)
  75. h = 8;
  76. cb_color_info = ((format << 2) | (1 << 27));
  77. pitch = (w / 8) - 1;
  78. slice = ((w * h) / 64) - 1;
  79. if (((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_R600) &&
  80. ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV770)) {
  81. BEGIN_RING(21 + 2);
  82. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  83. OUT_RING((R600_CB_COLOR0_BASE - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  84. OUT_RING(gpu_addr >> 8);
  85. OUT_RING(CP_PACKET3(R600_IT_SURFACE_BASE_UPDATE, 0));
  86. OUT_RING(2 << 0);
  87. } else {
  88. BEGIN_RING(21);
  89. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  90. OUT_RING((R600_CB_COLOR0_BASE - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  91. OUT_RING(gpu_addr >> 8);
  92. }
  93. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  94. OUT_RING((R600_CB_COLOR0_SIZE - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  95. OUT_RING((pitch << 0) | (slice << 10));
  96. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  97. OUT_RING((R600_CB_COLOR0_VIEW - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  98. OUT_RING(0);
  99. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  100. OUT_RING((R600_CB_COLOR0_INFO - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  101. OUT_RING(cb_color_info);
  102. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  103. OUT_RING((R600_CB_COLOR0_TILE - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  104. OUT_RING(0);
  105. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  106. OUT_RING((R600_CB_COLOR0_FRAG - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  107. OUT_RING(0);
  108. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  109. OUT_RING((R600_CB_COLOR0_MASK - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  110. OUT_RING(0);
  111. ADVANCE_RING();
  112. }
  113. static void
  114. cp_set_surface_sync(drm_radeon_private_t *dev_priv,
  115. u32 sync_type, u32 size, u64 mc_addr)
  116. {
  117. u32 cp_coher_size;
  118. RING_LOCALS;
  119. DRM_DEBUG("\n");
  120. if (size == 0xffffffff)
  121. cp_coher_size = 0xffffffff;
  122. else
  123. cp_coher_size = ((size + 255) >> 8);
  124. BEGIN_RING(5);
  125. OUT_RING(CP_PACKET3(R600_IT_SURFACE_SYNC, 3));
  126. OUT_RING(sync_type);
  127. OUT_RING(cp_coher_size);
  128. OUT_RING((mc_addr >> 8));
  129. OUT_RING(10); /* poll interval */
  130. ADVANCE_RING();
  131. }
  132. static void
  133. set_shaders(struct drm_device *dev)
  134. {
  135. drm_radeon_private_t *dev_priv = dev->dev_private;
  136. u64 gpu_addr;
  137. int i;
  138. u32 *vs, *ps;
  139. uint32_t sq_pgm_resources;
  140. RING_LOCALS;
  141. DRM_DEBUG("\n");
  142. /* load shaders */
  143. vs = (u32 *) ((char *)dev->agp_buffer_map->handle + dev_priv->blit_vb->offset);
  144. ps = (u32 *) ((char *)dev->agp_buffer_map->handle + dev_priv->blit_vb->offset + 256);
  145. for (i = 0; i < r6xx_vs_size; i++)
  146. vs[i] = cpu_to_le32(r6xx_vs[i]);
  147. for (i = 0; i < r6xx_ps_size; i++)
  148. ps[i] = cpu_to_le32(r6xx_ps[i]);
  149. dev_priv->blit_vb->used = 512;
  150. gpu_addr = dev_priv->gart_buffers_offset + dev_priv->blit_vb->offset;
  151. /* setup shader regs */
  152. sq_pgm_resources = (1 << 0);
  153. BEGIN_RING(9 + 12);
  154. /* VS */
  155. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  156. OUT_RING((R600_SQ_PGM_START_VS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  157. OUT_RING(gpu_addr >> 8);
  158. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  159. OUT_RING((R600_SQ_PGM_RESOURCES_VS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  160. OUT_RING(sq_pgm_resources);
  161. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  162. OUT_RING((R600_SQ_PGM_CF_OFFSET_VS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  163. OUT_RING(0);
  164. /* PS */
  165. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  166. OUT_RING((R600_SQ_PGM_START_PS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  167. OUT_RING((gpu_addr + 256) >> 8);
  168. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  169. OUT_RING((R600_SQ_PGM_RESOURCES_PS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  170. OUT_RING(sq_pgm_resources | (1 << 28));
  171. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  172. OUT_RING((R600_SQ_PGM_EXPORTS_PS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  173. OUT_RING(2);
  174. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 1));
  175. OUT_RING((R600_SQ_PGM_CF_OFFSET_PS - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  176. OUT_RING(0);
  177. ADVANCE_RING();
  178. cp_set_surface_sync(dev_priv,
  179. R600_SH_ACTION_ENA, 512, gpu_addr);
  180. }
  181. static void
  182. set_vtx_resource(drm_radeon_private_t *dev_priv, u64 gpu_addr)
  183. {
  184. uint32_t sq_vtx_constant_word2;
  185. RING_LOCALS;
  186. DRM_DEBUG("\n");
  187. sq_vtx_constant_word2 = (((gpu_addr >> 32) & 0xff) | (16 << 8));
  188. #ifdef __BIG_ENDIAN
  189. sq_vtx_constant_word2 |= (2 << 30);
  190. #endif
  191. BEGIN_RING(9);
  192. OUT_RING(CP_PACKET3(R600_IT_SET_RESOURCE, 7));
  193. OUT_RING(0x460);
  194. OUT_RING(gpu_addr & 0xffffffff);
  195. OUT_RING(48 - 1);
  196. OUT_RING(sq_vtx_constant_word2);
  197. OUT_RING(1 << 0);
  198. OUT_RING(0);
  199. OUT_RING(0);
  200. OUT_RING(R600_SQ_TEX_VTX_VALID_BUFFER << 30);
  201. ADVANCE_RING();
  202. if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  203. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  204. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  205. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880) ||
  206. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV710))
  207. cp_set_surface_sync(dev_priv,
  208. R600_TC_ACTION_ENA, 48, gpu_addr);
  209. else
  210. cp_set_surface_sync(dev_priv,
  211. R600_VC_ACTION_ENA, 48, gpu_addr);
  212. }
  213. static void
  214. set_tex_resource(drm_radeon_private_t *dev_priv,
  215. int format, int w, int h, int pitch, u64 gpu_addr)
  216. {
  217. uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4;
  218. RING_LOCALS;
  219. DRM_DEBUG("\n");
  220. if (h < 1)
  221. h = 1;
  222. sq_tex_resource_word0 = (1 << 0);
  223. sq_tex_resource_word0 |= ((((pitch >> 3) - 1) << 8) |
  224. ((w - 1) << 19));
  225. sq_tex_resource_word1 = (format << 26);
  226. sq_tex_resource_word1 |= ((h - 1) << 0);
  227. sq_tex_resource_word4 = ((1 << 14) |
  228. (0 << 16) |
  229. (1 << 19) |
  230. (2 << 22) |
  231. (3 << 25));
  232. BEGIN_RING(9);
  233. OUT_RING(CP_PACKET3(R600_IT_SET_RESOURCE, 7));
  234. OUT_RING(0);
  235. OUT_RING(sq_tex_resource_word0);
  236. OUT_RING(sq_tex_resource_word1);
  237. OUT_RING(gpu_addr >> 8);
  238. OUT_RING(gpu_addr >> 8);
  239. OUT_RING(sq_tex_resource_word4);
  240. OUT_RING(0);
  241. OUT_RING(R600_SQ_TEX_VTX_VALID_TEXTURE << 30);
  242. ADVANCE_RING();
  243. }
  244. static void
  245. set_scissors(drm_radeon_private_t *dev_priv, int x1, int y1, int x2, int y2)
  246. {
  247. RING_LOCALS;
  248. DRM_DEBUG("\n");
  249. BEGIN_RING(12);
  250. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 2));
  251. OUT_RING((R600_PA_SC_SCREEN_SCISSOR_TL - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  252. OUT_RING((x1 << 0) | (y1 << 16));
  253. OUT_RING((x2 << 0) | (y2 << 16));
  254. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 2));
  255. OUT_RING((R600_PA_SC_GENERIC_SCISSOR_TL - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  256. OUT_RING((x1 << 0) | (y1 << 16) | (1 << 31));
  257. OUT_RING((x2 << 0) | (y2 << 16));
  258. OUT_RING(CP_PACKET3(R600_IT_SET_CONTEXT_REG, 2));
  259. OUT_RING((R600_PA_SC_WINDOW_SCISSOR_TL - R600_SET_CONTEXT_REG_OFFSET) >> 2);
  260. OUT_RING((x1 << 0) | (y1 << 16) | (1 << 31));
  261. OUT_RING((x2 << 0) | (y2 << 16));
  262. ADVANCE_RING();
  263. }
  264. static void
  265. draw_auto(drm_radeon_private_t *dev_priv)
  266. {
  267. RING_LOCALS;
  268. DRM_DEBUG("\n");
  269. BEGIN_RING(10);
  270. OUT_RING(CP_PACKET3(R600_IT_SET_CONFIG_REG, 1));
  271. OUT_RING((R600_VGT_PRIMITIVE_TYPE - R600_SET_CONFIG_REG_OFFSET) >> 2);
  272. OUT_RING(DI_PT_RECTLIST);
  273. OUT_RING(CP_PACKET3(R600_IT_INDEX_TYPE, 0));
  274. #ifdef __BIG_ENDIAN
  275. OUT_RING((2 << 2) | DI_INDEX_SIZE_16_BIT);
  276. #else
  277. OUT_RING(DI_INDEX_SIZE_16_BIT);
  278. #endif
  279. OUT_RING(CP_PACKET3(R600_IT_NUM_INSTANCES, 0));
  280. OUT_RING(1);
  281. OUT_RING(CP_PACKET3(R600_IT_DRAW_INDEX_AUTO, 1));
  282. OUT_RING(3);
  283. OUT_RING(DI_SRC_SEL_AUTO_INDEX);
  284. ADVANCE_RING();
  285. COMMIT_RING();
  286. }
  287. static void
  288. set_default_state(drm_radeon_private_t *dev_priv)
  289. {
  290. int i;
  291. u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2;
  292. u32 sq_thread_resource_mgmt, sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2;
  293. int num_ps_gprs, num_vs_gprs, num_temp_gprs, num_gs_gprs, num_es_gprs;
  294. int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
  295. int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
  296. RING_LOCALS;
  297. switch ((dev_priv->flags & RADEON_FAMILY_MASK)) {
  298. case CHIP_R600:
  299. num_ps_gprs = 192;
  300. num_vs_gprs = 56;
  301. num_temp_gprs = 4;
  302. num_gs_gprs = 0;
  303. num_es_gprs = 0;
  304. num_ps_threads = 136;
  305. num_vs_threads = 48;
  306. num_gs_threads = 4;
  307. num_es_threads = 4;
  308. num_ps_stack_entries = 128;
  309. num_vs_stack_entries = 128;
  310. num_gs_stack_entries = 0;
  311. num_es_stack_entries = 0;
  312. break;
  313. case CHIP_RV630:
  314. case CHIP_RV635:
  315. num_ps_gprs = 84;
  316. num_vs_gprs = 36;
  317. num_temp_gprs = 4;
  318. num_gs_gprs = 0;
  319. num_es_gprs = 0;
  320. num_ps_threads = 144;
  321. num_vs_threads = 40;
  322. num_gs_threads = 4;
  323. num_es_threads = 4;
  324. num_ps_stack_entries = 40;
  325. num_vs_stack_entries = 40;
  326. num_gs_stack_entries = 32;
  327. num_es_stack_entries = 16;
  328. break;
  329. case CHIP_RV610:
  330. case CHIP_RV620:
  331. case CHIP_RS780:
  332. case CHIP_RS880:
  333. default:
  334. num_ps_gprs = 84;
  335. num_vs_gprs = 36;
  336. num_temp_gprs = 4;
  337. num_gs_gprs = 0;
  338. num_es_gprs = 0;
  339. num_ps_threads = 136;
  340. num_vs_threads = 48;
  341. num_gs_threads = 4;
  342. num_es_threads = 4;
  343. num_ps_stack_entries = 40;
  344. num_vs_stack_entries = 40;
  345. num_gs_stack_entries = 32;
  346. num_es_stack_entries = 16;
  347. break;
  348. case CHIP_RV670:
  349. num_ps_gprs = 144;
  350. num_vs_gprs = 40;
  351. num_temp_gprs = 4;
  352. num_gs_gprs = 0;
  353. num_es_gprs = 0;
  354. num_ps_threads = 136;
  355. num_vs_threads = 48;
  356. num_gs_threads = 4;
  357. num_es_threads = 4;
  358. num_ps_stack_entries = 40;
  359. num_vs_stack_entries = 40;
  360. num_gs_stack_entries = 32;
  361. num_es_stack_entries = 16;
  362. break;
  363. case CHIP_RV770:
  364. num_ps_gprs = 192;
  365. num_vs_gprs = 56;
  366. num_temp_gprs = 4;
  367. num_gs_gprs = 0;
  368. num_es_gprs = 0;
  369. num_ps_threads = 188;
  370. num_vs_threads = 60;
  371. num_gs_threads = 0;
  372. num_es_threads = 0;
  373. num_ps_stack_entries = 256;
  374. num_vs_stack_entries = 256;
  375. num_gs_stack_entries = 0;
  376. num_es_stack_entries = 0;
  377. break;
  378. case CHIP_RV730:
  379. case CHIP_RV740:
  380. num_ps_gprs = 84;
  381. num_vs_gprs = 36;
  382. num_temp_gprs = 4;
  383. num_gs_gprs = 0;
  384. num_es_gprs = 0;
  385. num_ps_threads = 188;
  386. num_vs_threads = 60;
  387. num_gs_threads = 0;
  388. num_es_threads = 0;
  389. num_ps_stack_entries = 128;
  390. num_vs_stack_entries = 128;
  391. num_gs_stack_entries = 0;
  392. num_es_stack_entries = 0;
  393. break;
  394. case CHIP_RV710:
  395. num_ps_gprs = 192;
  396. num_vs_gprs = 56;
  397. num_temp_gprs = 4;
  398. num_gs_gprs = 0;
  399. num_es_gprs = 0;
  400. num_ps_threads = 144;
  401. num_vs_threads = 48;
  402. num_gs_threads = 0;
  403. num_es_threads = 0;
  404. num_ps_stack_entries = 128;
  405. num_vs_stack_entries = 128;
  406. num_gs_stack_entries = 0;
  407. num_es_stack_entries = 0;
  408. break;
  409. }
  410. if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  411. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  412. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  413. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880) ||
  414. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV710))
  415. sq_config = 0;
  416. else
  417. sq_config = R600_VC_ENABLE;
  418. sq_config |= (R600_DX9_CONSTS |
  419. R600_ALU_INST_PREFER_VECTOR |
  420. R600_PS_PRIO(0) |
  421. R600_VS_PRIO(1) |
  422. R600_GS_PRIO(2) |
  423. R600_ES_PRIO(3));
  424. sq_gpr_resource_mgmt_1 = (R600_NUM_PS_GPRS(num_ps_gprs) |
  425. R600_NUM_VS_GPRS(num_vs_gprs) |
  426. R600_NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
  427. sq_gpr_resource_mgmt_2 = (R600_NUM_GS_GPRS(num_gs_gprs) |
  428. R600_NUM_ES_GPRS(num_es_gprs));
  429. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS(num_ps_threads) |
  430. R600_NUM_VS_THREADS(num_vs_threads) |
  431. R600_NUM_GS_THREADS(num_gs_threads) |
  432. R600_NUM_ES_THREADS(num_es_threads));
  433. sq_stack_resource_mgmt_1 = (R600_NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
  434. R600_NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
  435. sq_stack_resource_mgmt_2 = (R600_NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
  436. R600_NUM_ES_STACK_ENTRIES(num_es_stack_entries));
  437. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) {
  438. BEGIN_RING(r7xx_default_size + 10);
  439. for (i = 0; i < r7xx_default_size; i++)
  440. OUT_RING(r7xx_default_state[i]);
  441. } else {
  442. BEGIN_RING(r6xx_default_size + 10);
  443. for (i = 0; i < r6xx_default_size; i++)
  444. OUT_RING(r6xx_default_state[i]);
  445. }
  446. OUT_RING(CP_PACKET3(R600_IT_EVENT_WRITE, 0));
  447. OUT_RING(R600_CACHE_FLUSH_AND_INV_EVENT);
  448. /* SQ config */
  449. OUT_RING(CP_PACKET3(R600_IT_SET_CONFIG_REG, 6));
  450. OUT_RING((R600_SQ_CONFIG - R600_SET_CONFIG_REG_OFFSET) >> 2);
  451. OUT_RING(sq_config);
  452. OUT_RING(sq_gpr_resource_mgmt_1);
  453. OUT_RING(sq_gpr_resource_mgmt_2);
  454. OUT_RING(sq_thread_resource_mgmt);
  455. OUT_RING(sq_stack_resource_mgmt_1);
  456. OUT_RING(sq_stack_resource_mgmt_2);
  457. ADVANCE_RING();
  458. }
  459. static int r600_nomm_get_vb(struct drm_device *dev)
  460. {
  461. drm_radeon_private_t *dev_priv = dev->dev_private;
  462. dev_priv->blit_vb = radeon_freelist_get(dev);
  463. if (!dev_priv->blit_vb) {
  464. DRM_ERROR("Unable to allocate vertex buffer for blit\n");
  465. return -EAGAIN;
  466. }
  467. return 0;
  468. }
  469. static void r600_nomm_put_vb(struct drm_device *dev)
  470. {
  471. drm_radeon_private_t *dev_priv = dev->dev_private;
  472. dev_priv->blit_vb->used = 0;
  473. radeon_cp_discard_buffer(dev, dev_priv->blit_vb->file_priv->master, dev_priv->blit_vb);
  474. }
  475. static void *r600_nomm_get_vb_ptr(struct drm_device *dev)
  476. {
  477. drm_radeon_private_t *dev_priv = dev->dev_private;
  478. return (((char *)dev->agp_buffer_map->handle +
  479. dev_priv->blit_vb->offset + dev_priv->blit_vb->used));
  480. }
  481. int
  482. r600_prepare_blit_copy(struct drm_device *dev, struct drm_file *file_priv)
  483. {
  484. drm_radeon_private_t *dev_priv = dev->dev_private;
  485. int ret;
  486. DRM_DEBUG("\n");
  487. ret = r600_nomm_get_vb(dev);
  488. if (ret)
  489. return ret;
  490. dev_priv->blit_vb->file_priv = file_priv;
  491. set_default_state(dev_priv);
  492. set_shaders(dev);
  493. return 0;
  494. }
  495. void
  496. r600_done_blit_copy(struct drm_device *dev)
  497. {
  498. drm_radeon_private_t *dev_priv = dev->dev_private;
  499. RING_LOCALS;
  500. DRM_DEBUG("\n");
  501. BEGIN_RING(5);
  502. OUT_RING(CP_PACKET3(R600_IT_EVENT_WRITE, 0));
  503. OUT_RING(R600_CACHE_FLUSH_AND_INV_EVENT);
  504. /* wait for 3D idle clean */
  505. OUT_RING(CP_PACKET3(R600_IT_SET_CONFIG_REG, 1));
  506. OUT_RING((R600_WAIT_UNTIL - R600_SET_CONFIG_REG_OFFSET) >> 2);
  507. OUT_RING(RADEON_WAIT_3D_IDLE | RADEON_WAIT_3D_IDLECLEAN);
  508. ADVANCE_RING();
  509. COMMIT_RING();
  510. r600_nomm_put_vb(dev);
  511. }
  512. void
  513. r600_blit_copy(struct drm_device *dev,
  514. uint64_t src_gpu_addr, uint64_t dst_gpu_addr,
  515. int size_bytes)
  516. {
  517. drm_radeon_private_t *dev_priv = dev->dev_private;
  518. int max_bytes;
  519. u64 vb_addr;
  520. u32 *vb;
  521. vb = r600_nomm_get_vb_ptr(dev);
  522. if ((size_bytes & 3) || (src_gpu_addr & 3) || (dst_gpu_addr & 3)) {
  523. max_bytes = 8192;
  524. while (size_bytes) {
  525. int cur_size = size_bytes;
  526. int src_x = src_gpu_addr & 255;
  527. int dst_x = dst_gpu_addr & 255;
  528. int h = 1;
  529. src_gpu_addr = src_gpu_addr & ~255;
  530. dst_gpu_addr = dst_gpu_addr & ~255;
  531. if (!src_x && !dst_x) {
  532. h = (cur_size / max_bytes);
  533. if (h > 8192)
  534. h = 8192;
  535. if (h == 0)
  536. h = 1;
  537. else
  538. cur_size = max_bytes;
  539. } else {
  540. if (cur_size > max_bytes)
  541. cur_size = max_bytes;
  542. if (cur_size > (max_bytes - dst_x))
  543. cur_size = (max_bytes - dst_x);
  544. if (cur_size > (max_bytes - src_x))
  545. cur_size = (max_bytes - src_x);
  546. }
  547. if ((dev_priv->blit_vb->used + 48) > dev_priv->blit_vb->total) {
  548. r600_nomm_put_vb(dev);
  549. r600_nomm_get_vb(dev);
  550. if (!dev_priv->blit_vb)
  551. return;
  552. set_shaders(dev);
  553. vb = r600_nomm_get_vb_ptr(dev);
  554. }
  555. vb[0] = int2float(dst_x);
  556. vb[1] = 0;
  557. vb[2] = int2float(src_x);
  558. vb[3] = 0;
  559. vb[4] = int2float(dst_x);
  560. vb[5] = int2float(h);
  561. vb[6] = int2float(src_x);
  562. vb[7] = int2float(h);
  563. vb[8] = int2float(dst_x + cur_size);
  564. vb[9] = int2float(h);
  565. vb[10] = int2float(src_x + cur_size);
  566. vb[11] = int2float(h);
  567. /* src */
  568. set_tex_resource(dev_priv, FMT_8,
  569. src_x + cur_size, h, src_x + cur_size,
  570. src_gpu_addr);
  571. cp_set_surface_sync(dev_priv,
  572. R600_TC_ACTION_ENA, (src_x + cur_size * h), src_gpu_addr);
  573. /* dst */
  574. set_render_target(dev_priv, COLOR_8,
  575. dst_x + cur_size, h,
  576. dst_gpu_addr);
  577. /* scissors */
  578. set_scissors(dev_priv, dst_x, 0, dst_x + cur_size, h);
  579. /* Vertex buffer setup */
  580. vb_addr = dev_priv->gart_buffers_offset +
  581. dev_priv->blit_vb->offset +
  582. dev_priv->blit_vb->used;
  583. set_vtx_resource(dev_priv, vb_addr);
  584. /* draw */
  585. draw_auto(dev_priv);
  586. cp_set_surface_sync(dev_priv,
  587. R600_CB_ACTION_ENA | R600_CB0_DEST_BASE_ENA,
  588. cur_size * h, dst_gpu_addr);
  589. vb += 12;
  590. dev_priv->blit_vb->used += 12 * 4;
  591. src_gpu_addr += cur_size * h;
  592. dst_gpu_addr += cur_size * h;
  593. size_bytes -= cur_size * h;
  594. }
  595. } else {
  596. max_bytes = 8192 * 4;
  597. while (size_bytes) {
  598. int cur_size = size_bytes;
  599. int src_x = (src_gpu_addr & 255);
  600. int dst_x = (dst_gpu_addr & 255);
  601. int h = 1;
  602. src_gpu_addr = src_gpu_addr & ~255;
  603. dst_gpu_addr = dst_gpu_addr & ~255;
  604. if (!src_x && !dst_x) {
  605. h = (cur_size / max_bytes);
  606. if (h > 8192)
  607. h = 8192;
  608. if (h == 0)
  609. h = 1;
  610. else
  611. cur_size = max_bytes;
  612. } else {
  613. if (cur_size > max_bytes)
  614. cur_size = max_bytes;
  615. if (cur_size > (max_bytes - dst_x))
  616. cur_size = (max_bytes - dst_x);
  617. if (cur_size > (max_bytes - src_x))
  618. cur_size = (max_bytes - src_x);
  619. }
  620. if ((dev_priv->blit_vb->used + 48) > dev_priv->blit_vb->total) {
  621. r600_nomm_put_vb(dev);
  622. r600_nomm_get_vb(dev);
  623. if (!dev_priv->blit_vb)
  624. return;
  625. set_shaders(dev);
  626. vb = r600_nomm_get_vb_ptr(dev);
  627. }
  628. vb[0] = int2float(dst_x / 4);
  629. vb[1] = 0;
  630. vb[2] = int2float(src_x / 4);
  631. vb[3] = 0;
  632. vb[4] = int2float(dst_x / 4);
  633. vb[5] = int2float(h);
  634. vb[6] = int2float(src_x / 4);
  635. vb[7] = int2float(h);
  636. vb[8] = int2float((dst_x + cur_size) / 4);
  637. vb[9] = int2float(h);
  638. vb[10] = int2float((src_x + cur_size) / 4);
  639. vb[11] = int2float(h);
  640. /* src */
  641. set_tex_resource(dev_priv, FMT_8_8_8_8,
  642. (src_x + cur_size) / 4,
  643. h, (src_x + cur_size) / 4,
  644. src_gpu_addr);
  645. cp_set_surface_sync(dev_priv,
  646. R600_TC_ACTION_ENA, (src_x + cur_size * h), src_gpu_addr);
  647. /* dst */
  648. set_render_target(dev_priv, COLOR_8_8_8_8,
  649. (dst_x + cur_size) / 4, h,
  650. dst_gpu_addr);
  651. /* scissors */
  652. set_scissors(dev_priv, (dst_x / 4), 0, (dst_x + cur_size / 4), h);
  653. /* Vertex buffer setup */
  654. vb_addr = dev_priv->gart_buffers_offset +
  655. dev_priv->blit_vb->offset +
  656. dev_priv->blit_vb->used;
  657. set_vtx_resource(dev_priv, vb_addr);
  658. /* draw */
  659. draw_auto(dev_priv);
  660. cp_set_surface_sync(dev_priv,
  661. R600_CB_ACTION_ENA | R600_CB0_DEST_BASE_ENA,
  662. cur_size * h, dst_gpu_addr);
  663. vb += 12;
  664. dev_priv->blit_vb->used += 12 * 4;
  665. src_gpu_addr += cur_size * h;
  666. dst_gpu_addr += cur_size * h;
  667. size_bytes -= cur_size * h;
  668. }
  669. }
  670. }
  671. void
  672. r600_blit_swap(struct drm_device *dev,
  673. uint64_t src_gpu_addr, uint64_t dst_gpu_addr,
  674. int sx, int sy, int dx, int dy,
  675. int w, int h, int src_pitch, int dst_pitch, int cpp)
  676. {
  677. drm_radeon_private_t *dev_priv = dev->dev_private;
  678. int cb_format, tex_format;
  679. int sx2, sy2, dx2, dy2;
  680. u64 vb_addr;
  681. u32 *vb;
  682. if ((dev_priv->blit_vb->used + 48) > dev_priv->blit_vb->total) {
  683. r600_nomm_put_vb(dev);
  684. r600_nomm_get_vb(dev);
  685. if (!dev_priv->blit_vb)
  686. return;
  687. set_shaders(dev);
  688. }
  689. vb = r600_nomm_get_vb_ptr(dev);
  690. sx2 = sx + w;
  691. sy2 = sy + h;
  692. dx2 = dx + w;
  693. dy2 = dy + h;
  694. vb[0] = int2float(dx);
  695. vb[1] = int2float(dy);
  696. vb[2] = int2float(sx);
  697. vb[3] = int2float(sy);
  698. vb[4] = int2float(dx);
  699. vb[5] = int2float(dy2);
  700. vb[6] = int2float(sx);
  701. vb[7] = int2float(sy2);
  702. vb[8] = int2float(dx2);
  703. vb[9] = int2float(dy2);
  704. vb[10] = int2float(sx2);
  705. vb[11] = int2float(sy2);
  706. switch(cpp) {
  707. case 4:
  708. cb_format = COLOR_8_8_8_8;
  709. tex_format = FMT_8_8_8_8;
  710. break;
  711. case 2:
  712. cb_format = COLOR_5_6_5;
  713. tex_format = FMT_5_6_5;
  714. break;
  715. default:
  716. cb_format = COLOR_8;
  717. tex_format = FMT_8;
  718. break;
  719. }
  720. /* src */
  721. set_tex_resource(dev_priv, tex_format,
  722. src_pitch / cpp,
  723. sy2, src_pitch / cpp,
  724. src_gpu_addr);
  725. cp_set_surface_sync(dev_priv,
  726. R600_TC_ACTION_ENA, src_pitch * sy2, src_gpu_addr);
  727. /* dst */
  728. set_render_target(dev_priv, cb_format,
  729. dst_pitch / cpp, dy2,
  730. dst_gpu_addr);
  731. /* scissors */
  732. set_scissors(dev_priv, dx, dy, dx2, dy2);
  733. /* Vertex buffer setup */
  734. vb_addr = dev_priv->gart_buffers_offset +
  735. dev_priv->blit_vb->offset +
  736. dev_priv->blit_vb->used;
  737. set_vtx_resource(dev_priv, vb_addr);
  738. /* draw */
  739. draw_auto(dev_priv);
  740. cp_set_surface_sync(dev_priv,
  741. R600_CB_ACTION_ENA | R600_CB0_DEST_BASE_ENA,
  742. dst_pitch * dy2, dst_gpu_addr);
  743. dev_priv->blit_vb->used += 12 * 4;
  744. }