1af69d88dSmrg/* 2af69d88dSmrg * Copyright 2010 Jerome Glisse <glisse@freedesktop.org> 301e04c3fSmrg * Copyright 2018 Advanced Micro Devices, Inc. 401e04c3fSmrg * All Rights Reserved. 5af69d88dSmrg * 6af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 7af69d88dSmrg * copy of this software and associated documentation files (the "Software"), 8af69d88dSmrg * to deal in the Software without restriction, including without limitation 9af69d88dSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub 10af69d88dSmrg * license, and/or sell copies of the Software, and to permit persons to whom 11af69d88dSmrg * the Software is furnished to do so, subject to the following conditions: 12af69d88dSmrg * 13af69d88dSmrg * The above copyright notice and this permission notice (including the next 14af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the 15af69d88dSmrg * Software. 16af69d88dSmrg * 17af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20af69d88dSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 21af69d88dSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22af69d88dSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 23af69d88dSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 24af69d88dSmrg */ 25af69d88dSmrg#ifndef SI_PIPE_H 26af69d88dSmrg#define SI_PIPE_H 27af69d88dSmrg 2801e04c3fSmrg#include "si_shader.h" 29af69d88dSmrg#include "si_state.h" 3001e04c3fSmrg#include "util/u_dynarray.h" 3101e04c3fSmrg#include "util/u_idalloc.h" 327ec681f3Smrg#include "util/u_suballoc.h" 3301e04c3fSmrg#include "util/u_threaded_context.h" 347ec681f3Smrg#include "util/u_vertex_state_cache.h" 357ec681f3Smrg#include "ac_sqtt.h" 367ec681f3Smrg 377ec681f3Smrg#ifdef __cplusplus 387ec681f3Smrgextern "C" { 397ec681f3Smrg#endif 4001e04c3fSmrg 417ec681f3Smrg#if UTIL_ARCH_BIG_ENDIAN 42af69d88dSmrg#define SI_BIG_ENDIAN 1 43af69d88dSmrg#else 44af69d88dSmrg#define SI_BIG_ENDIAN 0 45af69d88dSmrg#endif 46af69d88dSmrg 477ec681f3Smrg#define ATI_VENDOR_ID 0x1002 487ec681f3Smrg#define SI_NOT_QUERY 0xffffffff 4901e04c3fSmrg 5001e04c3fSmrg/* The base vertex and primitive restart can be any number, but we must pick 5101e04c3fSmrg * one which will mean "unknown" for the purpose of state tracking and 5201e04c3fSmrg * the number shouldn't be a commonly-used one. */ 537ec681f3Smrg#define SI_BASE_VERTEX_UNKNOWN INT_MIN 547ec681f3Smrg#define SI_START_INSTANCE_UNKNOWN ((unsigned)INT_MIN) 557ec681f3Smrg#define SI_DRAW_ID_UNKNOWN ((unsigned)INT_MIN) 567ec681f3Smrg#define SI_RESTART_INDEX_UNKNOWN ((unsigned)INT_MIN) 577ec681f3Smrg#define SI_INSTANCE_COUNT_UNKNOWN ((unsigned)INT_MIN) 587ec681f3Smrg#define SI_NUM_SMOOTH_AA_SAMPLES 4 597ec681f3Smrg#define SI_MAX_POINT_SIZE 2048 607ec681f3Smrg#define SI_GS_PER_ES 128 6101e04c3fSmrg/* Alignment for optimal CP DMA performance. */ 627ec681f3Smrg#define SI_CPDMA_ALIGNMENT 32 6301e04c3fSmrg 6401e04c3fSmrg/* Tunables for compute-based clear_buffer and copy_buffer: */ 657ec681f3Smrg#define SI_COMPUTE_CLEAR_DW_PER_THREAD 4 667ec681f3Smrg#define SI_COMPUTE_COPY_DW_PER_THREAD 4 677ec681f3Smrg/* L2 LRU is recommended because the compute shader can finish sooner due to fewer L2 evictions. */ 687ec681f3Smrg#define SI_COMPUTE_DST_CACHE_POLICY L2_LRU 6901e04c3fSmrg 7001e04c3fSmrg/* Pipeline & streamout query controls. */ 717ec681f3Smrg#define SI_CONTEXT_START_PIPELINE_STATS (1 << 0) 727ec681f3Smrg#define SI_CONTEXT_STOP_PIPELINE_STATS (1 << 1) 7301e04c3fSmrg#define SI_CONTEXT_FLUSH_FOR_RENDER_COND (1 << 2) 7401e04c3fSmrg/* Instruction cache. */ 757ec681f3Smrg#define SI_CONTEXT_INV_ICACHE (1 << 3) 767ec681f3Smrg/* Scalar cache. (GFX6-9: scalar L1; GFX10: scalar L0) 777ec681f3Smrg * GFX10: This also invalidates the L1 shader array cache. */ 787ec681f3Smrg#define SI_CONTEXT_INV_SCACHE (1 << 4) 797ec681f3Smrg/* Vector cache. (GFX6-9: vector L1; GFX10: vector L0) 807ec681f3Smrg * GFX10: This also invalidates the L1 shader array cache. */ 817ec681f3Smrg#define SI_CONTEXT_INV_VCACHE (1 << 5) 827ec681f3Smrg/* L2 cache + L2 metadata cache writeback & invalidate. 837ec681f3Smrg * GFX6-8: Used by shaders only. GFX9-10: Used by everything. */ 847ec681f3Smrg#define SI_CONTEXT_INV_L2 (1 << 6) 857ec681f3Smrg/* L2 writeback (write dirty L2 lines to memory for non-L2 clients). 867ec681f3Smrg * Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8. 877ec681f3Smrg * GFX6-7 will do complete invalidation, because the writeback is unsupported. */ 887ec681f3Smrg#define SI_CONTEXT_WB_L2 (1 << 7) 897ec681f3Smrg/* Writeback & invalidate the L2 metadata cache only. It can only be coupled with 9001e04c3fSmrg * a CB or DB flush. */ 917ec681f3Smrg#define SI_CONTEXT_INV_L2_METADATA (1 << 8) 9201e04c3fSmrg/* Framebuffer caches. */ 937ec681f3Smrg#define SI_CONTEXT_FLUSH_AND_INV_DB (1 << 9) 9401e04c3fSmrg#define SI_CONTEXT_FLUSH_AND_INV_DB_META (1 << 10) 957ec681f3Smrg#define SI_CONTEXT_FLUSH_AND_INV_CB (1 << 11) 9601e04c3fSmrg/* Engine synchronization. */ 977ec681f3Smrg#define SI_CONTEXT_VS_PARTIAL_FLUSH (1 << 12) 987ec681f3Smrg#define SI_CONTEXT_PS_PARTIAL_FLUSH (1 << 13) 997ec681f3Smrg#define SI_CONTEXT_CS_PARTIAL_FLUSH (1 << 14) 1007ec681f3Smrg#define SI_CONTEXT_VGT_FLUSH (1 << 15) 1017ec681f3Smrg#define SI_CONTEXT_VGT_STREAMOUT_SYNC (1 << 16) 1027ec681f3Smrg/* PFP waits for ME to finish. Used to sync for index and indirect buffers and render 1037ec681f3Smrg * condition. It's typically set when doing a VS/PS/CS partial flush for buffers. */ 1047ec681f3Smrg#define SI_CONTEXT_PFP_SYNC_ME (1 << 17) 1057ec681f3Smrg 1067ec681f3Smrg#define SI_PREFETCH_LS (1 << 1) 1077ec681f3Smrg#define SI_PREFETCH_HS (1 << 2) 1087ec681f3Smrg#define SI_PREFETCH_ES (1 << 3) 1097ec681f3Smrg#define SI_PREFETCH_GS (1 << 4) 1107ec681f3Smrg#define SI_PREFETCH_VS (1 << 5) 1117ec681f3Smrg#define SI_PREFETCH_PS (1 << 6) 1127ec681f3Smrg 1137ec681f3Smrg#define SI_MAX_BORDER_COLORS 4096 1147ec681f3Smrg#define SI_MAX_VIEWPORTS 16 1157ec681f3Smrg#define SIX_BITS 0x3F 1167ec681f3Smrg#define SI_MAP_BUFFER_ALIGNMENT 64 1177ec681f3Smrg/* We only support the minimum allowed value (512), so that we can pack a 3D block size 1187ec681f3Smrg * in 1 SGPR. */ 1197ec681f3Smrg#define SI_MAX_VARIABLE_THREADS_PER_BLOCK 512 1207ec681f3Smrg 1217ec681f3Smrg#define SI_CONTEXT_FLAG_AUX (1u << 31) 1227ec681f3Smrg 1237ec681f3Smrg#define SI_RESOURCE_FLAG_FORCE_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) 1247ec681f3Smrg#define SI_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1) 1259f464c52Smaya#define SI_RESOURCE_FLAG_FORCE_MSAA_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2) 1267ec681f3Smrg#define SI_RESOURCE_FLAG_DISABLE_DCC (PIPE_RESOURCE_FLAG_DRV_PRIV << 3) 1277ec681f3Smrg#define SI_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4) 1287ec681f3Smrg#define SI_RESOURCE_FLAG_READ_ONLY (PIPE_RESOURCE_FLAG_DRV_PRIV << 5) 1297ec681f3Smrg#define SI_RESOURCE_FLAG_32BIT (PIPE_RESOURCE_FLAG_DRV_PRIV << 6) 1307ec681f3Smrg#define SI_RESOURCE_FLAG_CLEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 7) 1317ec681f3Smrg/* gap */ 1327ec681f3Smrg/* Set a micro tile mode: */ 1337ec681f3Smrg#define SI_RESOURCE_FLAG_FORCE_MICRO_TILE_MODE (PIPE_RESOURCE_FLAG_DRV_PRIV << 9) 1347ec681f3Smrg#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT (util_logbase2(PIPE_RESOURCE_FLAG_DRV_PRIV) + 10) 1357ec681f3Smrg#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_SET(x) \ 1367ec681f3Smrg (((x)&0x3) << SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT) 1377ec681f3Smrg#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_GET(x) \ 1387ec681f3Smrg (((x) >> SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT) & 0x3) 1397ec681f3Smrg#define SI_RESOURCE_FLAG_UNCACHED (PIPE_RESOURCE_FLAG_DRV_PRIV << 12) 1407ec681f3Smrg#define SI_RESOURCE_FLAG_DRIVER_INTERNAL (PIPE_RESOURCE_FLAG_DRV_PRIV << 13) 1417ec681f3Smrg#define SI_RESOURCE_AUX_PLANE (PIPE_RESOURCE_FLAG_DRV_PRIV << 14) 1427ec681f3Smrg 1437ec681f3Smrgenum si_has_gs { 1447ec681f3Smrg GS_OFF, 1457ec681f3Smrg GS_ON, 1467ec681f3Smrg}; 1477ec681f3Smrg 1487ec681f3Smrgenum si_has_tess { 1497ec681f3Smrg TESS_OFF, 1507ec681f3Smrg TESS_ON, 1517ec681f3Smrg}; 1527ec681f3Smrg 1537ec681f3Smrgenum si_has_ngg { 1547ec681f3Smrg NGG_OFF, 1557ec681f3Smrg NGG_ON, 1567ec681f3Smrg}; 1579f464c52Smaya 1589f464c52Smayaenum si_clear_code 1599f464c52Smaya{ 1607ec681f3Smrg DCC_CLEAR_COLOR_0000 = 0x00000000, 1617ec681f3Smrg DCC_CLEAR_COLOR_0001 = 0x40404040, 1627ec681f3Smrg DCC_CLEAR_COLOR_1110 = 0x80808080, 1637ec681f3Smrg DCC_CLEAR_COLOR_1111 = 0xC0C0C0C0, 1647ec681f3Smrg DCC_CLEAR_COLOR_REG = 0x20202020, 1657ec681f3Smrg DCC_UNCOMPRESSED = 0xFFFFFFFF, 1669f464c52Smaya}; 1679f464c52Smaya 1687ec681f3Smrg#define SI_IMAGE_ACCESS_DCC_OFF (1 << 8) 1697ec681f3Smrg#define SI_IMAGE_ACCESS_ALLOW_DCC_STORE (1 << 9) 17001e04c3fSmrg 17101e04c3fSmrg/* Debug flags. */ 1727ec681f3Smrgenum 1737ec681f3Smrg{ 1747ec681f3Smrg /* Shader logging options: */ 1757ec681f3Smrg DBG_VS = MESA_SHADER_VERTEX, 1767ec681f3Smrg DBG_TCS = MESA_SHADER_TESS_CTRL, 1777ec681f3Smrg DBG_TES = MESA_SHADER_TESS_EVAL, 1787ec681f3Smrg DBG_GS = MESA_SHADER_GEOMETRY, 1797ec681f3Smrg DBG_PS = MESA_SHADER_FRAGMENT, 1807ec681f3Smrg DBG_CS = MESA_SHADER_COMPUTE, 1817ec681f3Smrg DBG_NO_IR, 1827ec681f3Smrg DBG_NO_NIR, 1837ec681f3Smrg DBG_NO_ASM, 1847ec681f3Smrg DBG_PREOPT_IR, 1857ec681f3Smrg 1867ec681f3Smrg /* Shader compiler options the shader cache should be aware of: */ 1877ec681f3Smrg DBG_FS_CORRECT_DERIVS_AFTER_KILL, 1887ec681f3Smrg DBG_GISEL, 1897ec681f3Smrg DBG_W32_GE, 1907ec681f3Smrg DBG_W32_PS, 1917ec681f3Smrg DBG_W32_CS, 1927ec681f3Smrg DBG_W64_GE, 1937ec681f3Smrg DBG_W64_PS, 1947ec681f3Smrg DBG_W64_CS, 1957ec681f3Smrg 1967ec681f3Smrg /* Shader compiler options (with no effect on the shader cache): */ 1977ec681f3Smrg DBG_CHECK_IR, 1987ec681f3Smrg DBG_MONOLITHIC_SHADERS, 1997ec681f3Smrg DBG_NO_OPT_VARIANT, 2007ec681f3Smrg 2017ec681f3Smrg /* Information logging options: */ 2027ec681f3Smrg DBG_INFO, 2037ec681f3Smrg DBG_TEX, 2047ec681f3Smrg DBG_COMPUTE, 2057ec681f3Smrg DBG_VM, 2067ec681f3Smrg DBG_CACHE_STATS, 2077ec681f3Smrg DBG_IB, 2087ec681f3Smrg 2097ec681f3Smrg /* Driver options: */ 2107ec681f3Smrg DBG_NO_WC, 2117ec681f3Smrg DBG_CHECK_VM, 2127ec681f3Smrg DBG_RESERVE_VMID, 2137ec681f3Smrg DBG_SHADOW_REGS, 2147ec681f3Smrg DBG_NO_FAST_DISPLAY_LIST, 2157ec681f3Smrg 2167ec681f3Smrg /* 3D engine options: */ 2177ec681f3Smrg DBG_NO_GFX, 2187ec681f3Smrg DBG_NO_NGG, 2197ec681f3Smrg DBG_ALWAYS_NGG_CULLING_ALL, 2207ec681f3Smrg DBG_ALWAYS_NGG_CULLING_TESS, 2217ec681f3Smrg DBG_NO_NGG_CULLING, 2227ec681f3Smrg DBG_SWITCH_ON_EOP, 2237ec681f3Smrg DBG_NO_OUT_OF_ORDER, 2247ec681f3Smrg DBG_NO_DPBB, 2257ec681f3Smrg DBG_DPBB, 2267ec681f3Smrg DBG_NO_HYPERZ, 2277ec681f3Smrg DBG_NO_2D_TILING, 2287ec681f3Smrg DBG_NO_TILING, 2297ec681f3Smrg DBG_NO_DISPLAY_TILING, 2307ec681f3Smrg DBG_NO_DISPLAY_DCC, 2317ec681f3Smrg DBG_NO_DCC, 2327ec681f3Smrg DBG_NO_DCC_CLEAR, 2337ec681f3Smrg DBG_NO_DCC_STORE, 2347ec681f3Smrg DBG_DCC_STORE, 2357ec681f3Smrg DBG_NO_DCC_MSAA, 2367ec681f3Smrg DBG_NO_FMASK, 2377ec681f3Smrg DBG_NO_DMA, 2387ec681f3Smrg 2397ec681f3Smrg DBG_TMZ, 2407ec681f3Smrg DBG_SQTT, 2417ec681f3Smrg 2427ec681f3Smrg DBG_COUNT 2437ec681f3Smrg}; 2447ec681f3Smrg 2457ec681f3Smrgenum 2467ec681f3Smrg{ 2477ec681f3Smrg /* Tests: */ 2487ec681f3Smrg DBG_TEST_BLIT, 2497ec681f3Smrg DBG_TEST_VMFAULT_CP, 2507ec681f3Smrg DBG_TEST_VMFAULT_SHADER, 2517ec681f3Smrg DBG_TEST_DMA_PERF, 2527ec681f3Smrg DBG_TEST_GDS, 2537ec681f3Smrg DBG_TEST_GDS_MM, 2547ec681f3Smrg DBG_TEST_GDS_OA_MM, 25501e04c3fSmrg}; 25601e04c3fSmrg 2577ec681f3Smrg#define DBG_ALL_SHADERS (((1 << (DBG_CS + 1)) - 1)) 2587ec681f3Smrg#define DBG(name) (1ull << DBG_##name) 25901e04c3fSmrg 2607ec681f3Smrgenum si_cache_policy 2617ec681f3Smrg{ 2627ec681f3Smrg L2_BYPASS, 2637ec681f3Smrg L2_STREAM, /* same as SLC=1 */ 2647ec681f3Smrg L2_LRU, /* same as SLC=0 */ 26501e04c3fSmrg}; 26601e04c3fSmrg 2677ec681f3Smrgenum si_coherency 2687ec681f3Smrg{ 2697ec681f3Smrg SI_COHERENCY_NONE, /* no cache flushes needed */ 2707ec681f3Smrg SI_COHERENCY_SHADER, 2717ec681f3Smrg SI_COHERENCY_CB_META, 2727ec681f3Smrg SI_COHERENCY_DB_META, 2737ec681f3Smrg SI_COHERENCY_CP, 27401e04c3fSmrg}; 27501e04c3fSmrg 27601e04c3fSmrgstruct si_compute; 2777ec681f3Smrgstruct si_shader_context; 27801e04c3fSmrgstruct hash_table; 27901e04c3fSmrg 28001e04c3fSmrg/* Only 32-bit buffer allocations are supported, gallium doesn't support more 28101e04c3fSmrg * at the moment. 28201e04c3fSmrg */ 2839f464c52Smayastruct si_resource { 2847ec681f3Smrg struct threaded_resource b; 2857ec681f3Smrg 2867ec681f3Smrg /* Winsys objects. */ 2877ec681f3Smrg struct pb_buffer *buf; 2887ec681f3Smrg uint64_t gpu_address; 2897ec681f3Smrg /* Memory usage if the buffer placement is optimal. */ 2907ec681f3Smrg uint32_t memory_usage_kb; 2917ec681f3Smrg 2927ec681f3Smrg /* Resource properties. */ 2937ec681f3Smrg uint64_t bo_size; 2947ec681f3Smrg uint8_t bo_alignment_log2; 2957ec681f3Smrg enum radeon_bo_domain domains:8; 2967ec681f3Smrg enum radeon_bo_flag flags:16; 2977ec681f3Smrg unsigned bind_history; 2987ec681f3Smrg 2997ec681f3Smrg /* The buffer range which is initialized (with a write transfer, 3007ec681f3Smrg * streamout, DMA, or as a random access target). The rest of 3017ec681f3Smrg * the buffer is considered invalid and can be mapped unsynchronized. 3027ec681f3Smrg * 3037ec681f3Smrg * This allows unsynchronized mapping of a buffer range which hasn't 3047ec681f3Smrg * been used yet. It's for applications which forget to use 3057ec681f3Smrg * the unsynchronized map flag and expect the driver to figure it out. 3067ec681f3Smrg */ 3077ec681f3Smrg struct util_range valid_buffer_range; 3087ec681f3Smrg 3097ec681f3Smrg /* For buffers only. This indicates that a write operation has been 3107ec681f3Smrg * performed by TC L2, but the cache hasn't been flushed. 3117ec681f3Smrg * Any hw block which doesn't use or bypasses TC L2 should check this 3127ec681f3Smrg * flag and flush the cache before using the buffer. 3137ec681f3Smrg * 3147ec681f3Smrg * For example, TC L2 must be flushed if a buffer which has been 3157ec681f3Smrg * modified by a shader store instruction is about to be used as 3167ec681f3Smrg * an index buffer. The reason is that VGT DMA index fetching doesn't 3177ec681f3Smrg * use TC L2. 3187ec681f3Smrg */ 3197ec681f3Smrg bool TC_L2_dirty; 3207ec681f3Smrg 3217ec681f3Smrg /* Whether this resource is referenced by bindless handles. */ 3227ec681f3Smrg bool texture_handle_allocated; 3237ec681f3Smrg bool image_handle_allocated; 3247ec681f3Smrg 3257ec681f3Smrg /* Whether the resource has been exported via resource_get_handle. */ 3267ec681f3Smrg uint8_t external_usage; /* PIPE_HANDLE_USAGE_* */ 32701e04c3fSmrg}; 32801e04c3fSmrg 32901e04c3fSmrgstruct si_transfer { 3307ec681f3Smrg struct threaded_transfer b; 3317ec681f3Smrg struct si_resource *staging; 33201e04c3fSmrg}; 33301e04c3fSmrg 33401e04c3fSmrgstruct si_texture { 3357ec681f3Smrg struct si_resource buffer; 3367ec681f3Smrg 3377ec681f3Smrg struct radeon_surf surface; 3387ec681f3Smrg struct si_texture *flushed_depth_texture; 3397ec681f3Smrg 3407ec681f3Smrg /* One texture allocation can contain these buffers: 3417ec681f3Smrg * - image (pixel data) 3427ec681f3Smrg * - FMASK buffer (MSAA compression) 3437ec681f3Smrg * - CMASK buffer (MSAA compression and/or legacy fast color clear) 3447ec681f3Smrg * - HTILE buffer (Z/S compression and fast Z/S clear) 3457ec681f3Smrg * - DCC buffer (color compression and new fast color clear) 3467ec681f3Smrg * - displayable DCC buffer (if the DCC buffer is not displayable) 3477ec681f3Smrg */ 3487ec681f3Smrg uint64_t cmask_base_address_reg; 3497ec681f3Smrg struct si_resource *cmask_buffer; 3507ec681f3Smrg unsigned cb_color_info; /* fast clear enable bit */ 3517ec681f3Smrg unsigned color_clear_value[2]; 3527ec681f3Smrg unsigned last_msaa_resolve_target_micro_mode; 3537ec681f3Smrg bool swap_rgb_to_bgr_on_next_clear; 3547ec681f3Smrg bool swap_rgb_to_bgr; 3557ec681f3Smrg unsigned num_level0_transfers; 3567ec681f3Smrg unsigned plane_index; /* other planes are different pipe_resources */ 3577ec681f3Smrg unsigned num_planes; 3587ec681f3Smrg 3597ec681f3Smrg /* Depth buffer compression and fast clear. */ 3607ec681f3Smrg float depth_clear_value[RADEON_SURF_MAX_LEVELS]; 3617ec681f3Smrg uint8_t stencil_clear_value[RADEON_SURF_MAX_LEVELS]; 3627ec681f3Smrg uint16_t depth_cleared_level_mask_once; /* if it was cleared at least once */ 3637ec681f3Smrg uint16_t depth_cleared_level_mask; /* track if it's cleared (can be false negative) */ 3647ec681f3Smrg uint16_t stencil_cleared_level_mask; /* if it was cleared at least once */ 3657ec681f3Smrg uint16_t dirty_level_mask; /* each bit says if that mipmap is compressed */ 3667ec681f3Smrg uint16_t stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */ 3677ec681f3Smrg enum pipe_format db_render_format : 16; 3687ec681f3Smrg bool fmask_is_identity : 1; 3697ec681f3Smrg bool tc_compatible_htile : 1; 3707ec681f3Smrg bool enable_tc_compatible_htile_next_clear : 1; 3717ec681f3Smrg bool htile_stencil_disabled : 1; 3727ec681f3Smrg bool upgraded_depth : 1; /* upgraded from unorm to Z32_FLOAT */ 3737ec681f3Smrg bool is_depth : 1; 3747ec681f3Smrg bool db_compatible : 1; 3757ec681f3Smrg bool can_sample_z : 1; 3767ec681f3Smrg bool can_sample_s : 1; 3777ec681f3Smrg bool need_flush_after_depth_decompression: 1; 3787ec681f3Smrg 3797ec681f3Smrg /* We need to track DCC dirtiness, because st/dri usually calls 3807ec681f3Smrg * flush_resource twice per frame (not a bug) and we don't wanna 3817ec681f3Smrg * decompress DCC twice. 3827ec681f3Smrg */ 3837ec681f3Smrg bool displayable_dcc_dirty : 1; 3847ec681f3Smrg 3857ec681f3Smrg /* Counter that should be non-zero if the texture is bound to a 3867ec681f3Smrg * framebuffer. 3877ec681f3Smrg */ 3887ec681f3Smrg unsigned framebuffers_bound; 3897ec681f3Smrg}; 3907ec681f3Smrg 3917ec681f3Smrg/* State trackers create separate textures in a next-chain for extra planes 3927ec681f3Smrg * even if those are planes created purely for modifiers. Because the linking 3937ec681f3Smrg * of the chain happens outside of the driver, and NULL is interpreted as 3947ec681f3Smrg * failure, let's create some dummy texture structs. We could use these 3957ec681f3Smrg * later to use the offsets for linking if we really wanted to. 3967ec681f3Smrg * 3977ec681f3Smrg * For now just create a dummy struct and completely ignore it. 3987ec681f3Smrg * 3997ec681f3Smrg * Potentially in the future we could store stride/offset and use it during 4007ec681f3Smrg * creation, though we might want to change how linking is done first. 4017ec681f3Smrg */ 4027ec681f3Smrgstruct si_auxiliary_texture { 4037ec681f3Smrg struct threaded_resource b; 4047ec681f3Smrg struct pb_buffer *buffer; 4057ec681f3Smrg uint32_t offset; 4067ec681f3Smrg uint32_t stride; 40701e04c3fSmrg}; 40801e04c3fSmrg 40901e04c3fSmrgstruct si_surface { 4107ec681f3Smrg struct pipe_surface base; 4117ec681f3Smrg 4127ec681f3Smrg /* These can vary with block-compressed textures. */ 4137ec681f3Smrg uint16_t width0; 4147ec681f3Smrg uint16_t height0; 4157ec681f3Smrg 4167ec681f3Smrg bool color_initialized : 1; 4177ec681f3Smrg bool depth_initialized : 1; 4187ec681f3Smrg 4197ec681f3Smrg /* Misc. color flags. */ 4207ec681f3Smrg bool color_is_int8 : 1; 4217ec681f3Smrg bool color_is_int10 : 1; 4227ec681f3Smrg bool dcc_incompatible : 1; 4237ec681f3Smrg 4247ec681f3Smrg /* Color registers. */ 4257ec681f3Smrg unsigned cb_color_info; 4267ec681f3Smrg unsigned cb_color_view; 4277ec681f3Smrg unsigned cb_color_attrib; 4287ec681f3Smrg unsigned cb_color_attrib2; /* GFX9 and later */ 4297ec681f3Smrg unsigned cb_color_attrib3; /* GFX10 and later */ 4307ec681f3Smrg unsigned cb_dcc_control; /* GFX8 and later */ 4317ec681f3Smrg unsigned spi_shader_col_format : 8; /* no blending, no alpha-to-coverage. */ 4327ec681f3Smrg unsigned spi_shader_col_format_alpha : 8; /* alpha-to-coverage */ 4337ec681f3Smrg unsigned spi_shader_col_format_blend : 8; /* blending without alpha. */ 4347ec681f3Smrg unsigned spi_shader_col_format_blend_alpha : 8; /* blending with alpha. */ 4357ec681f3Smrg 4367ec681f3Smrg /* DB registers. */ 4377ec681f3Smrg uint64_t db_depth_base; /* DB_Z_READ/WRITE_BASE */ 4387ec681f3Smrg uint64_t db_stencil_base; 4397ec681f3Smrg uint64_t db_htile_data_base; 4407ec681f3Smrg unsigned db_depth_info; 4417ec681f3Smrg unsigned db_z_info; 4427ec681f3Smrg unsigned db_z_info2; /* GFX9 only */ 4437ec681f3Smrg unsigned db_depth_view; 4447ec681f3Smrg unsigned db_depth_size; 4457ec681f3Smrg unsigned db_depth_slice; 4467ec681f3Smrg unsigned db_stencil_info; 4477ec681f3Smrg unsigned db_stencil_info2; /* GFX9 only */ 4487ec681f3Smrg unsigned db_htile_surface; 44901e04c3fSmrg}; 45001e04c3fSmrg 45101e04c3fSmrgstruct si_mmio_counter { 4527ec681f3Smrg unsigned busy; 4537ec681f3Smrg unsigned idle; 45401e04c3fSmrg}; 45501e04c3fSmrg 45601e04c3fSmrgunion si_mmio_counters { 4577ec681f3Smrg struct si_mmio_counters_named { 4587ec681f3Smrg /* For global GPU load including SDMA. */ 4597ec681f3Smrg struct si_mmio_counter gpu; 4607ec681f3Smrg 4617ec681f3Smrg /* GRBM_STATUS */ 4627ec681f3Smrg struct si_mmio_counter spi; 4637ec681f3Smrg struct si_mmio_counter gui; 4647ec681f3Smrg struct si_mmio_counter ta; 4657ec681f3Smrg struct si_mmio_counter gds; 4667ec681f3Smrg struct si_mmio_counter vgt; 4677ec681f3Smrg struct si_mmio_counter ia; 4687ec681f3Smrg struct si_mmio_counter sx; 4697ec681f3Smrg struct si_mmio_counter wd; 4707ec681f3Smrg struct si_mmio_counter bci; 4717ec681f3Smrg struct si_mmio_counter sc; 4727ec681f3Smrg struct si_mmio_counter pa; 4737ec681f3Smrg struct si_mmio_counter db; 4747ec681f3Smrg struct si_mmio_counter cp; 4757ec681f3Smrg struct si_mmio_counter cb; 4767ec681f3Smrg 4777ec681f3Smrg /* SRBM_STATUS2 */ 4787ec681f3Smrg struct si_mmio_counter sdma; 4797ec681f3Smrg 4807ec681f3Smrg /* CP_STAT */ 4817ec681f3Smrg struct si_mmio_counter pfp; 4827ec681f3Smrg struct si_mmio_counter meq; 4837ec681f3Smrg struct si_mmio_counter me; 4847ec681f3Smrg struct si_mmio_counter surf_sync; 4857ec681f3Smrg struct si_mmio_counter cp_dma; 4867ec681f3Smrg struct si_mmio_counter scratch_ram; 4877ec681f3Smrg } named; 4887ec681f3Smrg 4897ec681f3Smrg unsigned array[sizeof(struct si_mmio_counters_named) / sizeof(unsigned)]; 49001e04c3fSmrg}; 49101e04c3fSmrg 49201e04c3fSmrgstruct si_memory_object { 4937ec681f3Smrg struct pipe_memory_object b; 4947ec681f3Smrg struct pb_buffer *buf; 4957ec681f3Smrg uint32_t stride; 49601e04c3fSmrg}; 49701e04c3fSmrg 49801e04c3fSmrg/* Saved CS data for debugging features. */ 49901e04c3fSmrgstruct radeon_saved_cs { 5007ec681f3Smrg uint32_t *ib; 5017ec681f3Smrg unsigned num_dw; 50201e04c3fSmrg 5037ec681f3Smrg struct radeon_bo_list_item *bo_list; 5047ec681f3Smrg unsigned bo_count; 50501e04c3fSmrg}; 506af69d88dSmrg 507af69d88dSmrgstruct si_screen { 5087ec681f3Smrg struct pipe_screen b; 5097ec681f3Smrg struct radeon_winsys *ws; 5107ec681f3Smrg struct disk_cache *disk_shader_cache; 5117ec681f3Smrg 5127ec681f3Smrg struct radeon_info info; 5137ec681f3Smrg struct nir_shader_compiler_options nir_options; 5147ec681f3Smrg uint64_t debug_flags; 5157ec681f3Smrg char renderer_string[183]; 5167ec681f3Smrg 5177ec681f3Smrg void (*make_texture_descriptor)(struct si_screen *screen, struct si_texture *tex, bool sampler, 5187ec681f3Smrg enum pipe_texture_target target, enum pipe_format pipe_format, 5197ec681f3Smrg const unsigned char state_swizzle[4], unsigned first_level, 5207ec681f3Smrg unsigned last_level, unsigned first_layer, unsigned last_layer, 5217ec681f3Smrg unsigned width, unsigned height, unsigned depth, uint32_t *state, 5227ec681f3Smrg uint32_t *fmask_state); 5237ec681f3Smrg 5247ec681f3Smrg unsigned max_memory_usage_kb; 5257ec681f3Smrg unsigned pa_sc_raster_config; 5267ec681f3Smrg unsigned pa_sc_raster_config_1; 5277ec681f3Smrg unsigned se_tile_repeat; 5287ec681f3Smrg unsigned gs_table_depth; 5297ec681f3Smrg unsigned tess_offchip_block_dw_size; 5307ec681f3Smrg unsigned tess_offchip_ring_size; 5317ec681f3Smrg unsigned tess_factor_ring_size; 5327ec681f3Smrg unsigned vgt_hs_offchip_param; 5337ec681f3Smrg unsigned eqaa_force_coverage_samples; 5347ec681f3Smrg unsigned eqaa_force_z_samples; 5357ec681f3Smrg unsigned eqaa_force_color_samples; 5367ec681f3Smrg unsigned pbb_context_states_per_bin; 5377ec681f3Smrg unsigned pbb_persistent_states_per_bin; 5387ec681f3Smrg bool has_draw_indirect_multi; 5397ec681f3Smrg bool has_out_of_order_rast; 5407ec681f3Smrg bool assume_no_z_fights; 5417ec681f3Smrg bool commutative_blend_add; 5427ec681f3Smrg bool allow_draw_out_of_order; 5437ec681f3Smrg bool dpbb_allowed; 5447ec681f3Smrg bool use_ngg; 5457ec681f3Smrg bool use_ngg_culling; 5467ec681f3Smrg bool use_ngg_streamout; 5477ec681f3Smrg bool allow_dcc_msaa_clear_to_reg_for_bpp[5]; /* indexed by log2(Bpp) */ 5487ec681f3Smrg bool always_allow_dcc_stores; 5497ec681f3Smrg 5507ec681f3Smrg struct { 5517ec681f3Smrg#define OPT_BOOL(name, dflt, description) bool name : 1; 5529f464c52Smaya#include "si_debug_options.h" 5537ec681f3Smrg } options; 5547ec681f3Smrg 5557ec681f3Smrg /* Whether shaders are monolithic (1-part) or separate (3-part). */ 5567ec681f3Smrg bool use_monolithic_shaders; 5577ec681f3Smrg bool record_llvm_ir; 5587ec681f3Smrg 5597ec681f3Smrg struct slab_parent_pool pool_transfers; 5607ec681f3Smrg 5617ec681f3Smrg /* Texture filter settings. */ 5627ec681f3Smrg int force_aniso; /* -1 = disabled */ 5637ec681f3Smrg 5647ec681f3Smrg /* Auxiliary context. Mainly used to initialize resources. 5657ec681f3Smrg * It must be locked prior to using and flushed before unlocking. */ 5667ec681f3Smrg struct pipe_context *aux_context; 5677ec681f3Smrg simple_mtx_t aux_context_lock; 5687ec681f3Smrg 5697ec681f3Smrg /* Async compute context for DRI_PRIME copies. */ 5707ec681f3Smrg struct pipe_context *async_compute_context; 5717ec681f3Smrg simple_mtx_t async_compute_context_lock; 5727ec681f3Smrg 5737ec681f3Smrg /* This must be in the screen, because UE4 uses one context for 5747ec681f3Smrg * compilation and another one for rendering. 5757ec681f3Smrg */ 5767ec681f3Smrg unsigned num_compilations; 5777ec681f3Smrg /* Along with ST_DEBUG=precompile, this should show if applications 5787ec681f3Smrg * are loading shaders on demand. This is a monotonic counter. 5797ec681f3Smrg */ 5807ec681f3Smrg unsigned num_shaders_created; 5817ec681f3Smrg unsigned num_memory_shader_cache_hits; 5827ec681f3Smrg unsigned num_memory_shader_cache_misses; 5837ec681f3Smrg unsigned num_disk_shader_cache_hits; 5847ec681f3Smrg unsigned num_disk_shader_cache_misses; 5857ec681f3Smrg 5867ec681f3Smrg /* GPU load thread. */ 5877ec681f3Smrg simple_mtx_t gpu_load_mutex; 5887ec681f3Smrg thrd_t gpu_load_thread; 5897ec681f3Smrg union si_mmio_counters mmio_counters; 5907ec681f3Smrg volatile unsigned gpu_load_stop_thread; /* bool */ 5917ec681f3Smrg 5927ec681f3Smrg /* Performance counters. */ 5937ec681f3Smrg struct si_perfcounters *perfcounters; 5947ec681f3Smrg 5957ec681f3Smrg /* If pipe_screen wants to recompute and re-emit the framebuffer, 5967ec681f3Smrg * sampler, and image states of all contexts, it should atomically 5977ec681f3Smrg * increment this. 5987ec681f3Smrg * 5997ec681f3Smrg * Each context will compare this with its own last known value of 6007ec681f3Smrg * the counter before drawing and re-emit the states accordingly. 6017ec681f3Smrg */ 6027ec681f3Smrg unsigned dirty_tex_counter; 6037ec681f3Smrg unsigned dirty_buf_counter; 6047ec681f3Smrg 6057ec681f3Smrg /* Atomically increment this counter when an existing texture's 6067ec681f3Smrg * metadata is enabled or disabled in a way that requires changing 6077ec681f3Smrg * contexts' compressed texture binding masks. 6087ec681f3Smrg */ 6097ec681f3Smrg unsigned compressed_colortex_counter; 6107ec681f3Smrg 6117ec681f3Smrg struct { 6127ec681f3Smrg /* Context flags to set so that all writes from earlier jobs 6137ec681f3Smrg * in the CP are seen by L2 clients. 6147ec681f3Smrg */ 6157ec681f3Smrg unsigned cp_to_L2; 6167ec681f3Smrg 6177ec681f3Smrg /* Context flags to set so that all writes from earlier jobs 6187ec681f3Smrg * that end in L2 are seen by CP. 6197ec681f3Smrg */ 6207ec681f3Smrg unsigned L2_to_cp; 6217ec681f3Smrg } barrier_flags; 6227ec681f3Smrg 6237ec681f3Smrg simple_mtx_t shader_parts_mutex; 6247ec681f3Smrg struct si_shader_part *vs_prologs; 6257ec681f3Smrg struct si_shader_part *tcs_epilogs; 6267ec681f3Smrg struct si_shader_part *gs_prologs; 6277ec681f3Smrg struct si_shader_part *ps_prologs; 6287ec681f3Smrg struct si_shader_part *ps_epilogs; 6297ec681f3Smrg 6307ec681f3Smrg /* Shader cache in memory. 6317ec681f3Smrg * 6327ec681f3Smrg * Design & limitations: 6337ec681f3Smrg * - The shader cache is per screen (= per process), never saved to 6347ec681f3Smrg * disk, and skips redundant shader compilations from NIR to bytecode. 6357ec681f3Smrg * - It can only be used with one-variant-per-shader support, in which 6367ec681f3Smrg * case only the main (typically middle) part of shaders is cached. 6377ec681f3Smrg * - Only VS, TCS, TES, PS are cached, out of which only the hw VS 6387ec681f3Smrg * variants of VS and TES are cached, so LS and ES aren't. 6397ec681f3Smrg * - GS and CS aren't cached, but it's certainly possible to cache 6407ec681f3Smrg * those as well. 6417ec681f3Smrg */ 6427ec681f3Smrg simple_mtx_t shader_cache_mutex; 6437ec681f3Smrg struct hash_table *shader_cache; 6447ec681f3Smrg /* Maximum and current size */ 6457ec681f3Smrg uint32_t shader_cache_size; 6467ec681f3Smrg uint32_t shader_cache_max_size; 6477ec681f3Smrg 6487ec681f3Smrg /* Shader cache of live shaders. */ 6497ec681f3Smrg struct util_live_shader_cache live_shader_cache; 6507ec681f3Smrg 6517ec681f3Smrg /* Shader compiler queue for multithreaded compilation. */ 6527ec681f3Smrg struct util_queue shader_compiler_queue; 6537ec681f3Smrg /* Use at most 3 normal compiler threads on quadcore and better. 6547ec681f3Smrg * Hyperthreaded CPUs report the number of threads, but we want 6557ec681f3Smrg * the number of cores. We only need this many threads for shader-db. */ 6567ec681f3Smrg struct ac_llvm_compiler compiler[24]; /* used by the queue only */ 6577ec681f3Smrg 6587ec681f3Smrg struct util_queue shader_compiler_queue_low_priority; 6597ec681f3Smrg /* Use at most 2 low priority threads on quadcore and better. 6607ec681f3Smrg * We want to minimize the impact on multithreaded Mesa. */ 6617ec681f3Smrg struct ac_llvm_compiler compiler_lowp[10]; 6627ec681f3Smrg 6637ec681f3Smrg unsigned compute_wave_size; 6647ec681f3Smrg unsigned ps_wave_size; 6657ec681f3Smrg unsigned ge_wave_size; 6667ec681f3Smrg unsigned ngg_subgroup_size; 6677ec681f3Smrg 6687ec681f3Smrg struct util_idalloc_mt buffer_ids; 6697ec681f3Smrg struct util_vertex_state_cache vertex_state_cache; 670af69d88dSmrg}; 671af69d88dSmrg 67201e04c3fSmrgstruct si_sampler_view { 6737ec681f3Smrg struct pipe_sampler_view base; 6747ec681f3Smrg /* [0..7] = image descriptor 6757ec681f3Smrg * [4..7] = buffer descriptor */ 6767ec681f3Smrg uint32_t state[8]; 6777ec681f3Smrg uint32_t fmask_state[8]; 6787ec681f3Smrg const struct legacy_surf_level *base_level_info; 6797ec681f3Smrg ubyte base_level; 6807ec681f3Smrg ubyte block_width; 6817ec681f3Smrg bool is_stencil_sampler; 6827ec681f3Smrg bool dcc_incompatible; 683af69d88dSmrg}; 684af69d88dSmrg 68501e04c3fSmrg#define SI_SAMPLER_STATE_MAGIC 0x34f1c35a 68601e04c3fSmrg 68701e04c3fSmrgstruct si_sampler_state { 6887ec681f3Smrg#ifndef NDEBUG 6897ec681f3Smrg unsigned magic; 69001e04c3fSmrg#endif 6917ec681f3Smrg uint32_t val[4]; 6927ec681f3Smrg uint32_t upgraded_depth_val[4]; 693af69d88dSmrg}; 694af69d88dSmrg 695af69d88dSmrgstruct si_cs_shader_state { 6967ec681f3Smrg struct si_compute *program; 6977ec681f3Smrg struct si_compute *emitted_program; 6987ec681f3Smrg unsigned offset; 6997ec681f3Smrg bool initialized; 7007ec681f3Smrg bool uses_scratch; 70101e04c3fSmrg}; 70201e04c3fSmrg 70301e04c3fSmrgstruct si_samplers { 7047ec681f3Smrg struct pipe_sampler_view *views[SI_NUM_SAMPLERS]; 7057ec681f3Smrg struct si_sampler_state *sampler_states[SI_NUM_SAMPLERS]; 70601e04c3fSmrg 7077ec681f3Smrg /* The i-th bit is set if that element is enabled (non-NULL resource). */ 7087ec681f3Smrg unsigned enabled_mask; 7097ec681f3Smrg uint32_t needs_depth_decompress_mask; 7107ec681f3Smrg uint32_t needs_color_decompress_mask; 711af69d88dSmrg}; 712af69d88dSmrg 71301e04c3fSmrgstruct si_images { 7147ec681f3Smrg struct pipe_image_view views[SI_NUM_IMAGES]; 7157ec681f3Smrg uint32_t needs_color_decompress_mask; 7167ec681f3Smrg unsigned enabled_mask; 7177ec681f3Smrg unsigned display_dcc_store_mask; 718af69d88dSmrg}; 719af69d88dSmrg 720af69d88dSmrgstruct si_framebuffer { 7217ec681f3Smrg struct pipe_framebuffer_state state; 7227ec681f3Smrg unsigned colorbuf_enabled_4bit; 7237ec681f3Smrg unsigned spi_shader_col_format; 7247ec681f3Smrg unsigned spi_shader_col_format_alpha; 7257ec681f3Smrg unsigned spi_shader_col_format_blend; 7267ec681f3Smrg unsigned spi_shader_col_format_blend_alpha; 7277ec681f3Smrg ubyte nr_samples : 5; /* at most 16xAA */ 7287ec681f3Smrg ubyte log_samples : 3; /* at most 4 = 16xAA */ 7297ec681f3Smrg ubyte nr_color_samples; /* at most 8xAA */ 7307ec681f3Smrg ubyte compressed_cb_mask; 7317ec681f3Smrg ubyte uncompressed_cb_mask; 7327ec681f3Smrg ubyte color_is_int8; 7337ec681f3Smrg ubyte color_is_int10; 7347ec681f3Smrg ubyte dirty_cbufs; 7357ec681f3Smrg ubyte dcc_overwrite_combiner_watermark; 7367ec681f3Smrg ubyte min_bytes_per_pixel; 7377ec681f3Smrg bool dirty_zsbuf; 7387ec681f3Smrg bool any_dst_linear; 7397ec681f3Smrg bool CB_has_shader_readable_metadata; 7407ec681f3Smrg bool DB_has_shader_readable_metadata; 7417ec681f3Smrg bool all_DCC_pipe_aligned; 7427ec681f3Smrg bool has_dcc_msaa; 74301e04c3fSmrg}; 74401e04c3fSmrg 7457ec681f3Smrgenum si_quant_mode 7467ec681f3Smrg{ 7477ec681f3Smrg /* This is the list we want to support. */ 7487ec681f3Smrg SI_QUANT_MODE_16_8_FIXED_POINT_1_256TH, 7497ec681f3Smrg SI_QUANT_MODE_14_10_FIXED_POINT_1_1024TH, 7507ec681f3Smrg SI_QUANT_MODE_12_12_FIXED_POINT_1_4096TH, 75101e04c3fSmrg}; 75201e04c3fSmrg 75301e04c3fSmrgstruct si_signed_scissor { 7547ec681f3Smrg int minx; 7557ec681f3Smrg int miny; 7567ec681f3Smrg int maxx; 7577ec681f3Smrg int maxy; 7587ec681f3Smrg enum si_quant_mode quant_mode; 759af69d88dSmrg}; 760af69d88dSmrg 76101e04c3fSmrgstruct si_viewports { 7627ec681f3Smrg struct pipe_viewport_state states[SI_MAX_VIEWPORTS]; 7637ec681f3Smrg struct si_signed_scissor as_scissor[SI_MAX_VIEWPORTS]; 76401e04c3fSmrg}; 76501e04c3fSmrg 76601e04c3fSmrgstruct si_streamout_target { 7677ec681f3Smrg struct pipe_stream_output_target b; 76801e04c3fSmrg 7697ec681f3Smrg /* The buffer where BUFFER_FILLED_SIZE is stored. */ 7707ec681f3Smrg struct si_resource *buf_filled_size; 7717ec681f3Smrg unsigned buf_filled_size_offset; 7727ec681f3Smrg bool buf_filled_size_valid; 77301e04c3fSmrg 7747ec681f3Smrg unsigned stride_in_dw; 77501e04c3fSmrg}; 77601e04c3fSmrg 77701e04c3fSmrgstruct si_streamout { 7787ec681f3Smrg bool begin_emitted; 77901e04c3fSmrg 7807ec681f3Smrg unsigned enabled_mask; 7817ec681f3Smrg unsigned num_targets; 7827ec681f3Smrg struct si_streamout_target *targets[PIPE_MAX_SO_BUFFERS]; 78301e04c3fSmrg 7847ec681f3Smrg unsigned append_bitmask; 7857ec681f3Smrg bool suspended; 78601e04c3fSmrg 7877ec681f3Smrg /* External state which comes from the vertex shader, 7887ec681f3Smrg * it must be set explicitly when binding a shader. */ 7897ec681f3Smrg uint16_t *stride_in_dw; 7907ec681f3Smrg unsigned enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */ 79101e04c3fSmrg 7927ec681f3Smrg /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */ 7937ec681f3Smrg unsigned hw_enabled_mask; 79401e04c3fSmrg 7957ec681f3Smrg /* The state of VGT_STRMOUT_(CONFIG|EN). */ 7967ec681f3Smrg bool streamout_enabled; 7977ec681f3Smrg bool prims_gen_query_enabled; 7987ec681f3Smrg int num_prims_gen_queries; 79901e04c3fSmrg}; 80001e04c3fSmrg 80101e04c3fSmrg/* A shader state consists of the shader selector, which is a constant state 80201e04c3fSmrg * object shared by multiple contexts and shouldn't be modified, and 80301e04c3fSmrg * the current shader variant selected for this context. 80401e04c3fSmrg */ 80501e04c3fSmrgstruct si_shader_ctx_state { 8067ec681f3Smrg struct si_shader_selector *cso; 8077ec681f3Smrg struct si_shader *current; 8087ec681f3Smrg /* The shader variant key representing the current state. */ 8097ec681f3Smrg struct si_shader_key key; 81001e04c3fSmrg}; 811af69d88dSmrg 81201e04c3fSmrg#define SI_NUM_VGT_PARAM_KEY_BITS 12 8137ec681f3Smrg#define SI_NUM_VGT_PARAM_STATES (1 << SI_NUM_VGT_PARAM_KEY_BITS) 81401e04c3fSmrg 81501e04c3fSmrg/* The IA_MULTI_VGT_PARAM key used to index the table of precomputed values. 81601e04c3fSmrg * Some fields are set by state-change calls, most are set by draw_vbo. 81701e04c3fSmrg */ 81801e04c3fSmrgunion si_vgt_param_key { 8197ec681f3Smrg struct { 8207ec681f3Smrg#if UTIL_ARCH_LITTLE_ENDIAN 8217ec681f3Smrg uint16_t prim : 4; 8227ec681f3Smrg uint16_t uses_instancing : 1; 8237ec681f3Smrg uint16_t multi_instances_smaller_than_primgroup : 1; 8247ec681f3Smrg uint16_t primitive_restart : 1; 8257ec681f3Smrg uint16_t count_from_stream_output : 1; 8267ec681f3Smrg uint16_t line_stipple_enabled : 1; 8277ec681f3Smrg uint16_t uses_tess : 1; 8287ec681f3Smrg uint16_t tess_uses_prim_id : 1; 8297ec681f3Smrg uint16_t uses_gs : 1; 8307ec681f3Smrg uint16_t _pad : 16 - SI_NUM_VGT_PARAM_KEY_BITS; 8317ec681f3Smrg#else /* UTIL_ARCH_BIG_ENDIAN */ 8327ec681f3Smrg uint16_t _pad : 16 - SI_NUM_VGT_PARAM_KEY_BITS; 8337ec681f3Smrg uint16_t uses_gs : 1; 8347ec681f3Smrg uint16_t tess_uses_prim_id : 1; 8357ec681f3Smrg uint16_t uses_tess : 1; 8367ec681f3Smrg uint16_t line_stipple_enabled : 1; 8377ec681f3Smrg uint16_t count_from_stream_output : 1; 8387ec681f3Smrg uint16_t primitive_restart : 1; 8397ec681f3Smrg uint16_t multi_instances_smaller_than_primgroup : 1; 8407ec681f3Smrg uint16_t uses_instancing : 1; 8417ec681f3Smrg uint16_t prim : 4; 84201e04c3fSmrg#endif 8437ec681f3Smrg } u; 8447ec681f3Smrg uint16_t index; 84501e04c3fSmrg}; 84601e04c3fSmrg 8477ec681f3Smrgstruct si_texture_handle { 8487ec681f3Smrg unsigned desc_slot; 8497ec681f3Smrg bool desc_dirty; 8507ec681f3Smrg struct pipe_sampler_view *view; 8517ec681f3Smrg struct si_sampler_state sstate; 85201e04c3fSmrg}; 85301e04c3fSmrg 8547ec681f3Smrgstruct si_image_handle { 8557ec681f3Smrg unsigned desc_slot; 8567ec681f3Smrg bool desc_dirty; 8577ec681f3Smrg struct pipe_image_view view; 85801e04c3fSmrg}; 85901e04c3fSmrg 86001e04c3fSmrgstruct si_saved_cs { 8617ec681f3Smrg struct pipe_reference reference; 8627ec681f3Smrg struct si_context *ctx; 8637ec681f3Smrg struct radeon_saved_cs gfx; 8647ec681f3Smrg struct radeon_saved_cs compute; 8657ec681f3Smrg struct si_resource *trace_buf; 8667ec681f3Smrg unsigned trace_id; 8677ec681f3Smrg 8687ec681f3Smrg unsigned gfx_last_dw; 8697ec681f3Smrg bool flushed; 8707ec681f3Smrg int64_t time_flush; 87101e04c3fSmrg}; 872af69d88dSmrg 8737ec681f3Smrgstruct si_small_prim_cull_info { 8747ec681f3Smrg float scale[2], translate[2]; 8757ec681f3Smrg float small_prim_precision; 8769f464c52Smaya}; 8779f464c52Smaya 8787ec681f3Smrgstruct si_vertex_state { 8797ec681f3Smrg struct pipe_vertex_state b; 8807ec681f3Smrg struct si_vertex_elements velems; 8817ec681f3Smrg uint32_t descriptors[4 * SI_MAX_ATTRIBS]; 882af69d88dSmrg}; 883af69d88dSmrg 8847ec681f3Smrgtypedef void (*pipe_draw_vbo_func)(struct pipe_context *pipe, 8857ec681f3Smrg const struct pipe_draw_info *info, 8867ec681f3Smrg unsigned drawid_offset, 8877ec681f3Smrg const struct pipe_draw_indirect_info *indirect, 8887ec681f3Smrg const struct pipe_draw_start_count_bias *draws, 8897ec681f3Smrg unsigned num_draws); 8907ec681f3Smrgtypedef void (*pipe_draw_vertex_state_func)(struct pipe_context *ctx, 8917ec681f3Smrg struct pipe_vertex_state *vstate, 8927ec681f3Smrg uint32_t partial_velem_mask, 8937ec681f3Smrg struct pipe_draw_vertex_state_info info, 8947ec681f3Smrg const struct pipe_draw_start_count_bias *draws, 8957ec681f3Smrg unsigned num_draws); 8967ec681f3Smrg 8977ec681f3Smrgstruct si_context { 8987ec681f3Smrg struct pipe_context b; /* base class */ 8997ec681f3Smrg 9007ec681f3Smrg enum radeon_family family; 9017ec681f3Smrg enum chip_class chip_class; 9027ec681f3Smrg 9037ec681f3Smrg struct radeon_winsys *ws; 9047ec681f3Smrg struct radeon_winsys_ctx *ctx; 9057ec681f3Smrg struct radeon_cmdbuf gfx_cs; /* compute IB if graphics is disabled */ 9067ec681f3Smrg struct radeon_cmdbuf *sdma_cs; 9077ec681f3Smrg struct pipe_fence_handle *last_gfx_fence; 9087ec681f3Smrg struct si_resource *eop_bug_scratch; 9097ec681f3Smrg struct si_resource *eop_bug_scratch_tmz; 9107ec681f3Smrg struct u_upload_mgr *cached_gtt_allocator; 9117ec681f3Smrg struct threaded_context *tc; 9127ec681f3Smrg struct u_suballocator allocator_zeroed_memory; 9137ec681f3Smrg struct slab_child_pool pool_transfers; 9147ec681f3Smrg struct slab_child_pool pool_transfers_unsync; /* for threaded_context */ 9157ec681f3Smrg struct pipe_device_reset_callback device_reset_callback; 9167ec681f3Smrg struct u_log_context *log; 9177ec681f3Smrg void *query_result_shader; 9187ec681f3Smrg void *sh_query_result_shader; 9197ec681f3Smrg struct si_resource *shadowed_regs; 9207ec681f3Smrg 9217ec681f3Smrg void (*emit_cache_flush)(struct si_context *ctx, struct radeon_cmdbuf *cs); 9227ec681f3Smrg 9237ec681f3Smrg struct blitter_context *blitter; 9247ec681f3Smrg void *noop_blend; 9257ec681f3Smrg void *noop_dsa; 9267ec681f3Smrg void *no_velems_state; 9277ec681f3Smrg void *discard_rasterizer_state; 9287ec681f3Smrg void *custom_dsa_flush; 9297ec681f3Smrg void *custom_blend_resolve; 9307ec681f3Smrg void *custom_blend_fmask_decompress; 9317ec681f3Smrg void *custom_blend_eliminate_fastclear; 9327ec681f3Smrg void *custom_blend_dcc_decompress; 9337ec681f3Smrg void *vs_blit_pos; 9347ec681f3Smrg void *vs_blit_pos_layered; 9357ec681f3Smrg void *vs_blit_color; 9367ec681f3Smrg void *vs_blit_color_layered; 9377ec681f3Smrg void *vs_blit_texcoord; 9387ec681f3Smrg void *cs_clear_buffer; 9397ec681f3Smrg void *cs_clear_buffer_rmw; 9407ec681f3Smrg void *cs_copy_buffer; 9417ec681f3Smrg void *cs_copy_image; 9427ec681f3Smrg void *cs_copy_image_1d_array; 9437ec681f3Smrg void *cs_clear_render_target; 9447ec681f3Smrg void *cs_clear_render_target_1d_array; 9457ec681f3Smrg void *cs_clear_12bytes_buffer; 9467ec681f3Smrg void *cs_dcc_decompress; 9477ec681f3Smrg void *cs_dcc_retile[32]; 9487ec681f3Smrg void *cs_fmask_expand[3][2]; /* [log2(samples)-1][is_array] */ 9497ec681f3Smrg struct si_screen *screen; 9507ec681f3Smrg struct pipe_debug_callback debug; 9517ec681f3Smrg struct ac_llvm_compiler compiler; /* only non-threaded compilation */ 9527ec681f3Smrg struct si_shader_ctx_state fixed_func_tcs_shader; 9537ec681f3Smrg /* Offset 0: EOP flush number; Offset 4: GDS prim restart counter */ 9547ec681f3Smrg struct si_resource *wait_mem_scratch; 9557ec681f3Smrg struct si_resource *wait_mem_scratch_tmz; 9567ec681f3Smrg unsigned wait_mem_number; 9577ec681f3Smrg uint16_t prefetch_L2_mask; 9587ec681f3Smrg 9597ec681f3Smrg bool blitter_running; 9607ec681f3Smrg bool is_noop:1; 9617ec681f3Smrg bool has_graphics:1; 9627ec681f3Smrg bool gfx_flush_in_progress : 1; 9637ec681f3Smrg bool gfx_last_ib_is_busy : 1; 9647ec681f3Smrg bool compute_is_busy : 1; 9657ec681f3Smrg int8_t pipeline_stats_enabled; /* -1 = unknown, 0 = disabled, 1 = enabled */ 9667ec681f3Smrg 9677ec681f3Smrg unsigned num_gfx_cs_flushes; 9687ec681f3Smrg unsigned initial_gfx_cs_size; 9697ec681f3Smrg unsigned last_dirty_tex_counter; 9707ec681f3Smrg unsigned last_dirty_buf_counter; 9717ec681f3Smrg unsigned last_compressed_colortex_counter; 9727ec681f3Smrg unsigned last_num_draw_calls; 9737ec681f3Smrg unsigned flags; /* flush flags */ 9747ec681f3Smrg /* Current unaccounted memory usage. */ 9757ec681f3Smrg uint32_t memory_usage_kb; 9767ec681f3Smrg 9777ec681f3Smrg /* NGG streamout. */ 9787ec681f3Smrg struct pb_buffer *gds; 9797ec681f3Smrg struct pb_buffer *gds_oa; 9807ec681f3Smrg 9817ec681f3Smrg /* Atoms (direct states). */ 9827ec681f3Smrg union si_state_atoms atoms; 9837ec681f3Smrg unsigned dirty_atoms; /* mask */ 9847ec681f3Smrg /* PM4 states (precomputed immutable states) */ 9857ec681f3Smrg unsigned dirty_states; 9867ec681f3Smrg union si_state queued; 9877ec681f3Smrg union si_state emitted; 9887ec681f3Smrg 9897ec681f3Smrg /* Atom declarations. */ 9907ec681f3Smrg struct si_framebuffer framebuffer; 9917ec681f3Smrg unsigned sample_locs_num_samples; 9927ec681f3Smrg uint16_t sample_mask; 9937ec681f3Smrg unsigned last_cb_target_mask; 9947ec681f3Smrg struct pipe_blend_color blend_color; 9957ec681f3Smrg struct pipe_clip_state clip_state; 9967ec681f3Smrg struct si_shader_data shader_pointers; 9977ec681f3Smrg struct si_stencil_ref stencil_ref; 9987ec681f3Smrg bool blend_color_any_nonzeros:1; 9997ec681f3Smrg bool clip_state_any_nonzeros:1; 10007ec681f3Smrg bool viewport0_y_inverted; 10017ec681f3Smrg struct pipe_scissor_state scissors[SI_MAX_VIEWPORTS]; 10027ec681f3Smrg struct si_streamout streamout; 10037ec681f3Smrg struct si_viewports viewports; 10047ec681f3Smrg unsigned num_window_rectangles; 10057ec681f3Smrg bool window_rectangles_include; 10067ec681f3Smrg struct pipe_scissor_state window_rectangles[4]; 10077ec681f3Smrg 10087ec681f3Smrg /* Precomputed states. */ 10097ec681f3Smrg struct si_pm4_state *cs_preamble_state; 10107ec681f3Smrg struct si_pm4_state *cs_preamble_tess_rings; 10117ec681f3Smrg struct si_pm4_state *cs_preamble_tess_rings_tmz; 10127ec681f3Smrg struct si_pm4_state *cs_preamble_gs_rings; 10137ec681f3Smrg bool cs_preamble_has_vgt_flush; 10147ec681f3Smrg struct si_pm4_state *vgt_shader_config[SI_NUM_VGT_STAGES_STATES]; 10157ec681f3Smrg 10167ec681f3Smrg /* shaders */ 10177ec681f3Smrg union { 10187ec681f3Smrg struct { 10197ec681f3Smrg struct si_shader_ctx_state vs; 10207ec681f3Smrg struct si_shader_ctx_state ps; 10217ec681f3Smrg struct si_shader_ctx_state gs; 10227ec681f3Smrg struct si_shader_ctx_state tcs; 10237ec681f3Smrg struct si_shader_ctx_state tes; 10247ec681f3Smrg } shader; 10257ec681f3Smrg /* indexed access using pipe_shader_type (not by MESA_SHADER_*) */ 10267ec681f3Smrg struct si_shader_ctx_state shaders[SI_NUM_GRAPHICS_SHADERS]; 10277ec681f3Smrg }; 10287ec681f3Smrg struct si_cs_shader_state cs_shader_state; 10297ec681f3Smrg 10307ec681f3Smrg /* shader information */ 10317ec681f3Smrg uint64_t ps_inputs_read_or_disabled; 10327ec681f3Smrg struct si_vertex_elements *vertex_elements; 10337ec681f3Smrg unsigned num_vertex_elements; 10347ec681f3Smrg unsigned cs_max_waves_per_sh; 10357ec681f3Smrg bool uses_nontrivial_vs_prolog; 10367ec681f3Smrg bool force_trivial_vs_prolog; 10377ec681f3Smrg bool do_update_shaders; 10387ec681f3Smrg bool compute_shaderbuf_sgprs_dirty; 10397ec681f3Smrg bool compute_image_sgprs_dirty; 10407ec681f3Smrg bool vs_uses_base_instance; 10417ec681f3Smrg bool vs_uses_draw_id; 10427ec681f3Smrg uint8_t patch_vertices; 10437ec681f3Smrg 10447ec681f3Smrg /* shader descriptors */ 10457ec681f3Smrg struct si_descriptors descriptors[SI_NUM_DESCS]; 10467ec681f3Smrg unsigned descriptors_dirty; 10477ec681f3Smrg unsigned shader_pointers_dirty; 10487ec681f3Smrg unsigned shader_needs_decompress_mask; 10497ec681f3Smrg struct si_buffer_resources internal_bindings; 10507ec681f3Smrg struct si_buffer_resources const_and_shader_buffers[SI_NUM_SHADERS]; 10517ec681f3Smrg struct si_samplers samplers[SI_NUM_SHADERS]; 10527ec681f3Smrg struct si_images images[SI_NUM_SHADERS]; 10537ec681f3Smrg bool bo_list_add_all_resident_resources; 10547ec681f3Smrg bool bo_list_add_all_gfx_resources; 10557ec681f3Smrg bool bo_list_add_all_compute_resources; 10567ec681f3Smrg 10577ec681f3Smrg /* other shader resources */ 10587ec681f3Smrg struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on GFX7 */ 10597ec681f3Smrg struct pipe_resource *esgs_ring; 10607ec681f3Smrg struct pipe_resource *gsvs_ring; 10617ec681f3Smrg struct pipe_resource *tess_rings; 10627ec681f3Smrg struct pipe_resource *tess_rings_tmz; 10637ec681f3Smrg union pipe_color_union *border_color_table; /* in CPU memory, any endian */ 10647ec681f3Smrg struct si_resource *border_color_buffer; 10657ec681f3Smrg union pipe_color_union *border_color_map; /* in VRAM (slow access), little endian */ 10667ec681f3Smrg unsigned border_color_count; 10677ec681f3Smrg unsigned num_vs_blit_sgprs; 10687ec681f3Smrg uint32_t vs_blit_sh_data[SI_VS_BLIT_SGPRS_POS_TEXCOORD]; 10697ec681f3Smrg uint32_t cs_user_data[4]; 10707ec681f3Smrg 10717ec681f3Smrg /* Vertex buffers. */ 10727ec681f3Smrg bool vertex_buffers_dirty; 10737ec681f3Smrg bool vertex_buffer_pointer_dirty; 10747ec681f3Smrg bool vertex_buffer_user_sgprs_dirty; 10757ec681f3Smrg struct pipe_vertex_buffer vertex_buffer[SI_NUM_VERTEX_BUFFERS]; 10767ec681f3Smrg uint16_t vertex_buffer_unaligned; /* bitmask of not dword-aligned buffers */ 10777ec681f3Smrg uint32_t *vb_descriptors_gpu_list; 10787ec681f3Smrg struct si_resource *vb_descriptors_buffer; 10797ec681f3Smrg unsigned vb_descriptors_offset; 10807ec681f3Smrg unsigned vb_descriptor_user_sgprs[5 * 4]; 10817ec681f3Smrg 10827ec681f3Smrg /* MSAA config state. */ 10837ec681f3Smrg int ps_iter_samples; 10847ec681f3Smrg bool ps_uses_fbfetch; 10857ec681f3Smrg bool smoothing_enabled; 10867ec681f3Smrg 10877ec681f3Smrg /* DB render state. */ 10887ec681f3Smrg unsigned ps_db_shader_control; 10897ec681f3Smrg unsigned dbcb_copy_sample; 10907ec681f3Smrg bool dbcb_depth_copy_enabled : 1; 10917ec681f3Smrg bool dbcb_stencil_copy_enabled : 1; 10927ec681f3Smrg bool db_flush_depth_inplace : 1; 10937ec681f3Smrg bool db_flush_stencil_inplace : 1; 10947ec681f3Smrg bool db_depth_clear : 1; 10957ec681f3Smrg bool db_depth_disable_expclear : 1; 10967ec681f3Smrg bool db_stencil_clear : 1; 10977ec681f3Smrg bool db_stencil_disable_expclear : 1; 10987ec681f3Smrg bool occlusion_queries_disabled : 1; 10997ec681f3Smrg bool generate_mipmap_for_depth : 1; 11007ec681f3Smrg bool allow_flat_shading : 1; 11017ec681f3Smrg 11027ec681f3Smrg /* Emitted draw state. */ 11037ec681f3Smrg bool ngg : 1; 11047ec681f3Smrg uint8_t ngg_culling; 11057ec681f3Smrg unsigned last_index_size; 11067ec681f3Smrg int last_base_vertex; 11077ec681f3Smrg unsigned last_start_instance; 11087ec681f3Smrg unsigned last_instance_count; 11097ec681f3Smrg unsigned last_drawid; 11107ec681f3Smrg unsigned last_sh_base_reg; 11117ec681f3Smrg int last_primitive_restart_en; 11127ec681f3Smrg unsigned last_restart_index; 11137ec681f3Smrg unsigned last_prim; 11147ec681f3Smrg unsigned last_multi_vgt_param; 11157ec681f3Smrg unsigned last_gs_out_prim; 11167ec681f3Smrg int last_binning_enabled; 11177ec681f3Smrg unsigned current_vs_state; 11187ec681f3Smrg unsigned last_vs_state; 11197ec681f3Smrg enum pipe_prim_type current_rast_prim; /* primitive type after TES, GS */ 11207ec681f3Smrg 11217ec681f3Smrg struct si_small_prim_cull_info last_small_prim_cull_info; 11227ec681f3Smrg struct si_resource *small_prim_cull_info_buf; 11237ec681f3Smrg uint64_t small_prim_cull_info_address; 11247ec681f3Smrg 11257ec681f3Smrg /* Scratch buffer */ 11267ec681f3Smrg struct si_resource *scratch_buffer; 11277ec681f3Smrg unsigned scratch_waves; 11287ec681f3Smrg unsigned spi_tmpring_size; 11297ec681f3Smrg unsigned max_seen_scratch_bytes_per_wave; 11307ec681f3Smrg unsigned max_seen_compute_scratch_bytes_per_wave; 11317ec681f3Smrg 11327ec681f3Smrg struct si_resource *compute_scratch_buffer; 11337ec681f3Smrg 11347ec681f3Smrg /* Emitted derived tessellation state. */ 11357ec681f3Smrg /* Local shader (VS), or HS if LS-HS are merged. */ 11367ec681f3Smrg struct si_shader *last_ls; 11377ec681f3Smrg struct si_shader_selector *last_tcs; 11387ec681f3Smrg unsigned last_num_tcs_input_cp; 11397ec681f3Smrg unsigned last_tes_sh_base; 11407ec681f3Smrg bool last_tess_uses_primid; 11417ec681f3Smrg unsigned last_num_patches; 11427ec681f3Smrg unsigned last_ls_hs_config; 11437ec681f3Smrg 11447ec681f3Smrg /* Debug state. */ 11457ec681f3Smrg bool is_debug; 11467ec681f3Smrg struct si_saved_cs *current_saved_cs; 11477ec681f3Smrg uint64_t dmesg_timestamp; 11487ec681f3Smrg unsigned apitrace_call_number; 11497ec681f3Smrg 11507ec681f3Smrg /* Other state */ 11517ec681f3Smrg bool need_check_render_feedback; 11527ec681f3Smrg bool decompression_enabled; 11537ec681f3Smrg bool dpbb_force_off; 11547ec681f3Smrg bool vs_writes_viewport_index; 11557ec681f3Smrg bool vs_disables_clipping_viewport; 11567ec681f3Smrg 11577ec681f3Smrg /* Precomputed IA_MULTI_VGT_PARAM */ 11587ec681f3Smrg union si_vgt_param_key ia_multi_vgt_param_key; 11597ec681f3Smrg unsigned ia_multi_vgt_param[SI_NUM_VGT_PARAM_STATES]; 11607ec681f3Smrg 11617ec681f3Smrg /* Bindless descriptors. */ 11627ec681f3Smrg struct si_descriptors bindless_descriptors; 11637ec681f3Smrg struct util_idalloc bindless_used_slots; 11647ec681f3Smrg unsigned num_bindless_descriptors; 11657ec681f3Smrg bool bindless_descriptors_dirty; 11667ec681f3Smrg bool graphics_bindless_pointer_dirty; 11677ec681f3Smrg bool compute_bindless_pointer_dirty; 11687ec681f3Smrg 11697ec681f3Smrg /* Allocated bindless handles */ 11707ec681f3Smrg struct hash_table *tex_handles; 11717ec681f3Smrg struct hash_table *img_handles; 11727ec681f3Smrg 11737ec681f3Smrg /* Resident bindless handles */ 11747ec681f3Smrg struct util_dynarray resident_tex_handles; 11757ec681f3Smrg struct util_dynarray resident_img_handles; 11767ec681f3Smrg 11777ec681f3Smrg /* Resident bindless handles which need decompression */ 11787ec681f3Smrg struct util_dynarray resident_tex_needs_color_decompress; 11797ec681f3Smrg struct util_dynarray resident_img_needs_color_decompress; 11807ec681f3Smrg struct util_dynarray resident_tex_needs_depth_decompress; 11817ec681f3Smrg 11827ec681f3Smrg /* Bindless state */ 11837ec681f3Smrg bool uses_bindless_samplers; 11847ec681f3Smrg bool uses_bindless_images; 11857ec681f3Smrg 11867ec681f3Smrg /* MSAA sample locations. 11877ec681f3Smrg * The first index is the sample index. 11887ec681f3Smrg * The second index is the coordinate: X, Y. */ 11897ec681f3Smrg struct { 11907ec681f3Smrg float x1[1][2]; 11917ec681f3Smrg float x2[2][2]; 11927ec681f3Smrg float x4[4][2]; 11937ec681f3Smrg float x8[8][2]; 11947ec681f3Smrg float x16[16][2]; 11957ec681f3Smrg } sample_positions; 11967ec681f3Smrg struct pipe_resource *sample_pos_buffer; 11977ec681f3Smrg 11987ec681f3Smrg /* Misc stats. */ 11997ec681f3Smrg unsigned num_draw_calls; 12007ec681f3Smrg unsigned num_decompress_calls; 12017ec681f3Smrg unsigned num_prim_restart_calls; 12027ec681f3Smrg unsigned num_compute_calls; 12037ec681f3Smrg unsigned num_cp_dma_calls; 12047ec681f3Smrg unsigned num_vs_flushes; 12057ec681f3Smrg unsigned num_ps_flushes; 12067ec681f3Smrg unsigned num_cs_flushes; 12077ec681f3Smrg unsigned num_cb_cache_flushes; 12087ec681f3Smrg unsigned num_db_cache_flushes; 12097ec681f3Smrg unsigned num_L2_invalidates; 12107ec681f3Smrg unsigned num_L2_writebacks; 12117ec681f3Smrg unsigned num_resident_handles; 12127ec681f3Smrg uint64_t num_alloc_tex_transfer_bytes; 12137ec681f3Smrg unsigned last_tex_ps_draw_ratio; /* for query */ 12147ec681f3Smrg unsigned context_roll; 12157ec681f3Smrg 12167ec681f3Smrg /* Queries. */ 12177ec681f3Smrg /* Maintain the list of active queries for pausing between IBs. */ 12187ec681f3Smrg int num_occlusion_queries; 12197ec681f3Smrg int num_perfect_occlusion_queries; 12207ec681f3Smrg int num_pipeline_stat_queries; 12217ec681f3Smrg struct list_head active_queries; 12227ec681f3Smrg unsigned num_cs_dw_queries_suspend; 12237ec681f3Smrg 12247ec681f3Smrg /* Render condition. */ 12257ec681f3Smrg struct pipe_query *render_cond; 12267ec681f3Smrg unsigned render_cond_mode; 12277ec681f3Smrg bool render_cond_invert; 12287ec681f3Smrg bool render_cond_enabled; /* for u_blitter */ 12297ec681f3Smrg 12307ec681f3Smrg /* Shader-based queries. */ 12317ec681f3Smrg struct list_head shader_query_buffers; 12327ec681f3Smrg unsigned num_active_shader_queries; 12337ec681f3Smrg 12347ec681f3Smrg bool force_cb_shader_coherent; 12357ec681f3Smrg 12367ec681f3Smrg struct si_tracked_regs tracked_regs; 12377ec681f3Smrg 12387ec681f3Smrg /* Resources that need to be flushed, but will not get an explicit 12397ec681f3Smrg * flush_resource from the frontend and that will need to get flushed during 12407ec681f3Smrg * a context flush. 12417ec681f3Smrg */ 12427ec681f3Smrg struct hash_table *dirty_implicit_resources; 12437ec681f3Smrg 12447ec681f3Smrg pipe_draw_vbo_func draw_vbo[2][2][2]; 12457ec681f3Smrg pipe_draw_vertex_state_func draw_vertex_state[2][2][2]; 12467ec681f3Smrg /* When b.draw_vbo is a wrapper, real_draw_vbo is the real draw_vbo function */ 12477ec681f3Smrg pipe_draw_vbo_func real_draw_vbo; 12487ec681f3Smrg pipe_draw_vertex_state_func real_draw_vertex_state; 12497ec681f3Smrg void (*emit_spi_map[33])(struct si_context *sctx); 12507ec681f3Smrg 12517ec681f3Smrg /* SQTT */ 12527ec681f3Smrg struct ac_thread_trace_data *thread_trace; 12537ec681f3Smrg struct pipe_fence_handle *last_sqtt_fence; 12547ec681f3Smrg enum rgp_sqtt_marker_event_type sqtt_next_event; 12557ec681f3Smrg bool thread_trace_enabled; 12567ec681f3Smrg 12577ec681f3Smrg unsigned context_flags; 12587ec681f3Smrg 12597ec681f3Smrg /* Shaders. */ 12607ec681f3Smrg /* TODO: move other shaders here too */ 12617ec681f3Smrg /* Only used for DCC MSAA clears with 4-8 fragments and 4-16 samples. */ 12627ec681f3Smrg void *cs_clear_dcc_msaa[32][5][2][3][2]; /* [swizzle_mode][log2(bpe)][fragments == 8][log2(samples)-2][is_array] */ 12637ec681f3Smrg}; 126401e04c3fSmrg 1265af69d88dSmrg/* si_blit.c */ 126601e04c3fSmrgenum si_blitter_op /* bitmask */ 126701e04c3fSmrg{ 12687ec681f3Smrg SI_SAVE_TEXTURES = 1, 12697ec681f3Smrg SI_SAVE_FRAMEBUFFER = 2, 12707ec681f3Smrg SI_SAVE_FRAGMENT_STATE = 4, 12717ec681f3Smrg SI_DISABLE_RENDER_COND = 8, 127201e04c3fSmrg}; 127301e04c3fSmrg 127401e04c3fSmrgvoid si_blitter_begin(struct si_context *sctx, enum si_blitter_op op); 127501e04c3fSmrgvoid si_blitter_end(struct si_context *sctx); 1276af69d88dSmrgvoid si_init_blit_functions(struct si_context *sctx); 127701e04c3fSmrgvoid si_decompress_textures(struct si_context *sctx, unsigned shader_mask); 12787ec681f3Smrgvoid si_decompress_subresource(struct pipe_context *ctx, struct pipe_resource *tex, unsigned planes, 12797ec681f3Smrg unsigned level, unsigned first_layer, unsigned last_layer); 12807ec681f3Smrgvoid si_resource_copy_region(struct pipe_context *ctx, struct pipe_resource *dst, 12817ec681f3Smrg unsigned dst_level, unsigned dstx, unsigned dsty, unsigned dstz, 12827ec681f3Smrg struct pipe_resource *src, unsigned src_level, 12837ec681f3Smrg const struct pipe_box *src_box); 128401e04c3fSmrgvoid si_decompress_dcc(struct si_context *sctx, struct si_texture *tex); 12857ec681f3Smrgvoid si_flush_implicit_resources(struct si_context *sctx); 12867ec681f3Smrg 12877ec681f3Smrg/* si_nir_optim.c */ 12887ec681f3Smrgbool si_nir_is_output_const_if_tex_is_const(nir_shader *shader, float *in, float *out, int *texunit); 128901e04c3fSmrg 129001e04c3fSmrg/* si_buffer.c */ 12917ec681f3Smrgbool si_cs_is_buffer_referenced(struct si_context *sctx, struct pb_buffer *buf, 12927ec681f3Smrg enum radeon_bo_usage usage); 12937ec681f3Smrgvoid *si_buffer_map(struct si_context *sctx, struct si_resource *resource, 12947ec681f3Smrg unsigned usage); 12957ec681f3Smrgvoid si_init_resource_fields(struct si_screen *sscreen, struct si_resource *res, uint64_t size, 12967ec681f3Smrg unsigned alignment); 12977ec681f3Smrgbool si_alloc_resource(struct si_screen *sscreen, struct si_resource *res); 12987ec681f3Smrgstruct pipe_resource *pipe_aligned_buffer_create(struct pipe_screen *screen, unsigned flags, 12997ec681f3Smrg unsigned usage, unsigned size, unsigned alignment); 13007ec681f3Smrgstruct si_resource *si_aligned_buffer_create(struct pipe_screen *screen, unsigned flags, 13017ec681f3Smrg unsigned usage, unsigned size, unsigned alignment); 13027ec681f3Smrgvoid si_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *dst, 13037ec681f3Smrg struct pipe_resource *src, unsigned num_rebinds, 13047ec681f3Smrg uint32_t rebind_mask, uint32_t delete_buffer_id); 130501e04c3fSmrgvoid si_init_screen_buffer_functions(struct si_screen *sscreen); 130601e04c3fSmrgvoid si_init_buffer_functions(struct si_context *sctx); 130701e04c3fSmrg 130801e04c3fSmrg/* si_clear.c */ 13097ec681f3Smrg#define SI_CLEAR_TYPE_CMASK (1 << 0) 13107ec681f3Smrg#define SI_CLEAR_TYPE_DCC (1 << 1) 13117ec681f3Smrg#define SI_CLEAR_TYPE_HTILE (1 << 2) 13127ec681f3Smrg 13137ec681f3Smrgstruct si_clear_info { 13147ec681f3Smrg struct pipe_resource *resource; 13157ec681f3Smrg uint64_t offset; 13167ec681f3Smrg uint32_t size; 13177ec681f3Smrg uint32_t clear_value; 13187ec681f3Smrg uint32_t writemask; 13197ec681f3Smrg bool is_dcc_msaa; /* Clear it as a DCC MSAA image. */ 13207ec681f3Smrg}; 13217ec681f3Smrg 132201e04c3fSmrgenum pipe_format si_simplify_cb_format(enum pipe_format format); 13237ec681f3Smrgbool vi_alpha_is_on_msb(struct si_screen *sscreen, enum pipe_format format); 13247ec681f3Smrgbool vi_dcc_get_clear_info(struct si_context *sctx, struct si_texture *tex, unsigned level, 13257ec681f3Smrg unsigned clear_value, struct si_clear_info *out); 13267ec681f3Smrgvoid si_init_buffer_clear(struct si_clear_info *info, 13277ec681f3Smrg struct pipe_resource *resource, uint64_t offset, 13287ec681f3Smrg uint32_t size, uint32_t clear_value); 13297ec681f3Smrgvoid si_execute_clears(struct si_context *sctx, struct si_clear_info *info, 13307ec681f3Smrg unsigned num_clears, unsigned types); 133101e04c3fSmrgvoid si_init_clear_functions(struct si_context *sctx); 133201e04c3fSmrg 133301e04c3fSmrg/* si_compute_blit.c */ 13347ec681f3Smrg#define SI_OP_SYNC_CS_BEFORE (1 << 0) 13357ec681f3Smrg#define SI_OP_SYNC_PS_BEFORE (1 << 1) 13367ec681f3Smrg#define SI_OP_SYNC_CPDMA_BEFORE (1 << 2) /* only affects CP DMA calls */ 13377ec681f3Smrg#define SI_OP_SYNC_BEFORE (SI_OP_SYNC_CS_BEFORE | SI_OP_SYNC_PS_BEFORE | SI_OP_SYNC_CPDMA_BEFORE) 13387ec681f3Smrg#define SI_OP_SYNC_AFTER (1 << 3) 13397ec681f3Smrg#define SI_OP_SYNC_BEFORE_AFTER (SI_OP_SYNC_BEFORE | SI_OP_SYNC_AFTER) 13407ec681f3Smrg#define SI_OP_SKIP_CACHE_INV_BEFORE (1 << 4) /* don't invalidate caches */ 13417ec681f3Smrg#define SI_OP_CS_IMAGE (1 << 5) 13427ec681f3Smrg#define SI_OP_CS_RENDER_COND_ENABLE (1 << 6) 13437ec681f3Smrg#define SI_OP_CPDMA_SKIP_CHECK_CS_SPACE (1 << 7) /* don't call need_cs_space */ 13447ec681f3Smrg 134501e04c3fSmrgunsigned si_get_flush_flags(struct si_context *sctx, enum si_coherency coher, 13467ec681f3Smrg enum si_cache_policy cache_policy); 13477ec681f3Smrgvoid si_launch_grid_internal(struct si_context *sctx, struct pipe_grid_info *info, 13487ec681f3Smrg void *shader, unsigned flags); 13497ec681f3Smrgvoid si_launch_grid_internal_ssbos(struct si_context *sctx, struct pipe_grid_info *info, 13507ec681f3Smrg void *shader, unsigned flags, enum si_coherency coher, 13517ec681f3Smrg unsigned num_buffers, const struct pipe_shader_buffer *buffers, 13527ec681f3Smrg unsigned writeable_bitmask); 13537ec681f3Smrgenum si_clear_method { 13547ec681f3Smrg SI_CP_DMA_CLEAR_METHOD, 13557ec681f3Smrg SI_COMPUTE_CLEAR_METHOD, 13567ec681f3Smrg SI_AUTO_SELECT_CLEAR_METHOD 13577ec681f3Smrg}; 135801e04c3fSmrgvoid si_clear_buffer(struct si_context *sctx, struct pipe_resource *dst, 13597ec681f3Smrg uint64_t offset, uint64_t size, uint32_t *clear_value, 13607ec681f3Smrg uint32_t clear_value_size, unsigned flags, 13617ec681f3Smrg enum si_coherency coher, enum si_clear_method method); 13627ec681f3Smrgvoid si_compute_clear_buffer_rmw(struct si_context *sctx, struct pipe_resource *dst, 13637ec681f3Smrg unsigned dst_offset, unsigned size, 13647ec681f3Smrg uint32_t clear_value, uint32_t writebitmask, 13657ec681f3Smrg unsigned flags, enum si_coherency coher); 13667ec681f3Smrgvoid si_screen_clear_buffer(struct si_screen *sscreen, struct pipe_resource *dst, uint64_t offset, 13677ec681f3Smrg uint64_t size, unsigned value, unsigned flags); 13687ec681f3Smrgvoid si_copy_buffer(struct si_context *sctx, struct pipe_resource *dst, struct pipe_resource *src, 13697ec681f3Smrg uint64_t dst_offset, uint64_t src_offset, unsigned size, unsigned flags); 13707ec681f3Smrgvoid si_compute_copy_image(struct si_context *sctx, struct pipe_resource *dst, unsigned dst_level, 13717ec681f3Smrg struct pipe_resource *src, unsigned src_level, unsigned dstx, 13727ec681f3Smrg unsigned dsty, unsigned dstz, const struct pipe_box *src_box, 13737ec681f3Smrg bool is_dcc_decompress, unsigned flags); 13747ec681f3Smrgvoid si_compute_clear_render_target(struct pipe_context *ctx, struct pipe_surface *dstsurf, 13757ec681f3Smrg const union pipe_color_union *color, unsigned dstx, 13767ec681f3Smrg unsigned dsty, unsigned width, unsigned height, 13777ec681f3Smrg bool render_condition_enabled); 13789f464c52Smayavoid si_retile_dcc(struct si_context *sctx, struct si_texture *tex); 13797ec681f3Smrgvoid gfx9_clear_dcc_msaa(struct si_context *sctx, struct pipe_resource *res, uint32_t clear_value, 13807ec681f3Smrg unsigned flags, enum si_coherency coher); 13817ec681f3Smrgvoid si_compute_expand_fmask(struct pipe_context *ctx, struct pipe_resource *tex); 138201e04c3fSmrgvoid si_init_compute_blit_functions(struct si_context *sctx); 138301e04c3fSmrg 138401e04c3fSmrg/* si_cp_dma.c */ 13857ec681f3Smrgvoid si_cp_dma_wait_for_idle(struct si_context *sctx, struct radeon_cmdbuf *cs); 13869f464c52Smayavoid si_cp_dma_clear_buffer(struct si_context *sctx, struct radeon_cmdbuf *cs, 13877ec681f3Smrg struct pipe_resource *dst, uint64_t offset, uint64_t size, 13887ec681f3Smrg unsigned value, unsigned user_flags, enum si_coherency coher, 13897ec681f3Smrg enum si_cache_policy cache_policy); 13907ec681f3Smrgvoid si_cp_dma_copy_buffer(struct si_context *sctx, struct pipe_resource *dst, 13917ec681f3Smrg struct pipe_resource *src, uint64_t dst_offset, uint64_t src_offset, 13927ec681f3Smrg unsigned size, unsigned user_flags, enum si_coherency coher, 13937ec681f3Smrg enum si_cache_policy cache_policy); 13947ec681f3Smrgvoid si_cp_dma_prefetch(struct si_context *sctx, struct pipe_resource *buf, 13957ec681f3Smrg unsigned offset, unsigned size); 139601e04c3fSmrgvoid si_test_gds(struct si_context *sctx); 13977ec681f3Smrgvoid si_cp_write_data(struct si_context *sctx, struct si_resource *buf, unsigned offset, 13987ec681f3Smrg unsigned size, unsigned dst_sel, unsigned engine, const void *data); 13997ec681f3Smrgvoid si_cp_copy_data(struct si_context *sctx, struct radeon_cmdbuf *cs, unsigned dst_sel, 14007ec681f3Smrg struct si_resource *dst, unsigned dst_offset, unsigned src_sel, 14017ec681f3Smrg struct si_resource *src, unsigned src_offset); 14027ec681f3Smrg 14037ec681f3Smrg/* si_cp_reg_shadowing.c */ 14047ec681f3Smrgvoid si_init_cp_reg_shadowing(struct si_context *sctx); 140501e04c3fSmrg 140601e04c3fSmrg/* si_debug.c */ 14077ec681f3Smrgvoid si_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, struct radeon_saved_cs *saved, 14087ec681f3Smrg bool get_buffer_list); 140901e04c3fSmrgvoid si_clear_saved_cs(struct radeon_saved_cs *saved); 141001e04c3fSmrgvoid si_destroy_saved_cs(struct si_saved_cs *scs); 141101e04c3fSmrgvoid si_auto_log_cs(void *data, struct u_log_context *log); 141201e04c3fSmrgvoid si_log_hw_flush(struct si_context *sctx); 141301e04c3fSmrgvoid si_log_draw_state(struct si_context *sctx, struct u_log_context *log); 141401e04c3fSmrgvoid si_log_compute_state(struct si_context *sctx, struct u_log_context *log); 141501e04c3fSmrgvoid si_init_debug_functions(struct si_context *sctx); 14167ec681f3Smrgvoid si_check_vm_faults(struct si_context *sctx, struct radeon_saved_cs *saved, 14177ec681f3Smrg enum ring_type ring); 14187ec681f3Smrgbool si_replace_shader(unsigned num, struct si_shader_binary *binary); 14197ec681f3Smrgvoid si_print_current_ib(struct si_context *sctx, FILE *f); 142001e04c3fSmrg 142101e04c3fSmrg/* si_fence.c */ 14227ec681f3Smrgvoid si_cp_release_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, unsigned event, 14237ec681f3Smrg unsigned event_flags, unsigned dst_sel, unsigned int_sel, unsigned data_sel, 14247ec681f3Smrg struct si_resource *buf, uint64_t va, uint32_t new_fence, 14257ec681f3Smrg unsigned query_type); 142601e04c3fSmrgunsigned si_cp_write_fence_dwords(struct si_screen *screen); 14277ec681f3Smrgvoid si_cp_wait_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, uint64_t va, uint32_t ref, 14287ec681f3Smrg uint32_t mask, unsigned flags); 142901e04c3fSmrgvoid si_init_fence_functions(struct si_context *ctx); 143001e04c3fSmrgvoid si_init_screen_fence_functions(struct si_screen *screen); 143101e04c3fSmrgstruct pipe_fence_handle *si_create_fence(struct pipe_context *ctx, 14327ec681f3Smrg struct tc_unflushed_batch_token *tc_token); 143301e04c3fSmrg 143401e04c3fSmrg/* si_get.c */ 143501e04c3fSmrgvoid si_init_screen_get_functions(struct si_screen *sscreen); 143601e04c3fSmrg 14377ec681f3Smrgbool si_sdma_copy_image(struct si_context *ctx, struct si_texture *dst, struct si_texture *src); 14387ec681f3Smrg 143901e04c3fSmrg/* si_gfx_cs.c */ 14407ec681f3Smrgvoid si_flush_gfx_cs(struct si_context *ctx, unsigned flags, struct pipe_fence_handle **fence); 14417ec681f3Smrgvoid si_allocate_gds(struct si_context *ctx); 14427ec681f3Smrgvoid si_set_tracked_regs_to_clear_state(struct si_context *ctx); 14437ec681f3Smrgvoid si_begin_new_gfx_cs(struct si_context *ctx, bool first_cs); 14447ec681f3Smrgvoid si_trace_emit(struct si_context *sctx); 14457ec681f3Smrgvoid si_emit_surface_sync(struct si_context *sctx, struct radeon_cmdbuf *cs, 14467ec681f3Smrg unsigned cp_coher_cntl); 14477ec681f3Smrgvoid gfx10_emit_cache_flush(struct si_context *sctx, struct radeon_cmdbuf *cs); 14487ec681f3Smrgvoid si_emit_cache_flush(struct si_context *sctx, struct radeon_cmdbuf *cs); 14497ec681f3Smrg/* Replace the sctx->b.draw_vbo function with a wrapper. This can be use to implement 14507ec681f3Smrg * optimizations without affecting the normal draw_vbo functions perf. 14517ec681f3Smrg */ 14527ec681f3Smrgvoid si_install_draw_wrapper(struct si_context *sctx, pipe_draw_vbo_func wrapper, 14537ec681f3Smrg pipe_draw_vertex_state_func vstate_wrapper); 145401e04c3fSmrg 14559f464c52Smaya/* si_gpu_load.c */ 145601e04c3fSmrgvoid si_gpu_load_kill_thread(struct si_screen *sscreen); 145701e04c3fSmrguint64_t si_begin_counter(struct si_screen *sscreen, unsigned type); 14587ec681f3Smrgunsigned si_end_counter(struct si_screen *sscreen, unsigned type, uint64_t begin); 1459af69d88dSmrg 1460af69d88dSmrg/* si_compute.c */ 14617ec681f3Smrgvoid si_emit_initial_compute_regs(struct si_context *sctx, struct radeon_cmdbuf *cs); 1462af69d88dSmrgvoid si_init_compute_functions(struct si_context *sctx); 1463af69d88dSmrg 14647ec681f3Smrg/* si_pipe.c */ 14657ec681f3Smrgvoid si_init_compiler(struct si_screen *sscreen, struct ac_llvm_compiler *compiler); 14667ec681f3Smrgvoid si_init_aux_async_compute_ctx(struct si_screen *sscreen); 14677ec681f3Smrg 146801e04c3fSmrg/* si_perfcounters.c */ 146901e04c3fSmrgvoid si_init_perfcounters(struct si_screen *screen); 14709f464c52Smayavoid si_destroy_perfcounters(struct si_screen *screen); 14717ec681f3Smrgvoid si_inhibit_clockgating(struct si_context *sctx, struct radeon_cmdbuf *cs, bool inhibit); 147201e04c3fSmrg 147301e04c3fSmrg/* si_query.c */ 147401e04c3fSmrgvoid si_init_screen_query_functions(struct si_screen *sscreen); 147501e04c3fSmrgvoid si_init_query_functions(struct si_context *sctx); 147601e04c3fSmrgvoid si_suspend_queries(struct si_context *sctx); 147701e04c3fSmrgvoid si_resume_queries(struct si_context *sctx); 147801e04c3fSmrg 14797ec681f3Smrg/* si_shaderlib_nir.c */ 14807ec681f3Smrgvoid *si_create_dcc_retile_cs(struct si_context *sctx, struct radeon_surf *surf); 14817ec681f3Smrgvoid *gfx9_create_clear_dcc_msaa_cs(struct si_context *sctx, struct si_texture *tex); 14827ec681f3Smrg 148301e04c3fSmrg/* si_shaderlib_tgsi.c */ 148401e04c3fSmrgvoid *si_get_blitter_vs(struct si_context *sctx, enum blitter_attrib_type type, 14857ec681f3Smrg unsigned num_layers); 148601e04c3fSmrgvoid *si_create_fixed_func_tcs(struct si_context *sctx); 14877ec681f3Smrgvoid *si_create_dma_compute_shader(struct pipe_context *ctx, unsigned num_dwords_per_thread, 14887ec681f3Smrg bool dst_stream_cache_policy, bool is_copy); 14897ec681f3Smrgvoid *si_create_clear_buffer_rmw_cs(struct pipe_context *ctx); 14909f464c52Smayavoid *si_create_copy_image_compute_shader(struct pipe_context *ctx); 14919f464c52Smayavoid *si_create_copy_image_compute_shader_1d_array(struct pipe_context *ctx); 14927ec681f3Smrgvoid *si_create_dcc_decompress_cs(struct pipe_context *ctx); 14939f464c52Smayavoid *si_clear_render_target_shader(struct pipe_context *ctx); 14949f464c52Smayavoid *si_clear_render_target_shader_1d_array(struct pipe_context *ctx); 14957ec681f3Smrgvoid *si_clear_12bytes_buffer_shader(struct pipe_context *ctx); 14967ec681f3Smrgvoid *si_create_fmask_expand_cs(struct pipe_context *ctx, unsigned num_samples, bool is_array); 149701e04c3fSmrgvoid *si_create_query_result_cs(struct si_context *sctx); 14987ec681f3Smrgvoid *gfx10_create_sh_query_result_cs(struct si_context *sctx); 149901e04c3fSmrg 15007ec681f3Smrg/* gfx10_query.c */ 15017ec681f3Smrgvoid gfx10_init_query(struct si_context *sctx); 15027ec681f3Smrgvoid gfx10_destroy_query(struct si_context *sctx); 15037ec681f3Smrg 15047ec681f3Smrg/* si_test_blit.c */ 15057ec681f3Smrgvoid si_test_blit(struct si_screen *sscreen); 150601e04c3fSmrg 150701e04c3fSmrg/* si_test_clearbuffer.c */ 150801e04c3fSmrgvoid si_test_dma_perf(struct si_screen *sscreen); 150901e04c3fSmrg 1510af69d88dSmrg/* si_uvd.c */ 1511af69d88dSmrgstruct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context, 15127ec681f3Smrg const struct pipe_video_codec *templ); 1513af69d88dSmrg 1514af69d88dSmrgstruct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe, 15157ec681f3Smrg const struct pipe_video_buffer *tmpl); 15167ec681f3Smrgstruct pipe_video_buffer *si_video_buffer_create_with_modifiers(struct pipe_context *pipe, 15177ec681f3Smrg const struct pipe_video_buffer *tmpl, 15187ec681f3Smrg const uint64_t *modifiers, 15197ec681f3Smrg unsigned int modifiers_count); 1520af69d88dSmrg 152101e04c3fSmrg/* si_viewport.c */ 15227ec681f3Smrgvoid si_get_small_prim_cull_info(struct si_context *sctx, struct si_small_prim_cull_info *out); 152301e04c3fSmrgvoid si_update_vs_viewport_state(struct si_context *ctx); 152401e04c3fSmrgvoid si_init_viewport_functions(struct si_context *ctx); 152501e04c3fSmrg 152601e04c3fSmrg/* si_texture.c */ 15277ec681f3Smrgvoid si_eliminate_fast_color_clear(struct si_context *sctx, struct si_texture *tex, 15287ec681f3Smrg bool *ctx_flushed); 15297ec681f3Smrgvoid si_texture_discard_cmask(struct si_screen *sscreen, struct si_texture *tex); 15307ec681f3Smrgbool si_init_flushed_depth_texture(struct pipe_context *ctx, struct pipe_resource *texture); 15317ec681f3Smrgvoid si_print_texture_info(struct si_screen *sscreen, struct si_texture *tex, 15327ec681f3Smrg struct u_log_context *log); 153301e04c3fSmrgstruct pipe_resource *si_texture_create(struct pipe_screen *screen, 15347ec681f3Smrg const struct pipe_resource *templ); 15357ec681f3Smrgbool vi_dcc_formats_compatible(struct si_screen *sscreen, enum pipe_format format1, 15367ec681f3Smrg enum pipe_format format2); 15377ec681f3Smrgbool vi_dcc_formats_are_incompatible(struct pipe_resource *tex, unsigned level, 15387ec681f3Smrg enum pipe_format view_format); 15397ec681f3Smrgvoid vi_disable_dcc_if_incompatible_format(struct si_context *sctx, struct pipe_resource *tex, 15407ec681f3Smrg unsigned level, enum pipe_format view_format); 154101e04c3fSmrgstruct pipe_surface *si_create_surface_custom(struct pipe_context *pipe, 15427ec681f3Smrg struct pipe_resource *texture, 15437ec681f3Smrg const struct pipe_surface *templ, unsigned width0, 15447ec681f3Smrg unsigned height0, unsigned width, unsigned height); 154501e04c3fSmrgunsigned si_translate_colorswap(enum pipe_format format, bool do_endian_swap); 15467ec681f3Smrgbool si_texture_disable_dcc(struct si_context *sctx, struct si_texture *tex); 154701e04c3fSmrgvoid si_init_screen_texture_functions(struct si_screen *sscreen); 154801e04c3fSmrgvoid si_init_context_texture_functions(struct si_context *sctx); 154901e04c3fSmrg 15507ec681f3Smrg/* si_sqtt.c */ 15517ec681f3Smrgvoid si_sqtt_write_event_marker(struct si_context* sctx, struct radeon_cmdbuf *rcs, 15527ec681f3Smrg enum rgp_sqtt_marker_event_type api_type, 15537ec681f3Smrg uint32_t vertex_offset_user_data, 15547ec681f3Smrg uint32_t instance_offset_user_data, 15557ec681f3Smrg uint32_t draw_index_user_data); 15567ec681f3Smrgbool si_sqtt_register_pipeline(struct si_context* sctx, uint64_t pipeline_hash, uint64_t base_address, bool is_compute); 15577ec681f3Smrgbool si_sqtt_pipeline_is_registered(struct ac_thread_trace_data *thread_trace_data, 15587ec681f3Smrg uint64_t pipeline_hash); 15597ec681f3Smrgvoid si_sqtt_describe_pipeline_bind(struct si_context* sctx, uint64_t pipeline_hash, int bind_point); 15607ec681f3Smrgvoid 15617ec681f3Smrgsi_write_event_with_dims_marker(struct si_context* sctx, struct radeon_cmdbuf *rcs, 15627ec681f3Smrg enum rgp_sqtt_marker_event_type api_type, 15637ec681f3Smrg uint32_t x, uint32_t y, uint32_t z); 15647ec681f3Smrgvoid 15657ec681f3Smrgsi_write_user_event(struct si_context* sctx, struct radeon_cmdbuf *rcs, 15667ec681f3Smrg enum rgp_sqtt_marker_user_event_type type, 15677ec681f3Smrg const char *str, int len); 15687ec681f3Smrgvoid 15697ec681f3Smrgsi_sqtt_describe_barrier_start(struct si_context* sctx, struct radeon_cmdbuf *rcs); 15707ec681f3Smrgvoid 15717ec681f3Smrgsi_sqtt_describe_barrier_end(struct si_context* sctx, struct radeon_cmdbuf *rcs, unsigned flags); 15727ec681f3Smrgbool si_init_thread_trace(struct si_context *sctx); 15737ec681f3Smrgvoid si_destroy_thread_trace(struct si_context *sctx); 15747ec681f3Smrgvoid si_handle_thread_trace(struct si_context *sctx, struct radeon_cmdbuf *rcs); 15757ec681f3Smrg 15767ec681f3Smrg/* si_state_shaders.c */ 15777ec681f3Smrgstruct si_pm4_state *si_build_vgt_shader_config(struct si_screen *screen, union si_vgt_stages_key key); 157801e04c3fSmrg 1579af69d88dSmrg/* 1580af69d88dSmrg * common helpers 1581af69d88dSmrg */ 1582af69d88dSmrg 15839f464c52Smayastatic inline struct si_resource *si_resource(struct pipe_resource *r) 158401e04c3fSmrg{ 15857ec681f3Smrg return (struct si_resource *)r; 158601e04c3fSmrg} 158701e04c3fSmrg 15887ec681f3Smrgstatic inline void si_resource_reference(struct si_resource **ptr, struct si_resource *res) 15897ec681f3Smrg{ 15907ec681f3Smrg pipe_resource_reference((struct pipe_resource **)ptr, (struct pipe_resource *)res); 15917ec681f3Smrg} 15927ec681f3Smrg 15937ec681f3Smrgstatic inline void si_texture_reference(struct si_texture **ptr, struct si_texture *res) 159401e04c3fSmrg{ 15957ec681f3Smrg pipe_resource_reference((struct pipe_resource **)ptr, &res->buffer.b.b); 159601e04c3fSmrg} 159701e04c3fSmrg 159801e04c3fSmrgstatic inline void 15997ec681f3Smrgsi_shader_selector_reference(struct si_context *sctx, /* sctx can optionally be NULL */ 16007ec681f3Smrg struct si_shader_selector **dst, struct si_shader_selector *src) 16017ec681f3Smrg{ 16027ec681f3Smrg if (*dst == src) 16037ec681f3Smrg return; 16047ec681f3Smrg 16057ec681f3Smrg struct si_screen *sscreen = src ? src->screen : (*dst)->screen; 16067ec681f3Smrg util_shader_reference(&sctx->b, &sscreen->live_shader_cache, (void **)dst, src); 16077ec681f3Smrg} 16087ec681f3Smrg 16097ec681f3Smrgstatic inline bool vi_dcc_enabled(struct si_texture *tex, unsigned level) 161001e04c3fSmrg{ 16117ec681f3Smrg return !tex->is_depth && tex->surface.meta_offset && level < tex->surface.num_meta_levels; 161201e04c3fSmrg} 161301e04c3fSmrg 16147ec681f3Smrgstatic inline unsigned si_tile_mode_index(struct si_texture *tex, unsigned level, bool stencil) 161501e04c3fSmrg{ 16167ec681f3Smrg if (stencil) 16177ec681f3Smrg return tex->surface.u.legacy.zs.stencil_tiling_index[level]; 16187ec681f3Smrg else 16197ec681f3Smrg return tex->surface.u.legacy.tiling_index[level]; 162001e04c3fSmrg} 162101e04c3fSmrg 16227ec681f3Smrgstatic inline unsigned si_get_minimum_num_gfx_cs_dwords(struct si_context *sctx, 16237ec681f3Smrg unsigned num_draws) 162401e04c3fSmrg{ 16257ec681f3Smrg /* Don't count the needed CS space exactly and just use an upper bound. 16267ec681f3Smrg * 16277ec681f3Smrg * Also reserve space for stopping queries at the end of IB, because 16287ec681f3Smrg * the number of active queries is unlimited in theory. 16297ec681f3Smrg */ 16307ec681f3Smrg return 2048 + sctx->num_cs_dw_queries_suspend + num_draws * 10; 163101e04c3fSmrg} 163201e04c3fSmrg 16337ec681f3Smrgstatic inline void si_context_add_resource_size(struct si_context *sctx, struct pipe_resource *r) 16349f464c52Smaya{ 16357ec681f3Smrg if (r) { 16367ec681f3Smrg /* Add memory usage for need_gfx_cs_space */ 16377ec681f3Smrg sctx->memory_usage_kb += si_resource(r)->memory_usage_kb; 16387ec681f3Smrg } 16399f464c52Smaya} 16409f464c52Smaya 16417ec681f3Smrgstatic inline void si_invalidate_draw_sh_constants(struct si_context *sctx) 164201e04c3fSmrg{ 16437ec681f3Smrg sctx->last_base_vertex = SI_BASE_VERTEX_UNKNOWN; 16447ec681f3Smrg sctx->last_start_instance = SI_START_INSTANCE_UNKNOWN; 16457ec681f3Smrg sctx->last_drawid = SI_DRAW_ID_UNKNOWN; 164601e04c3fSmrg} 164701e04c3fSmrg 16487ec681f3Smrgstatic inline void si_invalidate_draw_constants(struct si_context *sctx) 164901e04c3fSmrg{ 16507ec681f3Smrg si_invalidate_draw_sh_constants(sctx); 16517ec681f3Smrg sctx->last_instance_count = SI_INSTANCE_COUNT_UNKNOWN; 165201e04c3fSmrg} 165301e04c3fSmrg 16547ec681f3Smrgstatic inline unsigned si_get_atom_bit(struct si_context *sctx, struct si_atom *atom) 165501e04c3fSmrg{ 16567ec681f3Smrg return 1 << (atom - sctx->atoms.array); 165701e04c3fSmrg} 165801e04c3fSmrg 16597ec681f3Smrgstatic inline void si_set_atom_dirty(struct si_context *sctx, struct si_atom *atom, bool dirty) 166001e04c3fSmrg{ 16617ec681f3Smrg unsigned bit = si_get_atom_bit(sctx, atom); 166201e04c3fSmrg 16637ec681f3Smrg if (dirty) 16647ec681f3Smrg sctx->dirty_atoms |= bit; 16657ec681f3Smrg else 16667ec681f3Smrg sctx->dirty_atoms &= ~bit; 166701e04c3fSmrg} 166801e04c3fSmrg 16697ec681f3Smrgstatic inline bool si_is_atom_dirty(struct si_context *sctx, struct si_atom *atom) 167001e04c3fSmrg{ 16717ec681f3Smrg return (sctx->dirty_atoms & si_get_atom_bit(sctx, atom)) != 0; 167201e04c3fSmrg} 167301e04c3fSmrg 16747ec681f3Smrgstatic inline void si_mark_atom_dirty(struct si_context *sctx, struct si_atom *atom) 167501e04c3fSmrg{ 16767ec681f3Smrg si_set_atom_dirty(sctx, atom, true); 167701e04c3fSmrg} 167801e04c3fSmrg 16797ec681f3Smrg/* This should be evaluated at compile time if all parameters except sctx are constants. */ 16807ec681f3Smrgstatic ALWAYS_INLINE struct si_shader_ctx_state * 16817ec681f3Smrgsi_get_vs_inline(struct si_context *sctx, enum si_has_tess has_tess, enum si_has_gs has_gs) 168201e04c3fSmrg{ 16837ec681f3Smrg if (has_gs) 16847ec681f3Smrg return &sctx->shader.gs; 16857ec681f3Smrg if (has_tess) 16867ec681f3Smrg return &sctx->shader.tes; 168701e04c3fSmrg 16887ec681f3Smrg return &sctx->shader.vs; 168901e04c3fSmrg} 169001e04c3fSmrg 16917ec681f3Smrgstatic inline struct si_shader_ctx_state *si_get_vs(struct si_context *sctx) 169201e04c3fSmrg{ 16937ec681f3Smrg return si_get_vs_inline(sctx, sctx->shader.tes.cso ? TESS_ON : TESS_OFF, 16947ec681f3Smrg sctx->shader.gs.cso ? GS_ON : GS_OFF); 169501e04c3fSmrg} 169601e04c3fSmrg 16977ec681f3Smrgstatic inline struct si_shader_info *si_get_vs_info(struct si_context *sctx) 169801e04c3fSmrg{ 16997ec681f3Smrg struct si_shader_ctx_state *vs = si_get_vs(sctx); 170001e04c3fSmrg 17017ec681f3Smrg return vs->cso ? &vs->cso->info : NULL; 170201e04c3fSmrg} 170301e04c3fSmrg 17047ec681f3Smrgstatic inline bool si_can_dump_shader(struct si_screen *sscreen, gl_shader_stage stage) 170501e04c3fSmrg{ 17067ec681f3Smrg return sscreen->debug_flags & (1 << stage); 170701e04c3fSmrg} 170801e04c3fSmrg 170901e04c3fSmrgstatic inline bool si_get_strmout_en(struct si_context *sctx) 171001e04c3fSmrg{ 17117ec681f3Smrg return sctx->streamout.streamout_enabled || sctx->streamout.prims_gen_query_enabled; 171201e04c3fSmrg} 171301e04c3fSmrg 17147ec681f3Smrgstatic inline unsigned si_optimal_tcc_alignment(struct si_context *sctx, unsigned upload_size) 171501e04c3fSmrg{ 17167ec681f3Smrg unsigned alignment, tcc_cache_line_size; 17177ec681f3Smrg 17187ec681f3Smrg /* If the upload size is less than the cache line size (e.g. 16, 32), 17197ec681f3Smrg * the whole thing will fit into a cache line if we align it to its size. 17207ec681f3Smrg * The idea is that multiple small uploads can share a cache line. 17217ec681f3Smrg * If the upload size is greater, align it to the cache line size. 17227ec681f3Smrg */ 17237ec681f3Smrg alignment = util_next_power_of_two(upload_size); 17247ec681f3Smrg tcc_cache_line_size = sctx->screen->info.tcc_cache_line_size; 17257ec681f3Smrg return MIN2(alignment, tcc_cache_line_size); 172601e04c3fSmrg} 172701e04c3fSmrg 17287ec681f3Smrgstatic inline void si_saved_cs_reference(struct si_saved_cs **dst, struct si_saved_cs *src) 172901e04c3fSmrg{ 17307ec681f3Smrg if (pipe_reference(&(*dst)->reference, &src->reference)) 17317ec681f3Smrg si_destroy_saved_cs(*dst); 173201e04c3fSmrg 17337ec681f3Smrg *dst = src; 173401e04c3fSmrg} 173501e04c3fSmrg 17367ec681f3Smrgstatic inline void si_make_CB_shader_coherent(struct si_context *sctx, unsigned num_samples, 17377ec681f3Smrg bool shaders_read_metadata, bool dcc_pipe_aligned) 173801e04c3fSmrg{ 17397ec681f3Smrg sctx->flags |= SI_CONTEXT_FLUSH_AND_INV_CB | SI_CONTEXT_INV_VCACHE; 17407ec681f3Smrg sctx->force_cb_shader_coherent = false; 17417ec681f3Smrg 17427ec681f3Smrg if (sctx->chip_class >= GFX10) { 17437ec681f3Smrg if (sctx->screen->info.tcc_rb_non_coherent) 17447ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17457ec681f3Smrg else if (shaders_read_metadata) 17467ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2_METADATA; 17477ec681f3Smrg } else if (sctx->chip_class == GFX9) { 17487ec681f3Smrg /* Single-sample color is coherent with shaders on GFX9, but 17497ec681f3Smrg * L2 metadata must be flushed if shaders read metadata. 17507ec681f3Smrg * (DCC, CMASK). 17517ec681f3Smrg */ 17527ec681f3Smrg if (num_samples >= 2 || (shaders_read_metadata && !dcc_pipe_aligned)) 17537ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17547ec681f3Smrg else if (shaders_read_metadata) 17557ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2_METADATA; 17567ec681f3Smrg } else { 17577ec681f3Smrg /* GFX6-GFX8 */ 17587ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17597ec681f3Smrg } 176001e04c3fSmrg} 176101e04c3fSmrg 17627ec681f3Smrgstatic inline void si_make_DB_shader_coherent(struct si_context *sctx, unsigned num_samples, 17637ec681f3Smrg bool include_stencil, bool shaders_read_metadata) 176401e04c3fSmrg{ 17657ec681f3Smrg sctx->flags |= SI_CONTEXT_FLUSH_AND_INV_DB | SI_CONTEXT_INV_VCACHE; 17667ec681f3Smrg 17677ec681f3Smrg if (sctx->chip_class >= GFX10) { 17687ec681f3Smrg if (sctx->screen->info.tcc_rb_non_coherent) 17697ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17707ec681f3Smrg else if (shaders_read_metadata) 17717ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2_METADATA; 17727ec681f3Smrg } else if (sctx->chip_class == GFX9) { 17737ec681f3Smrg /* Single-sample depth (not stencil) is coherent with shaders 17747ec681f3Smrg * on GFX9, but L2 metadata must be flushed if shaders read 17757ec681f3Smrg * metadata. 17767ec681f3Smrg */ 17777ec681f3Smrg if (num_samples >= 2 || include_stencil) 17787ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17797ec681f3Smrg else if (shaders_read_metadata) 17807ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2_METADATA; 17817ec681f3Smrg } else { 17827ec681f3Smrg /* GFX6-GFX8 */ 17837ec681f3Smrg sctx->flags |= SI_CONTEXT_INV_L2; 17847ec681f3Smrg } 178501e04c3fSmrg} 178601e04c3fSmrg 17877ec681f3Smrgstatic inline bool si_can_sample_zs(struct si_texture *tex, bool stencil_sampler) 178801e04c3fSmrg{ 17897ec681f3Smrg return (stencil_sampler && tex->can_sample_s) || (!stencil_sampler && tex->can_sample_z); 179001e04c3fSmrg} 179101e04c3fSmrg 17927ec681f3Smrgstatic inline bool si_htile_enabled(struct si_texture *tex, unsigned level, unsigned zs_mask) 179301e04c3fSmrg{ 17947ec681f3Smrg if (zs_mask == PIPE_MASK_S && (tex->htile_stencil_disabled || !tex->surface.has_stencil)) 17957ec681f3Smrg return false; 17967ec681f3Smrg 17977ec681f3Smrg if (!tex->is_depth || !tex->surface.meta_offset) 17987ec681f3Smrg return false; 17997ec681f3Smrg 18007ec681f3Smrg struct si_screen *sscreen = (struct si_screen *)tex->buffer.b.b.screen; 18017ec681f3Smrg if (sscreen->info.chip_class >= GFX8) { 18027ec681f3Smrg return level < tex->surface.num_meta_levels; 18037ec681f3Smrg } else { 18047ec681f3Smrg /* GFX6-7 don't have TC-compatible HTILE, which means they have to run 18057ec681f3Smrg * a decompression pass for every mipmap level before texturing, so compress 18067ec681f3Smrg * only one level to reduce the number of decompression passes to a minimum. 18077ec681f3Smrg */ 18087ec681f3Smrg return level == 0; 18097ec681f3Smrg } 181001e04c3fSmrg} 181101e04c3fSmrg 18127ec681f3Smrgstatic inline bool vi_tc_compat_htile_enabled(struct si_texture *tex, unsigned level, 18137ec681f3Smrg unsigned zs_mask) 181401e04c3fSmrg{ 18157ec681f3Smrg assert(!tex->tc_compatible_htile || tex->surface.meta_offset); 18167ec681f3Smrg return tex->tc_compatible_htile && si_htile_enabled(tex, level, zs_mask); 181701e04c3fSmrg} 181801e04c3fSmrg 181901e04c3fSmrgstatic inline unsigned si_get_ps_iter_samples(struct si_context *sctx) 182001e04c3fSmrg{ 18217ec681f3Smrg if (sctx->ps_uses_fbfetch) 18227ec681f3Smrg return sctx->framebuffer.nr_color_samples; 182301e04c3fSmrg 18247ec681f3Smrg return MIN2(sctx->ps_iter_samples, sctx->framebuffer.nr_color_samples); 182501e04c3fSmrg} 182601e04c3fSmrg 182701e04c3fSmrgstatic inline unsigned si_get_total_colormask(struct si_context *sctx) 182801e04c3fSmrg{ 18297ec681f3Smrg if (sctx->queued.named.rasterizer->rasterizer_discard) 18307ec681f3Smrg return 0; 183101e04c3fSmrg 18327ec681f3Smrg struct si_shader_selector *ps = sctx->shader.ps.cso; 18337ec681f3Smrg if (!ps) 18347ec681f3Smrg return 0; 183501e04c3fSmrg 18367ec681f3Smrg unsigned colormask = 18377ec681f3Smrg sctx->framebuffer.colorbuf_enabled_4bit & sctx->queued.named.blend->cb_target_mask; 183801e04c3fSmrg 18397ec681f3Smrg if (!ps->info.color0_writes_all_cbufs) 18407ec681f3Smrg colormask &= ps->colors_written_4bit; 18417ec681f3Smrg else if (!ps->colors_written_4bit) 18427ec681f3Smrg colormask = 0; /* color0 writes all cbufs, but it's not written */ 184301e04c3fSmrg 18447ec681f3Smrg return colormask; 184501e04c3fSmrg} 184601e04c3fSmrg 18477ec681f3Smrg#define UTIL_ALL_PRIM_LINE_MODES \ 18487ec681f3Smrg ((1 << PIPE_PRIM_LINES) | (1 << PIPE_PRIM_LINE_LOOP) | (1 << PIPE_PRIM_LINE_STRIP) | \ 18497ec681f3Smrg (1 << PIPE_PRIM_LINES_ADJACENCY) | (1 << PIPE_PRIM_LINE_STRIP_ADJACENCY)) 18507ec681f3Smrg 18517ec681f3Smrg#define UTIL_ALL_PRIM_TRIANGLE_MODES \ 18527ec681f3Smrg ((1 << PIPE_PRIM_TRIANGLES) | (1 << PIPE_PRIM_TRIANGLE_STRIP) | \ 18537ec681f3Smrg (1 << PIPE_PRIM_TRIANGLE_FAN) | (1 << PIPE_PRIM_QUADS) | (1 << PIPE_PRIM_QUAD_STRIP) | \ 18547ec681f3Smrg (1 << PIPE_PRIM_POLYGON) | (1 << PIPE_PRIM_TRIANGLES_ADJACENCY) | \ 18557ec681f3Smrg (1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY)) 185601e04c3fSmrg 185701e04c3fSmrgstatic inline bool util_prim_is_lines(unsigned prim) 185801e04c3fSmrg{ 18597ec681f3Smrg return ((1 << prim) & UTIL_ALL_PRIM_LINE_MODES) != 0; 186001e04c3fSmrg} 186101e04c3fSmrg 186201e04c3fSmrgstatic inline bool util_prim_is_points_or_lines(unsigned prim) 186301e04c3fSmrg{ 18647ec681f3Smrg return ((1 << prim) & (UTIL_ALL_PRIM_LINE_MODES | (1 << PIPE_PRIM_POINTS))) != 0; 18657ec681f3Smrg} 18667ec681f3Smrg 18677ec681f3Smrgstatic inline bool util_rast_prim_is_triangles(unsigned prim) 18687ec681f3Smrg{ 18697ec681f3Smrg return ((1 << prim) & UTIL_ALL_PRIM_TRIANGLE_MODES) != 0; 18707ec681f3Smrg} 18717ec681f3Smrg 18727ec681f3Smrgstatic inline bool util_rast_prim_is_lines_or_triangles(unsigned prim) 18737ec681f3Smrg{ 18747ec681f3Smrg return ((1 << prim) & (UTIL_ALL_PRIM_LINE_MODES | UTIL_ALL_PRIM_TRIANGLE_MODES)) != 0; 187501e04c3fSmrg} 187601e04c3fSmrg 187701e04c3fSmrg/** 187801e04c3fSmrg * Return true if there is enough memory in VRAM and GTT for the buffers 187901e04c3fSmrg * added so far. 188001e04c3fSmrg * 188101e04c3fSmrg * \param vram VRAM memory size not added to the buffer list yet 188201e04c3fSmrg * \param gtt GTT memory size not added to the buffer list yet 188301e04c3fSmrg */ 18847ec681f3Smrgstatic inline bool radeon_cs_memory_below_limit(struct si_screen *screen, struct radeon_cmdbuf *cs, 18857ec681f3Smrg uint32_t kb) 18867ec681f3Smrg{ 18877ec681f3Smrg return kb + cs->used_vram_kb + cs->used_gart_kb < screen->max_memory_usage_kb; 18887ec681f3Smrg} 18897ec681f3Smrg 18907ec681f3Smrgstatic inline void si_need_gfx_cs_space(struct si_context *ctx, unsigned num_draws) 189101e04c3fSmrg{ 18927ec681f3Smrg struct radeon_cmdbuf *cs = &ctx->gfx_cs; 18937ec681f3Smrg 18947ec681f3Smrg /* There are two memory usage counters in the winsys for all buffers 18957ec681f3Smrg * that have been added (cs_add_buffer) and one counter in the pipe 18967ec681f3Smrg * driver for those that haven't been added yet. 18977ec681f3Smrg */ 18987ec681f3Smrg uint32_t kb = ctx->memory_usage_kb; 18997ec681f3Smrg ctx->memory_usage_kb = 0; 190001e04c3fSmrg 19017ec681f3Smrg if (radeon_cs_memory_below_limit(ctx->screen, &ctx->gfx_cs, kb) && 19027ec681f3Smrg ctx->ws->cs_check_space(cs, si_get_minimum_num_gfx_cs_dwords(ctx, num_draws), false)) 19037ec681f3Smrg return; 190401e04c3fSmrg 19057ec681f3Smrg si_flush_gfx_cs(ctx, RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW, NULL); 190601e04c3fSmrg} 190701e04c3fSmrg 190801e04c3fSmrg/** 190901e04c3fSmrg * Add a buffer to the buffer list for the given command stream (CS). 191001e04c3fSmrg * 191101e04c3fSmrg * All buffers used by a CS must be added to the list. This tells the kernel 191201e04c3fSmrg * driver which buffers are used by GPU commands. Other buffers can 191301e04c3fSmrg * be swapped out (not accessible) during execution. 191401e04c3fSmrg * 191501e04c3fSmrg * The buffer list becomes empty after every context flush and must be 191601e04c3fSmrg * rebuilt. 191701e04c3fSmrg */ 19187ec681f3Smrgstatic inline void radeon_add_to_buffer_list(struct si_context *sctx, struct radeon_cmdbuf *cs, 19197ec681f3Smrg struct si_resource *bo, enum radeon_bo_usage usage, 19207ec681f3Smrg enum radeon_bo_priority priority) 192101e04c3fSmrg{ 19227ec681f3Smrg assert(usage); 19237ec681f3Smrg sctx->ws->cs_add_buffer(cs, bo->buf, (enum radeon_bo_usage)(usage | RADEON_USAGE_SYNCHRONIZED), 19247ec681f3Smrg bo->domains, priority); 192501e04c3fSmrg} 192601e04c3fSmrg 192701e04c3fSmrg/** 192801e04c3fSmrg * Same as above, but also checks memory usage and flushes the context 192901e04c3fSmrg * accordingly. 193001e04c3fSmrg * 193101e04c3fSmrg * When this SHOULD NOT be used: 193201e04c3fSmrg * 193301e04c3fSmrg * - if si_context_add_resource_size has been called for the buffer 193401e04c3fSmrg * followed by *_need_cs_space for checking the memory usage 193501e04c3fSmrg * 193601e04c3fSmrg * - when emitting state packets and draw packets (because preceding packets 193701e04c3fSmrg * can't be re-emitted at that point) 193801e04c3fSmrg * 193901e04c3fSmrg * - if shader resource "enabled_mask" is not up-to-date or there is 194001e04c3fSmrg * a different constraint disallowing a context flush 194101e04c3fSmrg */ 19427ec681f3Smrgstatic inline void radeon_add_to_gfx_buffer_list_check_mem(struct si_context *sctx, 19437ec681f3Smrg struct si_resource *bo, 19447ec681f3Smrg enum radeon_bo_usage usage, 19457ec681f3Smrg enum radeon_bo_priority priority, 19467ec681f3Smrg bool check_mem) 1947af69d88dSmrg{ 19487ec681f3Smrg if (check_mem && 19497ec681f3Smrg !radeon_cs_memory_below_limit(sctx->screen, &sctx->gfx_cs, sctx->memory_usage_kb + bo->memory_usage_kb)) 19507ec681f3Smrg si_flush_gfx_cs(sctx, RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW, NULL); 19517ec681f3Smrg 19527ec681f3Smrg radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, bo, usage, priority); 19537ec681f3Smrg} 195401e04c3fSmrg 19557ec681f3Smrgstatic inline unsigned si_get_wave_size(struct si_screen *sscreen, 19567ec681f3Smrg gl_shader_stage stage, bool ngg, bool es) 19577ec681f3Smrg{ 19587ec681f3Smrg if (stage == MESA_SHADER_COMPUTE) 19597ec681f3Smrg return sscreen->compute_wave_size; 19607ec681f3Smrg else if (stage == MESA_SHADER_FRAGMENT) 19617ec681f3Smrg return sscreen->ps_wave_size; 19627ec681f3Smrg else if ((stage == MESA_SHADER_VERTEX && es && !ngg) || 19637ec681f3Smrg (stage == MESA_SHADER_TESS_EVAL && es && !ngg) || 19647ec681f3Smrg (stage == MESA_SHADER_GEOMETRY && !ngg)) /* legacy GS only supports Wave64 */ 19657ec681f3Smrg return 64; 19667ec681f3Smrg else 19677ec681f3Smrg return sscreen->ge_wave_size; 19687ec681f3Smrg} 19697ec681f3Smrg 19707ec681f3Smrgstatic inline unsigned si_get_shader_wave_size(struct si_shader *shader) 19717ec681f3Smrg{ 19727ec681f3Smrg return si_get_wave_size(shader->selector->screen, shader->selector->info.stage, 19737ec681f3Smrg shader->key.as_ngg, 19747ec681f3Smrg shader->key.as_es); 1975af69d88dSmrg} 1976af69d88dSmrg 19777ec681f3Smrgstatic inline void si_select_draw_vbo(struct si_context *sctx) 19787ec681f3Smrg{ 19797ec681f3Smrg pipe_draw_vbo_func draw_vbo = sctx->draw_vbo[!!sctx->shader.tes.cso] 19807ec681f3Smrg [!!sctx->shader.gs.cso] 19817ec681f3Smrg [sctx->ngg]; 19827ec681f3Smrg pipe_draw_vertex_state_func draw_vertex_state = 19837ec681f3Smrg sctx->draw_vertex_state[!!sctx->shader.tes.cso] 19847ec681f3Smrg [!!sctx->shader.gs.cso] 19857ec681f3Smrg [sctx->ngg]; 19867ec681f3Smrg assert(draw_vbo); 19877ec681f3Smrg assert(draw_vertex_state); 19887ec681f3Smrg 19897ec681f3Smrg if (unlikely(sctx->real_draw_vbo)) { 19907ec681f3Smrg assert(sctx->real_draw_vertex_state); 19917ec681f3Smrg sctx->real_draw_vbo = draw_vbo; 19927ec681f3Smrg sctx->real_draw_vertex_state = draw_vertex_state; 19937ec681f3Smrg } else { 19947ec681f3Smrg assert(!sctx->real_draw_vertex_state); 19957ec681f3Smrg sctx->b.draw_vbo = draw_vbo; 19967ec681f3Smrg sctx->b.draw_vertex_state = draw_vertex_state; 19977ec681f3Smrg } 19987ec681f3Smrg} 19997ec681f3Smrg 20007ec681f3Smrg/* Return the number of samples that the rasterizer uses. */ 20017ec681f3Smrgstatic inline unsigned si_get_num_coverage_samples(struct si_context *sctx) 20027ec681f3Smrg{ 20037ec681f3Smrg if (sctx->framebuffer.nr_samples > 1 && 20047ec681f3Smrg sctx->queued.named.rasterizer->multisample_enable) 20057ec681f3Smrg return sctx->framebuffer.nr_samples; 20067ec681f3Smrg 20077ec681f3Smrg /* Note that smoothing_enabled is set by si_update_shaders. */ 20087ec681f3Smrg if (sctx->smoothing_enabled) 20097ec681f3Smrg return SI_NUM_SMOOTH_AA_SAMPLES; 20107ec681f3Smrg 20117ec681f3Smrg return 1; 20127ec681f3Smrg} 20137ec681f3Smrg 20147ec681f3Smrgstatic unsigned ALWAYS_INLINE 20157ec681f3Smrgsi_num_vbos_in_user_sgprs_inline(enum chip_class chip_class) 20167ec681f3Smrg{ 20177ec681f3Smrg /* This decreases CPU overhead if all descriptors are in user SGPRs because we don't 20187ec681f3Smrg * have to allocate and count references for the upload buffer. 20197ec681f3Smrg */ 20207ec681f3Smrg return chip_class >= GFX9 ? 5 : 1; 20217ec681f3Smrg} 20227ec681f3Smrg 20237ec681f3Smrgstatic inline unsigned si_num_vbos_in_user_sgprs(struct si_screen *sscreen) 20247ec681f3Smrg{ 20257ec681f3Smrg return si_num_vbos_in_user_sgprs_inline(sscreen->info.chip_class); 20267ec681f3Smrg} 20277ec681f3Smrg 20287ec681f3Smrg#define PRINT_ERR(fmt, args...) \ 20297ec681f3Smrg fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args) 20307ec681f3Smrg 20317ec681f3Smrgstruct pipe_resource *si_buffer_from_winsys_buffer(struct pipe_screen *screen, 20327ec681f3Smrg const struct pipe_resource *templ, 20337ec681f3Smrg struct pb_buffer *imported_buf, 20347ec681f3Smrg bool dedicated); 20357ec681f3Smrg 20367ec681f3Smrg#ifdef __cplusplus 20377ec681f3Smrg} 20387ec681f3Smrg#endif 203901e04c3fSmrg 2040af69d88dSmrg#endif 2041