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 "ir3/ir3_nir.h"
28
29 /* This has to reach into the fd_context a bit more than the rest of
30 * ir3, but it needs to be aligned with the compiler, so both agree
31 * on which const regs hold what. And the logic is identical between
32 * ir3 generations, the only difference is small details in the actual
33 * CP_LOAD_STATE packets (which is handled inside the generation
34 * specific ctx->emit_const(_bo)() fxns)
35 *
36 * This file should be included in only a single .c file per gen, which
37 * defines the following functions:
38 */
39
40 static bool is_stateobj(struct fd_ringbuffer *ring);
41
42 static void emit_const_user(struct fd_ringbuffer *ring,
43 const struct ir3_shader_variant *v, uint32_t regid,
44 uint32_t size, const uint32_t *user_buffer);
45
46 static void emit_const_bo(struct fd_ringbuffer *ring,
47 const struct ir3_shader_variant *v, uint32_t regid,
48 uint32_t offset, uint32_t size, struct fd_bo *bo);
49
50 static void
emit_const_prsc(struct fd_ringbuffer * ring,const struct ir3_shader_variant * v,uint32_t regid,uint32_t offset,uint32_t size,struct pipe_resource * buffer)51 emit_const_prsc(struct fd_ringbuffer *ring, const struct ir3_shader_variant *v,
52 uint32_t regid, uint32_t offset, uint32_t size,
53 struct pipe_resource *buffer)
54 {
55 struct fd_resource *rsc = fd_resource(buffer);
56 emit_const_bo(ring, v, regid, offset, size, rsc->bo);
57 }
58
59 static void emit_const_ptrs(struct fd_ringbuffer *ring,
60 const struct ir3_shader_variant *v,
61 uint32_t dst_offset, uint32_t num,
62 struct fd_bo **bos, uint32_t *offsets);
63
64 static void
emit_const_asserts(struct fd_ringbuffer * ring,const struct ir3_shader_variant * v,uint32_t regid,uint32_t sizedwords)65 emit_const_asserts(struct fd_ringbuffer *ring,
66 const struct ir3_shader_variant *v, uint32_t regid,
67 uint32_t sizedwords)
68 {
69 assert((regid % 4) == 0);
70 assert((sizedwords % 4) == 0);
71 assert(regid + sizedwords <= v->constlen * 4);
72 }
73
74 static void
ring_wfi(struct fd_batch * batch,struct fd_ringbuffer * ring)75 ring_wfi(struct fd_batch *batch, struct fd_ringbuffer *ring) assert_dt
76 {
77 /* when we emit const state via ring (IB2) we need a WFI, but when
78 * it is emit'd via stateobj, we don't
79 */
80 if (is_stateobj(ring))
81 return;
82
83 fd_wfi(batch, ring);
84 }
85
86 /**
87 * Indirectly calculates size of cmdstream needed for ir3_emit_user_consts().
88 * Returns number of packets, and total size of all the payload.
89 *
90 * The value can be a worst-case, ie. some shader variants may not read all
91 * consts, etc.
92 *
93 * Returns size in dwords.
94 */
95 static inline void
ir3_user_consts_size(struct ir3_ubo_analysis_state * state,unsigned * packets,unsigned * size)96 ir3_user_consts_size(struct ir3_ubo_analysis_state *state, unsigned *packets,
97 unsigned *size)
98 {
99 *packets = *size = 0;
100
101 for (uint32_t i = 0; i < ARRAY_SIZE(state->range); i++) {
102 if (state->range[i].start < state->range[i].end) {
103 *size += state->range[i].end - state->range[i].start;
104 (*packets)++;
105 }
106 }
107 }
108
109 /**
110 * Uploads the referenced subranges of the nir constant_data to the hardware's
111 * constant buffer.
112 */
113 static inline void
ir3_emit_constant_data(struct fd_screen * screen,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring)114 ir3_emit_constant_data(struct fd_screen *screen,
115 const struct ir3_shader_variant *v,
116 struct fd_ringbuffer *ring)
117 {
118 const struct ir3_const_state *const_state = ir3_const_state(v);
119 const struct ir3_ubo_analysis_state *state = &const_state->ubo_state;
120
121 for (unsigned i = 0; i < state->num_enabled; i++) {
122 unsigned ubo = state->range[i].ubo.block;
123 if (ubo != const_state->constant_data_ubo)
124 continue;
125
126 uint32_t size = state->range[i].end - state->range[i].start;
127
128 /* Pre-a6xx, we might have ranges enabled in the shader that aren't
129 * used in the binning variant.
130 */
131 if (16 * v->constlen <= state->range[i].offset)
132 continue;
133
134 /* and even if the start of the const buffer is before
135 * first_immediate, the end may not be:
136 */
137 size = MIN2(size, (16 * v->constlen) - state->range[i].offset);
138
139 if (size == 0)
140 continue;
141
142 emit_const_bo(ring, v, state->range[i].offset / 4,
143 v->info.constant_data_offset + state->range[i].start,
144 size / 4, v->bo);
145 }
146 }
147
148 /**
149 * Uploads sub-ranges of UBOs to the hardware's constant buffer (UBO access
150 * outside of these ranges will be done using full UBO accesses in the
151 * shader).
152 */
153 static inline void
ir3_emit_user_consts(struct fd_screen * screen,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_constbuf_stateobj * constbuf)154 ir3_emit_user_consts(struct fd_screen *screen,
155 const struct ir3_shader_variant *v,
156 struct fd_ringbuffer *ring,
157 struct fd_constbuf_stateobj *constbuf)
158 {
159 const struct ir3_const_state *const_state = ir3_const_state(v);
160 const struct ir3_ubo_analysis_state *state = &const_state->ubo_state;
161
162 for (unsigned i = 0; i < state->num_enabled; i++) {
163 assert(!state->range[i].ubo.bindless);
164 unsigned ubo = state->range[i].ubo.block;
165 if (!(constbuf->enabled_mask & (1 << ubo)) ||
166 ubo == const_state->constant_data_ubo) {
167 continue;
168 }
169 struct pipe_constant_buffer *cb = &constbuf->cb[ubo];
170
171 uint32_t size = state->range[i].end - state->range[i].start;
172 uint32_t offset = cb->buffer_offset + state->range[i].start;
173
174 /* Pre-a6xx, we might have ranges enabled in the shader that aren't
175 * used in the binning variant.
176 */
177 if (16 * v->constlen <= state->range[i].offset)
178 continue;
179
180 /* and even if the start of the const buffer is before
181 * first_immediate, the end may not be:
182 */
183 size = MIN2(size, (16 * v->constlen) - state->range[i].offset);
184
185 if (size == 0)
186 continue;
187
188 /* things should be aligned to vec4: */
189 debug_assert((state->range[i].offset % 16) == 0);
190 debug_assert((size % 16) == 0);
191 debug_assert((offset % 16) == 0);
192
193 if (cb->user_buffer) {
194 emit_const_user(ring, v, state->range[i].offset / 4, size / 4,
195 cb->user_buffer + state->range[i].start);
196 } else {
197 emit_const_prsc(ring, v, state->range[i].offset / 4, offset, size / 4,
198 cb->buffer);
199 }
200 }
201 }
202
203 static inline void
ir3_emit_ubos(struct fd_context * ctx,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_constbuf_stateobj * constbuf)204 ir3_emit_ubos(struct fd_context *ctx, const struct ir3_shader_variant *v,
205 struct fd_ringbuffer *ring, struct fd_constbuf_stateobj *constbuf)
206 {
207 const struct ir3_const_state *const_state = ir3_const_state(v);
208 uint32_t offset = const_state->offsets.ubo;
209
210 /* a6xx+ uses UBO state and ldc instead of pointers emitted in
211 * const state and ldg:
212 */
213 if (ctx->screen->gen >= 6)
214 return;
215
216 if (v->constlen > offset) {
217 uint32_t params = const_state->num_ubos;
218 uint32_t offsets[params];
219 struct fd_bo *bos[params];
220
221 for (uint32_t i = 0; i < params; i++) {
222 if (i == const_state->constant_data_ubo) {
223 bos[i] = v->bo;
224 offsets[i] = v->info.constant_data_offset;
225 continue;
226 }
227
228 struct pipe_constant_buffer *cb = &constbuf->cb[i];
229
230 /* If we have user pointers (constbuf 0, aka GL uniforms), upload
231 * them to a buffer now, and save it in the constbuf so that we
232 * don't have to reupload until they get changed.
233 */
234 if (cb->user_buffer) {
235 struct pipe_context *pctx = &ctx->base;
236 u_upload_data(pctx->stream_uploader, 0, cb->buffer_size, 64,
237 cb->user_buffer, &cb->buffer_offset, &cb->buffer);
238 cb->user_buffer = NULL;
239 }
240
241 if ((constbuf->enabled_mask & (1 << i)) && cb->buffer) {
242 offsets[i] = cb->buffer_offset;
243 bos[i] = fd_resource(cb->buffer)->bo;
244 } else {
245 offsets[i] = 0;
246 bos[i] = NULL;
247 }
248 }
249
250 assert(offset * 4 + params <= v->constlen * 4);
251
252 emit_const_ptrs(ring, v, offset * 4, params, bos, offsets);
253 }
254 }
255
256 static inline void
ir3_emit_image_dims(struct fd_screen * screen,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_shaderimg_stateobj * si)257 ir3_emit_image_dims(struct fd_screen *screen,
258 const struct ir3_shader_variant *v,
259 struct fd_ringbuffer *ring,
260 struct fd_shaderimg_stateobj *si)
261 {
262 const struct ir3_const_state *const_state = ir3_const_state(v);
263 uint32_t offset = const_state->offsets.image_dims;
264 if (v->constlen > offset) {
265 uint32_t dims[align(const_state->image_dims.count, 4)];
266 unsigned mask = const_state->image_dims.mask;
267
268 while (mask) {
269 struct pipe_image_view *img;
270 struct fd_resource *rsc;
271 unsigned index = u_bit_scan(&mask);
272 unsigned off = const_state->image_dims.off[index];
273
274 img = &si->si[index];
275 rsc = fd_resource(img->resource);
276
277 dims[off + 0] = util_format_get_blocksize(img->format);
278 if (img->resource->target != PIPE_BUFFER) {
279 struct fdl_slice *slice = fd_resource_slice(rsc, img->u.tex.level);
280 /* note for 2d/cube/etc images, even if re-interpreted
281 * as a different color format, the pixel size should
282 * be the same, so use original dimensions for y and z
283 * stride:
284 */
285 dims[off + 1] = fd_resource_pitch(rsc, img->u.tex.level);
286 /* see corresponding logic in fd_resource_offset(): */
287 if (rsc->layout.layer_first) {
288 dims[off + 2] = rsc->layout.layer_size;
289 } else {
290 dims[off + 2] = slice->size0;
291 }
292 } else {
293 /* For buffer-backed images, the log2 of the format's
294 * bytes-per-pixel is placed on the 2nd slot. This is useful
295 * when emitting image_size instructions, for which we need
296 * to divide by bpp for image buffers. Since the bpp
297 * can only be power-of-two, the division is implemented
298 * as a SHR, and for that it is handy to have the log2 of
299 * bpp as a constant. (log2 = first-set-bit - 1)
300 */
301 dims[off + 1] = ffs(dims[off + 0]) - 1;
302 }
303 }
304 uint32_t size = MIN2(ARRAY_SIZE(dims), v->constlen * 4 - offset * 4);
305
306 emit_const_user(ring, v, offset * 4, size, dims);
307 }
308 }
309
310 static inline void
ir3_emit_immediates(struct fd_screen * screen,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring)311 ir3_emit_immediates(struct fd_screen *screen,
312 const struct ir3_shader_variant *v,
313 struct fd_ringbuffer *ring)
314 {
315 const struct ir3_const_state *const_state = ir3_const_state(v);
316 uint32_t base = const_state->offsets.immediate;
317 int size = DIV_ROUND_UP(const_state->immediates_count, 4);
318
319 /* truncate size to avoid writing constants that shader
320 * does not use:
321 */
322 size = MIN2(size + base, v->constlen) - base;
323
324 /* convert out of vec4: */
325 base *= 4;
326 size *= 4;
327
328 if (size > 0)
329 emit_const_user(ring, v, base, size, const_state->immediates);
330
331 /* NIR constant data has the same lifetime as immediates, so upload it
332 * now, too.
333 */
334 ir3_emit_constant_data(screen, v, ring);
335 }
336
337 static inline void
ir3_emit_link_map(struct fd_screen * screen,const struct ir3_shader_variant * producer,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring)338 ir3_emit_link_map(struct fd_screen *screen,
339 const struct ir3_shader_variant *producer,
340 const struct ir3_shader_variant *v,
341 struct fd_ringbuffer *ring)
342 {
343 const struct ir3_const_state *const_state = ir3_const_state(v);
344 uint32_t base = const_state->offsets.primitive_map;
345 int size = DIV_ROUND_UP(v->input_size, 4);
346
347 /* truncate size to avoid writing constants that shader
348 * does not use:
349 */
350 size = MIN2(size + base, v->constlen) - base;
351
352 /* convert out of vec4: */
353 base *= 4;
354 size *= 4;
355
356 if (size > 0)
357 emit_const_user(ring, v, base, size, producer->output_loc);
358 }
359
360 /* emit stream-out buffers: */
361 static inline void
emit_tfbos(struct fd_context * ctx,const struct ir3_shader_variant * v,struct fd_ringbuffer * ring)362 emit_tfbos(struct fd_context *ctx, const struct ir3_shader_variant *v,
363 struct fd_ringbuffer *ring)
364 {
365 /* streamout addresses after driver-params: */
366 const struct ir3_const_state *const_state = ir3_const_state(v);
367 uint32_t offset = const_state->offsets.tfbo;
368 if (v->constlen > offset) {
369 struct fd_streamout_stateobj *so = &ctx->streamout;
370 struct ir3_stream_output_info *info = &v->shader->stream_output;
371 uint32_t params = 4;
372 uint32_t offsets[params];
373 struct fd_bo *bos[params];
374
375 for (uint32_t i = 0; i < params; i++) {
376 struct pipe_stream_output_target *target = so->targets[i];
377
378 if (target) {
379 offsets[i] =
380 (so->offsets[i] * info->stride[i] * 4) + target->buffer_offset;
381 bos[i] = fd_resource(target->buffer)->bo;
382 } else {
383 offsets[i] = 0;
384 bos[i] = NULL;
385 }
386 }
387
388 assert(offset * 4 + params <= v->constlen * 4);
389
390 emit_const_ptrs(ring, v, offset * 4, params, bos, offsets);
391 }
392 }
393
394 static inline void
emit_common_consts(const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_context * ctx,enum pipe_shader_type t)395 emit_common_consts(const struct ir3_shader_variant *v,
396 struct fd_ringbuffer *ring, struct fd_context *ctx,
397 enum pipe_shader_type t) assert_dt
398 {
399 enum fd_dirty_shader_state dirty = ctx->dirty_shader[t];
400
401 /* When we use CP_SET_DRAW_STATE objects to emit constant state,
402 * if we emit any of it we need to emit all. This is because
403 * we are using the same state-group-id each time for uniform
404 * state, and if previous update is never evaluated (due to no
405 * visible primitives in the current tile) then the new stateobj
406 * completely replaces the old one.
407 *
408 * Possibly if we split up different parts of the const state to
409 * different state-objects we could avoid this.
410 */
411 if (dirty && is_stateobj(ring))
412 dirty = ~0;
413
414 if (dirty & (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_CONST)) {
415 struct fd_constbuf_stateobj *constbuf;
416 bool shader_dirty;
417
418 constbuf = &ctx->constbuf[t];
419 shader_dirty = !!(dirty & FD_DIRTY_SHADER_PROG);
420
421 ring_wfi(ctx->batch, ring);
422
423 ir3_emit_user_consts(ctx->screen, v, ring, constbuf);
424 ir3_emit_ubos(ctx, v, ring, constbuf);
425 if (shader_dirty)
426 ir3_emit_immediates(ctx->screen, v, ring);
427 }
428
429 if (dirty & (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_IMAGE)) {
430 struct fd_shaderimg_stateobj *si = &ctx->shaderimg[t];
431 ring_wfi(ctx->batch, ring);
432 ir3_emit_image_dims(ctx->screen, v, ring, si);
433 }
434 }
435
436 static inline void
ir3_emit_vs_driver_params(const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_context * ctx,const struct pipe_draw_info * info,const struct pipe_draw_indirect_info * indirect,const struct pipe_draw_start_count_bias * draw)437 ir3_emit_vs_driver_params(const struct ir3_shader_variant *v,
438 struct fd_ringbuffer *ring, struct fd_context *ctx,
439 const struct pipe_draw_info *info,
440 const struct pipe_draw_indirect_info *indirect,
441 const struct pipe_draw_start_count_bias *draw) assert_dt
442 {
443 assert(v->need_driver_params);
444
445 const struct ir3_const_state *const_state = ir3_const_state(v);
446 uint32_t offset = const_state->offsets.driver_param;
447 uint32_t vertex_params[IR3_DP_VS_COUNT] = {
448 [IR3_DP_DRAWID] = 0, /* filled by hw (CP_DRAW_INDIRECT_MULTI) */
449 [IR3_DP_VTXID_BASE] = info->index_size ? draw->index_bias : draw->start,
450 [IR3_DP_INSTID_BASE] = info->start_instance,
451 [IR3_DP_VTXCNT_MAX] = ctx->streamout.max_tf_vtx,
452 };
453 if (v->key.ucp_enables) {
454 struct pipe_clip_state *ucp = &ctx->ucp;
455 unsigned pos = IR3_DP_UCP0_X;
456 for (unsigned i = 0; pos <= IR3_DP_UCP7_W; i++) {
457 for (unsigned j = 0; j < 4; j++) {
458 vertex_params[pos] = fui(ucp->ucp[i][j]);
459 pos++;
460 }
461 }
462 }
463
464 /* Only emit as many params as needed, i.e. up to the highest enabled UCP
465 * plane. However a binning pass may drop even some of these, so limit to
466 * program max.
467 */
468 const uint32_t vertex_params_size =
469 MIN2(const_state->num_driver_params, (v->constlen - offset) * 4);
470 assert(vertex_params_size <= IR3_DP_VS_COUNT);
471
472 bool needs_vtxid_base =
473 ir3_find_sysval_regid(v, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) !=
474 regid(63, 0);
475
476 /* for indirect draw, we need to copy VTXID_BASE from
477 * indirect-draw parameters buffer.. which is annoying
478 * and means we can't easily emit these consts in cmd
479 * stream so need to copy them to bo.
480 */
481 if (indirect && needs_vtxid_base) {
482 uint32_t vertex_params_area = align(vertex_params_size, 16);
483 struct pipe_resource *vertex_params_rsc =
484 pipe_buffer_create(&ctx->screen->base, PIPE_BIND_CONSTANT_BUFFER,
485 PIPE_USAGE_STREAM, vertex_params_area * 4);
486 unsigned src_off = indirect->offset;
487 ;
488 void *ptr;
489
490 ptr = fd_bo_map(fd_resource(vertex_params_rsc)->bo);
491 memcpy(ptr, vertex_params, vertex_params_size * 4);
492
493 if (info->index_size) {
494 /* indexed draw, index_bias is 4th field: */
495 src_off += 3 * 4;
496 } else {
497 /* non-indexed draw, start is 3rd field: */
498 src_off += 2 * 4;
499 }
500
501 /* copy index_bias or start from draw params: */
502 ctx->screen->mem_to_mem(ring, vertex_params_rsc, 0, indirect->buffer,
503 src_off, 1);
504
505 emit_const_prsc(ring, v, offset * 4, 0, vertex_params_area,
506 vertex_params_rsc);
507
508 pipe_resource_reference(&vertex_params_rsc, NULL);
509 } else {
510 emit_const_user(ring, v, offset * 4, vertex_params_size, vertex_params);
511 }
512
513 /* if needed, emit stream-out buffer addresses: */
514 if (vertex_params[IR3_DP_VTXCNT_MAX] > 0) {
515 emit_tfbos(ctx, v, ring);
516 }
517 }
518
519 static inline void
ir3_emit_vs_consts(const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_context * ctx,const struct pipe_draw_info * info,const struct pipe_draw_indirect_info * indirect,const struct pipe_draw_start_count_bias * draw)520 ir3_emit_vs_consts(const struct ir3_shader_variant *v,
521 struct fd_ringbuffer *ring, struct fd_context *ctx,
522 const struct pipe_draw_info *info,
523 const struct pipe_draw_indirect_info *indirect,
524 const struct pipe_draw_start_count_bias *draw) assert_dt
525 {
526 debug_assert(v->type == MESA_SHADER_VERTEX);
527
528 emit_common_consts(v, ring, ctx, PIPE_SHADER_VERTEX);
529
530 /* emit driver params every time: */
531 if (info && v->need_driver_params) {
532 ring_wfi(ctx->batch, ring);
533 ir3_emit_vs_driver_params(v, ring, ctx, info, indirect, draw);
534 }
535 }
536
537 static inline void
ir3_emit_fs_consts(const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_context * ctx)538 ir3_emit_fs_consts(const struct ir3_shader_variant *v,
539 struct fd_ringbuffer *ring, struct fd_context *ctx) assert_dt
540 {
541 debug_assert(v->type == MESA_SHADER_FRAGMENT);
542
543 emit_common_consts(v, ring, ctx, PIPE_SHADER_FRAGMENT);
544 }
545
546 /* emit compute-shader consts: */
547 static inline void
ir3_emit_cs_consts(const struct ir3_shader_variant * v,struct fd_ringbuffer * ring,struct fd_context * ctx,const struct pipe_grid_info * info)548 ir3_emit_cs_consts(const struct ir3_shader_variant *v,
549 struct fd_ringbuffer *ring, struct fd_context *ctx,
550 const struct pipe_grid_info *info) assert_dt
551 {
552 debug_assert(gl_shader_stage_is_compute(v->type));
553
554 emit_common_consts(v, ring, ctx, PIPE_SHADER_COMPUTE);
555
556 /* emit compute-shader driver-params: */
557 const struct ir3_const_state *const_state = ir3_const_state(v);
558 uint32_t offset = const_state->offsets.driver_param;
559 if (v->constlen > offset) {
560 ring_wfi(ctx->batch, ring);
561
562 if (info->indirect) {
563 struct pipe_resource *indirect = NULL;
564 unsigned indirect_offset;
565
566 /* This is a bit awkward, but CP_LOAD_STATE.EXT_SRC_ADDR needs
567 * to be aligned more strongly than 4 bytes. So in this case
568 * we need a temporary buffer to copy NumWorkGroups.xyz to.
569 *
570 * TODO if previous compute job is writing to info->indirect,
571 * we might need a WFI.. but since we currently flush for each
572 * compute job, we are probably ok for now.
573 */
574 if (info->indirect_offset & 0xf) {
575 indirect = pipe_buffer_create(&ctx->screen->base,
576 PIPE_BIND_COMMAND_ARGS_BUFFER,
577 PIPE_USAGE_STREAM, 0x1000);
578 indirect_offset = 0;
579
580 ctx->screen->mem_to_mem(ring, indirect, 0, info->indirect,
581 info->indirect_offset, 3);
582 } else {
583 pipe_resource_reference(&indirect, info->indirect);
584 indirect_offset = info->indirect_offset;
585 }
586
587 emit_const_prsc(ring, v, offset * 4, indirect_offset, 16, indirect);
588
589 pipe_resource_reference(&indirect, NULL);
590 } else {
591 uint32_t compute_params[IR3_DP_CS_COUNT] = {
592 [IR3_DP_NUM_WORK_GROUPS_X] = info->grid[0],
593 [IR3_DP_NUM_WORK_GROUPS_Y] = info->grid[1],
594 [IR3_DP_NUM_WORK_GROUPS_Z] = info->grid[2],
595 [IR3_DP_LOCAL_GROUP_SIZE_X] = info->block[0],
596 [IR3_DP_LOCAL_GROUP_SIZE_Y] = info->block[1],
597 [IR3_DP_LOCAL_GROUP_SIZE_Z] = info->block[2],
598 };
599 uint32_t size =
600 MIN2(const_state->num_driver_params, v->constlen * 4 - offset * 4);
601
602 emit_const_user(ring, v, offset * 4, size, compute_params);
603 }
604 }
605 }
606