Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ilo_render_gen7.c 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /*
  2. * Mesa 3-D graphics library
  3. *
  4. * Copyright (C) 2013 LunarG, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Chia-I Wu <olv@lunarg.com>
  26. */
  27. #include "genhw/genhw.h"
  28. #include "util/u_dual_blend.h"
  29. #include "ilo_blitter.h"
  30. #include "ilo_builder_3d.h"
  31. #include "ilo_builder_render.h"
  32. #include "ilo_shader.h"
  33. #include "ilo_state.h"
  34. #include "ilo_render.h"
  35. #include "ilo_render_gen.h"
  36. #include "ilo_render_gen7.h"
  37. /**
  38. * A wrapper for gen6_PIPE_CONTROL().
  39. */
  40. static inline void
  41. gen7_pipe_control(struct ilo_render *r, uint32_t dw1)
  42. {
  43. struct intel_bo *bo = (dw1 & GEN6_PIPE_CONTROL_WRITE__MASK) ?
  44. r->workaround_bo : NULL;
  45. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  46. if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
  47. /* CS stall cannot be set alone */
  48. const uint32_t mask = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
  49. GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
  50. GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
  51. GEN6_PIPE_CONTROL_DEPTH_STALL |
  52. GEN6_PIPE_CONTROL_WRITE__MASK;
  53. if (!(dw1 & mask))
  54. dw1 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
  55. }
  56. gen6_PIPE_CONTROL(r->builder, dw1, bo, 0, false);
  57. r->state.current_pipe_control_dw1 |= dw1;
  58. r->state.deferred_pipe_control_dw1 &= ~dw1;
  59. }
  60. static void
  61. gen7_wa_post_3dstate_push_constant_alloc_ps(struct ilo_render *r)
  62. {
  63. /*
  64. * From the Ivy Bridge PRM, volume 2 part 1, page 292:
  65. *
  66. * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
  67. * in the ring after this instruction
  68. * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
  69. */
  70. const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL;
  71. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  72. r->state.deferred_pipe_control_dw1 |= dw1;
  73. }
  74. static void
  75. gen7_wa_pre_vs(struct ilo_render *r)
  76. {
  77. /*
  78. * From the Ivy Bridge PRM, volume 2 part 1, page 106:
  79. *
  80. * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
  81. * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
  82. * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
  83. * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
  84. * needs to be sent before any combination of VS associated 3DSTATE."
  85. */
  86. const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_STALL |
  87. GEN6_PIPE_CONTROL_WRITE_IMM;
  88. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  89. if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
  90. gen7_pipe_control(r, dw1);
  91. }
  92. static void
  93. gen7_wa_pre_3dstate_sf_depth_bias(struct ilo_render *r)
  94. {
  95. /*
  96. * From the Ivy Bridge PRM, volume 2 part 1, page 258:
  97. *
  98. * "Due to an HW issue driver needs to send a pipe control with stall
  99. * when ever there is state change in depth bias related state (in
  100. * 3DSTATE_SF)"
  101. */
  102. const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL;
  103. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  104. if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
  105. gen7_pipe_control(r, dw1);
  106. }
  107. static void
  108. gen7_wa_pre_3dstate_multisample(struct ilo_render *r)
  109. {
  110. /*
  111. * From the Ivy Bridge PRM, volume 2 part 1, page 304:
  112. *
  113. * "Driver must ierarchi that all the caches in the depth pipe are
  114. * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
  115. * requires driver to send a PIPE_CONTROL with a CS stall along with a
  116. * Depth Flush prior to this command.
  117. */
  118. const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
  119. GEN6_PIPE_CONTROL_CS_STALL;
  120. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  121. if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
  122. gen7_pipe_control(r, dw1);
  123. }
  124. static void
  125. gen7_wa_pre_depth(struct ilo_render *r)
  126. {
  127. /*
  128. * From the Ivy Bridge PRM, volume 2 part 1, page 315:
  129. *
  130. * "Driver must send a least one PIPE_CONTROL command with CS Stall and
  131. * a post sync operation prior to the group of depth
  132. * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
  133. * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
  134. */
  135. const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL |
  136. GEN6_PIPE_CONTROL_WRITE_IMM;
  137. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  138. if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
  139. gen7_pipe_control(r, dw1);
  140. /*
  141. * From the Ivy Bridge PRM, volume 2 part 1, page 315:
  142. *
  143. * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
  144. * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
  145. * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
  146. * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
  147. * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
  148. * Depth Flush Bit set, followed by another pipelined depth stall
  149. * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
  150. * guarantee that the pipeline from WM onwards is already flushed
  151. * (e.g., via a preceding MI_FLUSH)."
  152. */
  153. gen7_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
  154. gen7_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH);
  155. gen7_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
  156. }
  157. static void
  158. gen7_wa_pre_3dstate_ps_max_threads(struct ilo_render *r)
  159. {
  160. /*
  161. * From the Ivy Bridge PRM, volume 2 part 1, page 286:
  162. *
  163. * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
  164. * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
  165. * Pixel Scoreboard set is required to be issued."
  166. */
  167. const uint32_t dw1 = GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
  168. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  169. if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
  170. gen7_pipe_control(r, dw1);
  171. }
  172. static void
  173. gen7_wa_post_ps_and_later(struct ilo_render *r)
  174. {
  175. /*
  176. * From the Ivy Bridge PRM, volume 2 part 1, page 276:
  177. *
  178. * "The driver must make sure a PIPE_CONTROL with the Depth Stall
  179. * Enable bit set after all the following states are programmed:
  180. *
  181. * - 3DSTATE_PS
  182. * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
  183. * - 3DSTATE_CONSTANT_PS
  184. * - 3DSTATE_BINDING_TABLE_POINTERS_PS
  185. * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
  186. * - 3DSTATE_CC_STATE_POINTERS
  187. * - 3DSTATE_BLEND_STATE_POINTERS
  188. * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
  189. */
  190. const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_STALL;
  191. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  192. r->state.deferred_pipe_control_dw1 |= dw1;
  193. }
  194. #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
  195. static void
  196. gen7_draw_common_urb(struct ilo_render *r,
  197. const struct ilo_state_vector *vec,
  198. struct gen6_draw_session *session)
  199. {
  200. /* 3DSTATE_URB_{VS,GS,HS,DS} */
  201. if (DIRTY(VE) || DIRTY(VS)) {
  202. /* the first 16KB are reserved for VS and PS PCBs */
  203. const int offset = (ilo_dev_gen(r->dev) == ILO_GEN(7.5) &&
  204. r->dev->gt == 3) ? 32768 : 16384;
  205. int vs_entry_size, vs_total_size;
  206. vs_entry_size = (vec->vs) ?
  207. ilo_shader_get_kernel_param(vec->vs, ILO_KERNEL_OUTPUT_COUNT) : 0;
  208. /*
  209. * From the Ivy Bridge PRM, volume 2 part 1, page 35:
  210. *
  211. * "Programming Restriction: As the VS URB entry serves as both the
  212. * per-vertex input and output of the VS shader, the VS URB
  213. * Allocation Size must be sized to the maximum of the vertex input
  214. * and output structures."
  215. */
  216. if (vs_entry_size < vec->ve->count)
  217. vs_entry_size = vec->ve->count;
  218. vs_entry_size *= sizeof(float) * 4;
  219. vs_total_size = r->dev->urb_size - offset;
  220. gen7_wa_pre_vs(r);
  221. gen7_3DSTATE_URB_VS(r->builder,
  222. offset, vs_total_size, vs_entry_size);
  223. gen7_3DSTATE_URB_GS(r->builder, offset, 0, 0);
  224. gen7_3DSTATE_URB_HS(r->builder, offset, 0, 0);
  225. gen7_3DSTATE_URB_DS(r->builder, offset, 0, 0);
  226. }
  227. }
  228. static void
  229. gen7_draw_common_pcb_alloc(struct ilo_render *r,
  230. const struct ilo_state_vector *vec,
  231. struct gen6_draw_session *session)
  232. {
  233. /* 3DSTATE_PUSH_CONSTANT_ALLOC_{VS,PS} */
  234. if (r->hw_ctx_changed) {
  235. /*
  236. * Push constant buffers are only allowed to take up at most the first
  237. * 16KB of the URB. Split the space evenly for VS and FS.
  238. */
  239. const int max_size = (ilo_dev_gen(r->dev) == ILO_GEN(7.5) &&
  240. r->dev->gt == 3) ? 32768 : 16384;
  241. const int size = max_size / 2;
  242. int offset = 0;
  243. gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r->builder, offset, size);
  244. offset += size;
  245. gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r->builder, offset, size);
  246. if (ilo_dev_gen(r->dev) == ILO_GEN(7))
  247. gen7_wa_post_3dstate_push_constant_alloc_ps(r);
  248. }
  249. }
  250. static void
  251. gen7_draw_common_pointers_1(struct ilo_render *r,
  252. const struct ilo_state_vector *vec,
  253. struct gen6_draw_session *session)
  254. {
  255. /* 3DSTATE_VIEWPORT_STATE_POINTERS_{CC,SF_CLIP} */
  256. if (session->viewport_changed) {
  257. gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r->builder,
  258. r->state.CC_VIEWPORT);
  259. gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(r->builder,
  260. r->state.SF_CLIP_VIEWPORT);
  261. }
  262. }
  263. static void
  264. gen7_draw_common_pointers_2(struct ilo_render *r,
  265. const struct ilo_state_vector *vec,
  266. struct gen6_draw_session *session)
  267. {
  268. /* 3DSTATE_BLEND_STATE_POINTERS */
  269. if (session->blend_changed) {
  270. gen7_3DSTATE_BLEND_STATE_POINTERS(r->builder,
  271. r->state.BLEND_STATE);
  272. }
  273. /* 3DSTATE_CC_STATE_POINTERS */
  274. if (session->cc_changed) {
  275. gen7_3DSTATE_CC_STATE_POINTERS(r->builder,
  276. r->state.COLOR_CALC_STATE);
  277. }
  278. /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS */
  279. if (session->dsa_changed) {
  280. gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r->builder,
  281. r->state.DEPTH_STENCIL_STATE);
  282. }
  283. }
  284. static void
  285. gen7_draw_vs(struct ilo_render *r,
  286. const struct ilo_state_vector *vec,
  287. struct gen6_draw_session *session)
  288. {
  289. const bool emit_3dstate_binding_table =
  290. session->binding_table_vs_changed;
  291. const bool emit_3dstate_sampler_state =
  292. session->sampler_vs_changed;
  293. /* see gen6_draw_vs() */
  294. const bool emit_3dstate_constant_vs = session->pcb_vs_changed;
  295. const bool emit_3dstate_vs = (DIRTY(VS) || DIRTY(SAMPLER_VS) ||
  296. r->instruction_bo_changed);
  297. /* emit depth stall before any of the VS commands */
  298. if (emit_3dstate_binding_table || emit_3dstate_sampler_state ||
  299. emit_3dstate_constant_vs || emit_3dstate_vs)
  300. gen7_wa_pre_vs(r);
  301. /* 3DSTATE_BINDING_TABLE_POINTERS_VS */
  302. if (emit_3dstate_binding_table) {
  303. gen7_3DSTATE_BINDING_TABLE_POINTERS_VS(r->builder,
  304. r->state.vs.BINDING_TABLE_STATE);
  305. }
  306. /* 3DSTATE_SAMPLER_STATE_POINTERS_VS */
  307. if (emit_3dstate_sampler_state) {
  308. gen7_3DSTATE_SAMPLER_STATE_POINTERS_VS(r->builder,
  309. r->state.vs.SAMPLER_STATE);
  310. }
  311. /* 3DSTATE_CONSTANT_VS */
  312. if (emit_3dstate_constant_vs) {
  313. gen7_3DSTATE_CONSTANT_VS(r->builder,
  314. &r->state.vs.PUSH_CONSTANT_BUFFER,
  315. &r->state.vs.PUSH_CONSTANT_BUFFER_size,
  316. 1);
  317. }
  318. /* 3DSTATE_VS */
  319. if (emit_3dstate_vs) {
  320. const int num_samplers = vec->sampler[PIPE_SHADER_VERTEX].count;
  321. gen6_3DSTATE_VS(r->builder, vec->vs, num_samplers);
  322. }
  323. }
  324. static void
  325. gen7_draw_hs(struct ilo_render *r,
  326. const struct ilo_state_vector *vec,
  327. struct gen6_draw_session *session)
  328. {
  329. /* 3DSTATE_CONSTANT_HS and 3DSTATE_HS */
  330. if (r->hw_ctx_changed) {
  331. gen7_3DSTATE_CONSTANT_HS(r->builder, 0, 0, 0);
  332. gen7_3DSTATE_HS(r->builder, NULL, 0);
  333. }
  334. /* 3DSTATE_BINDING_TABLE_POINTERS_HS */
  335. if (r->hw_ctx_changed)
  336. gen7_3DSTATE_BINDING_TABLE_POINTERS_HS(r->builder, 0);
  337. }
  338. static void
  339. gen7_draw_te(struct ilo_render *r,
  340. const struct ilo_state_vector *vec,
  341. struct gen6_draw_session *session)
  342. {
  343. /* 3DSTATE_TE */
  344. if (r->hw_ctx_changed)
  345. gen7_3DSTATE_TE(r->builder);
  346. }
  347. static void
  348. gen7_draw_ds(struct ilo_render *r,
  349. const struct ilo_state_vector *vec,
  350. struct gen6_draw_session *session)
  351. {
  352. /* 3DSTATE_CONSTANT_DS and 3DSTATE_DS */
  353. if (r->hw_ctx_changed) {
  354. gen7_3DSTATE_CONSTANT_DS(r->builder, 0, 0, 0);
  355. gen7_3DSTATE_DS(r->builder, NULL, 0);
  356. }
  357. /* 3DSTATE_BINDING_TABLE_POINTERS_DS */
  358. if (r->hw_ctx_changed)
  359. gen7_3DSTATE_BINDING_TABLE_POINTERS_DS(r->builder, 0);
  360. }
  361. static void
  362. gen7_draw_gs(struct ilo_render *r,
  363. const struct ilo_state_vector *vec,
  364. struct gen6_draw_session *session)
  365. {
  366. /* 3DSTATE_CONSTANT_GS and 3DSTATE_GS */
  367. if (r->hw_ctx_changed) {
  368. gen7_3DSTATE_CONSTANT_GS(r->builder, 0, 0, 0);
  369. gen7_3DSTATE_GS(r->builder, NULL, 0);
  370. }
  371. /* 3DSTATE_BINDING_TABLE_POINTERS_GS */
  372. if (session->binding_table_gs_changed) {
  373. gen7_3DSTATE_BINDING_TABLE_POINTERS_GS(r->builder,
  374. r->state.gs.BINDING_TABLE_STATE);
  375. }
  376. }
  377. static void
  378. gen7_draw_sol(struct ilo_render *r,
  379. const struct ilo_state_vector *vec,
  380. struct gen6_draw_session *session)
  381. {
  382. const struct pipe_stream_output_info *so_info;
  383. const struct ilo_shader_state *shader;
  384. bool dirty_sh = false;
  385. if (vec->gs) {
  386. shader = vec->gs;
  387. dirty_sh = DIRTY(GS);
  388. }
  389. else {
  390. shader = vec->vs;
  391. dirty_sh = DIRTY(VS);
  392. }
  393. so_info = ilo_shader_get_kernel_so_info(shader);
  394. /* 3DSTATE_SO_BUFFER */
  395. if ((DIRTY(SO) || dirty_sh || r->batch_bo_changed) &&
  396. vec->so.enabled) {
  397. int i;
  398. for (i = 0; i < vec->so.count; i++) {
  399. const int stride = so_info->stride[i] * 4; /* in bytes */
  400. int base = 0;
  401. gen7_3DSTATE_SO_BUFFER(r->builder, i, base, stride,
  402. vec->so.states[i]);
  403. }
  404. for (; i < 4; i++)
  405. gen7_3DSTATE_SO_BUFFER(r->builder, i, 0, 0, NULL);
  406. }
  407. /* 3DSTATE_SO_DECL_LIST */
  408. if (dirty_sh && vec->so.enabled)
  409. gen7_3DSTATE_SO_DECL_LIST(r->builder, so_info);
  410. /* 3DSTATE_STREAMOUT */
  411. if (DIRTY(SO) || DIRTY(RASTERIZER) || dirty_sh) {
  412. const unsigned buffer_mask = (1 << vec->so.count) - 1;
  413. const int output_count = ilo_shader_get_kernel_param(shader,
  414. ILO_KERNEL_OUTPUT_COUNT);
  415. gen7_3DSTATE_STREAMOUT(r->builder, buffer_mask, output_count,
  416. vec->rasterizer->state.rasterizer_discard);
  417. }
  418. }
  419. static void
  420. gen7_draw_sf(struct ilo_render *r,
  421. const struct ilo_state_vector *vec,
  422. struct gen6_draw_session *session)
  423. {
  424. /* 3DSTATE_SBE */
  425. if (DIRTY(RASTERIZER) || DIRTY(FS))
  426. gen7_3DSTATE_SBE(r->builder, vec->rasterizer, vec->fs);
  427. /* 3DSTATE_SF */
  428. if (DIRTY(RASTERIZER) || DIRTY(FB)) {
  429. struct pipe_surface *zs = vec->fb.state.zsbuf;
  430. gen7_wa_pre_3dstate_sf_depth_bias(r);
  431. gen7_3DSTATE_SF(r->builder, vec->rasterizer,
  432. (zs) ? zs->format : PIPE_FORMAT_NONE);
  433. }
  434. }
  435. static void
  436. gen7_draw_wm(struct ilo_render *r,
  437. const struct ilo_state_vector *vec,
  438. struct gen6_draw_session *session)
  439. {
  440. /* 3DSTATE_WM */
  441. if (DIRTY(FS) || DIRTY(BLEND) || DIRTY(DSA) || DIRTY(RASTERIZER)) {
  442. const bool cc_may_kill = (vec->dsa->dw_alpha ||
  443. vec->blend->alpha_to_coverage);
  444. gen7_3DSTATE_WM(r->builder, vec->fs,
  445. vec->rasterizer, cc_may_kill, 0);
  446. }
  447. /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
  448. if (session->binding_table_fs_changed) {
  449. gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(r->builder,
  450. r->state.wm.BINDING_TABLE_STATE);
  451. }
  452. /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
  453. if (session->sampler_fs_changed) {
  454. gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(r->builder,
  455. r->state.wm.SAMPLER_STATE);
  456. }
  457. /* 3DSTATE_CONSTANT_PS */
  458. if (session->pcb_fs_changed) {
  459. gen7_3DSTATE_CONSTANT_PS(r->builder,
  460. &r->state.wm.PUSH_CONSTANT_BUFFER,
  461. &r->state.wm.PUSH_CONSTANT_BUFFER_size,
  462. 1);
  463. }
  464. /* 3DSTATE_PS */
  465. if (DIRTY(FS) || DIRTY(SAMPLER_FS) || DIRTY(BLEND) ||
  466. r->instruction_bo_changed) {
  467. const int num_samplers = vec->sampler[PIPE_SHADER_FRAGMENT].count;
  468. const bool dual_blend = vec->blend->dual_blend;
  469. if ((ilo_dev_gen(r->dev) == ILO_GEN(7) ||
  470. ilo_dev_gen(r->dev) == ILO_GEN(7.5)) &&
  471. r->hw_ctx_changed)
  472. gen7_wa_pre_3dstate_ps_max_threads(r);
  473. gen7_3DSTATE_PS(r->builder, vec->fs, num_samplers, dual_blend);
  474. }
  475. /* 3DSTATE_SCISSOR_STATE_POINTERS */
  476. if (session->scissor_changed) {
  477. gen6_3DSTATE_SCISSOR_STATE_POINTERS(r->builder,
  478. r->state.SCISSOR_RECT);
  479. }
  480. /* XXX what is the best way to know if this workaround is needed? */
  481. {
  482. const bool emit_3dstate_ps =
  483. (DIRTY(FS) || DIRTY(SAMPLER_FS) || DIRTY(BLEND));
  484. const bool emit_3dstate_depth_buffer =
  485. (DIRTY(FB) || DIRTY(DSA) || r->state_bo_changed);
  486. if (emit_3dstate_ps ||
  487. session->pcb_fs_changed ||
  488. session->viewport_changed ||
  489. session->binding_table_fs_changed ||
  490. session->sampler_fs_changed ||
  491. session->cc_changed ||
  492. session->blend_changed ||
  493. session->dsa_changed)
  494. gen7_wa_post_ps_and_later(r);
  495. if (emit_3dstate_depth_buffer)
  496. gen7_wa_pre_depth(r);
  497. }
  498. /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
  499. if (DIRTY(FB) || r->batch_bo_changed) {
  500. const struct ilo_zs_surface *zs;
  501. uint32_t clear_params;
  502. if (vec->fb.state.zsbuf) {
  503. const struct ilo_surface_cso *surface =
  504. (const struct ilo_surface_cso *) vec->fb.state.zsbuf;
  505. const struct ilo_texture_slice *slice =
  506. ilo_texture_get_slice(ilo_texture(surface->base.texture),
  507. surface->base.u.tex.level, surface->base.u.tex.first_layer);
  508. assert(!surface->is_rt);
  509. zs = &surface->u.zs;
  510. clear_params = slice->clear_value;
  511. }
  512. else {
  513. zs = &vec->fb.null_zs;
  514. clear_params = 0;
  515. }
  516. gen6_3DSTATE_DEPTH_BUFFER(r->builder, zs);
  517. gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder, zs);
  518. gen6_3DSTATE_STENCIL_BUFFER(r->builder, zs);
  519. gen7_3DSTATE_CLEAR_PARAMS(r->builder, clear_params);
  520. }
  521. }
  522. static void
  523. gen7_draw_wm_multisample(struct ilo_render *r,
  524. const struct ilo_state_vector *vec,
  525. struct gen6_draw_session *session)
  526. {
  527. /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
  528. if (DIRTY(SAMPLE_MASK) || DIRTY(FB)) {
  529. const uint32_t *packed_sample_pos;
  530. gen7_wa_pre_3dstate_multisample(r);
  531. packed_sample_pos =
  532. (vec->fb.num_samples > 4) ? r->packed_sample_position_8x :
  533. (vec->fb.num_samples > 1) ? &r->packed_sample_position_4x :
  534. &r->packed_sample_position_1x;
  535. gen6_3DSTATE_MULTISAMPLE(r->builder,
  536. vec->fb.num_samples, packed_sample_pos,
  537. vec->rasterizer->state.half_pixel_center);
  538. gen7_3DSTATE_SAMPLE_MASK(r->builder,
  539. (vec->fb.num_samples > 1) ? vec->sample_mask : 0x1,
  540. vec->fb.num_samples);
  541. }
  542. }
  543. static void
  544. gen7_draw_vf_draw(struct ilo_render *r,
  545. const struct ilo_state_vector *vec,
  546. struct gen6_draw_session *session)
  547. {
  548. if (r->state.deferred_pipe_control_dw1)
  549. gen7_pipe_control(r, r->state.deferred_pipe_control_dw1);
  550. /* 3DPRIMITIVE */
  551. gen7_3DPRIMITIVE(r->builder, vec->draw, &vec->ib);
  552. r->state.current_pipe_control_dw1 = 0;
  553. r->state.deferred_pipe_control_dw1 = 0;
  554. }
  555. static void
  556. gen7_draw_commands(struct ilo_render *render,
  557. const struct ilo_state_vector *vec,
  558. struct gen6_draw_session *session)
  559. {
  560. /*
  561. * We try to keep the order of the commands match, as closely as possible,
  562. * that of the classic i965 driver. It allows us to compare the command
  563. * streams easily.
  564. */
  565. gen6_draw_common_select(render, vec, session);
  566. gen6_draw_common_sip(render, vec, session);
  567. gen6_draw_vf_statistics(render, vec, session);
  568. gen7_draw_common_pcb_alloc(render, vec, session);
  569. gen6_draw_common_base_address(render, vec, session);
  570. gen7_draw_common_pointers_1(render, vec, session);
  571. gen7_draw_common_urb(render, vec, session);
  572. gen7_draw_common_pointers_2(render, vec, session);
  573. gen7_draw_wm_multisample(render, vec, session);
  574. gen7_draw_gs(render, vec, session);
  575. gen7_draw_hs(render, vec, session);
  576. gen7_draw_te(render, vec, session);
  577. gen7_draw_ds(render, vec, session);
  578. gen7_draw_vs(render, vec, session);
  579. gen7_draw_sol(render, vec, session);
  580. gen6_draw_clip(render, vec, session);
  581. gen7_draw_sf(render, vec, session);
  582. gen7_draw_wm(render, vec, session);
  583. gen6_draw_wm_raster(render, vec, session);
  584. gen6_draw_sf_rect(render, vec, session);
  585. gen6_draw_vf(render, vec, session);
  586. gen7_draw_vf_draw(render, vec, session);
  587. }
  588. static void
  589. ilo_render_emit_draw_gen7(struct ilo_render *render,
  590. const struct ilo_state_vector *vec)
  591. {
  592. struct gen6_draw_session session;
  593. gen6_draw_prepare(render, vec, &session);
  594. session.emit_draw_commands = gen7_draw_commands;
  595. gen6_draw_emit(render, vec, &session);
  596. gen6_draw_end(render, vec, &session);
  597. }
  598. static void
  599. gen7_rectlist_pcb_alloc(struct ilo_render *r,
  600. const struct ilo_blitter *blitter)
  601. {
  602. /*
  603. * Push constant buffers are only allowed to take up at most the first
  604. * 16KB of the URB. Split the space evenly for VS and FS.
  605. */
  606. const int max_size =
  607. (ilo_dev_gen(r->dev) == ILO_GEN(7.5) && r->dev->gt == 3) ? 32768 : 16384;
  608. const int size = max_size / 2;
  609. int offset = 0;
  610. gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r->builder, offset, size);
  611. offset += size;
  612. gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r->builder, offset, size);
  613. gen7_wa_post_3dstate_push_constant_alloc_ps(r);
  614. }
  615. static void
  616. gen7_rectlist_urb(struct ilo_render *r,
  617. const struct ilo_blitter *blitter)
  618. {
  619. /* the first 16KB are reserved for VS and PS PCBs */
  620. const int offset =
  621. (ilo_dev_gen(r->dev) == ILO_GEN(7.5) && r->dev->gt == 3) ? 32768 : 16384;
  622. gen7_3DSTATE_URB_VS(r->builder, offset, r->dev->urb_size - offset,
  623. blitter->ve.count * 4 * sizeof(float));
  624. gen7_3DSTATE_URB_GS(r->builder, offset, 0, 0);
  625. gen7_3DSTATE_URB_HS(r->builder, offset, 0, 0);
  626. gen7_3DSTATE_URB_DS(r->builder, offset, 0, 0);
  627. }
  628. static void
  629. gen7_rectlist_vs_to_sf(struct ilo_render *r,
  630. const struct ilo_blitter *blitter)
  631. {
  632. gen7_3DSTATE_CONSTANT_VS(r->builder, NULL, NULL, 0);
  633. gen6_3DSTATE_VS(r->builder, NULL, 0);
  634. gen7_3DSTATE_CONSTANT_HS(r->builder, NULL, NULL, 0);
  635. gen7_3DSTATE_HS(r->builder, NULL, 0);
  636. gen7_3DSTATE_TE(r->builder);
  637. gen7_3DSTATE_CONSTANT_DS(r->builder, NULL, NULL, 0);
  638. gen7_3DSTATE_DS(r->builder, NULL, 0);
  639. gen7_3DSTATE_CONSTANT_GS(r->builder, NULL, NULL, 0);
  640. gen7_3DSTATE_GS(r->builder, NULL, 0);
  641. gen7_3DSTATE_STREAMOUT(r->builder, 0x0, 0, false);
  642. gen6_3DSTATE_CLIP(r->builder, NULL, NULL, false, 0);
  643. gen7_wa_pre_3dstate_sf_depth_bias(r);
  644. gen7_3DSTATE_SF(r->builder, NULL, blitter->fb.dst.base.format);
  645. gen7_3DSTATE_SBE(r->builder, NULL, NULL);
  646. }
  647. static void
  648. gen7_rectlist_wm(struct ilo_render *r,
  649. const struct ilo_blitter *blitter)
  650. {
  651. uint32_t hiz_op;
  652. switch (blitter->op) {
  653. case ILO_BLITTER_RECTLIST_CLEAR_ZS:
  654. hiz_op = GEN7_WM_DW1_DEPTH_CLEAR;
  655. break;
  656. case ILO_BLITTER_RECTLIST_RESOLVE_Z:
  657. hiz_op = GEN7_WM_DW1_DEPTH_RESOLVE;
  658. break;
  659. case ILO_BLITTER_RECTLIST_RESOLVE_HIZ:
  660. hiz_op = GEN7_WM_DW1_HIZ_RESOLVE;
  661. break;
  662. default:
  663. hiz_op = 0;
  664. break;
  665. }
  666. gen7_3DSTATE_WM(r->builder, NULL, NULL, false, hiz_op);
  667. gen7_3DSTATE_CONSTANT_PS(r->builder, NULL, NULL, 0);
  668. gen7_wa_pre_3dstate_ps_max_threads(r);
  669. gen7_3DSTATE_PS(r->builder, NULL, 0, false);
  670. }
  671. static void
  672. gen7_rectlist_wm_depth(struct ilo_render *r,
  673. const struct ilo_blitter *blitter)
  674. {
  675. gen7_wa_pre_depth(r);
  676. if (blitter->uses & (ILO_BLITTER_USE_FB_DEPTH |
  677. ILO_BLITTER_USE_FB_STENCIL)) {
  678. gen6_3DSTATE_DEPTH_BUFFER(r->builder,
  679. &blitter->fb.dst.u.zs);
  680. }
  681. if (blitter->uses & ILO_BLITTER_USE_FB_DEPTH) {
  682. gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder,
  683. &blitter->fb.dst.u.zs);
  684. }
  685. if (blitter->uses & ILO_BLITTER_USE_FB_STENCIL) {
  686. gen6_3DSTATE_STENCIL_BUFFER(r->builder,
  687. &blitter->fb.dst.u.zs);
  688. }
  689. gen7_3DSTATE_CLEAR_PARAMS(r->builder,
  690. blitter->depth_clear_value);
  691. }
  692. static void
  693. gen7_rectlist_wm_multisample(struct ilo_render *r,
  694. const struct ilo_blitter *blitter)
  695. {
  696. const uint32_t *packed_sample_pos =
  697. (blitter->fb.num_samples > 4) ? r->packed_sample_position_8x :
  698. (blitter->fb.num_samples > 1) ? &r->packed_sample_position_4x :
  699. &r->packed_sample_position_1x;
  700. gen7_wa_pre_3dstate_multisample(r);
  701. gen6_3DSTATE_MULTISAMPLE(r->builder, blitter->fb.num_samples,
  702. packed_sample_pos, true);
  703. gen7_3DSTATE_SAMPLE_MASK(r->builder,
  704. (1 << blitter->fb.num_samples) - 1, blitter->fb.num_samples);
  705. }
  706. void
  707. ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
  708. const struct ilo_blitter *blitter)
  709. {
  710. ILO_DEV_ASSERT(r->dev, 7, 7.5);
  711. gen7_rectlist_wm_multisample(r, blitter);
  712. gen6_state_base_address(r->builder, true);
  713. gen6_3DSTATE_VERTEX_BUFFERS(r->builder,
  714. &blitter->ve, &blitter->vb);
  715. gen6_3DSTATE_VERTEX_ELEMENTS(r->builder,
  716. &blitter->ve, false, false);
  717. gen7_rectlist_pcb_alloc(r, blitter);
  718. /* needed for any VS-related commands */
  719. gen7_wa_pre_vs(r);
  720. gen7_rectlist_urb(r, blitter);
  721. if (blitter->uses & ILO_BLITTER_USE_DSA) {
  722. gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r->builder,
  723. r->state.DEPTH_STENCIL_STATE);
  724. }
  725. if (blitter->uses & ILO_BLITTER_USE_CC) {
  726. gen7_3DSTATE_CC_STATE_POINTERS(r->builder,
  727. r->state.COLOR_CALC_STATE);
  728. }
  729. gen7_rectlist_vs_to_sf(r, blitter);
  730. gen7_rectlist_wm(r, blitter);
  731. if (blitter->uses & ILO_BLITTER_USE_VIEWPORT) {
  732. gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r->builder,
  733. r->state.CC_VIEWPORT);
  734. }
  735. gen7_rectlist_wm_depth(r, blitter);
  736. gen6_3DSTATE_DRAWING_RECTANGLE(r->builder, 0, 0,
  737. blitter->fb.width, blitter->fb.height);
  738. gen7_3DPRIMITIVE(r->builder, &blitter->draw, NULL);
  739. }
  740. static int
  741. gen7_render_max_command_size(const struct ilo_render *render)
  742. {
  743. static int size;
  744. if (!size) {
  745. size += GEN7_3DSTATE_URB_ANY__SIZE * 4;
  746. size += GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE * 5;
  747. size += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 5;
  748. size += GEN7_3DSTATE_POINTERS_ANY__SIZE * (5 + 5 + 4);
  749. size += GEN7_3DSTATE_SO_BUFFER__SIZE * 4;
  750. size += GEN6_PIPE_CONTROL__SIZE * 5;
  751. size +=
  752. GEN6_STATE_BASE_ADDRESS__SIZE +
  753. GEN6_STATE_SIP__SIZE +
  754. GEN6_3DSTATE_VF_STATISTICS__SIZE +
  755. GEN6_PIPELINE_SELECT__SIZE +
  756. GEN6_3DSTATE_CLEAR_PARAMS__SIZE +
  757. GEN6_3DSTATE_DEPTH_BUFFER__SIZE +
  758. GEN6_3DSTATE_STENCIL_BUFFER__SIZE +
  759. GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE +
  760. GEN6_3DSTATE_VERTEX_BUFFERS__SIZE +
  761. GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE +
  762. GEN6_3DSTATE_INDEX_BUFFER__SIZE +
  763. GEN75_3DSTATE_VF__SIZE +
  764. GEN6_3DSTATE_VS__SIZE +
  765. GEN6_3DSTATE_GS__SIZE +
  766. GEN6_3DSTATE_CLIP__SIZE +
  767. GEN6_3DSTATE_SF__SIZE +
  768. GEN6_3DSTATE_WM__SIZE +
  769. GEN6_3DSTATE_SAMPLE_MASK__SIZE +
  770. GEN7_3DSTATE_HS__SIZE +
  771. GEN7_3DSTATE_TE__SIZE +
  772. GEN7_3DSTATE_DS__SIZE +
  773. GEN7_3DSTATE_STREAMOUT__SIZE +
  774. GEN7_3DSTATE_SBE__SIZE +
  775. GEN7_3DSTATE_PS__SIZE +
  776. GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE +
  777. GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE +
  778. GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE +
  779. GEN6_3DSTATE_LINE_STIPPLE__SIZE +
  780. GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE +
  781. GEN6_3DSTATE_MULTISAMPLE__SIZE +
  782. GEN7_3DSTATE_SO_DECL_LIST__SIZE +
  783. GEN6_3DPRIMITIVE__SIZE;
  784. }
  785. return size;
  786. }
  787. static int
  788. ilo_render_estimate_size_gen7(struct ilo_render *render,
  789. enum ilo_render_action action,
  790. const void *arg)
  791. {
  792. int size;
  793. switch (action) {
  794. case ILO_RENDER_DRAW:
  795. {
  796. const struct ilo_state_vector *vec = arg;
  797. size = gen7_render_max_command_size(render) +
  798. ilo_render_get_draw_dynamic_states_len(render, vec) +
  799. ilo_render_get_draw_surface_states_len(render, vec);
  800. }
  801. break;
  802. default:
  803. assert(!"unknown render action");
  804. size = 0;
  805. break;
  806. }
  807. return size;
  808. }
  809. void
  810. ilo_render_init_gen7(struct ilo_render *render)
  811. {
  812. render->estimate_size = ilo_render_estimate_size_gen7;
  813. render->emit_draw = ilo_render_emit_draw_gen7;
  814. }