1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3bf215546Sopenharmony_ci * Copyright 2018 Advanced Micro Devices, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
10bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
11bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
15bf215546Sopenharmony_ci * Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci#ifndef SI_PIPE_H
26bf215546Sopenharmony_ci#define SI_PIPE_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "si_shader.h"
29bf215546Sopenharmony_ci#include "si_state.h"
30bf215546Sopenharmony_ci#include "util/u_dynarray.h"
31bf215546Sopenharmony_ci#include "util/u_idalloc.h"
32bf215546Sopenharmony_ci#include "util/u_suballoc.h"
33bf215546Sopenharmony_ci#include "util/u_threaded_context.h"
34bf215546Sopenharmony_ci#include "util/u_vertex_state_cache.h"
35bf215546Sopenharmony_ci#include "ac_sqtt.h"
36bf215546Sopenharmony_ci#include "ac_spm.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#ifdef __cplusplus
39bf215546Sopenharmony_ciextern "C" {
40bf215546Sopenharmony_ci#endif
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#if UTIL_ARCH_BIG_ENDIAN
43bf215546Sopenharmony_ci#define SI_BIG_ENDIAN 1
44bf215546Sopenharmony_ci#else
45bf215546Sopenharmony_ci#define SI_BIG_ENDIAN 0
46bf215546Sopenharmony_ci#endif
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci#define ATI_VENDOR_ID         0x1002
49bf215546Sopenharmony_ci#define SI_NOT_QUERY          0xffffffff
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci/* The base vertex and primitive restart can be any number, but we must pick
52bf215546Sopenharmony_ci * one which will mean "unknown" for the purpose of state tracking and
53bf215546Sopenharmony_ci * the number shouldn't be a commonly-used one. */
54bf215546Sopenharmony_ci#define SI_BASE_VERTEX_UNKNOWN    INT_MIN
55bf215546Sopenharmony_ci#define SI_START_INSTANCE_UNKNOWN ((unsigned)INT_MIN)
56bf215546Sopenharmony_ci#define SI_DRAW_ID_UNKNOWN        ((unsigned)INT_MIN)
57bf215546Sopenharmony_ci#define SI_RESTART_INDEX_UNKNOWN  ((unsigned)INT_MIN)
58bf215546Sopenharmony_ci#define SI_INSTANCE_COUNT_UNKNOWN ((unsigned)INT_MIN)
59bf215546Sopenharmony_ci#define SI_NUM_SMOOTH_AA_SAMPLES  4
60bf215546Sopenharmony_ci#define SI_MAX_POINT_SIZE         2048
61bf215546Sopenharmony_ci#define SI_GS_PER_ES              128
62bf215546Sopenharmony_ci/* Alignment for optimal CP DMA performance. */
63bf215546Sopenharmony_ci#define SI_CPDMA_ALIGNMENT 32
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/* Tunables for compute-based clear_buffer and copy_buffer: */
66bf215546Sopenharmony_ci#define SI_COMPUTE_CLEAR_DW_PER_THREAD 4
67bf215546Sopenharmony_ci#define SI_COMPUTE_COPY_DW_PER_THREAD  4
68bf215546Sopenharmony_ci/* L2 LRU is recommended because the compute shader can finish sooner due to fewer L2 evictions. */
69bf215546Sopenharmony_ci#define SI_COMPUTE_DST_CACHE_POLICY    L2_LRU
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci/* Pipeline & streamout query controls. */
72bf215546Sopenharmony_ci#define SI_CONTEXT_START_PIPELINE_STATS  (1 << 0)
73bf215546Sopenharmony_ci#define SI_CONTEXT_STOP_PIPELINE_STATS   (1 << 1)
74bf215546Sopenharmony_ci#define SI_CONTEXT_FLUSH_FOR_RENDER_COND (1 << 2)
75bf215546Sopenharmony_ci/* Instruction cache. */
76bf215546Sopenharmony_ci#define SI_CONTEXT_INV_ICACHE (1 << 3)
77bf215546Sopenharmony_ci/* Scalar cache. (GFX6-9: scalar L1; GFX10: scalar L0)
78bf215546Sopenharmony_ci * GFX10: This also invalidates the L1 shader array cache. */
79bf215546Sopenharmony_ci#define SI_CONTEXT_INV_SCACHE (1 << 4)
80bf215546Sopenharmony_ci/* Vector cache. (GFX6-9: vector L1; GFX10: vector L0)
81bf215546Sopenharmony_ci * GFX10: This also invalidates the L1 shader array cache. */
82bf215546Sopenharmony_ci#define SI_CONTEXT_INV_VCACHE (1 << 5)
83bf215546Sopenharmony_ci/* L2 cache + L2 metadata cache writeback & invalidate.
84bf215546Sopenharmony_ci * GFX6-8: Used by shaders only. GFX9-10: Used by everything. */
85bf215546Sopenharmony_ci#define SI_CONTEXT_INV_L2 (1 << 6)
86bf215546Sopenharmony_ci/* L2 writeback (write dirty L2 lines to memory for non-L2 clients).
87bf215546Sopenharmony_ci * Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8.
88bf215546Sopenharmony_ci * GFX6-7 will do complete invalidation, because the writeback is unsupported. */
89bf215546Sopenharmony_ci#define SI_CONTEXT_WB_L2 (1 << 7)
90bf215546Sopenharmony_ci/* Writeback & invalidate the L2 metadata cache only. It can only be coupled with
91bf215546Sopenharmony_ci * a CB or DB flush. */
92bf215546Sopenharmony_ci#define SI_CONTEXT_INV_L2_METADATA (1 << 8)
93bf215546Sopenharmony_ci/* Framebuffer caches. */
94bf215546Sopenharmony_ci#define SI_CONTEXT_FLUSH_AND_INV_DB      (1 << 9)
95bf215546Sopenharmony_ci#define SI_CONTEXT_FLUSH_AND_INV_DB_META (1 << 10)
96bf215546Sopenharmony_ci#define SI_CONTEXT_FLUSH_AND_INV_CB      (1 << 11)
97bf215546Sopenharmony_ci/* Engine synchronization. */
98bf215546Sopenharmony_ci#define SI_CONTEXT_VS_PARTIAL_FLUSH   (1 << 12)
99bf215546Sopenharmony_ci#define SI_CONTEXT_PS_PARTIAL_FLUSH   (1 << 13)
100bf215546Sopenharmony_ci#define SI_CONTEXT_CS_PARTIAL_FLUSH   (1 << 14)
101bf215546Sopenharmony_ci#define SI_CONTEXT_VGT_FLUSH          (1 << 15)
102bf215546Sopenharmony_ci#define SI_CONTEXT_VGT_STREAMOUT_SYNC (1 << 16)
103bf215546Sopenharmony_ci/* PFP waits for ME to finish. Used to sync for index and indirect buffers and render
104bf215546Sopenharmony_ci * condition. It's typically set when doing a VS/PS/CS partial flush for buffers. */
105bf215546Sopenharmony_ci#define SI_CONTEXT_PFP_SYNC_ME        (1 << 17)
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci#define SI_PREFETCH_LS              (1 << 1)
108bf215546Sopenharmony_ci#define SI_PREFETCH_HS              (1 << 2)
109bf215546Sopenharmony_ci#define SI_PREFETCH_ES              (1 << 3)
110bf215546Sopenharmony_ci#define SI_PREFETCH_GS              (1 << 4)
111bf215546Sopenharmony_ci#define SI_PREFETCH_VS              (1 << 5)
112bf215546Sopenharmony_ci#define SI_PREFETCH_PS              (1 << 6)
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci#define SI_MAX_BORDER_COLORS              4096
115bf215546Sopenharmony_ci#define SI_MAX_VIEWPORTS                  16
116bf215546Sopenharmony_ci#define SI_MAP_BUFFER_ALIGNMENT           64
117bf215546Sopenharmony_ci/* We only support the minimum allowed value (512), so that we can pack a 3D block size
118bf215546Sopenharmony_ci * in 1 SGPR. */
119bf215546Sopenharmony_ci#define SI_MAX_VARIABLE_THREADS_PER_BLOCK 512
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci#define SI_CONTEXT_FLAG_AUX               (1u << 31)
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_FORCE_LINEAR      (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
124bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_FLUSHED_DEPTH     (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
125bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_FORCE_MSAA_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
126bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_DISABLE_DCC       (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
127bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_DRIVER_INTERNAL   (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)
128bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_READ_ONLY         (PIPE_RESOURCE_FLAG_DRV_PRIV << 5)
129bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_32BIT             (PIPE_RESOURCE_FLAG_DRV_PRIV << 6)
130bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_CLEAR             (PIPE_RESOURCE_FLAG_DRV_PRIV << 7)
131bf215546Sopenharmony_ci#define SI_RESOURCE_AUX_PLANE              (PIPE_RESOURCE_FLAG_DRV_PRIV << 8)
132bf215546Sopenharmony_ci/* Set a micro tile mode: */
133bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_FORCE_MICRO_TILE_MODE (PIPE_RESOURCE_FLAG_DRV_PRIV << 9)
134bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT (util_logbase2(PIPE_RESOURCE_FLAG_DRV_PRIV) + 10)
135bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_SET(x)                                                    \
136bf215546Sopenharmony_ci   (((x)&0x3) << SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT)
137bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_MICRO_TILE_MODE_GET(x)                                                    \
138bf215546Sopenharmony_ci   (((x) >> SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT) & 0x3)
139bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_GL2_BYPASS        (PIPE_RESOURCE_FLAG_DRV_PRIV << 12)
140bf215546Sopenharmony_ci/* Discard instead of evict. */
141bf215546Sopenharmony_ci#define SI_RESOURCE_FLAG_DISCARDABLE       (PIPE_RESOURCE_FLAG_DRV_PRIV << 13)
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_cienum si_has_gs {
144bf215546Sopenharmony_ci   GS_OFF,
145bf215546Sopenharmony_ci   GS_ON,
146bf215546Sopenharmony_ci};
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_cienum si_has_tess {
149bf215546Sopenharmony_ci   TESS_OFF,
150bf215546Sopenharmony_ci   TESS_ON,
151bf215546Sopenharmony_ci};
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_cienum si_has_ngg {
154bf215546Sopenharmony_ci   NGG_OFF,
155bf215546Sopenharmony_ci   NGG_ON,
156bf215546Sopenharmony_ci};
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci#define DCC_CODE(x) (((x) << 24) | ((x) << 16) | ((x) << 8) | (x))
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_cienum si_clear_code
161bf215546Sopenharmony_ci{
162bf215546Sopenharmony_ci   /* Common clear codes. */
163bf215546Sopenharmony_ci   DCC_CLEAR_0000    = DCC_CODE(0x00), /* all bits are 0 */
164bf215546Sopenharmony_ci   DCC_UNCOMPRESSED  = DCC_CODE(0xFF),
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci   GFX8_DCC_CLEAR_0000     = DCC_CLEAR_0000,
167bf215546Sopenharmony_ci   GFX8_DCC_CLEAR_0001     = DCC_CODE(0x40),
168bf215546Sopenharmony_ci   GFX8_DCC_CLEAR_1110     = DCC_CODE(0x80),
169bf215546Sopenharmony_ci   GFX8_DCC_CLEAR_1111     = DCC_CODE(0xC0),
170bf215546Sopenharmony_ci   GFX8_DCC_CLEAR_REG      = DCC_CODE(0x20),
171bf215546Sopenharmony_ci   GFX9_DCC_CLEAR_SINGLE   = DCC_CODE(0x10),
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_SINGLE     = DCC_CODE(0x01),
174bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_0000       = DCC_CLEAR_0000, /* all bits are 0 */
175bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_1111_UNORM = DCC_CODE(0x02), /* all bits are 1 */
176bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_1111_FP16  = DCC_CODE(0x04), /* all 16-bit words are 0x3c00, max 64bpp */
177bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_1111_FP32  = DCC_CODE(0x06), /* all 32-bit words are 0x3f800000 */
178bf215546Sopenharmony_ci   /* Color bits are 0, alpha bits are 1; only 88, 8888, 16161616 with alpha_on_msb=1 */
179bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_0001_UNORM = DCC_CODE(0x08),
180bf215546Sopenharmony_ci   /* Color bits are 1, alpha bits are 0, only 88, 8888, 16161616 with alpha_on_msb=1 */
181bf215546Sopenharmony_ci   GFX11_DCC_CLEAR_1110_UNORM = DCC_CODE(0x0A),
182bf215546Sopenharmony_ci};
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci#define SI_IMAGE_ACCESS_DCC_OFF              (1 << 8)
185bf215546Sopenharmony_ci#define SI_IMAGE_ACCESS_ALLOW_DCC_STORE      (1 << 9)
186bf215546Sopenharmony_ci#define SI_IMAGE_ACCESS_BLOCK_FORMAT_AS_UINT (1 << 10) /* for compressed/subsampled images */
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci/* Debug flags. */
189bf215546Sopenharmony_cienum
190bf215546Sopenharmony_ci{
191bf215546Sopenharmony_ci   /* Shader logging options: */
192bf215546Sopenharmony_ci   DBG_VS = MESA_SHADER_VERTEX,
193bf215546Sopenharmony_ci   DBG_TCS = MESA_SHADER_TESS_CTRL,
194bf215546Sopenharmony_ci   DBG_TES = MESA_SHADER_TESS_EVAL,
195bf215546Sopenharmony_ci   DBG_GS = MESA_SHADER_GEOMETRY,
196bf215546Sopenharmony_ci   DBG_PS = MESA_SHADER_FRAGMENT,
197bf215546Sopenharmony_ci   DBG_CS = MESA_SHADER_COMPUTE,
198bf215546Sopenharmony_ci   DBG_NO_IR,
199bf215546Sopenharmony_ci   DBG_NO_NIR,
200bf215546Sopenharmony_ci   DBG_NO_ASM,
201bf215546Sopenharmony_ci   DBG_PREOPT_IR,
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   /* Shader compiler options the shader cache should be aware of: */
204bf215546Sopenharmony_ci   DBG_FS_CORRECT_DERIVS_AFTER_KILL,
205bf215546Sopenharmony_ci   DBG_W32_GE,
206bf215546Sopenharmony_ci   DBG_W32_PS,
207bf215546Sopenharmony_ci   DBG_W32_PS_DISCARD,
208bf215546Sopenharmony_ci   DBG_W32_CS,
209bf215546Sopenharmony_ci   DBG_W64_GE,
210bf215546Sopenharmony_ci   DBG_W64_PS,
211bf215546Sopenharmony_ci   DBG_W64_CS,
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   /* Shader compiler options (with no effect on the shader cache): */
214bf215546Sopenharmony_ci   DBG_CHECK_IR,
215bf215546Sopenharmony_ci   DBG_MONOLITHIC_SHADERS,
216bf215546Sopenharmony_ci   DBG_NO_OPT_VARIANT,
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_ci   /* Information logging options: */
219bf215546Sopenharmony_ci   DBG_INFO,
220bf215546Sopenharmony_ci   DBG_TEX,
221bf215546Sopenharmony_ci   DBG_COMPUTE,
222bf215546Sopenharmony_ci   DBG_VM,
223bf215546Sopenharmony_ci   DBG_CACHE_STATS,
224bf215546Sopenharmony_ci   DBG_IB,
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci   /* Driver options: */
227bf215546Sopenharmony_ci   DBG_NO_WC,
228bf215546Sopenharmony_ci   DBG_CHECK_VM,
229bf215546Sopenharmony_ci   DBG_RESERVE_VMID,
230bf215546Sopenharmony_ci   DBG_SHADOW_REGS,
231bf215546Sopenharmony_ci   DBG_NO_FAST_DISPLAY_LIST,
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci   /* Multimedia options: */
234bf215546Sopenharmony_ci   DBG_NO_EFC,
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci   /* 3D engine options: */
237bf215546Sopenharmony_ci   DBG_NO_GFX,
238bf215546Sopenharmony_ci   DBG_NO_NGG,
239bf215546Sopenharmony_ci   DBG_ALWAYS_NGG_CULLING_ALL,
240bf215546Sopenharmony_ci   DBG_NO_NGG_CULLING,
241bf215546Sopenharmony_ci   DBG_SWITCH_ON_EOP,
242bf215546Sopenharmony_ci   DBG_NO_OUT_OF_ORDER,
243bf215546Sopenharmony_ci   DBG_NO_DPBB,
244bf215546Sopenharmony_ci   DBG_DPBB,
245bf215546Sopenharmony_ci   DBG_NO_HYPERZ,
246bf215546Sopenharmony_ci   DBG_NO_2D_TILING,
247bf215546Sopenharmony_ci   DBG_NO_TILING,
248bf215546Sopenharmony_ci   DBG_NO_DISPLAY_TILING,
249bf215546Sopenharmony_ci   DBG_NO_DISPLAY_DCC,
250bf215546Sopenharmony_ci   DBG_NO_EXPORTED_DCC,
251bf215546Sopenharmony_ci   DBG_NO_DCC,
252bf215546Sopenharmony_ci   DBG_NO_DCC_CLEAR,
253bf215546Sopenharmony_ci   DBG_NO_DCC_STORE,
254bf215546Sopenharmony_ci   DBG_DCC_STORE,
255bf215546Sopenharmony_ci   DBG_NO_DCC_MSAA,
256bf215546Sopenharmony_ci   DBG_NO_FMASK,
257bf215546Sopenharmony_ci   DBG_NO_DMA,
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci   DBG_TMZ,
260bf215546Sopenharmony_ci   DBG_SQTT,
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   DBG_COUNT
263bf215546Sopenharmony_ci};
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_cienum
266bf215546Sopenharmony_ci{
267bf215546Sopenharmony_ci   /* Tests: */
268bf215546Sopenharmony_ci   DBG_TEST_IMAGE_COPY,
269bf215546Sopenharmony_ci   DBG_TEST_CB_RESOLVE,
270bf215546Sopenharmony_ci   DBG_TEST_COMPUTE_BLIT,
271bf215546Sopenharmony_ci   DBG_TEST_VMFAULT_CP,
272bf215546Sopenharmony_ci   DBG_TEST_VMFAULT_SHADER,
273bf215546Sopenharmony_ci   DBG_TEST_DMA_PERF,
274bf215546Sopenharmony_ci   DBG_TEST_GDS,
275bf215546Sopenharmony_ci   DBG_TEST_GDS_MM,
276bf215546Sopenharmony_ci   DBG_TEST_GDS_OA_MM,
277bf215546Sopenharmony_ci};
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci#define DBG_ALL_SHADERS (((1 << (DBG_CS + 1)) - 1))
280bf215546Sopenharmony_ci#define DBG(name)       (1ull << DBG_##name)
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_cienum si_cache_policy
283bf215546Sopenharmony_ci{
284bf215546Sopenharmony_ci   L2_BYPASS,
285bf215546Sopenharmony_ci   L2_STREAM, /* same as SLC=1 */
286bf215546Sopenharmony_ci   L2_LRU,    /* same as SLC=0 */
287bf215546Sopenharmony_ci};
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_cienum si_coherency
290bf215546Sopenharmony_ci{
291bf215546Sopenharmony_ci   SI_COHERENCY_NONE, /* no cache flushes needed */
292bf215546Sopenharmony_ci   SI_COHERENCY_SHADER,
293bf215546Sopenharmony_ci   SI_COHERENCY_CB_META,
294bf215546Sopenharmony_ci   SI_COHERENCY_DB_META,
295bf215546Sopenharmony_ci   SI_COHERENCY_CP,
296bf215546Sopenharmony_ci};
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_ci#define SI_BIND_CONSTANT_BUFFER_SHIFT     0
299bf215546Sopenharmony_ci#define SI_BIND_SHADER_BUFFER_SHIFT       6
300bf215546Sopenharmony_ci#define SI_BIND_IMAGE_BUFFER_SHIFT        12
301bf215546Sopenharmony_ci#define SI_BIND_SAMPLER_BUFFER_SHIFT      18
302bf215546Sopenharmony_ci#define SI_BIND_OTHER_BUFFER_SHIFT        24
303bf215546Sopenharmony_ci
304bf215546Sopenharmony_ci/* Bind masks for all 6 shader stages. */
305bf215546Sopenharmony_ci#define SI_BIND_CONSTANT_BUFFER_ALL       (0x3f << SI_BIND_CONSTANT_BUFFER_SHIFT)
306bf215546Sopenharmony_ci#define SI_BIND_SHADER_BUFFER_ALL         (0x3f << SI_BIND_SHADER_BUFFER_SHIFT)
307bf215546Sopenharmony_ci#define SI_BIND_IMAGE_BUFFER_ALL          (0x3f << SI_BIND_IMAGE_BUFFER_SHIFT)
308bf215546Sopenharmony_ci#define SI_BIND_SAMPLER_BUFFER_ALL        (0x3f << SI_BIND_SAMPLER_BUFFER_SHIFT)
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci#define SI_BIND_CONSTANT_BUFFER(shader)   ((1 << (shader)) << SI_BIND_CONSTANT_BUFFER_SHIFT)
311bf215546Sopenharmony_ci#define SI_BIND_SHADER_BUFFER(shader)     ((1 << (shader)) << SI_BIND_SHADER_BUFFER_SHIFT)
312bf215546Sopenharmony_ci#define SI_BIND_IMAGE_BUFFER(shader)      ((1 << (shader)) << SI_BIND_IMAGE_BUFFER_SHIFT)
313bf215546Sopenharmony_ci#define SI_BIND_SAMPLER_BUFFER(shader)    ((1 << (shader)) << SI_BIND_SAMPLER_BUFFER_SHIFT)
314bf215546Sopenharmony_ci#define SI_BIND_VERTEX_BUFFER             (1 << (SI_BIND_OTHER_BUFFER_SHIFT + 0))
315bf215546Sopenharmony_ci#define SI_BIND_STREAMOUT_BUFFER          (1 << (SI_BIND_OTHER_BUFFER_SHIFT + 1))
316bf215546Sopenharmony_ci
317bf215546Sopenharmony_cistruct si_compute;
318bf215546Sopenharmony_cistruct si_shader_context;
319bf215546Sopenharmony_cistruct hash_table;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci/* Only 32-bit buffer allocations are supported, gallium doesn't support more
322bf215546Sopenharmony_ci * at the moment.
323bf215546Sopenharmony_ci */
324bf215546Sopenharmony_cistruct si_resource {
325bf215546Sopenharmony_ci   struct threaded_resource b;
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci   /* Winsys objects. */
328bf215546Sopenharmony_ci   struct pb_buffer *buf;
329bf215546Sopenharmony_ci   uint64_t gpu_address;
330bf215546Sopenharmony_ci   /* Memory usage if the buffer placement is optimal. */
331bf215546Sopenharmony_ci   uint32_t memory_usage_kb;
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   /* Resource properties. */
334bf215546Sopenharmony_ci   uint64_t bo_size;
335bf215546Sopenharmony_ci   uint8_t bo_alignment_log2;
336bf215546Sopenharmony_ci   enum radeon_bo_domain domains:8;
337bf215546Sopenharmony_ci   enum radeon_bo_flag flags:16;
338bf215546Sopenharmony_ci   unsigned bind_history; /* bitmask of SI_BIND_xxx_BUFFER */
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci   /* The buffer range which is initialized (with a write transfer,
341bf215546Sopenharmony_ci    * streamout, DMA, or as a random access target). The rest of
342bf215546Sopenharmony_ci    * the buffer is considered invalid and can be mapped unsynchronized.
343bf215546Sopenharmony_ci    *
344bf215546Sopenharmony_ci    * This allows unsynchronized mapping of a buffer range which hasn't
345bf215546Sopenharmony_ci    * been used yet. It's for applications which forget to use
346bf215546Sopenharmony_ci    * the unsynchronized map flag and expect the driver to figure it out.
347bf215546Sopenharmony_ci    */
348bf215546Sopenharmony_ci   struct util_range valid_buffer_range;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci   /* For buffers only. This indicates that a write operation has been
351bf215546Sopenharmony_ci    * performed by TC L2, but the cache hasn't been flushed.
352bf215546Sopenharmony_ci    * Any hw block which doesn't use or bypasses TC L2 should check this
353bf215546Sopenharmony_ci    * flag and flush the cache before using the buffer.
354bf215546Sopenharmony_ci    *
355bf215546Sopenharmony_ci    * For example, TC L2 must be flushed if a buffer which has been
356bf215546Sopenharmony_ci    * modified by a shader store instruction is about to be used as
357bf215546Sopenharmony_ci    * an index buffer. The reason is that VGT DMA index fetching doesn't
358bf215546Sopenharmony_ci    * use TC L2.
359bf215546Sopenharmony_ci    */
360bf215546Sopenharmony_ci   bool TC_L2_dirty;
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci   /* Whether this resource is referenced by bindless handles. */
363bf215546Sopenharmony_ci   bool texture_handle_allocated;
364bf215546Sopenharmony_ci   bool image_handle_allocated;
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci   /* Whether the resource has been exported via resource_get_handle. */
367bf215546Sopenharmony_ci   uint8_t external_usage; /* PIPE_HANDLE_USAGE_* */
368bf215546Sopenharmony_ci};
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_cistruct si_transfer {
371bf215546Sopenharmony_ci   struct threaded_transfer b;
372bf215546Sopenharmony_ci   struct si_resource *staging;
373bf215546Sopenharmony_ci};
374bf215546Sopenharmony_ci
375bf215546Sopenharmony_cistruct si_texture {
376bf215546Sopenharmony_ci   struct si_resource buffer;
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_ci   struct radeon_surf surface;
379bf215546Sopenharmony_ci   struct si_texture *flushed_depth_texture;
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci   /* One texture allocation can contain these buffers:
382bf215546Sopenharmony_ci    * - image (pixel data)
383bf215546Sopenharmony_ci    * - FMASK buffer (MSAA compression)
384bf215546Sopenharmony_ci    * - CMASK buffer (MSAA compression and/or legacy fast color clear)
385bf215546Sopenharmony_ci    * - HTILE buffer (Z/S compression and fast Z/S clear)
386bf215546Sopenharmony_ci    * - DCC buffer (color compression and new fast color clear)
387bf215546Sopenharmony_ci    * - displayable DCC buffer (if the DCC buffer is not displayable)
388bf215546Sopenharmony_ci    */
389bf215546Sopenharmony_ci   uint64_t cmask_base_address_reg;
390bf215546Sopenharmony_ci   struct si_resource *cmask_buffer;
391bf215546Sopenharmony_ci   unsigned cb_color_info; /* fast clear enable bit */
392bf215546Sopenharmony_ci   unsigned color_clear_value[2]; /* not on gfx11 */
393bf215546Sopenharmony_ci   unsigned last_msaa_resolve_target_micro_mode;
394bf215546Sopenharmony_ci   bool swap_rgb_to_bgr_on_next_clear;
395bf215546Sopenharmony_ci   bool swap_rgb_to_bgr;
396bf215546Sopenharmony_ci   unsigned num_level0_transfers;
397bf215546Sopenharmony_ci   unsigned plane_index; /* other planes are different pipe_resources */
398bf215546Sopenharmony_ci   unsigned num_planes;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   /* Depth buffer compression and fast clear. */
401bf215546Sopenharmony_ci   float depth_clear_value[RADEON_SURF_MAX_LEVELS];
402bf215546Sopenharmony_ci   uint8_t stencil_clear_value[RADEON_SURF_MAX_LEVELS];
403bf215546Sopenharmony_ci   uint16_t depth_cleared_level_mask_once; /* if it was cleared at least once */
404bf215546Sopenharmony_ci   uint16_t depth_cleared_level_mask;     /* track if it's cleared (can be false negative) */
405bf215546Sopenharmony_ci   uint16_t stencil_cleared_level_mask_once; /* if it was cleared at least once */
406bf215546Sopenharmony_ci   uint16_t dirty_level_mask;         /* each bit says if that mipmap is compressed */
407bf215546Sopenharmony_ci   uint16_t stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */
408bf215546Sopenharmony_ci   enum pipe_format db_render_format : 16;
409bf215546Sopenharmony_ci   bool fmask_is_identity : 1;
410bf215546Sopenharmony_ci   bool tc_compatible_htile : 1;
411bf215546Sopenharmony_ci   bool enable_tc_compatible_htile_next_clear : 1;
412bf215546Sopenharmony_ci   bool htile_stencil_disabled : 1;
413bf215546Sopenharmony_ci   bool upgraded_depth : 1;  /* upgraded from unorm to Z32_FLOAT */
414bf215546Sopenharmony_ci   bool is_depth : 1;
415bf215546Sopenharmony_ci   bool db_compatible : 1;
416bf215546Sopenharmony_ci   bool can_sample_z : 1;
417bf215546Sopenharmony_ci   bool can_sample_s : 1;
418bf215546Sopenharmony_ci   bool need_flush_after_depth_decompression: 1;
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ci   /* We need to track DCC dirtiness, because st/dri usually calls
421bf215546Sopenharmony_ci    * flush_resource twice per frame (not a bug) and we don't wanna
422bf215546Sopenharmony_ci    * decompress DCC twice.
423bf215546Sopenharmony_ci    */
424bf215546Sopenharmony_ci   bool displayable_dcc_dirty : 1;
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_ci   /* Counter that should be non-zero if the texture is bound to a
427bf215546Sopenharmony_ci    * framebuffer.
428bf215546Sopenharmony_ci    */
429bf215546Sopenharmony_ci   unsigned framebuffers_bound;
430bf215546Sopenharmony_ci};
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci/* State trackers create separate textures in a next-chain for extra planes
433bf215546Sopenharmony_ci * even if those are planes created purely for modifiers. Because the linking
434bf215546Sopenharmony_ci * of the chain happens outside of the driver, and NULL is interpreted as
435bf215546Sopenharmony_ci * failure, let's create some dummy texture structs. We could use these
436bf215546Sopenharmony_ci * later to use the offsets for linking if we really wanted to.
437bf215546Sopenharmony_ci *
438bf215546Sopenharmony_ci * For now just create a dummy struct and completely ignore it.
439bf215546Sopenharmony_ci *
440bf215546Sopenharmony_ci * Potentially in the future we could store stride/offset and use it during
441bf215546Sopenharmony_ci * creation, though we might want to change how linking is done first.
442bf215546Sopenharmony_ci */
443bf215546Sopenharmony_cistruct si_auxiliary_texture {
444bf215546Sopenharmony_ci   struct threaded_resource b;
445bf215546Sopenharmony_ci   struct pb_buffer *buffer;
446bf215546Sopenharmony_ci   uint32_t offset;
447bf215546Sopenharmony_ci   uint32_t stride;
448bf215546Sopenharmony_ci};
449bf215546Sopenharmony_ci
450bf215546Sopenharmony_cistruct si_surface {
451bf215546Sopenharmony_ci   struct pipe_surface base;
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   /* These can vary with block-compressed textures. */
454bf215546Sopenharmony_ci   uint16_t width0;
455bf215546Sopenharmony_ci   uint16_t height0;
456bf215546Sopenharmony_ci
457bf215546Sopenharmony_ci   bool color_initialized : 1;
458bf215546Sopenharmony_ci   bool depth_initialized : 1;
459bf215546Sopenharmony_ci
460bf215546Sopenharmony_ci   /* Misc. color flags. */
461bf215546Sopenharmony_ci   bool color_is_int8 : 1;
462bf215546Sopenharmony_ci   bool color_is_int10 : 1;
463bf215546Sopenharmony_ci   bool dcc_incompatible : 1;
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   /* Color registers. */
466bf215546Sopenharmony_ci   unsigned cb_color_info;
467bf215546Sopenharmony_ci   unsigned cb_color_view;
468bf215546Sopenharmony_ci   unsigned cb_color_attrib;
469bf215546Sopenharmony_ci   unsigned cb_color_attrib2;                      /* GFX9 and later */
470bf215546Sopenharmony_ci   unsigned cb_color_attrib3;                      /* GFX10 and later */
471bf215546Sopenharmony_ci   unsigned cb_dcc_control;                        /* GFX8 and later */
472bf215546Sopenharmony_ci   unsigned spi_shader_col_format : 8;             /* no blending, no alpha-to-coverage. */
473bf215546Sopenharmony_ci   unsigned spi_shader_col_format_alpha : 8;       /* alpha-to-coverage */
474bf215546Sopenharmony_ci   unsigned spi_shader_col_format_blend : 8;       /* blending without alpha. */
475bf215546Sopenharmony_ci   unsigned spi_shader_col_format_blend_alpha : 8; /* blending with alpha. */
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci   /* DB registers. */
478bf215546Sopenharmony_ci   uint64_t db_depth_base; /* DB_Z_READ/WRITE_BASE */
479bf215546Sopenharmony_ci   uint64_t db_stencil_base;
480bf215546Sopenharmony_ci   uint64_t db_htile_data_base;
481bf215546Sopenharmony_ci   unsigned db_depth_info;
482bf215546Sopenharmony_ci   unsigned db_z_info;
483bf215546Sopenharmony_ci   unsigned db_z_info2; /* GFX9 only */
484bf215546Sopenharmony_ci   unsigned db_depth_view;
485bf215546Sopenharmony_ci   unsigned db_depth_size;
486bf215546Sopenharmony_ci   unsigned db_depth_slice;
487bf215546Sopenharmony_ci   unsigned db_stencil_info;
488bf215546Sopenharmony_ci   unsigned db_stencil_info2; /* GFX9 only */
489bf215546Sopenharmony_ci   unsigned db_htile_surface;
490bf215546Sopenharmony_ci};
491bf215546Sopenharmony_ci
492bf215546Sopenharmony_cistruct si_mmio_counter {
493bf215546Sopenharmony_ci   unsigned busy;
494bf215546Sopenharmony_ci   unsigned idle;
495bf215546Sopenharmony_ci};
496bf215546Sopenharmony_ci
497bf215546Sopenharmony_ciunion si_mmio_counters {
498bf215546Sopenharmony_ci   struct si_mmio_counters_named {
499bf215546Sopenharmony_ci      /* For global GPU load including SDMA. */
500bf215546Sopenharmony_ci      struct si_mmio_counter gpu;
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci      /* GRBM_STATUS */
503bf215546Sopenharmony_ci      struct si_mmio_counter spi;
504bf215546Sopenharmony_ci      struct si_mmio_counter gui;
505bf215546Sopenharmony_ci      struct si_mmio_counter ta;
506bf215546Sopenharmony_ci      struct si_mmio_counter gds;
507bf215546Sopenharmony_ci      struct si_mmio_counter vgt;
508bf215546Sopenharmony_ci      struct si_mmio_counter ia;
509bf215546Sopenharmony_ci      struct si_mmio_counter sx;
510bf215546Sopenharmony_ci      struct si_mmio_counter wd;
511bf215546Sopenharmony_ci      struct si_mmio_counter bci;
512bf215546Sopenharmony_ci      struct si_mmio_counter sc;
513bf215546Sopenharmony_ci      struct si_mmio_counter pa;
514bf215546Sopenharmony_ci      struct si_mmio_counter db;
515bf215546Sopenharmony_ci      struct si_mmio_counter cp;
516bf215546Sopenharmony_ci      struct si_mmio_counter cb;
517bf215546Sopenharmony_ci
518bf215546Sopenharmony_ci      /* SRBM_STATUS2 */
519bf215546Sopenharmony_ci      struct si_mmio_counter sdma;
520bf215546Sopenharmony_ci
521bf215546Sopenharmony_ci      /* CP_STAT */
522bf215546Sopenharmony_ci      struct si_mmio_counter pfp;
523bf215546Sopenharmony_ci      struct si_mmio_counter meq;
524bf215546Sopenharmony_ci      struct si_mmio_counter me;
525bf215546Sopenharmony_ci      struct si_mmio_counter surf_sync;
526bf215546Sopenharmony_ci      struct si_mmio_counter cp_dma;
527bf215546Sopenharmony_ci      struct si_mmio_counter scratch_ram;
528bf215546Sopenharmony_ci   } named;
529bf215546Sopenharmony_ci
530bf215546Sopenharmony_ci   unsigned array[sizeof(struct si_mmio_counters_named) / sizeof(unsigned)];
531bf215546Sopenharmony_ci};
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_cistruct si_memory_object {
534bf215546Sopenharmony_ci   struct pipe_memory_object b;
535bf215546Sopenharmony_ci   struct pb_buffer *buf;
536bf215546Sopenharmony_ci   uint32_t stride;
537bf215546Sopenharmony_ci};
538bf215546Sopenharmony_ci
539bf215546Sopenharmony_ci/* Saved CS data for debugging features. */
540bf215546Sopenharmony_cistruct radeon_saved_cs {
541bf215546Sopenharmony_ci   uint32_t *ib;
542bf215546Sopenharmony_ci   unsigned num_dw;
543bf215546Sopenharmony_ci
544bf215546Sopenharmony_ci   struct radeon_bo_list_item *bo_list;
545bf215546Sopenharmony_ci   unsigned bo_count;
546bf215546Sopenharmony_ci};
547bf215546Sopenharmony_ci
548bf215546Sopenharmony_cistruct si_screen {
549bf215546Sopenharmony_ci   struct pipe_screen b;
550bf215546Sopenharmony_ci   struct radeon_winsys *ws;
551bf215546Sopenharmony_ci   struct disk_cache *disk_shader_cache;
552bf215546Sopenharmony_ci
553bf215546Sopenharmony_ci   struct radeon_info info;
554bf215546Sopenharmony_ci   struct nir_shader_compiler_options nir_options;
555bf215546Sopenharmony_ci   uint64_t debug_flags;
556bf215546Sopenharmony_ci   char renderer_string[183];
557bf215546Sopenharmony_ci
558bf215546Sopenharmony_ci   void (*make_texture_descriptor)(struct si_screen *screen, struct si_texture *tex, bool sampler,
559bf215546Sopenharmony_ci                                   enum pipe_texture_target target, enum pipe_format pipe_format,
560bf215546Sopenharmony_ci                                   const unsigned char state_swizzle[4], unsigned first_level,
561bf215546Sopenharmony_ci                                   unsigned last_level, unsigned first_layer, unsigned last_layer,
562bf215546Sopenharmony_ci                                   unsigned width, unsigned height, unsigned depth, uint32_t *state,
563bf215546Sopenharmony_ci                                   uint32_t *fmask_state);
564bf215546Sopenharmony_ci
565bf215546Sopenharmony_ci   unsigned max_memory_usage_kb;
566bf215546Sopenharmony_ci   unsigned pa_sc_raster_config;
567bf215546Sopenharmony_ci   unsigned pa_sc_raster_config_1;
568bf215546Sopenharmony_ci   unsigned se_tile_repeat;
569bf215546Sopenharmony_ci   unsigned gs_table_depth;
570bf215546Sopenharmony_ci   struct ac_hs_info hs;
571bf215546Sopenharmony_ci   unsigned eqaa_force_coverage_samples;
572bf215546Sopenharmony_ci   unsigned eqaa_force_z_samples;
573bf215546Sopenharmony_ci   unsigned eqaa_force_color_samples;
574bf215546Sopenharmony_ci   unsigned pbb_context_states_per_bin;
575bf215546Sopenharmony_ci   unsigned pbb_persistent_states_per_bin;
576bf215546Sopenharmony_ci   bool has_draw_indirect_multi;
577bf215546Sopenharmony_ci   bool has_out_of_order_rast;
578bf215546Sopenharmony_ci   bool dpbb_allowed;
579bf215546Sopenharmony_ci   bool use_ngg;
580bf215546Sopenharmony_ci   bool use_ngg_culling;
581bf215546Sopenharmony_ci   bool use_ngg_streamout;
582bf215546Sopenharmony_ci   bool allow_dcc_msaa_clear_to_reg_for_bpp[5]; /* indexed by log2(Bpp) */
583bf215546Sopenharmony_ci   bool always_allow_dcc_stores;
584bf215546Sopenharmony_ci
585bf215546Sopenharmony_ci   struct {
586bf215546Sopenharmony_ci#define OPT_BOOL(name, dflt, description) bool name : 1;
587bf215546Sopenharmony_ci#define OPT_INT(name, dflt, description) int name;
588bf215546Sopenharmony_ci#include "si_debug_options.h"
589bf215546Sopenharmony_ci   } options;
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci   /* Whether shaders are monolithic (1-part) or separate (3-part). */
592bf215546Sopenharmony_ci   bool use_monolithic_shaders;
593bf215546Sopenharmony_ci   bool record_llvm_ir;
594bf215546Sopenharmony_ci
595bf215546Sopenharmony_ci   struct slab_parent_pool pool_transfers;
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci   /* Texture filter settings. */
598bf215546Sopenharmony_ci   int force_aniso; /* -1 = disabled */
599bf215546Sopenharmony_ci
600bf215546Sopenharmony_ci   unsigned max_texel_buffer_elements;
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_ci   /* Auxiliary context. Mainly used to initialize resources. */
603bf215546Sopenharmony_ci   void *aux_context;
604bf215546Sopenharmony_ci   mtx_t aux_context_lock;
605bf215546Sopenharmony_ci
606bf215546Sopenharmony_ci   /* Async compute context for DRI_PRIME copies. */
607bf215546Sopenharmony_ci   struct pipe_context *async_compute_context;
608bf215546Sopenharmony_ci   simple_mtx_t async_compute_context_lock;
609bf215546Sopenharmony_ci
610bf215546Sopenharmony_ci   /* This must be in the screen, because UE4 uses one context for
611bf215546Sopenharmony_ci    * compilation and another one for rendering.
612bf215546Sopenharmony_ci    */
613bf215546Sopenharmony_ci   unsigned num_compilations;
614bf215546Sopenharmony_ci   /* Along with ST_DEBUG=precompile, this should show if applications
615bf215546Sopenharmony_ci    * are loading shaders on demand. This is a monotonic counter.
616bf215546Sopenharmony_ci    */
617bf215546Sopenharmony_ci   unsigned num_shaders_created;
618bf215546Sopenharmony_ci   unsigned num_memory_shader_cache_hits;
619bf215546Sopenharmony_ci   unsigned num_memory_shader_cache_misses;
620bf215546Sopenharmony_ci   unsigned num_disk_shader_cache_hits;
621bf215546Sopenharmony_ci   unsigned num_disk_shader_cache_misses;
622bf215546Sopenharmony_ci
623bf215546Sopenharmony_ci   /* GPU load thread. */
624bf215546Sopenharmony_ci   simple_mtx_t gpu_load_mutex;
625bf215546Sopenharmony_ci   thrd_t gpu_load_thread;
626bf215546Sopenharmony_ci   bool gpu_load_thread_created;
627bf215546Sopenharmony_ci   union si_mmio_counters mmio_counters;
628bf215546Sopenharmony_ci   volatile unsigned gpu_load_stop_thread; /* bool */
629bf215546Sopenharmony_ci
630bf215546Sopenharmony_ci   /* Performance counters. */
631bf215546Sopenharmony_ci   struct si_perfcounters *perfcounters;
632bf215546Sopenharmony_ci
633bf215546Sopenharmony_ci   /* If pipe_screen wants to recompute and re-emit the framebuffer,
634bf215546Sopenharmony_ci    * sampler, and image states of all contexts, it should atomically
635bf215546Sopenharmony_ci    * increment this.
636bf215546Sopenharmony_ci    *
637bf215546Sopenharmony_ci    * Each context will compare this with its own last known value of
638bf215546Sopenharmony_ci    * the counter before drawing and re-emit the states accordingly.
639bf215546Sopenharmony_ci    */
640bf215546Sopenharmony_ci   unsigned dirty_tex_counter;
641bf215546Sopenharmony_ci   unsigned dirty_buf_counter;
642bf215546Sopenharmony_ci
643bf215546Sopenharmony_ci   /* Atomically increment this counter when an existing texture's
644bf215546Sopenharmony_ci    * metadata is enabled or disabled in a way that requires changing
645bf215546Sopenharmony_ci    * contexts' compressed texture binding masks.
646bf215546Sopenharmony_ci    */
647bf215546Sopenharmony_ci   unsigned compressed_colortex_counter;
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_ci   struct {
650bf215546Sopenharmony_ci      /* Context flags to set so that all writes from earlier jobs
651bf215546Sopenharmony_ci       * in the CP are seen by L2 clients.
652bf215546Sopenharmony_ci       */
653bf215546Sopenharmony_ci      unsigned cp_to_L2;
654bf215546Sopenharmony_ci
655bf215546Sopenharmony_ci      /* Context flags to set so that all writes from earlier jobs
656bf215546Sopenharmony_ci       * that end in L2 are seen by CP.
657bf215546Sopenharmony_ci       */
658bf215546Sopenharmony_ci      unsigned L2_to_cp;
659bf215546Sopenharmony_ci   } barrier_flags;
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_ci   simple_mtx_t shader_parts_mutex;
662bf215546Sopenharmony_ci   struct si_shader_part *vs_prologs;
663bf215546Sopenharmony_ci   struct si_shader_part *tcs_epilogs;
664bf215546Sopenharmony_ci   struct si_shader_part *ps_prologs;
665bf215546Sopenharmony_ci   struct si_shader_part *ps_epilogs;
666bf215546Sopenharmony_ci
667bf215546Sopenharmony_ci   /* Shader cache in memory.
668bf215546Sopenharmony_ci    *
669bf215546Sopenharmony_ci    * Design & limitations:
670bf215546Sopenharmony_ci    * - The shader cache is per screen (= per process), never saved to
671bf215546Sopenharmony_ci    *   disk, and skips redundant shader compilations from NIR to bytecode.
672bf215546Sopenharmony_ci    * - It can only be used with one-variant-per-shader support, in which
673bf215546Sopenharmony_ci    *   case only the main (typically middle) part of shaders is cached.
674bf215546Sopenharmony_ci    * - Only VS, TCS, TES, PS are cached, out of which only the hw VS
675bf215546Sopenharmony_ci    *   variants of VS and TES are cached, so LS and ES aren't.
676bf215546Sopenharmony_ci    * - GS and CS aren't cached, but it's certainly possible to cache
677bf215546Sopenharmony_ci    *   those as well.
678bf215546Sopenharmony_ci    */
679bf215546Sopenharmony_ci   simple_mtx_t shader_cache_mutex;
680bf215546Sopenharmony_ci   struct hash_table *shader_cache;
681bf215546Sopenharmony_ci   /* Maximum and current size */
682bf215546Sopenharmony_ci   uint32_t shader_cache_size;
683bf215546Sopenharmony_ci   uint32_t shader_cache_max_size;
684bf215546Sopenharmony_ci
685bf215546Sopenharmony_ci   /* Shader cache of live shaders. */
686bf215546Sopenharmony_ci   struct util_live_shader_cache live_shader_cache;
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci   /* Shader compiler queue for multithreaded compilation. */
689bf215546Sopenharmony_ci   struct util_queue shader_compiler_queue;
690bf215546Sopenharmony_ci   /* Use at most 3 normal compiler threads on quadcore and better.
691bf215546Sopenharmony_ci    * Hyperthreaded CPUs report the number of threads, but we want
692bf215546Sopenharmony_ci    * the number of cores. We only need this many threads for shader-db. */
693bf215546Sopenharmony_ci   struct ac_llvm_compiler compiler[24]; /* used by the queue only */
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci   struct util_queue shader_compiler_queue_low_priority;
696bf215546Sopenharmony_ci   /* Use at most 2 low priority threads on quadcore and better.
697bf215546Sopenharmony_ci    * We want to minimize the impact on multithreaded Mesa. */
698bf215546Sopenharmony_ci   struct ac_llvm_compiler compiler_lowp[10];
699bf215546Sopenharmony_ci
700bf215546Sopenharmony_ci   unsigned ngg_subgroup_size;
701bf215546Sopenharmony_ci
702bf215546Sopenharmony_ci   struct util_idalloc_mt buffer_ids;
703bf215546Sopenharmony_ci   struct util_vertex_state_cache vertex_state_cache;
704bf215546Sopenharmony_ci
705bf215546Sopenharmony_ci   struct si_resource *attribute_ring;
706bf215546Sopenharmony_ci
707bf215546Sopenharmony_ci   /* NGG streamout. */
708bf215546Sopenharmony_ci   simple_mtx_t gds_mutex;
709bf215546Sopenharmony_ci   struct pb_buffer *gds;
710bf215546Sopenharmony_ci   struct pb_buffer *gds_oa;
711bf215546Sopenharmony_ci};
712bf215546Sopenharmony_ci
713bf215546Sopenharmony_cistruct si_sampler_view {
714bf215546Sopenharmony_ci   struct pipe_sampler_view base;
715bf215546Sopenharmony_ci   /* [0..7] = image descriptor
716bf215546Sopenharmony_ci    * [4..7] = buffer descriptor */
717bf215546Sopenharmony_ci   uint32_t state[8];
718bf215546Sopenharmony_ci   uint32_t fmask_state[8];
719bf215546Sopenharmony_ci   const struct legacy_surf_level *base_level_info;
720bf215546Sopenharmony_ci   ubyte block_width;
721bf215546Sopenharmony_ci   bool is_stencil_sampler;
722bf215546Sopenharmony_ci   bool dcc_incompatible;
723bf215546Sopenharmony_ci};
724bf215546Sopenharmony_ci
725bf215546Sopenharmony_ci#define SI_SAMPLER_STATE_MAGIC 0x34f1c35a
726bf215546Sopenharmony_ci
727bf215546Sopenharmony_cistruct si_sampler_state {
728bf215546Sopenharmony_ci#ifndef NDEBUG
729bf215546Sopenharmony_ci   unsigned magic;
730bf215546Sopenharmony_ci#endif
731bf215546Sopenharmony_ci   uint32_t val[4];
732bf215546Sopenharmony_ci   uint32_t upgraded_depth_val[4];
733bf215546Sopenharmony_ci};
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_cistruct si_cs_shader_state {
736bf215546Sopenharmony_ci   struct si_compute *program;
737bf215546Sopenharmony_ci   struct si_compute *emitted_program;
738bf215546Sopenharmony_ci   unsigned offset;
739bf215546Sopenharmony_ci   bool initialized;
740bf215546Sopenharmony_ci};
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_cistruct si_samplers {
743bf215546Sopenharmony_ci   struct pipe_sampler_view *views[SI_NUM_SAMPLERS];
744bf215546Sopenharmony_ci   struct si_sampler_state *sampler_states[SI_NUM_SAMPLERS];
745bf215546Sopenharmony_ci
746bf215546Sopenharmony_ci   /* The i-th bit is set if that element is enabled (non-NULL resource). */
747bf215546Sopenharmony_ci   unsigned enabled_mask;
748bf215546Sopenharmony_ci   uint32_t has_depth_tex_mask;
749bf215546Sopenharmony_ci   uint32_t needs_depth_decompress_mask;
750bf215546Sopenharmony_ci   uint32_t needs_color_decompress_mask;
751bf215546Sopenharmony_ci};
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_cistruct si_images {
754bf215546Sopenharmony_ci   struct pipe_image_view views[SI_NUM_IMAGES];
755bf215546Sopenharmony_ci   uint32_t needs_color_decompress_mask;
756bf215546Sopenharmony_ci   unsigned enabled_mask;
757bf215546Sopenharmony_ci   unsigned display_dcc_store_mask;
758bf215546Sopenharmony_ci};
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_cistruct si_framebuffer {
761bf215546Sopenharmony_ci   struct pipe_framebuffer_state state;
762bf215546Sopenharmony_ci   unsigned colorbuf_enabled_4bit;
763bf215546Sopenharmony_ci   unsigned spi_shader_col_format;
764bf215546Sopenharmony_ci   unsigned spi_shader_col_format_alpha;
765bf215546Sopenharmony_ci   unsigned spi_shader_col_format_blend;
766bf215546Sopenharmony_ci   unsigned spi_shader_col_format_blend_alpha;
767bf215546Sopenharmony_ci   ubyte nr_samples : 5;   /* at most 16xAA */
768bf215546Sopenharmony_ci   ubyte log_samples : 3;  /* at most 4 = 16xAA */
769bf215546Sopenharmony_ci   ubyte nr_color_samples; /* at most 8xAA */
770bf215546Sopenharmony_ci   ubyte compressed_cb_mask;
771bf215546Sopenharmony_ci   ubyte uncompressed_cb_mask;
772bf215546Sopenharmony_ci   ubyte color_is_int8;
773bf215546Sopenharmony_ci   ubyte color_is_int10;
774bf215546Sopenharmony_ci   ubyte dirty_cbufs;
775bf215546Sopenharmony_ci   ubyte min_bytes_per_pixel;
776bf215546Sopenharmony_ci   bool dirty_zsbuf;
777bf215546Sopenharmony_ci   bool any_dst_linear;
778bf215546Sopenharmony_ci   bool CB_has_shader_readable_metadata;
779bf215546Sopenharmony_ci   bool DB_has_shader_readable_metadata;
780bf215546Sopenharmony_ci   bool all_DCC_pipe_aligned;
781bf215546Sopenharmony_ci   bool has_dcc_msaa;
782bf215546Sopenharmony_ci};
783bf215546Sopenharmony_ci
784bf215546Sopenharmony_cienum si_quant_mode
785bf215546Sopenharmony_ci{
786bf215546Sopenharmony_ci   /* This is the list we want to support. */
787bf215546Sopenharmony_ci   SI_QUANT_MODE_16_8_FIXED_POINT_1_256TH,
788bf215546Sopenharmony_ci   SI_QUANT_MODE_14_10_FIXED_POINT_1_1024TH,
789bf215546Sopenharmony_ci   SI_QUANT_MODE_12_12_FIXED_POINT_1_4096TH,
790bf215546Sopenharmony_ci};
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_cistruct si_signed_scissor {
793bf215546Sopenharmony_ci   int minx;
794bf215546Sopenharmony_ci   int miny;
795bf215546Sopenharmony_ci   int maxx;
796bf215546Sopenharmony_ci   int maxy;
797bf215546Sopenharmony_ci   enum si_quant_mode quant_mode;
798bf215546Sopenharmony_ci};
799bf215546Sopenharmony_ci
800bf215546Sopenharmony_cistruct si_viewports {
801bf215546Sopenharmony_ci   struct pipe_viewport_state states[SI_MAX_VIEWPORTS];
802bf215546Sopenharmony_ci   struct si_signed_scissor as_scissor[SI_MAX_VIEWPORTS];
803bf215546Sopenharmony_ci};
804bf215546Sopenharmony_ci
805bf215546Sopenharmony_cistruct si_streamout_target {
806bf215546Sopenharmony_ci   struct pipe_stream_output_target b;
807bf215546Sopenharmony_ci
808bf215546Sopenharmony_ci   /* The buffer where BUFFER_FILLED_SIZE is stored. */
809bf215546Sopenharmony_ci   struct si_resource *buf_filled_size;
810bf215546Sopenharmony_ci   unsigned buf_filled_size_offset;
811bf215546Sopenharmony_ci   bool buf_filled_size_valid;
812bf215546Sopenharmony_ci
813bf215546Sopenharmony_ci   unsigned stride_in_dw;
814bf215546Sopenharmony_ci};
815bf215546Sopenharmony_ci
816bf215546Sopenharmony_cistruct si_streamout {
817bf215546Sopenharmony_ci   bool begin_emitted;
818bf215546Sopenharmony_ci
819bf215546Sopenharmony_ci   unsigned enabled_mask;
820bf215546Sopenharmony_ci   unsigned num_targets;
821bf215546Sopenharmony_ci   struct si_streamout_target *targets[PIPE_MAX_SO_BUFFERS];
822bf215546Sopenharmony_ci
823bf215546Sopenharmony_ci   unsigned append_bitmask;
824bf215546Sopenharmony_ci   bool suspended;
825bf215546Sopenharmony_ci
826bf215546Sopenharmony_ci   /* External state which comes from the vertex shader,
827bf215546Sopenharmony_ci    * it must be set explicitly when binding a shader. */
828bf215546Sopenharmony_ci   uint8_t *stride_in_dw;
829bf215546Sopenharmony_ci   unsigned enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
830bf215546Sopenharmony_ci
831bf215546Sopenharmony_ci   /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */
832bf215546Sopenharmony_ci   unsigned hw_enabled_mask;
833bf215546Sopenharmony_ci
834bf215546Sopenharmony_ci   /* The state of VGT_STRMOUT_(CONFIG|EN). */
835bf215546Sopenharmony_ci   bool streamout_enabled;
836bf215546Sopenharmony_ci   bool prims_gen_query_enabled;
837bf215546Sopenharmony_ci   int num_prims_gen_queries;
838bf215546Sopenharmony_ci};
839bf215546Sopenharmony_ci
840bf215546Sopenharmony_ci/* A shader state consists of the shader selector, which is a constant state
841bf215546Sopenharmony_ci * object shared by multiple contexts and shouldn't be modified, and
842bf215546Sopenharmony_ci * the current shader variant selected for this context.
843bf215546Sopenharmony_ci */
844bf215546Sopenharmony_cistruct si_shader_ctx_state {
845bf215546Sopenharmony_ci   struct si_shader_selector *cso;
846bf215546Sopenharmony_ci   struct si_shader *current;
847bf215546Sopenharmony_ci   /* The shader variant key representing the current state. */
848bf215546Sopenharmony_ci   union si_shader_key key;
849bf215546Sopenharmony_ci};
850bf215546Sopenharmony_ci
851bf215546Sopenharmony_ci#define SI_NUM_VGT_PARAM_KEY_BITS 12
852bf215546Sopenharmony_ci#define SI_NUM_VGT_PARAM_STATES   (1 << SI_NUM_VGT_PARAM_KEY_BITS)
853bf215546Sopenharmony_ci
854bf215546Sopenharmony_ci/* The IA_MULTI_VGT_PARAM key used to index the table of precomputed values.
855bf215546Sopenharmony_ci * Some fields are set by state-change calls, most are set by draw_vbo.
856bf215546Sopenharmony_ci */
857bf215546Sopenharmony_ciunion si_vgt_param_key {
858bf215546Sopenharmony_ci   struct {
859bf215546Sopenharmony_ci#if UTIL_ARCH_LITTLE_ENDIAN
860bf215546Sopenharmony_ci      uint16_t prim : 4;
861bf215546Sopenharmony_ci      uint16_t uses_instancing : 1;
862bf215546Sopenharmony_ci      uint16_t multi_instances_smaller_than_primgroup : 1;
863bf215546Sopenharmony_ci      uint16_t primitive_restart : 1;
864bf215546Sopenharmony_ci      uint16_t count_from_stream_output : 1;
865bf215546Sopenharmony_ci      uint16_t line_stipple_enabled : 1;
866bf215546Sopenharmony_ci      uint16_t uses_tess : 1;
867bf215546Sopenharmony_ci      uint16_t tess_uses_prim_id : 1;
868bf215546Sopenharmony_ci      uint16_t uses_gs : 1;
869bf215546Sopenharmony_ci      uint16_t _pad : 16 - SI_NUM_VGT_PARAM_KEY_BITS;
870bf215546Sopenharmony_ci#else /* UTIL_ARCH_BIG_ENDIAN */
871bf215546Sopenharmony_ci      uint16_t _pad : 16 - SI_NUM_VGT_PARAM_KEY_BITS;
872bf215546Sopenharmony_ci      uint16_t uses_gs : 1;
873bf215546Sopenharmony_ci      uint16_t tess_uses_prim_id : 1;
874bf215546Sopenharmony_ci      uint16_t uses_tess : 1;
875bf215546Sopenharmony_ci      uint16_t line_stipple_enabled : 1;
876bf215546Sopenharmony_ci      uint16_t count_from_stream_output : 1;
877bf215546Sopenharmony_ci      uint16_t primitive_restart : 1;
878bf215546Sopenharmony_ci      uint16_t multi_instances_smaller_than_primgroup : 1;
879bf215546Sopenharmony_ci      uint16_t uses_instancing : 1;
880bf215546Sopenharmony_ci      uint16_t prim : 4;
881bf215546Sopenharmony_ci#endif
882bf215546Sopenharmony_ci   } u;
883bf215546Sopenharmony_ci   uint16_t index;
884bf215546Sopenharmony_ci};
885bf215546Sopenharmony_ci
886bf215546Sopenharmony_cistruct si_texture_handle {
887bf215546Sopenharmony_ci   unsigned desc_slot;
888bf215546Sopenharmony_ci   bool desc_dirty;
889bf215546Sopenharmony_ci   struct pipe_sampler_view *view;
890bf215546Sopenharmony_ci   struct si_sampler_state sstate;
891bf215546Sopenharmony_ci};
892bf215546Sopenharmony_ci
893bf215546Sopenharmony_cistruct si_image_handle {
894bf215546Sopenharmony_ci   unsigned desc_slot;
895bf215546Sopenharmony_ci   bool desc_dirty;
896bf215546Sopenharmony_ci   struct pipe_image_view view;
897bf215546Sopenharmony_ci};
898bf215546Sopenharmony_ci
899bf215546Sopenharmony_cistruct si_saved_cs {
900bf215546Sopenharmony_ci   struct pipe_reference reference;
901bf215546Sopenharmony_ci   struct si_context *ctx;
902bf215546Sopenharmony_ci   struct radeon_saved_cs gfx;
903bf215546Sopenharmony_ci   struct radeon_saved_cs compute;
904bf215546Sopenharmony_ci   struct si_resource *trace_buf;
905bf215546Sopenharmony_ci   unsigned trace_id;
906bf215546Sopenharmony_ci
907bf215546Sopenharmony_ci   unsigned gfx_last_dw;
908bf215546Sopenharmony_ci   bool flushed;
909bf215546Sopenharmony_ci   int64_t time_flush;
910bf215546Sopenharmony_ci};
911bf215546Sopenharmony_ci
912bf215546Sopenharmony_cistruct si_small_prim_cull_info {
913bf215546Sopenharmony_ci   float scale[2], translate[2];
914bf215546Sopenharmony_ci   float scale_no_aa[2], translate_no_aa[2];
915bf215546Sopenharmony_ci   float clip_half_line_width[2];      /* line_width * 0.5 in clip space in X and Y directions */
916bf215546Sopenharmony_ci};
917bf215546Sopenharmony_ci
918bf215546Sopenharmony_cistruct si_vertex_state {
919bf215546Sopenharmony_ci   struct pipe_vertex_state b;
920bf215546Sopenharmony_ci   struct si_vertex_elements velems;
921bf215546Sopenharmony_ci   uint32_t descriptors[4 * SI_MAX_ATTRIBS];
922bf215546Sopenharmony_ci};
923bf215546Sopenharmony_ci
924bf215546Sopenharmony_citypedef void (*pipe_draw_vbo_func)(struct pipe_context *pipe,
925bf215546Sopenharmony_ci                                   const struct pipe_draw_info *info,
926bf215546Sopenharmony_ci                                   unsigned drawid_offset,
927bf215546Sopenharmony_ci                                   const struct pipe_draw_indirect_info *indirect,
928bf215546Sopenharmony_ci                                   const struct pipe_draw_start_count_bias *draws,
929bf215546Sopenharmony_ci                                   unsigned num_draws);
930bf215546Sopenharmony_citypedef void (*pipe_draw_vertex_state_func)(struct pipe_context *ctx,
931bf215546Sopenharmony_ci                                            struct pipe_vertex_state *vstate,
932bf215546Sopenharmony_ci                                            uint32_t partial_velem_mask,
933bf215546Sopenharmony_ci                                            struct pipe_draw_vertex_state_info info,
934bf215546Sopenharmony_ci                                            const struct pipe_draw_start_count_bias *draws,
935bf215546Sopenharmony_ci                                            unsigned num_draws);
936bf215546Sopenharmony_ci
937bf215546Sopenharmony_cistruct si_context {
938bf215546Sopenharmony_ci   struct pipe_context b; /* base class */
939bf215546Sopenharmony_ci
940bf215546Sopenharmony_ci   enum radeon_family family;
941bf215546Sopenharmony_ci   enum amd_gfx_level gfx_level;
942bf215546Sopenharmony_ci
943bf215546Sopenharmony_ci   struct radeon_winsys *ws;
944bf215546Sopenharmony_ci   struct radeon_winsys_ctx *ctx;
945bf215546Sopenharmony_ci   struct radeon_cmdbuf gfx_cs; /* compute IB if graphics is disabled */
946bf215546Sopenharmony_ci   struct radeon_cmdbuf *sdma_cs;
947bf215546Sopenharmony_ci   struct pipe_fence_handle *last_gfx_fence;
948bf215546Sopenharmony_ci   struct si_resource *eop_bug_scratch;
949bf215546Sopenharmony_ci   struct si_resource *eop_bug_scratch_tmz;
950bf215546Sopenharmony_ci   struct u_upload_mgr *cached_gtt_allocator;
951bf215546Sopenharmony_ci   struct threaded_context *tc;
952bf215546Sopenharmony_ci   struct u_suballocator allocator_zeroed_memory;
953bf215546Sopenharmony_ci   struct slab_child_pool pool_transfers;
954bf215546Sopenharmony_ci   struct slab_child_pool pool_transfers_unsync; /* for threaded_context */
955bf215546Sopenharmony_ci   struct pipe_device_reset_callback device_reset_callback;
956bf215546Sopenharmony_ci   struct u_log_context *log;
957bf215546Sopenharmony_ci   void *query_result_shader;
958bf215546Sopenharmony_ci   void *sh_query_result_shader;
959bf215546Sopenharmony_ci   struct si_resource *shadowed_regs;
960bf215546Sopenharmony_ci
961bf215546Sopenharmony_ci   void (*emit_cache_flush)(struct si_context *ctx, struct radeon_cmdbuf *cs);
962bf215546Sopenharmony_ci
963bf215546Sopenharmony_ci   struct blitter_context *blitter;
964bf215546Sopenharmony_ci   void *noop_blend;
965bf215546Sopenharmony_ci   void *noop_dsa;
966bf215546Sopenharmony_ci   void *no_velems_state;
967bf215546Sopenharmony_ci   void *discard_rasterizer_state;
968bf215546Sopenharmony_ci   void *custom_dsa_flush;
969bf215546Sopenharmony_ci   void *custom_blend_resolve;
970bf215546Sopenharmony_ci   void *custom_blend_fmask_decompress;
971bf215546Sopenharmony_ci   void *custom_blend_eliminate_fastclear;
972bf215546Sopenharmony_ci   void *custom_blend_dcc_decompress;
973bf215546Sopenharmony_ci   void *vs_blit_pos;
974bf215546Sopenharmony_ci   void *vs_blit_pos_layered;
975bf215546Sopenharmony_ci   void *vs_blit_color;
976bf215546Sopenharmony_ci   void *vs_blit_color_layered;
977bf215546Sopenharmony_ci   void *vs_blit_texcoord;
978bf215546Sopenharmony_ci   void *cs_clear_buffer;
979bf215546Sopenharmony_ci   void *cs_clear_buffer_rmw;
980bf215546Sopenharmony_ci   void *cs_copy_buffer;
981bf215546Sopenharmony_ci   void *cs_copy_image[2][2]; /* [src_is_1d][dst_is_1d] */
982bf215546Sopenharmony_ci   void *cs_clear_render_target;
983bf215546Sopenharmony_ci   void *cs_clear_render_target_1d_array;
984bf215546Sopenharmony_ci   void *cs_clear_12bytes_buffer;
985bf215546Sopenharmony_ci   void *cs_dcc_retile[32];
986bf215546Sopenharmony_ci   void *cs_fmask_expand[3][2]; /* [log2(samples)-1][is_array] */
987bf215546Sopenharmony_ci   struct si_screen *screen;
988bf215546Sopenharmony_ci   struct util_debug_callback debug;
989bf215546Sopenharmony_ci   struct ac_llvm_compiler compiler; /* only non-threaded compilation */
990bf215546Sopenharmony_ci   struct hash_table *fixed_func_tcs_shader_cache;
991bf215546Sopenharmony_ci   struct si_resource *wait_mem_scratch;
992bf215546Sopenharmony_ci   struct si_resource *wait_mem_scratch_tmz;
993bf215546Sopenharmony_ci   unsigned wait_mem_number;
994bf215546Sopenharmony_ci   uint16_t prefetch_L2_mask;
995bf215546Sopenharmony_ci
996bf215546Sopenharmony_ci   bool blitter_running;
997bf215546Sopenharmony_ci   bool in_update_ps_colorbuf0_slot;
998bf215546Sopenharmony_ci   bool is_noop:1;
999bf215546Sopenharmony_ci   bool has_graphics:1;
1000bf215546Sopenharmony_ci   bool gfx_flush_in_progress : 1;
1001bf215546Sopenharmony_ci   bool gfx_last_ib_is_busy : 1;
1002bf215546Sopenharmony_ci   bool compute_is_busy : 1;
1003bf215546Sopenharmony_ci   int8_t pipeline_stats_enabled; /* -1 = unknown, 0 = disabled, 1 = enabled */
1004bf215546Sopenharmony_ci
1005bf215546Sopenharmony_ci   unsigned num_gfx_cs_flushes;
1006bf215546Sopenharmony_ci   unsigned initial_gfx_cs_size;
1007bf215546Sopenharmony_ci   unsigned last_dirty_tex_counter;
1008bf215546Sopenharmony_ci   unsigned last_dirty_buf_counter;
1009bf215546Sopenharmony_ci   unsigned last_compressed_colortex_counter;
1010bf215546Sopenharmony_ci   unsigned last_num_draw_calls;
1011bf215546Sopenharmony_ci   unsigned flags; /* flush flags */
1012bf215546Sopenharmony_ci   /* Current unaccounted memory usage. */
1013bf215546Sopenharmony_ci   uint32_t memory_usage_kb;
1014bf215546Sopenharmony_ci
1015bf215546Sopenharmony_ci   /* Atoms (direct states). */
1016bf215546Sopenharmony_ci   union si_state_atoms atoms;
1017bf215546Sopenharmony_ci   unsigned dirty_atoms; /* mask */
1018bf215546Sopenharmony_ci   /* PM4 states (precomputed immutable states) */
1019bf215546Sopenharmony_ci   unsigned dirty_states;
1020bf215546Sopenharmony_ci   union si_state queued;
1021bf215546Sopenharmony_ci   union si_state emitted;
1022bf215546Sopenharmony_ci
1023bf215546Sopenharmony_ci   /* Atom declarations. */
1024bf215546Sopenharmony_ci   struct si_framebuffer framebuffer;
1025bf215546Sopenharmony_ci   unsigned sample_locs_num_samples;
1026bf215546Sopenharmony_ci   uint16_t sample_mask;
1027bf215546Sopenharmony_ci   unsigned last_cb_target_mask;
1028bf215546Sopenharmony_ci   struct pipe_blend_color blend_color;
1029bf215546Sopenharmony_ci   struct pipe_clip_state clip_state;
1030bf215546Sopenharmony_ci   struct si_shader_data shader_pointers;
1031bf215546Sopenharmony_ci   struct si_stencil_ref stencil_ref;
1032bf215546Sopenharmony_ci   bool blend_color_any_nonzeros:1;
1033bf215546Sopenharmony_ci   bool clip_state_any_nonzeros:1;
1034bf215546Sopenharmony_ci   bool viewport0_y_inverted;
1035bf215546Sopenharmony_ci   struct pipe_scissor_state scissors[SI_MAX_VIEWPORTS];
1036bf215546Sopenharmony_ci   struct si_streamout streamout;
1037bf215546Sopenharmony_ci   struct si_viewports viewports;
1038bf215546Sopenharmony_ci   unsigned num_window_rectangles;
1039bf215546Sopenharmony_ci   bool window_rectangles_include;
1040bf215546Sopenharmony_ci   struct pipe_scissor_state window_rectangles[4];
1041bf215546Sopenharmony_ci
1042bf215546Sopenharmony_ci   /* Precomputed states. */
1043bf215546Sopenharmony_ci   struct si_pm4_state *last_preamble;
1044bf215546Sopenharmony_ci   struct si_pm4_state *cs_preamble_state;
1045bf215546Sopenharmony_ci   struct si_pm4_state *cs_preamble_state_tmz;
1046bf215546Sopenharmony_ci   uint16_t gs_ring_state_dw_offset;
1047bf215546Sopenharmony_ci   uint16_t gs_ring_state_dw_offset_tmz;
1048bf215546Sopenharmony_ci   bool cs_preamble_has_vgt_flush;
1049bf215546Sopenharmony_ci   bool cs_preamble_has_vgt_flush_tmz;
1050bf215546Sopenharmony_ci
1051bf215546Sopenharmony_ci   struct si_pm4_state *vgt_shader_config[SI_NUM_VGT_STAGES_STATES];
1052bf215546Sopenharmony_ci
1053bf215546Sopenharmony_ci   /* shaders */
1054bf215546Sopenharmony_ci   union {
1055bf215546Sopenharmony_ci      struct {
1056bf215546Sopenharmony_ci         struct si_shader_ctx_state vs;
1057bf215546Sopenharmony_ci         struct si_shader_ctx_state ps;
1058bf215546Sopenharmony_ci         struct si_shader_ctx_state gs;
1059bf215546Sopenharmony_ci         struct si_shader_ctx_state tcs;
1060bf215546Sopenharmony_ci         struct si_shader_ctx_state tes;
1061bf215546Sopenharmony_ci      } shader;
1062bf215546Sopenharmony_ci      /* indexed access using pipe_shader_type (not by MESA_SHADER_*) */
1063bf215546Sopenharmony_ci      struct si_shader_ctx_state shaders[SI_NUM_GRAPHICS_SHADERS];
1064bf215546Sopenharmony_ci   };
1065bf215546Sopenharmony_ci   struct si_cs_shader_state cs_shader_state;
1066bf215546Sopenharmony_ci   /* if current tcs set by user */
1067bf215546Sopenharmony_ci   bool is_user_tcs;
1068bf215546Sopenharmony_ci
1069bf215546Sopenharmony_ci   /* shader information */
1070bf215546Sopenharmony_ci   uint64_t ps_inputs_read_or_disabled;
1071bf215546Sopenharmony_ci   struct si_vertex_elements *vertex_elements;
1072bf215546Sopenharmony_ci   unsigned num_vertex_elements;
1073bf215546Sopenharmony_ci   unsigned cs_max_waves_per_sh;
1074bf215546Sopenharmony_ci   bool uses_nontrivial_vs_prolog;
1075bf215546Sopenharmony_ci   bool force_trivial_vs_prolog;
1076bf215546Sopenharmony_ci   bool do_update_shaders;
1077bf215546Sopenharmony_ci   bool compute_shaderbuf_sgprs_dirty;
1078bf215546Sopenharmony_ci   bool compute_image_sgprs_dirty;
1079bf215546Sopenharmony_ci   bool vs_uses_base_instance;
1080bf215546Sopenharmony_ci   bool vs_uses_draw_id;
1081bf215546Sopenharmony_ci   uint8_t patch_vertices;
1082bf215546Sopenharmony_ci
1083bf215546Sopenharmony_ci   /* shader descriptors */
1084bf215546Sopenharmony_ci   struct si_descriptors descriptors[SI_NUM_DESCS];
1085bf215546Sopenharmony_ci   unsigned descriptors_dirty;
1086bf215546Sopenharmony_ci   unsigned shader_pointers_dirty;
1087bf215546Sopenharmony_ci   unsigned shader_needs_decompress_mask;
1088bf215546Sopenharmony_ci   unsigned shader_has_depth_tex;
1089bf215546Sopenharmony_ci   struct si_buffer_resources internal_bindings;
1090bf215546Sopenharmony_ci   struct si_buffer_resources const_and_shader_buffers[SI_NUM_SHADERS];
1091bf215546Sopenharmony_ci   struct si_samplers samplers[SI_NUM_SHADERS];
1092bf215546Sopenharmony_ci   struct si_images images[SI_NUM_SHADERS];
1093bf215546Sopenharmony_ci   bool bo_list_add_all_resident_resources;
1094bf215546Sopenharmony_ci   bool bo_list_add_all_gfx_resources;
1095bf215546Sopenharmony_ci   bool bo_list_add_all_compute_resources;
1096bf215546Sopenharmony_ci
1097bf215546Sopenharmony_ci   /* other shader resources */
1098bf215546Sopenharmony_ci   struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on GFX7 */
1099bf215546Sopenharmony_ci   struct pipe_resource *esgs_ring;
1100bf215546Sopenharmony_ci   struct pipe_resource *gsvs_ring;
1101bf215546Sopenharmony_ci   struct pipe_resource *tess_rings;
1102bf215546Sopenharmony_ci   struct pipe_resource *tess_rings_tmz;
1103bf215546Sopenharmony_ci   union pipe_color_union *border_color_table; /* in CPU memory, any endian */
1104bf215546Sopenharmony_ci   struct si_resource *border_color_buffer;
1105bf215546Sopenharmony_ci   union pipe_color_union *border_color_map; /* in VRAM (slow access), little endian */
1106bf215546Sopenharmony_ci   unsigned border_color_count;
1107bf215546Sopenharmony_ci   unsigned num_vs_blit_sgprs;
1108bf215546Sopenharmony_ci   uint32_t vs_blit_sh_data[SI_VS_BLIT_SGPRS_POS_TEXCOORD];
1109bf215546Sopenharmony_ci   uint32_t cs_user_data[4];
1110bf215546Sopenharmony_ci
1111bf215546Sopenharmony_ci   /* Vertex buffers. */
1112bf215546Sopenharmony_ci   bool vertex_buffers_dirty;
1113bf215546Sopenharmony_ci   bool vertex_buffer_pointer_dirty;
1114bf215546Sopenharmony_ci   bool vertex_buffer_user_sgprs_dirty;
1115bf215546Sopenharmony_ci   struct pipe_vertex_buffer vertex_buffer[SI_NUM_VERTEX_BUFFERS];
1116bf215546Sopenharmony_ci   uint16_t vertex_buffer_unaligned; /* bitmask of not dword-aligned buffers */
1117bf215546Sopenharmony_ci   uint32_t *vb_descriptors_gpu_list;
1118bf215546Sopenharmony_ci   struct si_resource *vb_descriptors_buffer;
1119bf215546Sopenharmony_ci   unsigned vb_descriptors_offset;
1120bf215546Sopenharmony_ci   unsigned vb_descriptor_user_sgprs[5 * 4];
1121bf215546Sopenharmony_ci
1122bf215546Sopenharmony_ci   /* MSAA config state. */
1123bf215546Sopenharmony_ci   int ps_iter_samples;
1124bf215546Sopenharmony_ci   bool ps_uses_fbfetch;
1125bf215546Sopenharmony_ci   bool smoothing_enabled;
1126bf215546Sopenharmony_ci
1127bf215546Sopenharmony_ci   /* point smoothing state.*/
1128bf215546Sopenharmony_ci   bool point_smoothing_enabled;
1129bf215546Sopenharmony_ci
1130bf215546Sopenharmony_ci   /* DB render state. */
1131bf215546Sopenharmony_ci   unsigned ps_db_shader_control;
1132bf215546Sopenharmony_ci   unsigned dbcb_copy_sample;
1133bf215546Sopenharmony_ci   bool dbcb_depth_copy_enabled : 1;
1134bf215546Sopenharmony_ci   bool dbcb_stencil_copy_enabled : 1;
1135bf215546Sopenharmony_ci   bool db_flush_depth_inplace : 1;
1136bf215546Sopenharmony_ci   bool db_flush_stencil_inplace : 1;
1137bf215546Sopenharmony_ci   bool db_depth_clear : 1;
1138bf215546Sopenharmony_ci   bool db_depth_disable_expclear : 1;
1139bf215546Sopenharmony_ci   bool db_stencil_clear : 1;
1140bf215546Sopenharmony_ci   bool db_stencil_disable_expclear : 1;
1141bf215546Sopenharmony_ci   bool occlusion_queries_disabled : 1;
1142bf215546Sopenharmony_ci   bool generate_mipmap_for_depth : 1;
1143bf215546Sopenharmony_ci   bool allow_flat_shading : 1;
1144bf215546Sopenharmony_ci
1145bf215546Sopenharmony_ci   /* Emitted draw state. */
1146bf215546Sopenharmony_ci   bool ngg : 1;
1147bf215546Sopenharmony_ci   bool disable_instance_packing : 1;
1148bf215546Sopenharmony_ci   uint16_t ngg_culling;
1149bf215546Sopenharmony_ci   unsigned last_index_size;
1150bf215546Sopenharmony_ci   int last_base_vertex;
1151bf215546Sopenharmony_ci   unsigned last_start_instance;
1152bf215546Sopenharmony_ci   unsigned last_instance_count;
1153bf215546Sopenharmony_ci   unsigned last_drawid;
1154bf215546Sopenharmony_ci   unsigned last_sh_base_reg;
1155bf215546Sopenharmony_ci   int last_primitive_restart_en;
1156bf215546Sopenharmony_ci   unsigned last_restart_index;
1157bf215546Sopenharmony_ci   unsigned last_prim;
1158bf215546Sopenharmony_ci   unsigned last_multi_vgt_param;
1159bf215546Sopenharmony_ci   unsigned last_gs_out_prim;
1160bf215546Sopenharmony_ci   unsigned current_vs_state; /* all VS bits including LS bits */
1161bf215546Sopenharmony_ci   unsigned current_gs_state; /* only GS and NGG bits */
1162bf215546Sopenharmony_ci   unsigned last_vs_state;
1163bf215546Sopenharmony_ci   unsigned last_gs_state;
1164bf215546Sopenharmony_ci   enum pipe_prim_type current_rast_prim; /* primitive type after TES, GS */
1165bf215546Sopenharmony_ci
1166bf215546Sopenharmony_ci   struct si_small_prim_cull_info last_small_prim_cull_info;
1167bf215546Sopenharmony_ci   struct si_resource *small_prim_cull_info_buf;
1168bf215546Sopenharmony_ci   uint64_t small_prim_cull_info_address;
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_ci   /* Scratch buffer */
1171bf215546Sopenharmony_ci   struct si_resource *scratch_buffer;
1172bf215546Sopenharmony_ci   unsigned spi_tmpring_size;
1173bf215546Sopenharmony_ci   unsigned max_seen_scratch_bytes_per_wave;
1174bf215546Sopenharmony_ci   unsigned max_seen_compute_scratch_bytes_per_wave;
1175bf215546Sopenharmony_ci
1176bf215546Sopenharmony_ci   struct si_resource *compute_scratch_buffer;
1177bf215546Sopenharmony_ci
1178bf215546Sopenharmony_ci   /* Emitted derived tessellation state. */
1179bf215546Sopenharmony_ci   /* Local shader (VS), or HS if LS-HS are merged. */
1180bf215546Sopenharmony_ci   struct si_shader *last_ls;
1181bf215546Sopenharmony_ci   struct si_shader_selector *last_tcs;
1182bf215546Sopenharmony_ci   unsigned last_num_tcs_input_cp;
1183bf215546Sopenharmony_ci   unsigned last_tes_sh_base;
1184bf215546Sopenharmony_ci   bool last_tess_uses_primid;
1185bf215546Sopenharmony_ci   unsigned last_num_patches;
1186bf215546Sopenharmony_ci   unsigned last_ls_hs_config;
1187bf215546Sopenharmony_ci
1188bf215546Sopenharmony_ci   /* Debug state. */
1189bf215546Sopenharmony_ci   bool is_debug;
1190bf215546Sopenharmony_ci   struct si_saved_cs *current_saved_cs;
1191bf215546Sopenharmony_ci   uint64_t dmesg_timestamp;
1192bf215546Sopenharmony_ci   unsigned apitrace_call_number;
1193bf215546Sopenharmony_ci
1194bf215546Sopenharmony_ci   /* Other state */
1195bf215546Sopenharmony_ci   bool need_check_render_feedback;
1196bf215546Sopenharmony_ci   bool decompression_enabled;
1197bf215546Sopenharmony_ci   bool dpbb_force_off;
1198bf215546Sopenharmony_ci   bool dpbb_force_off_profile_vs;
1199bf215546Sopenharmony_ci   bool dpbb_force_off_profile_ps;
1200bf215546Sopenharmony_ci   bool vs_writes_viewport_index;
1201bf215546Sopenharmony_ci   bool vs_disables_clipping_viewport;
1202bf215546Sopenharmony_ci
1203bf215546Sopenharmony_ci   /* Precomputed IA_MULTI_VGT_PARAM */
1204bf215546Sopenharmony_ci   union si_vgt_param_key ia_multi_vgt_param_key;
1205bf215546Sopenharmony_ci   unsigned ia_multi_vgt_param[SI_NUM_VGT_PARAM_STATES];
1206bf215546Sopenharmony_ci
1207bf215546Sopenharmony_ci   /* Bindless descriptors. */
1208bf215546Sopenharmony_ci   struct si_descriptors bindless_descriptors;
1209bf215546Sopenharmony_ci   struct util_idalloc bindless_used_slots;
1210bf215546Sopenharmony_ci   unsigned num_bindless_descriptors;
1211bf215546Sopenharmony_ci   bool bindless_descriptors_dirty;
1212bf215546Sopenharmony_ci   bool graphics_bindless_pointer_dirty;
1213bf215546Sopenharmony_ci   bool compute_bindless_pointer_dirty;
1214bf215546Sopenharmony_ci   bool gs_attribute_ring_pointer_dirty;
1215bf215546Sopenharmony_ci
1216bf215546Sopenharmony_ci   /* Allocated bindless handles */
1217bf215546Sopenharmony_ci   struct hash_table *tex_handles;
1218bf215546Sopenharmony_ci   struct hash_table *img_handles;
1219bf215546Sopenharmony_ci
1220bf215546Sopenharmony_ci   /* Resident bindless handles */
1221bf215546Sopenharmony_ci   struct util_dynarray resident_tex_handles;
1222bf215546Sopenharmony_ci   struct util_dynarray resident_img_handles;
1223bf215546Sopenharmony_ci
1224bf215546Sopenharmony_ci   /* Resident bindless handles which need decompression */
1225bf215546Sopenharmony_ci   struct util_dynarray resident_tex_needs_color_decompress;
1226bf215546Sopenharmony_ci   struct util_dynarray resident_img_needs_color_decompress;
1227bf215546Sopenharmony_ci   struct util_dynarray resident_tex_needs_depth_decompress;
1228bf215546Sopenharmony_ci
1229bf215546Sopenharmony_ci   /* Bindless state */
1230bf215546Sopenharmony_ci   bool uses_bindless_samplers;
1231bf215546Sopenharmony_ci   bool uses_bindless_images;
1232bf215546Sopenharmony_ci
1233bf215546Sopenharmony_ci   /* MSAA sample locations.
1234bf215546Sopenharmony_ci    * The first index is the sample index.
1235bf215546Sopenharmony_ci    * The second index is the coordinate: X, Y. */
1236bf215546Sopenharmony_ci   struct {
1237bf215546Sopenharmony_ci      float x1[1][2];
1238bf215546Sopenharmony_ci      float x2[2][2];
1239bf215546Sopenharmony_ci      float x4[4][2];
1240bf215546Sopenharmony_ci      float x8[8][2];
1241bf215546Sopenharmony_ci      float x16[16][2];
1242bf215546Sopenharmony_ci   } sample_positions;
1243bf215546Sopenharmony_ci   struct pipe_resource *sample_pos_buffer;
1244bf215546Sopenharmony_ci
1245bf215546Sopenharmony_ci   /* Misc stats. */
1246bf215546Sopenharmony_ci   unsigned num_draw_calls;
1247bf215546Sopenharmony_ci   unsigned num_decompress_calls;
1248bf215546Sopenharmony_ci   unsigned num_prim_restart_calls;
1249bf215546Sopenharmony_ci   unsigned num_compute_calls;
1250bf215546Sopenharmony_ci   unsigned num_cp_dma_calls;
1251bf215546Sopenharmony_ci   unsigned num_vs_flushes;
1252bf215546Sopenharmony_ci   unsigned num_ps_flushes;
1253bf215546Sopenharmony_ci   unsigned num_cs_flushes;
1254bf215546Sopenharmony_ci   unsigned num_cb_cache_flushes;
1255bf215546Sopenharmony_ci   unsigned num_db_cache_flushes;
1256bf215546Sopenharmony_ci   unsigned num_L2_invalidates;
1257bf215546Sopenharmony_ci   unsigned num_L2_writebacks;
1258bf215546Sopenharmony_ci   unsigned num_resident_handles;
1259bf215546Sopenharmony_ci   uint64_t num_alloc_tex_transfer_bytes;
1260bf215546Sopenharmony_ci   unsigned last_tex_ps_draw_ratio; /* for query */
1261bf215546Sopenharmony_ci   unsigned context_roll;
1262bf215546Sopenharmony_ci
1263bf215546Sopenharmony_ci   /* Queries. */
1264bf215546Sopenharmony_ci   /* Maintain the list of active queries for pausing between IBs. */
1265bf215546Sopenharmony_ci   int num_occlusion_queries;
1266bf215546Sopenharmony_ci   int num_perfect_occlusion_queries;
1267bf215546Sopenharmony_ci   int num_pipeline_stat_queries;
1268bf215546Sopenharmony_ci   int num_pipeline_stat_emulated_queries;
1269bf215546Sopenharmony_ci   struct list_head active_queries;
1270bf215546Sopenharmony_ci   unsigned num_cs_dw_queries_suspend;
1271bf215546Sopenharmony_ci   /* Shared buffer for pipeline stats queries implemented with an atomic op */
1272bf215546Sopenharmony_ci   struct si_resource *pipeline_stats_query_buf;
1273bf215546Sopenharmony_ci
1274bf215546Sopenharmony_ci   /* Render condition. */
1275bf215546Sopenharmony_ci   struct pipe_query *render_cond;
1276bf215546Sopenharmony_ci   unsigned render_cond_mode;
1277bf215546Sopenharmony_ci   bool render_cond_invert;
1278bf215546Sopenharmony_ci   bool render_cond_enabled; /* for u_blitter */
1279bf215546Sopenharmony_ci
1280bf215546Sopenharmony_ci   /* Shader-based queries. */
1281bf215546Sopenharmony_ci   struct list_head shader_query_buffers;
1282bf215546Sopenharmony_ci   unsigned num_active_shader_queries;
1283bf215546Sopenharmony_ci
1284bf215546Sopenharmony_ci   bool force_cb_shader_coherent;
1285bf215546Sopenharmony_ci
1286bf215546Sopenharmony_ci   struct si_tracked_regs tracked_regs;
1287bf215546Sopenharmony_ci
1288bf215546Sopenharmony_ci   /* Resources that need to be flushed, but will not get an explicit
1289bf215546Sopenharmony_ci    * flush_resource from the frontend and that will need to get flushed during
1290bf215546Sopenharmony_ci    * a context flush.
1291bf215546Sopenharmony_ci    */
1292bf215546Sopenharmony_ci   struct hash_table *dirty_implicit_resources;
1293bf215546Sopenharmony_ci
1294bf215546Sopenharmony_ci   pipe_draw_vbo_func draw_vbo[2][2][2];
1295bf215546Sopenharmony_ci   pipe_draw_vertex_state_func draw_vertex_state[2][2][2];
1296bf215546Sopenharmony_ci   /* When b.draw_vbo is a wrapper, real_draw_vbo is the real draw_vbo function */
1297bf215546Sopenharmony_ci   pipe_draw_vbo_func real_draw_vbo;
1298bf215546Sopenharmony_ci   pipe_draw_vertex_state_func real_draw_vertex_state;
1299bf215546Sopenharmony_ci   void (*emit_spi_map[33])(struct si_context *sctx);
1300bf215546Sopenharmony_ci
1301bf215546Sopenharmony_ci   /* SQTT */
1302bf215546Sopenharmony_ci   struct ac_thread_trace_data *thread_trace;
1303bf215546Sopenharmony_ci   struct ac_spm_trace_data spm_trace;
1304bf215546Sopenharmony_ci   struct pipe_fence_handle *last_sqtt_fence;
1305bf215546Sopenharmony_ci   enum rgp_sqtt_marker_event_type sqtt_next_event;
1306bf215546Sopenharmony_ci   bool thread_trace_enabled;
1307bf215546Sopenharmony_ci
1308bf215546Sopenharmony_ci   unsigned context_flags;
1309bf215546Sopenharmony_ci
1310bf215546Sopenharmony_ci   /* Shaders. */
1311bf215546Sopenharmony_ci   /* TODO: move other shaders here too */
1312bf215546Sopenharmony_ci   /* Only used for DCC MSAA clears with 4-8 fragments and 4-16 samples. */
1313bf215546Sopenharmony_ci   void *cs_clear_dcc_msaa[32][5][2][3][2]; /* [swizzle_mode][log2(bpe)][fragments == 8][log2(samples)-2][is_array] */
1314bf215546Sopenharmony_ci};
1315bf215546Sopenharmony_ci
1316bf215546Sopenharmony_ci/* si_blit.c */
1317bf215546Sopenharmony_cienum si_blitter_op /* bitmask */
1318bf215546Sopenharmony_ci{
1319bf215546Sopenharmony_ci   SI_SAVE_TEXTURES = 1,
1320bf215546Sopenharmony_ci   SI_SAVE_FRAMEBUFFER = 2,
1321bf215546Sopenharmony_ci   SI_SAVE_FRAGMENT_STATE = 4,
1322bf215546Sopenharmony_ci   SI_DISABLE_RENDER_COND = 8,
1323bf215546Sopenharmony_ci};
1324bf215546Sopenharmony_ci
1325bf215546Sopenharmony_civoid si_blitter_begin(struct si_context *sctx, enum si_blitter_op op);
1326bf215546Sopenharmony_civoid si_blitter_end(struct si_context *sctx);
1327bf215546Sopenharmony_civoid si_init_blit_functions(struct si_context *sctx);
1328bf215546Sopenharmony_civoid si_decompress_textures(struct si_context *sctx, unsigned shader_mask);
1329bf215546Sopenharmony_civoid si_decompress_subresource(struct pipe_context *ctx, struct pipe_resource *tex, unsigned planes,
1330bf215546Sopenharmony_ci                               unsigned level, unsigned first_layer, unsigned last_layer,
1331bf215546Sopenharmony_ci                               bool need_fmask_expand);
1332bf215546Sopenharmony_civoid si_resource_copy_region(struct pipe_context *ctx, struct pipe_resource *dst,
1333bf215546Sopenharmony_ci                             unsigned dst_level, unsigned dstx, unsigned dsty, unsigned dstz,
1334bf215546Sopenharmony_ci                             struct pipe_resource *src, unsigned src_level,
1335bf215546Sopenharmony_ci                             const struct pipe_box *src_box);
1336bf215546Sopenharmony_civoid si_decompress_dcc(struct si_context *sctx, struct si_texture *tex);
1337bf215546Sopenharmony_civoid si_flush_implicit_resources(struct si_context *sctx);
1338bf215546Sopenharmony_cibool si_msaa_resolve_blit_via_CB(struct pipe_context *ctx, const struct pipe_blit_info *info);
1339bf215546Sopenharmony_civoid si_gfx_blit(struct pipe_context *ctx, const struct pipe_blit_info *info);
1340bf215546Sopenharmony_ci
1341bf215546Sopenharmony_ci/* si_nir_optim.c */
1342bf215546Sopenharmony_cibool si_nir_is_output_const_if_tex_is_const(nir_shader *shader, float *in, float *out, int *texunit);
1343bf215546Sopenharmony_ci
1344bf215546Sopenharmony_ci/* si_buffer.c */
1345bf215546Sopenharmony_cibool si_cs_is_buffer_referenced(struct si_context *sctx, struct pb_buffer *buf,
1346bf215546Sopenharmony_ci                                unsigned usage);
1347bf215546Sopenharmony_civoid *si_buffer_map(struct si_context *sctx, struct si_resource *resource,
1348bf215546Sopenharmony_ci                    unsigned usage);
1349bf215546Sopenharmony_civoid si_init_resource_fields(struct si_screen *sscreen, struct si_resource *res, uint64_t size,
1350bf215546Sopenharmony_ci                             unsigned alignment);
1351bf215546Sopenharmony_cibool si_alloc_resource(struct si_screen *sscreen, struct si_resource *res);
1352bf215546Sopenharmony_cistruct pipe_resource *pipe_aligned_buffer_create(struct pipe_screen *screen, unsigned flags,
1353bf215546Sopenharmony_ci                                                 unsigned usage, unsigned size, unsigned alignment);
1354bf215546Sopenharmony_cistruct si_resource *si_aligned_buffer_create(struct pipe_screen *screen, unsigned flags,
1355bf215546Sopenharmony_ci                                             unsigned usage, unsigned size, unsigned alignment);
1356bf215546Sopenharmony_cistruct pipe_resource *si_buffer_from_winsys_buffer(struct pipe_screen *screen,
1357bf215546Sopenharmony_ci                                                   const struct pipe_resource *templ,
1358bf215546Sopenharmony_ci                                                   struct pb_buffer *imported_buf,
1359bf215546Sopenharmony_ci                                                   uint64_t offset);
1360bf215546Sopenharmony_civoid si_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *dst,
1361bf215546Sopenharmony_ci                               struct pipe_resource *src, unsigned num_rebinds,
1362bf215546Sopenharmony_ci                               uint32_t rebind_mask, uint32_t delete_buffer_id);
1363bf215546Sopenharmony_civoid si_init_screen_buffer_functions(struct si_screen *sscreen);
1364bf215546Sopenharmony_civoid si_init_buffer_functions(struct si_context *sctx);
1365bf215546Sopenharmony_ci
1366bf215546Sopenharmony_ci/* si_clear.c */
1367bf215546Sopenharmony_ci#define SI_CLEAR_TYPE_CMASK  (1 << 0)
1368bf215546Sopenharmony_ci#define SI_CLEAR_TYPE_DCC    (1 << 1)
1369bf215546Sopenharmony_ci#define SI_CLEAR_TYPE_HTILE  (1 << 2)
1370bf215546Sopenharmony_ci
1371bf215546Sopenharmony_cistruct si_clear_info {
1372bf215546Sopenharmony_ci   struct pipe_resource *resource;
1373bf215546Sopenharmony_ci   uint64_t offset;
1374bf215546Sopenharmony_ci   uint32_t size;
1375bf215546Sopenharmony_ci   uint32_t clear_value;
1376bf215546Sopenharmony_ci   uint32_t writemask;
1377bf215546Sopenharmony_ci   bool is_dcc_msaa; /* Clear it as a DCC MSAA image. */
1378bf215546Sopenharmony_ci};
1379bf215546Sopenharmony_ci
1380bf215546Sopenharmony_cienum pipe_format si_simplify_cb_format(enum pipe_format format);
1381bf215546Sopenharmony_cibool vi_alpha_is_on_msb(struct si_screen *sscreen, enum pipe_format format);
1382bf215546Sopenharmony_cibool vi_dcc_get_clear_info(struct si_context *sctx, struct si_texture *tex, unsigned level,
1383bf215546Sopenharmony_ci                           unsigned clear_value, struct si_clear_info *out);
1384bf215546Sopenharmony_civoid si_init_buffer_clear(struct si_clear_info *info,
1385bf215546Sopenharmony_ci                          struct pipe_resource *resource, uint64_t offset,
1386bf215546Sopenharmony_ci                          uint32_t size, uint32_t clear_value);
1387bf215546Sopenharmony_civoid si_execute_clears(struct si_context *sctx, struct si_clear_info *info,
1388bf215546Sopenharmony_ci                       unsigned num_clears, unsigned types);
1389bf215546Sopenharmony_civoid si_init_clear_functions(struct si_context *sctx);
1390bf215546Sopenharmony_ci
1391bf215546Sopenharmony_ci/* si_compute_blit.c */
1392bf215546Sopenharmony_ci#define SI_OP_SYNC_CS_BEFORE              (1 << 0)
1393bf215546Sopenharmony_ci#define SI_OP_SYNC_PS_BEFORE              (1 << 1)
1394bf215546Sopenharmony_ci#define SI_OP_SYNC_CPDMA_BEFORE           (1 << 2) /* only affects CP DMA calls */
1395bf215546Sopenharmony_ci#define SI_OP_SYNC_BEFORE                 (SI_OP_SYNC_CS_BEFORE | SI_OP_SYNC_PS_BEFORE | SI_OP_SYNC_CPDMA_BEFORE)
1396bf215546Sopenharmony_ci#define SI_OP_SYNC_AFTER                  (1 << 3)
1397bf215546Sopenharmony_ci#define SI_OP_SYNC_BEFORE_AFTER           (SI_OP_SYNC_BEFORE | SI_OP_SYNC_AFTER)
1398bf215546Sopenharmony_ci#define SI_OP_SKIP_CACHE_INV_BEFORE       (1 << 4) /* don't invalidate caches */
1399bf215546Sopenharmony_ci#define SI_OP_CS_IMAGE                    (1 << 5)
1400bf215546Sopenharmony_ci#define SI_OP_CS_RENDER_COND_ENABLE       (1 << 6)
1401bf215546Sopenharmony_ci#define SI_OP_CPDMA_SKIP_CHECK_CS_SPACE   (1 << 7) /* don't call need_cs_space */
1402bf215546Sopenharmony_ci#define SI_OP_SYNC_GE_BEFORE              (1 << 8) /* only sync VS, TCS, TES, GS */
1403bf215546Sopenharmony_ci
1404bf215546Sopenharmony_ciunsigned si_get_flush_flags(struct si_context *sctx, enum si_coherency coher,
1405bf215546Sopenharmony_ci                            enum si_cache_policy cache_policy);
1406bf215546Sopenharmony_civoid si_launch_grid_internal_ssbos(struct si_context *sctx, struct pipe_grid_info *info,
1407bf215546Sopenharmony_ci                                   void *shader, unsigned flags, enum si_coherency coher,
1408bf215546Sopenharmony_ci                                   unsigned num_buffers, const struct pipe_shader_buffer *buffers,
1409bf215546Sopenharmony_ci                                   unsigned writeable_bitmask);
1410bf215546Sopenharmony_cienum si_clear_method {
1411bf215546Sopenharmony_ci  SI_CP_DMA_CLEAR_METHOD,
1412bf215546Sopenharmony_ci  SI_COMPUTE_CLEAR_METHOD,
1413bf215546Sopenharmony_ci  SI_AUTO_SELECT_CLEAR_METHOD
1414bf215546Sopenharmony_ci};
1415bf215546Sopenharmony_civoid si_clear_buffer(struct si_context *sctx, struct pipe_resource *dst,
1416bf215546Sopenharmony_ci                     uint64_t offset, uint64_t size, uint32_t *clear_value,
1417bf215546Sopenharmony_ci                     uint32_t clear_value_size, unsigned flags,
1418bf215546Sopenharmony_ci                     enum si_coherency coher, enum si_clear_method method);
1419bf215546Sopenharmony_civoid si_compute_clear_buffer_rmw(struct si_context *sctx, struct pipe_resource *dst,
1420bf215546Sopenharmony_ci                                 unsigned dst_offset, unsigned size,
1421bf215546Sopenharmony_ci                                 uint32_t clear_value, uint32_t writebitmask,
1422bf215546Sopenharmony_ci                                 unsigned flags, enum si_coherency coher);
1423bf215546Sopenharmony_civoid si_screen_clear_buffer(struct si_screen *sscreen, struct pipe_resource *dst, uint64_t offset,
1424bf215546Sopenharmony_ci                            uint64_t size, unsigned value, unsigned flags);
1425bf215546Sopenharmony_civoid si_copy_buffer(struct si_context *sctx, struct pipe_resource *dst, struct pipe_resource *src,
1426bf215546Sopenharmony_ci                    uint64_t dst_offset, uint64_t src_offset, unsigned size, unsigned flags);
1427bf215546Sopenharmony_cibool si_compute_copy_image(struct si_context *sctx, struct pipe_resource *dst, unsigned dst_level,
1428bf215546Sopenharmony_ci                           struct pipe_resource *src, unsigned src_level, unsigned dstx,
1429bf215546Sopenharmony_ci                           unsigned dsty, unsigned dstz, const struct pipe_box *src_box,
1430bf215546Sopenharmony_ci                           unsigned flags);
1431bf215546Sopenharmony_civoid si_compute_clear_render_target(struct pipe_context *ctx, struct pipe_surface *dstsurf,
1432bf215546Sopenharmony_ci                                    const union pipe_color_union *color, unsigned dstx,
1433bf215546Sopenharmony_ci                                    unsigned dsty, unsigned width, unsigned height,
1434bf215546Sopenharmony_ci                                    bool render_condition_enabled);
1435bf215546Sopenharmony_civoid si_retile_dcc(struct si_context *sctx, struct si_texture *tex);
1436bf215546Sopenharmony_civoid gfx9_clear_dcc_msaa(struct si_context *sctx, struct pipe_resource *res, uint32_t clear_value,
1437bf215546Sopenharmony_ci                         unsigned flags, enum si_coherency coher);
1438bf215546Sopenharmony_civoid si_compute_expand_fmask(struct pipe_context *ctx, struct pipe_resource *tex);
1439bf215546Sopenharmony_civoid si_init_compute_blit_functions(struct si_context *sctx);
1440bf215546Sopenharmony_ci
1441bf215546Sopenharmony_ci/* si_cp_dma.c */
1442bf215546Sopenharmony_civoid si_cp_dma_wait_for_idle(struct si_context *sctx, struct radeon_cmdbuf *cs);
1443bf215546Sopenharmony_civoid si_cp_dma_clear_buffer(struct si_context *sctx, struct radeon_cmdbuf *cs,
1444bf215546Sopenharmony_ci                            struct pipe_resource *dst, uint64_t offset, uint64_t size,
1445bf215546Sopenharmony_ci                            unsigned value, unsigned user_flags, enum si_coherency coher,
1446bf215546Sopenharmony_ci                            enum si_cache_policy cache_policy);
1447bf215546Sopenharmony_civoid si_cp_dma_copy_buffer(struct si_context *sctx, struct pipe_resource *dst,
1448bf215546Sopenharmony_ci                           struct pipe_resource *src, uint64_t dst_offset, uint64_t src_offset,
1449bf215546Sopenharmony_ci                           unsigned size, unsigned user_flags, enum si_coherency coher,
1450bf215546Sopenharmony_ci                           enum si_cache_policy cache_policy);
1451bf215546Sopenharmony_civoid si_test_gds(struct si_context *sctx);
1452bf215546Sopenharmony_civoid si_cp_write_data(struct si_context *sctx, struct si_resource *buf, unsigned offset,
1453bf215546Sopenharmony_ci                      unsigned size, unsigned dst_sel, unsigned engine, const void *data);
1454bf215546Sopenharmony_civoid si_cp_copy_data(struct si_context *sctx, struct radeon_cmdbuf *cs, unsigned dst_sel,
1455bf215546Sopenharmony_ci                     struct si_resource *dst, unsigned dst_offset, unsigned src_sel,
1456bf215546Sopenharmony_ci                     struct si_resource *src, unsigned src_offset);
1457bf215546Sopenharmony_ci
1458bf215546Sopenharmony_ci/* si_cp_reg_shadowing.c */
1459bf215546Sopenharmony_civoid si_init_cp_reg_shadowing(struct si_context *sctx);
1460bf215546Sopenharmony_ci
1461bf215546Sopenharmony_ci/* si_debug.c */
1462bf215546Sopenharmony_civoid si_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, struct radeon_saved_cs *saved,
1463bf215546Sopenharmony_ci                bool get_buffer_list);
1464bf215546Sopenharmony_civoid si_clear_saved_cs(struct radeon_saved_cs *saved);
1465bf215546Sopenharmony_civoid si_destroy_saved_cs(struct si_saved_cs *scs);
1466bf215546Sopenharmony_civoid si_auto_log_cs(void *data, struct u_log_context *log);
1467bf215546Sopenharmony_civoid si_log_hw_flush(struct si_context *sctx);
1468bf215546Sopenharmony_civoid si_log_draw_state(struct si_context *sctx, struct u_log_context *log);
1469bf215546Sopenharmony_civoid si_log_compute_state(struct si_context *sctx, struct u_log_context *log);
1470bf215546Sopenharmony_civoid si_init_debug_functions(struct si_context *sctx);
1471bf215546Sopenharmony_civoid si_check_vm_faults(struct si_context *sctx, struct radeon_saved_cs *saved,
1472bf215546Sopenharmony_ci                        enum amd_ip_type ring);
1473bf215546Sopenharmony_cibool si_replace_shader(unsigned num, struct si_shader_binary *binary);
1474bf215546Sopenharmony_civoid si_print_current_ib(struct si_context *sctx, FILE *f);
1475bf215546Sopenharmony_ci
1476bf215546Sopenharmony_ci/* si_fence.c */
1477bf215546Sopenharmony_civoid si_cp_release_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, unsigned event,
1478bf215546Sopenharmony_ci                       unsigned event_flags, unsigned dst_sel, unsigned int_sel, unsigned data_sel,
1479bf215546Sopenharmony_ci                       struct si_resource *buf, uint64_t va, uint32_t new_fence,
1480bf215546Sopenharmony_ci                       unsigned query_type);
1481bf215546Sopenharmony_ciunsigned si_cp_write_fence_dwords(struct si_screen *screen);
1482bf215546Sopenharmony_civoid si_cp_wait_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, uint64_t va, uint32_t ref,
1483bf215546Sopenharmony_ci                    uint32_t mask, unsigned flags);
1484bf215546Sopenharmony_civoid si_init_fence_functions(struct si_context *ctx);
1485bf215546Sopenharmony_civoid si_init_screen_fence_functions(struct si_screen *screen);
1486bf215546Sopenharmony_cistruct pipe_fence_handle *si_create_fence(struct pipe_context *ctx,
1487bf215546Sopenharmony_ci                                          struct tc_unflushed_batch_token *tc_token);
1488bf215546Sopenharmony_ci
1489bf215546Sopenharmony_ci/* si_get.c */
1490bf215546Sopenharmony_civoid si_init_screen_get_functions(struct si_screen *sscreen);
1491bf215546Sopenharmony_ci
1492bf215546Sopenharmony_cibool si_sdma_copy_image(struct si_context *ctx, struct si_texture *dst, struct si_texture *src);
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_ci/* si_gfx_cs.c */
1495bf215546Sopenharmony_civoid si_flush_gfx_cs(struct si_context *ctx, unsigned flags, struct pipe_fence_handle **fence);
1496bf215546Sopenharmony_civoid si_allocate_gds(struct si_context *ctx);
1497bf215546Sopenharmony_civoid si_set_tracked_regs_to_clear_state(struct si_context *ctx);
1498bf215546Sopenharmony_civoid si_begin_new_gfx_cs(struct si_context *ctx, bool first_cs);
1499bf215546Sopenharmony_civoid si_trace_emit(struct si_context *sctx);
1500bf215546Sopenharmony_civoid si_emit_surface_sync(struct si_context *sctx, struct radeon_cmdbuf *cs,
1501bf215546Sopenharmony_ci                          unsigned cp_coher_cntl);
1502bf215546Sopenharmony_civoid gfx10_emit_cache_flush(struct si_context *sctx, struct radeon_cmdbuf *cs);
1503bf215546Sopenharmony_civoid si_emit_cache_flush(struct si_context *sctx, struct radeon_cmdbuf *cs);
1504bf215546Sopenharmony_ci/* Replace the sctx->b.draw_vbo function with a wrapper. This can be use to implement
1505bf215546Sopenharmony_ci * optimizations without affecting the normal draw_vbo functions perf.
1506bf215546Sopenharmony_ci */
1507bf215546Sopenharmony_civoid si_install_draw_wrapper(struct si_context *sctx, pipe_draw_vbo_func wrapper,
1508bf215546Sopenharmony_ci                             pipe_draw_vertex_state_func vstate_wrapper);
1509bf215546Sopenharmony_ci
1510bf215546Sopenharmony_ci/* si_gpu_load.c */
1511bf215546Sopenharmony_civoid si_gpu_load_kill_thread(struct si_screen *sscreen);
1512bf215546Sopenharmony_ciuint64_t si_begin_counter(struct si_screen *sscreen, unsigned type);
1513bf215546Sopenharmony_ciunsigned si_end_counter(struct si_screen *sscreen, unsigned type, uint64_t begin);
1514bf215546Sopenharmony_ci
1515bf215546Sopenharmony_ci/* si_compute.c */
1516bf215546Sopenharmony_civoid si_emit_initial_compute_regs(struct si_context *sctx, struct radeon_cmdbuf *cs);
1517bf215546Sopenharmony_civoid si_init_compute_functions(struct si_context *sctx);
1518bf215546Sopenharmony_ci
1519bf215546Sopenharmony_ci/* si_pipe.c */
1520bf215546Sopenharmony_cibool si_init_compiler(struct si_screen *sscreen, struct ac_llvm_compiler *compiler);
1521bf215546Sopenharmony_civoid si_init_aux_async_compute_ctx(struct si_screen *sscreen);
1522bf215546Sopenharmony_cistruct si_context* si_get_aux_context(struct si_screen *sscreen);
1523bf215546Sopenharmony_civoid si_put_aux_context_flush(struct si_screen *sscreen);
1524bf215546Sopenharmony_ci
1525bf215546Sopenharmony_ci/* si_perfcounters.c */
1526bf215546Sopenharmony_civoid si_init_perfcounters(struct si_screen *screen);
1527bf215546Sopenharmony_civoid si_destroy_perfcounters(struct si_screen *screen);
1528bf215546Sopenharmony_civoid si_inhibit_clockgating(struct si_context *sctx, struct radeon_cmdbuf *cs, bool inhibit);
1529bf215546Sopenharmony_civoid si_pc_emit_shaders(struct radeon_cmdbuf *cs, unsigned shaders);
1530bf215546Sopenharmony_civoid si_pc_emit_spm_start(struct radeon_cmdbuf *cs);
1531bf215546Sopenharmony_civoid si_pc_emit_spm_stop(struct radeon_cmdbuf *cs, bool never_stop_sq_perf_counters,
1532bf215546Sopenharmony_ci                         bool never_send_perfcounter_stop);
1533bf215546Sopenharmony_civoid si_pc_emit_spm_reset(struct radeon_cmdbuf *cs);
1534bf215546Sopenharmony_civoid si_emit_spm_setup(struct si_context *sctx, struct radeon_cmdbuf *cs);
1535bf215546Sopenharmony_cibool si_spm_init(struct si_context *sctx);
1536bf215546Sopenharmony_civoid si_spm_finish(struct si_context *sctx);
1537bf215546Sopenharmony_ci
1538bf215546Sopenharmony_ci/* si_query.c */
1539bf215546Sopenharmony_civoid si_init_screen_query_functions(struct si_screen *sscreen);
1540bf215546Sopenharmony_civoid si_init_query_functions(struct si_context *sctx);
1541bf215546Sopenharmony_civoid si_suspend_queries(struct si_context *sctx);
1542bf215546Sopenharmony_civoid si_resume_queries(struct si_context *sctx);
1543bf215546Sopenharmony_ci
1544bf215546Sopenharmony_ci/* si_shaderlib_nir.c */
1545bf215546Sopenharmony_civoid *si_create_copy_image_cs(struct si_context *sctx, bool src_is_1d_array, bool dst_is_1d_array);
1546bf215546Sopenharmony_civoid *si_create_dcc_retile_cs(struct si_context *sctx, struct radeon_surf *surf);
1547bf215546Sopenharmony_civoid *gfx9_create_clear_dcc_msaa_cs(struct si_context *sctx, struct si_texture *tex);
1548bf215546Sopenharmony_civoid *si_create_passthrough_tcs(struct si_context *sctx);
1549bf215546Sopenharmony_ci
1550bf215546Sopenharmony_ci/* si_shaderlib_tgsi.c */
1551bf215546Sopenharmony_civoid *si_get_blitter_vs(struct si_context *sctx, enum blitter_attrib_type type,
1552bf215546Sopenharmony_ci                        unsigned num_layers);
1553bf215546Sopenharmony_civoid *si_create_dma_compute_shader(struct pipe_context *ctx, unsigned num_dwords_per_thread,
1554bf215546Sopenharmony_ci                                   bool dst_stream_cache_policy, bool is_copy);
1555bf215546Sopenharmony_civoid *si_create_clear_buffer_rmw_cs(struct si_context *sctx);
1556bf215546Sopenharmony_civoid *si_clear_render_target_shader(struct pipe_context *ctx);
1557bf215546Sopenharmony_civoid *si_clear_render_target_shader_1d_array(struct pipe_context *ctx);
1558bf215546Sopenharmony_civoid *si_clear_12bytes_buffer_shader(struct pipe_context *ctx);
1559bf215546Sopenharmony_civoid *si_create_fmask_expand_cs(struct pipe_context *ctx, unsigned num_samples, bool is_array);
1560bf215546Sopenharmony_civoid *si_create_query_result_cs(struct si_context *sctx);
1561bf215546Sopenharmony_civoid *gfx10_create_sh_query_result_cs(struct si_context *sctx);
1562bf215546Sopenharmony_ci
1563bf215546Sopenharmony_ci/* gfx10_query.c */
1564bf215546Sopenharmony_civoid gfx10_init_query(struct si_context *sctx);
1565bf215546Sopenharmony_civoid gfx10_destroy_query(struct si_context *sctx);
1566bf215546Sopenharmony_ci
1567bf215546Sopenharmony_ci/* si_test_image_copy_region.c */
1568bf215546Sopenharmony_civoid si_test_image_copy_region(struct si_screen *sscreen);
1569bf215546Sopenharmony_civoid si_test_blit(struct si_screen *sscreen, unsigned test_flags);
1570bf215546Sopenharmony_ci
1571bf215546Sopenharmony_ci/* si_test_clearbuffer.c */
1572bf215546Sopenharmony_civoid si_test_dma_perf(struct si_screen *sscreen);
1573bf215546Sopenharmony_ci
1574bf215546Sopenharmony_ci/* si_uvd.c */
1575bf215546Sopenharmony_cistruct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
1576bf215546Sopenharmony_ci                                               const struct pipe_video_codec *templ);
1577bf215546Sopenharmony_ci
1578bf215546Sopenharmony_cistruct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
1579bf215546Sopenharmony_ci                                                 const struct pipe_video_buffer *tmpl);
1580bf215546Sopenharmony_cistruct pipe_video_buffer *si_video_buffer_create_with_modifiers(struct pipe_context *pipe,
1581bf215546Sopenharmony_ci                                                                const struct pipe_video_buffer *tmpl,
1582bf215546Sopenharmony_ci                                                                const uint64_t *modifiers,
1583bf215546Sopenharmony_ci                                                                unsigned int modifiers_count);
1584bf215546Sopenharmony_ci
1585bf215546Sopenharmony_ci/* si_state_viewport.c */
1586bf215546Sopenharmony_civoid si_update_vs_viewport_state(struct si_context *ctx);
1587bf215546Sopenharmony_civoid si_init_viewport_functions(struct si_context *ctx);
1588bf215546Sopenharmony_ci
1589bf215546Sopenharmony_ci/* si_texture.c */
1590bf215546Sopenharmony_civoid si_eliminate_fast_color_clear(struct si_context *sctx, struct si_texture *tex,
1591bf215546Sopenharmony_ci                                   bool *ctx_flushed);
1592bf215546Sopenharmony_civoid si_texture_discard_cmask(struct si_screen *sscreen, struct si_texture *tex);
1593bf215546Sopenharmony_cibool si_init_flushed_depth_texture(struct pipe_context *ctx, struct pipe_resource *texture);
1594bf215546Sopenharmony_civoid si_print_texture_info(struct si_screen *sscreen, struct si_texture *tex,
1595bf215546Sopenharmony_ci                           struct u_log_context *log);
1596bf215546Sopenharmony_cistruct pipe_resource *si_texture_create(struct pipe_screen *screen,
1597bf215546Sopenharmony_ci                                        const struct pipe_resource *templ);
1598bf215546Sopenharmony_cibool si_texture_commit(struct si_context *ctx, struct si_resource *res, unsigned level,
1599bf215546Sopenharmony_ci                       struct pipe_box *box, bool commit);
1600bf215546Sopenharmony_cibool vi_dcc_formats_compatible(struct si_screen *sscreen, enum pipe_format format1,
1601bf215546Sopenharmony_ci                               enum pipe_format format2);
1602bf215546Sopenharmony_cibool vi_dcc_formats_are_incompatible(struct pipe_resource *tex, unsigned level,
1603bf215546Sopenharmony_ci                                     enum pipe_format view_format);
1604bf215546Sopenharmony_civoid vi_disable_dcc_if_incompatible_format(struct si_context *sctx, struct pipe_resource *tex,
1605bf215546Sopenharmony_ci                                           unsigned level, enum pipe_format view_format);
1606bf215546Sopenharmony_ciunsigned si_translate_colorswap(enum amd_gfx_level gfx_level, enum pipe_format format,
1607bf215546Sopenharmony_ci                                bool do_endian_swap);
1608bf215546Sopenharmony_cibool si_texture_disable_dcc(struct si_context *sctx, struct si_texture *tex);
1609bf215546Sopenharmony_civoid si_init_screen_texture_functions(struct si_screen *sscreen);
1610bf215546Sopenharmony_civoid si_init_context_texture_functions(struct si_context *sctx);
1611bf215546Sopenharmony_ci
1612bf215546Sopenharmony_ci/* si_sqtt.c */
1613bf215546Sopenharmony_civoid si_sqtt_write_event_marker(struct si_context* sctx, struct radeon_cmdbuf *rcs,
1614bf215546Sopenharmony_ci                                enum rgp_sqtt_marker_event_type api_type,
1615bf215546Sopenharmony_ci                                uint32_t vertex_offset_user_data,
1616bf215546Sopenharmony_ci                                uint32_t instance_offset_user_data,
1617bf215546Sopenharmony_ci                                uint32_t draw_index_user_data);
1618bf215546Sopenharmony_cibool si_sqtt_register_pipeline(struct si_context* sctx, uint64_t pipeline_hash, uint64_t base_address, bool is_compute);
1619bf215546Sopenharmony_cibool si_sqtt_pipeline_is_registered(struct ac_thread_trace_data *thread_trace_data,
1620bf215546Sopenharmony_ci                                    uint64_t pipeline_hash);
1621bf215546Sopenharmony_civoid si_sqtt_describe_pipeline_bind(struct si_context* sctx, uint64_t pipeline_hash, int bind_point);
1622bf215546Sopenharmony_civoid
1623bf215546Sopenharmony_cisi_write_event_with_dims_marker(struct si_context* sctx, struct radeon_cmdbuf *rcs,
1624bf215546Sopenharmony_ci                                enum rgp_sqtt_marker_event_type api_type,
1625bf215546Sopenharmony_ci                                uint32_t x, uint32_t y, uint32_t z);
1626bf215546Sopenharmony_civoid
1627bf215546Sopenharmony_cisi_write_user_event(struct si_context* sctx, struct radeon_cmdbuf *rcs,
1628bf215546Sopenharmony_ci                    enum rgp_sqtt_marker_user_event_type type,
1629bf215546Sopenharmony_ci                    const char *str, int len);
1630bf215546Sopenharmony_civoid
1631bf215546Sopenharmony_cisi_sqtt_describe_barrier_start(struct si_context* sctx, struct radeon_cmdbuf *rcs);
1632bf215546Sopenharmony_civoid
1633bf215546Sopenharmony_cisi_sqtt_describe_barrier_end(struct si_context* sctx, struct radeon_cmdbuf *rcs, unsigned flags);
1634bf215546Sopenharmony_cibool si_init_thread_trace(struct si_context *sctx);
1635bf215546Sopenharmony_civoid si_destroy_thread_trace(struct si_context *sctx);
1636bf215546Sopenharmony_civoid si_handle_thread_trace(struct si_context *sctx, struct radeon_cmdbuf *rcs);
1637bf215546Sopenharmony_ci
1638bf215546Sopenharmony_ci/*
1639bf215546Sopenharmony_ci * common helpers
1640bf215546Sopenharmony_ci */
1641bf215546Sopenharmony_ci
1642bf215546Sopenharmony_cistatic inline struct si_resource *si_resource(struct pipe_resource *r)
1643bf215546Sopenharmony_ci{
1644bf215546Sopenharmony_ci   return (struct si_resource *)r;
1645bf215546Sopenharmony_ci}
1646bf215546Sopenharmony_ci
1647bf215546Sopenharmony_cistatic inline void si_resource_reference(struct si_resource **ptr, struct si_resource *res)
1648bf215546Sopenharmony_ci{
1649bf215546Sopenharmony_ci   pipe_resource_reference((struct pipe_resource **)ptr, (struct pipe_resource *)res);
1650bf215546Sopenharmony_ci}
1651bf215546Sopenharmony_ci
1652bf215546Sopenharmony_cistatic inline void si_texture_reference(struct si_texture **ptr, struct si_texture *res)
1653bf215546Sopenharmony_ci{
1654bf215546Sopenharmony_ci   pipe_resource_reference((struct pipe_resource **)ptr, &res->buffer.b.b);
1655bf215546Sopenharmony_ci}
1656bf215546Sopenharmony_ci
1657bf215546Sopenharmony_cistatic inline void
1658bf215546Sopenharmony_cisi_shader_selector_reference(struct si_context *sctx, /* sctx can optionally be NULL */
1659bf215546Sopenharmony_ci                             struct si_shader_selector **dst, struct si_shader_selector *src)
1660bf215546Sopenharmony_ci{
1661bf215546Sopenharmony_ci   if (*dst == src)
1662bf215546Sopenharmony_ci      return;
1663bf215546Sopenharmony_ci
1664bf215546Sopenharmony_ci   struct si_screen *sscreen = src ? src->screen : (*dst)->screen;
1665bf215546Sopenharmony_ci   util_shader_reference(&sctx->b, &sscreen->live_shader_cache, (void **)dst, src);
1666bf215546Sopenharmony_ci}
1667bf215546Sopenharmony_ci
1668bf215546Sopenharmony_cistatic inline bool vi_dcc_enabled(struct si_texture *tex, unsigned level)
1669bf215546Sopenharmony_ci{
1670bf215546Sopenharmony_ci   return !tex->is_depth && tex->surface.meta_offset && level < tex->surface.num_meta_levels;
1671bf215546Sopenharmony_ci}
1672bf215546Sopenharmony_ci
1673bf215546Sopenharmony_cistatic inline unsigned si_tile_mode_index(struct si_texture *tex, unsigned level, bool stencil)
1674bf215546Sopenharmony_ci{
1675bf215546Sopenharmony_ci   if (stencil)
1676bf215546Sopenharmony_ci      return tex->surface.u.legacy.zs.stencil_tiling_index[level];
1677bf215546Sopenharmony_ci   else
1678bf215546Sopenharmony_ci      return tex->surface.u.legacy.tiling_index[level];
1679bf215546Sopenharmony_ci}
1680bf215546Sopenharmony_ci
1681bf215546Sopenharmony_cistatic inline unsigned si_get_minimum_num_gfx_cs_dwords(struct si_context *sctx,
1682bf215546Sopenharmony_ci                                                        unsigned num_draws)
1683bf215546Sopenharmony_ci{
1684bf215546Sopenharmony_ci   /* Don't count the needed CS space exactly and just use an upper bound.
1685bf215546Sopenharmony_ci    *
1686bf215546Sopenharmony_ci    * Also reserve space for stopping queries at the end of IB, because
1687bf215546Sopenharmony_ci    * the number of active queries is unlimited in theory.
1688bf215546Sopenharmony_ci    */
1689bf215546Sopenharmony_ci   return 2048 + sctx->num_cs_dw_queries_suspend + num_draws * 10;
1690bf215546Sopenharmony_ci}
1691bf215546Sopenharmony_ci
1692bf215546Sopenharmony_cistatic inline void si_context_add_resource_size(struct si_context *sctx, struct pipe_resource *r)
1693bf215546Sopenharmony_ci{
1694bf215546Sopenharmony_ci   if (r) {
1695bf215546Sopenharmony_ci      /* Add memory usage for need_gfx_cs_space */
1696bf215546Sopenharmony_ci      sctx->memory_usage_kb += si_resource(r)->memory_usage_kb;
1697bf215546Sopenharmony_ci   }
1698bf215546Sopenharmony_ci}
1699bf215546Sopenharmony_ci
1700bf215546Sopenharmony_cistatic inline void si_invalidate_draw_sh_constants(struct si_context *sctx)
1701bf215546Sopenharmony_ci{
1702bf215546Sopenharmony_ci   sctx->last_base_vertex = SI_BASE_VERTEX_UNKNOWN;
1703bf215546Sopenharmony_ci   sctx->last_start_instance = SI_START_INSTANCE_UNKNOWN;
1704bf215546Sopenharmony_ci   sctx->last_drawid = SI_DRAW_ID_UNKNOWN;
1705bf215546Sopenharmony_ci}
1706bf215546Sopenharmony_ci
1707bf215546Sopenharmony_cistatic inline void si_invalidate_draw_constants(struct si_context *sctx)
1708bf215546Sopenharmony_ci{
1709bf215546Sopenharmony_ci   si_invalidate_draw_sh_constants(sctx);
1710bf215546Sopenharmony_ci   sctx->last_instance_count = SI_INSTANCE_COUNT_UNKNOWN;
1711bf215546Sopenharmony_ci}
1712bf215546Sopenharmony_ci
1713bf215546Sopenharmony_cistatic inline unsigned si_get_atom_bit(struct si_context *sctx, struct si_atom *atom)
1714bf215546Sopenharmony_ci{
1715bf215546Sopenharmony_ci   return 1 << (atom - sctx->atoms.array);
1716bf215546Sopenharmony_ci}
1717bf215546Sopenharmony_ci
1718bf215546Sopenharmony_cistatic inline void si_set_atom_dirty(struct si_context *sctx, struct si_atom *atom, bool dirty)
1719bf215546Sopenharmony_ci{
1720bf215546Sopenharmony_ci   unsigned bit = si_get_atom_bit(sctx, atom);
1721bf215546Sopenharmony_ci
1722bf215546Sopenharmony_ci   if (dirty)
1723bf215546Sopenharmony_ci      sctx->dirty_atoms |= bit;
1724bf215546Sopenharmony_ci   else
1725bf215546Sopenharmony_ci      sctx->dirty_atoms &= ~bit;
1726bf215546Sopenharmony_ci}
1727bf215546Sopenharmony_ci
1728bf215546Sopenharmony_cistatic inline bool si_is_atom_dirty(struct si_context *sctx, struct si_atom *atom)
1729bf215546Sopenharmony_ci{
1730bf215546Sopenharmony_ci   return (sctx->dirty_atoms & si_get_atom_bit(sctx, atom)) != 0;
1731bf215546Sopenharmony_ci}
1732bf215546Sopenharmony_ci
1733bf215546Sopenharmony_cistatic inline void si_mark_atom_dirty(struct si_context *sctx, struct si_atom *atom)
1734bf215546Sopenharmony_ci{
1735bf215546Sopenharmony_ci   si_set_atom_dirty(sctx, atom, true);
1736bf215546Sopenharmony_ci}
1737bf215546Sopenharmony_ci
1738bf215546Sopenharmony_ci/* This should be evaluated at compile time if all parameters except sctx are constants. */
1739bf215546Sopenharmony_cistatic ALWAYS_INLINE struct si_shader_ctx_state *
1740bf215546Sopenharmony_cisi_get_vs_inline(struct si_context *sctx, enum si_has_tess has_tess, enum si_has_gs has_gs)
1741bf215546Sopenharmony_ci{
1742bf215546Sopenharmony_ci   if (has_gs)
1743bf215546Sopenharmony_ci      return &sctx->shader.gs;
1744bf215546Sopenharmony_ci   if (has_tess)
1745bf215546Sopenharmony_ci      return &sctx->shader.tes;
1746bf215546Sopenharmony_ci
1747bf215546Sopenharmony_ci   return &sctx->shader.vs;
1748bf215546Sopenharmony_ci}
1749bf215546Sopenharmony_ci
1750bf215546Sopenharmony_cistatic inline struct si_shader_ctx_state *si_get_vs(struct si_context *sctx)
1751bf215546Sopenharmony_ci{
1752bf215546Sopenharmony_ci   return si_get_vs_inline(sctx, sctx->shader.tes.cso ? TESS_ON : TESS_OFF,
1753bf215546Sopenharmony_ci                           sctx->shader.gs.cso ? GS_ON : GS_OFF);
1754bf215546Sopenharmony_ci}
1755bf215546Sopenharmony_ci
1756bf215546Sopenharmony_cistatic inline bool si_can_dump_shader(struct si_screen *sscreen, gl_shader_stage stage)
1757bf215546Sopenharmony_ci{
1758bf215546Sopenharmony_ci   return sscreen->debug_flags & (1 << stage);
1759bf215546Sopenharmony_ci}
1760bf215546Sopenharmony_ci
1761bf215546Sopenharmony_cistatic inline bool si_get_strmout_en(struct si_context *sctx)
1762bf215546Sopenharmony_ci{
1763bf215546Sopenharmony_ci   return sctx->streamout.streamout_enabled || sctx->streamout.prims_gen_query_enabled;
1764bf215546Sopenharmony_ci}
1765bf215546Sopenharmony_ci
1766bf215546Sopenharmony_cistatic inline unsigned si_optimal_tcc_alignment(struct si_context *sctx, unsigned upload_size)
1767bf215546Sopenharmony_ci{
1768bf215546Sopenharmony_ci   unsigned alignment, tcc_cache_line_size;
1769bf215546Sopenharmony_ci
1770bf215546Sopenharmony_ci   /* If the upload size is less than the cache line size (e.g. 16, 32),
1771bf215546Sopenharmony_ci    * the whole thing will fit into a cache line if we align it to its size.
1772bf215546Sopenharmony_ci    * The idea is that multiple small uploads can share a cache line.
1773bf215546Sopenharmony_ci    * If the upload size is greater, align it to the cache line size.
1774bf215546Sopenharmony_ci    */
1775bf215546Sopenharmony_ci   alignment = util_next_power_of_two(upload_size);
1776bf215546Sopenharmony_ci   tcc_cache_line_size = sctx->screen->info.tcc_cache_line_size;
1777bf215546Sopenharmony_ci   return MIN2(alignment, tcc_cache_line_size);
1778bf215546Sopenharmony_ci}
1779bf215546Sopenharmony_ci
1780bf215546Sopenharmony_cistatic inline void si_saved_cs_reference(struct si_saved_cs **dst, struct si_saved_cs *src)
1781bf215546Sopenharmony_ci{
1782bf215546Sopenharmony_ci   if (pipe_reference(&(*dst)->reference, &src->reference))
1783bf215546Sopenharmony_ci      si_destroy_saved_cs(*dst);
1784bf215546Sopenharmony_ci
1785bf215546Sopenharmony_ci   *dst = src;
1786bf215546Sopenharmony_ci}
1787bf215546Sopenharmony_ci
1788bf215546Sopenharmony_cistatic inline void si_make_CB_shader_coherent(struct si_context *sctx, unsigned num_samples,
1789bf215546Sopenharmony_ci                                              bool shaders_read_metadata, bool dcc_pipe_aligned)
1790bf215546Sopenharmony_ci{
1791bf215546Sopenharmony_ci   sctx->flags |= SI_CONTEXT_FLUSH_AND_INV_CB | SI_CONTEXT_INV_VCACHE;
1792bf215546Sopenharmony_ci   sctx->force_cb_shader_coherent = false;
1793bf215546Sopenharmony_ci
1794bf215546Sopenharmony_ci   if (sctx->gfx_level >= GFX10) {
1795bf215546Sopenharmony_ci      if (sctx->screen->info.tcc_rb_non_coherent)
1796bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2;
1797bf215546Sopenharmony_ci      else if (shaders_read_metadata)
1798bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2_METADATA;
1799bf215546Sopenharmony_ci   } else if (sctx->gfx_level == GFX9) {
1800bf215546Sopenharmony_ci      /* Single-sample color is coherent with shaders on GFX9, but
1801bf215546Sopenharmony_ci       * L2 metadata must be flushed if shaders read metadata.
1802bf215546Sopenharmony_ci       * (DCC, CMASK).
1803bf215546Sopenharmony_ci       */
1804bf215546Sopenharmony_ci      if (num_samples >= 2 || (shaders_read_metadata && !dcc_pipe_aligned))
1805bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2;
1806bf215546Sopenharmony_ci      else if (shaders_read_metadata)
1807bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2_METADATA;
1808bf215546Sopenharmony_ci   } else {
1809bf215546Sopenharmony_ci      /* GFX6-GFX8 */
1810bf215546Sopenharmony_ci      sctx->flags |= SI_CONTEXT_INV_L2;
1811bf215546Sopenharmony_ci   }
1812bf215546Sopenharmony_ci}
1813bf215546Sopenharmony_ci
1814bf215546Sopenharmony_cistatic inline void si_make_DB_shader_coherent(struct si_context *sctx, unsigned num_samples,
1815bf215546Sopenharmony_ci                                              bool include_stencil, bool shaders_read_metadata)
1816bf215546Sopenharmony_ci{
1817bf215546Sopenharmony_ci   sctx->flags |= SI_CONTEXT_FLUSH_AND_INV_DB | SI_CONTEXT_INV_VCACHE;
1818bf215546Sopenharmony_ci
1819bf215546Sopenharmony_ci   if (sctx->gfx_level >= GFX10) {
1820bf215546Sopenharmony_ci      if (sctx->screen->info.tcc_rb_non_coherent)
1821bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2;
1822bf215546Sopenharmony_ci      else if (shaders_read_metadata)
1823bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2_METADATA;
1824bf215546Sopenharmony_ci   } else if (sctx->gfx_level == GFX9) {
1825bf215546Sopenharmony_ci      /* Single-sample depth (not stencil) is coherent with shaders
1826bf215546Sopenharmony_ci       * on GFX9, but L2 metadata must be flushed if shaders read
1827bf215546Sopenharmony_ci       * metadata.
1828bf215546Sopenharmony_ci       */
1829bf215546Sopenharmony_ci      if (num_samples >= 2 || include_stencil)
1830bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2;
1831bf215546Sopenharmony_ci      else if (shaders_read_metadata)
1832bf215546Sopenharmony_ci         sctx->flags |= SI_CONTEXT_INV_L2_METADATA;
1833bf215546Sopenharmony_ci   } else {
1834bf215546Sopenharmony_ci      /* GFX6-GFX8 */
1835bf215546Sopenharmony_ci      sctx->flags |= SI_CONTEXT_INV_L2;
1836bf215546Sopenharmony_ci   }
1837bf215546Sopenharmony_ci}
1838bf215546Sopenharmony_ci
1839bf215546Sopenharmony_cistatic inline bool si_can_sample_zs(struct si_texture *tex, bool stencil_sampler)
1840bf215546Sopenharmony_ci{
1841bf215546Sopenharmony_ci   return (stencil_sampler && tex->can_sample_s) || (!stencil_sampler && tex->can_sample_z);
1842bf215546Sopenharmony_ci}
1843bf215546Sopenharmony_ci
1844bf215546Sopenharmony_cistatic inline bool si_htile_enabled(struct si_texture *tex, unsigned level, unsigned zs_mask)
1845bf215546Sopenharmony_ci{
1846bf215546Sopenharmony_ci   if (zs_mask == PIPE_MASK_S && (tex->htile_stencil_disabled || !tex->surface.has_stencil))
1847bf215546Sopenharmony_ci      return false;
1848bf215546Sopenharmony_ci
1849bf215546Sopenharmony_ci   if (!tex->is_depth || !tex->surface.meta_offset)
1850bf215546Sopenharmony_ci      return false;
1851bf215546Sopenharmony_ci
1852bf215546Sopenharmony_ci   struct si_screen *sscreen = (struct si_screen *)tex->buffer.b.b.screen;
1853bf215546Sopenharmony_ci   if (sscreen->info.gfx_level >= GFX8) {
1854bf215546Sopenharmony_ci      return level < tex->surface.num_meta_levels;
1855bf215546Sopenharmony_ci   } else {
1856bf215546Sopenharmony_ci      /* GFX6-7 don't have TC-compatible HTILE, which means they have to run
1857bf215546Sopenharmony_ci       * a decompression pass for every mipmap level before texturing, so compress
1858bf215546Sopenharmony_ci       * only one level to reduce the number of decompression passes to a minimum.
1859bf215546Sopenharmony_ci       */
1860bf215546Sopenharmony_ci      return level == 0;
1861bf215546Sopenharmony_ci   }
1862bf215546Sopenharmony_ci}
1863bf215546Sopenharmony_ci
1864bf215546Sopenharmony_cistatic inline bool vi_tc_compat_htile_enabled(struct si_texture *tex, unsigned level,
1865bf215546Sopenharmony_ci                                              unsigned zs_mask)
1866bf215546Sopenharmony_ci{
1867bf215546Sopenharmony_ci   assert(!tex->tc_compatible_htile || tex->surface.meta_offset);
1868bf215546Sopenharmony_ci   return tex->tc_compatible_htile && si_htile_enabled(tex, level, zs_mask);
1869bf215546Sopenharmony_ci}
1870bf215546Sopenharmony_ci
1871bf215546Sopenharmony_cistatic inline unsigned si_get_ps_iter_samples(struct si_context *sctx)
1872bf215546Sopenharmony_ci{
1873bf215546Sopenharmony_ci   if (sctx->ps_uses_fbfetch)
1874bf215546Sopenharmony_ci      return sctx->framebuffer.nr_color_samples;
1875bf215546Sopenharmony_ci
1876bf215546Sopenharmony_ci   return MIN2(sctx->ps_iter_samples, sctx->framebuffer.nr_color_samples);
1877bf215546Sopenharmony_ci}
1878bf215546Sopenharmony_ci
1879bf215546Sopenharmony_cistatic inline unsigned si_get_total_colormask(struct si_context *sctx)
1880bf215546Sopenharmony_ci{
1881bf215546Sopenharmony_ci   if (sctx->queued.named.rasterizer->rasterizer_discard)
1882bf215546Sopenharmony_ci      return 0;
1883bf215546Sopenharmony_ci
1884bf215546Sopenharmony_ci   struct si_shader_selector *ps = sctx->shader.ps.cso;
1885bf215546Sopenharmony_ci   if (!ps)
1886bf215546Sopenharmony_ci      return 0;
1887bf215546Sopenharmony_ci
1888bf215546Sopenharmony_ci   unsigned colormask =
1889bf215546Sopenharmony_ci      sctx->framebuffer.colorbuf_enabled_4bit & sctx->queued.named.blend->cb_target_mask;
1890bf215546Sopenharmony_ci
1891bf215546Sopenharmony_ci   if (!ps->info.color0_writes_all_cbufs)
1892bf215546Sopenharmony_ci      colormask &= ps->info.colors_written_4bit;
1893bf215546Sopenharmony_ci   else if (!ps->info.colors_written_4bit)
1894bf215546Sopenharmony_ci      colormask = 0; /* color0 writes all cbufs, but it's not written */
1895bf215546Sopenharmony_ci
1896bf215546Sopenharmony_ci   return colormask;
1897bf215546Sopenharmony_ci}
1898bf215546Sopenharmony_ci
1899bf215546Sopenharmony_ci#define UTIL_ALL_PRIM_LINE_MODES                                                                   \
1900bf215546Sopenharmony_ci   ((1 << PIPE_PRIM_LINES) | (1 << PIPE_PRIM_LINE_LOOP) | (1 << PIPE_PRIM_LINE_STRIP) |            \
1901bf215546Sopenharmony_ci    (1 << PIPE_PRIM_LINES_ADJACENCY) | (1 << PIPE_PRIM_LINE_STRIP_ADJACENCY))
1902bf215546Sopenharmony_ci
1903bf215546Sopenharmony_ci#define UTIL_ALL_PRIM_TRIANGLE_MODES \
1904bf215546Sopenharmony_ci   ((1 << PIPE_PRIM_TRIANGLES) | (1 << PIPE_PRIM_TRIANGLE_STRIP) | \
1905bf215546Sopenharmony_ci    (1 << PIPE_PRIM_TRIANGLE_FAN) | (1 << PIPE_PRIM_QUADS) | (1 << PIPE_PRIM_QUAD_STRIP) | \
1906bf215546Sopenharmony_ci    (1 << PIPE_PRIM_POLYGON) | (1 << PIPE_PRIM_TRIANGLES_ADJACENCY) | \
1907bf215546Sopenharmony_ci    (1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY))
1908bf215546Sopenharmony_ci
1909bf215546Sopenharmony_cistatic inline bool util_prim_is_lines(unsigned prim)
1910bf215546Sopenharmony_ci{
1911bf215546Sopenharmony_ci   return ((1 << prim) & UTIL_ALL_PRIM_LINE_MODES) != 0;
1912bf215546Sopenharmony_ci}
1913bf215546Sopenharmony_ci
1914bf215546Sopenharmony_cistatic inline bool util_prim_is_points_or_lines(unsigned prim)
1915bf215546Sopenharmony_ci{
1916bf215546Sopenharmony_ci   return ((1 << prim) & (UTIL_ALL_PRIM_LINE_MODES | (1 << PIPE_PRIM_POINTS))) != 0;
1917bf215546Sopenharmony_ci}
1918bf215546Sopenharmony_ci
1919bf215546Sopenharmony_cistatic inline bool util_rast_prim_is_triangles(unsigned prim)
1920bf215546Sopenharmony_ci{
1921bf215546Sopenharmony_ci   return ((1 << prim) & UTIL_ALL_PRIM_TRIANGLE_MODES) != 0;
1922bf215546Sopenharmony_ci}
1923bf215546Sopenharmony_ci
1924bf215546Sopenharmony_cistatic inline bool util_rast_prim_is_lines_or_triangles(unsigned prim)
1925bf215546Sopenharmony_ci{
1926bf215546Sopenharmony_ci   return ((1 << prim) & (UTIL_ALL_PRIM_LINE_MODES | UTIL_ALL_PRIM_TRIANGLE_MODES)) != 0;
1927bf215546Sopenharmony_ci}
1928bf215546Sopenharmony_ci
1929bf215546Sopenharmony_ci/**
1930bf215546Sopenharmony_ci * Return true if there is enough memory in VRAM and GTT for the buffers
1931bf215546Sopenharmony_ci * added so far.
1932bf215546Sopenharmony_ci *
1933bf215546Sopenharmony_ci * \param vram      VRAM memory size not added to the buffer list yet
1934bf215546Sopenharmony_ci * \param gtt       GTT memory size not added to the buffer list yet
1935bf215546Sopenharmony_ci */
1936bf215546Sopenharmony_cistatic inline bool radeon_cs_memory_below_limit(struct si_screen *screen, struct radeon_cmdbuf *cs,
1937bf215546Sopenharmony_ci                                                uint32_t kb)
1938bf215546Sopenharmony_ci{
1939bf215546Sopenharmony_ci   return kb + cs->used_vram_kb + cs->used_gart_kb < screen->max_memory_usage_kb;
1940bf215546Sopenharmony_ci}
1941bf215546Sopenharmony_ci
1942bf215546Sopenharmony_cistatic inline void si_need_gfx_cs_space(struct si_context *ctx, unsigned num_draws)
1943bf215546Sopenharmony_ci{
1944bf215546Sopenharmony_ci   struct radeon_cmdbuf *cs = &ctx->gfx_cs;
1945bf215546Sopenharmony_ci
1946bf215546Sopenharmony_ci   /* There are two memory usage counters in the winsys for all buffers
1947bf215546Sopenharmony_ci    * that have been added (cs_add_buffer) and one counter in the pipe
1948bf215546Sopenharmony_ci    * driver for those that haven't been added yet.
1949bf215546Sopenharmony_ci    */
1950bf215546Sopenharmony_ci   uint32_t kb = ctx->memory_usage_kb;
1951bf215546Sopenharmony_ci   ctx->memory_usage_kb = 0;
1952bf215546Sopenharmony_ci
1953bf215546Sopenharmony_ci   if (radeon_cs_memory_below_limit(ctx->screen, &ctx->gfx_cs, kb) &&
1954bf215546Sopenharmony_ci       ctx->ws->cs_check_space(cs, si_get_minimum_num_gfx_cs_dwords(ctx, num_draws)))
1955bf215546Sopenharmony_ci      return;
1956bf215546Sopenharmony_ci
1957bf215546Sopenharmony_ci   si_flush_gfx_cs(ctx, RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW, NULL);
1958bf215546Sopenharmony_ci}
1959bf215546Sopenharmony_ci
1960bf215546Sopenharmony_ci/**
1961bf215546Sopenharmony_ci * Add a buffer to the buffer list for the given command stream (CS).
1962bf215546Sopenharmony_ci *
1963bf215546Sopenharmony_ci * All buffers used by a CS must be added to the list. This tells the kernel
1964bf215546Sopenharmony_ci * driver which buffers are used by GPU commands. Other buffers can
1965bf215546Sopenharmony_ci * be swapped out (not accessible) during execution.
1966bf215546Sopenharmony_ci *
1967bf215546Sopenharmony_ci * The buffer list becomes empty after every context flush and must be
1968bf215546Sopenharmony_ci * rebuilt.
1969bf215546Sopenharmony_ci */
1970bf215546Sopenharmony_cistatic inline void radeon_add_to_buffer_list(struct si_context *sctx, struct radeon_cmdbuf *cs,
1971bf215546Sopenharmony_ci                                             struct si_resource *bo, unsigned usage)
1972bf215546Sopenharmony_ci{
1973bf215546Sopenharmony_ci   assert(usage);
1974bf215546Sopenharmony_ci   sctx->ws->cs_add_buffer(cs, bo->buf, usage | RADEON_USAGE_SYNCHRONIZED,
1975bf215546Sopenharmony_ci                           bo->domains);
1976bf215546Sopenharmony_ci}
1977bf215546Sopenharmony_ci
1978bf215546Sopenharmony_ci/**
1979bf215546Sopenharmony_ci * Same as above, but also checks memory usage and flushes the context
1980bf215546Sopenharmony_ci * accordingly.
1981bf215546Sopenharmony_ci *
1982bf215546Sopenharmony_ci * When this SHOULD NOT be used:
1983bf215546Sopenharmony_ci *
1984bf215546Sopenharmony_ci * - if si_context_add_resource_size has been called for the buffer
1985bf215546Sopenharmony_ci *   followed by *_need_cs_space for checking the memory usage
1986bf215546Sopenharmony_ci *
1987bf215546Sopenharmony_ci * - when emitting state packets and draw packets (because preceding packets
1988bf215546Sopenharmony_ci *   can't be re-emitted at that point)
1989bf215546Sopenharmony_ci *
1990bf215546Sopenharmony_ci * - if shader resource "enabled_mask" is not up-to-date or there is
1991bf215546Sopenharmony_ci *   a different constraint disallowing a context flush
1992bf215546Sopenharmony_ci */
1993bf215546Sopenharmony_cistatic inline void radeon_add_to_gfx_buffer_list_check_mem(struct si_context *sctx,
1994bf215546Sopenharmony_ci                                                           struct si_resource *bo,
1995bf215546Sopenharmony_ci                                                           unsigned usage,
1996bf215546Sopenharmony_ci                                                           bool check_mem)
1997bf215546Sopenharmony_ci{
1998bf215546Sopenharmony_ci   if (check_mem &&
1999bf215546Sopenharmony_ci       !radeon_cs_memory_below_limit(sctx->screen, &sctx->gfx_cs, sctx->memory_usage_kb + bo->memory_usage_kb))
2000bf215546Sopenharmony_ci      si_flush_gfx_cs(sctx, RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW, NULL);
2001bf215546Sopenharmony_ci
2002bf215546Sopenharmony_ci   radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, bo, usage);
2003bf215546Sopenharmony_ci}
2004bf215546Sopenharmony_ci
2005bf215546Sopenharmony_cistatic inline void si_select_draw_vbo(struct si_context *sctx)
2006bf215546Sopenharmony_ci{
2007bf215546Sopenharmony_ci   pipe_draw_vbo_func draw_vbo = sctx->draw_vbo[!!sctx->shader.tes.cso]
2008bf215546Sopenharmony_ci                                               [!!sctx->shader.gs.cso]
2009bf215546Sopenharmony_ci                                               [sctx->ngg];
2010bf215546Sopenharmony_ci   pipe_draw_vertex_state_func draw_vertex_state =
2011bf215546Sopenharmony_ci      sctx->draw_vertex_state[!!sctx->shader.tes.cso]
2012bf215546Sopenharmony_ci                             [!!sctx->shader.gs.cso]
2013bf215546Sopenharmony_ci                             [sctx->ngg];
2014bf215546Sopenharmony_ci   assert(draw_vbo);
2015bf215546Sopenharmony_ci   assert(draw_vertex_state);
2016bf215546Sopenharmony_ci
2017bf215546Sopenharmony_ci   if (unlikely(sctx->real_draw_vbo)) {
2018bf215546Sopenharmony_ci      assert(sctx->real_draw_vertex_state);
2019bf215546Sopenharmony_ci      sctx->real_draw_vbo = draw_vbo;
2020bf215546Sopenharmony_ci      sctx->real_draw_vertex_state = draw_vertex_state;
2021bf215546Sopenharmony_ci   } else {
2022bf215546Sopenharmony_ci      assert(!sctx->real_draw_vertex_state);
2023bf215546Sopenharmony_ci      sctx->b.draw_vbo = draw_vbo;
2024bf215546Sopenharmony_ci      sctx->b.draw_vertex_state = draw_vertex_state;
2025bf215546Sopenharmony_ci   }
2026bf215546Sopenharmony_ci}
2027bf215546Sopenharmony_ci
2028bf215546Sopenharmony_ci/* Return the number of samples that the rasterizer uses. */
2029bf215546Sopenharmony_cistatic inline unsigned si_get_num_coverage_samples(struct si_context *sctx)
2030bf215546Sopenharmony_ci{
2031bf215546Sopenharmony_ci   if (sctx->framebuffer.nr_samples > 1 &&
2032bf215546Sopenharmony_ci       sctx->queued.named.rasterizer->multisample_enable)
2033bf215546Sopenharmony_ci      return sctx->framebuffer.nr_samples;
2034bf215546Sopenharmony_ci
2035bf215546Sopenharmony_ci   /* Note that smoothing_enabled is set by si_update_shaders. */
2036bf215546Sopenharmony_ci   if (sctx->smoothing_enabled)
2037bf215546Sopenharmony_ci      return SI_NUM_SMOOTH_AA_SAMPLES;
2038bf215546Sopenharmony_ci
2039bf215546Sopenharmony_ci   return 1;
2040bf215546Sopenharmony_ci}
2041bf215546Sopenharmony_ci
2042bf215546Sopenharmony_cistatic unsigned ALWAYS_INLINE
2043bf215546Sopenharmony_cisi_num_vbos_in_user_sgprs_inline(enum amd_gfx_level gfx_level)
2044bf215546Sopenharmony_ci{
2045bf215546Sopenharmony_ci   /* This decreases CPU overhead if all descriptors are in user SGPRs because we don't
2046bf215546Sopenharmony_ci    * have to allocate and count references for the upload buffer.
2047bf215546Sopenharmony_ci    */
2048bf215546Sopenharmony_ci   return gfx_level >= GFX9 ? 5 : 1;
2049bf215546Sopenharmony_ci}
2050bf215546Sopenharmony_ci
2051bf215546Sopenharmony_cistatic inline unsigned si_num_vbos_in_user_sgprs(struct si_screen *sscreen)
2052bf215546Sopenharmony_ci{
2053bf215546Sopenharmony_ci   return si_num_vbos_in_user_sgprs_inline(sscreen->info.gfx_level);
2054bf215546Sopenharmony_ci}
2055bf215546Sopenharmony_ci
2056bf215546Sopenharmony_cistatic inline
2057bf215546Sopenharmony_civoid si_check_dirty_buffers_textures(struct si_context *sctx)
2058bf215546Sopenharmony_ci{
2059bf215546Sopenharmony_ci   /* Recompute and re-emit the texture resource states if needed. */
2060bf215546Sopenharmony_ci   unsigned dirty_tex_counter = p_atomic_read(&sctx->screen->dirty_tex_counter);
2061bf215546Sopenharmony_ci   if (unlikely(dirty_tex_counter != sctx->last_dirty_tex_counter)) {
2062bf215546Sopenharmony_ci      sctx->last_dirty_tex_counter = dirty_tex_counter;
2063bf215546Sopenharmony_ci      sctx->framebuffer.dirty_cbufs |= ((1 << sctx->framebuffer.state.nr_cbufs) - 1);
2064bf215546Sopenharmony_ci      sctx->framebuffer.dirty_zsbuf = true;
2065bf215546Sopenharmony_ci      si_mark_atom_dirty(sctx, &sctx->atoms.s.framebuffer);
2066bf215546Sopenharmony_ci      si_update_all_texture_descriptors(sctx);
2067bf215546Sopenharmony_ci   }
2068bf215546Sopenharmony_ci
2069bf215546Sopenharmony_ci   unsigned dirty_buf_counter = p_atomic_read(&sctx->screen->dirty_buf_counter);
2070bf215546Sopenharmony_ci   if (unlikely(dirty_buf_counter != sctx->last_dirty_buf_counter)) {
2071bf215546Sopenharmony_ci      sctx->last_dirty_buf_counter = dirty_buf_counter;
2072bf215546Sopenharmony_ci      /* Rebind all buffers unconditionally. */
2073bf215546Sopenharmony_ci      si_rebind_buffer(sctx, NULL);
2074bf215546Sopenharmony_ci   }
2075bf215546Sopenharmony_ci}
2076bf215546Sopenharmony_ci
2077bf215546Sopenharmony_ci
2078bf215546Sopenharmony_ci#define PRINT_ERR(fmt, args...)                                                                    \
2079bf215546Sopenharmony_ci   fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)
2080bf215546Sopenharmony_ci
2081bf215546Sopenharmony_ci#ifdef __cplusplus
2082bf215546Sopenharmony_ci}
2083bf215546Sopenharmony_ci#endif
2084bf215546Sopenharmony_ci
2085bf215546Sopenharmony_ci#endif
2086