freedreno: Stop reporting max_const in shader-db.
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_gallium.c
1 /*
2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #include "pipe/p_state.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_string.h"
30 #include "util/u_memory.h"
31 #include "util/u_inlines.h"
32 #include "util/u_format.h"
33 #include "tgsi/tgsi_dump.h"
34 #include "tgsi/tgsi_parse.h"
35
36 #include "nir/tgsi_to_nir.h"
37
38 #include "freedreno_context.h"
39 #include "freedreno_util.h"
40
41 #include "ir3/ir3_shader.h"
42 #include "ir3/ir3_gallium.h"
43 #include "ir3/ir3_compiler.h"
44 #include "ir3/ir3_nir.h"
45
46 static void
47 dump_shader_info(struct ir3_shader_variant *v, bool binning_pass,
48 struct pipe_debug_callback *debug)
49 {
50 if (!unlikely(fd_mesa_debug & FD_DBG_SHADERDB))
51 return;
52
53 pipe_debug_message(debug, SHADER_INFO,
54 "%s%s shader: %u inst, %u dwords, "
55 "%u half, %u full, %u constlen, "
56 "%u (ss), %u (sy), %d max_sun, %d loops\n",
57 binning_pass ? "B" : "",
58 ir3_shader_stage(v->shader),
59 v->info.instrs_count,
60 v->info.sizedwords,
61 v->info.max_half_reg + 1,
62 v->info.max_reg + 1,
63 v->constlen,
64 v->info.ss, v->info.sy,
65 v->max_sun, v->loops);
66 }
67
68 struct ir3_shader_variant *
69 ir3_shader_variant(struct ir3_shader *shader, struct ir3_shader_key key,
70 bool binning_pass, struct pipe_debug_callback *debug)
71 {
72 struct ir3_shader_variant *v;
73 bool created = false;
74
75 /* some shader key values only apply to vertex or frag shader,
76 * so normalize the key to avoid constructing multiple identical
77 * variants:
78 */
79 ir3_normalize_key(&key, shader->type);
80
81 v = ir3_shader_get_variant(shader, &key, binning_pass, &created);
82
83 if (created) {
84 dump_shader_info(v, binning_pass, debug);
85 }
86
87 return v;
88 }
89
90 static void
91 copy_stream_out(struct ir3_stream_output_info *i,
92 const struct pipe_stream_output_info *p)
93 {
94 STATIC_ASSERT(ARRAY_SIZE(i->stride) == ARRAY_SIZE(p->stride));
95 STATIC_ASSERT(ARRAY_SIZE(i->output) == ARRAY_SIZE(p->output));
96
97 i->num_outputs = p->num_outputs;
98 for (int n = 0; n < ARRAY_SIZE(i->stride); n++)
99 i->stride[n] = p->stride[n];
100
101 for (int n = 0; n < ARRAY_SIZE(i->output); n++) {
102 i->output[n].register_index = p->output[n].register_index;
103 i->output[n].start_component = p->output[n].start_component;
104 i->output[n].num_components = p->output[n].num_components;
105 i->output[n].output_buffer = p->output[n].output_buffer;
106 i->output[n].dst_offset = p->output[n].dst_offset;
107 i->output[n].stream = p->output[n].stream;
108 }
109 }
110
111 struct ir3_shader *
112 ir3_shader_create(struct ir3_compiler *compiler,
113 const struct pipe_shader_state *cso, gl_shader_stage type,
114 struct pipe_debug_callback *debug,
115 struct pipe_screen *screen)
116 {
117 nir_shader *nir;
118 if (cso->type == PIPE_SHADER_IR_NIR) {
119 /* we take ownership of the reference: */
120 nir = cso->ir.nir;
121 } else {
122 debug_assert(cso->type == PIPE_SHADER_IR_TGSI);
123 if (ir3_shader_debug & IR3_DBG_DISASM) {
124 tgsi_dump(cso->tokens, 0);
125 }
126 nir = tgsi_to_nir(cso->tokens, screen);
127 }
128
129 struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir);
130
131 copy_stream_out(&shader->stream_output, &cso->stream_output);
132
133 if (fd_mesa_debug & FD_DBG_SHADERDB) {
134 /* if shader-db run, create a standard variant immediately
135 * (as otherwise nothing will trigger the shader to be
136 * actually compiled)
137 */
138 static struct ir3_shader_key key;
139 memset(&key, 0, sizeof(key));
140 ir3_shader_variant(shader, key, false, debug);
141
142 if (nir->info.stage != MESA_SHADER_FRAGMENT)
143 ir3_shader_variant(shader, key, true, debug);
144 }
145 return shader;
146 }
147
148 /* a bit annoying that compute-shader and normal shader state objects
149 * aren't a bit more aligned.
150 */
151 struct ir3_shader *
152 ir3_shader_create_compute(struct ir3_compiler *compiler,
153 const struct pipe_compute_state *cso,
154 struct pipe_debug_callback *debug,
155 struct pipe_screen *screen)
156 {
157 nir_shader *nir;
158 if (cso->ir_type == PIPE_SHADER_IR_NIR) {
159 /* we take ownership of the reference: */
160 nir = (nir_shader *)cso->prog;
161 } else {
162 debug_assert(cso->ir_type == PIPE_SHADER_IR_TGSI);
163 if (ir3_shader_debug & IR3_DBG_DISASM) {
164 tgsi_dump(cso->prog, 0);
165 }
166 nir = tgsi_to_nir(cso->prog, screen);
167 }
168
169 struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir);
170
171 return shader;
172 }
173
174 /* This has to reach into the fd_context a bit more than the rest of
175 * ir3, but it needs to be aligned with the compiler, so both agree
176 * on which const regs hold what. And the logic is identical between
177 * a3xx/a4xx, the only difference is small details in the actual
178 * CP_LOAD_STATE packets (which is handled inside the generation
179 * specific ctx->emit_const(_bo)() fxns)
180 */
181
182 #include "freedreno_resource.h"
183
184 static inline bool
185 is_stateobj(struct fd_ringbuffer *ring)
186 {
187 /* XXX this is an ugly way to differentiate.. */
188 return !!(ring->flags & FD_RINGBUFFER_STREAMING);
189 }
190
191 static inline void
192 ring_wfi(struct fd_batch *batch, struct fd_ringbuffer *ring)
193 {
194 /* when we emit const state via ring (IB2) we need a WFI, but when
195 * it is emit'd via stateobj, we don't
196 */
197 if (is_stateobj(ring))
198 return;
199
200 fd_wfi(batch, ring);
201 }
202
203 static void
204 emit_user_consts(struct fd_context *ctx, const struct ir3_shader_variant *v,
205 struct fd_ringbuffer *ring, struct fd_constbuf_stateobj *constbuf)
206 {
207 const unsigned index = 0; /* user consts are index 0 */
208
209 if (constbuf->enabled_mask & (1 << index)) {
210 struct pipe_constant_buffer *cb = &constbuf->cb[index];
211 /* size in dwords, aligned to vec4. (This works at least
212 * with mesa/st, which seems to align constant buffer to
213 * 16 bytes)
214 */
215 unsigned size = align(cb->buffer_size, 16) / 4;
216
217 /* in particular, with binning shader we may end up with
218 * unused consts, ie. we could end up w/ constlen that is
219 * smaller than first_driver_param. In that case truncate
220 * the user consts early to avoid HLSQ lockup caused by
221 * writing too many consts
222 */
223 const struct ir3_const_state *const_state = &v->shader->const_state;
224 uint32_t max_const = MIN2(const_state->num_uniforms, v->constlen);
225
226 /* and even if the start of the const buffer is before
227 * first_immediate, the end may not be:
228 */
229 size = MIN2(size, 4 * max_const);
230
231 if (size > 0) {
232 ring_wfi(ctx->batch, ring);
233 ctx->emit_const(ring, v->type, 0,
234 cb->buffer_offset, size,
235 cb->user_buffer, cb->buffer);
236 }
237 }
238
239 struct ir3_ubo_analysis_state *state;
240 state = &v->shader->ubo_state;
241
242 for (uint32_t i = 1; i < ARRAY_SIZE(state->range); i++) {
243 struct pipe_constant_buffer *cb = &constbuf->cb[i];
244
245 if (state->range[i].start < state->range[i].end &&
246 constbuf->enabled_mask & (1 << i)) {
247
248 uint32_t size = state->range[i].end - state->range[i].start;
249 uint32_t offset = cb->buffer_offset + state->range[i].start;
250 debug_assert((state->range[i].offset % 16) == 0);
251 debug_assert((size % 16) == 0);
252 debug_assert((offset % 16) == 0);
253 ctx->emit_const(ring, v->type, state->range[i].offset / 4,
254 offset, size / 4, cb->user_buffer, cb->buffer);
255 }
256 }
257 }
258
259 static void
260 emit_ubos(struct fd_context *ctx, const struct ir3_shader_variant *v,
261 struct fd_ringbuffer *ring, struct fd_constbuf_stateobj *constbuf)
262 {
263 const struct ir3_const_state *const_state = &v->shader->const_state;
264 uint32_t offset = const_state->offsets.ubo;
265 if (v->constlen > offset) {
266 uint32_t params = const_state->num_ubos;
267 uint32_t offsets[params];
268 struct pipe_resource *prscs[params];
269
270 for (uint32_t i = 0; i < params; i++) {
271 const uint32_t index = i + 1; /* UBOs start at index 1 */
272 struct pipe_constant_buffer *cb = &constbuf->cb[index];
273 assert(!cb->user_buffer);
274
275 if ((constbuf->enabled_mask & (1 << index)) && cb->buffer) {
276 offsets[i] = cb->buffer_offset;
277 prscs[i] = cb->buffer;
278 } else {
279 offsets[i] = 0;
280 prscs[i] = NULL;
281 }
282 }
283
284 ring_wfi(ctx->batch, ring);
285 ctx->emit_const_bo(ring, v->type, false, offset * 4, params, prscs, offsets);
286 }
287 }
288
289 static void
290 emit_ssbo_sizes(struct fd_context *ctx, const struct ir3_shader_variant *v,
291 struct fd_ringbuffer *ring, struct fd_shaderbuf_stateobj *sb)
292 {
293 const struct ir3_const_state *const_state = &v->shader->const_state;
294 uint32_t offset = const_state->offsets.ssbo_sizes;
295 if (v->constlen > offset) {
296 uint32_t sizes[align(const_state->ssbo_size.count, 4)];
297 unsigned mask = const_state->ssbo_size.mask;
298
299 while (mask) {
300 unsigned index = u_bit_scan(&mask);
301 unsigned off = const_state->ssbo_size.off[index];
302 sizes[off] = sb->sb[index].buffer_size;
303 }
304
305 ring_wfi(ctx->batch, ring);
306 ctx->emit_const(ring, v->type, offset * 4,
307 0, ARRAY_SIZE(sizes), sizes, NULL);
308 }
309 }
310
311 static void
312 emit_image_dims(struct fd_context *ctx, const struct ir3_shader_variant *v,
313 struct fd_ringbuffer *ring, struct fd_shaderimg_stateobj *si)
314 {
315 const struct ir3_const_state *const_state = &v->shader->const_state;
316 uint32_t offset = const_state->offsets.image_dims;
317 if (v->constlen > offset) {
318 uint32_t dims[align(const_state->image_dims.count, 4)];
319 unsigned mask = const_state->image_dims.mask;
320
321 while (mask) {
322 struct pipe_image_view *img;
323 struct fd_resource *rsc;
324 unsigned index = u_bit_scan(&mask);
325 unsigned off = const_state->image_dims.off[index];
326
327 img = &si->si[index];
328 rsc = fd_resource(img->resource);
329
330 dims[off + 0] = util_format_get_blocksize(img->format);
331 if (img->resource->target != PIPE_BUFFER) {
332 unsigned lvl = img->u.tex.level;
333 /* note for 2d/cube/etc images, even if re-interpreted
334 * as a different color format, the pixel size should
335 * be the same, so use original dimensions for y and z
336 * stride:
337 */
338 dims[off + 1] = rsc->slices[lvl].pitch * rsc->cpp;
339 /* see corresponding logic in fd_resource_offset(): */
340 if (rsc->layer_first) {
341 dims[off + 2] = rsc->layer_size;
342 } else {
343 dims[off + 2] = rsc->slices[lvl].size0;
344 }
345 } else {
346 /* For buffer-backed images, the log2 of the format's
347 * bytes-per-pixel is placed on the 2nd slot. This is useful
348 * when emitting image_size instructions, for which we need
349 * to divide by bpp for image buffers. Since the bpp
350 * can only be power-of-two, the division is implemented
351 * as a SHR, and for that it is handy to have the log2 of
352 * bpp as a constant. (log2 = first-set-bit - 1)
353 */
354 dims[off + 1] = ffs(dims[off + 0]) - 1;
355 }
356 }
357
358 ring_wfi(ctx->batch, ring);
359 ctx->emit_const(ring, v->type, offset * 4,
360 0, ARRAY_SIZE(dims), dims, NULL);
361 }
362 }
363
364 static void
365 emit_immediates(struct fd_context *ctx, const struct ir3_shader_variant *v,
366 struct fd_ringbuffer *ring)
367 {
368 const struct ir3_const_state *const_state = &v->shader->const_state;
369 uint32_t base = const_state->offsets.immediate;
370 int size = const_state->immediates_count;
371
372 /* truncate size to avoid writing constants that shader
373 * does not use:
374 */
375 size = MIN2(size + base, v->constlen) - base;
376
377 /* convert out of vec4: */
378 base *= 4;
379 size *= 4;
380
381 if (size > 0) {
382 ring_wfi(ctx->batch, ring);
383 ctx->emit_const(ring, v->type, base,
384 0, size, const_state->immediates[0].val, NULL);
385 }
386 }
387
388 /* emit stream-out buffers: */
389 static void
390 emit_tfbos(struct fd_context *ctx, const struct ir3_shader_variant *v,
391 struct fd_ringbuffer *ring)
392 {
393 /* streamout addresses after driver-params: */
394 const struct ir3_const_state *const_state = &v->shader->const_state;
395 uint32_t offset = const_state->offsets.tfbo;
396 if (v->constlen > offset) {
397 struct fd_streamout_stateobj *so = &ctx->streamout;
398 struct ir3_stream_output_info *info = &v->shader->stream_output;
399 uint32_t params = 4;
400 uint32_t offsets[params];
401 struct pipe_resource *prscs[params];
402
403 for (uint32_t i = 0; i < params; i++) {
404 struct pipe_stream_output_target *target = so->targets[i];
405
406 if (target) {
407 offsets[i] = (so->offsets[i] * info->stride[i] * 4) +
408 target->buffer_offset;
409 prscs[i] = target->buffer;
410 } else {
411 offsets[i] = 0;
412 prscs[i] = NULL;
413 }
414 }
415
416 ring_wfi(ctx->batch, ring);
417 ctx->emit_const_bo(ring, v->type, true, offset * 4, params, prscs, offsets);
418 }
419 }
420
421 static uint32_t
422 max_tf_vtx(struct fd_context *ctx, const struct ir3_shader_variant *v)
423 {
424 struct fd_streamout_stateobj *so = &ctx->streamout;
425 struct ir3_stream_output_info *info = &v->shader->stream_output;
426 uint32_t maxvtxcnt = 0x7fffffff;
427
428 if (ctx->screen->gpu_id >= 500)
429 return 0;
430 if (v->binning_pass)
431 return 0;
432 if (v->shader->stream_output.num_outputs == 0)
433 return 0;
434 if (so->num_targets == 0)
435 return 0;
436
437 /* offset to write to is:
438 *
439 * total_vtxcnt = vtxcnt + offsets[i]
440 * offset = total_vtxcnt * stride[i]
441 *
442 * offset = vtxcnt * stride[i] ; calculated in shader
443 * + offsets[i] * stride[i] ; calculated at emit_tfbos()
444 *
445 * assuming for each vtx, each target buffer will have data written
446 * up to 'offset + stride[i]', that leaves maxvtxcnt as:
447 *
448 * buffer_size = (maxvtxcnt * stride[i]) + stride[i]
449 * maxvtxcnt = (buffer_size - stride[i]) / stride[i]
450 *
451 * but shader is actually doing a less-than (rather than less-than-
452 * equal) check, so we can drop the -stride[i].
453 *
454 * TODO is assumption about `offset + stride[i]` legit?
455 */
456 for (unsigned i = 0; i < so->num_targets; i++) {
457 struct pipe_stream_output_target *target = so->targets[i];
458 unsigned stride = info->stride[i] * 4; /* convert dwords->bytes */
459 if (target) {
460 uint32_t max = target->buffer_size / stride;
461 maxvtxcnt = MIN2(maxvtxcnt, max);
462 }
463 }
464
465 return maxvtxcnt;
466 }
467
468 static void
469 emit_common_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
470 struct fd_context *ctx, enum pipe_shader_type t)
471 {
472 enum fd_dirty_shader_state dirty = ctx->dirty_shader[t];
473
474 /* When we use CP_SET_DRAW_STATE objects to emit constant state,
475 * if we emit any of it we need to emit all. This is because
476 * we are using the same state-group-id each time for uniform
477 * state, and if previous update is never evaluated (due to no
478 * visible primitives in the current tile) then the new stateobj
479 * completely replaces the old one.
480 *
481 * Possibly if we split up different parts of the const state to
482 * different state-objects we could avoid this.
483 */
484 if (dirty && is_stateobj(ring))
485 dirty = ~0;
486
487 if (dirty & (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_CONST)) {
488 struct fd_constbuf_stateobj *constbuf;
489 bool shader_dirty;
490
491 constbuf = &ctx->constbuf[t];
492 shader_dirty = !!(dirty & FD_DIRTY_SHADER_PROG);
493
494 emit_user_consts(ctx, v, ring, constbuf);
495 emit_ubos(ctx, v, ring, constbuf);
496 if (shader_dirty)
497 emit_immediates(ctx, v, ring);
498 }
499
500 if (dirty & (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_SSBO)) {
501 struct fd_shaderbuf_stateobj *sb = &ctx->shaderbuf[t];
502 emit_ssbo_sizes(ctx, v, ring, sb);
503 }
504
505 if (dirty & (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_IMAGE)) {
506 struct fd_shaderimg_stateobj *si = &ctx->shaderimg[t];
507 emit_image_dims(ctx, v, ring, si);
508 }
509 }
510
511 void
512 ir3_emit_vs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
513 struct fd_context *ctx, const struct pipe_draw_info *info)
514 {
515 debug_assert(v->type == MESA_SHADER_VERTEX);
516
517 emit_common_consts(v, ring, ctx, PIPE_SHADER_VERTEX);
518
519 /* emit driver params every time: */
520 /* TODO skip emit if shader doesn't use driver params to avoid WFI.. */
521 if (info) {
522 const struct ir3_const_state *const_state = &v->shader->const_state;
523 uint32_t offset = const_state->offsets.driver_param;
524 if (v->constlen > offset) {
525 uint32_t vertex_params[IR3_DP_VS_COUNT] = {
526 [IR3_DP_VTXID_BASE] = info->index_size ?
527 info->index_bias : info->start,
528 [IR3_DP_VTXCNT_MAX] = max_tf_vtx(ctx, v),
529 };
530 /* if no user-clip-planes, we don't need to emit the
531 * entire thing:
532 */
533 uint32_t vertex_params_size = 4;
534
535 if (v->key.ucp_enables) {
536 struct pipe_clip_state *ucp = &ctx->ucp;
537 unsigned pos = IR3_DP_UCP0_X;
538 for (unsigned i = 0; pos <= IR3_DP_UCP7_W; i++) {
539 for (unsigned j = 0; j < 4; j++) {
540 vertex_params[pos] = fui(ucp->ucp[i][j]);
541 pos++;
542 }
543 }
544 vertex_params_size = ARRAY_SIZE(vertex_params);
545 }
546
547 ring_wfi(ctx->batch, ring);
548
549 bool needs_vtxid_base =
550 ir3_find_sysval_regid(v, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) != regid(63, 0);
551
552 /* for indirect draw, we need to copy VTXID_BASE from
553 * indirect-draw parameters buffer.. which is annoying
554 * and means we can't easily emit these consts in cmd
555 * stream so need to copy them to bo.
556 */
557 if (info->indirect && needs_vtxid_base) {
558 struct pipe_draw_indirect_info *indirect = info->indirect;
559 struct pipe_resource *vertex_params_rsc =
560 pipe_buffer_create(&ctx->screen->base,
561 PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM,
562 vertex_params_size * 4);
563 unsigned src_off = info->indirect->offset;;
564 void *ptr;
565
566 ptr = fd_bo_map(fd_resource(vertex_params_rsc)->bo);
567 memcpy(ptr, vertex_params, vertex_params_size * 4);
568
569 if (info->index_size) {
570 /* indexed draw, index_bias is 4th field: */
571 src_off += 3 * 4;
572 } else {
573 /* non-indexed draw, start is 3rd field: */
574 src_off += 2 * 4;
575 }
576
577 /* copy index_bias or start from draw params: */
578 ctx->mem_to_mem(ring, vertex_params_rsc, 0,
579 indirect->buffer, src_off, 1);
580
581 ctx->emit_const(ring, MESA_SHADER_VERTEX, offset * 4, 0,
582 vertex_params_size, NULL, vertex_params_rsc);
583
584 pipe_resource_reference(&vertex_params_rsc, NULL);
585 } else {
586 ctx->emit_const(ring, MESA_SHADER_VERTEX, offset * 4, 0,
587 vertex_params_size, vertex_params, NULL);
588 }
589
590 /* if needed, emit stream-out buffer addresses: */
591 if (vertex_params[IR3_DP_VTXCNT_MAX] > 0) {
592 emit_tfbos(ctx, v, ring);
593 }
594 }
595 }
596 }
597
598 void
599 ir3_emit_fs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
600 struct fd_context *ctx)
601 {
602 debug_assert(v->type == MESA_SHADER_FRAGMENT);
603
604 emit_common_consts(v, ring, ctx, PIPE_SHADER_FRAGMENT);
605 }
606
607 /* emit compute-shader consts: */
608 void
609 ir3_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
610 struct fd_context *ctx, const struct pipe_grid_info *info)
611 {
612 debug_assert(gl_shader_stage_is_compute(v->type));
613
614 emit_common_consts(v, ring, ctx, PIPE_SHADER_COMPUTE);
615
616 /* emit compute-shader driver-params: */
617 const struct ir3_const_state *const_state = &v->shader->const_state;
618 uint32_t offset = const_state->offsets.driver_param;
619 if (v->constlen > offset) {
620 ring_wfi(ctx->batch, ring);
621
622 if (info->indirect) {
623 struct pipe_resource *indirect = NULL;
624 unsigned indirect_offset;
625
626 /* This is a bit awkward, but CP_LOAD_STATE.EXT_SRC_ADDR needs
627 * to be aligned more strongly than 4 bytes. So in this case
628 * we need a temporary buffer to copy NumWorkGroups.xyz to.
629 *
630 * TODO if previous compute job is writing to info->indirect,
631 * we might need a WFI.. but since we currently flush for each
632 * compute job, we are probably ok for now.
633 */
634 if (info->indirect_offset & 0xf) {
635 indirect = pipe_buffer_create(&ctx->screen->base,
636 PIPE_BIND_COMMAND_ARGS_BUFFER, PIPE_USAGE_STREAM,
637 0x1000);
638 indirect_offset = 0;
639
640 ctx->mem_to_mem(ring, indirect, 0, info->indirect,
641 info->indirect_offset, 3);
642 } else {
643 pipe_resource_reference(&indirect, info->indirect);
644 indirect_offset = info->indirect_offset;
645 }
646
647 ctx->emit_const(ring, MESA_SHADER_COMPUTE, offset * 4,
648 indirect_offset, 4, NULL, indirect);
649
650 pipe_resource_reference(&indirect, NULL);
651 } else {
652 uint32_t compute_params[IR3_DP_CS_COUNT] = {
653 [IR3_DP_NUM_WORK_GROUPS_X] = info->grid[0],
654 [IR3_DP_NUM_WORK_GROUPS_Y] = info->grid[1],
655 [IR3_DP_NUM_WORK_GROUPS_Z] = info->grid[2],
656 [IR3_DP_LOCAL_GROUP_SIZE_X] = info->block[0],
657 [IR3_DP_LOCAL_GROUP_SIZE_Y] = info->block[1],
658 [IR3_DP_LOCAL_GROUP_SIZE_Z] = info->block[2],
659 };
660
661 ctx->emit_const(ring, MESA_SHADER_COMPUTE, offset * 4, 0,
662 ARRAY_SIZE(compute_params), compute_params, NULL);
663 }
664 }
665 }