vc4_render_cl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Copyright © 2014-2015 Broadcom
  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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. /**
  24. * DOC: Render command list generation
  25. *
  26. * In the V3D hardware, render command lists are what load and store
  27. * tiles of a framebuffer and optionally call out to binner-generated
  28. * command lists to do the 3D drawing for that tile.
  29. *
  30. * In the VC4 driver, render command list generation is performed by the
  31. * kernel instead of userspace. We do this because validating a
  32. * user-submitted command list is hard to get right and has high CPU overhead,
  33. * while the number of valid configurations for render command lists is
  34. * actually fairly low.
  35. */
  36. #include "uapi/drm/vc4_drm.h"
  37. #include "vc4_drv.h"
  38. #include "vc4_packet.h"
  39. struct vc4_rcl_setup {
  40. struct drm_gem_dma_object *color_read;
  41. struct drm_gem_dma_object *color_write;
  42. struct drm_gem_dma_object *zs_read;
  43. struct drm_gem_dma_object *zs_write;
  44. struct drm_gem_dma_object *msaa_color_write;
  45. struct drm_gem_dma_object *msaa_zs_write;
  46. struct drm_gem_dma_object *rcl;
  47. u32 next_offset;
  48. u32 next_write_bo_index;
  49. };
  50. static inline void rcl_u8(struct vc4_rcl_setup *setup, u8 val)
  51. {
  52. *(u8 *)(setup->rcl->vaddr + setup->next_offset) = val;
  53. setup->next_offset += 1;
  54. }
  55. static inline void rcl_u16(struct vc4_rcl_setup *setup, u16 val)
  56. {
  57. *(u16 *)(setup->rcl->vaddr + setup->next_offset) = val;
  58. setup->next_offset += 2;
  59. }
  60. static inline void rcl_u32(struct vc4_rcl_setup *setup, u32 val)
  61. {
  62. *(u32 *)(setup->rcl->vaddr + setup->next_offset) = val;
  63. setup->next_offset += 4;
  64. }
  65. /*
  66. * Emits a no-op STORE_TILE_BUFFER_GENERAL.
  67. *
  68. * If we emit a PACKET_TILE_COORDINATES, it must be followed by a store of
  69. * some sort before another load is triggered.
  70. */
  71. static void vc4_store_before_load(struct vc4_rcl_setup *setup)
  72. {
  73. rcl_u8(setup, VC4_PACKET_STORE_TILE_BUFFER_GENERAL);
  74. rcl_u16(setup,
  75. VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_NONE,
  76. VC4_LOADSTORE_TILE_BUFFER_BUFFER) |
  77. VC4_STORE_TILE_BUFFER_DISABLE_COLOR_CLEAR |
  78. VC4_STORE_TILE_BUFFER_DISABLE_ZS_CLEAR |
  79. VC4_STORE_TILE_BUFFER_DISABLE_VG_MASK_CLEAR);
  80. rcl_u32(setup, 0); /* no address, since we're in None mode */
  81. }
  82. /*
  83. * Calculates the physical address of the start of a tile in a RCL surface.
  84. *
  85. * Unlike the other load/store packets,
  86. * VC4_PACKET_LOAD/STORE_FULL_RES_TILE_BUFFER don't look at the tile
  87. * coordinates packet, and instead just store to the address given.
  88. */
  89. static uint32_t vc4_full_res_offset(struct vc4_exec_info *exec,
  90. struct drm_gem_dma_object *bo,
  91. struct drm_vc4_submit_rcl_surface *surf,
  92. uint8_t x, uint8_t y)
  93. {
  94. return bo->dma_addr + surf->offset + VC4_TILE_BUFFER_SIZE *
  95. (DIV_ROUND_UP(exec->args->width, 32) * y + x);
  96. }
  97. /*
  98. * Emits a PACKET_TILE_COORDINATES if one isn't already pending.
  99. *
  100. * The tile coordinates packet triggers a pending load if there is one, are
  101. * used for clipping during rendering, and determine where loads/stores happen
  102. * relative to their base address.
  103. */
  104. static void vc4_tile_coordinates(struct vc4_rcl_setup *setup,
  105. uint32_t x, uint32_t y)
  106. {
  107. rcl_u8(setup, VC4_PACKET_TILE_COORDINATES);
  108. rcl_u8(setup, x);
  109. rcl_u8(setup, y);
  110. }
  111. static void emit_tile(struct vc4_exec_info *exec,
  112. struct vc4_rcl_setup *setup,
  113. uint8_t x, uint8_t y, bool first, bool last)
  114. {
  115. struct drm_vc4_submit_cl *args = exec->args;
  116. bool has_bin = args->bin_cl_size != 0;
  117. /* Note that the load doesn't actually occur until the
  118. * tile coords packet is processed, and only one load
  119. * may be outstanding at a time.
  120. */
  121. if (setup->color_read) {
  122. if (args->color_read.flags &
  123. VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  124. rcl_u8(setup, VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER);
  125. rcl_u32(setup,
  126. vc4_full_res_offset(exec, setup->color_read,
  127. &args->color_read, x, y) |
  128. VC4_LOADSTORE_FULL_RES_DISABLE_ZS);
  129. } else {
  130. rcl_u8(setup, VC4_PACKET_LOAD_TILE_BUFFER_GENERAL);
  131. rcl_u16(setup, args->color_read.bits);
  132. rcl_u32(setup, setup->color_read->dma_addr +
  133. args->color_read.offset);
  134. }
  135. }
  136. if (setup->zs_read) {
  137. if (setup->color_read) {
  138. /* Exec previous load. */
  139. vc4_tile_coordinates(setup, x, y);
  140. vc4_store_before_load(setup);
  141. }
  142. if (args->zs_read.flags &
  143. VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  144. rcl_u8(setup, VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER);
  145. rcl_u32(setup,
  146. vc4_full_res_offset(exec, setup->zs_read,
  147. &args->zs_read, x, y) |
  148. VC4_LOADSTORE_FULL_RES_DISABLE_COLOR);
  149. } else {
  150. rcl_u8(setup, VC4_PACKET_LOAD_TILE_BUFFER_GENERAL);
  151. rcl_u16(setup, args->zs_read.bits);
  152. rcl_u32(setup, setup->zs_read->dma_addr +
  153. args->zs_read.offset);
  154. }
  155. }
  156. /* Clipping depends on tile coordinates having been
  157. * emitted, so we always need one here.
  158. */
  159. vc4_tile_coordinates(setup, x, y);
  160. /* Wait for the binner before jumping to the first
  161. * tile's lists.
  162. */
  163. if (first && has_bin)
  164. rcl_u8(setup, VC4_PACKET_WAIT_ON_SEMAPHORE);
  165. if (has_bin) {
  166. rcl_u8(setup, VC4_PACKET_BRANCH_TO_SUB_LIST);
  167. rcl_u32(setup, (exec->tile_alloc_offset +
  168. (y * exec->bin_tiles_x + x) * 32));
  169. }
  170. if (setup->msaa_color_write) {
  171. bool last_tile_write = (!setup->msaa_zs_write &&
  172. !setup->zs_write &&
  173. !setup->color_write);
  174. uint32_t bits = VC4_LOADSTORE_FULL_RES_DISABLE_ZS;
  175. if (!last_tile_write)
  176. bits |= VC4_LOADSTORE_FULL_RES_DISABLE_CLEAR_ALL;
  177. else if (last)
  178. bits |= VC4_LOADSTORE_FULL_RES_EOF;
  179. rcl_u8(setup, VC4_PACKET_STORE_FULL_RES_TILE_BUFFER);
  180. rcl_u32(setup,
  181. vc4_full_res_offset(exec, setup->msaa_color_write,
  182. &args->msaa_color_write, x, y) |
  183. bits);
  184. }
  185. if (setup->msaa_zs_write) {
  186. bool last_tile_write = (!setup->zs_write &&
  187. !setup->color_write);
  188. uint32_t bits = VC4_LOADSTORE_FULL_RES_DISABLE_COLOR;
  189. if (setup->msaa_color_write)
  190. vc4_tile_coordinates(setup, x, y);
  191. if (!last_tile_write)
  192. bits |= VC4_LOADSTORE_FULL_RES_DISABLE_CLEAR_ALL;
  193. else if (last)
  194. bits |= VC4_LOADSTORE_FULL_RES_EOF;
  195. rcl_u8(setup, VC4_PACKET_STORE_FULL_RES_TILE_BUFFER);
  196. rcl_u32(setup,
  197. vc4_full_res_offset(exec, setup->msaa_zs_write,
  198. &args->msaa_zs_write, x, y) |
  199. bits);
  200. }
  201. if (setup->zs_write) {
  202. bool last_tile_write = !setup->color_write;
  203. if (setup->msaa_color_write || setup->msaa_zs_write)
  204. vc4_tile_coordinates(setup, x, y);
  205. rcl_u8(setup, VC4_PACKET_STORE_TILE_BUFFER_GENERAL);
  206. rcl_u16(setup, args->zs_write.bits |
  207. (last_tile_write ?
  208. 0 : VC4_STORE_TILE_BUFFER_DISABLE_COLOR_CLEAR));
  209. rcl_u32(setup,
  210. (setup->zs_write->dma_addr + args->zs_write.offset) |
  211. ((last && last_tile_write) ?
  212. VC4_LOADSTORE_TILE_BUFFER_EOF : 0));
  213. }
  214. if (setup->color_write) {
  215. if (setup->msaa_color_write || setup->msaa_zs_write ||
  216. setup->zs_write) {
  217. vc4_tile_coordinates(setup, x, y);
  218. }
  219. if (last)
  220. rcl_u8(setup, VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF);
  221. else
  222. rcl_u8(setup, VC4_PACKET_STORE_MS_TILE_BUFFER);
  223. }
  224. }
  225. static int vc4_create_rcl_bo(struct drm_device *dev, struct vc4_exec_info *exec,
  226. struct vc4_rcl_setup *setup)
  227. {
  228. struct drm_vc4_submit_cl *args = exec->args;
  229. bool has_bin = args->bin_cl_size != 0;
  230. uint8_t min_x_tile = args->min_x_tile;
  231. uint8_t min_y_tile = args->min_y_tile;
  232. uint8_t max_x_tile = args->max_x_tile;
  233. uint8_t max_y_tile = args->max_y_tile;
  234. uint8_t xtiles = max_x_tile - min_x_tile + 1;
  235. uint8_t ytiles = max_y_tile - min_y_tile + 1;
  236. uint8_t xi, yi;
  237. uint32_t size, loop_body_size;
  238. bool positive_x = true;
  239. bool positive_y = true;
  240. if (args->flags & VC4_SUBMIT_CL_FIXED_RCL_ORDER) {
  241. if (!(args->flags & VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X))
  242. positive_x = false;
  243. if (!(args->flags & VC4_SUBMIT_CL_RCL_ORDER_INCREASING_Y))
  244. positive_y = false;
  245. }
  246. size = VC4_PACKET_TILE_RENDERING_MODE_CONFIG_SIZE;
  247. loop_body_size = VC4_PACKET_TILE_COORDINATES_SIZE;
  248. if (args->flags & VC4_SUBMIT_CL_USE_CLEAR_COLOR) {
  249. size += VC4_PACKET_CLEAR_COLORS_SIZE +
  250. VC4_PACKET_TILE_COORDINATES_SIZE +
  251. VC4_PACKET_STORE_TILE_BUFFER_GENERAL_SIZE;
  252. }
  253. if (setup->color_read) {
  254. if (args->color_read.flags &
  255. VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  256. loop_body_size += VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER_SIZE;
  257. } else {
  258. loop_body_size += VC4_PACKET_LOAD_TILE_BUFFER_GENERAL_SIZE;
  259. }
  260. }
  261. if (setup->zs_read) {
  262. if (setup->color_read) {
  263. loop_body_size += VC4_PACKET_TILE_COORDINATES_SIZE;
  264. loop_body_size += VC4_PACKET_STORE_TILE_BUFFER_GENERAL_SIZE;
  265. }
  266. if (args->zs_read.flags &
  267. VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  268. loop_body_size += VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER_SIZE;
  269. } else {
  270. loop_body_size += VC4_PACKET_LOAD_TILE_BUFFER_GENERAL_SIZE;
  271. }
  272. }
  273. if (has_bin) {
  274. size += VC4_PACKET_WAIT_ON_SEMAPHORE_SIZE;
  275. loop_body_size += VC4_PACKET_BRANCH_TO_SUB_LIST_SIZE;
  276. }
  277. if (setup->msaa_color_write)
  278. loop_body_size += VC4_PACKET_STORE_FULL_RES_TILE_BUFFER_SIZE;
  279. if (setup->msaa_zs_write)
  280. loop_body_size += VC4_PACKET_STORE_FULL_RES_TILE_BUFFER_SIZE;
  281. if (setup->zs_write)
  282. loop_body_size += VC4_PACKET_STORE_TILE_BUFFER_GENERAL_SIZE;
  283. if (setup->color_write)
  284. loop_body_size += VC4_PACKET_STORE_MS_TILE_BUFFER_SIZE;
  285. /* We need a VC4_PACKET_TILE_COORDINATES in between each store. */
  286. loop_body_size += VC4_PACKET_TILE_COORDINATES_SIZE *
  287. ((setup->msaa_color_write != NULL) +
  288. (setup->msaa_zs_write != NULL) +
  289. (setup->color_write != NULL) +
  290. (setup->zs_write != NULL) - 1);
  291. size += xtiles * ytiles * loop_body_size;
  292. setup->rcl = &vc4_bo_create(dev, size, true, VC4_BO_TYPE_RCL)->base;
  293. if (IS_ERR(setup->rcl))
  294. return PTR_ERR(setup->rcl);
  295. list_add_tail(&to_vc4_bo(&setup->rcl->base)->unref_head,
  296. &exec->unref_list);
  297. /* The tile buffer gets cleared when the previous tile is stored. If
  298. * the clear values changed between frames, then the tile buffer has
  299. * stale clear values in it, so we have to do a store in None mode (no
  300. * writes) so that we trigger the tile buffer clear.
  301. */
  302. if (args->flags & VC4_SUBMIT_CL_USE_CLEAR_COLOR) {
  303. rcl_u8(setup, VC4_PACKET_CLEAR_COLORS);
  304. rcl_u32(setup, args->clear_color[0]);
  305. rcl_u32(setup, args->clear_color[1]);
  306. rcl_u32(setup, args->clear_z);
  307. rcl_u8(setup, args->clear_s);
  308. vc4_tile_coordinates(setup, 0, 0);
  309. rcl_u8(setup, VC4_PACKET_STORE_TILE_BUFFER_GENERAL);
  310. rcl_u16(setup, VC4_LOADSTORE_TILE_BUFFER_NONE);
  311. rcl_u32(setup, 0); /* no address, since we're in None mode */
  312. }
  313. rcl_u8(setup, VC4_PACKET_TILE_RENDERING_MODE_CONFIG);
  314. rcl_u32(setup,
  315. (setup->color_write ? (setup->color_write->dma_addr +
  316. args->color_write.offset) :
  317. 0));
  318. rcl_u16(setup, args->width);
  319. rcl_u16(setup, args->height);
  320. rcl_u16(setup, args->color_write.bits);
  321. for (yi = 0; yi < ytiles; yi++) {
  322. int y = positive_y ? min_y_tile + yi : max_y_tile - yi;
  323. for (xi = 0; xi < xtiles; xi++) {
  324. int x = positive_x ? min_x_tile + xi : max_x_tile - xi;
  325. bool first = (xi == 0 && yi == 0);
  326. bool last = (xi == xtiles - 1 && yi == ytiles - 1);
  327. emit_tile(exec, setup, x, y, first, last);
  328. }
  329. }
  330. BUG_ON(setup->next_offset != size);
  331. exec->ct1ca = setup->rcl->dma_addr;
  332. exec->ct1ea = setup->rcl->dma_addr + setup->next_offset;
  333. return 0;
  334. }
  335. static int vc4_full_res_bounds_check(struct vc4_exec_info *exec,
  336. struct drm_gem_dma_object *obj,
  337. struct drm_vc4_submit_rcl_surface *surf)
  338. {
  339. struct drm_vc4_submit_cl *args = exec->args;
  340. u32 render_tiles_stride = DIV_ROUND_UP(exec->args->width, 32);
  341. if (surf->offset > obj->base.size) {
  342. DRM_DEBUG("surface offset %d > BO size %zd\n",
  343. surf->offset, obj->base.size);
  344. return -EINVAL;
  345. }
  346. if ((obj->base.size - surf->offset) / VC4_TILE_BUFFER_SIZE <
  347. render_tiles_stride * args->max_y_tile + args->max_x_tile) {
  348. DRM_DEBUG("MSAA tile %d, %d out of bounds "
  349. "(bo size %zd, offset %d).\n",
  350. args->max_x_tile, args->max_y_tile,
  351. obj->base.size,
  352. surf->offset);
  353. return -EINVAL;
  354. }
  355. return 0;
  356. }
  357. static int vc4_rcl_msaa_surface_setup(struct vc4_exec_info *exec,
  358. struct drm_gem_dma_object **obj,
  359. struct drm_vc4_submit_rcl_surface *surf)
  360. {
  361. if (surf->flags != 0 || surf->bits != 0) {
  362. DRM_DEBUG("MSAA surface had nonzero flags/bits\n");
  363. return -EINVAL;
  364. }
  365. if (surf->hindex == ~0)
  366. return 0;
  367. *obj = vc4_use_bo(exec, surf->hindex);
  368. if (!*obj)
  369. return -EINVAL;
  370. exec->rcl_write_bo[exec->rcl_write_bo_count++] = *obj;
  371. if (surf->offset & 0xf) {
  372. DRM_DEBUG("MSAA write must be 16b aligned.\n");
  373. return -EINVAL;
  374. }
  375. return vc4_full_res_bounds_check(exec, *obj, surf);
  376. }
  377. static int vc4_rcl_surface_setup(struct vc4_exec_info *exec,
  378. struct drm_gem_dma_object **obj,
  379. struct drm_vc4_submit_rcl_surface *surf,
  380. bool is_write)
  381. {
  382. uint8_t tiling = VC4_GET_FIELD(surf->bits,
  383. VC4_LOADSTORE_TILE_BUFFER_TILING);
  384. uint8_t buffer = VC4_GET_FIELD(surf->bits,
  385. VC4_LOADSTORE_TILE_BUFFER_BUFFER);
  386. uint8_t format = VC4_GET_FIELD(surf->bits,
  387. VC4_LOADSTORE_TILE_BUFFER_FORMAT);
  388. int cpp;
  389. int ret;
  390. if (surf->flags & ~VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  391. DRM_DEBUG("Extra flags set\n");
  392. return -EINVAL;
  393. }
  394. if (surf->hindex == ~0)
  395. return 0;
  396. *obj = vc4_use_bo(exec, surf->hindex);
  397. if (!*obj)
  398. return -EINVAL;
  399. if (is_write)
  400. exec->rcl_write_bo[exec->rcl_write_bo_count++] = *obj;
  401. if (surf->flags & VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  402. if (surf == &exec->args->zs_write) {
  403. DRM_DEBUG("general zs write may not be a full-res.\n");
  404. return -EINVAL;
  405. }
  406. if (surf->bits != 0) {
  407. DRM_DEBUG("load/store general bits set with "
  408. "full res load/store.\n");
  409. return -EINVAL;
  410. }
  411. ret = vc4_full_res_bounds_check(exec, *obj, surf);
  412. if (ret)
  413. return ret;
  414. return 0;
  415. }
  416. if (surf->bits & ~(VC4_LOADSTORE_TILE_BUFFER_TILING_MASK |
  417. VC4_LOADSTORE_TILE_BUFFER_BUFFER_MASK |
  418. VC4_LOADSTORE_TILE_BUFFER_FORMAT_MASK)) {
  419. DRM_DEBUG("Unknown bits in load/store: 0x%04x\n",
  420. surf->bits);
  421. return -EINVAL;
  422. }
  423. if (tiling > VC4_TILING_FORMAT_LT) {
  424. DRM_DEBUG("Bad tiling format\n");
  425. return -EINVAL;
  426. }
  427. if (buffer == VC4_LOADSTORE_TILE_BUFFER_ZS) {
  428. if (format != 0) {
  429. DRM_DEBUG("No color format should be set for ZS\n");
  430. return -EINVAL;
  431. }
  432. cpp = 4;
  433. } else if (buffer == VC4_LOADSTORE_TILE_BUFFER_COLOR) {
  434. switch (format) {
  435. case VC4_LOADSTORE_TILE_BUFFER_BGR565:
  436. case VC4_LOADSTORE_TILE_BUFFER_BGR565_DITHER:
  437. cpp = 2;
  438. break;
  439. case VC4_LOADSTORE_TILE_BUFFER_RGBA8888:
  440. cpp = 4;
  441. break;
  442. default:
  443. DRM_DEBUG("Bad tile buffer format\n");
  444. return -EINVAL;
  445. }
  446. } else {
  447. DRM_DEBUG("Bad load/store buffer %d.\n", buffer);
  448. return -EINVAL;
  449. }
  450. if (surf->offset & 0xf) {
  451. DRM_DEBUG("load/store buffer must be 16b aligned.\n");
  452. return -EINVAL;
  453. }
  454. if (!vc4_check_tex_size(exec, *obj, surf->offset, tiling,
  455. exec->args->width, exec->args->height, cpp)) {
  456. return -EINVAL;
  457. }
  458. return 0;
  459. }
  460. static int
  461. vc4_rcl_render_config_surface_setup(struct vc4_exec_info *exec,
  462. struct vc4_rcl_setup *setup,
  463. struct drm_gem_dma_object **obj,
  464. struct drm_vc4_submit_rcl_surface *surf)
  465. {
  466. uint8_t tiling = VC4_GET_FIELD(surf->bits,
  467. VC4_RENDER_CONFIG_MEMORY_FORMAT);
  468. uint8_t format = VC4_GET_FIELD(surf->bits,
  469. VC4_RENDER_CONFIG_FORMAT);
  470. int cpp;
  471. if (surf->flags != 0) {
  472. DRM_DEBUG("No flags supported on render config.\n");
  473. return -EINVAL;
  474. }
  475. if (surf->bits & ~(VC4_RENDER_CONFIG_MEMORY_FORMAT_MASK |
  476. VC4_RENDER_CONFIG_FORMAT_MASK |
  477. VC4_RENDER_CONFIG_MS_MODE_4X |
  478. VC4_RENDER_CONFIG_DECIMATE_MODE_4X)) {
  479. DRM_DEBUG("Unknown bits in render config: 0x%04x\n",
  480. surf->bits);
  481. return -EINVAL;
  482. }
  483. if (surf->hindex == ~0)
  484. return 0;
  485. *obj = vc4_use_bo(exec, surf->hindex);
  486. if (!*obj)
  487. return -EINVAL;
  488. exec->rcl_write_bo[exec->rcl_write_bo_count++] = *obj;
  489. if (tiling > VC4_TILING_FORMAT_LT) {
  490. DRM_DEBUG("Bad tiling format\n");
  491. return -EINVAL;
  492. }
  493. switch (format) {
  494. case VC4_RENDER_CONFIG_FORMAT_BGR565_DITHERED:
  495. case VC4_RENDER_CONFIG_FORMAT_BGR565:
  496. cpp = 2;
  497. break;
  498. case VC4_RENDER_CONFIG_FORMAT_RGBA8888:
  499. cpp = 4;
  500. break;
  501. default:
  502. DRM_DEBUG("Bad tile buffer format\n");
  503. return -EINVAL;
  504. }
  505. if (!vc4_check_tex_size(exec, *obj, surf->offset, tiling,
  506. exec->args->width, exec->args->height, cpp)) {
  507. return -EINVAL;
  508. }
  509. return 0;
  510. }
  511. int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec)
  512. {
  513. struct vc4_dev *vc4 = to_vc4_dev(dev);
  514. struct vc4_rcl_setup setup = {0};
  515. struct drm_vc4_submit_cl *args = exec->args;
  516. bool has_bin = args->bin_cl_size != 0;
  517. int ret;
  518. if (WARN_ON_ONCE(vc4->gen == VC4_GEN_5))
  519. return -ENODEV;
  520. if (args->min_x_tile > args->max_x_tile ||
  521. args->min_y_tile > args->max_y_tile) {
  522. DRM_DEBUG("Bad render tile set (%d,%d)-(%d,%d)\n",
  523. args->min_x_tile, args->min_y_tile,
  524. args->max_x_tile, args->max_y_tile);
  525. return -EINVAL;
  526. }
  527. if (has_bin &&
  528. (args->max_x_tile > exec->bin_tiles_x ||
  529. args->max_y_tile > exec->bin_tiles_y)) {
  530. DRM_DEBUG("Render tiles (%d,%d) outside of bin config "
  531. "(%d,%d)\n",
  532. args->max_x_tile, args->max_y_tile,
  533. exec->bin_tiles_x, exec->bin_tiles_y);
  534. return -EINVAL;
  535. }
  536. ret = vc4_rcl_render_config_surface_setup(exec, &setup,
  537. &setup.color_write,
  538. &args->color_write);
  539. if (ret)
  540. return ret;
  541. ret = vc4_rcl_surface_setup(exec, &setup.color_read, &args->color_read,
  542. false);
  543. if (ret)
  544. return ret;
  545. ret = vc4_rcl_surface_setup(exec, &setup.zs_read, &args->zs_read,
  546. false);
  547. if (ret)
  548. return ret;
  549. ret = vc4_rcl_surface_setup(exec, &setup.zs_write, &args->zs_write,
  550. true);
  551. if (ret)
  552. return ret;
  553. ret = vc4_rcl_msaa_surface_setup(exec, &setup.msaa_color_write,
  554. &args->msaa_color_write);
  555. if (ret)
  556. return ret;
  557. ret = vc4_rcl_msaa_surface_setup(exec, &setup.msaa_zs_write,
  558. &args->msaa_zs_write);
  559. if (ret)
  560. return ret;
  561. /* We shouldn't even have the job submitted to us if there's no
  562. * surface to write out.
  563. */
  564. if (!setup.color_write && !setup.zs_write &&
  565. !setup.msaa_color_write && !setup.msaa_zs_write) {
  566. DRM_DEBUG("RCL requires color or Z/S write\n");
  567. return -EINVAL;
  568. }
  569. return vc4_create_rcl_bo(dev, exec, &setup);
  570. }