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