freedreno/ir3: rename has_kill to no_earlyz
[mesa.git] / src / gallium / drivers / freedreno / a3xx / fd3_emit.c
1 /*
2 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
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 "util/u_format.h"
32 #include "util/u_viewport.h"
33
34 #include "freedreno_resource.h"
35 #include "freedreno_query_hw.h"
36
37 #include "fd3_emit.h"
38 #include "fd3_blend.h"
39 #include "fd3_context.h"
40 #include "fd3_program.h"
41 #include "fd3_rasterizer.h"
42 #include "fd3_texture.h"
43 #include "fd3_format.h"
44 #include "fd3_zsa.h"
45
46 static const enum adreno_state_block sb[] = {
47 [MESA_SHADER_VERTEX] = SB_VERT_SHADER,
48 [MESA_SHADER_FRAGMENT] = SB_FRAG_SHADER,
49 };
50
51 /* regid: base const register
52 * prsc or dwords: buffer containing constant values
53 * sizedwords: size of const value buffer
54 */
55 static void
56 fd3_emit_const(struct fd_ringbuffer *ring, gl_shader_stage type,
57 uint32_t regid, uint32_t offset, uint32_t sizedwords,
58 const uint32_t *dwords, struct pipe_resource *prsc)
59 {
60 uint32_t i, sz;
61 enum adreno_state_src src;
62
63 debug_assert((regid % 4) == 0);
64 debug_assert((sizedwords % 4) == 0);
65
66 if (prsc) {
67 sz = 0;
68 src = SS_INDIRECT;
69 } else {
70 sz = sizedwords;
71 src = SS_DIRECT;
72 }
73
74 OUT_PKT3(ring, CP_LOAD_STATE, 2 + sz);
75 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(regid/2) |
76 CP_LOAD_STATE_0_STATE_SRC(src) |
77 CP_LOAD_STATE_0_STATE_BLOCK(sb[type]) |
78 CP_LOAD_STATE_0_NUM_UNIT(sizedwords/2));
79 if (prsc) {
80 struct fd_bo *bo = fd_resource(prsc)->bo;
81 OUT_RELOC(ring, bo, offset,
82 CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS), 0);
83 } else {
84 OUT_RING(ring, CP_LOAD_STATE_1_EXT_SRC_ADDR(0) |
85 CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS));
86 dwords = (uint32_t *)&((uint8_t *)dwords)[offset];
87 }
88 for (i = 0; i < sz; i++) {
89 OUT_RING(ring, dwords[i]);
90 }
91 }
92
93 static void
94 fd3_emit_const_bo(struct fd_ringbuffer *ring, gl_shader_stage type, boolean write,
95 uint32_t regid, uint32_t num, struct pipe_resource **prscs, uint32_t *offsets)
96 {
97 uint32_t anum = align(num, 4);
98 uint32_t i;
99
100 debug_assert((regid % 4) == 0);
101
102 OUT_PKT3(ring, CP_LOAD_STATE, 2 + anum);
103 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(regid/2) |
104 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
105 CP_LOAD_STATE_0_STATE_BLOCK(sb[type]) |
106 CP_LOAD_STATE_0_NUM_UNIT(anum/2));
107 OUT_RING(ring, CP_LOAD_STATE_1_EXT_SRC_ADDR(0) |
108 CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS));
109
110 for (i = 0; i < num; i++) {
111 if (prscs[i]) {
112 if (write) {
113 OUT_RELOCW(ring, fd_resource(prscs[i])->bo, offsets[i], 0, 0);
114 } else {
115 OUT_RELOC(ring, fd_resource(prscs[i])->bo, offsets[i], 0, 0);
116 }
117 } else {
118 OUT_RING(ring, 0xbad00000 | (i << 16));
119 }
120 }
121
122 for (; i < anum; i++)
123 OUT_RING(ring, 0xffffffff);
124 }
125
126 #define VERT_TEX_OFF 0
127 #define FRAG_TEX_OFF 16
128 #define BASETABLE_SZ A3XX_MAX_MIP_LEVELS
129
130 static void
131 emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
132 enum adreno_state_block sb, struct fd_texture_stateobj *tex)
133 {
134 static const unsigned tex_off[] = {
135 [SB_VERT_TEX] = VERT_TEX_OFF,
136 [SB_FRAG_TEX] = FRAG_TEX_OFF,
137 };
138 static const enum adreno_state_block mipaddr[] = {
139 [SB_VERT_TEX] = SB_VERT_MIPADDR,
140 [SB_FRAG_TEX] = SB_FRAG_MIPADDR,
141 };
142 static const uint32_t bcolor_reg[] = {
143 [SB_VERT_TEX] = REG_A3XX_TPL1_TP_VS_BORDER_COLOR_BASE_ADDR,
144 [SB_FRAG_TEX] = REG_A3XX_TPL1_TP_FS_BORDER_COLOR_BASE_ADDR,
145 };
146 struct fd3_context *fd3_ctx = fd3_context(ctx);
147 bool needs_border = false;
148 unsigned i, j;
149
150 if (tex->num_samplers > 0) {
151 /* output sampler state: */
152 OUT_PKT3(ring, CP_LOAD_STATE, 2 + (2 * tex->num_samplers));
153 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(tex_off[sb]) |
154 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
155 CP_LOAD_STATE_0_STATE_BLOCK(sb) |
156 CP_LOAD_STATE_0_NUM_UNIT(tex->num_samplers));
157 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_SHADER) |
158 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
159 for (i = 0; i < tex->num_samplers; i++) {
160 static const struct fd3_sampler_stateobj dummy_sampler = {};
161 const struct fd3_sampler_stateobj *sampler = tex->samplers[i] ?
162 fd3_sampler_stateobj(tex->samplers[i]) :
163 &dummy_sampler;
164
165 OUT_RING(ring, sampler->texsamp0);
166 OUT_RING(ring, sampler->texsamp1);
167
168 needs_border |= sampler->needs_border;
169 }
170 }
171
172 if (tex->num_textures > 0) {
173 /* emit texture state: */
174 OUT_PKT3(ring, CP_LOAD_STATE, 2 + (4 * tex->num_textures));
175 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(tex_off[sb]) |
176 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
177 CP_LOAD_STATE_0_STATE_BLOCK(sb) |
178 CP_LOAD_STATE_0_NUM_UNIT(tex->num_textures));
179 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS) |
180 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
181 for (i = 0; i < tex->num_textures; i++) {
182 static const struct fd3_pipe_sampler_view dummy_view = {};
183 const struct fd3_pipe_sampler_view *view = tex->textures[i] ?
184 fd3_pipe_sampler_view(tex->textures[i]) :
185 &dummy_view;
186 OUT_RING(ring, view->texconst0);
187 OUT_RING(ring, view->texconst1);
188 OUT_RING(ring, view->texconst2 |
189 A3XX_TEX_CONST_2_INDX(BASETABLE_SZ * i));
190 OUT_RING(ring, view->texconst3);
191 }
192
193 /* emit mipaddrs: */
194 OUT_PKT3(ring, CP_LOAD_STATE, 2 + (BASETABLE_SZ * tex->num_textures));
195 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(BASETABLE_SZ * tex_off[sb]) |
196 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
197 CP_LOAD_STATE_0_STATE_BLOCK(mipaddr[sb]) |
198 CP_LOAD_STATE_0_NUM_UNIT(BASETABLE_SZ * tex->num_textures));
199 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS) |
200 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
201 for (i = 0; i < tex->num_textures; i++) {
202 static const struct fd3_pipe_sampler_view dummy_view = {
203 .base.target = PIPE_TEXTURE_1D, /* anything !PIPE_BUFFER */
204 .base.u.tex.first_level = 1,
205 };
206 const struct fd3_pipe_sampler_view *view = tex->textures[i] ?
207 fd3_pipe_sampler_view(tex->textures[i]) :
208 &dummy_view;
209 struct fd_resource *rsc = fd_resource(view->base.texture);
210 if (rsc && rsc->base.target == PIPE_BUFFER) {
211 OUT_RELOC(ring, rsc->bo, view->base.u.buf.offset, 0, 0);
212 j = 1;
213 } else {
214 unsigned start = fd_sampler_first_level(&view->base);
215 unsigned end = fd_sampler_last_level(&view->base);
216
217 for (j = 0; j < (end - start + 1); j++) {
218 struct fd_resource_slice *slice =
219 fd_resource_slice(rsc, j + start);
220 OUT_RELOC(ring, rsc->bo, slice->offset, 0, 0);
221 }
222 }
223
224 /* pad the remaining entries w/ null: */
225 for (; j < BASETABLE_SZ; j++) {
226 OUT_RING(ring, 0x00000000);
227 }
228 }
229 }
230
231 if (needs_border) {
232 unsigned off;
233 void *ptr;
234
235 u_upload_alloc(fd3_ctx->border_color_uploader,
236 0, BORDER_COLOR_UPLOAD_SIZE,
237 BORDER_COLOR_UPLOAD_SIZE, &off,
238 &fd3_ctx->border_color_buf,
239 &ptr);
240
241 fd_setup_border_colors(tex, ptr, tex_off[sb]);
242
243 OUT_PKT0(ring, bcolor_reg[sb], 1);
244 OUT_RELOC(ring, fd_resource(fd3_ctx->border_color_buf)->bo, off, 0, 0);
245
246 u_upload_unmap(fd3_ctx->border_color_uploader);
247 }
248 }
249
250 /* emit texture state for mem->gmem restore operation.. eventually it would
251 * be good to get rid of this and use normal CSO/etc state for more of these
252 * special cases, but for now the compiler is not sufficient..
253 *
254 * Also, for using normal state, not quite sure how to handle the special
255 * case format (fd3_gmem_restore_format()) stuff for restoring depth/stencil.
256 */
257 void
258 fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring,
259 struct pipe_surface **psurf,
260 int bufs)
261 {
262 int i, j;
263
264 /* output sampler state: */
265 OUT_PKT3(ring, CP_LOAD_STATE, 2 + 2 * bufs);
266 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(FRAG_TEX_OFF) |
267 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
268 CP_LOAD_STATE_0_STATE_BLOCK(SB_FRAG_TEX) |
269 CP_LOAD_STATE_0_NUM_UNIT(bufs));
270 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_SHADER) |
271 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
272 for (i = 0; i < bufs; i++) {
273 OUT_RING(ring, A3XX_TEX_SAMP_0_XY_MAG(A3XX_TEX_NEAREST) |
274 A3XX_TEX_SAMP_0_XY_MIN(A3XX_TEX_NEAREST) |
275 A3XX_TEX_SAMP_0_WRAP_S(A3XX_TEX_CLAMP_TO_EDGE) |
276 A3XX_TEX_SAMP_0_WRAP_T(A3XX_TEX_CLAMP_TO_EDGE) |
277 A3XX_TEX_SAMP_0_WRAP_R(A3XX_TEX_REPEAT));
278 OUT_RING(ring, 0x00000000);
279 }
280
281 /* emit texture state: */
282 OUT_PKT3(ring, CP_LOAD_STATE, 2 + 4 * bufs);
283 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(FRAG_TEX_OFF) |
284 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
285 CP_LOAD_STATE_0_STATE_BLOCK(SB_FRAG_TEX) |
286 CP_LOAD_STATE_0_NUM_UNIT(bufs));
287 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS) |
288 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
289 for (i = 0; i < bufs; i++) {
290 if (!psurf[i]) {
291 OUT_RING(ring, A3XX_TEX_CONST_0_TYPE(A3XX_TEX_2D) |
292 A3XX_TEX_CONST_0_SWIZ_X(A3XX_TEX_ONE) |
293 A3XX_TEX_CONST_0_SWIZ_Y(A3XX_TEX_ONE) |
294 A3XX_TEX_CONST_0_SWIZ_Z(A3XX_TEX_ONE) |
295 A3XX_TEX_CONST_0_SWIZ_W(A3XX_TEX_ONE));
296 OUT_RING(ring, 0x00000000);
297 OUT_RING(ring, A3XX_TEX_CONST_2_INDX(BASETABLE_SZ * i));
298 OUT_RING(ring, 0x00000000);
299 continue;
300 }
301
302 struct fd_resource *rsc = fd_resource(psurf[i]->texture);
303 enum pipe_format format = fd_gmem_restore_format(psurf[i]->format);
304 /* The restore blit_zs shader expects stencil in sampler 0, and depth
305 * in sampler 1
306 */
307 if (rsc->stencil && i == 0) {
308 rsc = rsc->stencil;
309 format = fd_gmem_restore_format(rsc->base.format);
310 }
311
312 /* note: PIPE_BUFFER disallowed for surfaces */
313 unsigned lvl = psurf[i]->u.tex.level;
314 struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl);
315
316 debug_assert(psurf[i]->u.tex.first_layer == psurf[i]->u.tex.last_layer);
317
318 OUT_RING(ring, A3XX_TEX_CONST_0_FMT(fd3_pipe2tex(format)) |
319 A3XX_TEX_CONST_0_TYPE(A3XX_TEX_2D) |
320 fd3_tex_swiz(format, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
321 PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W));
322 OUT_RING(ring, A3XX_TEX_CONST_1_FETCHSIZE(TFETCH_DISABLE) |
323 A3XX_TEX_CONST_1_WIDTH(psurf[i]->width) |
324 A3XX_TEX_CONST_1_HEIGHT(psurf[i]->height));
325 OUT_RING(ring, A3XX_TEX_CONST_2_PITCH(slice->pitch * rsc->cpp) |
326 A3XX_TEX_CONST_2_INDX(BASETABLE_SZ * i));
327 OUT_RING(ring, 0x00000000);
328 }
329
330 /* emit mipaddrs: */
331 OUT_PKT3(ring, CP_LOAD_STATE, 2 + BASETABLE_SZ * bufs);
332 OUT_RING(ring, CP_LOAD_STATE_0_DST_OFF(BASETABLE_SZ * FRAG_TEX_OFF) |
333 CP_LOAD_STATE_0_STATE_SRC(SS_DIRECT) |
334 CP_LOAD_STATE_0_STATE_BLOCK(SB_FRAG_MIPADDR) |
335 CP_LOAD_STATE_0_NUM_UNIT(BASETABLE_SZ * bufs));
336 OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS) |
337 CP_LOAD_STATE_1_EXT_SRC_ADDR(0));
338 for (i = 0; i < bufs; i++) {
339 if (psurf[i]) {
340 struct fd_resource *rsc = fd_resource(psurf[i]->texture);
341 /* Matches above logic for blit_zs shader */
342 if (rsc->stencil && i == 0)
343 rsc = rsc->stencil;
344 unsigned lvl = psurf[i]->u.tex.level;
345 uint32_t offset = fd_resource_offset(rsc, lvl, psurf[i]->u.tex.first_layer);
346 OUT_RELOC(ring, rsc->bo, offset, 0, 0);
347 } else {
348 OUT_RING(ring, 0x00000000);
349 }
350
351 /* pad the remaining entries w/ null: */
352 for (j = 1; j < BASETABLE_SZ; j++) {
353 OUT_RING(ring, 0x00000000);
354 }
355 }
356 }
357
358 void
359 fd3_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd3_emit *emit)
360 {
361 int32_t i, j, last = -1;
362 uint32_t total_in = 0;
363 const struct fd_vertex_state *vtx = emit->vtx;
364 const struct ir3_shader_variant *vp = fd3_emit_get_vp(emit);
365 unsigned vertex_regid = regid(63, 0);
366 unsigned instance_regid = regid(63, 0);
367 unsigned vtxcnt_regid = regid(63, 0);
368
369 /* Note that sysvals come *after* normal inputs: */
370 for (i = 0; i < vp->inputs_count; i++) {
371 if (!vp->inputs[i].compmask)
372 continue;
373 if (vp->inputs[i].sysval) {
374 switch(vp->inputs[i].slot) {
375 case SYSTEM_VALUE_FIRST_VERTEX:
376 /* handled elsewhere */
377 break;
378 case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE:
379 vertex_regid = vp->inputs[i].regid;
380 break;
381 case SYSTEM_VALUE_INSTANCE_ID:
382 instance_regid = vp->inputs[i].regid;
383 break;
384 case SYSTEM_VALUE_VERTEX_CNT:
385 vtxcnt_regid = vp->inputs[i].regid;
386 break;
387 default:
388 unreachable("invalid system value");
389 break;
390 }
391 } else if (i < vtx->vtx->num_elements) {
392 last = i;
393 }
394 }
395
396 for (i = 0, j = 0; i <= last; i++) {
397 assert(!vp->inputs[i].sysval);
398 if (vp->inputs[i].compmask) {
399 struct pipe_vertex_element *elem = &vtx->vtx->pipe[i];
400 const struct pipe_vertex_buffer *vb =
401 &vtx->vertexbuf.vb[elem->vertex_buffer_index];
402 struct fd_resource *rsc = fd_resource(vb->buffer.resource);
403 enum pipe_format pfmt = elem->src_format;
404 enum a3xx_vtx_fmt fmt = fd3_pipe2vtx(pfmt);
405 bool switchnext = (i != last) ||
406 (vertex_regid != regid(63, 0)) ||
407 (instance_regid != regid(63, 0)) ||
408 (vtxcnt_regid != regid(63, 0));
409 bool isint = util_format_is_pure_integer(pfmt);
410 uint32_t off = vb->buffer_offset + elem->src_offset;
411 uint32_t fs = util_format_get_blocksize(pfmt);
412
413 #ifdef DEBUG
414 /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
415 * should mesa/st be protecting us from this?
416 */
417 if (off > fd_bo_size(rsc->bo))
418 continue;
419 #endif
420
421 debug_assert(fmt != ~0);
422
423 OUT_PKT0(ring, REG_A3XX_VFD_FETCH(j), 2);
424 OUT_RING(ring, A3XX_VFD_FETCH_INSTR_0_FETCHSIZE(fs - 1) |
425 A3XX_VFD_FETCH_INSTR_0_BUFSTRIDE(vb->stride) |
426 COND(switchnext, A3XX_VFD_FETCH_INSTR_0_SWITCHNEXT) |
427 A3XX_VFD_FETCH_INSTR_0_INDEXCODE(j) |
428 COND(elem->instance_divisor, A3XX_VFD_FETCH_INSTR_0_INSTANCED) |
429 A3XX_VFD_FETCH_INSTR_0_STEPRATE(MAX2(1, elem->instance_divisor)));
430 OUT_RELOC(ring, rsc->bo, off, 0, 0);
431
432 OUT_PKT0(ring, REG_A3XX_VFD_DECODE_INSTR(j), 1);
433 OUT_RING(ring, A3XX_VFD_DECODE_INSTR_CONSTFILL |
434 A3XX_VFD_DECODE_INSTR_WRITEMASK(vp->inputs[i].compmask) |
435 A3XX_VFD_DECODE_INSTR_FORMAT(fmt) |
436 A3XX_VFD_DECODE_INSTR_SWAP(fd3_pipe2swap(pfmt)) |
437 A3XX_VFD_DECODE_INSTR_REGID(vp->inputs[i].regid) |
438 A3XX_VFD_DECODE_INSTR_SHIFTCNT(fs) |
439 A3XX_VFD_DECODE_INSTR_LASTCOMPVALID |
440 COND(isint, A3XX_VFD_DECODE_INSTR_INT) |
441 COND(switchnext, A3XX_VFD_DECODE_INSTR_SWITCHNEXT));
442
443 total_in += vp->inputs[i].ncomp;
444 j++;
445 }
446 }
447
448 /* hw doesn't like to be configured for zero vbo's, it seems: */
449 if (last < 0) {
450 /* just recycle the shader bo, we just need to point to *something*
451 * valid:
452 */
453 struct fd_bo *dummy_vbo = vp->bo;
454 bool switchnext = (vertex_regid != regid(63, 0)) ||
455 (instance_regid != regid(63, 0)) ||
456 (vtxcnt_regid != regid(63, 0));
457
458 OUT_PKT0(ring, REG_A3XX_VFD_FETCH(0), 2);
459 OUT_RING(ring, A3XX_VFD_FETCH_INSTR_0_FETCHSIZE(0) |
460 A3XX_VFD_FETCH_INSTR_0_BUFSTRIDE(0) |
461 COND(switchnext, A3XX_VFD_FETCH_INSTR_0_SWITCHNEXT) |
462 A3XX_VFD_FETCH_INSTR_0_INDEXCODE(0) |
463 A3XX_VFD_FETCH_INSTR_0_STEPRATE(1));
464 OUT_RELOC(ring, dummy_vbo, 0, 0, 0);
465
466 OUT_PKT0(ring, REG_A3XX_VFD_DECODE_INSTR(0), 1);
467 OUT_RING(ring, A3XX_VFD_DECODE_INSTR_CONSTFILL |
468 A3XX_VFD_DECODE_INSTR_WRITEMASK(0x1) |
469 A3XX_VFD_DECODE_INSTR_FORMAT(VFMT_8_UNORM) |
470 A3XX_VFD_DECODE_INSTR_SWAP(XYZW) |
471 A3XX_VFD_DECODE_INSTR_REGID(regid(0,0)) |
472 A3XX_VFD_DECODE_INSTR_SHIFTCNT(1) |
473 A3XX_VFD_DECODE_INSTR_LASTCOMPVALID |
474 COND(switchnext, A3XX_VFD_DECODE_INSTR_SWITCHNEXT));
475
476 total_in = 1;
477 j = 1;
478 }
479
480 OUT_PKT0(ring, REG_A3XX_VFD_CONTROL_0, 2);
481 OUT_RING(ring, A3XX_VFD_CONTROL_0_TOTALATTRTOVS(total_in) |
482 A3XX_VFD_CONTROL_0_PACKETSIZE(2) |
483 A3XX_VFD_CONTROL_0_STRMDECINSTRCNT(j) |
484 A3XX_VFD_CONTROL_0_STRMFETCHINSTRCNT(j));
485 OUT_RING(ring, A3XX_VFD_CONTROL_1_MAXSTORAGE(1) | // XXX
486 A3XX_VFD_CONTROL_1_REGID4VTX(vertex_regid) |
487 A3XX_VFD_CONTROL_1_REGID4INST(instance_regid));
488
489 OUT_PKT0(ring, REG_A3XX_VFD_VS_THREADING_THRESHOLD, 1);
490 OUT_RING(ring, A3XX_VFD_VS_THREADING_THRESHOLD_REGID_THRESHOLD(15) |
491 A3XX_VFD_VS_THREADING_THRESHOLD_REGID_VTXCNT(vtxcnt_regid));
492 }
493
494 void
495 fd3_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
496 struct fd3_emit *emit)
497 {
498 const struct ir3_shader_variant *vp = fd3_emit_get_vp(emit);
499 const struct ir3_shader_variant *fp = fd3_emit_get_fp(emit);
500 const enum fd_dirty_3d_state dirty = emit->dirty;
501
502 emit_marker(ring, 5);
503
504 if (dirty & FD_DIRTY_SAMPLE_MASK) {
505 OUT_PKT0(ring, REG_A3XX_RB_MSAA_CONTROL, 1);
506 OUT_RING(ring, A3XX_RB_MSAA_CONTROL_DISABLE |
507 A3XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE) |
508 A3XX_RB_MSAA_CONTROL_SAMPLE_MASK(ctx->sample_mask));
509 }
510
511 if ((dirty & (FD_DIRTY_ZSA | FD_DIRTY_PROG | FD_DIRTY_BLEND_DUAL)) &&
512 !emit->binning_pass) {
513 uint32_t val = fd3_zsa_stateobj(ctx->zsa)->rb_render_control |
514 fd3_blend_stateobj(ctx->blend)->rb_render_control;
515
516 val |= COND(fp->frag_face, A3XX_RB_RENDER_CONTROL_FACENESS);
517 val |= COND(fp->frag_coord, A3XX_RB_RENDER_CONTROL_XCOORD |
518 A3XX_RB_RENDER_CONTROL_YCOORD |
519 A3XX_RB_RENDER_CONTROL_ZCOORD |
520 A3XX_RB_RENDER_CONTROL_WCOORD);
521
522 /* I suppose if we needed to (which I don't *think* we need
523 * to), we could emit this for binning pass too. But we
524 * would need to keep a different patch-list for binning
525 * vs render pass.
526 */
527
528 OUT_PKT0(ring, REG_A3XX_RB_RENDER_CONTROL, 1);
529 OUT_RINGP(ring, val, &ctx->batch->rbrc_patches);
530 }
531
532 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_STENCIL_REF)) {
533 struct fd3_zsa_stateobj *zsa = fd3_zsa_stateobj(ctx->zsa);
534 struct pipe_stencil_ref *sr = &ctx->stencil_ref;
535
536 OUT_PKT0(ring, REG_A3XX_RB_ALPHA_REF, 1);
537 OUT_RING(ring, zsa->rb_alpha_ref);
538
539 OUT_PKT0(ring, REG_A3XX_RB_STENCIL_CONTROL, 1);
540 OUT_RING(ring, zsa->rb_stencil_control);
541
542 OUT_PKT0(ring, REG_A3XX_RB_STENCILREFMASK, 2);
543 OUT_RING(ring, zsa->rb_stencilrefmask |
544 A3XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
545 OUT_RING(ring, zsa->rb_stencilrefmask_bf |
546 A3XX_RB_STENCILREFMASK_BF_STENCILREF(sr->ref_value[1]));
547 }
548
549 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_RASTERIZER | FD_DIRTY_PROG)) {
550 uint32_t val = fd3_zsa_stateobj(ctx->zsa)->rb_depth_control;
551 if (fp->writes_pos) {
552 val |= A3XX_RB_DEPTH_CONTROL_FRAG_WRITES_Z;
553 val |= A3XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE;
554 }
555 if (fp->no_earlyz) {
556 val |= A3XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE;
557 }
558 if (!ctx->rasterizer->depth_clip_near) {
559 val |= A3XX_RB_DEPTH_CONTROL_Z_CLAMP_ENABLE;
560 }
561 OUT_PKT0(ring, REG_A3XX_RB_DEPTH_CONTROL, 1);
562 OUT_RING(ring, val);
563 }
564
565 if (dirty & FD_DIRTY_RASTERIZER) {
566 struct fd3_rasterizer_stateobj *rasterizer =
567 fd3_rasterizer_stateobj(ctx->rasterizer);
568
569 OUT_PKT0(ring, REG_A3XX_GRAS_SU_MODE_CONTROL, 1);
570 OUT_RING(ring, rasterizer->gras_su_mode_control);
571
572 OUT_PKT0(ring, REG_A3XX_GRAS_SU_POINT_MINMAX, 2);
573 OUT_RING(ring, rasterizer->gras_su_point_minmax);
574 OUT_RING(ring, rasterizer->gras_su_point_size);
575
576 OUT_PKT0(ring, REG_A3XX_GRAS_SU_POLY_OFFSET_SCALE, 2);
577 OUT_RING(ring, rasterizer->gras_su_poly_offset_scale);
578 OUT_RING(ring, rasterizer->gras_su_poly_offset_offset);
579 }
580
581 if (dirty & (FD_DIRTY_RASTERIZER | FD_DIRTY_PROG)) {
582 uint32_t val = fd3_rasterizer_stateobj(ctx->rasterizer)
583 ->gras_cl_clip_cntl;
584 uint8_t planes = ctx->rasterizer->clip_plane_enable;
585 val |= COND(fp->writes_pos, A3XX_GRAS_CL_CLIP_CNTL_ZCLIP_DISABLE);
586 val |= COND(fp->frag_coord, A3XX_GRAS_CL_CLIP_CNTL_ZCOORD |
587 A3XX_GRAS_CL_CLIP_CNTL_WCOORD);
588 if (!emit->key.ucp_enables)
589 val |= A3XX_GRAS_CL_CLIP_CNTL_NUM_USER_CLIP_PLANES(
590 MIN2(util_bitcount(planes), 6));
591 OUT_PKT0(ring, REG_A3XX_GRAS_CL_CLIP_CNTL, 1);
592 OUT_RING(ring, val);
593 }
594
595 if (dirty & (FD_DIRTY_RASTERIZER | FD_DIRTY_PROG | FD_DIRTY_UCP)) {
596 uint32_t planes = ctx->rasterizer->clip_plane_enable;
597 int count = 0;
598
599 if (emit->key.ucp_enables)
600 planes = 0;
601
602 while (planes && count < 6) {
603 int i = ffs(planes) - 1;
604
605 planes &= ~(1U << i);
606 fd_wfi(ctx->batch, ring);
607 OUT_PKT0(ring, REG_A3XX_GRAS_CL_USER_PLANE(count++), 4);
608 OUT_RING(ring, fui(ctx->ucp.ucp[i][0]));
609 OUT_RING(ring, fui(ctx->ucp.ucp[i][1]));
610 OUT_RING(ring, fui(ctx->ucp.ucp[i][2]));
611 OUT_RING(ring, fui(ctx->ucp.ucp[i][3]));
612 }
613 }
614
615 /* NOTE: since primitive_restart is not actually part of any
616 * state object, we need to make sure that we always emit
617 * PRIM_VTX_CNTL.. either that or be more clever and detect
618 * when it changes.
619 */
620 if (emit->info) {
621 const struct pipe_draw_info *info = emit->info;
622 uint32_t val = fd3_rasterizer_stateobj(ctx->rasterizer)
623 ->pc_prim_vtx_cntl;
624
625 if (!emit->binning_pass) {
626 uint32_t stride_in_vpc = align(fp->total_in, 4) / 4;
627 if (stride_in_vpc > 0)
628 stride_in_vpc = MAX2(stride_in_vpc, 2);
629 val |= A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(stride_in_vpc);
630 }
631
632 if (info->index_size && info->primitive_restart) {
633 val |= A3XX_PC_PRIM_VTX_CNTL_PRIMITIVE_RESTART;
634 }
635
636 val |= COND(vp->writes_psize, A3XX_PC_PRIM_VTX_CNTL_PSIZE);
637
638 OUT_PKT0(ring, REG_A3XX_PC_PRIM_VTX_CNTL, 1);
639 OUT_RING(ring, val);
640 }
641
642 if (dirty & (FD_DIRTY_SCISSOR | FD_DIRTY_RASTERIZER | FD_DIRTY_VIEWPORT)) {
643 struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
644 int minx = scissor->minx;
645 int miny = scissor->miny;
646 int maxx = scissor->maxx;
647 int maxy = scissor->maxy;
648
649 /* Unfortunately there is no separate depth clip disable, only an all
650 * or nothing deal. So when we disable clipping, we must handle the
651 * viewport clip via scissors.
652 */
653 if (!ctx->rasterizer->depth_clip_near) {
654 struct pipe_viewport_state *vp = &ctx->viewport;
655 minx = MAX2(minx, (int)floorf(vp->translate[0] - fabsf(vp->scale[0])));
656 miny = MAX2(miny, (int)floorf(vp->translate[1] - fabsf(vp->scale[1])));
657 maxx = MIN2(maxx, (int)ceilf(vp->translate[0] + fabsf(vp->scale[0])));
658 maxy = MIN2(maxy, (int)ceilf(vp->translate[1] + fabsf(vp->scale[1])));
659 }
660
661 OUT_PKT0(ring, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL, 2);
662 OUT_RING(ring, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(minx) |
663 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(miny));
664 OUT_RING(ring, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(maxx - 1) |
665 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(maxy - 1));
666
667 ctx->batch->max_scissor.minx = MIN2(ctx->batch->max_scissor.minx, minx);
668 ctx->batch->max_scissor.miny = MIN2(ctx->batch->max_scissor.miny, miny);
669 ctx->batch->max_scissor.maxx = MAX2(ctx->batch->max_scissor.maxx, maxx);
670 ctx->batch->max_scissor.maxy = MAX2(ctx->batch->max_scissor.maxy, maxy);
671 }
672
673 if (dirty & FD_DIRTY_VIEWPORT) {
674 fd_wfi(ctx->batch, ring);
675 OUT_PKT0(ring, REG_A3XX_GRAS_CL_VPORT_XOFFSET, 6);
676 OUT_RING(ring, A3XX_GRAS_CL_VPORT_XOFFSET(ctx->viewport.translate[0] - 0.5));
677 OUT_RING(ring, A3XX_GRAS_CL_VPORT_XSCALE(ctx->viewport.scale[0]));
678 OUT_RING(ring, A3XX_GRAS_CL_VPORT_YOFFSET(ctx->viewport.translate[1] - 0.5));
679 OUT_RING(ring, A3XX_GRAS_CL_VPORT_YSCALE(ctx->viewport.scale[1]));
680 OUT_RING(ring, A3XX_GRAS_CL_VPORT_ZOFFSET(ctx->viewport.translate[2]));
681 OUT_RING(ring, A3XX_GRAS_CL_VPORT_ZSCALE(ctx->viewport.scale[2]));
682 }
683
684 if (dirty & (FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER | FD_DIRTY_FRAMEBUFFER)) {
685 float zmin, zmax;
686 int depth = 24;
687 if (ctx->batch->framebuffer.zsbuf) {
688 depth = util_format_get_component_bits(
689 pipe_surface_format(ctx->batch->framebuffer.zsbuf),
690 UTIL_FORMAT_COLORSPACE_ZS, 0);
691 }
692 util_viewport_zmin_zmax(&ctx->viewport, ctx->rasterizer->clip_halfz,
693 &zmin, &zmax);
694
695 OUT_PKT0(ring, REG_A3XX_RB_Z_CLAMP_MIN, 2);
696 if (depth == 32) {
697 OUT_RING(ring, (uint32_t)(zmin * 0xffffffff));
698 OUT_RING(ring, (uint32_t)(zmax * 0xffffffff));
699 } else if (depth == 16) {
700 OUT_RING(ring, (uint32_t)(zmin * 0xffff));
701 OUT_RING(ring, (uint32_t)(zmax * 0xffff));
702 } else {
703 OUT_RING(ring, (uint32_t)(zmin * 0xffffff));
704 OUT_RING(ring, (uint32_t)(zmax * 0xffffff));
705 }
706 }
707
708 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_FRAMEBUFFER | FD_DIRTY_BLEND_DUAL)) {
709 struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
710 int nr_cbufs = pfb->nr_cbufs;
711 if (fd3_blend_stateobj(ctx->blend)->rb_render_control &
712 A3XX_RB_RENDER_CONTROL_DUAL_COLOR_IN_ENABLE)
713 nr_cbufs++;
714 fd3_program_emit(ring, emit, nr_cbufs, pfb->cbufs);
715 }
716
717 /* TODO we should not need this or fd_wfi() before emit_constants():
718 */
719 OUT_PKT3(ring, CP_EVENT_WRITE, 1);
720 OUT_RING(ring, HLSQ_FLUSH);
721
722 if (emit->prog == &ctx->prog) { /* evil hack to deal sanely with clear path */
723 ir3_emit_vs_consts(vp, ring, ctx, emit->info);
724 if (!emit->binning_pass)
725 ir3_emit_fs_consts(fp, ring, ctx);
726 }
727
728 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_FRAMEBUFFER)) {
729 struct fd3_blend_stateobj *blend = fd3_blend_stateobj(ctx->blend);
730 uint32_t i;
731
732 for (i = 0; i < ARRAY_SIZE(blend->rb_mrt); i++) {
733 enum pipe_format format =
734 pipe_surface_format(ctx->batch->framebuffer.cbufs[i]);
735 const struct util_format_description *desc =
736 util_format_description(format);
737 bool is_float = util_format_is_float(format);
738 bool is_int = util_format_is_pure_integer(format);
739 bool has_alpha = util_format_has_alpha(format);
740 uint32_t control = blend->rb_mrt[i].control;
741 uint32_t blend_control = blend->rb_mrt[i].blend_control_alpha;
742
743 if (is_int) {
744 control &= (A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK |
745 A3XX_RB_MRT_CONTROL_DITHER_MODE__MASK);
746 control |= A3XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY);
747 }
748
749 if (format == PIPE_FORMAT_NONE)
750 control &= ~A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK;
751
752 if (has_alpha) {
753 blend_control |= blend->rb_mrt[i].blend_control_rgb;
754 } else {
755 blend_control |= blend->rb_mrt[i].blend_control_no_alpha_rgb;
756 control &= ~A3XX_RB_MRT_CONTROL_BLEND2;
757 }
758
759 if (format && util_format_get_component_bits(
760 format, UTIL_FORMAT_COLORSPACE_RGB, 0) < 8) {
761 const struct pipe_rt_blend_state *rt;
762 if (ctx->blend->independent_blend_enable)
763 rt = &ctx->blend->rt[i];
764 else
765 rt = &ctx->blend->rt[0];
766
767 if (!util_format_colormask_full(desc, rt->colormask))
768 control |= A3XX_RB_MRT_CONTROL_READ_DEST_ENABLE;
769 }
770
771 OUT_PKT0(ring, REG_A3XX_RB_MRT_CONTROL(i), 1);
772 OUT_RING(ring, control);
773
774 OUT_PKT0(ring, REG_A3XX_RB_MRT_BLEND_CONTROL(i), 1);
775 OUT_RING(ring, blend_control |
776 COND(!is_float, A3XX_RB_MRT_BLEND_CONTROL_CLAMP_ENABLE));
777 }
778 }
779
780 if (dirty & FD_DIRTY_BLEND_COLOR) {
781 struct pipe_blend_color *bcolor = &ctx->blend_color;
782 OUT_PKT0(ring, REG_A3XX_RB_BLEND_RED, 4);
783 OUT_RING(ring, A3XX_RB_BLEND_RED_UINT(bcolor->color[0] * 255.0) |
784 A3XX_RB_BLEND_RED_FLOAT(bcolor->color[0]));
785 OUT_RING(ring, A3XX_RB_BLEND_GREEN_UINT(bcolor->color[1] * 255.0) |
786 A3XX_RB_BLEND_GREEN_FLOAT(bcolor->color[1]));
787 OUT_RING(ring, A3XX_RB_BLEND_BLUE_UINT(bcolor->color[2] * 255.0) |
788 A3XX_RB_BLEND_BLUE_FLOAT(bcolor->color[2]));
789 OUT_RING(ring, A3XX_RB_BLEND_ALPHA_UINT(bcolor->color[3] * 255.0) |
790 A3XX_RB_BLEND_ALPHA_FLOAT(bcolor->color[3]));
791 }
792
793 if (dirty & FD_DIRTY_TEX)
794 fd_wfi(ctx->batch, ring);
795
796 if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & FD_DIRTY_SHADER_TEX)
797 emit_textures(ctx, ring, SB_VERT_TEX, &ctx->tex[PIPE_SHADER_VERTEX]);
798
799 if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_TEX)
800 emit_textures(ctx, ring, SB_FRAG_TEX, &ctx->tex[PIPE_SHADER_FRAGMENT]);
801 }
802
803 /* emit setup at begin of new cmdstream buffer (don't rely on previous
804 * state, there could have been a context switch between ioctls):
805 */
806 void
807 fd3_emit_restore(struct fd_batch *batch, struct fd_ringbuffer *ring)
808 {
809 struct fd_context *ctx = batch->ctx;
810 struct fd3_context *fd3_ctx = fd3_context(ctx);
811 int i;
812
813 if (ctx->screen->gpu_id == 320) {
814 OUT_PKT3(ring, CP_REG_RMW, 3);
815 OUT_RING(ring, REG_A3XX_RBBM_CLOCK_CTL);
816 OUT_RING(ring, 0xfffcffff);
817 OUT_RING(ring, 0x00000000);
818 }
819
820 fd_wfi(batch, ring);
821 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
822 OUT_RING(ring, 0x00007fff);
823
824 OUT_PKT0(ring, REG_A3XX_SP_VS_PVT_MEM_PARAM_REG, 3);
825 OUT_RING(ring, 0x08000001); /* SP_VS_PVT_MEM_CTRL_REG */
826 OUT_RELOC(ring, fd3_ctx->vs_pvt_mem, 0,0,0); /* SP_VS_PVT_MEM_ADDR_REG */
827 OUT_RING(ring, 0x00000000); /* SP_VS_PVT_MEM_SIZE_REG */
828
829 OUT_PKT0(ring, REG_A3XX_SP_FS_PVT_MEM_PARAM_REG, 3);
830 OUT_RING(ring, 0x08000001); /* SP_FS_PVT_MEM_CTRL_REG */
831 OUT_RELOC(ring, fd3_ctx->fs_pvt_mem, 0,0,0); /* SP_FS_PVT_MEM_ADDR_REG */
832 OUT_RING(ring, 0x00000000); /* SP_FS_PVT_MEM_SIZE_REG */
833
834 OUT_PKT0(ring, REG_A3XX_PC_VERTEX_REUSE_BLOCK_CNTL, 1);
835 OUT_RING(ring, 0x0000000b); /* PC_VERTEX_REUSE_BLOCK_CNTL */
836
837 OUT_PKT0(ring, REG_A3XX_GRAS_SC_CONTROL, 1);
838 OUT_RING(ring, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS) |
839 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE) |
840 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
841
842 OUT_PKT0(ring, REG_A3XX_RB_MSAA_CONTROL, 2);
843 OUT_RING(ring, A3XX_RB_MSAA_CONTROL_DISABLE |
844 A3XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE) |
845 A3XX_RB_MSAA_CONTROL_SAMPLE_MASK(0xffff));
846 OUT_RING(ring, 0x00000000); /* RB_ALPHA_REF */
847
848 OUT_PKT0(ring, REG_A3XX_GRAS_CL_GB_CLIP_ADJ, 1);
849 OUT_RING(ring, A3XX_GRAS_CL_GB_CLIP_ADJ_HORZ(0) |
850 A3XX_GRAS_CL_GB_CLIP_ADJ_VERT(0));
851
852 OUT_PKT0(ring, REG_A3XX_GRAS_TSE_DEBUG_ECO, 1);
853 OUT_RING(ring, 0x00000001); /* GRAS_TSE_DEBUG_ECO */
854
855 OUT_PKT0(ring, REG_A3XX_TPL1_TP_VS_TEX_OFFSET, 1);
856 OUT_RING(ring, A3XX_TPL1_TP_VS_TEX_OFFSET_SAMPLEROFFSET(VERT_TEX_OFF) |
857 A3XX_TPL1_TP_VS_TEX_OFFSET_MEMOBJOFFSET(VERT_TEX_OFF) |
858 A3XX_TPL1_TP_VS_TEX_OFFSET_BASETABLEPTR(BASETABLE_SZ * VERT_TEX_OFF));
859
860 OUT_PKT0(ring, REG_A3XX_TPL1_TP_FS_TEX_OFFSET, 1);
861 OUT_RING(ring, A3XX_TPL1_TP_FS_TEX_OFFSET_SAMPLEROFFSET(FRAG_TEX_OFF) |
862 A3XX_TPL1_TP_FS_TEX_OFFSET_MEMOBJOFFSET(FRAG_TEX_OFF) |
863 A3XX_TPL1_TP_FS_TEX_OFFSET_BASETABLEPTR(BASETABLE_SZ * FRAG_TEX_OFF));
864
865 OUT_PKT0(ring, REG_A3XX_VPC_VARY_CYLWRAP_ENABLE_0, 2);
866 OUT_RING(ring, 0x00000000); /* VPC_VARY_CYLWRAP_ENABLE_0 */
867 OUT_RING(ring, 0x00000000); /* VPC_VARY_CYLWRAP_ENABLE_1 */
868
869 OUT_PKT0(ring, REG_A3XX_UNKNOWN_0E43, 1);
870 OUT_RING(ring, 0x00000001); /* UNKNOWN_0E43 */
871
872 OUT_PKT0(ring, REG_A3XX_UNKNOWN_0F03, 1);
873 OUT_RING(ring, 0x00000001); /* UNKNOWN_0F03 */
874
875 OUT_PKT0(ring, REG_A3XX_UNKNOWN_0EE0, 1);
876 OUT_RING(ring, 0x00000003); /* UNKNOWN_0EE0 */
877
878 OUT_PKT0(ring, REG_A3XX_UNKNOWN_0C3D, 1);
879 OUT_RING(ring, 0x00000001); /* UNKNOWN_0C3D */
880
881 OUT_PKT0(ring, REG_A3XX_HLSQ_PERFCOUNTER0_SELECT, 1);
882 OUT_RING(ring, 0x00000000); /* HLSQ_PERFCOUNTER0_SELECT */
883
884 OUT_PKT0(ring, REG_A3XX_HLSQ_CONST_VSPRESV_RANGE_REG, 2);
885 OUT_RING(ring, A3XX_HLSQ_CONST_VSPRESV_RANGE_REG_STARTENTRY(0) |
886 A3XX_HLSQ_CONST_VSPRESV_RANGE_REG_ENDENTRY(0));
887 OUT_RING(ring, A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_STARTENTRY(0) |
888 A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_ENDENTRY(0));
889
890 fd3_emit_cache_flush(batch, ring);
891
892 OUT_PKT0(ring, REG_A3XX_GRAS_CL_CLIP_CNTL, 1);
893 OUT_RING(ring, 0x00000000); /* GRAS_CL_CLIP_CNTL */
894
895 OUT_PKT0(ring, REG_A3XX_GRAS_SU_POINT_MINMAX, 2);
896 OUT_RING(ring, 0xffc00010); /* GRAS_SU_POINT_MINMAX */
897 OUT_RING(ring, 0x00000008); /* GRAS_SU_POINT_SIZE */
898
899 OUT_PKT0(ring, REG_A3XX_PC_RESTART_INDEX, 1);
900 OUT_RING(ring, 0xffffffff); /* PC_RESTART_INDEX */
901
902 OUT_PKT0(ring, REG_A3XX_RB_WINDOW_OFFSET, 1);
903 OUT_RING(ring, A3XX_RB_WINDOW_OFFSET_X(0) |
904 A3XX_RB_WINDOW_OFFSET_Y(0));
905
906 OUT_PKT0(ring, REG_A3XX_RB_BLEND_RED, 4);
907 OUT_RING(ring, A3XX_RB_BLEND_RED_UINT(0) |
908 A3XX_RB_BLEND_RED_FLOAT(0.0));
909 OUT_RING(ring, A3XX_RB_BLEND_GREEN_UINT(0) |
910 A3XX_RB_BLEND_GREEN_FLOAT(0.0));
911 OUT_RING(ring, A3XX_RB_BLEND_BLUE_UINT(0) |
912 A3XX_RB_BLEND_BLUE_FLOAT(0.0));
913 OUT_RING(ring, A3XX_RB_BLEND_ALPHA_UINT(0xff) |
914 A3XX_RB_BLEND_ALPHA_FLOAT(1.0));
915
916 for (i = 0; i < 6; i++) {
917 OUT_PKT0(ring, REG_A3XX_GRAS_CL_USER_PLANE(i), 4);
918 OUT_RING(ring, 0x00000000); /* GRAS_CL_USER_PLANE[i].X */
919 OUT_RING(ring, 0x00000000); /* GRAS_CL_USER_PLANE[i].Y */
920 OUT_RING(ring, 0x00000000); /* GRAS_CL_USER_PLANE[i].Z */
921 OUT_RING(ring, 0x00000000); /* GRAS_CL_USER_PLANE[i].W */
922 }
923
924 OUT_PKT0(ring, REG_A3XX_PC_VSTREAM_CONTROL, 1);
925 OUT_RING(ring, 0x00000000);
926
927 fd_event_write(batch, ring, CACHE_FLUSH);
928
929 if (is_a3xx_p0(ctx->screen)) {
930 OUT_PKT3(ring, CP_DRAW_INDX, 3);
931 OUT_RING(ring, 0x00000000);
932 OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX,
933 INDEX_SIZE_IGN, IGNORE_VISIBILITY, 0));
934 OUT_RING(ring, 0); /* NumIndices */
935 }
936
937 OUT_PKT3(ring, CP_NOP, 4);
938 OUT_RING(ring, 0x00000000);
939 OUT_RING(ring, 0x00000000);
940 OUT_RING(ring, 0x00000000);
941 OUT_RING(ring, 0x00000000);
942
943 fd_wfi(batch, ring);
944
945 fd_hw_query_enable(batch, ring);
946 }
947
948 static void
949 fd3_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target)
950 {
951 __OUT_IB(ring, true, target);
952 }
953
954 void
955 fd3_emit_init(struct pipe_context *pctx)
956 {
957 struct fd_context *ctx = fd_context(pctx);
958 ctx->emit_const = fd3_emit_const;
959 ctx->emit_const_bo = fd3_emit_const_bo;
960 ctx->emit_ib = fd3_emit_ib;
961 }