vc4_render_cl.c 18 KB

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