gallium: remove pipe_index_buffer and set_index_buffer
[mesa.git] / src / gallium / drivers / freedreno / a4xx / fd4_emit.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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 (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_helpers.h"
33 #include "util/u_format.h"
34 #include "util/u_viewport.h"
35
36 #include "freedreno_resource.h"
37 #include "freedreno_query_hw.h"
38
39 #include "fd4_emit.h"
40 #include "fd4_blend.h"
41 #include "fd4_context.h"
42 #include "fd4_program.h"
43 #include "fd4_rasterizer.h"
44 #include "fd4_texture.h"
45 #include "fd4_format.h"
46 #include "fd4_zsa.h"
47
48 /* regid: base const register
49 * prsc or dwords: buffer containing constant values
50 * sizedwords: size of const value buffer
51 */
52 static void
53 fd4_emit_const(struct fd_ringbuffer *ring, enum shader_t type,
54 uint32_t regid, uint32_t offset, uint32_t sizedwords,
55 const uint32_t *dwords, struct pipe_resource *prsc)
56 {
57 uint32_t i, sz;
58 enum a4xx_state_src src;
59
60 debug_assert((regid % 4) == 0);
61 debug_assert((sizedwords % 4) == 0);
62
63 if (prsc) {
64 sz = 0;
65 src = SS4_INDIRECT;
66 } else {
67 sz = sizedwords;
68 src = SS4_DIRECT;
69 }
70
71 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + sz);
72 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
73 CP_LOAD_STATE4_0_STATE_SRC(src) |
74 CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
75 CP_LOAD_STATE4_0_NUM_UNIT(sizedwords/4));
76 if (prsc) {
77 struct fd_bo *bo = fd_resource(prsc)->bo;
78 OUT_RELOC(ring, bo, offset,
79 CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS), 0);
80 } else {
81 OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
82 CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
83 dwords = (uint32_t *)&((uint8_t *)dwords)[offset];
84 }
85 for (i = 0; i < sz; i++) {
86 OUT_RING(ring, dwords[i]);
87 }
88 }
89
90 static void
91 fd4_emit_const_bo(struct fd_ringbuffer *ring, enum shader_t type, boolean write,
92 uint32_t regid, uint32_t num, struct pipe_resource **prscs, uint32_t *offsets)
93 {
94 uint32_t anum = align(num, 4);
95 uint32_t i;
96
97 debug_assert((regid % 4) == 0);
98
99 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + anum);
100 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
101 CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
102 CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
103 CP_LOAD_STATE4_0_NUM_UNIT(anum/4));
104 OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
105 CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
106
107 for (i = 0; i < num; i++) {
108 if (prscs[i]) {
109 if (write) {
110 OUT_RELOCW(ring, fd_resource(prscs[i])->bo, offsets[i], 0, 0);
111 } else {
112 OUT_RELOC(ring, fd_resource(prscs[i])->bo, offsets[i], 0, 0);
113 }
114 } else {
115 OUT_RING(ring, 0xbad00000 | (i << 16));
116 }
117 }
118
119 for (; i < anum; i++)
120 OUT_RING(ring, 0xffffffff);
121 }
122
123 static void
124 emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
125 enum a4xx_state_block sb, struct fd_texture_stateobj *tex,
126 const struct ir3_shader_variant *v)
127 {
128 static const uint32_t bcolor_reg[] = {
129 [SB4_VS_TEX] = REG_A4XX_TPL1_TP_VS_BORDER_COLOR_BASE_ADDR,
130 [SB4_FS_TEX] = REG_A4XX_TPL1_TP_FS_BORDER_COLOR_BASE_ADDR,
131 };
132 struct fd4_context *fd4_ctx = fd4_context(ctx);
133 bool needs_border = false;
134 unsigned i;
135
136 if (tex->num_samplers > 0) {
137 int num_samplers;
138
139 /* not sure if this is an a420.0 workaround, but we seem
140 * to need to emit these in pairs.. emit a final dummy
141 * entry if odd # of samplers:
142 */
143 num_samplers = align(tex->num_samplers, 2);
144
145 /* output sampler state: */
146 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (2 * num_samplers));
147 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
148 CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
149 CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
150 CP_LOAD_STATE4_0_NUM_UNIT(num_samplers));
151 OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER) |
152 CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
153 for (i = 0; i < tex->num_samplers; i++) {
154 static const struct fd4_sampler_stateobj dummy_sampler = {};
155 const struct fd4_sampler_stateobj *sampler = tex->samplers[i] ?
156 fd4_sampler_stateobj(tex->samplers[i]) :
157 &dummy_sampler;
158 OUT_RING(ring, sampler->texsamp0);
159 OUT_RING(ring, sampler->texsamp1);
160
161 needs_border |= sampler->needs_border;
162 }
163
164 for (; i < num_samplers; i++) {
165 OUT_RING(ring, 0x00000000);
166 OUT_RING(ring, 0x00000000);
167 }
168 }
169
170 if (tex->num_textures > 0) {
171 unsigned num_textures = tex->num_textures + v->astc_srgb.count;
172
173 /* emit texture state: */
174 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (8 * num_textures));
175 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
176 CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
177 CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
178 CP_LOAD_STATE4_0_NUM_UNIT(num_textures));
179 OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS) |
180 CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
181 for (i = 0; i < tex->num_textures; i++) {
182 static const struct fd4_pipe_sampler_view dummy_view = {};
183 const struct fd4_pipe_sampler_view *view = tex->textures[i] ?
184 fd4_pipe_sampler_view(tex->textures[i]) :
185 &dummy_view;
186
187 OUT_RING(ring, view->texconst0);
188 OUT_RING(ring, view->texconst1);
189 OUT_RING(ring, view->texconst2);
190 OUT_RING(ring, view->texconst3);
191 if (view->base.texture) {
192 struct fd_resource *rsc = fd_resource(view->base.texture);
193 OUT_RELOC(ring, rsc->bo, view->offset, view->texconst4, 0);
194 } else {
195 OUT_RING(ring, 0x00000000);
196 }
197 OUT_RING(ring, 0x00000000);
198 OUT_RING(ring, 0x00000000);
199 OUT_RING(ring, 0x00000000);
200 }
201
202 for (i = 0; i < v->astc_srgb.count; i++) {
203 static const struct fd4_pipe_sampler_view dummy_view = {};
204 const struct fd4_pipe_sampler_view *view;
205 unsigned idx = v->astc_srgb.orig_idx[i];
206
207 view = tex->textures[idx] ?
208 fd4_pipe_sampler_view(tex->textures[idx]) :
209 &dummy_view;
210
211 debug_assert(view->texconst0 & A4XX_TEX_CONST_0_SRGB);
212
213 OUT_RING(ring, view->texconst0 & ~A4XX_TEX_CONST_0_SRGB);
214 OUT_RING(ring, view->texconst1);
215 OUT_RING(ring, view->texconst2);
216 OUT_RING(ring, view->texconst3);
217 if (view->base.texture) {
218 struct fd_resource *rsc = fd_resource(view->base.texture);
219 OUT_RELOC(ring, rsc->bo, view->offset, view->texconst4, 0);
220 } else {
221 OUT_RING(ring, 0x00000000);
222 }
223 OUT_RING(ring, 0x00000000);
224 OUT_RING(ring, 0x00000000);
225 OUT_RING(ring, 0x00000000);
226 }
227 } else {
228 debug_assert(v->astc_srgb.count == 0);
229 }
230
231 if (needs_border) {
232 unsigned off;
233 void *ptr;
234
235 u_upload_alloc(fd4_ctx->border_color_uploader,
236 0, BORDER_COLOR_UPLOAD_SIZE,
237 BORDER_COLOR_UPLOAD_SIZE, &off,
238 &fd4_ctx->border_color_buf,
239 &ptr);
240
241 fd_setup_border_colors(tex, ptr, 0);
242 OUT_PKT0(ring, bcolor_reg[sb], 1);
243 OUT_RELOC(ring, fd_resource(fd4_ctx->border_color_buf)->bo, off, 0, 0);
244
245 u_upload_unmap(fd4_ctx->border_color_uploader);
246 }
247 }
248
249 /* emit texture state for mem->gmem restore operation.. eventually it would
250 * be good to get rid of this and use normal CSO/etc state for more of these
251 * special cases..
252 */
253 void
254 fd4_emit_gmem_restore_tex(struct fd_ringbuffer *ring, unsigned nr_bufs,
255 struct pipe_surface **bufs)
256 {
257 unsigned char mrt_comp[A4XX_MAX_RENDER_TARGETS];
258 int i;
259
260 for (i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
261 mrt_comp[i] = (i < nr_bufs) ? 0xf : 0;
262 }
263
264 /* output sampler state: */
265 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (2 * nr_bufs));
266 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
267 CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
268 CP_LOAD_STATE4_0_STATE_BLOCK(SB4_FS_TEX) |
269 CP_LOAD_STATE4_0_NUM_UNIT(nr_bufs));
270 OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER) |
271 CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
272 for (i = 0; i < nr_bufs; i++) {
273 OUT_RING(ring, A4XX_TEX_SAMP_0_XY_MAG(A4XX_TEX_NEAREST) |
274 A4XX_TEX_SAMP_0_XY_MIN(A4XX_TEX_NEAREST) |
275 A4XX_TEX_SAMP_0_WRAP_S(A4XX_TEX_CLAMP_TO_EDGE) |
276 A4XX_TEX_SAMP_0_WRAP_T(A4XX_TEX_CLAMP_TO_EDGE) |
277 A4XX_TEX_SAMP_0_WRAP_R(A4XX_TEX_REPEAT));
278 OUT_RING(ring, 0x00000000);
279 }
280
281 /* emit texture state: */
282 OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (8 * nr_bufs));
283 OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
284 CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
285 CP_LOAD_STATE4_0_STATE_BLOCK(SB4_FS_TEX) |
286 CP_LOAD_STATE4_0_NUM_UNIT(nr_bufs));
287 OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS) |
288 CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
289 for (i = 0; i < nr_bufs; i++) {
290 if (bufs[i]) {
291 struct fd_resource *rsc = fd_resource(bufs[i]->texture);
292 enum pipe_format format = fd_gmem_restore_format(bufs[i]->format);
293
294 /* The restore blit_zs shader expects stencil in sampler 0,
295 * and depth in sampler 1
296 */
297 if (rsc->stencil && (i == 0)) {
298 rsc = rsc->stencil;
299 format = fd_gmem_restore_format(rsc->base.b.format);
300 }
301
302 /* note: PIPE_BUFFER disallowed for surfaces */
303 unsigned lvl = bufs[i]->u.tex.level;
304 struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl);
305 unsigned offset = fd_resource_offset(rsc, lvl, bufs[i]->u.tex.first_layer);
306
307 /* z32 restore is accomplished using depth write. If there is
308 * no stencil component (ie. PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
309 * then no render target:
310 *
311 * (The same applies for z32_s8x24, since for stencil sampler
312 * state the above 'if' will replace 'format' with s8)
313 */
314 if ((format == PIPE_FORMAT_Z32_FLOAT) ||
315 (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT))
316 mrt_comp[i] = 0;
317
318 debug_assert(bufs[i]->u.tex.first_layer == bufs[i]->u.tex.last_layer);
319
320 OUT_RING(ring, A4XX_TEX_CONST_0_FMT(fd4_pipe2tex(format)) |
321 A4XX_TEX_CONST_0_TYPE(A4XX_TEX_2D) |
322 fd4_tex_swiz(format, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
323 PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W));
324 OUT_RING(ring, A4XX_TEX_CONST_1_WIDTH(bufs[i]->width) |
325 A4XX_TEX_CONST_1_HEIGHT(bufs[i]->height));
326 OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(slice->pitch * rsc->cpp) |
327 A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(format)));
328 OUT_RING(ring, 0x00000000);
329 OUT_RELOC(ring, rsc->bo, offset, 0, 0);
330 OUT_RING(ring, 0x00000000);
331 OUT_RING(ring, 0x00000000);
332 OUT_RING(ring, 0x00000000);
333 } else {
334 OUT_RING(ring, A4XX_TEX_CONST_0_FMT(0) |
335 A4XX_TEX_CONST_0_TYPE(A4XX_TEX_2D) |
336 A4XX_TEX_CONST_0_SWIZ_X(A4XX_TEX_ONE) |
337 A4XX_TEX_CONST_0_SWIZ_Y(A4XX_TEX_ONE) |
338 A4XX_TEX_CONST_0_SWIZ_Z(A4XX_TEX_ONE) |
339 A4XX_TEX_CONST_0_SWIZ_W(A4XX_TEX_ONE));
340 OUT_RING(ring, A4XX_TEX_CONST_1_WIDTH(0) |
341 A4XX_TEX_CONST_1_HEIGHT(0));
342 OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(0));
343 OUT_RING(ring, 0x00000000);
344 OUT_RING(ring, 0x00000000);
345 OUT_RING(ring, 0x00000000);
346 OUT_RING(ring, 0x00000000);
347 OUT_RING(ring, 0x00000000);
348 }
349 }
350
351 OUT_PKT0(ring, REG_A4XX_RB_RENDER_COMPONENTS, 1);
352 OUT_RING(ring, A4XX_RB_RENDER_COMPONENTS_RT0(mrt_comp[0]) |
353 A4XX_RB_RENDER_COMPONENTS_RT1(mrt_comp[1]) |
354 A4XX_RB_RENDER_COMPONENTS_RT2(mrt_comp[2]) |
355 A4XX_RB_RENDER_COMPONENTS_RT3(mrt_comp[3]) |
356 A4XX_RB_RENDER_COMPONENTS_RT4(mrt_comp[4]) |
357 A4XX_RB_RENDER_COMPONENTS_RT5(mrt_comp[5]) |
358 A4XX_RB_RENDER_COMPONENTS_RT6(mrt_comp[6]) |
359 A4XX_RB_RENDER_COMPONENTS_RT7(mrt_comp[7]));
360 }
361
362 void
363 fd4_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd4_emit *emit)
364 {
365 int32_t i, j, last = -1;
366 uint32_t total_in = 0;
367 const struct fd_vertex_state *vtx = emit->vtx;
368 const struct ir3_shader_variant *vp = fd4_emit_get_vp(emit);
369 unsigned vertex_regid = regid(63, 0);
370 unsigned instance_regid = regid(63, 0);
371 unsigned vtxcnt_regid = regid(63, 0);
372
373 /* Note that sysvals come *after* normal inputs: */
374 for (i = 0; i < vp->inputs_count; i++) {
375 if (!vp->inputs[i].compmask)
376 continue;
377 if (vp->inputs[i].sysval) {
378 switch(vp->inputs[i].slot) {
379 case SYSTEM_VALUE_BASE_VERTEX:
380 /* handled elsewhere */
381 break;
382 case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE:
383 vertex_regid = vp->inputs[i].regid;
384 break;
385 case SYSTEM_VALUE_INSTANCE_ID:
386 instance_regid = vp->inputs[i].regid;
387 break;
388 case SYSTEM_VALUE_VERTEX_CNT:
389 vtxcnt_regid = vp->inputs[i].regid;
390 break;
391 default:
392 unreachable("invalid system value");
393 break;
394 }
395 } else if (i < vtx->vtx->num_elements) {
396 last = i;
397 }
398 }
399
400 for (i = 0, j = 0; i <= last; i++) {
401 assert(!vp->inputs[i].sysval);
402 if (vp->inputs[i].compmask) {
403 struct pipe_vertex_element *elem = &vtx->vtx->pipe[i];
404 const struct pipe_vertex_buffer *vb =
405 &vtx->vertexbuf.vb[elem->vertex_buffer_index];
406 struct fd_resource *rsc = fd_resource(vb->buffer.resource);
407 enum pipe_format pfmt = elem->src_format;
408 enum a4xx_vtx_fmt fmt = fd4_pipe2vtx(pfmt);
409 bool switchnext = (i != last) ||
410 (vertex_regid != regid(63, 0)) ||
411 (instance_regid != regid(63, 0)) ||
412 (vtxcnt_regid != regid(63, 0));
413 bool isint = util_format_is_pure_integer(pfmt);
414 uint32_t fs = util_format_get_blocksize(pfmt);
415 uint32_t off = vb->buffer_offset + elem->src_offset;
416 uint32_t size = fd_bo_size(rsc->bo) - off;
417 debug_assert(fmt != ~0);
418
419 OUT_PKT0(ring, REG_A4XX_VFD_FETCH(j), 4);
420 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_0_FETCHSIZE(fs - 1) |
421 A4XX_VFD_FETCH_INSTR_0_BUFSTRIDE(vb->stride) |
422 COND(elem->instance_divisor, A4XX_VFD_FETCH_INSTR_0_INSTANCED) |
423 COND(switchnext, A4XX_VFD_FETCH_INSTR_0_SWITCHNEXT));
424 OUT_RELOC(ring, rsc->bo, off, 0, 0);
425 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_2_SIZE(size));
426 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_3_STEPRATE(MAX2(1, elem->instance_divisor)));
427
428 OUT_PKT0(ring, REG_A4XX_VFD_DECODE_INSTR(j), 1);
429 OUT_RING(ring, A4XX_VFD_DECODE_INSTR_CONSTFILL |
430 A4XX_VFD_DECODE_INSTR_WRITEMASK(vp->inputs[i].compmask) |
431 A4XX_VFD_DECODE_INSTR_FORMAT(fmt) |
432 A4XX_VFD_DECODE_INSTR_SWAP(fd4_pipe2swap(pfmt)) |
433 A4XX_VFD_DECODE_INSTR_REGID(vp->inputs[i].regid) |
434 A4XX_VFD_DECODE_INSTR_SHIFTCNT(fs) |
435 A4XX_VFD_DECODE_INSTR_LASTCOMPVALID |
436 COND(isint, A4XX_VFD_DECODE_INSTR_INT) |
437 COND(switchnext, A4XX_VFD_DECODE_INSTR_SWITCHNEXT));
438
439 total_in += vp->inputs[i].ncomp;
440 j++;
441 }
442 }
443
444 /* hw doesn't like to be configured for zero vbo's, it seems: */
445 if (last < 0) {
446 /* just recycle the shader bo, we just need to point to *something*
447 * valid:
448 */
449 struct fd_bo *dummy_vbo = vp->bo;
450 bool switchnext = (vertex_regid != regid(63, 0)) ||
451 (instance_regid != regid(63, 0)) ||
452 (vtxcnt_regid != regid(63, 0));
453
454 OUT_PKT0(ring, REG_A4XX_VFD_FETCH(0), 4);
455 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_0_FETCHSIZE(0) |
456 A4XX_VFD_FETCH_INSTR_0_BUFSTRIDE(0) |
457 COND(switchnext, A4XX_VFD_FETCH_INSTR_0_SWITCHNEXT));
458 OUT_RELOC(ring, dummy_vbo, 0, 0, 0);
459 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_2_SIZE(1));
460 OUT_RING(ring, A4XX_VFD_FETCH_INSTR_3_STEPRATE(1));
461
462 OUT_PKT0(ring, REG_A4XX_VFD_DECODE_INSTR(0), 1);
463 OUT_RING(ring, A4XX_VFD_DECODE_INSTR_CONSTFILL |
464 A4XX_VFD_DECODE_INSTR_WRITEMASK(0x1) |
465 A4XX_VFD_DECODE_INSTR_FORMAT(VFMT4_8_UNORM) |
466 A4XX_VFD_DECODE_INSTR_SWAP(XYZW) |
467 A4XX_VFD_DECODE_INSTR_REGID(regid(0,0)) |
468 A4XX_VFD_DECODE_INSTR_SHIFTCNT(1) |
469 A4XX_VFD_DECODE_INSTR_LASTCOMPVALID |
470 COND(switchnext, A4XX_VFD_DECODE_INSTR_SWITCHNEXT));
471
472 total_in = 1;
473 j = 1;
474 }
475
476 OUT_PKT0(ring, REG_A4XX_VFD_CONTROL_0, 5);
477 OUT_RING(ring, A4XX_VFD_CONTROL_0_TOTALATTRTOVS(total_in) |
478 0xa0000 | /* XXX */
479 A4XX_VFD_CONTROL_0_STRMDECINSTRCNT(j) |
480 A4XX_VFD_CONTROL_0_STRMFETCHINSTRCNT(j));
481 OUT_RING(ring, A4XX_VFD_CONTROL_1_MAXSTORAGE(129) | // XXX
482 A4XX_VFD_CONTROL_1_REGID4VTX(vertex_regid) |
483 A4XX_VFD_CONTROL_1_REGID4INST(instance_regid));
484 OUT_RING(ring, 0x00000000); /* XXX VFD_CONTROL_2 */
485 OUT_RING(ring, A4XX_VFD_CONTROL_3_REGID_VTXCNT(vtxcnt_regid));
486 OUT_RING(ring, 0x00000000); /* XXX VFD_CONTROL_4 */
487
488 /* cache invalidate, otherwise vertex fetch could see
489 * stale vbo contents:
490 */
491 OUT_PKT0(ring, REG_A4XX_UCHE_INVALIDATE0, 2);
492 OUT_RING(ring, 0x00000000);
493 OUT_RING(ring, 0x00000012);
494 }
495
496 void
497 fd4_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
498 struct fd4_emit *emit)
499 {
500 const struct ir3_shader_variant *vp = fd4_emit_get_vp(emit);
501 const struct ir3_shader_variant *fp = fd4_emit_get_fp(emit);
502 const enum fd_dirty_3d_state dirty = emit->dirty;
503
504 emit_marker(ring, 5);
505
506 if ((dirty & FD_DIRTY_FRAMEBUFFER) && !emit->key.binning_pass) {
507 struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
508 unsigned char mrt_comp[A4XX_MAX_RENDER_TARGETS] = {0};
509
510 for (unsigned i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
511 mrt_comp[i] = ((i < pfb->nr_cbufs) && pfb->cbufs[i]) ? 0xf : 0;
512 }
513
514 OUT_PKT0(ring, REG_A4XX_RB_RENDER_COMPONENTS, 1);
515 OUT_RING(ring, A4XX_RB_RENDER_COMPONENTS_RT0(mrt_comp[0]) |
516 A4XX_RB_RENDER_COMPONENTS_RT1(mrt_comp[1]) |
517 A4XX_RB_RENDER_COMPONENTS_RT2(mrt_comp[2]) |
518 A4XX_RB_RENDER_COMPONENTS_RT3(mrt_comp[3]) |
519 A4XX_RB_RENDER_COMPONENTS_RT4(mrt_comp[4]) |
520 A4XX_RB_RENDER_COMPONENTS_RT5(mrt_comp[5]) |
521 A4XX_RB_RENDER_COMPONENTS_RT6(mrt_comp[6]) |
522 A4XX_RB_RENDER_COMPONENTS_RT7(mrt_comp[7]));
523 }
524
525 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_FRAMEBUFFER)) {
526 struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
527 struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
528 uint32_t rb_alpha_control = zsa->rb_alpha_control;
529
530 if (util_format_is_pure_integer(pipe_surface_format(pfb->cbufs[0])))
531 rb_alpha_control &= ~A4XX_RB_ALPHA_CONTROL_ALPHA_TEST;
532
533 OUT_PKT0(ring, REG_A4XX_RB_ALPHA_CONTROL, 1);
534 OUT_RING(ring, rb_alpha_control);
535
536 OUT_PKT0(ring, REG_A4XX_RB_STENCIL_CONTROL, 2);
537 OUT_RING(ring, zsa->rb_stencil_control);
538 OUT_RING(ring, zsa->rb_stencil_control2);
539 }
540
541 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_STENCIL_REF)) {
542 struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
543 struct pipe_stencil_ref *sr = &ctx->stencil_ref;
544
545 OUT_PKT0(ring, REG_A4XX_RB_STENCILREFMASK, 2);
546 OUT_RING(ring, zsa->rb_stencilrefmask |
547 A4XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
548 OUT_RING(ring, zsa->rb_stencilrefmask_bf |
549 A4XX_RB_STENCILREFMASK_BF_STENCILREF(sr->ref_value[1]));
550 }
551
552 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_RASTERIZER | FD_DIRTY_PROG)) {
553 struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
554 bool fragz = fp->has_kill | fp->writes_pos;
555 bool clamp = !ctx->rasterizer->depth_clip;
556
557 OUT_PKT0(ring, REG_A4XX_RB_DEPTH_CONTROL, 1);
558 OUT_RING(ring, zsa->rb_depth_control |
559 COND(clamp, A4XX_RB_DEPTH_CONTROL_Z_CLAMP_ENABLE) |
560 COND(fragz, A4XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE) |
561 COND(fragz && fp->frag_coord, A4XX_RB_DEPTH_CONTROL_FORCE_FRAGZ_TO_FS));
562
563 /* maybe this register/bitfield needs a better name.. this
564 * appears to be just disabling early-z
565 */
566 OUT_PKT0(ring, REG_A4XX_GRAS_ALPHA_CONTROL, 1);
567 OUT_RING(ring, zsa->gras_alpha_control |
568 COND(fragz, A4XX_GRAS_ALPHA_CONTROL_ALPHA_TEST_ENABLE) |
569 COND(fragz && fp->frag_coord, A4XX_GRAS_ALPHA_CONTROL_FORCE_FRAGZ_TO_FS));
570 }
571
572 if (dirty & FD_DIRTY_RASTERIZER) {
573 struct fd4_rasterizer_stateobj *rasterizer =
574 fd4_rasterizer_stateobj(ctx->rasterizer);
575
576 OUT_PKT0(ring, REG_A4XX_GRAS_SU_MODE_CONTROL, 1);
577 OUT_RING(ring, rasterizer->gras_su_mode_control |
578 A4XX_GRAS_SU_MODE_CONTROL_RENDERING_PASS);
579
580 OUT_PKT0(ring, REG_A4XX_GRAS_SU_POINT_MINMAX, 2);
581 OUT_RING(ring, rasterizer->gras_su_point_minmax);
582 OUT_RING(ring, rasterizer->gras_su_point_size);
583
584 OUT_PKT0(ring, REG_A4XX_GRAS_SU_POLY_OFFSET_SCALE, 2);
585 OUT_RING(ring, rasterizer->gras_su_poly_offset_scale);
586 OUT_RING(ring, rasterizer->gras_su_poly_offset_offset);
587
588 OUT_PKT0(ring, REG_A4XX_GRAS_CL_CLIP_CNTL, 1);
589 OUT_RING(ring, rasterizer->gras_cl_clip_cntl);
590 }
591
592 /* NOTE: since primitive_restart is not actually part of any
593 * state object, we need to make sure that we always emit
594 * PRIM_VTX_CNTL.. either that or be more clever and detect
595 * when it changes.
596 */
597 if (emit->info) {
598 const struct pipe_draw_info *info = emit->info;
599 struct fd4_rasterizer_stateobj *rast =
600 fd4_rasterizer_stateobj(ctx->rasterizer);
601 uint32_t val = rast->pc_prim_vtx_cntl;
602
603 if (info->index_size && info->primitive_restart)
604 val |= A4XX_PC_PRIM_VTX_CNTL_PRIMITIVE_RESTART;
605
606 val |= COND(vp->writes_psize, A4XX_PC_PRIM_VTX_CNTL_PSIZE);
607
608 if (fp->total_in > 0) {
609 uint32_t varout = align(fp->total_in, 16) / 16;
610 if (varout > 1)
611 varout = align(varout, 2);
612 val |= A4XX_PC_PRIM_VTX_CNTL_VAROUT(varout);
613 }
614
615 OUT_PKT0(ring, REG_A4XX_PC_PRIM_VTX_CNTL, 2);
616 OUT_RING(ring, val);
617 OUT_RING(ring, rast->pc_prim_vtx_cntl2);
618 }
619
620 if (dirty & FD_DIRTY_SCISSOR) {
621 struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
622
623 OUT_PKT0(ring, REG_A4XX_GRAS_SC_WINDOW_SCISSOR_BR, 2);
624 OUT_RING(ring, A4XX_GRAS_SC_WINDOW_SCISSOR_BR_X(scissor->maxx - 1) |
625 A4XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(scissor->maxy - 1));
626 OUT_RING(ring, A4XX_GRAS_SC_WINDOW_SCISSOR_TL_X(scissor->minx) |
627 A4XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(scissor->miny));
628
629 ctx->batch->max_scissor.minx = MIN2(ctx->batch->max_scissor.minx, scissor->minx);
630 ctx->batch->max_scissor.miny = MIN2(ctx->batch->max_scissor.miny, scissor->miny);
631 ctx->batch->max_scissor.maxx = MAX2(ctx->batch->max_scissor.maxx, scissor->maxx);
632 ctx->batch->max_scissor.maxy = MAX2(ctx->batch->max_scissor.maxy, scissor->maxy);
633 }
634
635 if (dirty & FD_DIRTY_VIEWPORT) {
636 fd_wfi(ctx->batch, ring);
637 OUT_PKT0(ring, REG_A4XX_GRAS_CL_VPORT_XOFFSET_0, 6);
638 OUT_RING(ring, A4XX_GRAS_CL_VPORT_XOFFSET_0(ctx->viewport.translate[0]));
639 OUT_RING(ring, A4XX_GRAS_CL_VPORT_XSCALE_0(ctx->viewport.scale[0]));
640 OUT_RING(ring, A4XX_GRAS_CL_VPORT_YOFFSET_0(ctx->viewport.translate[1]));
641 OUT_RING(ring, A4XX_GRAS_CL_VPORT_YSCALE_0(ctx->viewport.scale[1]));
642 OUT_RING(ring, A4XX_GRAS_CL_VPORT_ZOFFSET_0(ctx->viewport.translate[2]));
643 OUT_RING(ring, A4XX_GRAS_CL_VPORT_ZSCALE_0(ctx->viewport.scale[2]));
644 }
645
646 if (dirty & (FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER | FD_DIRTY_FRAMEBUFFER)) {
647 float zmin, zmax;
648 int depth = 24;
649 if (ctx->batch->framebuffer.zsbuf) {
650 depth = util_format_get_component_bits(
651 pipe_surface_format(ctx->batch->framebuffer.zsbuf),
652 UTIL_FORMAT_COLORSPACE_ZS, 0);
653 }
654 util_viewport_zmin_zmax(&ctx->viewport, ctx->rasterizer->clip_halfz,
655 &zmin, &zmax);
656
657 OUT_PKT0(ring, REG_A4XX_RB_VPORT_Z_CLAMP(0), 2);
658 if (depth == 32) {
659 OUT_RING(ring, fui(zmin));
660 OUT_RING(ring, fui(zmax));
661 } else if (depth == 16) {
662 OUT_RING(ring, (uint32_t)(zmin * 0xffff));
663 OUT_RING(ring, (uint32_t)(zmax * 0xffff));
664 } else {
665 OUT_RING(ring, (uint32_t)(zmin * 0xffffff));
666 OUT_RING(ring, (uint32_t)(zmax * 0xffffff));
667 }
668 }
669
670 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_FRAMEBUFFER)) {
671 struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
672 unsigned n = pfb->nr_cbufs;
673 /* if we have depth/stencil, we need at least on MRT: */
674 if (pfb->zsbuf)
675 n = MAX2(1, n);
676 fd4_program_emit(ring, emit, n, pfb->cbufs);
677 }
678
679 if (emit->prog == &ctx->prog) { /* evil hack to deal sanely with clear path */
680 ir3_emit_vs_consts(vp, ring, ctx, emit->info);
681 if (!emit->key.binning_pass)
682 ir3_emit_fs_consts(fp, ring, ctx);
683 }
684
685 if ((dirty & FD_DIRTY_BLEND)) {
686 struct fd4_blend_stateobj *blend = fd4_blend_stateobj(ctx->blend);
687 uint32_t i;
688
689 for (i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
690 enum pipe_format format = pipe_surface_format(
691 ctx->batch->framebuffer.cbufs[i]);
692 bool is_int = util_format_is_pure_integer(format);
693 bool has_alpha = util_format_has_alpha(format);
694 uint32_t control = blend->rb_mrt[i].control;
695 uint32_t blend_control = blend->rb_mrt[i].blend_control_alpha;
696
697 if (is_int) {
698 control &= A4XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK;
699 control |= A4XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY);
700 }
701
702 if (has_alpha) {
703 blend_control |= blend->rb_mrt[i].blend_control_rgb;
704 } else {
705 blend_control |= blend->rb_mrt[i].blend_control_no_alpha_rgb;
706 control &= ~A4XX_RB_MRT_CONTROL_BLEND2;
707 }
708
709 OUT_PKT0(ring, REG_A4XX_RB_MRT_CONTROL(i), 1);
710 OUT_RING(ring, control);
711
712 OUT_PKT0(ring, REG_A4XX_RB_MRT_BLEND_CONTROL(i), 1);
713 OUT_RING(ring, blend_control);
714 }
715
716 OUT_PKT0(ring, REG_A4XX_RB_FS_OUTPUT, 1);
717 OUT_RING(ring, blend->rb_fs_output |
718 A4XX_RB_FS_OUTPUT_SAMPLE_MASK(0xffff));
719 }
720
721 if (dirty & FD_DIRTY_BLEND_COLOR) {
722 struct pipe_blend_color *bcolor = &ctx->blend_color;
723
724 OUT_PKT0(ring, REG_A4XX_RB_BLEND_RED, 8);
725 OUT_RING(ring, A4XX_RB_BLEND_RED_FLOAT(bcolor->color[0]) |
726 A4XX_RB_BLEND_RED_UINT(bcolor->color[0] * 0xff) |
727 A4XX_RB_BLEND_RED_SINT(bcolor->color[0] * 0x7f));
728 OUT_RING(ring, A4XX_RB_BLEND_RED_F32(bcolor->color[0]));
729 OUT_RING(ring, A4XX_RB_BLEND_GREEN_FLOAT(bcolor->color[1]) |
730 A4XX_RB_BLEND_GREEN_UINT(bcolor->color[1] * 0xff) |
731 A4XX_RB_BLEND_GREEN_SINT(bcolor->color[1] * 0x7f));
732 OUT_RING(ring, A4XX_RB_BLEND_RED_F32(bcolor->color[1]));
733 OUT_RING(ring, A4XX_RB_BLEND_BLUE_FLOAT(bcolor->color[2]) |
734 A4XX_RB_BLEND_BLUE_UINT(bcolor->color[2] * 0xff) |
735 A4XX_RB_BLEND_BLUE_SINT(bcolor->color[2] * 0x7f));
736 OUT_RING(ring, A4XX_RB_BLEND_BLUE_F32(bcolor->color[2]));
737 OUT_RING(ring, A4XX_RB_BLEND_ALPHA_FLOAT(bcolor->color[3]) |
738 A4XX_RB_BLEND_ALPHA_UINT(bcolor->color[3] * 0xff) |
739 A4XX_RB_BLEND_ALPHA_SINT(bcolor->color[3] * 0x7f));
740 OUT_RING(ring, A4XX_RB_BLEND_ALPHA_F32(bcolor->color[3]));
741 }
742
743 if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & FD_DIRTY_SHADER_TEX)
744 emit_textures(ctx, ring, SB4_VS_TEX, &ctx->tex[PIPE_SHADER_VERTEX], vp);
745
746 if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_TEX)
747 emit_textures(ctx, ring, SB4_FS_TEX, &ctx->tex[PIPE_SHADER_FRAGMENT], fp);
748 }
749
750 /* emit setup at begin of new cmdstream buffer (don't rely on previous
751 * state, there could have been a context switch between ioctls):
752 */
753 void
754 fd4_emit_restore(struct fd_batch *batch, struct fd_ringbuffer *ring)
755 {
756 struct fd_context *ctx = batch->ctx;
757 struct fd4_context *fd4_ctx = fd4_context(ctx);
758
759 OUT_PKT0(ring, REG_A4XX_RBBM_PERFCTR_CTL, 1);
760 OUT_RING(ring, 0x00000001);
761
762 OUT_PKT0(ring, REG_A4XX_GRAS_DEBUG_ECO_CONTROL, 1);
763 OUT_RING(ring, 0x00000000);
764
765 OUT_PKT0(ring, REG_A4XX_SP_MODE_CONTROL, 1);
766 OUT_RING(ring, 0x00000006);
767
768 OUT_PKT0(ring, REG_A4XX_TPL1_TP_MODE_CONTROL, 1);
769 OUT_RING(ring, 0x0000003a);
770
771 OUT_PKT0(ring, REG_A4XX_UNKNOWN_0D01, 1);
772 OUT_RING(ring, 0x00000001);
773
774 OUT_PKT0(ring, REG_A4XX_UNKNOWN_0E42, 1);
775 OUT_RING(ring, 0x00000000);
776
777 OUT_PKT0(ring, REG_A4XX_UCHE_CACHE_WAYS_VFD, 1);
778 OUT_RING(ring, 0x00000007);
779
780 OUT_PKT0(ring, REG_A4XX_UCHE_CACHE_MODE_CONTROL, 1);
781 OUT_RING(ring, 0x00000000);
782
783 OUT_PKT0(ring, REG_A4XX_UCHE_INVALIDATE0, 2);
784 OUT_RING(ring, 0x00000000);
785 OUT_RING(ring, 0x00000012);
786
787 OUT_PKT0(ring, REG_A4XX_HLSQ_MODE_CONTROL, 1);
788 OUT_RING(ring, 0x00000000);
789
790 OUT_PKT0(ring, REG_A4XX_UNKNOWN_0CC5, 1);
791 OUT_RING(ring, 0x00000006);
792
793 OUT_PKT0(ring, REG_A4XX_UNKNOWN_0CC6, 1);
794 OUT_RING(ring, 0x00000000);
795
796 OUT_PKT0(ring, REG_A4XX_UNKNOWN_0EC2, 1);
797 OUT_RING(ring, 0x00040000);
798
799 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2001, 1);
800 OUT_RING(ring, 0x00000000);
801
802 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
803 OUT_RING(ring, 0x00001000);
804
805 OUT_PKT0(ring, REG_A4XX_UNKNOWN_20EF, 1);
806 OUT_RING(ring, 0x00000000);
807
808 OUT_PKT0(ring, REG_A4XX_RB_BLEND_RED, 4);
809 OUT_RING(ring, A4XX_RB_BLEND_RED_UINT(0) |
810 A4XX_RB_BLEND_RED_FLOAT(0.0));
811 OUT_RING(ring, A4XX_RB_BLEND_GREEN_UINT(0) |
812 A4XX_RB_BLEND_GREEN_FLOAT(0.0));
813 OUT_RING(ring, A4XX_RB_BLEND_BLUE_UINT(0) |
814 A4XX_RB_BLEND_BLUE_FLOAT(0.0));
815 OUT_RING(ring, A4XX_RB_BLEND_ALPHA_UINT(0x7fff) |
816 A4XX_RB_BLEND_ALPHA_FLOAT(1.0));
817
818 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2152, 1);
819 OUT_RING(ring, 0x00000000);
820
821 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2153, 1);
822 OUT_RING(ring, 0x00000000);
823
824 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2154, 1);
825 OUT_RING(ring, 0x00000000);
826
827 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2155, 1);
828 OUT_RING(ring, 0x00000000);
829
830 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2156, 1);
831 OUT_RING(ring, 0x00000000);
832
833 OUT_PKT0(ring, REG_A4XX_UNKNOWN_2157, 1);
834 OUT_RING(ring, 0x00000000);
835
836 OUT_PKT0(ring, REG_A4XX_UNKNOWN_21C3, 1);
837 OUT_RING(ring, 0x0000001d);
838
839 OUT_PKT0(ring, REG_A4XX_PC_GS_PARAM, 1);
840 OUT_RING(ring, 0x00000000);
841
842 OUT_PKT0(ring, REG_A4XX_UNKNOWN_21E6, 1);
843 OUT_RING(ring, 0x00000001);
844
845 OUT_PKT0(ring, REG_A4XX_PC_HS_PARAM, 1);
846 OUT_RING(ring, 0x00000000);
847
848 OUT_PKT0(ring, REG_A4XX_UNKNOWN_22D7, 1);
849 OUT_RING(ring, 0x00000000);
850
851 OUT_PKT0(ring, REG_A4XX_TPL1_TP_TEX_OFFSET, 1);
852 OUT_RING(ring, 0x00000000);
853
854 OUT_PKT0(ring, REG_A4XX_TPL1_TP_TEX_COUNT, 1);
855 OUT_RING(ring, A4XX_TPL1_TP_TEX_COUNT_VS(16) |
856 A4XX_TPL1_TP_TEX_COUNT_HS(0) |
857 A4XX_TPL1_TP_TEX_COUNT_DS(0) |
858 A4XX_TPL1_TP_TEX_COUNT_GS(0));
859
860 OUT_PKT0(ring, REG_A4XX_TPL1_TP_FS_TEX_COUNT, 1);
861 OUT_RING(ring, 16);
862
863 /* we don't use this yet.. probably best to disable.. */
864 OUT_PKT3(ring, CP_SET_DRAW_STATE, 2);
865 OUT_RING(ring, CP_SET_DRAW_STATE__0_COUNT(0) |
866 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS |
867 CP_SET_DRAW_STATE__0_GROUP_ID(0));
868 OUT_RING(ring, CP_SET_DRAW_STATE__1_ADDR_LO(0));
869
870 OUT_PKT0(ring, REG_A4XX_SP_VS_PVT_MEM_PARAM, 2);
871 OUT_RING(ring, 0x08000001); /* SP_VS_PVT_MEM_PARAM */
872 OUT_RELOC(ring, fd4_ctx->vs_pvt_mem, 0,0,0); /* SP_VS_PVT_MEM_ADDR */
873
874 OUT_PKT0(ring, REG_A4XX_SP_FS_PVT_MEM_PARAM, 2);
875 OUT_RING(ring, 0x08000001); /* SP_FS_PVT_MEM_PARAM */
876 OUT_RELOC(ring, fd4_ctx->fs_pvt_mem, 0,0,0); /* SP_FS_PVT_MEM_ADDR */
877
878 OUT_PKT0(ring, REG_A4XX_GRAS_SC_CONTROL, 1);
879 OUT_RING(ring, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS) |
880 A4XX_GRAS_SC_CONTROL_MSAA_DISABLE |
881 A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE) |
882 A4XX_GRAS_SC_CONTROL_RASTER_MODE(0));
883
884 OUT_PKT0(ring, REG_A4XX_RB_MSAA_CONTROL, 1);
885 OUT_RING(ring, A4XX_RB_MSAA_CONTROL_DISABLE |
886 A4XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE));
887
888 OUT_PKT0(ring, REG_A4XX_GRAS_CL_GB_CLIP_ADJ, 1);
889 OUT_RING(ring, A4XX_GRAS_CL_GB_CLIP_ADJ_HORZ(0) |
890 A4XX_GRAS_CL_GB_CLIP_ADJ_VERT(0));
891
892 OUT_PKT0(ring, REG_A4XX_RB_ALPHA_CONTROL, 1);
893 OUT_RING(ring, A4XX_RB_ALPHA_CONTROL_ALPHA_TEST_FUNC(FUNC_ALWAYS));
894
895 OUT_PKT0(ring, REG_A4XX_RB_FS_OUTPUT, 1);
896 OUT_RING(ring, A4XX_RB_FS_OUTPUT_SAMPLE_MASK(0xffff));
897
898 OUT_PKT0(ring, REG_A4XX_GRAS_CLEAR_CNTL, 1);
899 OUT_RING(ring, A4XX_GRAS_CLEAR_CNTL_NOT_FASTCLEAR);
900
901 OUT_PKT0(ring, REG_A4XX_GRAS_ALPHA_CONTROL, 1);
902 OUT_RING(ring, 0x0);
903
904 fd_hw_query_enable(batch, ring);
905 }
906
907 static void
908 fd4_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target)
909 {
910 __OUT_IB(ring, true, target);
911 }
912
913 void
914 fd4_emit_init(struct pipe_context *pctx)
915 {
916 struct fd_context *ctx = fd_context(pctx);
917 ctx->emit_const = fd4_emit_const;
918 ctx->emit_const_bo = fd4_emit_const_bo;
919 ctx->emit_ib = fd4_emit_ib;
920 }