Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

freedreno_state.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
  2. /*
  3. * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Authors:
  25. * Rob Clark <robclark@freedesktop.org>
  26. */
  27. #include "pipe/p_state.h"
  28. #include "util/u_string.h"
  29. #include "util/u_memory.h"
  30. #include "util/u_helpers.h"
  31. #include "freedreno_state.h"
  32. #include "freedreno_context.h"
  33. #include "freedreno_zsa.h"
  34. #include "freedreno_rasterizer.h"
  35. #include "freedreno_blend.h"
  36. #include "freedreno_program.h"
  37. #include "freedreno_resource.h"
  38. #include "freedreno_texture.h"
  39. #include "freedreno_gmem.h"
  40. #include "freedreno_util.h"
  41. static void
  42. fd_set_blend_color(struct pipe_context *pctx,
  43. const struct pipe_blend_color *blend_color)
  44. {
  45. struct fd_context *ctx = fd_context(pctx);
  46. ctx->blend_color = *blend_color;
  47. ctx->dirty |= FD_DIRTY_BLEND_COLOR;
  48. }
  49. static void
  50. fd_set_stencil_ref(struct pipe_context *pctx,
  51. const struct pipe_stencil_ref *stencil_ref)
  52. {
  53. struct fd_context *ctx = fd_context(pctx);
  54. ctx->stencil_ref =* stencil_ref;
  55. ctx->dirty |= FD_DIRTY_STENCIL_REF;
  56. }
  57. static void
  58. fd_set_clip_state(struct pipe_context *pctx,
  59. const struct pipe_clip_state *clip)
  60. {
  61. DBG("TODO: ");
  62. }
  63. static void
  64. fd_set_sample_mask(struct pipe_context *pctx, unsigned sample_mask)
  65. {
  66. struct fd_context *ctx = fd_context(pctx);
  67. ctx->sample_mask = (uint16_t)sample_mask;
  68. ctx->dirty |= FD_DIRTY_SAMPLE_MASK;
  69. }
  70. /* notes from calim on #dri-devel:
  71. * index==0 will be non-UBO (ie. glUniformXYZ()) all packed together padded
  72. * out to vec4's
  73. * I should be able to consider that I own the user_ptr until the next
  74. * set_constant_buffer() call, at which point I don't really care about the
  75. * previous values.
  76. * index>0 will be UBO's.. well, I'll worry about that later
  77. */
  78. static void
  79. fd_set_constant_buffer(struct pipe_context *pctx, uint shader, uint index,
  80. struct pipe_constant_buffer *cb)
  81. {
  82. struct fd_context *ctx = fd_context(pctx);
  83. struct fd_constbuf_stateobj *so = &ctx->constbuf[shader];
  84. /* Note that the state tracker can unbind constant buffers by
  85. * passing NULL here.
  86. */
  87. if (unlikely(!cb)) {
  88. so->enabled_mask &= ~(1 << index);
  89. so->dirty_mask &= ~(1 << index);
  90. pipe_resource_reference(&so->cb[index].buffer, NULL);
  91. return;
  92. }
  93. pipe_resource_reference(&so->cb[index].buffer, cb->buffer);
  94. so->cb[index].buffer_offset = cb->buffer_offset;
  95. so->cb[index].buffer_size = cb->buffer_size;
  96. so->cb[index].user_buffer = cb->user_buffer;
  97. so->enabled_mask |= 1 << index;
  98. so->dirty_mask |= 1 << index;
  99. ctx->dirty |= FD_DIRTY_CONSTBUF;
  100. }
  101. static void
  102. fd_set_framebuffer_state(struct pipe_context *pctx,
  103. const struct pipe_framebuffer_state *framebuffer)
  104. {
  105. struct fd_context *ctx = fd_context(pctx);
  106. struct pipe_framebuffer_state *cso = &ctx->framebuffer;
  107. unsigned i;
  108. DBG("%d: cbufs[0]=%p, zsbuf=%p", ctx->needs_flush,
  109. cso->cbufs[0], cso->zsbuf);
  110. fd_context_render(pctx);
  111. for (i = 0; i < framebuffer->nr_cbufs; i++)
  112. pipe_surface_reference(&cso->cbufs[i], framebuffer->cbufs[i]);
  113. for (; i < ctx->framebuffer.nr_cbufs; i++)
  114. pipe_surface_reference(&cso->cbufs[i], NULL);
  115. cso->nr_cbufs = framebuffer->nr_cbufs;
  116. cso->width = framebuffer->width;
  117. cso->height = framebuffer->height;
  118. pipe_surface_reference(&cso->zsbuf, framebuffer->zsbuf);
  119. ctx->dirty |= FD_DIRTY_FRAMEBUFFER;
  120. /* also need to reset the scissor.. mesa/gl state tracker
  121. * does this for us, but u_blitter doesn't and other
  122. * state trackers might not..
  123. */
  124. ctx->scissor.minx = 0;
  125. ctx->scissor.miny = 0;
  126. ctx->scissor.maxx = cso->width;
  127. ctx->scissor.maxy = cso->height;
  128. ctx->dirty |= FD_DIRTY_SCISSOR;
  129. }
  130. static void
  131. fd_set_polygon_stipple(struct pipe_context *pctx,
  132. const struct pipe_poly_stipple *stipple)
  133. {
  134. struct fd_context *ctx = fd_context(pctx);
  135. ctx->stipple = *stipple;
  136. ctx->dirty |= FD_DIRTY_STIPPLE;
  137. }
  138. static void
  139. fd_set_scissor_states(struct pipe_context *pctx,
  140. unsigned start_slot,
  141. unsigned num_scissors,
  142. const struct pipe_scissor_state *scissor)
  143. {
  144. struct fd_context *ctx = fd_context(pctx);
  145. ctx->scissor = *scissor;
  146. ctx->dirty |= FD_DIRTY_SCISSOR;
  147. }
  148. static void
  149. fd_set_viewport_states(struct pipe_context *pctx,
  150. unsigned start_slot,
  151. unsigned num_viewports,
  152. const struct pipe_viewport_state *viewport)
  153. {
  154. struct fd_context *ctx = fd_context(pctx);
  155. ctx->viewport = *viewport;
  156. ctx->dirty |= FD_DIRTY_VIEWPORT;
  157. }
  158. static void
  159. fd_set_vertex_buffers(struct pipe_context *pctx,
  160. unsigned start_slot, unsigned count,
  161. const struct pipe_vertex_buffer *vb)
  162. {
  163. struct fd_context *ctx = fd_context(pctx);
  164. struct fd_vertexbuf_stateobj *so = &ctx->vertexbuf;
  165. int i;
  166. /* on a2xx, pitch is encoded in the vtx fetch instruction, so
  167. * we need to mark VTXSTATE as dirty as well to trigger patching
  168. * and re-emitting the vtx shader:
  169. */
  170. for (i = 0; i < count; i++) {
  171. bool new_enabled = vb && (vb[i].buffer || vb[i].user_buffer);
  172. bool old_enabled = so->vb[i].buffer || so->vb[i].user_buffer;
  173. uint32_t new_stride = vb ? vb[i].stride : 0;
  174. uint32_t old_stride = so->vb[i].stride;
  175. if ((new_enabled != old_enabled) || (new_stride != old_stride)) {
  176. ctx->dirty |= FD_DIRTY_VTXSTATE;
  177. break;
  178. }
  179. }
  180. util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, start_slot, count);
  181. so->count = util_last_bit(so->enabled_mask);
  182. ctx->dirty |= FD_DIRTY_VTXBUF;
  183. }
  184. static void
  185. fd_set_index_buffer(struct pipe_context *pctx,
  186. const struct pipe_index_buffer *ib)
  187. {
  188. struct fd_context *ctx = fd_context(pctx);
  189. if (ib) {
  190. pipe_resource_reference(&ctx->indexbuf.buffer, ib->buffer);
  191. ctx->indexbuf.index_size = ib->index_size;
  192. ctx->indexbuf.offset = ib->offset;
  193. ctx->indexbuf.user_buffer = ib->user_buffer;
  194. } else {
  195. pipe_resource_reference(&ctx->indexbuf.buffer, NULL);
  196. }
  197. ctx->dirty |= FD_DIRTY_INDEXBUF;
  198. }
  199. void
  200. fd_state_init(struct pipe_context *pctx)
  201. {
  202. pctx->set_blend_color = fd_set_blend_color;
  203. pctx->set_stencil_ref = fd_set_stencil_ref;
  204. pctx->set_clip_state = fd_set_clip_state;
  205. pctx->set_sample_mask = fd_set_sample_mask;
  206. pctx->set_constant_buffer = fd_set_constant_buffer;
  207. pctx->set_framebuffer_state = fd_set_framebuffer_state;
  208. pctx->set_polygon_stipple = fd_set_polygon_stipple;
  209. pctx->set_scissor_states = fd_set_scissor_states;
  210. pctx->set_viewport_states = fd_set_viewport_states;
  211. pctx->set_vertex_buffers = fd_set_vertex_buffers;
  212. pctx->set_index_buffer = fd_set_index_buffer;
  213. }
  214. /* NOTE: just define the position for const regs statically.. the blob
  215. * driver doesn't seem to change these dynamically, and I can't really
  216. * think of a good reason to so..
  217. */
  218. #define VS_CONST_BASE 0x20
  219. #define PS_CONST_BASE 0x120
  220. static void
  221. emit_constants(struct fd_ringbuffer *ring, uint32_t base,
  222. struct fd_constbuf_stateobj *constbuf,
  223. struct fd_shader_stateobj *shader)
  224. {
  225. uint32_t enabled_mask = constbuf->enabled_mask;
  226. uint32_t start_base = base;
  227. unsigned i;
  228. // XXX TODO only emit dirty consts.. but we need to keep track if
  229. // they are clobbered by a clear, gmem2mem, or mem2gmem..
  230. constbuf->dirty_mask = enabled_mask;
  231. /* emit user constants: */
  232. while (enabled_mask) {
  233. unsigned index = ffs(enabled_mask) - 1;
  234. struct pipe_constant_buffer *cb = &constbuf->cb[index];
  235. unsigned size = align(cb->buffer_size, 4) / 4; /* size in dwords */
  236. // I expect that size should be a multiple of vec4's:
  237. assert(size == align(size, 4));
  238. /* hmm, sometimes we still seem to end up with consts bound,
  239. * even if shader isn't using them, which ends up overwriting
  240. * const reg's used for immediates.. this is a hack to work
  241. * around that:
  242. */
  243. if (shader && ((base - start_base) >= (shader->first_immediate * 4)))
  244. break;
  245. if (constbuf->dirty_mask & (1 << index)) {
  246. const uint32_t *dwords;
  247. if (cb->user_buffer) {
  248. dwords = cb->user_buffer;
  249. } else {
  250. struct fd_resource *rsc = fd_resource(cb->buffer);
  251. dwords = fd_bo_map(rsc->bo);
  252. }
  253. dwords = (uint32_t *)(((uint8_t *)dwords) + cb->buffer_offset);
  254. OUT_PKT3(ring, CP_SET_CONSTANT, size + 1);
  255. OUT_RING(ring, base);
  256. for (i = 0; i < size; i++)
  257. OUT_RING(ring, *(dwords++));
  258. constbuf->dirty_mask &= ~(1 << index);
  259. }
  260. base += size;
  261. enabled_mask &= ~(1 << index);
  262. }
  263. /* emit shader immediates: */
  264. if (shader) {
  265. for (i = 0; i < shader->num_immediates; i++) {
  266. OUT_PKT3(ring, CP_SET_CONSTANT, 5);
  267. OUT_RING(ring, start_base + (4 * (shader->first_immediate + i)));
  268. OUT_RING(ring, shader->immediates[i].val[0]);
  269. OUT_RING(ring, shader->immediates[i].val[1]);
  270. OUT_RING(ring, shader->immediates[i].val[2]);
  271. OUT_RING(ring, shader->immediates[i].val[3]);
  272. base += 4;
  273. }
  274. }
  275. }
  276. /* this works at least for a220 and earlier.. if later gpu's gain more than
  277. * 32 texture units, might need to bump this up to uint64_t
  278. */
  279. typedef uint32_t texmask;
  280. static texmask
  281. emit_texture(struct fd_ringbuffer *ring, struct fd_context *ctx,
  282. struct fd_texture_stateobj *tex, unsigned samp_id, texmask emitted)
  283. {
  284. unsigned const_idx = fd_get_const_idx(ctx, tex, samp_id);
  285. struct fd_sampler_stateobj *sampler;
  286. struct fd_pipe_sampler_view *view;
  287. if (emitted & (1 << const_idx))
  288. return 0;
  289. sampler = tex->samplers[samp_id];
  290. view = fd_pipe_sampler_view(tex->textures[samp_id]);
  291. OUT_PKT3(ring, CP_SET_CONSTANT, 7);
  292. OUT_RING(ring, 0x00010000 + (0x6 * const_idx));
  293. OUT_RING(ring, sampler->tex0 | view->tex0);
  294. OUT_RELOC(ring, view->tex_resource->bo, 0, view->fmt);
  295. OUT_RING(ring, view->tex2);
  296. OUT_RING(ring, sampler->tex3 | view->tex3);
  297. OUT_RING(ring, sampler->tex4);
  298. OUT_RING(ring, sampler->tex5);
  299. return (1 << const_idx);
  300. }
  301. static void
  302. emit_textures(struct fd_ringbuffer *ring, struct fd_context *ctx)
  303. {
  304. texmask emitted = 0;
  305. unsigned i;
  306. for (i = 0; i < ctx->verttex.num_samplers; i++)
  307. if (ctx->verttex.samplers[i])
  308. emitted |= emit_texture(ring, ctx, &ctx->verttex, i, emitted);
  309. for (i = 0; i < ctx->fragtex.num_samplers; i++)
  310. if (ctx->fragtex.samplers[i])
  311. emitted |= emit_texture(ring, ctx, &ctx->fragtex, i, emitted);
  312. }
  313. void
  314. fd_emit_vertex_bufs(struct fd_ringbuffer *ring, uint32_t val,
  315. struct fd_vertex_buf *vbufs, uint32_t n)
  316. {
  317. unsigned i;
  318. OUT_PKT3(ring, CP_SET_CONSTANT, 1 + (2 * n));
  319. OUT_RING(ring, (0x1 << 16) | (val & 0xffff));
  320. for (i = 0; i < n; i++) {
  321. struct fd_resource *rsc = fd_resource(vbufs[i].prsc);
  322. OUT_RELOC(ring, rsc->bo, vbufs[i].offset, 3);
  323. OUT_RING (ring, vbufs[i].size);
  324. }
  325. }
  326. void
  327. fd_state_emit(struct pipe_context *pctx, uint32_t dirty)
  328. {
  329. struct fd_context *ctx = fd_context(pctx);
  330. struct fd_ringbuffer *ring = ctx->ring;
  331. /* NOTE: we probably want to eventually refactor this so each state
  332. * object handles emitting it's own state.. although the mapping of
  333. * state to registers is not always orthogonal, sometimes a single
  334. * register contains bitfields coming from multiple state objects,
  335. * so not sure the best way to deal with that yet.
  336. */
  337. if (dirty & FD_DIRTY_SAMPLE_MASK) {
  338. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  339. OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_MASK));
  340. OUT_RING(ring, ctx->sample_mask);
  341. }
  342. if (dirty & FD_DIRTY_ZSA) {
  343. struct pipe_stencil_ref *sr = &ctx->stencil_ref;
  344. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  345. OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTHCONTROL));
  346. OUT_RING(ring, ctx->zsa->rb_depthcontrol);
  347. OUT_PKT3(ring, CP_SET_CONSTANT, 4);
  348. OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF));
  349. OUT_RING(ring, ctx->zsa->rb_stencilrefmask_bf |
  350. A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[1]));
  351. OUT_RING(ring, ctx->zsa->rb_stencilrefmask |
  352. A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
  353. OUT_RING(ring, ctx->zsa->rb_alpha_ref);
  354. }
  355. if (dirty & (FD_DIRTY_RASTERIZER | FD_DIRTY_FRAMEBUFFER)) {
  356. OUT_PKT3(ring, CP_SET_CONSTANT, 3);
  357. OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_CLIP_CNTL));
  358. OUT_RING(ring, ctx->rasterizer->pa_cl_clip_cntl);
  359. OUT_RING(ring, ctx->rasterizer->pa_su_sc_mode_cntl |
  360. A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE);
  361. OUT_PKT3(ring, CP_SET_CONSTANT, 5);
  362. OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_POINT_SIZE));
  363. OUT_RING(ring, ctx->rasterizer->pa_su_point_size);
  364. OUT_RING(ring, ctx->rasterizer->pa_su_point_minmax);
  365. OUT_RING(ring, ctx->rasterizer->pa_su_line_cntl);
  366. OUT_RING(ring, ctx->rasterizer->pa_sc_line_stipple);
  367. OUT_PKT3(ring, CP_SET_CONSTANT, 6);
  368. OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_VTX_CNTL));
  369. OUT_RING(ring, ctx->rasterizer->pa_su_vtx_cntl);
  370. OUT_RING(ring, fui(1.0)); /* PA_CL_GB_VERT_CLIP_ADJ */
  371. OUT_RING(ring, fui(1.0)); /* PA_CL_GB_VERT_DISC_ADJ */
  372. OUT_RING(ring, fui(1.0)); /* PA_CL_GB_HORZ_CLIP_ADJ */
  373. OUT_RING(ring, fui(1.0)); /* PA_CL_GB_HORZ_DISC_ADJ */
  374. }
  375. if (dirty & FD_DIRTY_SCISSOR) {
  376. OUT_PKT3(ring, CP_SET_CONSTANT, 3);
  377. OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_SCISSOR_TL));
  378. OUT_RING(ring, xy2d(ctx->scissor.minx, /* PA_SC_WINDOW_SCISSOR_TL */
  379. ctx->scissor.miny));
  380. OUT_RING(ring, xy2d(ctx->scissor.maxx, /* PA_SC_WINDOW_SCISSOR_BR */
  381. ctx->scissor.maxy));
  382. ctx->max_scissor.minx = MIN2(ctx->max_scissor.minx, ctx->scissor.minx);
  383. ctx->max_scissor.miny = MIN2(ctx->max_scissor.miny, ctx->scissor.miny);
  384. ctx->max_scissor.maxx = MAX2(ctx->max_scissor.maxx, ctx->scissor.maxx);
  385. ctx->max_scissor.maxy = MAX2(ctx->max_scissor.maxy, ctx->scissor.maxy);
  386. }
  387. if (dirty & FD_DIRTY_VIEWPORT) {
  388. OUT_PKT3(ring, CP_SET_CONSTANT, 7);
  389. OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_XSCALE));
  390. OUT_RING(ring, fui(ctx->viewport.scale[0])); /* PA_CL_VPORT_XSCALE */
  391. OUT_RING(ring, fui(ctx->viewport.translate[0])); /* PA_CL_VPORT_XOFFSET */
  392. OUT_RING(ring, fui(ctx->viewport.scale[1])); /* PA_CL_VPORT_YSCALE */
  393. OUT_RING(ring, fui(ctx->viewport.translate[1])); /* PA_CL_VPORT_YOFFSET */
  394. OUT_RING(ring, fui(ctx->viewport.scale[2])); /* PA_CL_VPORT_ZSCALE */
  395. OUT_RING(ring, fui(ctx->viewport.translate[2])); /* PA_CL_VPORT_ZOFFSET */
  396. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  397. OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VTE_CNTL));
  398. OUT_RING(ring, A2XX_PA_CL_VTE_CNTL_VTX_W0_FMT |
  399. A2XX_PA_CL_VTE_CNTL_VPORT_X_SCALE_ENA |
  400. A2XX_PA_CL_VTE_CNTL_VPORT_X_OFFSET_ENA |
  401. A2XX_PA_CL_VTE_CNTL_VPORT_Y_SCALE_ENA |
  402. A2XX_PA_CL_VTE_CNTL_VPORT_Y_OFFSET_ENA |
  403. A2XX_PA_CL_VTE_CNTL_VPORT_Z_SCALE_ENA |
  404. A2XX_PA_CL_VTE_CNTL_VPORT_Z_OFFSET_ENA);
  405. }
  406. if (dirty & (FD_DIRTY_PROG | FD_DIRTY_VTXSTATE | FD_DIRTY_TEXSTATE)) {
  407. fd_program_validate(ctx);
  408. fd_program_emit(ring, &ctx->prog);
  409. }
  410. if (dirty & (FD_DIRTY_PROG | FD_DIRTY_CONSTBUF)) {
  411. emit_constants(ring, VS_CONST_BASE * 4,
  412. &ctx->constbuf[PIPE_SHADER_VERTEX],
  413. (dirty & FD_DIRTY_PROG) ? ctx->prog.vp : NULL);
  414. emit_constants(ring, PS_CONST_BASE * 4,
  415. &ctx->constbuf[PIPE_SHADER_FRAGMENT],
  416. (dirty & FD_DIRTY_PROG) ? ctx->prog.fp : NULL);
  417. }
  418. if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_ZSA)) {
  419. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  420. OUT_RING(ring, CP_REG(REG_A2XX_RB_COLORCONTROL));
  421. OUT_RING(ring, ctx->zsa->rb_colorcontrol | ctx->blend->rb_colorcontrol);
  422. }
  423. if (dirty & FD_DIRTY_BLEND) {
  424. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  425. OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_CONTROL));
  426. OUT_RING(ring, ctx->blend->rb_blendcontrol);
  427. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  428. OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
  429. OUT_RING(ring, ctx->blend->rb_colormask);
  430. }
  431. if (dirty & (FD_DIRTY_VERTTEX | FD_DIRTY_FRAGTEX | FD_DIRTY_PROG))
  432. emit_textures(ring, ctx);
  433. ctx->dirty &= ~dirty;
  434. }
  435. /* emit per-context initialization:
  436. */
  437. void
  438. fd_state_emit_setup(struct pipe_context *pctx)
  439. {
  440. struct fd_context *ctx = fd_context(pctx);
  441. struct fd_ringbuffer *ring = ctx->ring;
  442. OUT_PKT0(ring, REG_A2XX_TP0_CHICKEN, 1);
  443. OUT_RING(ring, 0x00000002);
  444. OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
  445. OUT_RING(ring, 0x00007fff);
  446. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  447. OUT_RING(ring, CP_REG(REG_A2XX_SQ_VS_CONST));
  448. OUT_RING(ring, A2XX_SQ_VS_CONST_BASE(VS_CONST_BASE) |
  449. A2XX_SQ_VS_CONST_SIZE(0x100));
  450. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  451. OUT_RING(ring, CP_REG(REG_A2XX_SQ_PS_CONST));
  452. OUT_RING(ring, A2XX_SQ_PS_CONST_BASE(PS_CONST_BASE) |
  453. A2XX_SQ_PS_CONST_SIZE(0xe0));
  454. OUT_PKT3(ring, CP_SET_CONSTANT, 3);
  455. OUT_RING(ring, CP_REG(REG_A2XX_VGT_MAX_VTX_INDX));
  456. OUT_RING(ring, 0xffffffff); /* VGT_MAX_VTX_INDX */
  457. OUT_RING(ring, 0x00000000); /* VGT_MIN_VTX_INDX */
  458. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  459. OUT_RING(ring, CP_REG(REG_A2XX_VGT_INDX_OFFSET));
  460. OUT_RING(ring, 0x00000000);
  461. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  462. OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL));
  463. OUT_RING(ring, 0x0000003b);
  464. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  465. OUT_RING(ring, CP_REG(REG_A2XX_SQ_CONTEXT_MISC));
  466. OUT_RING(ring, A2XX_SQ_CONTEXT_MISC_SC_SAMPLE_CNTL(CENTERS_ONLY));
  467. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  468. OUT_RING(ring, CP_REG(REG_A2XX_SQ_INTERPOLATOR_CNTL));
  469. OUT_RING(ring, 0xffffffff);
  470. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  471. OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_CONFIG));
  472. OUT_RING(ring, 0x00000000);
  473. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  474. OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_LINE_CNTL));
  475. OUT_RING(ring, 0x00000000);
  476. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  477. OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_OFFSET));
  478. OUT_RING(ring, 0x00000000);
  479. // XXX we change this dynamically for draw/clear.. vs gmem<->mem..
  480. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  481. OUT_RING(ring, CP_REG(REG_A2XX_RB_MODECONTROL));
  482. OUT_RING(ring, A2XX_RB_MODECONTROL_EDRAM_MODE(COLOR_DEPTH));
  483. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  484. OUT_RING(ring, CP_REG(REG_A2XX_RB_SAMPLE_POS));
  485. OUT_RING(ring, 0x88888888);
  486. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  487. OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_DEST_MASK));
  488. OUT_RING(ring, 0xffffffff);
  489. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  490. OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_DEST_INFO));
  491. OUT_RING(ring, A2XX_RB_COPY_DEST_INFO_FORMAT(COLORX_4_4_4_4) |
  492. A2XX_RB_COPY_DEST_INFO_WRITE_RED |
  493. A2XX_RB_COPY_DEST_INFO_WRITE_GREEN |
  494. A2XX_RB_COPY_DEST_INFO_WRITE_BLUE |
  495. A2XX_RB_COPY_DEST_INFO_WRITE_ALPHA);
  496. OUT_PKT3(ring, CP_SET_CONSTANT, 3);
  497. OUT_RING(ring, CP_REG(REG_A2XX_SQ_WRAPPING_0));
  498. OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_0 */
  499. OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_1 */
  500. OUT_PKT3(ring, CP_SET_DRAW_INIT_FLAGS, 1);
  501. OUT_RING(ring, 0x00000000);
  502. OUT_PKT3(ring, CP_WAIT_REG_EQ, 4);
  503. OUT_RING(ring, 0x000005d0);
  504. OUT_RING(ring, 0x00000000);
  505. OUT_RING(ring, 0x5f601000);
  506. OUT_RING(ring, 0x00000001);
  507. OUT_PKT0(ring, REG_A2XX_SQ_INST_STORE_MANAGMENT, 1);
  508. OUT_RING(ring, 0x00000180);
  509. OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
  510. OUT_RING(ring, 0x00000300);
  511. OUT_PKT3(ring, CP_SET_SHADER_BASES, 1);
  512. OUT_RING(ring, 0x80000180);
  513. /* not sure what this form of CP_SET_CONSTANT is.. */
  514. OUT_PKT3(ring, CP_SET_CONSTANT, 13);
  515. OUT_RING(ring, 0x00000000);
  516. OUT_RING(ring, 0x00000000);
  517. OUT_RING(ring, 0x00000000);
  518. OUT_RING(ring, 0x00000000);
  519. OUT_RING(ring, 0x00000000);
  520. OUT_RING(ring, 0x469c4000);
  521. OUT_RING(ring, 0x3f800000);
  522. OUT_RING(ring, 0x3f000000);
  523. OUT_RING(ring, 0x00000000);
  524. OUT_RING(ring, 0x40000000);
  525. OUT_RING(ring, 0x3f400000);
  526. OUT_RING(ring, 0x3ec00000);
  527. OUT_RING(ring, 0x3e800000);
  528. OUT_PKT3(ring, CP_SET_CONSTANT, 2);
  529. OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
  530. OUT_RING(ring, A2XX_RB_COLOR_MASK_WRITE_RED |
  531. A2XX_RB_COLOR_MASK_WRITE_GREEN |
  532. A2XX_RB_COLOR_MASK_WRITE_BLUE |
  533. A2XX_RB_COLOR_MASK_WRITE_ALPHA);
  534. OUT_PKT3(ring, CP_SET_CONSTANT, 5);
  535. OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_RED));
  536. OUT_RING(ring, 0x00000000); /* RB_BLEND_RED */
  537. OUT_RING(ring, 0x00000000); /* RB_BLEND_GREEN */
  538. OUT_RING(ring, 0x00000000); /* RB_BLEND_BLUE */
  539. OUT_RING(ring, 0x000000ff); /* RB_BLEND_ALPHA */
  540. fd_ringbuffer_flush(ring);
  541. fd_ringmarker_mark(ctx->draw_start);
  542. }