1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "pipe/p_state.h"
28bf215546Sopenharmony_ci#include "util/format/u_format.h"
29bf215546Sopenharmony_ci#include "util/u_helpers.h"
30bf215546Sopenharmony_ci#include "util/u_memory.h"
31bf215546Sopenharmony_ci#include "util/u_string.h"
32bf215546Sopenharmony_ci#include "util/u_viewport.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "freedreno_query_hw.h"
35bf215546Sopenharmony_ci#include "freedreno_resource.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "fd4_blend.h"
38bf215546Sopenharmony_ci#include "fd4_context.h"
39bf215546Sopenharmony_ci#include "fd4_emit.h"
40bf215546Sopenharmony_ci#include "fd4_format.h"
41bf215546Sopenharmony_ci#include "fd4_image.h"
42bf215546Sopenharmony_ci#include "fd4_program.h"
43bf215546Sopenharmony_ci#include "fd4_rasterizer.h"
44bf215546Sopenharmony_ci#include "fd4_texture.h"
45bf215546Sopenharmony_ci#include "fd4_zsa.h"
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci#define emit_const_user fd4_emit_const_user
48bf215546Sopenharmony_ci#define emit_const_bo   fd4_emit_const_bo
49bf215546Sopenharmony_ci#include "ir3_const.h"
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci/* regid:          base const register
52bf215546Sopenharmony_ci * prsc or dwords: buffer containing constant values
53bf215546Sopenharmony_ci * sizedwords:     size of const value buffer
54bf215546Sopenharmony_ci */
55bf215546Sopenharmony_cistatic void
56bf215546Sopenharmony_cifd4_emit_const_user(struct fd_ringbuffer *ring,
57bf215546Sopenharmony_ci                    const struct ir3_shader_variant *v, uint32_t regid,
58bf215546Sopenharmony_ci                    uint32_t sizedwords, const uint32_t *dwords)
59bf215546Sopenharmony_ci{
60bf215546Sopenharmony_ci   emit_const_asserts(ring, v, regid, sizedwords);
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + sizedwords);
63bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid / 4) |
64bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
65bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(v->type)) |
66bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_NUM_UNIT(sizedwords / 4));
67bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
68bf215546Sopenharmony_ci                     CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
69bf215546Sopenharmony_ci   for (int i = 0; i < sizedwords; i++)
70bf215546Sopenharmony_ci      OUT_RING(ring, dwords[i]);
71bf215546Sopenharmony_ci}
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_cistatic void
74bf215546Sopenharmony_cifd4_emit_const_bo(struct fd_ringbuffer *ring,
75bf215546Sopenharmony_ci                  const struct ir3_shader_variant *v, uint32_t regid,
76bf215546Sopenharmony_ci                  uint32_t offset, uint32_t sizedwords, struct fd_bo *bo)
77bf215546Sopenharmony_ci{
78bf215546Sopenharmony_ci   uint32_t dst_off = regid / 4;
79bf215546Sopenharmony_ci   assert(dst_off % 4 == 0);
80bf215546Sopenharmony_ci   uint32_t num_unit = sizedwords / 4;
81bf215546Sopenharmony_ci   assert(num_unit % 4 == 0);
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   emit_const_asserts(ring, v, regid, sizedwords);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2);
86bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(dst_off) |
87bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_SRC(SS4_INDIRECT) |
88bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(v->type)) |
89bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_NUM_UNIT(num_unit));
90bf215546Sopenharmony_ci   OUT_RELOC(ring, bo, offset, CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS), 0);
91bf215546Sopenharmony_ci}
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_cistatic void
94bf215546Sopenharmony_cifd4_emit_const_ptrs(struct fd_ringbuffer *ring, gl_shader_stage type,
95bf215546Sopenharmony_ci                    uint32_t regid, uint32_t num, struct fd_bo **bos,
96bf215546Sopenharmony_ci                    uint32_t *offsets)
97bf215546Sopenharmony_ci{
98bf215546Sopenharmony_ci   uint32_t anum = align(num, 4);
99bf215546Sopenharmony_ci   uint32_t i;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   assert((regid % 4) == 0);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + anum);
104bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid / 4) |
105bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
106bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
107bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_NUM_UNIT(anum / 4));
108bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
109bf215546Sopenharmony_ci                     CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   for (i = 0; i < num; i++) {
112bf215546Sopenharmony_ci      if (bos[i]) {
113bf215546Sopenharmony_ci         OUT_RELOC(ring, bos[i], offsets[i], 0, 0);
114bf215546Sopenharmony_ci      } else {
115bf215546Sopenharmony_ci         OUT_RING(ring, 0xbad00000 | (i << 16));
116bf215546Sopenharmony_ci      }
117bf215546Sopenharmony_ci   }
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   for (; i < anum; i++)
120bf215546Sopenharmony_ci      OUT_RING(ring, 0xffffffff);
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistatic bool
124bf215546Sopenharmony_ciis_stateobj(struct fd_ringbuffer *ring)
125bf215546Sopenharmony_ci{
126bf215546Sopenharmony_ci   return false;
127bf215546Sopenharmony_ci}
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_cistatic void
130bf215546Sopenharmony_ciemit_const_ptrs(struct fd_ringbuffer *ring, const struct ir3_shader_variant *v,
131bf215546Sopenharmony_ci                uint32_t dst_offset, uint32_t num, struct fd_bo **bos,
132bf215546Sopenharmony_ci                uint32_t *offsets)
133bf215546Sopenharmony_ci{
134bf215546Sopenharmony_ci   /* TODO inline this */
135bf215546Sopenharmony_ci   assert(dst_offset + num <= v->constlen * 4);
136bf215546Sopenharmony_ci   fd4_emit_const_ptrs(ring, v->type, dst_offset, num, bos, offsets);
137bf215546Sopenharmony_ci}
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_civoid
140bf215546Sopenharmony_cifd4_emit_cs_consts(const struct ir3_shader_variant *v,
141bf215546Sopenharmony_ci                   struct fd_ringbuffer *ring, struct fd_context *ctx,
142bf215546Sopenharmony_ci                   const struct pipe_grid_info *info)
143bf215546Sopenharmony_ci{
144bf215546Sopenharmony_ci   ir3_emit_cs_consts(v, ring, ctx, info);
145bf215546Sopenharmony_ci}
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_cistatic void
148bf215546Sopenharmony_ciemit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
149bf215546Sopenharmony_ci              enum a4xx_state_block sb, struct fd_texture_stateobj *tex,
150bf215546Sopenharmony_ci              const struct ir3_shader_variant *v)
151bf215546Sopenharmony_ci{
152bf215546Sopenharmony_ci   static const uint32_t bcolor_reg[] = {
153bf215546Sopenharmony_ci      [SB4_VS_TEX] = REG_A4XX_TPL1_TP_VS_BORDER_COLOR_BASE_ADDR,
154bf215546Sopenharmony_ci      [SB4_FS_TEX] = REG_A4XX_TPL1_TP_FS_BORDER_COLOR_BASE_ADDR,
155bf215546Sopenharmony_ci      [SB4_CS_TEX] = REG_A4XX_TPL1_TP_CS_BORDER_COLOR_BASE_ADDR,
156bf215546Sopenharmony_ci   };
157bf215546Sopenharmony_ci   struct fd4_context *fd4_ctx = fd4_context(ctx);
158bf215546Sopenharmony_ci   bool needs_border = false;
159bf215546Sopenharmony_ci   unsigned i;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci   if (tex->num_samplers > 0 || tex->num_textures > 0) {
162bf215546Sopenharmony_ci      int num_samplers = tex->num_samplers;
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci      /* We want to always make sure that there's at least one sampler if
165bf215546Sopenharmony_ci       * there are going to be texture accesses. Gallium might not upload a
166bf215546Sopenharmony_ci       * sampler for e.g. buffer textures.
167bf215546Sopenharmony_ci       */
168bf215546Sopenharmony_ci      if (num_samplers == 0)
169bf215546Sopenharmony_ci         num_samplers++;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci      /* not sure if this is an a420.0 workaround, but we seem
172bf215546Sopenharmony_ci       * to need to emit these in pairs.. emit a final dummy
173bf215546Sopenharmony_ci       * entry if odd # of samplers:
174bf215546Sopenharmony_ci       */
175bf215546Sopenharmony_ci      num_samplers = align(num_samplers, 2);
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci      /* output sampler state: */
178bf215546Sopenharmony_ci      OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (2 * num_samplers));
179bf215546Sopenharmony_ci      OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
180bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
181bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
182bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_NUM_UNIT(num_samplers));
183bf215546Sopenharmony_ci      OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER) |
184bf215546Sopenharmony_ci                        CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
185bf215546Sopenharmony_ci      for (i = 0; i < tex->num_samplers; i++) {
186bf215546Sopenharmony_ci         static const struct fd4_sampler_stateobj dummy_sampler = {};
187bf215546Sopenharmony_ci         const struct fd4_sampler_stateobj *sampler =
188bf215546Sopenharmony_ci            tex->samplers[i] ? fd4_sampler_stateobj(tex->samplers[i])
189bf215546Sopenharmony_ci                             : &dummy_sampler;
190bf215546Sopenharmony_ci         OUT_RING(ring, sampler->texsamp0);
191bf215546Sopenharmony_ci         OUT_RING(ring, sampler->texsamp1);
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci         needs_border |= sampler->needs_border;
194bf215546Sopenharmony_ci      }
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_ci      for (; i < num_samplers; i++) {
197bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
198bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
199bf215546Sopenharmony_ci      }
200bf215546Sopenharmony_ci   }
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ci   if (tex->num_textures > 0) {
203bf215546Sopenharmony_ci      unsigned num_textures = tex->num_textures + v->astc_srgb.count + v->tg4.count;
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci      /* emit texture state: */
206bf215546Sopenharmony_ci      OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (8 * num_textures));
207bf215546Sopenharmony_ci      OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
208bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
209bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
210bf215546Sopenharmony_ci                        CP_LOAD_STATE4_0_NUM_UNIT(num_textures));
211bf215546Sopenharmony_ci      OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS) |
212bf215546Sopenharmony_ci                        CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
213bf215546Sopenharmony_ci      for (i = 0; i < tex->num_textures; i++) {
214bf215546Sopenharmony_ci         static const struct fd4_pipe_sampler_view dummy_view = {};
215bf215546Sopenharmony_ci         const struct fd4_pipe_sampler_view *view =
216bf215546Sopenharmony_ci            tex->textures[i] ? fd4_pipe_sampler_view(tex->textures[i])
217bf215546Sopenharmony_ci                             : &dummy_view;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst0);
220bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst1);
221bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst2);
222bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst3);
223bf215546Sopenharmony_ci         if (view->base.texture) {
224bf215546Sopenharmony_ci            struct fd_resource *rsc = fd_resource(view->base.texture);
225bf215546Sopenharmony_ci            if (view->base.format == PIPE_FORMAT_X32_S8X24_UINT)
226bf215546Sopenharmony_ci               rsc = rsc->stencil;
227bf215546Sopenharmony_ci            OUT_RELOC(ring, rsc->bo, view->offset, view->texconst4, 0);
228bf215546Sopenharmony_ci         } else {
229bf215546Sopenharmony_ci            OUT_RING(ring, 0x00000000);
230bf215546Sopenharmony_ci         }
231bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
232bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
233bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
234bf215546Sopenharmony_ci      }
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci      for (i = 0; i < v->astc_srgb.count; i++) {
237bf215546Sopenharmony_ci         static const struct fd4_pipe_sampler_view dummy_view = {};
238bf215546Sopenharmony_ci         const struct fd4_pipe_sampler_view *view;
239bf215546Sopenharmony_ci         unsigned idx = v->astc_srgb.orig_idx[i];
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci         view = tex->textures[idx] ? fd4_pipe_sampler_view(tex->textures[idx])
242bf215546Sopenharmony_ci                                   : &dummy_view;
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci         assert(view->texconst0 & A4XX_TEX_CONST_0_SRGB);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst0 & ~A4XX_TEX_CONST_0_SRGB);
247bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst1);
248bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst2);
249bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst3);
250bf215546Sopenharmony_ci         if (view->base.texture) {
251bf215546Sopenharmony_ci            struct fd_resource *rsc = fd_resource(view->base.texture);
252bf215546Sopenharmony_ci            OUT_RELOC(ring, rsc->bo, view->offset, view->texconst4, 0);
253bf215546Sopenharmony_ci         } else {
254bf215546Sopenharmony_ci            OUT_RING(ring, 0x00000000);
255bf215546Sopenharmony_ci         }
256bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
257bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
258bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
259bf215546Sopenharmony_ci      }
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci      for (i = 0; i < v->tg4.count; i++) {
262bf215546Sopenharmony_ci         static const struct fd4_pipe_sampler_view dummy_view = {};
263bf215546Sopenharmony_ci         const struct fd4_pipe_sampler_view *view;
264bf215546Sopenharmony_ci         unsigned idx = v->tg4.orig_idx[i];
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci         view = tex->textures[idx] ? fd4_pipe_sampler_view(tex->textures[idx])
267bf215546Sopenharmony_ci                                   : &dummy_view;
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci         unsigned texconst0 = view->texconst0 & ~(0xfff << 4);
270bf215546Sopenharmony_ci         texconst0 |= A4XX_TEX_CONST_0_SWIZ_X(A4XX_TEX_X) |
271bf215546Sopenharmony_ci            A4XX_TEX_CONST_0_SWIZ_Y(A4XX_TEX_Y) |
272bf215546Sopenharmony_ci            A4XX_TEX_CONST_0_SWIZ_Z(A4XX_TEX_Z) |
273bf215546Sopenharmony_ci            A4XX_TEX_CONST_0_SWIZ_W(A4XX_TEX_W);
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ci         /* Remap integer formats as unorm (will be fixed up in shader) */
276bf215546Sopenharmony_ci         if (util_format_is_pure_integer(view->base.format)) {
277bf215546Sopenharmony_ci            texconst0 &= ~A4XX_TEX_CONST_0_FMT__MASK;
278bf215546Sopenharmony_ci            switch (fd4_pipe2tex(view->base.format)) {
279bf215546Sopenharmony_ci            case TFMT4_8_8_8_8_UINT:
280bf215546Sopenharmony_ci            case TFMT4_8_8_8_8_SINT:
281bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_8_8_8_8_UNORM);
282bf215546Sopenharmony_ci               break;
283bf215546Sopenharmony_ci            case TFMT4_8_8_UINT:
284bf215546Sopenharmony_ci            case TFMT4_8_8_SINT:
285bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_8_8_UNORM);
286bf215546Sopenharmony_ci               break;
287bf215546Sopenharmony_ci            case TFMT4_8_UINT:
288bf215546Sopenharmony_ci            case TFMT4_8_SINT:
289bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_8_UNORM);
290bf215546Sopenharmony_ci               break;
291bf215546Sopenharmony_ci
292bf215546Sopenharmony_ci            case TFMT4_16_16_16_16_UINT:
293bf215546Sopenharmony_ci            case TFMT4_16_16_16_16_SINT:
294bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_16_16_16_16_UNORM);
295bf215546Sopenharmony_ci               break;
296bf215546Sopenharmony_ci            case TFMT4_16_16_UINT:
297bf215546Sopenharmony_ci            case TFMT4_16_16_SINT:
298bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_16_16_UNORM);
299bf215546Sopenharmony_ci               break;
300bf215546Sopenharmony_ci            case TFMT4_16_UINT:
301bf215546Sopenharmony_ci            case TFMT4_16_SINT:
302bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_16_UNORM);
303bf215546Sopenharmony_ci               break;
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci            case TFMT4_32_32_32_32_UINT:
306bf215546Sopenharmony_ci            case TFMT4_32_32_32_32_SINT:
307bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_32_32_32_32_FLOAT);
308bf215546Sopenharmony_ci               break;
309bf215546Sopenharmony_ci            case TFMT4_32_32_UINT:
310bf215546Sopenharmony_ci            case TFMT4_32_32_SINT:
311bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_32_32_FLOAT);
312bf215546Sopenharmony_ci               break;
313bf215546Sopenharmony_ci            case TFMT4_32_UINT:
314bf215546Sopenharmony_ci            case TFMT4_32_SINT:
315bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_32_FLOAT);
316bf215546Sopenharmony_ci               break;
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_ci            case TFMT4_10_10_10_2_UINT:
319bf215546Sopenharmony_ci               texconst0 |= A4XX_TEX_CONST_0_FMT(TFMT4_10_10_10_2_UNORM);
320bf215546Sopenharmony_ci               break;
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_ci            default:
323bf215546Sopenharmony_ci               assert(0);
324bf215546Sopenharmony_ci            }
325bf215546Sopenharmony_ci         }
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci         OUT_RING(ring, texconst0);
328bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst1);
329bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst2);
330bf215546Sopenharmony_ci         OUT_RING(ring, view->texconst3);
331bf215546Sopenharmony_ci         if (view->base.texture) {
332bf215546Sopenharmony_ci            struct fd_resource *rsc = fd_resource(view->base.texture);
333bf215546Sopenharmony_ci            OUT_RELOC(ring, rsc->bo, view->offset, view->texconst4, 0);
334bf215546Sopenharmony_ci         } else {
335bf215546Sopenharmony_ci            OUT_RING(ring, 0x00000000);
336bf215546Sopenharmony_ci         }
337bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
338bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
339bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
340bf215546Sopenharmony_ci      }
341bf215546Sopenharmony_ci   } else {
342bf215546Sopenharmony_ci      assert(v->astc_srgb.count == 0);
343bf215546Sopenharmony_ci      assert(v->tg4.count == 0);
344bf215546Sopenharmony_ci   }
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   if (needs_border) {
347bf215546Sopenharmony_ci      unsigned off;
348bf215546Sopenharmony_ci      void *ptr;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci      u_upload_alloc(fd4_ctx->border_color_uploader, 0,
351bf215546Sopenharmony_ci                     BORDER_COLOR_UPLOAD_SIZE, BORDER_COLOR_UPLOAD_SIZE, &off,
352bf215546Sopenharmony_ci                     &fd4_ctx->border_color_buf, &ptr);
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci      fd_setup_border_colors(tex, ptr, 0);
355bf215546Sopenharmony_ci      OUT_PKT0(ring, bcolor_reg[sb], 1);
356bf215546Sopenharmony_ci      OUT_RELOC(ring, fd_resource(fd4_ctx->border_color_buf)->bo, off, 0, 0);
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci      u_upload_unmap(fd4_ctx->border_color_uploader);
359bf215546Sopenharmony_ci   }
360bf215546Sopenharmony_ci}
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci/* emit texture state for mem->gmem restore operation.. eventually it would
363bf215546Sopenharmony_ci * be good to get rid of this and use normal CSO/etc state for more of these
364bf215546Sopenharmony_ci * special cases..
365bf215546Sopenharmony_ci */
366bf215546Sopenharmony_civoid
367bf215546Sopenharmony_cifd4_emit_gmem_restore_tex(struct fd_ringbuffer *ring, unsigned nr_bufs,
368bf215546Sopenharmony_ci                          struct pipe_surface **bufs)
369bf215546Sopenharmony_ci{
370bf215546Sopenharmony_ci   unsigned char mrt_comp[A4XX_MAX_RENDER_TARGETS];
371bf215546Sopenharmony_ci   int i;
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci   for (i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
374bf215546Sopenharmony_ci      mrt_comp[i] = (i < nr_bufs) ? 0xf : 0;
375bf215546Sopenharmony_ci   }
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci   /* output sampler state: */
378bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (2 * nr_bufs));
379bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
380bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
381bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_BLOCK(SB4_FS_TEX) |
382bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_NUM_UNIT(nr_bufs));
383bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER) |
384bf215546Sopenharmony_ci                     CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
385bf215546Sopenharmony_ci   for (i = 0; i < nr_bufs; i++) {
386bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_TEX_SAMP_0_XY_MAG(A4XX_TEX_NEAREST) |
387bf215546Sopenharmony_ci                        A4XX_TEX_SAMP_0_XY_MIN(A4XX_TEX_NEAREST) |
388bf215546Sopenharmony_ci                        A4XX_TEX_SAMP_0_WRAP_S(A4XX_TEX_CLAMP_TO_EDGE) |
389bf215546Sopenharmony_ci                        A4XX_TEX_SAMP_0_WRAP_T(A4XX_TEX_CLAMP_TO_EDGE) |
390bf215546Sopenharmony_ci                        A4XX_TEX_SAMP_0_WRAP_R(A4XX_TEX_REPEAT));
391bf215546Sopenharmony_ci      OUT_RING(ring, 0x00000000);
392bf215546Sopenharmony_ci   }
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci   /* emit texture state: */
395bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (8 * nr_bufs));
396bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
397bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
398bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_STATE_BLOCK(SB4_FS_TEX) |
399bf215546Sopenharmony_ci                     CP_LOAD_STATE4_0_NUM_UNIT(nr_bufs));
400bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS) |
401bf215546Sopenharmony_ci                     CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
402bf215546Sopenharmony_ci   for (i = 0; i < nr_bufs; i++) {
403bf215546Sopenharmony_ci      if (bufs[i]) {
404bf215546Sopenharmony_ci         struct fd_resource *rsc = fd_resource(bufs[i]->texture);
405bf215546Sopenharmony_ci         enum pipe_format format = fd_gmem_restore_format(bufs[i]->format);
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_ci         /* The restore blit_zs shader expects stencil in sampler 0,
408bf215546Sopenharmony_ci          * and depth in sampler 1
409bf215546Sopenharmony_ci          */
410bf215546Sopenharmony_ci         if (rsc->stencil && (i == 0)) {
411bf215546Sopenharmony_ci            rsc = rsc->stencil;
412bf215546Sopenharmony_ci            format = fd_gmem_restore_format(rsc->b.b.format);
413bf215546Sopenharmony_ci         }
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci         /* note: PIPE_BUFFER disallowed for surfaces */
416bf215546Sopenharmony_ci         unsigned lvl = bufs[i]->u.tex.level;
417bf215546Sopenharmony_ci         unsigned offset =
418bf215546Sopenharmony_ci            fd_resource_offset(rsc, lvl, bufs[i]->u.tex.first_layer);
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ci         /* z32 restore is accomplished using depth write.  If there is
421bf215546Sopenharmony_ci          * no stencil component (ie. PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
422bf215546Sopenharmony_ci          * then no render target:
423bf215546Sopenharmony_ci          *
424bf215546Sopenharmony_ci          * (The same applies for z32_s8x24, since for stencil sampler
425bf215546Sopenharmony_ci          * state the above 'if' will replace 'format' with s8)
426bf215546Sopenharmony_ci          */
427bf215546Sopenharmony_ci         if ((format == PIPE_FORMAT_Z32_FLOAT) ||
428bf215546Sopenharmony_ci             (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT))
429bf215546Sopenharmony_ci            mrt_comp[i] = 0;
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci         assert(bufs[i]->u.tex.first_layer == bufs[i]->u.tex.last_layer);
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_0_FMT(fd4_pipe2tex(format)) |
434bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_TYPE(A4XX_TEX_2D) |
435bf215546Sopenharmony_ci                           fd4_tex_swiz(format, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
436bf215546Sopenharmony_ci                                        PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W));
437bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_1_WIDTH(bufs[i]->width) |
438bf215546Sopenharmony_ci                           A4XX_TEX_CONST_1_HEIGHT(bufs[i]->height));
439bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(fd_resource_pitch(rsc, lvl)));
440bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
441bf215546Sopenharmony_ci         OUT_RELOC(ring, rsc->bo, offset, 0, 0);
442bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
443bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
444bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
445bf215546Sopenharmony_ci      } else {
446bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_0_FMT(0) |
447bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_TYPE(A4XX_TEX_2D) |
448bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_SWIZ_X(A4XX_TEX_ONE) |
449bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_SWIZ_Y(A4XX_TEX_ONE) |
450bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_SWIZ_Z(A4XX_TEX_ONE) |
451bf215546Sopenharmony_ci                           A4XX_TEX_CONST_0_SWIZ_W(A4XX_TEX_ONE));
452bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_1_WIDTH(0) | A4XX_TEX_CONST_1_HEIGHT(0));
453bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(0));
454bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
455bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
456bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
457bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
458bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
459bf215546Sopenharmony_ci      }
460bf215546Sopenharmony_ci   }
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RB_RENDER_COMPONENTS, 1);
463bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_RENDER_COMPONENTS_RT0(mrt_comp[0]) |
464bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT1(mrt_comp[1]) |
465bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT2(mrt_comp[2]) |
466bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT3(mrt_comp[3]) |
467bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT4(mrt_comp[4]) |
468bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT5(mrt_comp[5]) |
469bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT6(mrt_comp[6]) |
470bf215546Sopenharmony_ci                     A4XX_RB_RENDER_COMPONENTS_RT7(mrt_comp[7]));
471bf215546Sopenharmony_ci}
472bf215546Sopenharmony_ci
473bf215546Sopenharmony_cistatic void
474bf215546Sopenharmony_ciemit_ssbos(struct fd_context *ctx, struct fd_ringbuffer *ring,
475bf215546Sopenharmony_ci      enum a4xx_state_block sb, struct fd_shaderbuf_stateobj *so)
476bf215546Sopenharmony_ci{
477bf215546Sopenharmony_ci   unsigned count = util_last_bit(so->enabled_mask);
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ci   if (count == 0)
480bf215546Sopenharmony_ci      return;
481bf215546Sopenharmony_ci
482bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (4 * count));
483bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
484bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
485bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
486bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_NUM_UNIT(count));
487bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(0) |
488bf215546Sopenharmony_ci         CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
489bf215546Sopenharmony_ci   for (unsigned i = 0; i < count; i++) {
490bf215546Sopenharmony_ci      struct pipe_shader_buffer *buf = &so->sb[i];
491bf215546Sopenharmony_ci      if (buf->buffer) {
492bf215546Sopenharmony_ci         struct fd_resource *rsc = fd_resource(buf->buffer);
493bf215546Sopenharmony_ci         OUT_RELOC(ring, rsc->bo, buf->buffer_offset, 0, 0);
494bf215546Sopenharmony_ci      } else {
495bf215546Sopenharmony_ci         OUT_RING(ring, 0x00000000);
496bf215546Sopenharmony_ci      }
497bf215546Sopenharmony_ci      OUT_RING(ring, 0x00000000);
498bf215546Sopenharmony_ci      OUT_RING(ring, 0x00000000);
499bf215546Sopenharmony_ci      OUT_RING(ring, 0x00000000);
500bf215546Sopenharmony_ci   }
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_LOAD_STATE4, 2 + (2 * count));
503bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(0) |
504bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
505bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_STATE_BLOCK(sb) |
506bf215546Sopenharmony_ci         CP_LOAD_STATE4_0_NUM_UNIT(count));
507bf215546Sopenharmony_ci   OUT_RING(ring, CP_LOAD_STATE4_1_STATE_TYPE(1) |
508bf215546Sopenharmony_ci         CP_LOAD_STATE4_1_EXT_SRC_ADDR(0));
509bf215546Sopenharmony_ci   for (unsigned i = 0; i < count; i++) {
510bf215546Sopenharmony_ci      struct pipe_shader_buffer *buf = &so->sb[i];
511bf215546Sopenharmony_ci      unsigned sz = buf->buffer_size;
512bf215546Sopenharmony_ci
513bf215546Sopenharmony_ci      /* width is in dwords, overflows into height: */
514bf215546Sopenharmony_ci      sz /= 4;
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_SSBO_1_0_WIDTH(sz));
517bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_SSBO_1_1_HEIGHT(sz >> 16));
518bf215546Sopenharmony_ci   }
519bf215546Sopenharmony_ci}
520bf215546Sopenharmony_ci
521bf215546Sopenharmony_civoid
522bf215546Sopenharmony_cifd4_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd4_emit *emit)
523bf215546Sopenharmony_ci{
524bf215546Sopenharmony_ci   int32_t i, j, last = -1;
525bf215546Sopenharmony_ci   uint32_t total_in = 0;
526bf215546Sopenharmony_ci   const struct fd_vertex_state *vtx = emit->vtx;
527bf215546Sopenharmony_ci   const struct ir3_shader_variant *vp = fd4_emit_get_vp(emit);
528bf215546Sopenharmony_ci   unsigned vertex_regid = regid(63, 0);
529bf215546Sopenharmony_ci   unsigned instance_regid = regid(63, 0);
530bf215546Sopenharmony_ci   unsigned vtxcnt_regid = regid(63, 0);
531bf215546Sopenharmony_ci
532bf215546Sopenharmony_ci   /* Note that sysvals come *after* normal inputs: */
533bf215546Sopenharmony_ci   for (i = 0; i < vp->inputs_count; i++) {
534bf215546Sopenharmony_ci      if (!vp->inputs[i].compmask)
535bf215546Sopenharmony_ci         continue;
536bf215546Sopenharmony_ci      if (vp->inputs[i].sysval) {
537bf215546Sopenharmony_ci         switch (vp->inputs[i].slot) {
538bf215546Sopenharmony_ci         case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE:
539bf215546Sopenharmony_ci            vertex_regid = vp->inputs[i].regid;
540bf215546Sopenharmony_ci            break;
541bf215546Sopenharmony_ci         case SYSTEM_VALUE_INSTANCE_ID:
542bf215546Sopenharmony_ci            instance_regid = vp->inputs[i].regid;
543bf215546Sopenharmony_ci            break;
544bf215546Sopenharmony_ci         case SYSTEM_VALUE_VERTEX_CNT:
545bf215546Sopenharmony_ci            vtxcnt_regid = vp->inputs[i].regid;
546bf215546Sopenharmony_ci            break;
547bf215546Sopenharmony_ci         default:
548bf215546Sopenharmony_ci            unreachable("invalid system value");
549bf215546Sopenharmony_ci            break;
550bf215546Sopenharmony_ci         }
551bf215546Sopenharmony_ci      } else if (i < vtx->vtx->num_elements) {
552bf215546Sopenharmony_ci         last = i;
553bf215546Sopenharmony_ci      }
554bf215546Sopenharmony_ci   }
555bf215546Sopenharmony_ci
556bf215546Sopenharmony_ci   for (i = 0, j = 0; i <= last; i++) {
557bf215546Sopenharmony_ci      assert(!vp->inputs[i].sysval);
558bf215546Sopenharmony_ci      if (vp->inputs[i].compmask) {
559bf215546Sopenharmony_ci         struct pipe_vertex_element *elem = &vtx->vtx->pipe[i];
560bf215546Sopenharmony_ci         const struct pipe_vertex_buffer *vb =
561bf215546Sopenharmony_ci            &vtx->vertexbuf.vb[elem->vertex_buffer_index];
562bf215546Sopenharmony_ci         struct fd_resource *rsc = fd_resource(vb->buffer.resource);
563bf215546Sopenharmony_ci         enum pipe_format pfmt = elem->src_format;
564bf215546Sopenharmony_ci         enum a4xx_vtx_fmt fmt = fd4_pipe2vtx(pfmt);
565bf215546Sopenharmony_ci         bool switchnext = (i != last) || (vertex_regid != regid(63, 0)) ||
566bf215546Sopenharmony_ci                           (instance_regid != regid(63, 0)) ||
567bf215546Sopenharmony_ci                           (vtxcnt_regid != regid(63, 0));
568bf215546Sopenharmony_ci         bool isint = util_format_is_pure_integer(pfmt);
569bf215546Sopenharmony_ci         uint32_t fs = util_format_get_blocksize(pfmt);
570bf215546Sopenharmony_ci         uint32_t off = vb->buffer_offset + elem->src_offset;
571bf215546Sopenharmony_ci         uint32_t size = vb->buffer.resource->width0 - off;
572bf215546Sopenharmony_ci         assert(fmt != VFMT4_NONE);
573bf215546Sopenharmony_ci
574bf215546Sopenharmony_ci         OUT_PKT0(ring, REG_A4XX_VFD_FETCH(j), 4);
575bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_VFD_FETCH_INSTR_0_FETCHSIZE(fs - 1) |
576bf215546Sopenharmony_ci                           A4XX_VFD_FETCH_INSTR_0_BUFSTRIDE(vb->stride) |
577bf215546Sopenharmony_ci                           COND(elem->instance_divisor,
578bf215546Sopenharmony_ci                                A4XX_VFD_FETCH_INSTR_0_INSTANCED) |
579bf215546Sopenharmony_ci                           COND(switchnext, A4XX_VFD_FETCH_INSTR_0_SWITCHNEXT));
580bf215546Sopenharmony_ci         OUT_RELOC(ring, rsc->bo, off, 0, 0);
581bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_VFD_FETCH_INSTR_2_SIZE(size));
582bf215546Sopenharmony_ci         OUT_RING(ring, A4XX_VFD_FETCH_INSTR_3_STEPRATE(
583bf215546Sopenharmony_ci                           MAX2(1, elem->instance_divisor)));
584bf215546Sopenharmony_ci
585bf215546Sopenharmony_ci         OUT_PKT0(ring, REG_A4XX_VFD_DECODE_INSTR(j), 1);
586bf215546Sopenharmony_ci         OUT_RING(ring,
587bf215546Sopenharmony_ci                  A4XX_VFD_DECODE_INSTR_CONSTFILL |
588bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_WRITEMASK(vp->inputs[i].compmask) |
589bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_FORMAT(fmt) |
590bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_SWAP(fd4_pipe2swap(pfmt)) |
591bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_REGID(vp->inputs[i].regid) |
592bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_SHIFTCNT(fs) |
593bf215546Sopenharmony_ci                     A4XX_VFD_DECODE_INSTR_LASTCOMPVALID |
594bf215546Sopenharmony_ci                     COND(isint, A4XX_VFD_DECODE_INSTR_INT) |
595bf215546Sopenharmony_ci                     COND(switchnext, A4XX_VFD_DECODE_INSTR_SWITCHNEXT));
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci         total_in += util_bitcount(vp->inputs[i].compmask);
598bf215546Sopenharmony_ci         j++;
599bf215546Sopenharmony_ci      }
600bf215546Sopenharmony_ci   }
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_ci   /* hw doesn't like to be configured for zero vbo's, it seems: */
603bf215546Sopenharmony_ci   if (last < 0) {
604bf215546Sopenharmony_ci      /* just recycle the shader bo, we just need to point to *something*
605bf215546Sopenharmony_ci       * valid:
606bf215546Sopenharmony_ci       */
607bf215546Sopenharmony_ci      struct fd_bo *dummy_vbo = vp->bo;
608bf215546Sopenharmony_ci      bool switchnext = (vertex_regid != regid(63, 0)) ||
609bf215546Sopenharmony_ci                        (instance_regid != regid(63, 0)) ||
610bf215546Sopenharmony_ci                        (vtxcnt_regid != regid(63, 0));
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_VFD_FETCH(0), 4);
613bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_VFD_FETCH_INSTR_0_FETCHSIZE(0) |
614bf215546Sopenharmony_ci                        A4XX_VFD_FETCH_INSTR_0_BUFSTRIDE(0) |
615bf215546Sopenharmony_ci                        COND(switchnext, A4XX_VFD_FETCH_INSTR_0_SWITCHNEXT));
616bf215546Sopenharmony_ci      OUT_RELOC(ring, dummy_vbo, 0, 0, 0);
617bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_VFD_FETCH_INSTR_2_SIZE(1));
618bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_VFD_FETCH_INSTR_3_STEPRATE(1));
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_VFD_DECODE_INSTR(0), 1);
621bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_VFD_DECODE_INSTR_CONSTFILL |
622bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_WRITEMASK(0x1) |
623bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_FORMAT(VFMT4_8_UNORM) |
624bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_SWAP(XYZW) |
625bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_REGID(regid(0, 0)) |
626bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_SHIFTCNT(1) |
627bf215546Sopenharmony_ci                        A4XX_VFD_DECODE_INSTR_LASTCOMPVALID |
628bf215546Sopenharmony_ci                        COND(switchnext, A4XX_VFD_DECODE_INSTR_SWITCHNEXT));
629bf215546Sopenharmony_ci
630bf215546Sopenharmony_ci      total_in = 1;
631bf215546Sopenharmony_ci      j = 1;
632bf215546Sopenharmony_ci   }
633bf215546Sopenharmony_ci
634bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_VFD_CONTROL_0, 5);
635bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_VFD_CONTROL_0_TOTALATTRTOVS(total_in) |
636bf215546Sopenharmony_ci                     0xa0000 | /* XXX */
637bf215546Sopenharmony_ci                     A4XX_VFD_CONTROL_0_STRMDECINSTRCNT(j) |
638bf215546Sopenharmony_ci                     A4XX_VFD_CONTROL_0_STRMFETCHINSTRCNT(j));
639bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_VFD_CONTROL_1_MAXSTORAGE(129) | // XXX
640bf215546Sopenharmony_ci                     A4XX_VFD_CONTROL_1_REGID4VTX(vertex_regid) |
641bf215546Sopenharmony_ci                     A4XX_VFD_CONTROL_1_REGID4INST(instance_regid));
642bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000); /* XXX VFD_CONTROL_2 */
643bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_VFD_CONTROL_3_REGID_VTXCNT(vtxcnt_regid));
644bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000); /* XXX VFD_CONTROL_4 */
645bf215546Sopenharmony_ci
646bf215546Sopenharmony_ci   /* cache invalidate, otherwise vertex fetch could see
647bf215546Sopenharmony_ci    * stale vbo contents:
648bf215546Sopenharmony_ci    */
649bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UCHE_INVALIDATE0, 2);
650bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
651bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000012);
652bf215546Sopenharmony_ci}
653bf215546Sopenharmony_ci
654bf215546Sopenharmony_civoid
655bf215546Sopenharmony_cifd4_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
656bf215546Sopenharmony_ci               struct fd4_emit *emit)
657bf215546Sopenharmony_ci{
658bf215546Sopenharmony_ci   const struct ir3_shader_variant *vp = fd4_emit_get_vp(emit);
659bf215546Sopenharmony_ci   const struct ir3_shader_variant *fp = fd4_emit_get_fp(emit);
660bf215546Sopenharmony_ci   const enum fd_dirty_3d_state dirty = emit->dirty;
661bf215546Sopenharmony_ci
662bf215546Sopenharmony_ci   emit_marker(ring, 5);
663bf215546Sopenharmony_ci
664bf215546Sopenharmony_ci   if ((dirty & FD_DIRTY_FRAMEBUFFER) && !emit->binning_pass) {
665bf215546Sopenharmony_ci      struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
666bf215546Sopenharmony_ci      unsigned char mrt_comp[A4XX_MAX_RENDER_TARGETS] = {0};
667bf215546Sopenharmony_ci
668bf215546Sopenharmony_ci      for (unsigned i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
669bf215546Sopenharmony_ci         mrt_comp[i] = ((i < pfb->nr_cbufs) && pfb->cbufs[i]) ? 0xf : 0;
670bf215546Sopenharmony_ci      }
671bf215546Sopenharmony_ci
672bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_RENDER_COMPONENTS, 1);
673bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_RENDER_COMPONENTS_RT0(mrt_comp[0]) |
674bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT1(mrt_comp[1]) |
675bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT2(mrt_comp[2]) |
676bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT3(mrt_comp[3]) |
677bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT4(mrt_comp[4]) |
678bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT5(mrt_comp[5]) |
679bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT6(mrt_comp[6]) |
680bf215546Sopenharmony_ci                        A4XX_RB_RENDER_COMPONENTS_RT7(mrt_comp[7]));
681bf215546Sopenharmony_ci   }
682bf215546Sopenharmony_ci
683bf215546Sopenharmony_ci   if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_FRAMEBUFFER)) {
684bf215546Sopenharmony_ci      struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
685bf215546Sopenharmony_ci      struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
686bf215546Sopenharmony_ci      uint32_t rb_alpha_control = zsa->rb_alpha_control;
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci      if (util_format_is_pure_integer(pipe_surface_format(pfb->cbufs[0])))
689bf215546Sopenharmony_ci         rb_alpha_control &= ~A4XX_RB_ALPHA_CONTROL_ALPHA_TEST;
690bf215546Sopenharmony_ci
691bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_ALPHA_CONTROL, 1);
692bf215546Sopenharmony_ci      OUT_RING(ring, rb_alpha_control);
693bf215546Sopenharmony_ci
694bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_STENCIL_CONTROL, 2);
695bf215546Sopenharmony_ci      OUT_RING(ring, zsa->rb_stencil_control);
696bf215546Sopenharmony_ci      OUT_RING(ring, zsa->rb_stencil_control2);
697bf215546Sopenharmony_ci   }
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_ci   if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_STENCIL_REF)) {
700bf215546Sopenharmony_ci      struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
701bf215546Sopenharmony_ci      struct pipe_stencil_ref *sr = &ctx->stencil_ref;
702bf215546Sopenharmony_ci
703bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_STENCILREFMASK, 2);
704bf215546Sopenharmony_ci      OUT_RING(ring, zsa->rb_stencilrefmask |
705bf215546Sopenharmony_ci                        A4XX_RB_STENCILREFMASK_STENCILREF(sr->ref_value[0]));
706bf215546Sopenharmony_ci      OUT_RING(ring, zsa->rb_stencilrefmask_bf |
707bf215546Sopenharmony_ci                        A4XX_RB_STENCILREFMASK_BF_STENCILREF(sr->ref_value[1]));
708bf215546Sopenharmony_ci   }
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_ci   if (dirty & (FD_DIRTY_ZSA | FD_DIRTY_RASTERIZER | FD_DIRTY_PROG)) {
711bf215546Sopenharmony_ci      struct fd4_zsa_stateobj *zsa = fd4_zsa_stateobj(ctx->zsa);
712bf215546Sopenharmony_ci      bool fragz = fp->no_earlyz || fp->has_kill || fp->writes_pos;
713bf215546Sopenharmony_ci      bool latez = !fp->fs.early_fragment_tests && fragz;
714bf215546Sopenharmony_ci      bool clamp = !ctx->rasterizer->depth_clip_near;
715bf215546Sopenharmony_ci
716bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_DEPTH_CONTROL, 1);
717bf215546Sopenharmony_ci      OUT_RING(ring, zsa->rb_depth_control |
718bf215546Sopenharmony_ci                        COND(clamp, A4XX_RB_DEPTH_CONTROL_Z_CLAMP_ENABLE) |
719bf215546Sopenharmony_ci                        COND(latez, A4XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE) |
720bf215546Sopenharmony_ci                        COND(fragz && fp->fragcoord_compmask != 0,
721bf215546Sopenharmony_ci                             A4XX_RB_DEPTH_CONTROL_FORCE_FRAGZ_TO_FS));
722bf215546Sopenharmony_ci
723bf215546Sopenharmony_ci      /* maybe this register/bitfield needs a better name.. this
724bf215546Sopenharmony_ci       * appears to be just disabling early-z
725bf215546Sopenharmony_ci       */
726bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_ALPHA_CONTROL, 1);
727bf215546Sopenharmony_ci      OUT_RING(ring, zsa->gras_alpha_control |
728bf215546Sopenharmony_ci                        COND(latez, A4XX_GRAS_ALPHA_CONTROL_ALPHA_TEST_ENABLE) |
729bf215546Sopenharmony_ci                        COND(fragz && fp->fragcoord_compmask != 0,
730bf215546Sopenharmony_ci                             A4XX_GRAS_ALPHA_CONTROL_FORCE_FRAGZ_TO_FS));
731bf215546Sopenharmony_ci   }
732bf215546Sopenharmony_ci
733bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_RASTERIZER) {
734bf215546Sopenharmony_ci      struct fd4_rasterizer_stateobj *rasterizer =
735bf215546Sopenharmony_ci         fd4_rasterizer_stateobj(ctx->rasterizer);
736bf215546Sopenharmony_ci
737bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_SU_MODE_CONTROL, 1);
738bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_mode_control |
739bf215546Sopenharmony_ci                        A4XX_GRAS_SU_MODE_CONTROL_RENDERING_PASS);
740bf215546Sopenharmony_ci
741bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_SU_POINT_MINMAX, 2);
742bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_point_minmax);
743bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_point_size);
744bf215546Sopenharmony_ci
745bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_SU_POLY_OFFSET_SCALE, 3);
746bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_poly_offset_scale);
747bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_poly_offset_offset);
748bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_su_poly_offset_clamp);
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_CL_CLIP_CNTL, 1);
751bf215546Sopenharmony_ci      OUT_RING(ring, rasterizer->gras_cl_clip_cntl);
752bf215546Sopenharmony_ci   }
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci   /* NOTE: since primitive_restart is not actually part of any
755bf215546Sopenharmony_ci    * state object, we need to make sure that we always emit
756bf215546Sopenharmony_ci    * PRIM_VTX_CNTL.. either that or be more clever and detect
757bf215546Sopenharmony_ci    * when it changes.
758bf215546Sopenharmony_ci    */
759bf215546Sopenharmony_ci   if (emit->info) {
760bf215546Sopenharmony_ci      const struct pipe_draw_info *info = emit->info;
761bf215546Sopenharmony_ci      struct fd4_rasterizer_stateobj *rast =
762bf215546Sopenharmony_ci         fd4_rasterizer_stateobj(ctx->rasterizer);
763bf215546Sopenharmony_ci      uint32_t val = rast->pc_prim_vtx_cntl;
764bf215546Sopenharmony_ci
765bf215546Sopenharmony_ci      if (info->index_size && info->primitive_restart)
766bf215546Sopenharmony_ci         val |= A4XX_PC_PRIM_VTX_CNTL_PRIMITIVE_RESTART;
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci      val |= COND(vp->writes_psize, A4XX_PC_PRIM_VTX_CNTL_PSIZE);
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci      if (fp->total_in > 0) {
771bf215546Sopenharmony_ci         uint32_t varout = align(fp->total_in, 16) / 16;
772bf215546Sopenharmony_ci         if (varout > 1)
773bf215546Sopenharmony_ci            varout = align(varout, 2);
774bf215546Sopenharmony_ci         val |= A4XX_PC_PRIM_VTX_CNTL_VAROUT(varout);
775bf215546Sopenharmony_ci      }
776bf215546Sopenharmony_ci
777bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_PC_PRIM_VTX_CNTL, 2);
778bf215546Sopenharmony_ci      OUT_RING(ring, val);
779bf215546Sopenharmony_ci      OUT_RING(ring, rast->pc_prim_vtx_cntl2);
780bf215546Sopenharmony_ci   }
781bf215546Sopenharmony_ci
782bf215546Sopenharmony_ci   /* NOTE: scissor enabled bit is part of rasterizer state: */
783bf215546Sopenharmony_ci   if (dirty & (FD_DIRTY_SCISSOR | FD_DIRTY_RASTERIZER)) {
784bf215546Sopenharmony_ci      struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
785bf215546Sopenharmony_ci
786bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_SC_WINDOW_SCISSOR_BR, 2);
787bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_SC_WINDOW_SCISSOR_BR_X(scissor->maxx - 1) |
788bf215546Sopenharmony_ci                        A4XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(scissor->maxy - 1));
789bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_SC_WINDOW_SCISSOR_TL_X(scissor->minx) |
790bf215546Sopenharmony_ci                        A4XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(scissor->miny));
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_ci      ctx->batch->max_scissor.minx =
793bf215546Sopenharmony_ci         MIN2(ctx->batch->max_scissor.minx, scissor->minx);
794bf215546Sopenharmony_ci      ctx->batch->max_scissor.miny =
795bf215546Sopenharmony_ci         MIN2(ctx->batch->max_scissor.miny, scissor->miny);
796bf215546Sopenharmony_ci      ctx->batch->max_scissor.maxx =
797bf215546Sopenharmony_ci         MAX2(ctx->batch->max_scissor.maxx, scissor->maxx);
798bf215546Sopenharmony_ci      ctx->batch->max_scissor.maxy =
799bf215546Sopenharmony_ci         MAX2(ctx->batch->max_scissor.maxy, scissor->maxy);
800bf215546Sopenharmony_ci   }
801bf215546Sopenharmony_ci
802bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_VIEWPORT) {
803bf215546Sopenharmony_ci      fd_wfi(ctx->batch, ring);
804bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_GRAS_CL_VPORT_XOFFSET_0, 6);
805bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_XOFFSET_0(ctx->viewport.translate[0]));
806bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_XSCALE_0(ctx->viewport.scale[0]));
807bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_YOFFSET_0(ctx->viewport.translate[1]));
808bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_YSCALE_0(ctx->viewport.scale[1]));
809bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_ZOFFSET_0(ctx->viewport.translate[2]));
810bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_GRAS_CL_VPORT_ZSCALE_0(ctx->viewport.scale[2]));
811bf215546Sopenharmony_ci   }
812bf215546Sopenharmony_ci
813bf215546Sopenharmony_ci   if (dirty &
814bf215546Sopenharmony_ci       (FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER | FD_DIRTY_FRAMEBUFFER)) {
815bf215546Sopenharmony_ci      float zmin, zmax;
816bf215546Sopenharmony_ci      int depth = 24;
817bf215546Sopenharmony_ci      if (ctx->batch->framebuffer.zsbuf) {
818bf215546Sopenharmony_ci         depth = util_format_get_component_bits(
819bf215546Sopenharmony_ci            pipe_surface_format(ctx->batch->framebuffer.zsbuf),
820bf215546Sopenharmony_ci            UTIL_FORMAT_COLORSPACE_ZS, 0);
821bf215546Sopenharmony_ci      }
822bf215546Sopenharmony_ci      util_viewport_zmin_zmax(&ctx->viewport, ctx->rasterizer->clip_halfz,
823bf215546Sopenharmony_ci                              &zmin, &zmax);
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_VPORT_Z_CLAMP(0), 2);
826bf215546Sopenharmony_ci      if (depth == 32) {
827bf215546Sopenharmony_ci         OUT_RING(ring, fui(zmin));
828bf215546Sopenharmony_ci         OUT_RING(ring, fui(zmax));
829bf215546Sopenharmony_ci      } else if (depth == 16) {
830bf215546Sopenharmony_ci         OUT_RING(ring, (uint32_t)(zmin * 0xffff));
831bf215546Sopenharmony_ci         OUT_RING(ring, (uint32_t)(zmax * 0xffff));
832bf215546Sopenharmony_ci      } else {
833bf215546Sopenharmony_ci         OUT_RING(ring, (uint32_t)(zmin * 0xffffff));
834bf215546Sopenharmony_ci         OUT_RING(ring, (uint32_t)(zmax * 0xffffff));
835bf215546Sopenharmony_ci      }
836bf215546Sopenharmony_ci   }
837bf215546Sopenharmony_ci
838bf215546Sopenharmony_ci   if (dirty & (FD_DIRTY_PROG | FD_DIRTY_FRAMEBUFFER)) {
839bf215546Sopenharmony_ci      struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
840bf215546Sopenharmony_ci      unsigned n = pfb->nr_cbufs;
841bf215546Sopenharmony_ci      /* if we have depth/stencil, we need at least on MRT: */
842bf215546Sopenharmony_ci      if (pfb->zsbuf)
843bf215546Sopenharmony_ci         n = MAX2(1, n);
844bf215546Sopenharmony_ci      fd4_program_emit(ring, emit, n, pfb->cbufs);
845bf215546Sopenharmony_ci   }
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci   if (!emit->skip_consts) { /* evil hack to deal sanely with clear path */
848bf215546Sopenharmony_ci      ir3_emit_vs_consts(vp, ring, ctx, emit->info, emit->indirect, emit->draw);
849bf215546Sopenharmony_ci      if (!emit->binning_pass)
850bf215546Sopenharmony_ci         ir3_emit_fs_consts(fp, ring, ctx);
851bf215546Sopenharmony_ci   }
852bf215546Sopenharmony_ci
853bf215546Sopenharmony_ci   if ((dirty & FD_DIRTY_BLEND)) {
854bf215546Sopenharmony_ci      struct fd4_blend_stateobj *blend = fd4_blend_stateobj(ctx->blend);
855bf215546Sopenharmony_ci      uint32_t i;
856bf215546Sopenharmony_ci
857bf215546Sopenharmony_ci      for (i = 0; i < A4XX_MAX_RENDER_TARGETS; i++) {
858bf215546Sopenharmony_ci         enum pipe_format format =
859bf215546Sopenharmony_ci            pipe_surface_format(ctx->batch->framebuffer.cbufs[i]);
860bf215546Sopenharmony_ci         bool is_int = util_format_is_pure_integer(format);
861bf215546Sopenharmony_ci         bool has_alpha = util_format_has_alpha(format);
862bf215546Sopenharmony_ci         uint32_t control = blend->rb_mrt[i].control;
863bf215546Sopenharmony_ci
864bf215546Sopenharmony_ci         if (is_int) {
865bf215546Sopenharmony_ci            control &= A4XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK;
866bf215546Sopenharmony_ci            control |= A4XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY);
867bf215546Sopenharmony_ci         }
868bf215546Sopenharmony_ci
869bf215546Sopenharmony_ci         if (!has_alpha) {
870bf215546Sopenharmony_ci            control &= ~A4XX_RB_MRT_CONTROL_BLEND2;
871bf215546Sopenharmony_ci         }
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_ci         OUT_PKT0(ring, REG_A4XX_RB_MRT_CONTROL(i), 1);
874bf215546Sopenharmony_ci         OUT_RING(ring, control);
875bf215546Sopenharmony_ci
876bf215546Sopenharmony_ci         OUT_PKT0(ring, REG_A4XX_RB_MRT_BLEND_CONTROL(i), 1);
877bf215546Sopenharmony_ci         OUT_RING(ring, blend->rb_mrt[i].blend_control);
878bf215546Sopenharmony_ci      }
879bf215546Sopenharmony_ci
880bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_FS_OUTPUT, 1);
881bf215546Sopenharmony_ci      OUT_RING(ring,
882bf215546Sopenharmony_ci               blend->rb_fs_output | A4XX_RB_FS_OUTPUT_SAMPLE_MASK(0xffff));
883bf215546Sopenharmony_ci   }
884bf215546Sopenharmony_ci
885bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_BLEND_COLOR) {
886bf215546Sopenharmony_ci      struct pipe_blend_color *bcolor = &ctx->blend_color;
887bf215546Sopenharmony_ci
888bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_RB_BLEND_RED, 8);
889bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_RED_FLOAT(bcolor->color[0]) |
890bf215546Sopenharmony_ci                        A4XX_RB_BLEND_RED_UINT(CLAMP(bcolor->color[0], 0.f, 1.f) * 0xff) |
891bf215546Sopenharmony_ci                        A4XX_RB_BLEND_RED_SINT(CLAMP(bcolor->color[0], -1.f, 1.f) * 0x7f));
892bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_RED_F32(bcolor->color[0]));
893bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_GREEN_FLOAT(bcolor->color[1]) |
894bf215546Sopenharmony_ci                        A4XX_RB_BLEND_GREEN_UINT(CLAMP(bcolor->color[1], 0.f, 1.f) * 0xff) |
895bf215546Sopenharmony_ci                        A4XX_RB_BLEND_GREEN_SINT(CLAMP(bcolor->color[1], -1.f, 1.f) * 0x7f));
896bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_GREEN_F32(bcolor->color[1]));
897bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_BLUE_FLOAT(bcolor->color[2]) |
898bf215546Sopenharmony_ci                        A4XX_RB_BLEND_BLUE_UINT(CLAMP(bcolor->color[2], 0.f, 1.f) * 0xff) |
899bf215546Sopenharmony_ci                        A4XX_RB_BLEND_BLUE_SINT(CLAMP(bcolor->color[2], -1.f, 1.f) * 0x7f));
900bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_BLUE_F32(bcolor->color[2]));
901bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_ALPHA_FLOAT(bcolor->color[3]) |
902bf215546Sopenharmony_ci                        A4XX_RB_BLEND_ALPHA_UINT(CLAMP(bcolor->color[3], 0.f, 1.f) * 0xff) |
903bf215546Sopenharmony_ci                        A4XX_RB_BLEND_ALPHA_SINT(CLAMP(bcolor->color[3], -1.f, 1.f) * 0x7f));
904bf215546Sopenharmony_ci      OUT_RING(ring, A4XX_RB_BLEND_ALPHA_F32(bcolor->color[3]));
905bf215546Sopenharmony_ci   }
906bf215546Sopenharmony_ci
907bf215546Sopenharmony_ci   if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & FD_DIRTY_SHADER_TEX)
908bf215546Sopenharmony_ci      emit_textures(ctx, ring, SB4_VS_TEX, &ctx->tex[PIPE_SHADER_VERTEX], vp);
909bf215546Sopenharmony_ci
910bf215546Sopenharmony_ci   if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_TEX)
911bf215546Sopenharmony_ci      emit_textures(ctx, ring, SB4_FS_TEX, &ctx->tex[PIPE_SHADER_FRAGMENT], fp);
912bf215546Sopenharmony_ci
913bf215546Sopenharmony_ci   if (!emit->binning_pass) {
914bf215546Sopenharmony_ci      if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_SSBO)
915bf215546Sopenharmony_ci         emit_ssbos(ctx, ring, SB4_SSBO, &ctx->shaderbuf[PIPE_SHADER_FRAGMENT]);
916bf215546Sopenharmony_ci
917bf215546Sopenharmony_ci      if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_IMAGE)
918bf215546Sopenharmony_ci         fd4_emit_images(ctx, ring, PIPE_SHADER_FRAGMENT, fp);
919bf215546Sopenharmony_ci   }
920bf215546Sopenharmony_ci}
921bf215546Sopenharmony_ci
922bf215546Sopenharmony_civoid
923bf215546Sopenharmony_cifd4_emit_cs_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
924bf215546Sopenharmony_ci                  struct ir3_shader_variant *cp)
925bf215546Sopenharmony_ci{
926bf215546Sopenharmony_ci   enum fd_dirty_shader_state dirty = ctx->dirty_shader[PIPE_SHADER_COMPUTE];
927bf215546Sopenharmony_ci   unsigned num_textures = ctx->tex[PIPE_SHADER_COMPUTE].num_textures +
928bf215546Sopenharmony_ci      cp->astc_srgb.count +
929bf215546Sopenharmony_ci      cp->tg4.count;
930bf215546Sopenharmony_ci
931bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_SHADER_TEX) {
932bf215546Sopenharmony_ci      emit_textures(ctx, ring, SB4_CS_TEX, &ctx->tex[PIPE_SHADER_COMPUTE], cp);
933bf215546Sopenharmony_ci
934bf215546Sopenharmony_ci      OUT_PKT0(ring, REG_A4XX_TPL1_TP_TEX_COUNT, 1);
935bf215546Sopenharmony_ci      OUT_RING(ring, 0);
936bf215546Sopenharmony_ci   }
937bf215546Sopenharmony_ci
938bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_TPL1_TP_FS_TEX_COUNT, 1);
939bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_TPL1_TP_FS_TEX_COUNT_CS(
940bf215546Sopenharmony_ci               ctx->shaderimg[PIPE_SHADER_COMPUTE].enabled_mask ? 0x80 : num_textures));
941bf215546Sopenharmony_ci
942bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_SHADER_SSBO)
943bf215546Sopenharmony_ci      emit_ssbos(ctx, ring, SB4_CS_SSBO, &ctx->shaderbuf[PIPE_SHADER_COMPUTE]);
944bf215546Sopenharmony_ci
945bf215546Sopenharmony_ci   if (dirty & FD_DIRTY_SHADER_IMAGE)
946bf215546Sopenharmony_ci      fd4_emit_images(ctx, ring, PIPE_SHADER_COMPUTE, cp);
947bf215546Sopenharmony_ci}
948bf215546Sopenharmony_ci
949bf215546Sopenharmony_ci/* emit setup at begin of new cmdstream buffer (don't rely on previous
950bf215546Sopenharmony_ci * state, there could have been a context switch between ioctls):
951bf215546Sopenharmony_ci */
952bf215546Sopenharmony_civoid
953bf215546Sopenharmony_cifd4_emit_restore(struct fd_batch *batch, struct fd_ringbuffer *ring)
954bf215546Sopenharmony_ci{
955bf215546Sopenharmony_ci   struct fd_context *ctx = batch->ctx;
956bf215546Sopenharmony_ci   struct fd4_context *fd4_ctx = fd4_context(ctx);
957bf215546Sopenharmony_ci
958bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RBBM_PERFCTR_CTL, 1);
959bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000001);
960bf215546Sopenharmony_ci
961bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_GRAS_DEBUG_ECO_CONTROL, 1);
962bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
963bf215546Sopenharmony_ci
964bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_SP_MODE_CONTROL, 1);
965bf215546Sopenharmony_ci   OUT_RING(ring, 0x0000001e);
966bf215546Sopenharmony_ci
967bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_TPL1_TP_MODE_CONTROL, 1);
968bf215546Sopenharmony_ci   OUT_RING(ring, 0x0000003a);
969bf215546Sopenharmony_ci
970bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_0D01, 1);
971bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000001);
972bf215546Sopenharmony_ci
973bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_0E42, 1);
974bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
975bf215546Sopenharmony_ci
976bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UCHE_CACHE_WAYS_VFD, 1);
977bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000007);
978bf215546Sopenharmony_ci
979bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UCHE_CACHE_MODE_CONTROL, 1);
980bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
981bf215546Sopenharmony_ci
982bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UCHE_INVALIDATE0, 2);
983bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
984bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000012);
985bf215546Sopenharmony_ci
986bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_HLSQ_MODE_CONTROL, 1);
987bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000003);
988bf215546Sopenharmony_ci
989bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_0CC5, 1);
990bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000006);
991bf215546Sopenharmony_ci
992bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_0CC6, 1);
993bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_0EC2, 1);
996bf215546Sopenharmony_ci   OUT_RING(ring, 0x00040000);
997bf215546Sopenharmony_ci
998bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2001, 1);
999bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1000bf215546Sopenharmony_ci
1001bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_INVALIDATE_STATE, 1);
1002bf215546Sopenharmony_ci   OUT_RING(ring, 0x00001000);
1003bf215546Sopenharmony_ci
1004bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_20EF, 1);
1005bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1006bf215546Sopenharmony_ci
1007bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RB_BLEND_RED, 4);
1008bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_BLEND_RED_UINT(0) | A4XX_RB_BLEND_RED_FLOAT(0.0f));
1009bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_BLEND_GREEN_UINT(0) | A4XX_RB_BLEND_GREEN_FLOAT(0.0f));
1010bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_BLEND_BLUE_UINT(0) | A4XX_RB_BLEND_BLUE_FLOAT(0.0f));
1011bf215546Sopenharmony_ci   OUT_RING(ring,
1012bf215546Sopenharmony_ci            A4XX_RB_BLEND_ALPHA_UINT(0x7fff) | A4XX_RB_BLEND_ALPHA_FLOAT(1.0f));
1013bf215546Sopenharmony_ci
1014bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2152, 1);
1015bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1016bf215546Sopenharmony_ci
1017bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2153, 1);
1018bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1019bf215546Sopenharmony_ci
1020bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2154, 1);
1021bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1022bf215546Sopenharmony_ci
1023bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2155, 1);
1024bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1025bf215546Sopenharmony_ci
1026bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2156, 1);
1027bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1028bf215546Sopenharmony_ci
1029bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_2157, 1);
1030bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1031bf215546Sopenharmony_ci
1032bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_21C3, 1);
1033bf215546Sopenharmony_ci   OUT_RING(ring, 0x0000001d);
1034bf215546Sopenharmony_ci
1035bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_PC_GS_PARAM, 1);
1036bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1037bf215546Sopenharmony_ci
1038bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_21E6, 1);
1039bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000001);
1040bf215546Sopenharmony_ci
1041bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_PC_HS_PARAM, 1);
1042bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1043bf215546Sopenharmony_ci
1044bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_UNKNOWN_22D7, 1);
1045bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1046bf215546Sopenharmony_ci
1047bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_TPL1_TP_TEX_OFFSET, 1);
1048bf215546Sopenharmony_ci   OUT_RING(ring, 0x00000000);
1049bf215546Sopenharmony_ci
1050bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_TPL1_TP_TEX_COUNT, 1);
1051bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_TPL1_TP_TEX_COUNT_VS(16) | A4XX_TPL1_TP_TEX_COUNT_HS(0) |
1052bf215546Sopenharmony_ci                     A4XX_TPL1_TP_TEX_COUNT_DS(0) |
1053bf215546Sopenharmony_ci                     A4XX_TPL1_TP_TEX_COUNT_GS(0));
1054bf215546Sopenharmony_ci
1055bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_TPL1_TP_FS_TEX_COUNT, 1);
1056bf215546Sopenharmony_ci   OUT_RING(ring, 16);
1057bf215546Sopenharmony_ci
1058bf215546Sopenharmony_ci   /* we don't use this yet.. probably best to disable.. */
1059bf215546Sopenharmony_ci   OUT_PKT3(ring, CP_SET_DRAW_STATE, 2);
1060bf215546Sopenharmony_ci   OUT_RING(ring, CP_SET_DRAW_STATE__0_COUNT(0) |
1061bf215546Sopenharmony_ci                     CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS |
1062bf215546Sopenharmony_ci                     CP_SET_DRAW_STATE__0_GROUP_ID(0));
1063bf215546Sopenharmony_ci   OUT_RING(ring, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1064bf215546Sopenharmony_ci
1065bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_SP_VS_PVT_MEM_PARAM, 2);
1066bf215546Sopenharmony_ci   OUT_RING(ring, 0x08000001);                    /* SP_VS_PVT_MEM_PARAM */
1067bf215546Sopenharmony_ci   OUT_RELOC(ring, fd4_ctx->vs_pvt_mem, 0, 0, 0); /* SP_VS_PVT_MEM_ADDR */
1068bf215546Sopenharmony_ci
1069bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_SP_FS_PVT_MEM_PARAM, 2);
1070bf215546Sopenharmony_ci   OUT_RING(ring, 0x08000001);                    /* SP_FS_PVT_MEM_PARAM */
1071bf215546Sopenharmony_ci   OUT_RELOC(ring, fd4_ctx->fs_pvt_mem, 0, 0, 0); /* SP_FS_PVT_MEM_ADDR */
1072bf215546Sopenharmony_ci
1073bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_GRAS_SC_CONTROL, 1);
1074bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS) |
1075bf215546Sopenharmony_ci                     A4XX_GRAS_SC_CONTROL_MSAA_DISABLE |
1076bf215546Sopenharmony_ci                     A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE) |
1077bf215546Sopenharmony_ci                     A4XX_GRAS_SC_CONTROL_RASTER_MODE(0));
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RB_MSAA_CONTROL, 1);
1080bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_MSAA_CONTROL_DISABLE |
1081bf215546Sopenharmony_ci                     A4XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE));
1082bf215546Sopenharmony_ci
1083bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_GRAS_CL_GB_CLIP_ADJ, 1);
1084bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_GRAS_CL_GB_CLIP_ADJ_HORZ(0) |
1085bf215546Sopenharmony_ci                     A4XX_GRAS_CL_GB_CLIP_ADJ_VERT(0));
1086bf215546Sopenharmony_ci
1087bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RB_ALPHA_CONTROL, 1);
1088bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_ALPHA_CONTROL_ALPHA_TEST_FUNC(FUNC_ALWAYS));
1089bf215546Sopenharmony_ci
1090bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_RB_FS_OUTPUT, 1);
1091bf215546Sopenharmony_ci   OUT_RING(ring, A4XX_RB_FS_OUTPUT_SAMPLE_MASK(0xffff));
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci   OUT_PKT0(ring, REG_A4XX_GRAS_ALPHA_CONTROL, 1);
1094bf215546Sopenharmony_ci   OUT_RING(ring, 0x0);
1095bf215546Sopenharmony_ci
1096bf215546Sopenharmony_ci   fd_hw_query_enable(batch, ring);
1097bf215546Sopenharmony_ci}
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_cistatic void
1100bf215546Sopenharmony_cifd4_mem_to_mem(struct fd_ringbuffer *ring, struct pipe_resource *dst,
1101bf215546Sopenharmony_ci               unsigned dst_off, struct pipe_resource *src, unsigned src_off,
1102bf215546Sopenharmony_ci               unsigned sizedwords)
1103bf215546Sopenharmony_ci{
1104bf215546Sopenharmony_ci   struct fd_bo *src_bo = fd_resource(src)->bo;
1105bf215546Sopenharmony_ci   struct fd_bo *dst_bo = fd_resource(dst)->bo;
1106bf215546Sopenharmony_ci   unsigned i;
1107bf215546Sopenharmony_ci
1108bf215546Sopenharmony_ci   for (i = 0; i < sizedwords; i++) {
1109bf215546Sopenharmony_ci      OUT_PKT3(ring, CP_MEM_TO_MEM, 3);
1110bf215546Sopenharmony_ci      OUT_RING(ring, 0x00000000);
1111bf215546Sopenharmony_ci      OUT_RELOC(ring, dst_bo, dst_off, 0, 0);
1112bf215546Sopenharmony_ci      OUT_RELOC(ring, src_bo, src_off, 0, 0);
1113bf215546Sopenharmony_ci
1114bf215546Sopenharmony_ci      dst_off += 4;
1115bf215546Sopenharmony_ci      src_off += 4;
1116bf215546Sopenharmony_ci   }
1117bf215546Sopenharmony_ci}
1118bf215546Sopenharmony_ci
1119bf215546Sopenharmony_civoid
1120bf215546Sopenharmony_cifd4_emit_init_screen(struct pipe_screen *pscreen)
1121bf215546Sopenharmony_ci{
1122bf215546Sopenharmony_ci   struct fd_screen *screen = fd_screen(pscreen);
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_ci   screen->emit_ib = fd4_emit_ib;
1125bf215546Sopenharmony_ci   screen->mem_to_mem = fd4_mem_to_mem;
1126bf215546Sopenharmony_ci}
1127bf215546Sopenharmony_ci
1128bf215546Sopenharmony_civoid
1129bf215546Sopenharmony_cifd4_emit_init(struct pipe_context *pctx)
1130bf215546Sopenharmony_ci{
1131bf215546Sopenharmony_ci}
1132