radeonsi: replace CP_DMA_USE_L2 with enum si_cache_policy
[mesa.git] / src / gallium / drivers / radeonsi / si_cp_dma.c
1 /*
2 * Copyright 2013 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "si_pipe.h"
26 #include "sid.h"
27
28 /* Recommended maximum sizes for optimal performance.
29 * Fall back to compute or SDMA if the size is greater.
30 */
31 #define CP_DMA_COPY_PERF_THRESHOLD (64 * 1024) /* copied from Vulkan */
32 #define CP_DMA_CLEAR_PERF_THRESHOLD (32 * 1024) /* guess (clear is much slower) */
33
34 /* Set this if you want the ME to wait until CP DMA is done.
35 * It should be set on the last CP DMA packet. */
36 #define CP_DMA_SYNC (1 << 0)
37
38 /* Set this if the source data was used as a destination in a previous CP DMA
39 * packet. It's for preventing a read-after-write (RAW) hazard between two
40 * CP DMA packets. */
41 #define CP_DMA_RAW_WAIT (1 << 1)
42 #define CP_DMA_CLEAR (1 << 3)
43 #define CP_DMA_PFP_SYNC_ME (1 << 4)
44
45 /* The max number of bytes that can be copied per packet. */
46 static inline unsigned cp_dma_max_byte_count(struct si_context *sctx)
47 {
48 unsigned max = sctx->chip_class >= GFX9 ?
49 S_414_BYTE_COUNT_GFX9(~0u) :
50 S_414_BYTE_COUNT_GFX6(~0u);
51
52 /* make it aligned for optimal performance */
53 return max & ~(SI_CPDMA_ALIGNMENT - 1);
54 }
55
56
57 /* Emit a CP DMA packet to do a copy from one buffer to another, or to clear
58 * a buffer. The size must fit in bits [20:0]. If CP_DMA_CLEAR is set, src_va is a 32-bit
59 * clear value.
60 */
61 static void si_emit_cp_dma(struct si_context *sctx, uint64_t dst_va,
62 uint64_t src_va, unsigned size, unsigned flags,
63 enum si_cache_policy cache_policy)
64 {
65 struct radeon_cmdbuf *cs = sctx->gfx_cs;
66 uint32_t header = 0, command = 0;
67
68 assert(size <= cp_dma_max_byte_count(sctx));
69 assert(sctx->chip_class != SI || cache_policy == L2_BYPASS);
70
71 if (sctx->chip_class >= GFX9)
72 command |= S_414_BYTE_COUNT_GFX9(size);
73 else
74 command |= S_414_BYTE_COUNT_GFX6(size);
75
76 /* Sync flags. */
77 if (flags & CP_DMA_SYNC)
78 header |= S_411_CP_SYNC(1);
79 else {
80 if (sctx->chip_class >= GFX9)
81 command |= S_414_DISABLE_WR_CONFIRM_GFX9(1);
82 else
83 command |= S_414_DISABLE_WR_CONFIRM_GFX6(1);
84 }
85
86 if (flags & CP_DMA_RAW_WAIT)
87 command |= S_414_RAW_WAIT(1);
88
89 /* Src and dst flags. */
90 if (sctx->chip_class >= GFX9 && !(flags & CP_DMA_CLEAR) &&
91 src_va == dst_va)
92 header |= S_411_DST_SEL(V_411_NOWHERE); /* prefetch only */
93 else if (sctx->chip_class >= CIK && cache_policy != L2_BYPASS)
94 header |= S_411_DST_SEL(V_411_DST_ADDR_TC_L2);
95
96 if (flags & CP_DMA_CLEAR)
97 header |= S_411_SRC_SEL(V_411_DATA);
98 else if (sctx->chip_class >= CIK && cache_policy != L2_BYPASS)
99 header |= S_411_SRC_SEL(V_411_SRC_ADDR_TC_L2);
100
101 if (sctx->chip_class >= CIK) {
102 radeon_emit(cs, PKT3(PKT3_DMA_DATA, 5, 0));
103 radeon_emit(cs, header);
104 radeon_emit(cs, src_va); /* SRC_ADDR_LO [31:0] */
105 radeon_emit(cs, src_va >> 32); /* SRC_ADDR_HI [31:0] */
106 radeon_emit(cs, dst_va); /* DST_ADDR_LO [31:0] */
107 radeon_emit(cs, dst_va >> 32); /* DST_ADDR_HI [31:0] */
108 radeon_emit(cs, command);
109 } else {
110 header |= S_411_SRC_ADDR_HI(src_va >> 32);
111
112 radeon_emit(cs, PKT3(PKT3_CP_DMA, 4, 0));
113 radeon_emit(cs, src_va); /* SRC_ADDR_LO [31:0] */
114 radeon_emit(cs, header); /* SRC_ADDR_HI [15:0] + flags. */
115 radeon_emit(cs, dst_va); /* DST_ADDR_LO [31:0] */
116 radeon_emit(cs, (dst_va >> 32) & 0xffff); /* DST_ADDR_HI [15:0] */
117 radeon_emit(cs, command);
118 }
119
120 /* CP DMA is executed in ME, but index buffers are read by PFP.
121 * This ensures that ME (CP DMA) is idle before PFP starts fetching
122 * indices. If we wanted to execute CP DMA in PFP, this packet
123 * should precede it.
124 */
125 if (flags & CP_DMA_PFP_SYNC_ME) {
126 radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, 0));
127 radeon_emit(cs, 0);
128 }
129 }
130
131 void si_cp_dma_wait_for_idle(struct si_context *sctx)
132 {
133 /* Issue a dummy DMA that copies zero bytes.
134 *
135 * The DMA engine will see that there's no work to do and skip this
136 * DMA request, however, the CP will see the sync flag and still wait
137 * for all DMAs to complete.
138 */
139 si_emit_cp_dma(sctx, 0, 0, 0, CP_DMA_SYNC, L2_BYPASS);
140 }
141
142 static unsigned get_flush_flags(struct si_context *sctx, enum si_coherency coher,
143 enum si_cache_policy cache_policy)
144 {
145 switch (coher) {
146 default:
147 case SI_COHERENCY_NONE:
148 return 0;
149 case SI_COHERENCY_SHADER:
150 assert(sctx->chip_class != SI || cache_policy == L2_BYPASS);
151 return SI_CONTEXT_INV_SMEM_L1 |
152 SI_CONTEXT_INV_VMEM_L1 |
153 (cache_policy == L2_BYPASS ? SI_CONTEXT_INV_GLOBAL_L2 : 0);
154 case SI_COHERENCY_CB_META:
155 assert(sctx->chip_class >= GFX9 ? cache_policy != L2_BYPASS :
156 cache_policy == L2_BYPASS);
157 return SI_CONTEXT_FLUSH_AND_INV_CB;
158 }
159 }
160
161 static enum si_cache_policy get_cache_policy(struct si_context *sctx,
162 enum si_coherency coher)
163 {
164 if ((sctx->chip_class >= GFX9 && coher == SI_COHERENCY_CB_META) ||
165 (sctx->chip_class >= CIK && coher == SI_COHERENCY_SHADER))
166 return L2_LRU;
167
168 return L2_BYPASS;
169 }
170
171 static void si_cp_dma_prepare(struct si_context *sctx, struct pipe_resource *dst,
172 struct pipe_resource *src, unsigned byte_count,
173 uint64_t remaining_size, unsigned user_flags,
174 enum si_coherency coher, bool *is_first,
175 unsigned *packet_flags)
176 {
177 /* Fast exit for a CPDMA prefetch. */
178 if ((user_flags & SI_CPDMA_SKIP_ALL) == SI_CPDMA_SKIP_ALL) {
179 *is_first = false;
180 return;
181 }
182
183 if (!(user_flags & SI_CPDMA_SKIP_BO_LIST_UPDATE)) {
184 /* Count memory usage in so that need_cs_space can take it into account. */
185 si_context_add_resource_size(sctx, dst);
186 if (src)
187 si_context_add_resource_size(sctx, src);
188 }
189
190 if (!(user_flags & SI_CPDMA_SKIP_CHECK_CS_SPACE))
191 si_need_gfx_cs_space(sctx);
192
193 /* This must be done after need_cs_space. */
194 if (!(user_flags & SI_CPDMA_SKIP_BO_LIST_UPDATE)) {
195 radeon_add_to_buffer_list(sctx, sctx->gfx_cs,
196 r600_resource(dst),
197 RADEON_USAGE_WRITE, RADEON_PRIO_CP_DMA);
198 if (src)
199 radeon_add_to_buffer_list(sctx, sctx->gfx_cs,
200 r600_resource(src),
201 RADEON_USAGE_READ, RADEON_PRIO_CP_DMA);
202 }
203
204 /* Flush the caches for the first copy only.
205 * Also wait for the previous CP DMA operations.
206 */
207 if (!(user_flags & SI_CPDMA_SKIP_GFX_SYNC) && sctx->flags)
208 si_emit_cache_flush(sctx);
209
210 if (!(user_flags & SI_CPDMA_SKIP_SYNC_BEFORE) && *is_first)
211 *packet_flags |= CP_DMA_RAW_WAIT;
212
213 *is_first = false;
214
215 /* Do the synchronization after the last dma, so that all data
216 * is written to memory.
217 */
218 if (!(user_flags & SI_CPDMA_SKIP_SYNC_AFTER) &&
219 byte_count == remaining_size) {
220 *packet_flags |= CP_DMA_SYNC;
221
222 if (coher == SI_COHERENCY_SHADER)
223 *packet_flags |= CP_DMA_PFP_SYNC_ME;
224 }
225 }
226
227 void si_clear_buffer(struct si_context *sctx, struct pipe_resource *dst,
228 uint64_t offset, uint64_t size, unsigned value,
229 enum si_coherency coher, enum si_method xfer)
230 {
231 struct radeon_winsys *ws = sctx->ws;
232 struct r600_resource *rdst = r600_resource(dst);
233 enum si_cache_policy cache_policy = get_cache_policy(sctx, coher);
234 unsigned flush_flags = get_flush_flags(sctx, coher, cache_policy);
235 uint64_t dma_clear_size;
236 bool is_first = true;
237
238 if (!size)
239 return;
240
241 dma_clear_size = size & ~3ull;
242
243 /* Mark the buffer range of destination as valid (initialized),
244 * so that transfer_map knows it should wait for the GPU when mapping
245 * that range. */
246 util_range_add(&rdst->valid_buffer_range, offset,
247 offset + dma_clear_size);
248
249 /* dma_clear_buffer can use clear_buffer on failure. Make sure that
250 * doesn't happen. We don't want an infinite recursion: */
251 if (sctx->dma_cs &&
252 !(dst->flags & PIPE_RESOURCE_FLAG_SPARSE) &&
253 (offset % 4 == 0) &&
254 /* CP DMA is very slow. Always use SDMA for big clears. This
255 * alone improves DeusEx:MD performance by 70%. */
256 (size > CP_DMA_CLEAR_PERF_THRESHOLD ||
257 /* Buffers not used by the GFX IB yet will be cleared by SDMA.
258 * This happens to move most buffer clears to SDMA, including
259 * DCC and CMASK clears, because pipe->clear clears them before
260 * si_emit_framebuffer_state (in a draw call) adds them.
261 * For example, DeusEx:MD has 21 buffer clears per frame and all
262 * of them are moved to SDMA thanks to this. */
263 !ws->cs_is_buffer_referenced(sctx->gfx_cs, rdst->buf,
264 RADEON_USAGE_READWRITE)) &&
265 /* bypass sdma transfer with param xfer */
266 (xfer != SI_METHOD_CP_DMA)) {
267 sctx->dma_clear_buffer(sctx, dst, offset, dma_clear_size, value);
268
269 offset += dma_clear_size;
270 size -= dma_clear_size;
271 } else if (dma_clear_size >= 4) {
272 uint64_t va = rdst->gpu_address + offset;
273
274 offset += dma_clear_size;
275 size -= dma_clear_size;
276
277 /* Flush the caches. */
278 sctx->flags |= SI_CONTEXT_PS_PARTIAL_FLUSH |
279 SI_CONTEXT_CS_PARTIAL_FLUSH | flush_flags;
280
281 while (dma_clear_size) {
282 unsigned byte_count = MIN2(dma_clear_size, cp_dma_max_byte_count(sctx));
283 unsigned dma_flags = CP_DMA_CLEAR;
284
285 si_cp_dma_prepare(sctx, dst, NULL, byte_count, dma_clear_size, 0,
286 coher, &is_first, &dma_flags);
287
288 /* Emit the clear packet. */
289 si_emit_cp_dma(sctx, va, value, byte_count, dma_flags,
290 cache_policy);
291
292 dma_clear_size -= byte_count;
293 va += byte_count;
294 }
295
296 if (cache_policy != L2_BYPASS)
297 rdst->TC_L2_dirty = true;
298
299 /* If it's not a framebuffer fast clear... */
300 if (coher == SI_COHERENCY_SHADER)
301 sctx->num_cp_dma_calls++;
302 }
303
304 if (size) {
305 /* Handle non-dword alignment.
306 *
307 * This function is called for embedded texture metadata clears,
308 * but those should always be properly aligned. */
309 assert(dst->target == PIPE_BUFFER);
310 assert(size < 4);
311
312 pipe_buffer_write(&sctx->b, dst, offset, size, &value);
313 }
314 }
315
316 static void si_pipe_clear_buffer(struct pipe_context *ctx,
317 struct pipe_resource *dst,
318 unsigned offset, unsigned size,
319 const void *clear_value_ptr,
320 int clear_value_size)
321 {
322 struct si_context *sctx = (struct si_context*)ctx;
323 uint32_t dword_value;
324 unsigned i;
325
326 assert(offset % clear_value_size == 0);
327 assert(size % clear_value_size == 0);
328
329 if (clear_value_size > 4) {
330 const uint32_t *u32 = clear_value_ptr;
331 bool clear_dword_duplicated = true;
332
333 /* See if we can lower large fills to dword fills. */
334 for (i = 1; i < clear_value_size / 4; i++)
335 if (u32[0] != u32[i]) {
336 clear_dword_duplicated = false;
337 break;
338 }
339
340 if (!clear_dword_duplicated) {
341 /* Use transform feedback for 64-bit, 96-bit, and
342 * 128-bit fills.
343 */
344 union pipe_color_union clear_value;
345
346 memcpy(&clear_value, clear_value_ptr, clear_value_size);
347 si_blitter_begin(sctx, SI_DISABLE_RENDER_COND);
348 util_blitter_clear_buffer(sctx->blitter, dst, offset,
349 size, clear_value_size / 4,
350 &clear_value);
351 si_blitter_end(sctx);
352 return;
353 }
354 }
355
356 /* Expand the clear value to a dword. */
357 switch (clear_value_size) {
358 case 1:
359 dword_value = *(uint8_t*)clear_value_ptr;
360 dword_value |= (dword_value << 8) |
361 (dword_value << 16) |
362 (dword_value << 24);
363 break;
364 case 2:
365 dword_value = *(uint16_t*)clear_value_ptr;
366 dword_value |= dword_value << 16;
367 break;
368 default:
369 dword_value = *(uint32_t*)clear_value_ptr;
370 }
371
372 si_clear_buffer(sctx, dst, offset, size, dword_value,
373 SI_COHERENCY_SHADER, SI_METHOD_BEST);
374 }
375
376 /**
377 * Realign the CP DMA engine. This must be done after a copy with an unaligned
378 * size.
379 *
380 * \param size Remaining size to the CP DMA alignment.
381 */
382 static void si_cp_dma_realign_engine(struct si_context *sctx, unsigned size,
383 unsigned user_flags, enum si_coherency coher,
384 enum si_cache_policy cache_policy,
385 bool *is_first)
386 {
387 uint64_t va;
388 unsigned dma_flags = 0;
389 unsigned scratch_size = SI_CPDMA_ALIGNMENT * 2;
390
391 assert(size < SI_CPDMA_ALIGNMENT);
392
393 /* Use the scratch buffer as the dummy buffer. The 3D engine should be
394 * idle at this point.
395 */
396 if (!sctx->scratch_buffer ||
397 sctx->scratch_buffer->b.b.width0 < scratch_size) {
398 r600_resource_reference(&sctx->scratch_buffer, NULL);
399 sctx->scratch_buffer =
400 si_aligned_buffer_create(&sctx->screen->b,
401 SI_RESOURCE_FLAG_UNMAPPABLE,
402 PIPE_USAGE_DEFAULT,
403 scratch_size, 256);
404 if (!sctx->scratch_buffer)
405 return;
406
407 si_mark_atom_dirty(sctx, &sctx->atoms.s.scratch_state);
408 }
409
410 si_cp_dma_prepare(sctx, &sctx->scratch_buffer->b.b,
411 &sctx->scratch_buffer->b.b, size, size, user_flags,
412 coher, is_first, &dma_flags);
413
414 va = sctx->scratch_buffer->gpu_address;
415 si_emit_cp_dma(sctx, va, va + SI_CPDMA_ALIGNMENT, size, dma_flags,
416 cache_policy);
417 }
418
419 /**
420 * Do memcpy between buffers using CP DMA.
421 *
422 * \param user_flags bitmask of SI_CPDMA_*
423 */
424 void si_copy_buffer(struct si_context *sctx,
425 struct pipe_resource *dst, struct pipe_resource *src,
426 uint64_t dst_offset, uint64_t src_offset, unsigned size,
427 unsigned user_flags)
428 {
429 uint64_t main_dst_offset, main_src_offset;
430 unsigned skipped_size = 0;
431 unsigned realign_size = 0;
432 enum si_coherency coher = SI_COHERENCY_SHADER;
433 enum si_cache_policy cache_policy = get_cache_policy(sctx, coher);
434 bool is_first = true;
435
436 if (!size)
437 return;
438
439 if (dst != src || dst_offset != src_offset) {
440 /* Mark the buffer range of destination as valid (initialized),
441 * so that transfer_map knows it should wait for the GPU when mapping
442 * that range. */
443 util_range_add(&r600_resource(dst)->valid_buffer_range, dst_offset,
444 dst_offset + size);
445 }
446
447 dst_offset += r600_resource(dst)->gpu_address;
448 src_offset += r600_resource(src)->gpu_address;
449
450 /* The workarounds aren't needed on Fiji and beyond. */
451 if (sctx->family <= CHIP_CARRIZO ||
452 sctx->family == CHIP_STONEY) {
453 /* If the size is not aligned, we must add a dummy copy at the end
454 * just to align the internal counter. Otherwise, the DMA engine
455 * would slow down by an order of magnitude for following copies.
456 */
457 if (size % SI_CPDMA_ALIGNMENT)
458 realign_size = SI_CPDMA_ALIGNMENT - (size % SI_CPDMA_ALIGNMENT);
459
460 /* If the copy begins unaligned, we must start copying from the next
461 * aligned block and the skipped part should be copied after everything
462 * else has been copied. Only the src alignment matters, not dst.
463 */
464 if (src_offset % SI_CPDMA_ALIGNMENT) {
465 skipped_size = SI_CPDMA_ALIGNMENT - (src_offset % SI_CPDMA_ALIGNMENT);
466 /* The main part will be skipped if the size is too small. */
467 skipped_size = MIN2(skipped_size, size);
468 size -= skipped_size;
469 }
470 }
471
472 /* Flush the caches. */
473 if (!(user_flags & SI_CPDMA_SKIP_GFX_SYNC)) {
474 sctx->flags |= SI_CONTEXT_PS_PARTIAL_FLUSH |
475 SI_CONTEXT_CS_PARTIAL_FLUSH |
476 get_flush_flags(sctx, coher, cache_policy);
477 }
478
479 /* This is the main part doing the copying. Src is always aligned. */
480 main_dst_offset = dst_offset + skipped_size;
481 main_src_offset = src_offset + skipped_size;
482
483 while (size) {
484 unsigned byte_count = MIN2(size, cp_dma_max_byte_count(sctx));
485 unsigned dma_flags = 0;
486
487 si_cp_dma_prepare(sctx, dst, src, byte_count,
488 size + skipped_size + realign_size,
489 user_flags, coher, &is_first, &dma_flags);
490
491 si_emit_cp_dma(sctx, main_dst_offset, main_src_offset,
492 byte_count, dma_flags, cache_policy);
493
494 size -= byte_count;
495 main_src_offset += byte_count;
496 main_dst_offset += byte_count;
497 }
498
499 /* Copy the part we skipped because src wasn't aligned. */
500 if (skipped_size) {
501 unsigned dma_flags = 0;
502
503 si_cp_dma_prepare(sctx, dst, src, skipped_size,
504 skipped_size + realign_size, user_flags,
505 coher, &is_first, &dma_flags);
506
507 si_emit_cp_dma(sctx, dst_offset, src_offset, skipped_size,
508 dma_flags, cache_policy);
509 }
510
511 /* Finally, realign the engine if the size wasn't aligned. */
512 if (realign_size) {
513 si_cp_dma_realign_engine(sctx, realign_size, user_flags, coher,
514 cache_policy, &is_first);
515 }
516
517 if (cache_policy != L2_BYPASS)
518 r600_resource(dst)->TC_L2_dirty = true;
519
520 /* If it's not a prefetch... */
521 if (dst_offset != src_offset)
522 sctx->num_cp_dma_calls++;
523 }
524
525 void cik_prefetch_TC_L2_async(struct si_context *sctx, struct pipe_resource *buf,
526 uint64_t offset, unsigned size)
527 {
528 assert(sctx->chip_class >= CIK);
529
530 si_copy_buffer(sctx, buf, buf, offset, offset, size, SI_CPDMA_SKIP_ALL);
531 }
532
533 static void cik_prefetch_shader_async(struct si_context *sctx,
534 struct si_pm4_state *state)
535 {
536 struct pipe_resource *bo = &state->bo[0]->b.b;
537 assert(state->nbo == 1);
538
539 cik_prefetch_TC_L2_async(sctx, bo, 0, bo->width0);
540 }
541
542 static void cik_prefetch_VBO_descriptors(struct si_context *sctx)
543 {
544 if (!sctx->vertex_elements)
545 return;
546
547 cik_prefetch_TC_L2_async(sctx, &sctx->vb_descriptors_buffer->b.b,
548 sctx->vb_descriptors_offset,
549 sctx->vertex_elements->desc_list_byte_size);
550 }
551
552 /**
553 * Prefetch shaders and VBO descriptors.
554 *
555 * \param vertex_stage_only Whether only the the API VS and VBO descriptors
556 * should be prefetched.
557 */
558 void cik_emit_prefetch_L2(struct si_context *sctx, bool vertex_stage_only)
559 {
560 unsigned mask = sctx->prefetch_L2_mask;
561 assert(mask);
562
563 /* Prefetch shaders and VBO descriptors to TC L2. */
564 if (sctx->chip_class >= GFX9) {
565 /* Choose the right spot for the VBO prefetch. */
566 if (sctx->tes_shader.cso) {
567 if (mask & SI_PREFETCH_HS)
568 cik_prefetch_shader_async(sctx, sctx->queued.named.hs);
569 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
570 cik_prefetch_VBO_descriptors(sctx);
571 if (vertex_stage_only) {
572 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_HS |
573 SI_PREFETCH_VBO_DESCRIPTORS);
574 return;
575 }
576
577 if (mask & SI_PREFETCH_GS)
578 cik_prefetch_shader_async(sctx, sctx->queued.named.gs);
579 if (mask & SI_PREFETCH_VS)
580 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
581 } else if (sctx->gs_shader.cso) {
582 if (mask & SI_PREFETCH_GS)
583 cik_prefetch_shader_async(sctx, sctx->queued.named.gs);
584 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
585 cik_prefetch_VBO_descriptors(sctx);
586 if (vertex_stage_only) {
587 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_GS |
588 SI_PREFETCH_VBO_DESCRIPTORS);
589 return;
590 }
591
592 if (mask & SI_PREFETCH_VS)
593 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
594 } else {
595 if (mask & SI_PREFETCH_VS)
596 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
597 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
598 cik_prefetch_VBO_descriptors(sctx);
599 if (vertex_stage_only) {
600 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_VS |
601 SI_PREFETCH_VBO_DESCRIPTORS);
602 return;
603 }
604 }
605 } else {
606 /* SI-CI-VI */
607 /* Choose the right spot for the VBO prefetch. */
608 if (sctx->tes_shader.cso) {
609 if (mask & SI_PREFETCH_LS)
610 cik_prefetch_shader_async(sctx, sctx->queued.named.ls);
611 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
612 cik_prefetch_VBO_descriptors(sctx);
613 if (vertex_stage_only) {
614 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_LS |
615 SI_PREFETCH_VBO_DESCRIPTORS);
616 return;
617 }
618
619 if (mask & SI_PREFETCH_HS)
620 cik_prefetch_shader_async(sctx, sctx->queued.named.hs);
621 if (mask & SI_PREFETCH_ES)
622 cik_prefetch_shader_async(sctx, sctx->queued.named.es);
623 if (mask & SI_PREFETCH_GS)
624 cik_prefetch_shader_async(sctx, sctx->queued.named.gs);
625 if (mask & SI_PREFETCH_VS)
626 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
627 } else if (sctx->gs_shader.cso) {
628 if (mask & SI_PREFETCH_ES)
629 cik_prefetch_shader_async(sctx, sctx->queued.named.es);
630 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
631 cik_prefetch_VBO_descriptors(sctx);
632 if (vertex_stage_only) {
633 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_ES |
634 SI_PREFETCH_VBO_DESCRIPTORS);
635 return;
636 }
637
638 if (mask & SI_PREFETCH_GS)
639 cik_prefetch_shader_async(sctx, sctx->queued.named.gs);
640 if (mask & SI_PREFETCH_VS)
641 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
642 } else {
643 if (mask & SI_PREFETCH_VS)
644 cik_prefetch_shader_async(sctx, sctx->queued.named.vs);
645 if (mask & SI_PREFETCH_VBO_DESCRIPTORS)
646 cik_prefetch_VBO_descriptors(sctx);
647 if (vertex_stage_only) {
648 sctx->prefetch_L2_mask &= ~(SI_PREFETCH_VS |
649 SI_PREFETCH_VBO_DESCRIPTORS);
650 return;
651 }
652 }
653 }
654
655 if (mask & SI_PREFETCH_PS)
656 cik_prefetch_shader_async(sctx, sctx->queued.named.ps);
657
658 sctx->prefetch_L2_mask = 0;
659 }
660
661 void si_init_cp_dma_functions(struct si_context *sctx)
662 {
663 sctx->b.clear_buffer = si_pipe_clear_buffer;
664 }