2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 * Copyright 2018 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "si_shader.h"
31 #include "util/u_dynarray.h"
32 #include "util/u_idalloc.h"
33 #include "util/u_range.h"
34 #include "util/u_threaded_context.h"
36 #ifdef PIPE_ARCH_BIG_ENDIAN
37 #define SI_BIG_ENDIAN 1
39 #define SI_BIG_ENDIAN 0
42 #define ATI_VENDOR_ID 0x1002
44 #define SI_NOT_QUERY 0xffffffff
46 /* The base vertex and primitive restart can be any number, but we must pick
47 * one which will mean "unknown" for the purpose of state tracking and
48 * the number shouldn't be a commonly-used one. */
49 #define SI_BASE_VERTEX_UNKNOWN INT_MIN
50 #define SI_RESTART_INDEX_UNKNOWN INT_MIN
51 #define SI_NUM_SMOOTH_AA_SAMPLES 8
52 #define SI_GS_PER_ES 128
53 /* Alignment for optimal CP DMA performance. */
54 #define SI_CPDMA_ALIGNMENT 32
56 /* Pipeline & streamout query controls. */
57 #define SI_CONTEXT_START_PIPELINE_STATS (1 << 0)
58 #define SI_CONTEXT_STOP_PIPELINE_STATS (1 << 1)
59 #define SI_CONTEXT_FLUSH_FOR_RENDER_COND (1 << 2)
60 /* Instruction cache. */
61 #define SI_CONTEXT_INV_ICACHE (1 << 3)
62 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
63 #define SI_CONTEXT_INV_SMEM_L1 (1 << 4)
64 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
65 #define SI_CONTEXT_INV_VMEM_L1 (1 << 5)
66 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
67 #define SI_CONTEXT_INV_GLOBAL_L2 (1 << 6)
68 /* Write dirty L2 lines back to memory (shader and CP DMA stores), but don't
69 * invalidate L2. SI-CIK can't do it, so they will do complete invalidation. */
70 #define SI_CONTEXT_WRITEBACK_GLOBAL_L2 (1 << 7)
71 /* Writeback & invalidate the L2 metadata cache. It can only be coupled with
72 * a CB or DB flush. */
73 #define SI_CONTEXT_INV_L2_METADATA (1 << 8)
74 /* Framebuffer caches. */
75 #define SI_CONTEXT_FLUSH_AND_INV_DB (1 << 9)
76 #define SI_CONTEXT_FLUSH_AND_INV_DB_META (1 << 10)
77 #define SI_CONTEXT_FLUSH_AND_INV_CB (1 << 11)
78 /* Engine synchronization. */
79 #define SI_CONTEXT_VS_PARTIAL_FLUSH (1 << 12)
80 #define SI_CONTEXT_PS_PARTIAL_FLUSH (1 << 13)
81 #define SI_CONTEXT_CS_PARTIAL_FLUSH (1 << 14)
82 #define SI_CONTEXT_VGT_FLUSH (1 << 15)
83 #define SI_CONTEXT_VGT_STREAMOUT_SYNC (1 << 16)
85 #define SI_PREFETCH_VBO_DESCRIPTORS (1 << 0)
86 #define SI_PREFETCH_LS (1 << 1)
87 #define SI_PREFETCH_HS (1 << 2)
88 #define SI_PREFETCH_ES (1 << 3)
89 #define SI_PREFETCH_GS (1 << 4)
90 #define SI_PREFETCH_VS (1 << 5)
91 #define SI_PREFETCH_PS (1 << 6)
93 #define SI_MAX_BORDER_COLORS 4096
94 #define SI_MAX_VIEWPORTS 16
96 #define SI_MAP_BUFFER_ALIGNMENT 64
97 #define SI_MAX_VARIABLE_THREADS_PER_BLOCK 1024
99 #define SI_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
100 #define SI_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
101 #define SI_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
102 #define SI_RESOURCE_FLAG_DISABLE_DCC (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
103 #define SI_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)
104 #define SI_RESOURCE_FLAG_READ_ONLY (PIPE_RESOURCE_FLAG_DRV_PRIV << 5)
105 #define SI_RESOURCE_FLAG_32BIT (PIPE_RESOURCE_FLAG_DRV_PRIV << 6)
109 /* Shader logging options: */
110 DBG_VS
= PIPE_SHADER_VERTEX
,
111 DBG_PS
= PIPE_SHADER_FRAGMENT
,
112 DBG_GS
= PIPE_SHADER_GEOMETRY
,
113 DBG_TCS
= PIPE_SHADER_TESS_CTRL
,
114 DBG_TES
= PIPE_SHADER_TESS_EVAL
,
115 DBG_CS
= PIPE_SHADER_COMPUTE
,
121 /* Shader compiler options the shader cache should be aware of: */
122 DBG_FS_CORRECT_DERIVS_AFTER_KILL
,
126 /* Shader compiler options (with no effect on the shader cache): */
129 DBG_MONOLITHIC_SHADERS
,
132 /* Information logging options: */
138 /* Driver options: */
145 /* 3D engine options: */
165 DBG_TEST_VMFAULT_SDMA
,
166 DBG_TEST_VMFAULT_SHADER
,
169 #define DBG_ALL_SHADERS (((1 << (DBG_CS + 1)) - 1))
170 #define DBG(name) (1ull << DBG_##name)
174 struct u_suballocator
;
176 /* Only 32-bit buffer allocations are supported, gallium doesn't support more
179 struct r600_resource
{
180 struct threaded_resource b
;
182 /* Winsys objects. */
183 struct pb_buffer
*buf
;
184 uint64_t gpu_address
;
185 /* Memory usage if the buffer placement is optimal. */
189 /* Resource properties. */
191 unsigned bo_alignment
;
192 enum radeon_bo_domain domains
;
193 enum radeon_bo_flag flags
;
194 unsigned bind_history
;
195 int max_forced_staging_uploads
;
197 /* The buffer range which is initialized (with a write transfer,
198 * streamout, DMA, or as a random access target). The rest of
199 * the buffer is considered invalid and can be mapped unsynchronized.
201 * This allows unsychronized mapping of a buffer range which hasn't
202 * been used yet. It's for applications which forget to use
203 * the unsynchronized map flag and expect the driver to figure it out.
205 struct util_range valid_buffer_range
;
207 /* For buffers only. This indicates that a write operation has been
208 * performed by TC L2, but the cache hasn't been flushed.
209 * Any hw block which doesn't use or bypasses TC L2 should check this
210 * flag and flush the cache before using the buffer.
212 * For example, TC L2 must be flushed if a buffer which has been
213 * modified by a shader store instruction is about to be used as
214 * an index buffer. The reason is that VGT DMA index fetching doesn't
219 /* Whether the resource has been exported via resource_get_handle. */
220 unsigned external_usage
; /* PIPE_HANDLE_USAGE_* */
222 /* Whether this resource is referenced by bindless handles. */
223 bool texture_handle_allocated
;
224 bool image_handle_allocated
;
227 struct r600_transfer
{
228 struct threaded_transfer b
;
229 struct r600_resource
*staging
;
233 struct r600_cmask_info
{
237 unsigned slice_tile_max
;
238 uint64_t base_address_reg
;
241 struct r600_texture
{
242 struct r600_resource buffer
;
244 struct radeon_surf surface
;
246 struct r600_texture
*flushed_depth_texture
;
248 /* Colorbuffer compression and fast clear. */
249 uint64_t fmask_offset
;
250 struct r600_cmask_info cmask
;
251 struct r600_resource
*cmask_buffer
;
252 uint64_t dcc_offset
; /* 0 = disabled */
253 unsigned cb_color_info
; /* fast clear enable bit */
254 unsigned color_clear_value
[2];
255 unsigned last_msaa_resolve_target_micro_mode
;
256 unsigned num_level0_transfers
;
258 /* Depth buffer compression and fast clear. */
259 uint64_t htile_offset
;
260 float depth_clear_value
;
261 uint16_t dirty_level_mask
; /* each bit says if that mipmap is compressed */
262 uint16_t stencil_dirty_level_mask
; /* each bit says if that mipmap is compressed */
263 enum pipe_format db_render_format
:16;
264 uint8_t stencil_clear_value
;
265 bool tc_compatible_htile
:1;
266 bool depth_cleared
:1; /* if it was cleared at least once */
267 bool stencil_cleared
:1; /* if it was cleared at least once */
268 bool upgraded_depth
:1; /* upgraded from unorm to Z32_FLOAT */
270 bool db_compatible
:1;
274 /* We need to track DCC dirtiness, because st/dri usually calls
275 * flush_resource twice per frame (not a bug) and we don't wanna
276 * decompress DCC twice. Also, the dirty tracking must be done even
277 * if DCC isn't used, because it's required by the DCC usage analysis
278 * for a possible future enablement.
280 bool separate_dcc_dirty
:1;
281 /* Statistics gathering for the DCC enablement heuristic. */
282 bool dcc_gather_statistics
:1;
283 /* Counter that should be non-zero if the texture is bound to a
286 unsigned framebuffers_bound
;
287 /* Whether the texture is a displayable back buffer and needs DCC
288 * decompression, which is expensive. Therefore, it's enabled only
289 * if statistics suggest that it will pay off and it's allocated
290 * separately. It can't be bound as a sampler by apps. Limited to
291 * target == 2D and last_level == 0. If enabled, dcc_offset contains
292 * the absolute GPUVM address, not the relative one.
294 struct r600_resource
*dcc_separate_buffer
;
295 /* When DCC is temporarily disabled, the separate buffer is here. */
296 struct r600_resource
*last_dcc_separate_buffer
;
297 /* Estimate of how much this color buffer is written to in units of
298 * full-screen draws: ps_invocations / (width * height)
299 * Shader kills, late Z, and blending with trivial discards make it
300 * inaccurate (we need to count CB updates, not PS invocations).
302 unsigned ps_draw_ratio
;
303 /* The number of clears since the last DCC usage analysis. */
304 unsigned num_slow_clears
;
307 struct r600_surface
{
308 struct pipe_surface base
;
310 /* These can vary with block-compressed textures. */
314 bool color_initialized
:1;
315 bool depth_initialized
:1;
317 /* Misc. color flags. */
318 bool color_is_int8
:1;
319 bool color_is_int10
:1;
320 bool dcc_incompatible
:1;
322 /* Color registers. */
323 unsigned cb_color_info
;
324 unsigned cb_color_view
;
325 unsigned cb_color_attrib
;
326 unsigned cb_color_attrib2
; /* GFX9 and later */
327 unsigned cb_dcc_control
; /* VI and later */
328 unsigned spi_shader_col_format
:8; /* no blending, no alpha-to-coverage. */
329 unsigned spi_shader_col_format_alpha
:8; /* alpha-to-coverage */
330 unsigned spi_shader_col_format_blend
:8; /* blending without alpha. */
331 unsigned spi_shader_col_format_blend_alpha
:8; /* blending with alpha. */
334 uint64_t db_depth_base
; /* DB_Z_READ/WRITE_BASE */
335 uint64_t db_stencil_base
;
336 uint64_t db_htile_data_base
;
337 unsigned db_depth_info
;
339 unsigned db_z_info2
; /* GFX9+ */
340 unsigned db_depth_view
;
341 unsigned db_depth_size
;
342 unsigned db_depth_slice
;
343 unsigned db_stencil_info
;
344 unsigned db_stencil_info2
; /* GFX9+ */
345 unsigned db_htile_surface
;
348 struct si_mmio_counter
{
353 union si_mmio_counters
{
355 /* For global GPU load including SDMA. */
356 struct si_mmio_counter gpu
;
359 struct si_mmio_counter spi
;
360 struct si_mmio_counter gui
;
361 struct si_mmio_counter ta
;
362 struct si_mmio_counter gds
;
363 struct si_mmio_counter vgt
;
364 struct si_mmio_counter ia
;
365 struct si_mmio_counter sx
;
366 struct si_mmio_counter wd
;
367 struct si_mmio_counter bci
;
368 struct si_mmio_counter sc
;
369 struct si_mmio_counter pa
;
370 struct si_mmio_counter db
;
371 struct si_mmio_counter cp
;
372 struct si_mmio_counter cb
;
375 struct si_mmio_counter sdma
;
378 struct si_mmio_counter pfp
;
379 struct si_mmio_counter meq
;
380 struct si_mmio_counter me
;
381 struct si_mmio_counter surf_sync
;
382 struct si_mmio_counter cp_dma
;
383 struct si_mmio_counter scratch_ram
;
388 struct r600_memory_object
{
389 struct pipe_memory_object b
;
390 struct pb_buffer
*buf
;
395 /* Saved CS data for debugging features. */
396 struct radeon_saved_cs
{
400 struct radeon_bo_list_item
*bo_list
;
405 struct pipe_screen b
;
406 struct radeon_winsys
*ws
;
407 struct disk_cache
*disk_shader_cache
;
409 struct radeon_info info
;
410 uint64_t debug_flags
;
411 char renderer_string
[100];
413 unsigned gs_table_depth
;
414 unsigned tess_offchip_block_dw_size
;
415 unsigned tess_offchip_ring_size
;
416 unsigned tess_factor_ring_size
;
417 unsigned vgt_hs_offchip_param
;
418 bool has_clear_state
;
419 bool has_distributed_tess
;
420 bool has_draw_indirect_multi
;
421 bool has_out_of_order_rast
;
422 bool assume_no_z_fights
;
423 bool commutative_blend_add
;
424 bool clear_db_cache_before_clear
;
425 bool has_msaa_sample_loc_bug
;
426 bool has_ls_vgpr_init_bug
;
429 bool llvm_has_working_vgpr_indexing
;
431 /* Whether shaders are monolithic (1-part) or separate (3-part). */
432 bool use_monolithic_shaders
;
434 bool has_rbplus
; /* if RB+ registers exist */
435 bool rbplus_allowed
; /* if RB+ is allowed */
436 bool dcc_msaa_allowed
;
437 bool cpdma_prefetch_writes_memory
;
439 struct slab_parent_pool pool_transfers
;
441 /* Texture filter settings. */
442 int force_aniso
; /* -1 = disabled */
444 /* Auxiliary context. Mainly used to initialize resources.
445 * It must be locked prior to using and flushed before unlocking. */
446 struct pipe_context
*aux_context
;
447 mtx_t aux_context_lock
;
449 /* This must be in the screen, because UE4 uses one context for
450 * compilation and another one for rendering.
452 unsigned num_compilations
;
453 /* Along with ST_DEBUG=precompile, this should show if applications
454 * are loading shaders on demand. This is a monotonic counter.
456 unsigned num_shaders_created
;
457 unsigned num_shader_cache_hits
;
459 /* GPU load thread. */
460 mtx_t gpu_load_mutex
;
461 thrd_t gpu_load_thread
;
462 union si_mmio_counters mmio_counters
;
463 volatile unsigned gpu_load_stop_thread
; /* bool */
465 /* Performance counters. */
466 struct si_perfcounters
*perfcounters
;
468 /* If pipe_screen wants to recompute and re-emit the framebuffer,
469 * sampler, and image states of all contexts, it should atomically
472 * Each context will compare this with its own last known value of
473 * the counter before drawing and re-emit the states accordingly.
475 unsigned dirty_tex_counter
;
477 /* Atomically increment this counter when an existing texture's
478 * metadata is enabled or disabled in a way that requires changing
479 * contexts' compressed texture binding masks.
481 unsigned compressed_colortex_counter
;
484 /* Context flags to set so that all writes from earlier jobs
485 * in the CP are seen by L2 clients.
489 /* Context flags to set so that all writes from earlier jobs
490 * that end in L2 are seen by CP.
495 mtx_t shader_parts_mutex
;
496 struct si_shader_part
*vs_prologs
;
497 struct si_shader_part
*tcs_epilogs
;
498 struct si_shader_part
*gs_prologs
;
499 struct si_shader_part
*ps_prologs
;
500 struct si_shader_part
*ps_epilogs
;
502 /* Shader cache in memory.
504 * Design & limitations:
505 * - The shader cache is per screen (= per process), never saved to
506 * disk, and skips redundant shader compilations from TGSI to bytecode.
507 * - It can only be used with one-variant-per-shader support, in which
508 * case only the main (typically middle) part of shaders is cached.
509 * - Only VS, TCS, TES, PS are cached, out of which only the hw VS
510 * variants of VS and TES are cached, so LS and ES aren't.
511 * - GS and CS aren't cached, but it's certainly possible to cache
514 mtx_t shader_cache_mutex
;
515 struct hash_table
*shader_cache
;
517 /* Shader compiler queue for multithreaded compilation. */
518 struct util_queue shader_compiler_queue
;
519 /* Use at most 3 normal compiler threads on quadcore and better.
520 * Hyperthreaded CPUs report the number of threads, but we want
521 * the number of cores. We only need this many threads for shader-db. */
522 struct si_compiler compiler
[24]; /* used by the queue only */
524 struct util_queue shader_compiler_queue_low_priority
;
525 /* Use at most 2 low priority threads on quadcore and better.
526 * We want to minimize the impact on multithreaded Mesa. */
527 struct si_compiler compiler_lowp
[10];
530 struct si_blend_color
{
531 struct pipe_blend_color state
;
535 struct si_sampler_view
{
536 struct pipe_sampler_view base
;
537 /* [0..7] = image descriptor
538 * [4..7] = buffer descriptor */
540 uint32_t fmask_state
[8];
541 const struct legacy_surf_level
*base_level_info
;
544 bool is_stencil_sampler
;
546 bool dcc_incompatible
;
549 #define SI_SAMPLER_STATE_MAGIC 0x34f1c35a
551 struct si_sampler_state
{
556 uint32_t integer_val
[4];
557 uint32_t upgraded_depth_val
[4];
560 struct si_cs_shader_state
{
561 struct si_compute
*program
;
562 struct si_compute
*emitted_program
;
569 struct pipe_sampler_view
*views
[SI_NUM_SAMPLERS
];
570 struct si_sampler_state
*sampler_states
[SI_NUM_SAMPLERS
];
572 /* The i-th bit is set if that element is enabled (non-NULL resource). */
573 unsigned enabled_mask
;
574 uint32_t needs_depth_decompress_mask
;
575 uint32_t needs_color_decompress_mask
;
579 struct pipe_image_view views
[SI_NUM_IMAGES
];
580 uint32_t needs_color_decompress_mask
;
581 unsigned enabled_mask
;
584 struct si_framebuffer
{
585 struct pipe_framebuffer_state state
;
586 unsigned colorbuf_enabled_4bit
;
587 unsigned spi_shader_col_format
;
588 unsigned spi_shader_col_format_alpha
;
589 unsigned spi_shader_col_format_blend
;
590 unsigned spi_shader_col_format_blend_alpha
;
591 ubyte nr_samples
:5; /* at most 16xAA */
592 ubyte log_samples
:3; /* at most 4 = 16xAA */
593 ubyte compressed_cb_mask
;
594 ubyte uncompressed_cb_mask
;
596 ubyte color_is_int10
;
600 bool CB_has_shader_readable_metadata
;
601 bool DB_has_shader_readable_metadata
;
604 struct si_signed_scissor
{
613 struct pipe_scissor_state states
[SI_MAX_VIEWPORTS
];
616 struct si_viewports
{
618 unsigned depth_range_dirty_mask
;
619 struct pipe_viewport_state states
[SI_MAX_VIEWPORTS
];
620 struct si_signed_scissor as_scissor
[SI_MAX_VIEWPORTS
];
623 struct si_clip_state
{
624 struct pipe_clip_state state
;
628 struct si_streamout_target
{
629 struct pipe_stream_output_target b
;
631 /* The buffer where BUFFER_FILLED_SIZE is stored. */
632 struct r600_resource
*buf_filled_size
;
633 unsigned buf_filled_size_offset
;
634 bool buf_filled_size_valid
;
636 unsigned stride_in_dw
;
639 struct si_streamout
{
642 unsigned enabled_mask
;
643 unsigned num_targets
;
644 struct si_streamout_target
*targets
[PIPE_MAX_SO_BUFFERS
];
646 unsigned append_bitmask
;
649 /* External state which comes from the vertex shader,
650 * it must be set explicitly when binding a shader. */
651 uint16_t *stride_in_dw
;
652 unsigned enabled_stream_buffers_mask
; /* stream0 buffers0-3 in 4 LSB */
654 /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */
655 unsigned hw_enabled_mask
;
657 /* The state of VGT_STRMOUT_(CONFIG|EN). */
658 bool streamout_enabled
;
659 bool prims_gen_query_enabled
;
660 int num_prims_gen_queries
;
663 /* A shader state consists of the shader selector, which is a constant state
664 * object shared by multiple contexts and shouldn't be modified, and
665 * the current shader variant selected for this context.
667 struct si_shader_ctx_state
{
668 struct si_shader_selector
*cso
;
669 struct si_shader
*current
;
672 #define SI_NUM_VGT_PARAM_KEY_BITS 12
673 #define SI_NUM_VGT_PARAM_STATES (1 << SI_NUM_VGT_PARAM_KEY_BITS)
675 /* The IA_MULTI_VGT_PARAM key used to index the table of precomputed values.
676 * Some fields are set by state-change calls, most are set by draw_vbo.
678 union si_vgt_param_key
{
680 #ifdef PIPE_ARCH_LITTLE_ENDIAN
682 unsigned uses_instancing
:1;
683 unsigned multi_instances_smaller_than_primgroup
:1;
684 unsigned primitive_restart
:1;
685 unsigned count_from_stream_output
:1;
686 unsigned line_stipple_enabled
:1;
687 unsigned uses_tess
:1;
688 unsigned tess_uses_prim_id
:1;
690 unsigned _pad
:32 - SI_NUM_VGT_PARAM_KEY_BITS
;
691 #else /* PIPE_ARCH_BIG_ENDIAN */
692 unsigned _pad
:32 - SI_NUM_VGT_PARAM_KEY_BITS
;
694 unsigned tess_uses_prim_id
:1;
695 unsigned uses_tess
:1;
696 unsigned line_stipple_enabled
:1;
697 unsigned count_from_stream_output
:1;
698 unsigned primitive_restart
:1;
699 unsigned multi_instances_smaller_than_primgroup
:1;
700 unsigned uses_instancing
:1;
707 struct si_texture_handle
711 struct pipe_sampler_view
*view
;
712 struct si_sampler_state sstate
;
715 struct si_image_handle
719 struct pipe_image_view view
;
723 struct pipe_reference reference
;
724 struct si_context
*ctx
;
725 struct radeon_saved_cs gfx
;
726 struct r600_resource
*trace_buf
;
729 unsigned gfx_last_dw
;
735 struct pipe_context b
; /* base class */
737 enum radeon_family family
;
738 enum chip_class chip_class
;
740 struct radeon_winsys
*ws
;
741 struct radeon_winsys_ctx
*ctx
;
742 struct radeon_winsys_cs
*gfx_cs
;
743 struct radeon_winsys_cs
*dma_cs
;
744 struct pipe_fence_handle
*last_gfx_fence
;
745 struct pipe_fence_handle
*last_sdma_fence
;
746 struct r600_resource
*eop_bug_scratch
;
747 struct u_upload_mgr
*cached_gtt_allocator
;
748 struct threaded_context
*tc
;
749 struct u_suballocator
*allocator_zeroed_memory
;
750 struct slab_child_pool pool_transfers
;
751 struct slab_child_pool pool_transfers_unsync
; /* for threaded_context */
752 struct pipe_device_reset_callback device_reset_callback
;
753 struct u_log_context
*log
;
754 void *query_result_shader
;
755 struct blitter_context
*blitter
;
756 void *custom_dsa_flush
;
757 void *custom_blend_resolve
;
758 void *custom_blend_fmask_decompress
;
759 void *custom_blend_eliminate_fastclear
;
760 void *custom_blend_dcc_decompress
;
762 void *vs_blit_pos_layered
;
764 void *vs_blit_color_layered
;
765 void *vs_blit_texcoord
;
766 struct si_screen
*screen
;
767 struct pipe_debug_callback debug
;
768 struct si_compiler compiler
; /* only non-threaded compilation */
769 struct si_shader_ctx_state fixed_func_tcs_shader
;
770 struct r600_resource
*wait_mem_scratch
;
771 unsigned wait_mem_number
;
772 uint16_t prefetch_L2_mask
;
774 bool gfx_flush_in_progress
:1;
775 bool gfx_last_ib_is_busy
:1;
776 bool compute_is_busy
:1;
778 unsigned num_gfx_cs_flushes
;
779 unsigned initial_gfx_cs_size
;
780 unsigned gpu_reset_counter
;
781 unsigned last_dirty_tex_counter
;
782 unsigned last_compressed_colortex_counter
;
783 unsigned last_num_draw_calls
;
784 unsigned flags
; /* flush flags */
785 /* Current unaccounted memory usage. */
789 /* Atoms (direct states). */
790 union si_state_atoms atoms
;
791 unsigned dirty_atoms
; /* mask */
792 /* PM4 states (precomputed immutable states) */
793 unsigned dirty_states
;
794 union si_state queued
;
795 union si_state emitted
;
797 /* Atom declarations. */
798 struct si_framebuffer framebuffer
;
799 unsigned sample_locs_num_samples
;
800 uint16_t sample_mask
;
801 unsigned last_cb_target_mask
;
802 struct si_blend_color blend_color
;
803 struct si_clip_state clip_state
;
804 struct si_shader_data shader_pointers
;
805 struct si_stencil_ref stencil_ref
;
806 struct si_scissors scissors
;
807 struct si_streamout streamout
;
808 struct si_viewports viewports
;
810 /* Precomputed states. */
811 struct si_pm4_state
*init_config
;
812 struct si_pm4_state
*init_config_gs_rings
;
813 bool init_config_has_vgt_flush
;
814 struct si_pm4_state
*vgt_shader_config
[4];
817 struct si_shader_ctx_state ps_shader
;
818 struct si_shader_ctx_state gs_shader
;
819 struct si_shader_ctx_state vs_shader
;
820 struct si_shader_ctx_state tcs_shader
;
821 struct si_shader_ctx_state tes_shader
;
822 struct si_cs_shader_state cs_shader_state
;
824 /* shader information */
825 struct si_vertex_elements
*vertex_elements
;
826 unsigned sprite_coord_enable
;
828 bool do_update_shaders
;
830 /* vertex buffer descriptors */
831 uint32_t *vb_descriptors_gpu_list
;
832 struct r600_resource
*vb_descriptors_buffer
;
833 unsigned vb_descriptors_offset
;
835 /* shader descriptors */
836 struct si_descriptors descriptors
[SI_NUM_DESCS
];
837 unsigned descriptors_dirty
;
838 unsigned shader_pointers_dirty
;
839 unsigned shader_needs_decompress_mask
;
840 struct si_buffer_resources rw_buffers
;
841 struct si_buffer_resources const_and_shader_buffers
[SI_NUM_SHADERS
];
842 struct si_samplers samplers
[SI_NUM_SHADERS
];
843 struct si_images images
[SI_NUM_SHADERS
];
845 /* other shader resources */
846 struct pipe_constant_buffer null_const_buf
; /* used for set_constant_buffer(NULL) on CIK */
847 struct pipe_resource
*esgs_ring
;
848 struct pipe_resource
*gsvs_ring
;
849 struct pipe_resource
*tess_rings
;
850 union pipe_color_union
*border_color_table
; /* in CPU memory, any endian */
851 struct r600_resource
*border_color_buffer
;
852 union pipe_color_union
*border_color_map
; /* in VRAM (slow access), little endian */
853 unsigned border_color_count
;
854 unsigned num_vs_blit_sgprs
;
855 uint32_t vs_blit_sh_data
[SI_VS_BLIT_SGPRS_POS_TEXCOORD
];
857 /* Vertex and index buffers. */
858 bool vertex_buffers_dirty
;
859 bool vertex_buffer_pointer_dirty
;
860 struct pipe_vertex_buffer vertex_buffer
[SI_NUM_VERTEX_BUFFERS
];
862 /* MSAA config state. */
864 bool ps_uses_fbfetch
;
865 bool smoothing_enabled
;
867 /* DB render state. */
868 unsigned ps_db_shader_control
;
869 unsigned dbcb_copy_sample
;
870 bool dbcb_depth_copy_enabled
:1;
871 bool dbcb_stencil_copy_enabled
:1;
872 bool db_flush_depth_inplace
:1;
873 bool db_flush_stencil_inplace
:1;
874 bool db_depth_clear
:1;
875 bool db_depth_disable_expclear
:1;
876 bool db_stencil_clear
:1;
877 bool db_stencil_disable_expclear
:1;
878 bool occlusion_queries_disabled
:1;
879 bool generate_mipmap_for_depth
:1;
881 /* Emitted draw state. */
882 bool gs_tri_strip_adj_fix
:1;
885 int last_base_vertex
;
886 int last_start_instance
;
888 int last_sh_base_reg
;
889 int last_primitive_restart_en
;
890 int last_restart_index
;
891 int last_gs_out_prim
;
893 int last_multi_vgt_param
;
895 unsigned last_sc_line_stipple
;
896 unsigned current_vs_state
;
897 unsigned last_vs_state
;
898 enum pipe_prim_type current_rast_prim
; /* primitive type after TES, GS */
901 struct r600_resource
*scratch_buffer
;
902 unsigned scratch_waves
;
903 unsigned spi_tmpring_size
;
905 struct r600_resource
*compute_scratch_buffer
;
907 /* Emitted derived tessellation state. */
908 /* Local shader (VS), or HS if LS-HS are merged. */
909 struct si_shader
*last_ls
;
910 struct si_shader_selector
*last_tcs
;
911 int last_num_tcs_input_cp
;
912 int last_tes_sh_base
;
913 bool last_tess_uses_primid
;
914 unsigned last_num_patches
;
918 struct si_saved_cs
*current_saved_cs
;
919 uint64_t dmesg_timestamp
;
920 unsigned apitrace_call_number
;
923 bool need_check_render_feedback
;
924 bool decompression_enabled
;
926 bool vs_writes_viewport_index
;
927 bool vs_disables_clipping_viewport
;
929 /* Precomputed IA_MULTI_VGT_PARAM */
930 union si_vgt_param_key ia_multi_vgt_param_key
;
931 unsigned ia_multi_vgt_param
[SI_NUM_VGT_PARAM_STATES
];
933 /* Bindless descriptors. */
934 struct si_descriptors bindless_descriptors
;
935 struct util_idalloc bindless_used_slots
;
936 unsigned num_bindless_descriptors
;
937 bool bindless_descriptors_dirty
;
938 bool graphics_bindless_pointer_dirty
;
939 bool compute_bindless_pointer_dirty
;
941 /* Allocated bindless handles */
942 struct hash_table
*tex_handles
;
943 struct hash_table
*img_handles
;
945 /* Resident bindless handles */
946 struct util_dynarray resident_tex_handles
;
947 struct util_dynarray resident_img_handles
;
949 /* Resident bindless handles which need decompression */
950 struct util_dynarray resident_tex_needs_color_decompress
;
951 struct util_dynarray resident_img_needs_color_decompress
;
952 struct util_dynarray resident_tex_needs_depth_decompress
;
955 bool uses_bindless_samplers
;
956 bool uses_bindless_images
;
958 /* MSAA sample locations.
959 * The first index is the sample index.
960 * The second index is the coordinate: X, Y. */
961 float sample_locations_1x
[1][2];
962 float sample_locations_2x
[2][2];
963 float sample_locations_4x
[4][2];
964 float sample_locations_8x
[8][2];
965 float sample_locations_16x
[16][2];
968 unsigned num_draw_calls
;
969 unsigned num_decompress_calls
;
970 unsigned num_mrt_draw_calls
;
971 unsigned num_prim_restart_calls
;
972 unsigned num_spill_draw_calls
;
973 unsigned num_compute_calls
;
974 unsigned num_spill_compute_calls
;
975 unsigned num_dma_calls
;
976 unsigned num_cp_dma_calls
;
977 unsigned num_vs_flushes
;
978 unsigned num_ps_flushes
;
979 unsigned num_cs_flushes
;
980 unsigned num_cb_cache_flushes
;
981 unsigned num_db_cache_flushes
;
982 unsigned num_L2_invalidates
;
983 unsigned num_L2_writebacks
;
984 unsigned num_resident_handles
;
985 uint64_t num_alloc_tex_transfer_bytes
;
986 unsigned last_tex_ps_draw_ratio
; /* for query */
989 /* Maintain the list of active queries for pausing between IBs. */
990 int num_occlusion_queries
;
991 int num_perfect_occlusion_queries
;
992 struct list_head active_queries
;
993 unsigned num_cs_dw_queries_suspend
;
995 /* Render condition. */
996 struct pipe_query
*render_cond
;
997 unsigned render_cond_mode
;
998 bool render_cond_invert
;
999 bool render_cond_force_off
; /* for u_blitter */
1001 /* Statistics gathering for the DCC enablement heuristic. It can't be
1002 * in r600_texture because r600_texture can be shared by multiple
1003 * contexts. This is for back buffers only. We shouldn't get too many
1006 * X11 DRI3 rotates among a finite set of back buffers. They should
1007 * all fit in this array. If they don't, separate DCC might never be
1008 * enabled by DCC stat gathering.
1011 struct r600_texture
*tex
;
1012 /* Query queue: 0 = usually active, 1 = waiting, 2 = readback. */
1013 struct pipe_query
*ps_stats
[3];
1014 /* If all slots are used and another slot is needed,
1015 * the least recently used slot is evicted based on this. */
1016 int64_t last_use_timestamp
;
1020 /* Copy one resource to another using async DMA. */
1021 void (*dma_copy
)(struct pipe_context
*ctx
,
1022 struct pipe_resource
*dst
,
1024 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
1025 struct pipe_resource
*src
,
1027 const struct pipe_box
*src_box
);
1029 void (*dma_clear_buffer
)(struct si_context
*sctx
, struct pipe_resource
*dst
,
1030 uint64_t offset
, uint64_t size
, unsigned value
);
1034 void cik_init_sdma_functions(struct si_context
*sctx
);
1037 enum si_blitter_op
/* bitmask */
1039 SI_SAVE_TEXTURES
= 1,
1040 SI_SAVE_FRAMEBUFFER
= 2,
1041 SI_SAVE_FRAGMENT_STATE
= 4,
1042 SI_DISABLE_RENDER_COND
= 8,
1045 void si_blitter_begin(struct si_context
*sctx
, enum si_blitter_op op
);
1046 void si_blitter_end(struct si_context
*sctx
);
1047 void si_init_blit_functions(struct si_context
*sctx
);
1048 void si_decompress_textures(struct si_context
*sctx
, unsigned shader_mask
);
1049 void si_resource_copy_region(struct pipe_context
*ctx
,
1050 struct pipe_resource
*dst
,
1052 unsigned dstx
, unsigned dsty
, unsigned dstz
,
1053 struct pipe_resource
*src
,
1055 const struct pipe_box
*src_box
);
1056 void si_decompress_dcc(struct si_context
*sctx
, struct r600_texture
*rtex
);
1057 void si_blit_decompress_depth(struct pipe_context
*ctx
,
1058 struct r600_texture
*texture
,
1059 struct r600_texture
*staging
,
1060 unsigned first_level
, unsigned last_level
,
1061 unsigned first_layer
, unsigned last_layer
,
1062 unsigned first_sample
, unsigned last_sample
);
1065 bool si_rings_is_buffer_referenced(struct si_context
*sctx
,
1066 struct pb_buffer
*buf
,
1067 enum radeon_bo_usage usage
);
1068 void *si_buffer_map_sync_with_rings(struct si_context
*sctx
,
1069 struct r600_resource
*resource
,
1071 void si_init_resource_fields(struct si_screen
*sscreen
,
1072 struct r600_resource
*res
,
1073 uint64_t size
, unsigned alignment
);
1074 bool si_alloc_resource(struct si_screen
*sscreen
,
1075 struct r600_resource
*res
);
1076 struct pipe_resource
*pipe_aligned_buffer_create(struct pipe_screen
*screen
,
1077 unsigned flags
, unsigned usage
,
1078 unsigned size
, unsigned alignment
);
1079 struct r600_resource
*si_aligned_buffer_create(struct pipe_screen
*screen
,
1080 unsigned flags
, unsigned usage
,
1081 unsigned size
, unsigned alignment
);
1082 void si_replace_buffer_storage(struct pipe_context
*ctx
,
1083 struct pipe_resource
*dst
,
1084 struct pipe_resource
*src
);
1085 void si_init_screen_buffer_functions(struct si_screen
*sscreen
);
1086 void si_init_buffer_functions(struct si_context
*sctx
);
1089 enum pipe_format
si_simplify_cb_format(enum pipe_format format
);
1090 bool vi_alpha_is_on_msb(enum pipe_format format
);
1091 void vi_dcc_clear_level(struct si_context
*sctx
,
1092 struct r600_texture
*rtex
,
1093 unsigned level
, unsigned clear_value
);
1094 void si_init_clear_functions(struct si_context
*sctx
);
1097 #define SI_CPDMA_SKIP_CHECK_CS_SPACE (1 << 0) /* don't call need_cs_space */
1098 #define SI_CPDMA_SKIP_SYNC_AFTER (1 << 1) /* don't wait for DMA after the copy */
1099 #define SI_CPDMA_SKIP_SYNC_BEFORE (1 << 2) /* don't wait for DMA before the copy (RAW hazards) */
1100 #define SI_CPDMA_SKIP_GFX_SYNC (1 << 3) /* don't flush caches and don't wait for PS/CS */
1101 #define SI_CPDMA_SKIP_BO_LIST_UPDATE (1 << 4) /* don't update the BO list */
1102 #define SI_CPDMA_SKIP_ALL (SI_CPDMA_SKIP_CHECK_CS_SPACE | \
1103 SI_CPDMA_SKIP_SYNC_AFTER | \
1104 SI_CPDMA_SKIP_SYNC_BEFORE | \
1105 SI_CPDMA_SKIP_GFX_SYNC | \
1106 SI_CPDMA_SKIP_BO_LIST_UPDATE)
1109 SI_COHERENCY_NONE
, /* no cache flushes needed */
1110 SI_COHERENCY_SHADER
,
1111 SI_COHERENCY_CB_META
,
1114 void si_cp_dma_wait_for_idle(struct si_context
*sctx
);
1115 void si_clear_buffer(struct si_context
*sctx
, struct pipe_resource
*dst
,
1116 uint64_t offset
, uint64_t size
, unsigned value
,
1117 enum si_coherency coher
);
1118 void si_copy_buffer(struct si_context
*sctx
,
1119 struct pipe_resource
*dst
, struct pipe_resource
*src
,
1120 uint64_t dst_offset
, uint64_t src_offset
, unsigned size
,
1121 unsigned user_flags
);
1122 void cik_prefetch_TC_L2_async(struct si_context
*sctx
, struct pipe_resource
*buf
,
1123 uint64_t offset
, unsigned size
);
1124 void cik_emit_prefetch_L2(struct si_context
*sctx
, bool vertex_stage_only
);
1125 void si_init_cp_dma_functions(struct si_context
*sctx
);
1128 void si_save_cs(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
,
1129 struct radeon_saved_cs
*saved
, bool get_buffer_list
);
1130 void si_clear_saved_cs(struct radeon_saved_cs
*saved
);
1131 void si_destroy_saved_cs(struct si_saved_cs
*scs
);
1132 void si_auto_log_cs(void *data
, struct u_log_context
*log
);
1133 void si_log_hw_flush(struct si_context
*sctx
);
1134 void si_log_draw_state(struct si_context
*sctx
, struct u_log_context
*log
);
1135 void si_log_compute_state(struct si_context
*sctx
, struct u_log_context
*log
);
1136 void si_init_debug_functions(struct si_context
*sctx
);
1137 void si_check_vm_faults(struct si_context
*sctx
,
1138 struct radeon_saved_cs
*saved
, enum ring_type ring
);
1139 bool si_replace_shader(unsigned num
, struct ac_shader_binary
*binary
);
1142 void si_init_dma_functions(struct si_context
*sctx
);
1145 void si_need_dma_space(struct si_context
*ctx
, unsigned num_dw
,
1146 struct r600_resource
*dst
, struct r600_resource
*src
);
1147 void si_flush_dma_cs(struct si_context
*ctx
, unsigned flags
,
1148 struct pipe_fence_handle
**fence
);
1149 void si_screen_clear_buffer(struct si_screen
*sscreen
, struct pipe_resource
*dst
,
1150 uint64_t offset
, uint64_t size
, unsigned value
);
1153 void si_gfx_write_event_eop(struct si_context
*ctx
,
1154 unsigned event
, unsigned event_flags
,
1156 struct r600_resource
*buf
, uint64_t va
,
1157 uint32_t new_fence
, unsigned query_type
);
1158 unsigned si_gfx_write_fence_dwords(struct si_screen
*screen
);
1159 void si_gfx_wait_fence(struct si_context
*ctx
,
1160 uint64_t va
, uint32_t ref
, uint32_t mask
);
1161 void si_init_fence_functions(struct si_context
*ctx
);
1162 void si_init_screen_fence_functions(struct si_screen
*screen
);
1163 struct pipe_fence_handle
*si_create_fence(struct pipe_context
*ctx
,
1164 struct tc_unflushed_batch_token
*tc_token
);
1167 const char *si_get_family_name(const struct si_screen
*sscreen
);
1168 void si_init_screen_get_functions(struct si_screen
*sscreen
);
1171 void si_flush_gfx_cs(struct si_context
*ctx
, unsigned flags
,
1172 struct pipe_fence_handle
**fence
);
1173 void si_begin_new_gfx_cs(struct si_context
*ctx
);
1174 void si_need_gfx_cs_space(struct si_context
*ctx
);
1176 /* r600_gpu_load.c */
1177 void si_gpu_load_kill_thread(struct si_screen
*sscreen
);
1178 uint64_t si_begin_counter(struct si_screen
*sscreen
, unsigned type
);
1179 unsigned si_end_counter(struct si_screen
*sscreen
, unsigned type
,
1183 void si_init_compute_functions(struct si_context
*sctx
);
1185 /* r600_perfcounters.c */
1186 void si_perfcounters_destroy(struct si_screen
*sscreen
);
1188 /* si_perfcounters.c */
1189 void si_init_perfcounters(struct si_screen
*screen
);
1192 bool si_check_device_reset(struct si_context
*sctx
);
1195 void si_init_screen_query_functions(struct si_screen
*sscreen
);
1196 void si_init_query_functions(struct si_context
*sctx
);
1197 void si_suspend_queries(struct si_context
*sctx
);
1198 void si_resume_queries(struct si_context
*sctx
);
1201 void si_test_dma(struct si_screen
*sscreen
);
1204 struct pipe_video_codec
*si_uvd_create_decoder(struct pipe_context
*context
,
1205 const struct pipe_video_codec
*templ
);
1207 struct pipe_video_buffer
*si_video_buffer_create(struct pipe_context
*pipe
,
1208 const struct pipe_video_buffer
*tmpl
);
1211 void si_update_vs_viewport_state(struct si_context
*ctx
);
1212 void si_init_viewport_functions(struct si_context
*ctx
);
1214 /* r600_texture.c */
1215 bool si_prepare_for_dma_blit(struct si_context
*sctx
,
1216 struct r600_texture
*rdst
,
1217 unsigned dst_level
, unsigned dstx
,
1218 unsigned dsty
, unsigned dstz
,
1219 struct r600_texture
*rsrc
,
1221 const struct pipe_box
*src_box
);
1222 void si_texture_get_cmask_info(struct si_screen
*sscreen
,
1223 struct r600_texture
*rtex
,
1224 struct r600_cmask_info
*out
);
1225 void si_eliminate_fast_color_clear(struct si_context
*sctx
,
1226 struct r600_texture
*rtex
);
1227 void si_texture_discard_cmask(struct si_screen
*sscreen
,
1228 struct r600_texture
*rtex
);
1229 bool si_init_flushed_depth_texture(struct pipe_context
*ctx
,
1230 struct pipe_resource
*texture
,
1231 struct r600_texture
**staging
);
1232 void si_print_texture_info(struct si_screen
*sscreen
,
1233 struct r600_texture
*rtex
, struct u_log_context
*log
);
1234 struct pipe_resource
*si_texture_create(struct pipe_screen
*screen
,
1235 const struct pipe_resource
*templ
);
1236 bool vi_dcc_formats_compatible(enum pipe_format format1
,
1237 enum pipe_format format2
);
1238 bool vi_dcc_formats_are_incompatible(struct pipe_resource
*tex
,
1240 enum pipe_format view_format
);
1241 void vi_disable_dcc_if_incompatible_format(struct si_context
*sctx
,
1242 struct pipe_resource
*tex
,
1244 enum pipe_format view_format
);
1245 struct pipe_surface
*si_create_surface_custom(struct pipe_context
*pipe
,
1246 struct pipe_resource
*texture
,
1247 const struct pipe_surface
*templ
,
1248 unsigned width0
, unsigned height0
,
1249 unsigned width
, unsigned height
);
1250 unsigned si_translate_colorswap(enum pipe_format format
, bool do_endian_swap
);
1251 void vi_separate_dcc_try_enable(struct si_context
*sctx
,
1252 struct r600_texture
*tex
);
1253 void vi_separate_dcc_start_query(struct si_context
*sctx
,
1254 struct r600_texture
*tex
);
1255 void vi_separate_dcc_stop_query(struct si_context
*sctx
,
1256 struct r600_texture
*tex
);
1257 void vi_separate_dcc_process_and_reset_stats(struct pipe_context
*ctx
,
1258 struct r600_texture
*tex
);
1259 bool si_texture_disable_dcc(struct si_context
*sctx
,
1260 struct r600_texture
*rtex
);
1261 void si_init_screen_texture_functions(struct si_screen
*sscreen
);
1262 void si_init_context_texture_functions(struct si_context
*sctx
);
1269 static inline struct r600_resource
*r600_resource(struct pipe_resource
*r
)
1271 return (struct r600_resource
*)r
;
1275 r600_resource_reference(struct r600_resource
**ptr
, struct r600_resource
*res
)
1277 pipe_resource_reference((struct pipe_resource
**)ptr
,
1278 (struct pipe_resource
*)res
);
1282 r600_texture_reference(struct r600_texture
**ptr
, struct r600_texture
*res
)
1284 pipe_resource_reference((struct pipe_resource
**)ptr
, &res
->buffer
.b
.b
);
1288 vi_dcc_enabled(struct r600_texture
*tex
, unsigned level
)
1290 return tex
->dcc_offset
&& level
< tex
->surface
.num_dcc_levels
;
1293 static inline unsigned
1294 si_tile_mode_index(struct r600_texture
*rtex
, unsigned level
, bool stencil
)
1297 return rtex
->surface
.u
.legacy
.stencil_tiling_index
[level
];
1299 return rtex
->surface
.u
.legacy
.tiling_index
[level
];
1303 si_context_add_resource_size(struct si_context
*sctx
, struct pipe_resource
*r
)
1306 /* Add memory usage for need_gfx_cs_space */
1307 sctx
->vram
+= r600_resource(r
)->vram_usage
;
1308 sctx
->gtt
+= r600_resource(r
)->gart_usage
;
1313 si_invalidate_draw_sh_constants(struct si_context
*sctx
)
1315 sctx
->last_base_vertex
= SI_BASE_VERTEX_UNKNOWN
;
1318 static inline unsigned
1319 si_get_atom_bit(struct si_context
*sctx
, struct si_atom
*atom
)
1321 return 1 << (atom
- sctx
->atoms
.array
);
1325 si_set_atom_dirty(struct si_context
*sctx
, struct si_atom
*atom
, bool dirty
)
1327 unsigned bit
= si_get_atom_bit(sctx
, atom
);
1330 sctx
->dirty_atoms
|= bit
;
1332 sctx
->dirty_atoms
&= ~bit
;
1336 si_is_atom_dirty(struct si_context
*sctx
, struct si_atom
*atom
)
1338 return (sctx
->dirty_atoms
& si_get_atom_bit(sctx
, atom
)) != 0;
1342 si_mark_atom_dirty(struct si_context
*sctx
, struct si_atom
*atom
)
1344 si_set_atom_dirty(sctx
, atom
, true);
1347 static inline struct si_shader_ctx_state
*si_get_vs(struct si_context
*sctx
)
1349 if (sctx
->gs_shader
.cso
)
1350 return &sctx
->gs_shader
;
1351 if (sctx
->tes_shader
.cso
)
1352 return &sctx
->tes_shader
;
1354 return &sctx
->vs_shader
;
1357 static inline struct tgsi_shader_info
*si_get_vs_info(struct si_context
*sctx
)
1359 struct si_shader_ctx_state
*vs
= si_get_vs(sctx
);
1361 return vs
->cso
? &vs
->cso
->info
: NULL
;
1364 static inline struct si_shader
* si_get_vs_state(struct si_context
*sctx
)
1366 if (sctx
->gs_shader
.cso
)
1367 return sctx
->gs_shader
.cso
->gs_copy_shader
;
1369 struct si_shader_ctx_state
*vs
= si_get_vs(sctx
);
1370 return vs
->current
? vs
->current
: NULL
;
1373 static inline bool si_can_dump_shader(struct si_screen
*sscreen
,
1376 return sscreen
->debug_flags
& (1 << processor
);
1379 static inline bool si_get_strmout_en(struct si_context
*sctx
)
1381 return sctx
->streamout
.streamout_enabled
||
1382 sctx
->streamout
.prims_gen_query_enabled
;
1385 static inline unsigned
1386 si_optimal_tcc_alignment(struct si_context
*sctx
, unsigned upload_size
)
1388 unsigned alignment
, tcc_cache_line_size
;
1390 /* If the upload size is less than the cache line size (e.g. 16, 32),
1391 * the whole thing will fit into a cache line if we align it to its size.
1392 * The idea is that multiple small uploads can share a cache line.
1393 * If the upload size is greater, align it to the cache line size.
1395 alignment
= util_next_power_of_two(upload_size
);
1396 tcc_cache_line_size
= sctx
->screen
->info
.tcc_cache_line_size
;
1397 return MIN2(alignment
, tcc_cache_line_size
);
1401 si_saved_cs_reference(struct si_saved_cs
**dst
, struct si_saved_cs
*src
)
1403 if (pipe_reference(&(*dst
)->reference
, &src
->reference
))
1404 si_destroy_saved_cs(*dst
);
1410 si_make_CB_shader_coherent(struct si_context
*sctx
, unsigned num_samples
,
1411 bool shaders_read_metadata
)
1413 sctx
->flags
|= SI_CONTEXT_FLUSH_AND_INV_CB
|
1414 SI_CONTEXT_INV_VMEM_L1
;
1416 if (sctx
->chip_class
>= GFX9
) {
1417 /* Single-sample color is coherent with shaders on GFX9, but
1418 * L2 metadata must be flushed if shaders read metadata.
1421 if (num_samples
>= 2)
1422 sctx
->flags
|= SI_CONTEXT_INV_GLOBAL_L2
;
1423 else if (shaders_read_metadata
)
1424 sctx
->flags
|= SI_CONTEXT_INV_L2_METADATA
;
1427 sctx
->flags
|= SI_CONTEXT_INV_GLOBAL_L2
;
1432 si_make_DB_shader_coherent(struct si_context
*sctx
, unsigned num_samples
,
1433 bool include_stencil
, bool shaders_read_metadata
)
1435 sctx
->flags
|= SI_CONTEXT_FLUSH_AND_INV_DB
|
1436 SI_CONTEXT_INV_VMEM_L1
;
1438 if (sctx
->chip_class
>= GFX9
) {
1439 /* Single-sample depth (not stencil) is coherent with shaders
1440 * on GFX9, but L2 metadata must be flushed if shaders read
1443 if (num_samples
>= 2 || include_stencil
)
1444 sctx
->flags
|= SI_CONTEXT_INV_GLOBAL_L2
;
1445 else if (shaders_read_metadata
)
1446 sctx
->flags
|= SI_CONTEXT_INV_L2_METADATA
;
1449 sctx
->flags
|= SI_CONTEXT_INV_GLOBAL_L2
;
1454 si_can_sample_zs(struct r600_texture
*tex
, bool stencil_sampler
)
1456 return (stencil_sampler
&& tex
->can_sample_s
) ||
1457 (!stencil_sampler
&& tex
->can_sample_z
);
1461 si_htile_enabled(struct r600_texture
*tex
, unsigned level
)
1463 return tex
->htile_offset
&& level
== 0;
1467 vi_tc_compat_htile_enabled(struct r600_texture
*tex
, unsigned level
)
1469 assert(!tex
->tc_compatible_htile
|| tex
->htile_offset
);
1470 return tex
->tc_compatible_htile
&& level
== 0;
1473 static inline unsigned si_get_ps_iter_samples(struct si_context
*sctx
)
1475 if (sctx
->ps_uses_fbfetch
)
1476 return sctx
->framebuffer
.nr_samples
;
1478 return sctx
->ps_iter_samples
;
1481 static inline unsigned si_get_total_colormask(struct si_context
*sctx
)
1483 if (sctx
->queued
.named
.rasterizer
->rasterizer_discard
)
1486 struct si_shader_selector
*ps
= sctx
->ps_shader
.cso
;
1490 unsigned colormask
= sctx
->framebuffer
.colorbuf_enabled_4bit
&
1491 sctx
->queued
.named
.blend
->cb_target_mask
;
1493 if (!ps
->info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
])
1494 colormask
&= ps
->colors_written_4bit
;
1495 else if (!ps
->colors_written_4bit
)
1496 colormask
= 0; /* color0 writes all cbufs, but it's not written */
1502 * Return true if there is enough memory in VRAM and GTT for the buffers
1505 * \param vram VRAM memory size not added to the buffer list yet
1506 * \param gtt GTT memory size not added to the buffer list yet
1509 radeon_cs_memory_below_limit(struct si_screen
*screen
,
1510 struct radeon_winsys_cs
*cs
,
1511 uint64_t vram
, uint64_t gtt
)
1513 vram
+= cs
->used_vram
;
1514 gtt
+= cs
->used_gart
;
1516 /* Anything that goes above the VRAM size should go to GTT. */
1517 if (vram
> screen
->info
.vram_size
)
1518 gtt
+= vram
- screen
->info
.vram_size
;
1520 /* Now we just need to check if we have enough GTT. */
1521 return gtt
< screen
->info
.gart_size
* 0.7;
1525 * Add a buffer to the buffer list for the given command stream (CS).
1527 * All buffers used by a CS must be added to the list. This tells the kernel
1528 * driver which buffers are used by GPU commands. Other buffers can
1529 * be swapped out (not accessible) during execution.
1531 * The buffer list becomes empty after every context flush and must be
1534 static inline void radeon_add_to_buffer_list(struct si_context
*sctx
,
1535 struct radeon_winsys_cs
*cs
,
1536 struct r600_resource
*rbo
,
1537 enum radeon_bo_usage usage
,
1538 enum radeon_bo_priority priority
)
1541 sctx
->ws
->cs_add_buffer(
1543 (enum radeon_bo_usage
)(usage
| RADEON_USAGE_SYNCHRONIZED
),
1544 rbo
->domains
, priority
);
1548 * Same as above, but also checks memory usage and flushes the context
1551 * When this SHOULD NOT be used:
1553 * - if si_context_add_resource_size has been called for the buffer
1554 * followed by *_need_cs_space for checking the memory usage
1556 * - if si_need_dma_space has been called for the buffer
1558 * - when emitting state packets and draw packets (because preceding packets
1559 * can't be re-emitted at that point)
1561 * - if shader resource "enabled_mask" is not up-to-date or there is
1562 * a different constraint disallowing a context flush
1565 radeon_add_to_gfx_buffer_list_check_mem(struct si_context
*sctx
,
1566 struct r600_resource
*rbo
,
1567 enum radeon_bo_usage usage
,
1568 enum radeon_bo_priority priority
,
1572 !radeon_cs_memory_below_limit(sctx
->screen
, sctx
->gfx_cs
,
1573 sctx
->vram
+ rbo
->vram_usage
,
1574 sctx
->gtt
+ rbo
->gart_usage
))
1575 si_flush_gfx_cs(sctx
, RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW
, NULL
);
1577 radeon_add_to_buffer_list(sctx
, sctx
->gfx_cs
, rbo
, usage
, priority
);
1580 #define PRINT_ERR(fmt, args...) \
1581 fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)