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