08d47ea414e97f05ee499d59d5fa8270cf45a43c
[mesa.git] / src / gallium / drivers / radeonsi / si_pipe.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef SI_PIPE_H
27 #define SI_PIPE_H
28
29 #include "si_shader.h"
30
31 #include "util/u_dynarray.h"
32 #include "util/u_idalloc.h"
33
34 #ifdef PIPE_ARCH_BIG_ENDIAN
35 #define SI_BIG_ENDIAN 1
36 #else
37 #define SI_BIG_ENDIAN 0
38 #endif
39
40 /* The base vertex and primitive restart can be any number, but we must pick
41 * one which will mean "unknown" for the purpose of state tracking and
42 * the number shouldn't be a commonly-used one. */
43 #define SI_BASE_VERTEX_UNKNOWN INT_MIN
44 #define SI_RESTART_INDEX_UNKNOWN INT_MIN
45 #define SI_NUM_SMOOTH_AA_SAMPLES 8
46 #define SI_GS_PER_ES 128
47 /* Alignment for optimal CP DMA performance. */
48 #define SI_CPDMA_ALIGNMENT 32
49
50 /* Instruction cache. */
51 #define SI_CONTEXT_INV_ICACHE (R600_CONTEXT_PRIVATE_FLAG << 0)
52 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
53 #define SI_CONTEXT_INV_SMEM_L1 (R600_CONTEXT_PRIVATE_FLAG << 1)
54 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
55 #define SI_CONTEXT_INV_VMEM_L1 (R600_CONTEXT_PRIVATE_FLAG << 2)
56 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
57 #define SI_CONTEXT_INV_GLOBAL_L2 (R600_CONTEXT_PRIVATE_FLAG << 3)
58 /* Write dirty L2 lines back to memory (shader and CP DMA stores), but don't
59 * invalidate L2. SI-CIK can't do it, so they will do complete invalidation. */
60 #define SI_CONTEXT_WRITEBACK_GLOBAL_L2 (R600_CONTEXT_PRIVATE_FLAG << 4)
61 /* Writeback & invalidate the L2 metadata cache. It can only be coupled with
62 * a CB or DB flush. */
63 #define SI_CONTEXT_INV_L2_METADATA (R600_CONTEXT_PRIVATE_FLAG << 5)
64 /* Framebuffer caches. */
65 #define SI_CONTEXT_FLUSH_AND_INV_DB (R600_CONTEXT_PRIVATE_FLAG << 6)
66 #define SI_CONTEXT_FLUSH_AND_INV_DB_META (R600_CONTEXT_PRIVATE_FLAG << 7)
67 #define SI_CONTEXT_FLUSH_AND_INV_CB (R600_CONTEXT_PRIVATE_FLAG << 8)
68 /* Engine synchronization. */
69 #define SI_CONTEXT_VS_PARTIAL_FLUSH (R600_CONTEXT_PRIVATE_FLAG << 9)
70 #define SI_CONTEXT_PS_PARTIAL_FLUSH (R600_CONTEXT_PRIVATE_FLAG << 10)
71 #define SI_CONTEXT_CS_PARTIAL_FLUSH (R600_CONTEXT_PRIVATE_FLAG << 11)
72 #define SI_CONTEXT_VGT_FLUSH (R600_CONTEXT_PRIVATE_FLAG << 12)
73 #define SI_CONTEXT_VGT_STREAMOUT_SYNC (R600_CONTEXT_PRIVATE_FLAG << 13)
74
75 #define SI_PREFETCH_VBO_DESCRIPTORS (1 << 0)
76 #define SI_PREFETCH_LS (1 << 1)
77 #define SI_PREFETCH_HS (1 << 2)
78 #define SI_PREFETCH_ES (1 << 3)
79 #define SI_PREFETCH_GS (1 << 4)
80 #define SI_PREFETCH_VS (1 << 5)
81 #define SI_PREFETCH_PS (1 << 6)
82
83 #define SI_MAX_BORDER_COLORS 4096
84 #define SIX_BITS 0x3F
85
86 struct si_compute;
87 struct hash_table;
88 struct u_suballocator;
89
90 struct si_screen {
91 struct r600_common_screen b;
92 unsigned gs_table_depth;
93 unsigned tess_offchip_block_dw_size;
94 bool has_clear_state;
95 bool has_distributed_tess;
96 bool has_draw_indirect_multi;
97 bool has_out_of_order_rast;
98 bool assume_no_z_fights;
99 bool commutative_blend_add;
100 bool has_msaa_sample_loc_bug;
101 bool dpbb_allowed;
102 bool dfsm_allowed;
103 bool llvm_has_working_vgpr_indexing;
104
105 /* Whether shaders are monolithic (1-part) or separate (3-part). */
106 bool use_monolithic_shaders;
107 bool record_llvm_ir;
108
109 mtx_t shader_parts_mutex;
110 struct si_shader_part *vs_prologs;
111 struct si_shader_part *tcs_epilogs;
112 struct si_shader_part *gs_prologs;
113 struct si_shader_part *ps_prologs;
114 struct si_shader_part *ps_epilogs;
115
116 /* Shader cache in memory.
117 *
118 * Design & limitations:
119 * - The shader cache is per screen (= per process), never saved to
120 * disk, and skips redundant shader compilations from TGSI to bytecode.
121 * - It can only be used with one-variant-per-shader support, in which
122 * case only the main (typically middle) part of shaders is cached.
123 * - Only VS, TCS, TES, PS are cached, out of which only the hw VS
124 * variants of VS and TES are cached, so LS and ES aren't.
125 * - GS and CS aren't cached, but it's certainly possible to cache
126 * those as well.
127 */
128 mtx_t shader_cache_mutex;
129 struct hash_table *shader_cache;
130
131 /* Shader compiler queue for multithreaded compilation. */
132 struct util_queue shader_compiler_queue;
133 /* Use at most 3 normal compiler threads on quadcore and better.
134 * Hyperthreaded CPUs report the number of threads, but we want
135 * the number of cores. */
136 LLVMTargetMachineRef tm[3]; /* used by the queue only */
137
138 struct util_queue shader_compiler_queue_low_priority;
139 /* Use at most 2 low priority threads on quadcore and better.
140 * We want to minimize the impact on multithreaded Mesa. */
141 LLVMTargetMachineRef tm_low_priority[2]; /* at most 2 threads */
142 };
143
144 struct si_blend_color {
145 struct r600_atom atom;
146 struct pipe_blend_color state;
147 bool any_nonzeros;
148 };
149
150 struct si_sampler_view {
151 struct pipe_sampler_view base;
152 /* [0..7] = image descriptor
153 * [4..7] = buffer descriptor */
154 uint32_t state[8];
155 uint32_t fmask_state[8];
156 const struct legacy_surf_level *base_level_info;
157 ubyte base_level;
158 ubyte block_width;
159 bool is_stencil_sampler;
160 bool is_integer;
161 bool dcc_incompatible;
162 };
163
164 #define SI_SAMPLER_STATE_MAGIC 0x34f1c35a
165
166 struct si_sampler_state {
167 #ifdef DEBUG
168 unsigned magic;
169 #endif
170 uint32_t val[4];
171 uint32_t integer_val[4];
172 uint32_t upgraded_depth_val[4];
173 };
174
175 struct si_cs_shader_state {
176 struct si_compute *program;
177 struct si_compute *emitted_program;
178 unsigned offset;
179 bool initialized;
180 bool uses_scratch;
181 };
182
183 struct si_textures_info {
184 struct si_sampler_views views;
185 uint32_t needs_depth_decompress_mask;
186 uint32_t needs_color_decompress_mask;
187 };
188
189 struct si_images_info {
190 struct pipe_image_view views[SI_NUM_IMAGES];
191 uint32_t needs_color_decompress_mask;
192 unsigned enabled_mask;
193 };
194
195 struct si_framebuffer {
196 struct r600_atom atom;
197 struct pipe_framebuffer_state state;
198 unsigned colorbuf_enabled_4bit;
199 unsigned spi_shader_col_format;
200 unsigned spi_shader_col_format_alpha;
201 unsigned spi_shader_col_format_blend;
202 unsigned spi_shader_col_format_blend_alpha;
203 ubyte nr_samples:5; /* at most 16xAA */
204 ubyte log_samples:3; /* at most 4 = 16xAA */
205 ubyte compressed_cb_mask;
206 ubyte color_is_int8;
207 ubyte color_is_int10;
208 ubyte dirty_cbufs;
209 bool dirty_zsbuf;
210 bool any_dst_linear;
211 bool CB_has_shader_readable_metadata;
212 bool DB_has_shader_readable_metadata;
213 };
214
215 struct si_clip_state {
216 struct r600_atom atom;
217 struct pipe_clip_state state;
218 bool any_nonzeros;
219 };
220
221 struct si_sample_locs {
222 struct r600_atom atom;
223 unsigned nr_samples;
224 };
225
226 struct si_sample_mask {
227 struct r600_atom atom;
228 uint16_t sample_mask;
229 };
230
231 /* A shader state consists of the shader selector, which is a constant state
232 * object shared by multiple contexts and shouldn't be modified, and
233 * the current shader variant selected for this context.
234 */
235 struct si_shader_ctx_state {
236 struct si_shader_selector *cso;
237 struct si_shader *current;
238 };
239
240 #define SI_NUM_VGT_PARAM_KEY_BITS 12
241 #define SI_NUM_VGT_PARAM_STATES (1 << SI_NUM_VGT_PARAM_KEY_BITS)
242
243 /* The IA_MULTI_VGT_PARAM key used to index the table of precomputed values.
244 * Some fields are set by state-change calls, most are set by draw_vbo.
245 */
246 union si_vgt_param_key {
247 struct {
248 unsigned prim:4;
249 unsigned uses_instancing:1;
250 unsigned multi_instances_smaller_than_primgroup:1;
251 unsigned primitive_restart:1;
252 unsigned count_from_stream_output:1;
253 unsigned line_stipple_enabled:1;
254 unsigned uses_tess:1;
255 unsigned tess_uses_prim_id:1;
256 unsigned uses_gs:1;
257 unsigned _pad:32 - SI_NUM_VGT_PARAM_KEY_BITS;
258 } u;
259 uint32_t index;
260 };
261
262 struct si_texture_handle
263 {
264 unsigned desc_slot;
265 bool desc_dirty;
266 struct pipe_sampler_view *view;
267 struct si_sampler_state sstate;
268 };
269
270 struct si_image_handle
271 {
272 unsigned desc_slot;
273 bool desc_dirty;
274 struct pipe_image_view view;
275 };
276
277 struct si_saved_cs {
278 struct pipe_reference reference;
279 struct si_context *ctx;
280 struct radeon_saved_cs gfx;
281 struct r600_resource *trace_buf;
282 unsigned trace_id;
283
284 unsigned gfx_last_dw;
285 bool flushed;
286 };
287
288 struct si_context {
289 struct r600_common_context b;
290 struct blitter_context *blitter;
291 void *custom_dsa_flush;
292 void *custom_blend_resolve;
293 void *custom_blend_fmask_decompress;
294 void *custom_blend_eliminate_fastclear;
295 void *custom_blend_dcc_decompress;
296 struct si_screen *screen;
297 LLVMTargetMachineRef tm; /* only non-threaded compilation */
298 struct si_shader_ctx_state fixed_func_tcs_shader;
299 struct r600_resource *wait_mem_scratch;
300 unsigned wait_mem_number;
301 uint16_t prefetch_L2_mask;
302
303 bool gfx_flush_in_progress:1;
304 bool compute_is_busy:1;
305
306 /* Atoms (direct states). */
307 union si_state_atoms atoms;
308 unsigned dirty_atoms; /* mask */
309 /* PM4 states (precomputed immutable states) */
310 unsigned dirty_states;
311 union si_state queued;
312 union si_state emitted;
313
314 /* Atom declarations. */
315 struct si_framebuffer framebuffer;
316 struct si_sample_locs msaa_sample_locs;
317 struct r600_atom db_render_state;
318 struct r600_atom dpbb_state;
319 struct r600_atom msaa_config;
320 struct si_sample_mask sample_mask;
321 struct r600_atom cb_render_state;
322 unsigned last_cb_target_mask;
323 struct si_blend_color blend_color;
324 struct r600_atom clip_regs;
325 struct si_clip_state clip_state;
326 struct si_shader_data shader_pointers;
327 struct si_stencil_ref stencil_ref;
328 struct r600_atom spi_map;
329
330 /* Precomputed states. */
331 struct si_pm4_state *init_config;
332 struct si_pm4_state *init_config_gs_rings;
333 bool init_config_has_vgt_flush;
334 struct si_pm4_state *vgt_shader_config[4];
335
336 /* shaders */
337 struct si_shader_ctx_state ps_shader;
338 struct si_shader_ctx_state gs_shader;
339 struct si_shader_ctx_state vs_shader;
340 struct si_shader_ctx_state tcs_shader;
341 struct si_shader_ctx_state tes_shader;
342 struct si_cs_shader_state cs_shader_state;
343
344 /* shader information */
345 struct si_vertex_elements *vertex_elements;
346 unsigned sprite_coord_enable;
347 bool flatshade;
348 bool do_update_shaders;
349
350 /* shader descriptors */
351 struct si_descriptors vertex_buffers;
352 struct si_descriptors descriptors[SI_NUM_DESCS];
353 unsigned descriptors_dirty;
354 unsigned shader_pointers_dirty;
355 unsigned shader_needs_decompress_mask;
356 struct si_buffer_resources rw_buffers;
357 struct si_buffer_resources const_and_shader_buffers[SI_NUM_SHADERS];
358 struct si_textures_info samplers[SI_NUM_SHADERS];
359 struct si_images_info images[SI_NUM_SHADERS];
360
361 /* other shader resources */
362 struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
363 struct pipe_resource *esgs_ring;
364 struct pipe_resource *gsvs_ring;
365 struct pipe_resource *tf_ring;
366 struct pipe_resource *tess_offchip_ring;
367 union pipe_color_union *border_color_table; /* in CPU memory, any endian */
368 struct r600_resource *border_color_buffer;
369 union pipe_color_union *border_color_map; /* in VRAM (slow access), little endian */
370 unsigned border_color_count;
371
372 /* Vertex and index buffers. */
373 bool vertex_buffers_dirty;
374 bool vertex_buffer_pointer_dirty;
375 struct pipe_vertex_buffer vertex_buffer[SI_NUM_VERTEX_BUFFERS];
376
377 /* MSAA config state. */
378 int ps_iter_samples;
379 bool smoothing_enabled;
380
381 /* DB render state. */
382 unsigned ps_db_shader_control;
383 unsigned dbcb_copy_sample;
384 bool dbcb_depth_copy_enabled:1;
385 bool dbcb_stencil_copy_enabled:1;
386 bool db_flush_depth_inplace:1;
387 bool db_flush_stencil_inplace:1;
388 bool db_depth_clear:1;
389 bool db_depth_disable_expclear:1;
390 bool db_stencil_clear:1;
391 bool db_stencil_disable_expclear:1;
392 bool occlusion_queries_disabled:1;
393 bool generate_mipmap_for_depth:1;
394
395 /* Emitted draw state. */
396 bool gs_tri_strip_adj_fix:1;
397 bool ls_vgpr_fix:1;
398 int last_index_size;
399 int last_base_vertex;
400 int last_start_instance;
401 int last_drawid;
402 int last_sh_base_reg;
403 int last_primitive_restart_en;
404 int last_restart_index;
405 int last_gs_out_prim;
406 int last_prim;
407 int last_multi_vgt_param;
408 int last_rast_prim;
409 unsigned last_sc_line_stipple;
410 unsigned current_vs_state;
411 unsigned last_vs_state;
412
413 /* Scratch buffer */
414 struct r600_atom scratch_state;
415 struct r600_resource *scratch_buffer;
416 unsigned scratch_waves;
417 unsigned spi_tmpring_size;
418
419 struct r600_resource *compute_scratch_buffer;
420
421 /* Emitted derived tessellation state. */
422 /* Local shader (VS), or HS if LS-HS are merged. */
423 struct si_shader *last_ls;
424 struct si_shader_selector *last_tcs;
425 int last_num_tcs_input_cp;
426 int last_tes_sh_base;
427 bool last_tess_uses_primid;
428 unsigned last_num_patches;
429
430 /* Debug state. */
431 bool is_debug;
432 struct si_saved_cs *current_saved_cs;
433 uint64_t dmesg_timestamp;
434 unsigned apitrace_call_number;
435
436 /* Other state */
437 bool need_check_render_feedback;
438 bool decompression_enabled;
439
440 /* Precomputed IA_MULTI_VGT_PARAM */
441 union si_vgt_param_key ia_multi_vgt_param_key;
442 unsigned ia_multi_vgt_param[SI_NUM_VGT_PARAM_STATES];
443
444 /* Bindless descriptors. */
445 struct si_descriptors bindless_descriptors;
446 struct util_idalloc bindless_used_slots;
447 unsigned num_bindless_descriptors;
448 bool bindless_descriptors_dirty;
449 bool graphics_bindless_pointer_dirty;
450 bool compute_bindless_pointer_dirty;
451
452 /* Allocated bindless handles */
453 struct hash_table *tex_handles;
454 struct hash_table *img_handles;
455
456 /* Resident bindless handles */
457 struct util_dynarray resident_tex_handles;
458 struct util_dynarray resident_img_handles;
459
460 /* Resident bindless handles which need decompression */
461 struct util_dynarray resident_tex_needs_color_decompress;
462 struct util_dynarray resident_img_needs_color_decompress;
463 struct util_dynarray resident_tex_needs_depth_decompress;
464
465 /* Bindless state */
466 bool uses_bindless_samplers;
467 bool uses_bindless_images;
468 };
469
470 /* cik_sdma.c */
471 void cik_init_sdma_functions(struct si_context *sctx);
472
473 /* si_blit.c */
474 void si_init_blit_functions(struct si_context *sctx);
475 void si_decompress_graphics_textures(struct si_context *sctx);
476 void si_decompress_compute_textures(struct si_context *sctx);
477 void si_resource_copy_region(struct pipe_context *ctx,
478 struct pipe_resource *dst,
479 unsigned dst_level,
480 unsigned dstx, unsigned dsty, unsigned dstz,
481 struct pipe_resource *src,
482 unsigned src_level,
483 const struct pipe_box *src_box);
484
485 /* si_cp_dma.c */
486 #define SI_CPDMA_SKIP_CHECK_CS_SPACE (1 << 0) /* don't call need_cs_space */
487 #define SI_CPDMA_SKIP_SYNC_AFTER (1 << 1) /* don't wait for DMA after the copy */
488 #define SI_CPDMA_SKIP_SYNC_BEFORE (1 << 2) /* don't wait for DMA before the copy (RAW hazards) */
489 #define SI_CPDMA_SKIP_GFX_SYNC (1 << 3) /* don't flush caches and don't wait for PS/CS */
490 #define SI_CPDMA_SKIP_BO_LIST_UPDATE (1 << 4) /* don't update the BO list */
491 #define SI_CPDMA_SKIP_ALL (SI_CPDMA_SKIP_CHECK_CS_SPACE | \
492 SI_CPDMA_SKIP_SYNC_AFTER | \
493 SI_CPDMA_SKIP_SYNC_BEFORE | \
494 SI_CPDMA_SKIP_GFX_SYNC | \
495 SI_CPDMA_SKIP_BO_LIST_UPDATE)
496
497 void si_copy_buffer(struct si_context *sctx,
498 struct pipe_resource *dst, struct pipe_resource *src,
499 uint64_t dst_offset, uint64_t src_offset, unsigned size,
500 unsigned user_flags);
501 void cik_prefetch_TC_L2_async(struct si_context *sctx, struct pipe_resource *buf,
502 uint64_t offset, unsigned size);
503 void cik_emit_prefetch_L2(struct si_context *sctx);
504 void si_init_cp_dma_functions(struct si_context *sctx);
505
506 /* si_debug.c */
507 void si_auto_log_cs(void *data, struct u_log_context *log);
508 void si_log_hw_flush(struct si_context *sctx);
509 void si_log_draw_state(struct si_context *sctx, struct u_log_context *log);
510 void si_log_compute_state(struct si_context *sctx, struct u_log_context *log);
511 void si_init_debug_functions(struct si_context *sctx);
512 void si_check_vm_faults(struct r600_common_context *ctx,
513 struct radeon_saved_cs *saved, enum ring_type ring);
514 bool si_replace_shader(unsigned num, struct ac_shader_binary *binary);
515
516 /* si_dma.c */
517 void si_init_dma_functions(struct si_context *sctx);
518
519 /* si_hw_context.c */
520 void si_destroy_saved_cs(struct si_saved_cs *scs);
521 void si_context_gfx_flush(void *context, unsigned flags,
522 struct pipe_fence_handle **fence);
523 void si_begin_new_cs(struct si_context *ctx);
524 void si_need_cs_space(struct si_context *ctx);
525
526 /* si_compute.c */
527 void si_init_compute_functions(struct si_context *sctx);
528
529 /* si_perfcounters.c */
530 void si_init_perfcounters(struct si_screen *screen);
531
532 /* si_uvd.c */
533 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
534 const struct pipe_video_codec *templ);
535
536 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
537 const struct pipe_video_buffer *tmpl);
538
539 /*
540 * common helpers
541 */
542
543 static inline void
544 si_invalidate_draw_sh_constants(struct si_context *sctx)
545 {
546 sctx->last_base_vertex = SI_BASE_VERTEX_UNKNOWN;
547 }
548
549 static inline void
550 si_set_atom_dirty(struct si_context *sctx,
551 struct r600_atom *atom, bool dirty)
552 {
553 unsigned bit = 1 << atom->id;
554
555 if (dirty)
556 sctx->dirty_atoms |= bit;
557 else
558 sctx->dirty_atoms &= ~bit;
559 }
560
561 static inline bool
562 si_is_atom_dirty(struct si_context *sctx,
563 struct r600_atom *atom)
564 {
565 unsigned bit = 1 << atom->id;
566
567 return sctx->dirty_atoms & bit;
568 }
569
570 static inline void
571 si_mark_atom_dirty(struct si_context *sctx,
572 struct r600_atom *atom)
573 {
574 si_set_atom_dirty(sctx, atom, true);
575 }
576
577 static inline struct si_shader_ctx_state *si_get_vs(struct si_context *sctx)
578 {
579 if (sctx->gs_shader.cso)
580 return &sctx->gs_shader;
581 if (sctx->tes_shader.cso)
582 return &sctx->tes_shader;
583
584 return &sctx->vs_shader;
585 }
586
587 static inline struct tgsi_shader_info *si_get_vs_info(struct si_context *sctx)
588 {
589 struct si_shader_ctx_state *vs = si_get_vs(sctx);
590
591 return vs->cso ? &vs->cso->info : NULL;
592 }
593
594 static inline struct si_shader* si_get_vs_state(struct si_context *sctx)
595 {
596 if (sctx->gs_shader.cso)
597 return sctx->gs_shader.cso->gs_copy_shader;
598
599 struct si_shader_ctx_state *vs = si_get_vs(sctx);
600 return vs->current ? vs->current : NULL;
601 }
602
603 static inline unsigned
604 si_optimal_tcc_alignment(struct si_context *sctx, unsigned upload_size)
605 {
606 unsigned alignment, tcc_cache_line_size;
607
608 /* If the upload size is less than the cache line size (e.g. 16, 32),
609 * the whole thing will fit into a cache line if we align it to its size.
610 * The idea is that multiple small uploads can share a cache line.
611 * If the upload size is greater, align it to the cache line size.
612 */
613 alignment = util_next_power_of_two(upload_size);
614 tcc_cache_line_size = sctx->screen->b.info.tcc_cache_line_size;
615 return MIN2(alignment, tcc_cache_line_size);
616 }
617
618 static inline void
619 si_saved_cs_reference(struct si_saved_cs **dst, struct si_saved_cs *src)
620 {
621 if (pipe_reference(&(*dst)->reference, &src->reference))
622 si_destroy_saved_cs(*dst);
623
624 *dst = src;
625 }
626
627 static inline void
628 si_make_CB_shader_coherent(struct si_context *sctx, unsigned num_samples,
629 bool shaders_read_metadata)
630 {
631 sctx->b.flags |= SI_CONTEXT_FLUSH_AND_INV_CB |
632 SI_CONTEXT_INV_VMEM_L1;
633
634 if (sctx->b.chip_class >= GFX9) {
635 /* Single-sample color is coherent with shaders on GFX9, but
636 * L2 metadata must be flushed if shaders read metadata.
637 * (DCC, CMASK).
638 */
639 if (num_samples >= 2)
640 sctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2;
641 else if (shaders_read_metadata)
642 sctx->b.flags |= SI_CONTEXT_INV_L2_METADATA;
643 } else {
644 /* SI-CI-VI */
645 sctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2;
646 }
647 }
648
649 static inline void
650 si_make_DB_shader_coherent(struct si_context *sctx, unsigned num_samples,
651 bool include_stencil, bool shaders_read_metadata)
652 {
653 sctx->b.flags |= SI_CONTEXT_FLUSH_AND_INV_DB |
654 SI_CONTEXT_INV_VMEM_L1;
655
656 if (sctx->b.chip_class >= GFX9) {
657 /* Single-sample depth (not stencil) is coherent with shaders
658 * on GFX9, but L2 metadata must be flushed if shaders read
659 * metadata.
660 */
661 if (num_samples >= 2 || include_stencil)
662 sctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2;
663 else if (shaders_read_metadata)
664 sctx->b.flags |= SI_CONTEXT_INV_L2_METADATA;
665 } else {
666 /* SI-CI-VI */
667 sctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2;
668 }
669 }
670
671 #endif