1 /*
2 * Copyright (C) 2012-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_helpers.h"
29 #include "util/u_memory.h"
30 #include "util/u_string.h"
31
32 #include "freedreno_resource.h"
33
34 #include "fd2_blend.h"
35 #include "fd2_context.h"
36 #include "fd2_emit.h"
37 #include "fd2_program.h"
38 #include "fd2_rasterizer.h"
39 #include "fd2_texture.h"
40 #include "fd2_util.h"
41 #include "fd2_zsa.h"
42
43 /* NOTE: just define the position for const regs statically.. the blob
44 * driver doesn't seem to change these dynamically, and I can't really
45 * think of a good reason to so..
46 */
47 #define VS_CONST_BASE 0x20
48 #define PS_CONST_BASE 0x120
49
50 static void
emit_constants(struct fd_ringbuffer * ring,uint32_t base,struct fd_constbuf_stateobj * constbuf,struct fd2_shader_stateobj * shader)51 emit_constants(struct fd_ringbuffer *ring, uint32_t base,
52 struct fd_constbuf_stateobj *constbuf,
53 struct fd2_shader_stateobj *shader)
54 {
55 uint32_t enabled_mask = constbuf->enabled_mask;
56 uint32_t start_base = base;
57 unsigned i;
58
59 /* emit user constants: */
60 while (enabled_mask) {
61 unsigned index = ffs(enabled_mask) - 1;
62 struct pipe_constant_buffer *cb = &constbuf->cb[index];
63 unsigned size = align(cb->buffer_size, 4) / 4; /* size in dwords */
64
65 // I expect that size should be a multiple of vec4's:
66 assert(size == align(size, 4));
67
68 /* hmm, sometimes we still seem to end up with consts bound,
69 * even if shader isn't using them, which ends up overwriting
70 * const reg's used for immediates.. this is a hack to work
71 * around that:
72 */
73 if (shader && ((base - start_base) >= (shader->first_immediate * 4)))
74 break;
75
76 const uint32_t *dwords;
77
78 if (cb->user_buffer) {
79 dwords = cb->user_buffer;
80 } else {
81 struct fd_resource *rsc = fd_resource(cb->buffer);
82 dwords = fd_bo_map(rsc->bo);
83 }
84
85 dwords = (uint32_t *)(((uint8_t *)dwords) + cb->buffer_offset);
86
87 OUT_PKT3(ring, CP_SET_CONSTANT, size + 1);
88 OUT_RING(ring, base);
89 for (i = 0; i < size; i++)
90 OUT_RING(ring, *(dwords++));
91
92 base += size;
93 enabled_mask &= ~(1 << index);
94 }
95
96 /* emit shader immediates: */
97 if (shader) {
98 for (i = 0; i < shader->num_immediates; i++) {
99 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
100 OUT_RING(ring, start_base + (4 * (shader->first_immediate + i)));
101 OUT_RING(ring, shader->immediates[i].val[0]);
102 OUT_RING(ring, shader->immediates[i].val[1]);
103 OUT_RING(ring, shader->immediates[i].val[2]);
104 OUT_RING(ring, shader->immediates[i].val[3]);
105 base += 4;
106 }
107 }
108 }
109
110 typedef uint32_t texmask;
111
112 static texmask
emit_texture(struct fd_ringbuffer * ring,struct fd_context * ctx,struct fd_texture_stateobj * tex,unsigned samp_id,texmask emitted)113 emit_texture(struct fd_ringbuffer *ring, struct fd_context *ctx,
114 struct fd_texture_stateobj *tex, unsigned samp_id, texmask emitted)
115 {
116 unsigned const_idx = fd2_get_const_idx(ctx, tex, samp_id);
117 static const struct fd2_sampler_stateobj dummy_sampler = {};
118 static const struct fd2_pipe_sampler_view dummy_view = {};
119 const struct fd2_sampler_stateobj *sampler;
120 const struct fd2_pipe_sampler_view *view;
121 struct fd_resource *rsc;
122
123 if (emitted & (1 << const_idx))
124 return 0;
125
126 sampler = tex->samplers[samp_id]
127 ? fd2_sampler_stateobj(tex->samplers[samp_id])
128 : &dummy_sampler;
129 view = tex->textures[samp_id] ? fd2_pipe_sampler_view(tex->textures[samp_id])
130 : &dummy_view;
131
132 rsc = view->base.texture ? fd_resource(view->base.texture) : NULL;
133
134 OUT_PKT3(ring, CP_SET_CONSTANT, 7);
135 OUT_RING(ring, 0x00010000 + (0x6 * const_idx));
136
137 OUT_RING(ring, sampler->tex0 | view->tex0);
138 if (rsc)
139 OUT_RELOC(ring, rsc->bo, fd_resource_offset(rsc, 0, 0), view->tex1, 0);
140 else
141 OUT_RING(ring, 0);
142
143 OUT_RING(ring, view->tex2);
144 OUT_RING(ring, sampler->tex3 | view->tex3);
145 OUT_RING(ring, sampler->tex4 | view->tex4);
146
147 if (rsc && rsc->b.b.last_level)
148 OUT_RELOC(ring, rsc->bo, fd_resource_offset(rsc, 1, 0), view->tex5, 0);
149 else
150 OUT_RING(ring, view->tex5);
151
152 return (1 << const_idx);
153 }
154
155 static void
emit_textures(struct fd_ringbuffer * ring,struct fd_context * ctx)156 emit_textures(struct fd_ringbuffer *ring, struct fd_context *ctx)
157 {
158 struct fd_texture_stateobj *fragtex = &ctx->tex[PIPE_SHADER_FRAGMENT];
159 struct fd_texture_stateobj *verttex = &ctx->tex[PIPE_SHADER_VERTEX];
160 texmask emitted = 0;
161 unsigned i;
162
163 for (i = 0; i < verttex->num_samplers; i++)
164 if (verttex->samplers[i])
165 emitted |= emit_texture(ring, ctx, verttex, i, emitted);
166
167 for (i = 0; i < fragtex->num_samplers; i++)
168 if (fragtex->samplers[i])
169 emitted |= emit_texture(ring, ctx, fragtex, i, emitted);
170 }
171
172 void
fd2_emit_vertex_bufs(struct fd_ringbuffer * ring,uint32_t val,struct fd2_vertex_buf * vbufs,uint32_t n)173 fd2_emit_vertex_bufs(struct fd_ringbuffer *ring, uint32_t val,
174 struct fd2_vertex_buf *vbufs, uint32_t n)
175 {
176 unsigned i;
177
178 OUT_PKT3(ring, CP_SET_CONSTANT, 1 + (2 * n));
179 OUT_RING(ring, (0x1 << 16) | (val & 0xffff));
180 for (i = 0; i < n; i++) {
181 struct fd_resource *rsc = fd_resource(vbufs[i].prsc);
182 OUT_RELOC(ring, rsc->bo, vbufs[i].offset, 3, 0);
183 OUT_RING(ring, vbufs[i].size);
184 }
185 }
186
187 void
fd2_emit_state_binning(struct fd_context * ctx,const enum fd_dirty_3d_state dirty)188 fd2_emit_state_binning(struct fd_context *ctx,
189 const enum fd_dirty_3d_state dirty)
190 {
191 struct fd2_blend_stateobj *blend = fd2_blend_stateobj(ctx->blend);
192 struct fd_ringbuffer *ring = ctx->batch->binning;
193
194 /* subset of fd2_emit_state needed for hw binning on a20x */
195
196 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_VTXSTATE))
197 fd2_program_emit(ctx, ring, &ctx->prog);
198
199 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_CONST)) {
200 emit_constants(ring, VS_CONST_BASE * 4,
201 &ctx->constbuf[PIPE_SHADER_VERTEX],
202 (dirty & FD_DIRTY_PROG) ? ctx->prog.vs : NULL);
203 }
204
205 if (dirty & FD_DIRTY_VIEWPORT) {
206 struct pipe_viewport_state *vp = & ctx->viewport[0];
207
208 OUT_PKT3(ring, CP_SET_CONSTANT, 9);
209 OUT_RING(ring, 0x00000184);
210 OUT_RING(ring, fui(vp->translate[0]));
211 OUT_RING(ring, fui(vp->translate[1]));
212 OUT_RING(ring, fui(vp->translate[2]));
213 OUT_RING(ring, fui(0.0f));
214 OUT_RING(ring, fui(vp->scale[0]));
215 OUT_RING(ring, fui(vp->scale[1]));
216 OUT_RING(ring, fui(vp->scale[2]));
217 OUT_RING(ring, fui(0.0f));
218 }
219
220 /* not sure why this is needed */
221 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_FRAMEBUFFER)) {
222 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
223 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_CONTROL));
224 OUT_RING(ring, blend->rb_blendcontrol);
225
226 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
227 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
228 OUT_RING(ring, blend->rb_colormask);
229 }
230
231 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
232 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_SC_MODE_CNTL));
233 OUT_RING(ring, A2XX_PA_SU_SC_MODE_CNTL_FACE_KILL_ENABLE);
234 }
235
236 void
fd2_emit_state(struct fd_context * ctx,const enum fd_dirty_3d_state dirty)237 fd2_emit_state(struct fd_context *ctx, const enum fd_dirty_3d_state dirty)
238 {
239 struct fd2_blend_stateobj *blend = fd2_blend_stateobj(ctx->blend);
240 struct fd2_zsa_stateobj *zsa = fd2_zsa_stateobj(ctx->zsa);
241 struct fd2_shader_stateobj *fs = ctx->prog.fs;
242 struct fd_ringbuffer *ring = ctx->batch->draw;
243
244 /* NOTE: we probably want to eventually refactor this so each state
245 * object handles emitting it's own state.. although the mapping of
246 * state to registers is not always orthogonal, sometimes a single
247 * register contains bitfields coming from multiple state objects,
248 * so not sure the best way to deal with that yet.
249 */
250
251 if (dirty & FD_DIRTY_SAMPLE_MASK) {
252 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
253 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_MASK));
254 OUT_RING(ring, ctx->sample_mask);
255 }
256
257 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_STENCIL_REF | FD_DIRTY_PROG)) {
258 struct pipe_stencil_ref *sr = &ctx->stencil_ref;
259 uint32_t val = zsa->rb_depthcontrol;
260
261 if (fs->has_kill)
262 val &= ~A2XX_RB_DEPTHCONTROL_EARLY_Z_ENABLE;
263
264 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
265 OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTHCONTROL));
266 OUT_RING(ring, val);
267
268 OUT_PKT3(ring, CP_SET_CONSTANT, 4);
269 OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF));
270 OUT_RING(ring, zsa->rb_stencilrefmask_bf |
271 A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[1]));
272 OUT_RING(ring, zsa->rb_stencilrefmask |
273 A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
274 OUT_RING(ring, zsa->rb_alpha_ref);
275 }
276
277 if (ctx->rasterizer && dirty & FD_DIRTY_RASTERIZER) {
278 struct fd2_rasterizer_stateobj *rasterizer =
279 fd2_rasterizer_stateobj(ctx->rasterizer);
280 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
281 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_CLIP_CNTL));
282 OUT_RING(ring, rasterizer->pa_cl_clip_cntl);
283 OUT_RING(ring, rasterizer->pa_su_sc_mode_cntl |
284 A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE);
285
286 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
287 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_POINT_SIZE));
288 OUT_RING(ring, rasterizer->pa_su_point_size);
289 OUT_RING(ring, rasterizer->pa_su_point_minmax);
290 OUT_RING(ring, rasterizer->pa_su_line_cntl);
291 OUT_RING(ring, rasterizer->pa_sc_line_stipple);
292
293 OUT_PKT3(ring, CP_SET_CONSTANT, 6);
294 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_VTX_CNTL));
295 OUT_RING(ring, rasterizer->pa_su_vtx_cntl);
296 OUT_RING(ring, fui(1.0f)); /* PA_CL_GB_VERT_CLIP_ADJ */
297 OUT_RING(ring, fui(1.0f)); /* PA_CL_GB_VERT_DISC_ADJ */
298 OUT_RING(ring, fui(1.0f)); /* PA_CL_GB_HORZ_CLIP_ADJ */
299 OUT_RING(ring, fui(1.0f)); /* PA_CL_GB_HORZ_DISC_ADJ */
300
301 if (rasterizer->base.offset_tri) {
302 /* TODO: why multiply scale by 2 ? without it deqp test fails
303 * deqp/piglit tests aren't very precise
304 */
305 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
306 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_POLY_OFFSET_FRONT_SCALE));
307 OUT_RING(ring,
308 fui(rasterizer->base.offset_scale * 2.0f)); /* FRONT_SCALE */
309 OUT_RING(ring, fui(rasterizer->base.offset_units)); /* FRONT_OFFSET */
310 OUT_RING(ring,
311 fui(rasterizer->base.offset_scale * 2.0f)); /* BACK_SCALE */
312 OUT_RING(ring, fui(rasterizer->base.offset_units)); /* BACK_OFFSET */
313 }
314 }
315
316 /* NOTE: scissor enabled bit is part of rasterizer state: */
317 if (dirty & (FD_DIRTY_SCISSOR | FD_DIRTY_RASTERIZER)) {
318 struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
319
320 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
321 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_SCISSOR_TL));
322 OUT_RING(ring, xy2d(scissor->minx, /* PA_SC_WINDOW_SCISSOR_TL */
323 scissor->miny));
324 OUT_RING(ring, xy2d(scissor->maxx, /* PA_SC_WINDOW_SCISSOR_BR */
325 scissor->maxy));
326
327 ctx->batch->max_scissor.minx =
328 MIN2(ctx->batch->max_scissor.minx, scissor->minx);
329 ctx->batch->max_scissor.miny =
330 MIN2(ctx->batch->max_scissor.miny, scissor->miny);
331 ctx->batch->max_scissor.maxx =
332 MAX2(ctx->batch->max_scissor.maxx, scissor->maxx);
333 ctx->batch->max_scissor.maxy =
334 MAX2(ctx->batch->max_scissor.maxy, scissor->maxy);
335 }
336
337 if (dirty & FD_DIRTY_VIEWPORT) {
338 struct pipe_viewport_state *vp = & ctx->viewport[0];
339
340 OUT_PKT3(ring, CP_SET_CONSTANT, 7);
341 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_XSCALE));
342 OUT_RING(ring, fui(vp->scale[0])); /* PA_CL_VPORT_XSCALE */
343 OUT_RING(ring, fui(vp->translate[0])); /* PA_CL_VPORT_XOFFSET */
344 OUT_RING(ring, fui(vp->scale[1])); /* PA_CL_VPORT_YSCALE */
345 OUT_RING(ring, fui(vp->translate[1])); /* PA_CL_VPORT_YOFFSET */
346 OUT_RING(ring, fui(vp->scale[2])); /* PA_CL_VPORT_ZSCALE */
347 OUT_RING(ring, fui(vp->translate[2])); /* PA_CL_VPORT_ZOFFSET */
348
349 /* set viewport in C65/C66, for a20x hw binning and fragcoord.z */
350 OUT_PKT3(ring, CP_SET_CONSTANT, 9);
351 OUT_RING(ring, 0x00000184);
352
353 OUT_RING(ring, fui(vp->translate[0]));
354 OUT_RING(ring, fui(vp->translate[1]));
355 OUT_RING(ring, fui(vp->translate[2]));
356 OUT_RING(ring, fui(0.0f));
357
358 OUT_RING(ring, fui(vp->scale[0]));
359 OUT_RING(ring, fui(vp->scale[1]));
360 OUT_RING(ring, fui(vp->scale[2]));
361 OUT_RING(ring, fui(0.0f));
362 }
363
364 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_VTXSTATE | FD_DIRTY_TEXSTATE))
365 fd2_program_emit(ctx, ring, &ctx->prog);
366
367 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_CONST)) {
368 emit_constants(ring, VS_CONST_BASE * 4,
369 &ctx->constbuf[PIPE_SHADER_VERTEX],
370 (dirty & FD_DIRTY_PROG) ? ctx->prog.vs : NULL);
371 emit_constants(ring, PS_CONST_BASE * 4,
372 &ctx->constbuf[PIPE_SHADER_FRAGMENT],
373 (dirty & FD_DIRTY_PROG) ? ctx->prog.fs : NULL);
374 }
375
376 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_ZSA)) {
377 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
378 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLORCONTROL));
379 OUT_RING(ring, zsa->rb_colorcontrol | blend->rb_colorcontrol);
380 }
381
382 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_FRAMEBUFFER)) {
383 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
384 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_CONTROL));
385 OUT_RING(ring, blend->rb_blendcontrol);
386
387 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
388 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
389 OUT_RING(ring, blend->rb_colormask);
390 }
391
392 if (dirty & FD_DIRTY_BLEND_COLOR) {
393 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
394 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_RED));
395 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[0]));
396 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[1]));
397 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[2]));
398 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[3]));
399 }
400
401 if (dirty & (FD_DIRTY_TEX | FD_DIRTY_PROG))
402 emit_textures(ring, ctx);
403 }
404
405 /* emit per-context initialization:
406 */
407 void
fd2_emit_restore(struct fd_context * ctx,struct fd_ringbuffer * ring)408 fd2_emit_restore(struct fd_context *ctx, struct fd_ringbuffer *ring)
409 {
410 if (is_a20x(ctx->screen)) {
411 OUT_PKT0(ring, REG_A2XX_RB_BC_CONTROL, 1);
412 OUT_RING(ring, A2XX_RB_BC_CONTROL_ACCUM_TIMEOUT_SELECT(3) |
413 A2XX_RB_BC_CONTROL_DISABLE_LZ_NULL_ZCMD_DROP |
414 A2XX_RB_BC_CONTROL_ENABLE_CRC_UPDATE |
415 A2XX_RB_BC_CONTROL_ACCUM_DATA_FIFO_LIMIT(8) |
416 A2XX_RB_BC_CONTROL_MEM_EXPORT_TIMEOUT_SELECT(3));
417
418 /* not sure why this is required */
419 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
420 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_VIZ_QUERY));
421 OUT_RING(ring, A2XX_PA_SC_VIZ_QUERY_VIZ_QUERY_ID(16));
422
423 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
424 OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL));
425 OUT_RING(ring, 0x00000002);
426
427 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
428 OUT_RING(ring, CP_REG(REG_A2XX_VGT_OUT_DEALLOC_CNTL));
429 OUT_RING(ring, 0x00000002);
430 } else {
431 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
432 OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL));
433 OUT_RING(ring, 0x0000003b);
434 }
435
436 /* enable perfcntrs */
437 OUT_PKT0(ring, REG_A2XX_CP_PERFMON_CNTL, 1);
438 OUT_RING(ring, COND(FD_DBG(PERFC), 1));
439
440 /* note: perfcntrs don't work without the PM_OVERRIDE bit */
441 OUT_PKT0(ring, REG_A2XX_RBBM_PM_OVERRIDE1, 2);
442 OUT_RING(ring, 0xffffffff);
443 OUT_RING(ring, 0x00000fff);
444
445 OUT_PKT0(ring, REG_A2XX_TP0_CHICKEN, 1);
446 OUT_RING(ring, 0x00000002);
447
448 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
449 OUT_RING(ring, 0x00007fff);
450
451 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
452 OUT_RING(ring, CP_REG(REG_A2XX_SQ_VS_CONST));
453 OUT_RING(ring, A2XX_SQ_VS_CONST_BASE(VS_CONST_BASE) |
454 A2XX_SQ_VS_CONST_SIZE(0x100));
455
456 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
457 OUT_RING(ring, CP_REG(REG_A2XX_SQ_PS_CONST));
458 OUT_RING(ring,
459 A2XX_SQ_PS_CONST_BASE(PS_CONST_BASE) | A2XX_SQ_PS_CONST_SIZE(0xe0));
460
461 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
462 OUT_RING(ring, CP_REG(REG_A2XX_VGT_MAX_VTX_INDX));
463 OUT_RING(ring, 0xffffffff); /* VGT_MAX_VTX_INDX */
464 OUT_RING(ring, 0x00000000); /* VGT_MIN_VTX_INDX */
465
466 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
467 OUT_RING(ring, CP_REG(REG_A2XX_VGT_INDX_OFFSET));
468 OUT_RING(ring, 0x00000000);
469
470 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
471 OUT_RING(ring, CP_REG(REG_A2XX_SQ_CONTEXT_MISC));
472 OUT_RING(ring, A2XX_SQ_CONTEXT_MISC_SC_SAMPLE_CNTL(CENTERS_ONLY));
473
474 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
475 OUT_RING(ring, CP_REG(REG_A2XX_SQ_INTERPOLATOR_CNTL));
476 OUT_RING(ring, 0xffffffff);
477
478 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
479 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_CONFIG));
480 OUT_RING(ring, 0x00000000);
481
482 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
483 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_LINE_CNTL));
484 OUT_RING(ring, 0x00000000);
485
486 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
487 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_OFFSET));
488 OUT_RING(ring, 0x00000000);
489
490 // XXX we change this dynamically for draw/clear.. vs gmem<->mem..
491 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
492 OUT_RING(ring, CP_REG(REG_A2XX_RB_MODECONTROL));
493 OUT_RING(ring, A2XX_RB_MODECONTROL_EDRAM_MODE(COLOR_DEPTH));
494
495 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
496 OUT_RING(ring, CP_REG(REG_A2XX_RB_SAMPLE_POS));
497 OUT_RING(ring, 0x88888888);
498
499 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
500 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_DEST_MASK));
501 OUT_RING(ring, 0xffffffff);
502
503 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
504 OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_DEST_INFO));
505 OUT_RING(ring, A2XX_RB_COPY_DEST_INFO_FORMAT(COLORX_4_4_4_4) |
506 A2XX_RB_COPY_DEST_INFO_WRITE_RED |
507 A2XX_RB_COPY_DEST_INFO_WRITE_GREEN |
508 A2XX_RB_COPY_DEST_INFO_WRITE_BLUE |
509 A2XX_RB_COPY_DEST_INFO_WRITE_ALPHA);
510
511 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
512 OUT_RING(ring, CP_REG(REG_A2XX_SQ_WRAPPING_0));
513 OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_0 */
514 OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_1 */
515
516 OUT_PKT3(ring, CP_SET_DRAW_INIT_FLAGS, 1);
517 OUT_RING(ring, 0x00000000);
518
519 OUT_PKT3(ring, CP_WAIT_REG_EQ, 4);
520 OUT_RING(ring, 0x000005d0);
521 OUT_RING(ring, 0x00000000);
522 OUT_RING(ring, 0x5f601000);
523 OUT_RING(ring, 0x00000001);
524
525 OUT_PKT0(ring, REG_A2XX_SQ_INST_STORE_MANAGMENT, 1);
526 OUT_RING(ring, 0x00000180);
527
528 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
529 OUT_RING(ring, 0x00000300);
530
531 OUT_PKT3(ring, CP_SET_SHADER_BASES, 1);
532 OUT_RING(ring, 0x80000180);
533
534 /* not sure what this form of CP_SET_CONSTANT is.. */
535 OUT_PKT3(ring, CP_SET_CONSTANT, 13);
536 OUT_RING(ring, 0x00000000);
537 OUT_RING(ring, 0x00000000);
538 OUT_RING(ring, 0x00000000);
539 OUT_RING(ring, 0x00000000);
540 OUT_RING(ring, 0x00000000);
541 OUT_RING(ring, 0x469c4000);
542 OUT_RING(ring, 0x3f800000);
543 OUT_RING(ring, 0x3f000000);
544 OUT_RING(ring, 0x00000000);
545 OUT_RING(ring, 0x40000000);
546 OUT_RING(ring, 0x3f400000);
547 OUT_RING(ring, 0x3ec00000);
548 OUT_RING(ring, 0x3e800000);
549
550 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
551 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
552 OUT_RING(ring,
553 A2XX_RB_COLOR_MASK_WRITE_RED | A2XX_RB_COLOR_MASK_WRITE_GREEN |
554 A2XX_RB_COLOR_MASK_WRITE_BLUE | A2XX_RB_COLOR_MASK_WRITE_ALPHA);
555
556 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
557 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_RED));
558 OUT_RING(ring, 0x00000000); /* RB_BLEND_RED */
559 OUT_RING(ring, 0x00000000); /* RB_BLEND_GREEN */
560 OUT_RING(ring, 0x00000000); /* RB_BLEND_BLUE */
561 OUT_RING(ring, 0x000000ff); /* RB_BLEND_ALPHA */
562
563 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
564 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VTE_CNTL));
565 OUT_RING(ring, A2XX_PA_CL_VTE_CNTL_VTX_W0_FMT |
566 A2XX_PA_CL_VTE_CNTL_VPORT_X_SCALE_ENA |
567 A2XX_PA_CL_VTE_CNTL_VPORT_X_OFFSET_ENA |
568 A2XX_PA_CL_VTE_CNTL_VPORT_Y_SCALE_ENA |
569 A2XX_PA_CL_VTE_CNTL_VPORT_Y_OFFSET_ENA |
570 A2XX_PA_CL_VTE_CNTL_VPORT_Z_SCALE_ENA |
571 A2XX_PA_CL_VTE_CNTL_VPORT_Z_OFFSET_ENA);
572 }
573
574 void
fd2_emit_init_screen(struct pipe_screen * pscreen)575 fd2_emit_init_screen(struct pipe_screen *pscreen)
576 {
577 struct fd_screen *screen = fd_screen(pscreen);
578 screen->emit_ib = fd2_emit_ib;
579 }
580
581 void
fd2_emit_init(struct pipe_context * pctx)582 fd2_emit_init(struct pipe_context *pctx)
583 {
584 }
585