freedreno: a2xx: Prevent crash in emit_texture if view is not set
[mesa.git] / src / gallium / drivers / freedreno / a2xx / fd2_emit.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012-2013 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
34 #include "freedreno_resource.h"
35
36 #include "fd2_emit.h"
37 #include "fd2_blend.h"
38 #include "fd2_context.h"
39 #include "fd2_program.h"
40 #include "fd2_rasterizer.h"
41 #include "fd2_texture.h"
42 #include "fd2_util.h"
43 #include "fd2_zsa.h"
44
45 /* NOTE: just define the position for const regs statically.. the blob
46 * driver doesn't seem to change these dynamically, and I can't really
47 * think of a good reason to so..
48 */
49 #define VS_CONST_BASE 0x20
50 #define PS_CONST_BASE 0x120
51
52 static void
53 emit_constants(struct fd_ringbuffer *ring, uint32_t base,
54 struct fd_constbuf_stateobj *constbuf,
55 struct fd2_shader_stateobj *shader)
56 {
57 uint32_t enabled_mask = constbuf->enabled_mask;
58 uint32_t start_base = base;
59 unsigned i;
60
61 // XXX TODO only emit dirty consts.. but we need to keep track if
62 // they are clobbered by a clear, gmem2mem, or mem2gmem..
63 constbuf->dirty_mask = enabled_mask;
64
65 /* emit user constants: */
66 while (enabled_mask) {
67 unsigned index = ffs(enabled_mask) - 1;
68 struct pipe_constant_buffer *cb = &constbuf->cb[index];
69 unsigned size = align(cb->buffer_size, 4) / 4; /* size in dwords */
70
71 // I expect that size should be a multiple of vec4's:
72 assert(size == align(size, 4));
73
74 /* hmm, sometimes we still seem to end up with consts bound,
75 * even if shader isn't using them, which ends up overwriting
76 * const reg's used for immediates.. this is a hack to work
77 * around that:
78 */
79 if (shader && ((base - start_base) >= (shader->first_immediate * 4)))
80 break;
81
82 if (constbuf->dirty_mask & (1 << index)) {
83 const uint32_t *dwords;
84
85 if (cb->user_buffer) {
86 dwords = cb->user_buffer;
87 } else {
88 struct fd_resource *rsc = fd_resource(cb->buffer);
89 dwords = fd_bo_map(rsc->bo);
90 }
91
92 dwords = (uint32_t *)(((uint8_t *)dwords) + cb->buffer_offset);
93
94 OUT_PKT3(ring, CP_SET_CONSTANT, size + 1);
95 OUT_RING(ring, base);
96 for (i = 0; i < size; i++)
97 OUT_RING(ring, *(dwords++));
98
99 constbuf->dirty_mask &= ~(1 << index);
100 }
101
102 base += size;
103 enabled_mask &= ~(1 << index);
104 }
105
106 /* emit shader immediates: */
107 if (shader) {
108 for (i = 0; i < shader->num_immediates; i++) {
109 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
110 OUT_RING(ring, start_base + (4 * (shader->first_immediate + i)));
111 OUT_RING(ring, shader->immediates[i].val[0]);
112 OUT_RING(ring, shader->immediates[i].val[1]);
113 OUT_RING(ring, shader->immediates[i].val[2]);
114 OUT_RING(ring, shader->immediates[i].val[3]);
115 base += 4;
116 }
117 }
118 }
119
120 typedef uint32_t texmask;
121
122 static texmask
123 emit_texture(struct fd_ringbuffer *ring, struct fd_context *ctx,
124 struct fd_texture_stateobj *tex, unsigned samp_id, texmask emitted)
125 {
126 unsigned const_idx = fd2_get_const_idx(ctx, tex, samp_id);
127 static const struct fd2_sampler_stateobj dummy_sampler = {};
128 static const struct fd2_pipe_sampler_view dummy_view = {};
129 const struct fd2_sampler_stateobj *sampler;
130 const struct fd2_pipe_sampler_view *view;
131
132 if (emitted & (1 << const_idx))
133 return 0;
134
135 sampler = tex->samplers[samp_id] ?
136 fd2_sampler_stateobj(tex->samplers[samp_id]) :
137 &dummy_sampler;
138 view = tex->textures[samp_id] ?
139 fd2_pipe_sampler_view(tex->textures[samp_id]) :
140 &dummy_view;
141
142 OUT_PKT3(ring, CP_SET_CONSTANT, 7);
143 OUT_RING(ring, 0x00010000 + (0x6 * const_idx));
144
145 OUT_RING(ring, sampler->tex0 | view->tex0);
146 if (view->base.texture)
147 OUT_RELOC(ring, fd_resource(view->base.texture)->bo, 0, view->fmt, 0);
148 else
149 OUT_RING(ring, 0);
150
151 OUT_RING(ring, view->tex2);
152 OUT_RING(ring, sampler->tex3 | view->tex3);
153 OUT_RING(ring, sampler->tex4);
154 OUT_RING(ring, sampler->tex5);
155
156 return (1 << const_idx);
157 }
158
159 static void
160 emit_textures(struct fd_ringbuffer *ring, struct fd_context *ctx)
161 {
162 struct fd_texture_stateobj *fragtex = &ctx->tex[PIPE_SHADER_FRAGMENT];
163 struct fd_texture_stateobj *verttex = &ctx->tex[PIPE_SHADER_VERTEX];
164 texmask emitted = 0;
165 unsigned i;
166
167 for (i = 0; i < verttex->num_samplers; i++)
168 if (verttex->samplers[i])
169 emitted |= emit_texture(ring, ctx, verttex, i, emitted);
170
171 for (i = 0; i < fragtex->num_samplers; i++)
172 if (fragtex->samplers[i])
173 emitted |= emit_texture(ring, ctx, fragtex, i, emitted);
174 }
175
176 void
177 fd2_emit_vertex_bufs(struct fd_ringbuffer *ring, uint32_t val,
178 struct fd2_vertex_buf *vbufs, uint32_t n)
179 {
180 unsigned i;
181
182 OUT_PKT3(ring, CP_SET_CONSTANT, 1 + (2 * n));
183 OUT_RING(ring, (0x1 << 16) | (val & 0xffff));
184 for (i = 0; i < n; i++) {
185 struct fd_resource *rsc = fd_resource(vbufs[i].prsc);
186 OUT_RELOC(ring, rsc->bo, vbufs[i].offset, 3, 0);
187 OUT_RING (ring, vbufs[i].size);
188 }
189 }
190
191 void
192 fd2_emit_state(struct fd_context *ctx, const enum fd_dirty_3d_state dirty)
193 {
194 struct fd2_blend_stateobj *blend = fd2_blend_stateobj(ctx->blend);
195 struct fd2_zsa_stateobj *zsa = fd2_zsa_stateobj(ctx->zsa);
196 struct fd_ringbuffer *ring = ctx->batch->draw;
197
198 /* NOTE: we probably want to eventually refactor this so each state
199 * object handles emitting it's own state.. although the mapping of
200 * state to registers is not always orthogonal, sometimes a single
201 * register contains bitfields coming from multiple state objects,
202 * so not sure the best way to deal with that yet.
203 */
204
205 if (dirty & FD_DIRTY_SAMPLE_MASK) {
206 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
207 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_MASK));
208 OUT_RING(ring, ctx->sample_mask);
209 }
210
211 if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_STENCIL_REF)) {
212 struct pipe_stencil_ref *sr = &ctx->stencil_ref;
213
214 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
215 OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTHCONTROL));
216 OUT_RING(ring, zsa->rb_depthcontrol);
217
218 OUT_PKT3(ring, CP_SET_CONSTANT, 4);
219 OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF));
220 OUT_RING(ring, zsa->rb_stencilrefmask_bf |
221 A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[1]));
222 OUT_RING(ring, zsa->rb_stencilrefmask |
223 A2XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
224 OUT_RING(ring, zsa->rb_alpha_ref);
225 }
226
227 if (ctx->rasterizer && dirty & FD_DIRTY_RASTERIZER) {
228 struct fd2_rasterizer_stateobj *rasterizer =
229 fd2_rasterizer_stateobj(ctx->rasterizer);
230 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
231 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_CLIP_CNTL));
232 OUT_RING(ring, rasterizer->pa_cl_clip_cntl);
233 OUT_RING(ring, rasterizer->pa_su_sc_mode_cntl |
234 A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE);
235
236 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
237 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_POINT_SIZE));
238 OUT_RING(ring, rasterizer->pa_su_point_size);
239 OUT_RING(ring, rasterizer->pa_su_point_minmax);
240 OUT_RING(ring, rasterizer->pa_su_line_cntl);
241 OUT_RING(ring, rasterizer->pa_sc_line_stipple);
242
243 OUT_PKT3(ring, CP_SET_CONSTANT, 6);
244 OUT_RING(ring, CP_REG(REG_A2XX_PA_SU_VTX_CNTL));
245 OUT_RING(ring, rasterizer->pa_su_vtx_cntl);
246 OUT_RING(ring, fui(1.0)); /* PA_CL_GB_VERT_CLIP_ADJ */
247 OUT_RING(ring, fui(1.0)); /* PA_CL_GB_VERT_DISC_ADJ */
248 OUT_RING(ring, fui(1.0)); /* PA_CL_GB_HORZ_CLIP_ADJ */
249 OUT_RING(ring, fui(1.0)); /* PA_CL_GB_HORZ_DISC_ADJ */
250 }
251
252 if (dirty & FD_DIRTY_SCISSOR) {
253 struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
254
255 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
256 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_SCISSOR_TL));
257 OUT_RING(ring, xy2d(scissor->minx, /* PA_SC_WINDOW_SCISSOR_TL */
258 scissor->miny));
259 OUT_RING(ring, xy2d(scissor->maxx, /* PA_SC_WINDOW_SCISSOR_BR */
260 scissor->maxy));
261
262 ctx->batch->max_scissor.minx = MIN2(ctx->batch->max_scissor.minx, scissor->minx);
263 ctx->batch->max_scissor.miny = MIN2(ctx->batch->max_scissor.miny, scissor->miny);
264 ctx->batch->max_scissor.maxx = MAX2(ctx->batch->max_scissor.maxx, scissor->maxx);
265 ctx->batch->max_scissor.maxy = MAX2(ctx->batch->max_scissor.maxy, scissor->maxy);
266 }
267
268 if (dirty & FD_DIRTY_VIEWPORT) {
269 OUT_PKT3(ring, CP_SET_CONSTANT, 7);
270 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_XSCALE));
271 OUT_RING(ring, fui(ctx->viewport.scale[0])); /* PA_CL_VPORT_XSCALE */
272 OUT_RING(ring, fui(ctx->viewport.translate[0])); /* PA_CL_VPORT_XOFFSET */
273 OUT_RING(ring, fui(ctx->viewport.scale[1])); /* PA_CL_VPORT_YSCALE */
274 OUT_RING(ring, fui(ctx->viewport.translate[1])); /* PA_CL_VPORT_YOFFSET */
275 OUT_RING(ring, fui(ctx->viewport.scale[2])); /* PA_CL_VPORT_ZSCALE */
276 OUT_RING(ring, fui(ctx->viewport.translate[2])); /* PA_CL_VPORT_ZOFFSET */
277
278 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
279 OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VTE_CNTL));
280 OUT_RING(ring, A2XX_PA_CL_VTE_CNTL_VTX_W0_FMT |
281 A2XX_PA_CL_VTE_CNTL_VPORT_X_SCALE_ENA |
282 A2XX_PA_CL_VTE_CNTL_VPORT_X_OFFSET_ENA |
283 A2XX_PA_CL_VTE_CNTL_VPORT_Y_SCALE_ENA |
284 A2XX_PA_CL_VTE_CNTL_VPORT_Y_OFFSET_ENA |
285 A2XX_PA_CL_VTE_CNTL_VPORT_Z_SCALE_ENA |
286 A2XX_PA_CL_VTE_CNTL_VPORT_Z_OFFSET_ENA);
287 }
288
289 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_VTXSTATE | FD_DIRTY_TEXSTATE)) {
290 fd2_program_validate(ctx);
291 fd2_program_emit(ring, &ctx->prog);
292 }
293
294 if (dirty & (FD_DIRTY_PROG | FD_DIRTY_CONST)) {
295 emit_constants(ring, VS_CONST_BASE * 4,
296 &ctx->constbuf[PIPE_SHADER_VERTEX],
297 (dirty & FD_DIRTY_PROG) ? ctx->prog.vp : NULL);
298 emit_constants(ring, PS_CONST_BASE * 4,
299 &ctx->constbuf[PIPE_SHADER_FRAGMENT],
300 (dirty & FD_DIRTY_PROG) ? ctx->prog.fp : NULL);
301 }
302
303 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_ZSA)) {
304 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
305 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLORCONTROL));
306 OUT_RING(ring, zsa->rb_colorcontrol | blend->rb_colorcontrol);
307 }
308
309 if (dirty & (FD_DIRTY_BLEND | FD_DIRTY_FRAMEBUFFER)) {
310 enum pipe_format format =
311 pipe_surface_format(ctx->batch->framebuffer.cbufs[0]);
312 bool has_alpha = util_format_has_alpha(format);
313
314 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
315 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_CONTROL));
316 OUT_RING(ring, blend->rb_blendcontrol_alpha |
317 COND(has_alpha, blend->rb_blendcontrol_rgb) |
318 COND(!has_alpha, blend->rb_blendcontrol_no_alpha_rgb));
319
320 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
321 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
322 OUT_RING(ring, blend->rb_colormask);
323 }
324
325 if (dirty & FD_DIRTY_BLEND_COLOR) {
326 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
327 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_RED));
328 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[0]));
329 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[1]));
330 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[2]));
331 OUT_RING(ring, float_to_ubyte(ctx->blend_color.color[3]));
332 }
333
334 if (dirty & (FD_DIRTY_TEX | FD_DIRTY_PROG))
335 emit_textures(ring, ctx);
336 }
337
338 /* emit per-context initialization:
339 */
340 void
341 fd2_emit_restore(struct fd_context *ctx, struct fd_ringbuffer *ring)
342 {
343 OUT_PKT0(ring, REG_A2XX_TP0_CHICKEN, 1);
344 OUT_RING(ring, 0x00000002);
345
346 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
347 OUT_RING(ring, 0x00007fff);
348
349 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
350 OUT_RING(ring, CP_REG(REG_A2XX_SQ_VS_CONST));
351 OUT_RING(ring, A2XX_SQ_VS_CONST_BASE(VS_CONST_BASE) |
352 A2XX_SQ_VS_CONST_SIZE(0x100));
353
354 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
355 OUT_RING(ring, CP_REG(REG_A2XX_SQ_PS_CONST));
356 OUT_RING(ring, A2XX_SQ_PS_CONST_BASE(PS_CONST_BASE) |
357 A2XX_SQ_PS_CONST_SIZE(0xe0));
358
359 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
360 OUT_RING(ring, CP_REG(REG_A2XX_VGT_MAX_VTX_INDX));
361 OUT_RING(ring, 0xffffffff); /* VGT_MAX_VTX_INDX */
362 OUT_RING(ring, 0x00000000); /* VGT_MIN_VTX_INDX */
363
364 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
365 OUT_RING(ring, CP_REG(REG_A2XX_VGT_INDX_OFFSET));
366 OUT_RING(ring, 0x00000000);
367
368 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
369 OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL));
370 OUT_RING(ring, 0x0000003b);
371
372 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
373 OUT_RING(ring, CP_REG(REG_A2XX_SQ_CONTEXT_MISC));
374 OUT_RING(ring, A2XX_SQ_CONTEXT_MISC_SC_SAMPLE_CNTL(CENTERS_ONLY));
375
376 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
377 OUT_RING(ring, CP_REG(REG_A2XX_SQ_INTERPOLATOR_CNTL));
378 OUT_RING(ring, 0xffffffff);
379
380 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
381 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_CONFIG));
382 OUT_RING(ring, 0x00000000);
383
384 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
385 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_LINE_CNTL));
386 OUT_RING(ring, 0x00000000);
387
388 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
389 OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_OFFSET));
390 OUT_RING(ring, 0x00000000);
391
392 // XXX we change this dynamically for draw/clear.. vs gmem<->mem..
393 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
394 OUT_RING(ring, CP_REG(REG_A2XX_RB_MODECONTROL));
395 OUT_RING(ring, A2XX_RB_MODECONTROL_EDRAM_MODE(COLOR_DEPTH));
396
397 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
398 OUT_RING(ring, CP_REG(REG_A2XX_RB_SAMPLE_POS));
399 OUT_RING(ring, 0x88888888);
400
401 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
402 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_DEST_MASK));
403 OUT_RING(ring, 0xffffffff);
404
405 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
406 OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_DEST_INFO));
407 OUT_RING(ring, A2XX_RB_COPY_DEST_INFO_FORMAT(COLORX_4_4_4_4) |
408 A2XX_RB_COPY_DEST_INFO_WRITE_RED |
409 A2XX_RB_COPY_DEST_INFO_WRITE_GREEN |
410 A2XX_RB_COPY_DEST_INFO_WRITE_BLUE |
411 A2XX_RB_COPY_DEST_INFO_WRITE_ALPHA);
412
413 OUT_PKT3(ring, CP_SET_CONSTANT, 3);
414 OUT_RING(ring, CP_REG(REG_A2XX_SQ_WRAPPING_0));
415 OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_0 */
416 OUT_RING(ring, 0x00000000); /* SQ_WRAPPING_1 */
417
418 OUT_PKT3(ring, CP_SET_DRAW_INIT_FLAGS, 1);
419 OUT_RING(ring, 0x00000000);
420
421 OUT_PKT3(ring, CP_WAIT_REG_EQ, 4);
422 OUT_RING(ring, 0x000005d0);
423 OUT_RING(ring, 0x00000000);
424 OUT_RING(ring, 0x5f601000);
425 OUT_RING(ring, 0x00000001);
426
427 OUT_PKT0(ring, REG_A2XX_SQ_INST_STORE_MANAGMENT, 1);
428 OUT_RING(ring, 0x00000180);
429
430 OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
431 OUT_RING(ring, 0x00000300);
432
433 OUT_PKT3(ring, CP_SET_SHADER_BASES, 1);
434 OUT_RING(ring, 0x80000180);
435
436 /* not sure what this form of CP_SET_CONSTANT is.. */
437 OUT_PKT3(ring, CP_SET_CONSTANT, 13);
438 OUT_RING(ring, 0x00000000);
439 OUT_RING(ring, 0x00000000);
440 OUT_RING(ring, 0x00000000);
441 OUT_RING(ring, 0x00000000);
442 OUT_RING(ring, 0x00000000);
443 OUT_RING(ring, 0x469c4000);
444 OUT_RING(ring, 0x3f800000);
445 OUT_RING(ring, 0x3f000000);
446 OUT_RING(ring, 0x00000000);
447 OUT_RING(ring, 0x40000000);
448 OUT_RING(ring, 0x3f400000);
449 OUT_RING(ring, 0x3ec00000);
450 OUT_RING(ring, 0x3e800000);
451
452 OUT_PKT3(ring, CP_SET_CONSTANT, 2);
453 OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK));
454 OUT_RING(ring, A2XX_RB_COLOR_MASK_WRITE_RED |
455 A2XX_RB_COLOR_MASK_WRITE_GREEN |
456 A2XX_RB_COLOR_MASK_WRITE_BLUE |
457 A2XX_RB_COLOR_MASK_WRITE_ALPHA);
458
459 OUT_PKT3(ring, CP_SET_CONSTANT, 5);
460 OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_RED));
461 OUT_RING(ring, 0x00000000); /* RB_BLEND_RED */
462 OUT_RING(ring, 0x00000000); /* RB_BLEND_GREEN */
463 OUT_RING(ring, 0x00000000); /* RB_BLEND_BLUE */
464 OUT_RING(ring, 0x000000ff); /* RB_BLEND_ALPHA */
465 }
466
467 static void
468 fd2_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target)
469 {
470 __OUT_IB(ring, false, target);
471 }
472
473 void
474 fd2_emit_init(struct pipe_context *pctx)
475 {
476 struct fd_context *ctx = fd_context(pctx);
477 ctx->emit_ib = fd2_emit_ib;
478 }