Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/amd/vulkan/radv_private.h
7206 views
1
/*
2
* Copyright © 2016 Red Hat.
3
* Copyright © 2016 Bas Nieuwenhuizen
4
*
5
* based in part on anv driver which is:
6
* Copyright © 2015 Intel Corporation
7
*
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
14
*
15
* The above copyright notice and this permission notice (including the next
16
* paragraph) shall be included in all copies or substantial portions of the
17
* Software.
18
*
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
* IN THE SOFTWARE.
26
*/
27
28
#ifndef RADV_PRIVATE_H
29
#define RADV_PRIVATE_H
30
31
#include <assert.h>
32
#include <stdbool.h>
33
#include <stdint.h>
34
#include <stdio.h>
35
#include <stdlib.h>
36
#include <string.h>
37
#ifdef HAVE_VALGRIND
38
#include <memcheck.h>
39
#include <valgrind.h>
40
#define VG(x) x
41
#else
42
#define VG(x) ((void)0)
43
#endif
44
45
#include "c11/threads.h"
46
#ifndef _WIN32
47
#include <amdgpu.h>
48
#include <xf86drm.h>
49
#endif
50
#include "compiler/shader_enums.h"
51
#include "util/bitscan.h"
52
#include "util/cnd_monotonic.h"
53
#include "util/list.h"
54
#include "util/macros.h"
55
#include "util/rwlock.h"
56
#include "util/xmlconfig.h"
57
#include "vk_alloc.h"
58
#include "vk_debug_report.h"
59
#include "vk_device.h"
60
#include "vk_format.h"
61
#include "vk_instance.h"
62
#include "vk_physical_device.h"
63
#include "vk_shader_module.h"
64
#include "vk_util.h"
65
66
#include "ac_binary.h"
67
#include "ac_gpu_info.h"
68
#include "ac_shader_util.h"
69
#include "ac_sqtt.h"
70
#include "ac_surface.h"
71
#include "radv_constants.h"
72
#include "radv_descriptor_set.h"
73
#include "radv_radeon_winsys.h"
74
#include "sid.h"
75
76
/* Pre-declarations needed for WSI entrypoints */
77
struct wl_surface;
78
struct wl_display;
79
typedef struct xcb_connection_t xcb_connection_t;
80
typedef uint32_t xcb_visualid_t;
81
typedef uint32_t xcb_window_t;
82
83
#include <vulkan/vk_android_native_buffer.h>
84
#include <vulkan/vk_icd.h>
85
#include <vulkan/vulkan.h>
86
#include <vulkan/vulkan_android.h>
87
88
#include "radv_entrypoints.h"
89
90
#include "wsi_common.h"
91
92
/* Helper to determine if we should compile
93
* any of the Android AHB support.
94
*
95
* To actually enable the ext we also need
96
* the necessary kernel support.
97
*/
98
#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
99
#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 1
100
#include <vndk/hardware_buffer.h>
101
#else
102
#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 0
103
#endif
104
105
#ifdef _WIN32
106
#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 0
107
#else
108
#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 1
109
#endif
110
111
#ifdef _WIN32
112
#define radv_printflike(a, b)
113
#else
114
#define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
115
#endif
116
117
static inline uint32_t
118
align_u32(uint32_t v, uint32_t a)
119
{
120
assert(a != 0 && a == (a & -a));
121
return (v + a - 1) & ~(a - 1);
122
}
123
124
static inline uint32_t
125
align_u32_npot(uint32_t v, uint32_t a)
126
{
127
return (v + a - 1) / a * a;
128
}
129
130
static inline uint64_t
131
align_u64(uint64_t v, uint64_t a)
132
{
133
assert(a != 0 && a == (a & -a));
134
return (v + a - 1) & ~(a - 1);
135
}
136
137
static inline int32_t
138
align_i32(int32_t v, int32_t a)
139
{
140
assert(a != 0 && a == (a & -a));
141
return (v + a - 1) & ~(a - 1);
142
}
143
144
/** Alignment must be a power of 2. */
145
static inline bool
146
radv_is_aligned(uintmax_t n, uintmax_t a)
147
{
148
assert(a == (a & -a));
149
return (n & (a - 1)) == 0;
150
}
151
152
static inline uint32_t
153
round_up_u32(uint32_t v, uint32_t a)
154
{
155
return (v + a - 1) / a;
156
}
157
158
static inline uint64_t
159
round_up_u64(uint64_t v, uint64_t a)
160
{
161
return (v + a - 1) / a;
162
}
163
164
static inline uint32_t
165
radv_minify(uint32_t n, uint32_t levels)
166
{
167
if (unlikely(n == 0))
168
return 0;
169
else
170
return MAX2(n >> levels, 1);
171
}
172
static inline float
173
radv_clamp_f(float f, float min, float max)
174
{
175
assert(min < max);
176
177
if (f > max)
178
return max;
179
else if (f < min)
180
return min;
181
else
182
return f;
183
}
184
185
static inline bool
186
radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
187
{
188
if (*inout_mask & clear_mask) {
189
*inout_mask &= ~clear_mask;
190
return true;
191
} else {
192
return false;
193
}
194
}
195
196
/* Whenever we generate an error, pass it through this function. Useful for
197
* debugging, where we can break on it. Only call at error site, not when
198
* propagating errors. Might be useful to plug in a stack trace here.
199
*/
200
201
struct radv_image_view;
202
struct radv_instance;
203
204
VkResult __vk_errorv(struct radv_instance *instance, const void *object,
205
VkDebugReportObjectTypeEXT type, VkResult error, const char *file, int line,
206
const char *format, va_list args);
207
208
VkResult __vk_errorf(struct radv_instance *instance, const void *object,
209
VkDebugReportObjectTypeEXT type, VkResult error, const char *file, int line,
210
const char *format, ...) radv_printflike(7, 8);
211
212
#define vk_error(instance, error) \
213
__vk_errorf(instance, NULL, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, error, __FILE__, __LINE__, \
214
NULL);
215
#define vk_errorf(instance, error, format, ...) \
216
__vk_errorf(instance, NULL, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, error, __FILE__, __LINE__, \
217
format, ##__VA_ARGS__);
218
219
void __radv_finishme(const char *file, int line, const char *format, ...) radv_printflike(3, 4);
220
void radv_loge(const char *format, ...) radv_printflike(1, 2);
221
void radv_loge_v(const char *format, va_list va);
222
void radv_logi(const char *format, ...) radv_printflike(1, 2);
223
void radv_logi_v(const char *format, va_list va);
224
225
/**
226
* Print a FINISHME message, including its source location.
227
*/
228
#define radv_finishme(format, ...) \
229
do { \
230
static bool reported = false; \
231
if (!reported) { \
232
__radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
233
reported = true; \
234
} \
235
} while (0)
236
237
/* A non-fatal assert. Useful for debugging. */
238
#ifdef NDEBUG
239
#define radv_assert(x) \
240
do { \
241
} while (0)
242
#else
243
#define radv_assert(x) \
244
do { \
245
if (unlikely(!(x))) \
246
fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
247
} while (0)
248
#endif
249
250
int radv_get_instance_entrypoint_index(const char *name);
251
int radv_get_device_entrypoint_index(const char *name);
252
int radv_get_physical_device_entrypoint_index(const char *name);
253
254
const char *radv_get_instance_entry_name(int index);
255
const char *radv_get_physical_device_entry_name(int index);
256
const char *radv_get_device_entry_name(int index);
257
258
struct radv_physical_device {
259
struct vk_physical_device vk;
260
261
/* Link in radv_instance::physical_devices */
262
struct list_head link;
263
264
struct radv_instance *instance;
265
266
struct radeon_winsys *ws;
267
struct radeon_info rad_info;
268
char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
269
uint8_t driver_uuid[VK_UUID_SIZE];
270
uint8_t device_uuid[VK_UUID_SIZE];
271
uint8_t cache_uuid[VK_UUID_SIZE];
272
273
int local_fd;
274
int master_fd;
275
struct wsi_device wsi_device;
276
277
bool out_of_order_rast_allowed;
278
279
/* Whether DCC should be enabled for MSAA textures. */
280
bool dcc_msaa_allowed;
281
282
/* Whether to enable NGG. */
283
bool use_ngg;
284
285
/* Whether to enable NGG streamout. */
286
bool use_ngg_streamout;
287
288
/* Number of threads per wave. */
289
uint8_t ps_wave_size;
290
uint8_t cs_wave_size;
291
uint8_t ge_wave_size;
292
293
/* Whether to use the LLVM compiler backend */
294
bool use_llvm;
295
296
/* This is the drivers on-disk cache used as a fallback as opposed to
297
* the pipeline cache defined by apps.
298
*/
299
struct disk_cache *disk_cache;
300
301
VkPhysicalDeviceMemoryProperties memory_properties;
302
enum radeon_bo_domain memory_domains[VK_MAX_MEMORY_TYPES];
303
enum radeon_bo_flag memory_flags[VK_MAX_MEMORY_TYPES];
304
unsigned heaps;
305
306
#ifndef _WIN32
307
int available_nodes;
308
drmPciBusInfo bus_info;
309
310
dev_t primary_devid;
311
dev_t render_devid;
312
#endif
313
};
314
315
struct radv_instance {
316
struct vk_instance vk;
317
318
VkAllocationCallbacks alloc;
319
320
uint64_t debug_flags;
321
uint64_t perftest_flags;
322
323
bool physical_devices_enumerated;
324
struct list_head physical_devices;
325
326
struct driOptionCache dri_options;
327
struct driOptionCache available_dri_options;
328
329
/**
330
* Workarounds for game bugs.
331
*/
332
bool enable_mrt_output_nan_fixup;
333
bool disable_tc_compat_htile_in_general;
334
bool disable_shrink_image_store;
335
bool absolute_depth_bias;
336
bool report_apu_as_dgpu;
337
};
338
339
VkResult radv_init_wsi(struct radv_physical_device *physical_device);
340
void radv_finish_wsi(struct radv_physical_device *physical_device);
341
342
struct cache_entry;
343
344
struct radv_pipeline_cache {
345
struct vk_object_base base;
346
struct radv_device *device;
347
mtx_t mutex;
348
VkPipelineCacheCreateFlags flags;
349
350
uint32_t total_size;
351
uint32_t table_size;
352
uint32_t kernel_count;
353
struct cache_entry **hash_table;
354
bool modified;
355
356
VkAllocationCallbacks alloc;
357
};
358
359
struct radv_pipeline_key {
360
uint32_t instance_rate_inputs;
361
uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];
362
uint8_t vertex_attribute_formats[MAX_VERTEX_ATTRIBS];
363
uint32_t vertex_attribute_bindings[MAX_VERTEX_ATTRIBS];
364
uint32_t vertex_attribute_offsets[MAX_VERTEX_ATTRIBS];
365
uint32_t vertex_attribute_strides[MAX_VERTEX_ATTRIBS];
366
uint8_t vertex_binding_align[MAX_VBS];
367
enum ac_fetch_format vertex_alpha_adjust[MAX_VERTEX_ATTRIBS];
368
uint32_t vertex_post_shuffle;
369
unsigned tess_input_vertices;
370
uint32_t col_format;
371
uint32_t is_int8;
372
uint32_t is_int10;
373
uint8_t log2_ps_iter_samples;
374
uint8_t num_samples;
375
uint32_t has_multiview_view_index : 1;
376
uint32_t optimisations_disabled : 1;
377
uint32_t provoking_vtx_last : 1;
378
uint8_t topology;
379
380
/* Non-zero if a required subgroup size is specified via
381
* VK_EXT_subgroup_size_control.
382
*/
383
uint8_t compute_subgroup_size;
384
bool require_full_subgroups;
385
};
386
387
struct radv_shader_binary;
388
struct radv_shader_variant;
389
390
void radv_pipeline_cache_init(struct radv_pipeline_cache *cache, struct radv_device *device);
391
void radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
392
bool radv_pipeline_cache_load(struct radv_pipeline_cache *cache, const void *data, size_t size);
393
394
bool radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
395
struct radv_pipeline_cache *cache,
396
const unsigned char *sha1,
397
struct radv_shader_variant **variants,
398
bool *found_in_application_cache);
399
400
void radv_pipeline_cache_insert_shaders(struct radv_device *device,
401
struct radv_pipeline_cache *cache,
402
const unsigned char *sha1,
403
struct radv_shader_variant **variants,
404
struct radv_shader_binary *const *binaries);
405
406
enum radv_blit_ds_layout {
407
RADV_BLIT_DS_LAYOUT_TILE_ENABLE,
408
RADV_BLIT_DS_LAYOUT_TILE_DISABLE,
409
RADV_BLIT_DS_LAYOUT_COUNT,
410
};
411
412
static inline enum radv_blit_ds_layout
413
radv_meta_blit_ds_to_type(VkImageLayout layout)
414
{
415
return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE
416
: RADV_BLIT_DS_LAYOUT_TILE_ENABLE;
417
}
418
419
static inline VkImageLayout
420
radv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)
421
{
422
return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
423
: VK_IMAGE_LAYOUT_GENERAL;
424
}
425
426
enum radv_meta_dst_layout {
427
RADV_META_DST_LAYOUT_GENERAL,
428
RADV_META_DST_LAYOUT_OPTIMAL,
429
RADV_META_DST_LAYOUT_COUNT,
430
};
431
432
static inline enum radv_meta_dst_layout
433
radv_meta_dst_layout_from_layout(VkImageLayout layout)
434
{
435
return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL
436
: RADV_META_DST_LAYOUT_OPTIMAL;
437
}
438
439
static inline VkImageLayout
440
radv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)
441
{
442
return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
443
: VK_IMAGE_LAYOUT_GENERAL;
444
}
445
446
struct radv_meta_state {
447
VkAllocationCallbacks alloc;
448
449
struct radv_pipeline_cache cache;
450
451
/*
452
* For on-demand pipeline creation, makes sure that
453
* only one thread tries to build a pipeline at the same time.
454
*/
455
mtx_t mtx;
456
457
/**
458
* Use array element `i` for images with `2^i` samples.
459
*/
460
struct {
461
VkRenderPass render_pass[NUM_META_FS_KEYS];
462
VkPipeline color_pipelines[NUM_META_FS_KEYS];
463
464
VkRenderPass depthstencil_rp;
465
VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
466
VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
467
VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
468
469
VkPipeline depth_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
470
VkPipeline stencil_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
471
VkPipeline depthstencil_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
472
} clear[MAX_SAMPLES_LOG2];
473
474
VkPipelineLayout clear_color_p_layout;
475
VkPipelineLayout clear_depth_p_layout;
476
VkPipelineLayout clear_depth_unrestricted_p_layout;
477
478
/* Optimized compute fast HTILE clear for stencil or depth only. */
479
VkPipeline clear_htile_mask_pipeline;
480
VkPipelineLayout clear_htile_mask_p_layout;
481
VkDescriptorSetLayout clear_htile_mask_ds_layout;
482
483
/* Copy VRS into HTILE. */
484
VkPipeline copy_vrs_htile_pipeline;
485
VkPipelineLayout copy_vrs_htile_p_layout;
486
VkDescriptorSetLayout copy_vrs_htile_ds_layout;
487
488
struct {
489
VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
490
491
/** Pipeline that blits from a 1D image. */
492
VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
493
494
/** Pipeline that blits from a 2D image. */
495
VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
496
497
/** Pipeline that blits from a 3D image. */
498
VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
499
500
VkRenderPass depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
501
VkPipeline depth_only_1d_pipeline;
502
VkPipeline depth_only_2d_pipeline;
503
VkPipeline depth_only_3d_pipeline;
504
505
VkRenderPass stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
506
VkPipeline stencil_only_1d_pipeline;
507
VkPipeline stencil_only_2d_pipeline;
508
VkPipeline stencil_only_3d_pipeline;
509
VkPipelineLayout pipeline_layout;
510
VkDescriptorSetLayout ds_layout;
511
} blit;
512
513
struct {
514
VkPipelineLayout p_layouts[5];
515
VkDescriptorSetLayout ds_layouts[5];
516
VkPipeline pipelines[5][NUM_META_FS_KEYS];
517
518
VkPipeline depth_only_pipeline[5];
519
520
VkPipeline stencil_only_pipeline[5];
521
} blit2d[MAX_SAMPLES_LOG2];
522
523
VkRenderPass blit2d_render_passes[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
524
VkRenderPass blit2d_depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
525
VkRenderPass blit2d_stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
526
527
struct {
528
VkPipelineLayout img_p_layout;
529
VkDescriptorSetLayout img_ds_layout;
530
VkPipeline pipeline;
531
VkPipeline pipeline_3d;
532
} itob;
533
struct {
534
VkPipelineLayout img_p_layout;
535
VkDescriptorSetLayout img_ds_layout;
536
VkPipeline pipeline;
537
VkPipeline pipeline_3d;
538
} btoi;
539
struct {
540
VkPipelineLayout img_p_layout;
541
VkDescriptorSetLayout img_ds_layout;
542
VkPipeline pipeline;
543
} btoi_r32g32b32;
544
struct {
545
VkPipelineLayout img_p_layout;
546
VkDescriptorSetLayout img_ds_layout;
547
VkPipeline pipeline[MAX_SAMPLES_LOG2];
548
VkPipeline pipeline_3d;
549
} itoi;
550
struct {
551
VkPipelineLayout img_p_layout;
552
VkDescriptorSetLayout img_ds_layout;
553
VkPipeline pipeline;
554
} itoi_r32g32b32;
555
struct {
556
VkPipelineLayout img_p_layout;
557
VkDescriptorSetLayout img_ds_layout;
558
VkPipeline pipeline[MAX_SAMPLES_LOG2];
559
VkPipeline pipeline_3d;
560
} cleari;
561
struct {
562
VkPipelineLayout img_p_layout;
563
VkDescriptorSetLayout img_ds_layout;
564
VkPipeline pipeline;
565
} cleari_r32g32b32;
566
567
struct {
568
VkPipelineLayout p_layout;
569
VkPipeline pipeline[NUM_META_FS_KEYS];
570
VkRenderPass pass[NUM_META_FS_KEYS];
571
} resolve;
572
573
struct {
574
VkDescriptorSetLayout ds_layout;
575
VkPipelineLayout p_layout;
576
struct {
577
VkPipeline pipeline;
578
VkPipeline i_pipeline;
579
VkPipeline srgb_pipeline;
580
} rc[MAX_SAMPLES_LOG2];
581
582
VkPipeline depth_zero_pipeline;
583
struct {
584
VkPipeline average_pipeline;
585
VkPipeline max_pipeline;
586
VkPipeline min_pipeline;
587
} depth[MAX_SAMPLES_LOG2];
588
589
VkPipeline stencil_zero_pipeline;
590
struct {
591
VkPipeline max_pipeline;
592
VkPipeline min_pipeline;
593
} stencil[MAX_SAMPLES_LOG2];
594
} resolve_compute;
595
596
struct {
597
VkDescriptorSetLayout ds_layout;
598
VkPipelineLayout p_layout;
599
600
struct {
601
VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
602
VkPipeline pipeline[NUM_META_FS_KEYS];
603
} rc[MAX_SAMPLES_LOG2];
604
605
VkRenderPass depth_render_pass;
606
VkPipeline depth_zero_pipeline;
607
struct {
608
VkPipeline average_pipeline;
609
VkPipeline max_pipeline;
610
VkPipeline min_pipeline;
611
} depth[MAX_SAMPLES_LOG2];
612
613
VkRenderPass stencil_render_pass;
614
VkPipeline stencil_zero_pipeline;
615
struct {
616
VkPipeline max_pipeline;
617
VkPipeline min_pipeline;
618
} stencil[MAX_SAMPLES_LOG2];
619
} resolve_fragment;
620
621
struct {
622
VkPipelineLayout p_layout;
623
VkPipeline decompress_pipeline;
624
VkPipeline resummarize_pipeline;
625
VkRenderPass pass;
626
} depth_decomp[MAX_SAMPLES_LOG2];
627
628
struct {
629
VkPipelineLayout p_layout;
630
VkPipeline cmask_eliminate_pipeline;
631
VkPipeline fmask_decompress_pipeline;
632
VkPipeline dcc_decompress_pipeline;
633
VkRenderPass pass;
634
635
VkDescriptorSetLayout dcc_decompress_compute_ds_layout;
636
VkPipelineLayout dcc_decompress_compute_p_layout;
637
VkPipeline dcc_decompress_compute_pipeline;
638
} fast_clear_flush;
639
640
struct {
641
VkPipelineLayout fill_p_layout;
642
VkPipelineLayout copy_p_layout;
643
VkDescriptorSetLayout fill_ds_layout;
644
VkDescriptorSetLayout copy_ds_layout;
645
VkPipeline fill_pipeline;
646
VkPipeline copy_pipeline;
647
} buffer;
648
649
struct {
650
VkDescriptorSetLayout ds_layout;
651
VkPipelineLayout p_layout;
652
VkPipeline occlusion_query_pipeline;
653
VkPipeline pipeline_statistics_query_pipeline;
654
VkPipeline tfb_query_pipeline;
655
VkPipeline timestamp_query_pipeline;
656
} query;
657
658
struct {
659
VkDescriptorSetLayout ds_layout;
660
VkPipelineLayout p_layout;
661
VkPipeline pipeline[MAX_SAMPLES_LOG2];
662
} fmask_expand;
663
664
struct {
665
VkDescriptorSetLayout ds_layout;
666
VkPipelineLayout p_layout;
667
VkPipeline pipeline;
668
} dcc_retile;
669
670
struct {
671
VkPipelineLayout leaf_p_layout;
672
VkPipeline leaf_pipeline;
673
VkPipelineLayout internal_p_layout;
674
VkPipeline internal_pipeline;
675
} accel_struct_build;
676
};
677
678
/* queue types */
679
#define RADV_QUEUE_GENERAL 0
680
#define RADV_QUEUE_COMPUTE 1
681
#define RADV_QUEUE_TRANSFER 2
682
683
/* Not a real queue family */
684
#define RADV_QUEUE_FOREIGN 3
685
686
#define RADV_MAX_QUEUE_FAMILIES 3
687
688
#define RADV_NUM_HW_CTX (RADEON_CTX_PRIORITY_REALTIME + 1)
689
690
struct radv_deferred_queue_submission;
691
692
enum ring_type radv_queue_family_to_ring(int f);
693
694
struct radv_queue {
695
struct vk_object_base base;
696
struct radv_device *device;
697
struct radeon_winsys_ctx *hw_ctx;
698
enum radeon_ctx_priority priority;
699
uint32_t queue_family_index;
700
int queue_idx;
701
VkDeviceQueueCreateFlags flags;
702
703
uint32_t scratch_size_per_wave;
704
uint32_t scratch_waves;
705
uint32_t compute_scratch_size_per_wave;
706
uint32_t compute_scratch_waves;
707
uint32_t esgs_ring_size;
708
uint32_t gsvs_ring_size;
709
bool has_tess_rings;
710
bool has_gds;
711
bool has_gds_oa;
712
bool has_sample_positions;
713
714
struct radeon_winsys_bo *scratch_bo;
715
struct radeon_winsys_bo *descriptor_bo;
716
struct radeon_winsys_bo *compute_scratch_bo;
717
struct radeon_winsys_bo *esgs_ring_bo;
718
struct radeon_winsys_bo *gsvs_ring_bo;
719
struct radeon_winsys_bo *tess_rings_bo;
720
struct radeon_winsys_bo *gds_bo;
721
struct radeon_winsys_bo *gds_oa_bo;
722
struct radeon_cmdbuf *initial_preamble_cs;
723
struct radeon_cmdbuf *initial_full_flush_preamble_cs;
724
struct radeon_cmdbuf *continue_preamble_cs;
725
726
struct list_head pending_submissions;
727
mtx_t pending_mutex;
728
729
mtx_t thread_mutex;
730
struct u_cnd_monotonic thread_cond;
731
struct radv_deferred_queue_submission *thread_submission;
732
thrd_t submission_thread;
733
bool thread_exit;
734
bool thread_running;
735
bool cond_created;
736
};
737
738
#define RADV_BORDER_COLOR_COUNT 4096
739
#define RADV_BORDER_COLOR_BUFFER_SIZE (sizeof(VkClearColorValue) * RADV_BORDER_COLOR_COUNT)
740
741
struct radv_device_border_color_data {
742
bool used[RADV_BORDER_COLOR_COUNT];
743
744
struct radeon_winsys_bo *bo;
745
VkClearColorValue *colors_gpu_ptr;
746
747
/* Mutex is required to guarantee vkCreateSampler thread safety
748
* given that we are writing to a buffer and checking color occupation */
749
mtx_t mutex;
750
};
751
752
enum radv_force_vrs {
753
RADV_FORCE_VRS_NONE = 0,
754
RADV_FORCE_VRS_2x2,
755
RADV_FORCE_VRS_2x1,
756
RADV_FORCE_VRS_1x2,
757
};
758
759
struct radv_device {
760
struct vk_device vk;
761
762
struct radv_instance *instance;
763
struct radeon_winsys *ws;
764
765
struct radeon_winsys_ctx *hw_ctx[RADV_NUM_HW_CTX];
766
struct radv_meta_state meta_state;
767
768
struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
769
int queue_count[RADV_MAX_QUEUE_FAMILIES];
770
struct radeon_cmdbuf *empty_cs[RADV_MAX_QUEUE_FAMILIES];
771
772
bool pbb_allowed;
773
uint32_t tess_offchip_block_dw_size;
774
uint32_t scratch_waves;
775
uint32_t dispatch_initiator;
776
777
uint32_t gs_table_depth;
778
779
/* MSAA sample locations.
780
* The first index is the sample index.
781
* The second index is the coordinate: X, Y. */
782
float sample_locations_1x[1][2];
783
float sample_locations_2x[2][2];
784
float sample_locations_4x[4][2];
785
float sample_locations_8x[8][2];
786
787
/* GFX7 and later */
788
uint32_t gfx_init_size_dw;
789
struct radeon_winsys_bo *gfx_init;
790
791
struct radeon_winsys_bo *trace_bo;
792
uint32_t *trace_id_ptr;
793
794
/* Whether to keep shader debug info, for tracing or VK_AMD_shader_info */
795
bool keep_shader_info;
796
797
struct radv_physical_device *physical_device;
798
799
/* Backup in-memory cache to be used if the app doesn't provide one */
800
struct radv_pipeline_cache *mem_cache;
801
802
/*
803
* use different counters so MSAA MRTs get consecutive surface indices,
804
* even if MASK is allocated in between.
805
*/
806
uint32_t image_mrt_offset_counter;
807
uint32_t fmask_mrt_offset_counter;
808
struct list_head shader_slabs;
809
mtx_t shader_slab_mutex;
810
811
/* For detecting VM faults reported by dmesg. */
812
uint64_t dmesg_timestamp;
813
814
/* Whether the app has enabled the robustBufferAccess/robustBufferAccess2 features. */
815
bool robust_buffer_access;
816
bool robust_buffer_access2;
817
818
/* Whether gl_FragCoord.z should be adjusted for VRS due to a hw bug
819
* on some GFX10.3 chips.
820
*/
821
bool adjust_frag_coord_z;
822
823
/* Whether the driver uses a global BO list. */
824
bool use_global_bo_list;
825
826
/* Whether attachment VRS is enabled. */
827
bool attachment_vrs_enabled;
828
829
/* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */
830
int force_aniso;
831
832
struct radv_device_border_color_data border_color_data;
833
834
/* Condition variable for legacy timelines, to notify waiters when a
835
* new point gets submitted. */
836
struct u_cnd_monotonic timeline_cond;
837
838
/* Thread trace. */
839
struct ac_thread_trace_data thread_trace;
840
841
/* Trap handler. */
842
struct radv_shader_variant *trap_handler_shader;
843
struct radeon_winsys_bo *tma_bo; /* Trap Memory Address */
844
uint32_t *tma_ptr;
845
846
/* Overallocation. */
847
bool overallocation_disallowed;
848
uint64_t allocated_memory_size[VK_MAX_MEMORY_HEAPS];
849
mtx_t overallocation_mutex;
850
851
/* Track the number of device loss occurs. */
852
int lost;
853
854
/* Whether the user forced VRS rates on GFX10.3+. */
855
enum radv_force_vrs force_vrs;
856
857
/* Depth image for VRS when not bound by the app. */
858
struct {
859
struct radv_image *image;
860
struct radv_device_memory *mem;
861
} vrs;
862
};
863
864
VkResult _radv_device_set_lost(struct radv_device *device, const char *file, int line,
865
const char *msg, ...) radv_printflike(4, 5);
866
867
#define radv_device_set_lost(dev, ...) _radv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)
868
869
static inline bool
870
radv_device_is_lost(const struct radv_device *device)
871
{
872
return unlikely(p_atomic_read(&device->lost));
873
}
874
875
struct radv_device_memory {
876
struct vk_object_base base;
877
struct radeon_winsys_bo *bo;
878
/* for dedicated allocations */
879
struct radv_image *image;
880
struct radv_buffer *buffer;
881
uint32_t heap_index;
882
uint64_t alloc_size;
883
void *map;
884
void *user_ptr;
885
886
#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
887
struct AHardwareBuffer *android_hardware_buffer;
888
#endif
889
};
890
891
struct radv_descriptor_range {
892
uint64_t va;
893
uint32_t size;
894
};
895
896
struct radv_descriptor_set_header {
897
struct vk_object_base base;
898
const struct radv_descriptor_set_layout *layout;
899
uint32_t size;
900
uint32_t buffer_count;
901
902
struct radeon_winsys_bo *bo;
903
uint64_t va;
904
uint32_t *mapped_ptr;
905
struct radv_descriptor_range *dynamic_descriptors;
906
};
907
908
struct radv_descriptor_set {
909
struct radv_descriptor_set_header header;
910
911
struct radeon_winsys_bo *descriptors[];
912
};
913
914
struct radv_push_descriptor_set {
915
struct radv_descriptor_set_header set;
916
uint32_t capacity;
917
};
918
919
struct radv_descriptor_pool_entry {
920
uint32_t offset;
921
uint32_t size;
922
struct radv_descriptor_set *set;
923
};
924
925
struct radv_descriptor_pool {
926
struct vk_object_base base;
927
struct radeon_winsys_bo *bo;
928
uint8_t *host_bo;
929
uint8_t *mapped_ptr;
930
uint64_t current_offset;
931
uint64_t size;
932
933
uint8_t *host_memory_base;
934
uint8_t *host_memory_ptr;
935
uint8_t *host_memory_end;
936
937
uint32_t entry_count;
938
uint32_t max_entry_count;
939
struct radv_descriptor_pool_entry entries[0];
940
};
941
942
struct radv_descriptor_update_template_entry {
943
VkDescriptorType descriptor_type;
944
945
/* The number of descriptors to update */
946
uint32_t descriptor_count;
947
948
/* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
949
uint32_t dst_offset;
950
951
/* In dwords. Not valid/used for dynamic descriptors */
952
uint32_t dst_stride;
953
954
uint32_t buffer_offset;
955
956
/* Only valid for combined image samplers and samplers */
957
uint8_t has_sampler;
958
uint8_t sampler_offset;
959
960
/* In bytes */
961
size_t src_offset;
962
size_t src_stride;
963
964
/* For push descriptors */
965
const uint32_t *immutable_samplers;
966
};
967
968
struct radv_descriptor_update_template {
969
struct vk_object_base base;
970
uint32_t entry_count;
971
VkPipelineBindPoint bind_point;
972
struct radv_descriptor_update_template_entry entry[0];
973
};
974
975
struct radv_buffer {
976
struct vk_object_base base;
977
VkDeviceSize size;
978
979
VkBufferUsageFlags usage;
980
VkBufferCreateFlags flags;
981
982
/* Set when bound */
983
struct radeon_winsys_bo *bo;
984
VkDeviceSize offset;
985
986
bool shareable;
987
};
988
989
enum radv_dynamic_state_bits {
990
RADV_DYNAMIC_VIEWPORT = 1ull << 0,
991
RADV_DYNAMIC_SCISSOR = 1ull << 1,
992
RADV_DYNAMIC_LINE_WIDTH = 1ull << 2,
993
RADV_DYNAMIC_DEPTH_BIAS = 1ull << 3,
994
RADV_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,
995
RADV_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,
996
RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,
997
RADV_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,
998
RADV_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,
999
RADV_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,
1000
RADV_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,
1001
RADV_DYNAMIC_LINE_STIPPLE = 1ull << 11,
1002
RADV_DYNAMIC_CULL_MODE = 1ull << 12,
1003
RADV_DYNAMIC_FRONT_FACE = 1ull << 13,
1004
RADV_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,
1005
RADV_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,
1006
RADV_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,
1007
RADV_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,
1008
RADV_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,
1009
RADV_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,
1010
RADV_DYNAMIC_STENCIL_OP = 1ull << 20,
1011
RADV_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,
1012
RADV_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,
1013
RADV_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,
1014
RADV_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,
1015
RADV_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,
1016
RADV_DYNAMIC_LOGIC_OP = 1ull << 26,
1017
RADV_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,
1018
RADV_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,
1019
RADV_DYNAMIC_ALL = (1ull << 29) - 1,
1020
};
1021
1022
enum radv_cmd_dirty_bits {
1023
/* Keep the dynamic state dirty bits in sync with
1024
* enum radv_dynamic_state_bits */
1025
RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1ull << 0,
1026
RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1ull << 1,
1027
RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1ull << 2,
1028
RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1ull << 3,
1029
RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,
1030
RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,
1031
RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,
1032
RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,
1033
RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,
1034
RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,
1035
RADV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,
1036
RADV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE = 1ull << 11,
1037
RADV_CMD_DIRTY_DYNAMIC_CULL_MODE = 1ull << 12,
1038
RADV_CMD_DIRTY_DYNAMIC_FRONT_FACE = 1ull << 13,
1039
RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,
1040
RADV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,
1041
RADV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,
1042
RADV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,
1043
RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,
1044
RADV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,
1045
RADV_CMD_DIRTY_DYNAMIC_STENCIL_OP = 1ull << 20,
1046
RADV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,
1047
RADV_CMD_DIRTY_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,
1048
RADV_CMD_DIRTY_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,
1049
RADV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,
1050
RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,
1051
RADV_CMD_DIRTY_DYNAMIC_LOGIC_OP = 1ull << 26,
1052
RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,
1053
RADV_CMD_DIRTY_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,
1054
RADV_CMD_DIRTY_DYNAMIC_ALL = (1ull << 29) - 1,
1055
RADV_CMD_DIRTY_PIPELINE = 1ull << 29,
1056
RADV_CMD_DIRTY_INDEX_BUFFER = 1ull << 30,
1057
RADV_CMD_DIRTY_FRAMEBUFFER = 1ull << 31,
1058
RADV_CMD_DIRTY_VERTEX_BUFFER = 1ull << 32,
1059
RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1ull << 33
1060
};
1061
1062
enum radv_cmd_flush_bits {
1063
/* Instruction cache. */
1064
RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
1065
/* Scalar L1 cache. */
1066
RADV_CMD_FLAG_INV_SCACHE = 1 << 1,
1067
/* Vector L1 cache. */
1068
RADV_CMD_FLAG_INV_VCACHE = 1 << 2,
1069
/* L2 cache + L2 metadata cache writeback & invalidate.
1070
* GFX6-8: Used by shaders only. GFX9-10: Used by everything. */
1071
RADV_CMD_FLAG_INV_L2 = 1 << 3,
1072
/* L2 writeback (write dirty L2 lines to memory for non-L2 clients).
1073
* Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8.
1074
* GFX6-7 will do complete invalidation, because the writeback is unsupported. */
1075
RADV_CMD_FLAG_WB_L2 = 1 << 4,
1076
/* Invalidate the metadata cache. To be used when the DCC/HTILE metadata
1077
* changed and we want to read an image from shaders. */
1078
RADV_CMD_FLAG_INV_L2_METADATA = 1 << 5,
1079
/* Framebuffer caches */
1080
RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 6,
1081
RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 7,
1082
RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 8,
1083
RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 9,
1084
/* Engine synchronization. */
1085
RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 10,
1086
RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 11,
1087
RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 12,
1088
RADV_CMD_FLAG_VGT_FLUSH = 1 << 13,
1089
/* Pipeline query controls. */
1090
RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 14,
1091
RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 15,
1092
RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 16,
1093
1094
RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER =
1095
(RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
1096
RADV_CMD_FLAG_FLUSH_AND_INV_DB | RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
1097
};
1098
1099
struct radv_vertex_binding {
1100
struct radv_buffer *buffer;
1101
VkDeviceSize offset;
1102
VkDeviceSize size;
1103
VkDeviceSize stride;
1104
};
1105
1106
struct radv_streamout_binding {
1107
struct radv_buffer *buffer;
1108
VkDeviceSize offset;
1109
VkDeviceSize size;
1110
};
1111
1112
struct radv_streamout_state {
1113
/* Mask of bound streamout buffers. */
1114
uint8_t enabled_mask;
1115
1116
/* External state that comes from the last vertex stage, it must be
1117
* set explicitely when binding a new graphics pipeline.
1118
*/
1119
uint16_t stride_in_dw[MAX_SO_BUFFERS];
1120
uint32_t enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
1121
1122
/* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */
1123
uint32_t hw_enabled_mask;
1124
1125
/* State of VGT_STRMOUT_(CONFIG|EN) */
1126
bool streamout_enabled;
1127
};
1128
1129
struct radv_viewport_state {
1130
uint32_t count;
1131
VkViewport viewports[MAX_VIEWPORTS];
1132
};
1133
1134
struct radv_scissor_state {
1135
uint32_t count;
1136
VkRect2D scissors[MAX_SCISSORS];
1137
};
1138
1139
struct radv_discard_rectangle_state {
1140
uint32_t count;
1141
VkRect2D rectangles[MAX_DISCARD_RECTANGLES];
1142
};
1143
1144
struct radv_sample_locations_state {
1145
VkSampleCountFlagBits per_pixel;
1146
VkExtent2D grid_size;
1147
uint32_t count;
1148
VkSampleLocationEXT locations[MAX_SAMPLE_LOCATIONS];
1149
};
1150
1151
struct radv_dynamic_state {
1152
/**
1153
* Bitmask of (1ull << VK_DYNAMIC_STATE_*).
1154
* Defines the set of saved dynamic state.
1155
*/
1156
uint64_t mask;
1157
1158
struct radv_viewport_state viewport;
1159
1160
struct radv_scissor_state scissor;
1161
1162
float line_width;
1163
1164
struct {
1165
float bias;
1166
float clamp;
1167
float slope;
1168
} depth_bias;
1169
1170
float blend_constants[4];
1171
1172
struct {
1173
float min;
1174
float max;
1175
} depth_bounds;
1176
1177
struct {
1178
uint32_t front;
1179
uint32_t back;
1180
} stencil_compare_mask;
1181
1182
struct {
1183
uint32_t front;
1184
uint32_t back;
1185
} stencil_write_mask;
1186
1187
struct {
1188
struct {
1189
VkStencilOp fail_op;
1190
VkStencilOp pass_op;
1191
VkStencilOp depth_fail_op;
1192
VkCompareOp compare_op;
1193
} front;
1194
1195
struct {
1196
VkStencilOp fail_op;
1197
VkStencilOp pass_op;
1198
VkStencilOp depth_fail_op;
1199
VkCompareOp compare_op;
1200
} back;
1201
} stencil_op;
1202
1203
struct {
1204
uint32_t front;
1205
uint32_t back;
1206
} stencil_reference;
1207
1208
struct radv_discard_rectangle_state discard_rectangle;
1209
1210
struct radv_sample_locations_state sample_location;
1211
1212
struct {
1213
uint32_t factor;
1214
uint16_t pattern;
1215
} line_stipple;
1216
1217
VkCullModeFlags cull_mode;
1218
VkFrontFace front_face;
1219
unsigned primitive_topology;
1220
1221
bool depth_test_enable;
1222
bool depth_write_enable;
1223
VkCompareOp depth_compare_op;
1224
bool depth_bounds_test_enable;
1225
bool stencil_test_enable;
1226
1227
struct {
1228
VkExtent2D size;
1229
VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
1230
} fragment_shading_rate;
1231
1232
bool depth_bias_enable;
1233
bool primitive_restart_enable;
1234
bool rasterizer_discard_enable;
1235
1236
unsigned logic_op;
1237
1238
uint32_t color_write_enable;
1239
};
1240
1241
extern const struct radv_dynamic_state default_dynamic_state;
1242
1243
const char *radv_get_debug_option_name(int id);
1244
1245
const char *radv_get_perftest_option_name(int id);
1246
1247
int radv_get_int_debug_option(const char *name, int default_value);
1248
1249
struct radv_color_buffer_info {
1250
uint64_t cb_color_base;
1251
uint64_t cb_color_cmask;
1252
uint64_t cb_color_fmask;
1253
uint64_t cb_dcc_base;
1254
uint32_t cb_color_slice;
1255
uint32_t cb_color_view;
1256
uint32_t cb_color_info;
1257
uint32_t cb_color_attrib;
1258
uint32_t cb_color_attrib2; /* GFX9 and later */
1259
uint32_t cb_color_attrib3; /* GFX10 and later */
1260
uint32_t cb_dcc_control;
1261
uint32_t cb_color_cmask_slice;
1262
uint32_t cb_color_fmask_slice;
1263
union {
1264
uint32_t cb_color_pitch; // GFX6-GFX8
1265
uint32_t cb_mrt_epitch; // GFX9+
1266
};
1267
};
1268
1269
struct radv_ds_buffer_info {
1270
uint64_t db_z_read_base;
1271
uint64_t db_stencil_read_base;
1272
uint64_t db_z_write_base;
1273
uint64_t db_stencil_write_base;
1274
uint64_t db_htile_data_base;
1275
uint32_t db_depth_info;
1276
uint32_t db_z_info;
1277
uint32_t db_stencil_info;
1278
uint32_t db_depth_view;
1279
uint32_t db_depth_size;
1280
uint32_t db_depth_slice;
1281
uint32_t db_htile_surface;
1282
uint32_t pa_su_poly_offset_db_fmt_cntl;
1283
uint32_t db_z_info2; /* GFX9 only */
1284
uint32_t db_stencil_info2; /* GFX9 only */
1285
};
1286
1287
void radv_initialise_color_surface(struct radv_device *device, struct radv_color_buffer_info *cb,
1288
struct radv_image_view *iview);
1289
void radv_initialise_ds_surface(struct radv_device *device, struct radv_ds_buffer_info *ds,
1290
struct radv_image_view *iview);
1291
1292
/**
1293
* Attachment state when recording a renderpass instance.
1294
*
1295
* The clear value is valid only if there exists a pending clear.
1296
*/
1297
struct radv_attachment_state {
1298
VkImageAspectFlags pending_clear_aspects;
1299
uint32_t cleared_views;
1300
VkClearValue clear_value;
1301
VkImageLayout current_layout;
1302
VkImageLayout current_stencil_layout;
1303
bool current_in_render_loop;
1304
bool disable_dcc;
1305
struct radv_sample_locations_state sample_location;
1306
1307
union {
1308
struct radv_color_buffer_info cb;
1309
struct radv_ds_buffer_info ds;
1310
};
1311
struct radv_image_view *iview;
1312
};
1313
1314
struct radv_descriptor_state {
1315
struct radv_descriptor_set *sets[MAX_SETS];
1316
uint32_t dirty;
1317
uint32_t valid;
1318
struct radv_push_descriptor_set push_set;
1319
bool push_dirty;
1320
uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
1321
};
1322
1323
struct radv_subpass_sample_locs_state {
1324
uint32_t subpass_idx;
1325
struct radv_sample_locations_state sample_location;
1326
};
1327
1328
enum rgp_flush_bits {
1329
RGP_FLUSH_WAIT_ON_EOP_TS = 0x1,
1330
RGP_FLUSH_VS_PARTIAL_FLUSH = 0x2,
1331
RGP_FLUSH_PS_PARTIAL_FLUSH = 0x4,
1332
RGP_FLUSH_CS_PARTIAL_FLUSH = 0x8,
1333
RGP_FLUSH_PFP_SYNC_ME = 0x10,
1334
RGP_FLUSH_SYNC_CP_DMA = 0x20,
1335
RGP_FLUSH_INVAL_VMEM_L0 = 0x40,
1336
RGP_FLUSH_INVAL_ICACHE = 0x80,
1337
RGP_FLUSH_INVAL_SMEM_L0 = 0x100,
1338
RGP_FLUSH_FLUSH_L2 = 0x200,
1339
RGP_FLUSH_INVAL_L2 = 0x400,
1340
RGP_FLUSH_FLUSH_CB = 0x800,
1341
RGP_FLUSH_INVAL_CB = 0x1000,
1342
RGP_FLUSH_FLUSH_DB = 0x2000,
1343
RGP_FLUSH_INVAL_DB = 0x4000,
1344
RGP_FLUSH_INVAL_L1 = 0x8000,
1345
};
1346
1347
struct radv_cmd_state {
1348
/* Vertex descriptors */
1349
uint64_t vb_va;
1350
1351
bool predicating;
1352
uint64_t dirty;
1353
1354
uint32_t prefetch_L2_mask;
1355
1356
struct radv_pipeline *pipeline;
1357
struct radv_pipeline *emitted_pipeline;
1358
struct radv_pipeline *compute_pipeline;
1359
struct radv_pipeline *emitted_compute_pipeline;
1360
struct radv_pipeline *rt_pipeline; /* emitted = emitted_compute_pipeline */
1361
struct radv_framebuffer *framebuffer;
1362
struct radv_render_pass *pass;
1363
const struct radv_subpass *subpass;
1364
struct radv_dynamic_state dynamic;
1365
struct radv_attachment_state *attachments;
1366
struct radv_streamout_state streamout;
1367
VkRect2D render_area;
1368
1369
uint32_t num_subpass_sample_locs;
1370
struct radv_subpass_sample_locs_state *subpass_sample_locs;
1371
1372
/* Index buffer */
1373
struct radv_buffer *index_buffer;
1374
uint64_t index_offset;
1375
uint32_t index_type;
1376
uint32_t max_index_count;
1377
uint64_t index_va;
1378
int32_t last_index_type;
1379
1380
int32_t last_primitive_reset_en;
1381
uint32_t last_primitive_reset_index;
1382
enum radv_cmd_flush_bits flush_bits;
1383
unsigned active_occlusion_queries;
1384
bool perfect_occlusion_queries_enabled;
1385
unsigned active_pipeline_queries;
1386
unsigned active_pipeline_gds_queries;
1387
uint32_t trace_id;
1388
uint32_t last_ia_multi_vgt_param;
1389
1390
uint32_t last_num_instances;
1391
uint32_t last_first_instance;
1392
uint32_t last_vertex_offset;
1393
uint32_t last_drawid;
1394
1395
uint32_t last_sx_ps_downconvert;
1396
uint32_t last_sx_blend_opt_epsilon;
1397
uint32_t last_sx_blend_opt_control;
1398
1399
/* Whether CP DMA is busy/idle. */
1400
bool dma_is_busy;
1401
1402
/* Conditional rendering info. */
1403
uint8_t predication_op; /* 32-bit or 64-bit predicate value */
1404
int predication_type; /* -1: disabled, 0: normal, 1: inverted */
1405
uint64_t predication_va;
1406
1407
/* Inheritance info. */
1408
VkQueryPipelineStatisticFlags inherited_pipeline_statistics;
1409
1410
bool context_roll_without_scissor_emitted;
1411
1412
/* SQTT related state. */
1413
uint32_t current_event_type;
1414
uint32_t num_events;
1415
uint32_t num_layout_transitions;
1416
bool pending_sqtt_barrier_end;
1417
enum rgp_flush_bits sqtt_flush_bits;
1418
1419
/* NGG culling state. */
1420
uint32_t last_nggc_settings;
1421
int8_t last_nggc_settings_sgpr_idx;
1422
bool last_nggc_skip;
1423
1424
uint8_t cb_mip[MAX_RTS];
1425
1426
/* Whether DRAW_{INDEX}_INDIRECT_MULTI is emitted. */
1427
bool uses_draw_indirect_multi;
1428
};
1429
1430
struct radv_cmd_pool {
1431
struct vk_object_base base;
1432
VkAllocationCallbacks alloc;
1433
struct list_head cmd_buffers;
1434
struct list_head free_cmd_buffers;
1435
uint32_t queue_family_index;
1436
};
1437
1438
struct radv_cmd_buffer_upload {
1439
uint8_t *map;
1440
unsigned offset;
1441
uint64_t size;
1442
struct radeon_winsys_bo *upload_bo;
1443
struct list_head list;
1444
};
1445
1446
enum radv_cmd_buffer_status {
1447
RADV_CMD_BUFFER_STATUS_INVALID,
1448
RADV_CMD_BUFFER_STATUS_INITIAL,
1449
RADV_CMD_BUFFER_STATUS_RECORDING,
1450
RADV_CMD_BUFFER_STATUS_EXECUTABLE,
1451
RADV_CMD_BUFFER_STATUS_PENDING,
1452
};
1453
1454
struct radv_cmd_buffer {
1455
struct vk_object_base base;
1456
1457
struct radv_device *device;
1458
1459
struct radv_cmd_pool *pool;
1460
struct list_head pool_link;
1461
1462
VkCommandBufferUsageFlags usage_flags;
1463
VkCommandBufferLevel level;
1464
enum radv_cmd_buffer_status status;
1465
struct radeon_cmdbuf *cs;
1466
struct radv_cmd_state state;
1467
struct radv_vertex_binding vertex_bindings[MAX_VBS];
1468
struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
1469
uint32_t queue_family_index;
1470
1471
uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
1472
VkShaderStageFlags push_constant_stages;
1473
struct radv_descriptor_set_header meta_push_descriptors;
1474
1475
struct radv_descriptor_state descriptors[MAX_BIND_POINTS];
1476
1477
struct radv_cmd_buffer_upload upload;
1478
1479
uint32_t scratch_size_per_wave_needed;
1480
uint32_t scratch_waves_wanted;
1481
uint32_t compute_scratch_size_per_wave_needed;
1482
uint32_t compute_scratch_waves_wanted;
1483
uint32_t esgs_ring_size_needed;
1484
uint32_t gsvs_ring_size_needed;
1485
bool tess_rings_needed;
1486
bool gds_needed; /* for GFX10 streamout and NGG GS queries */
1487
bool gds_oa_needed; /* for GFX10 streamout */
1488
bool sample_positions_needed;
1489
1490
VkResult record_result;
1491
1492
uint64_t gfx9_fence_va;
1493
uint32_t gfx9_fence_idx;
1494
uint64_t gfx9_eop_bug_va;
1495
1496
/**
1497
* Whether a query pool has been resetted and we have to flush caches.
1498
*/
1499
bool pending_reset_query;
1500
1501
/**
1502
* Bitmask of pending active query flushes.
1503
*/
1504
enum radv_cmd_flush_bits active_query_flush_bits;
1505
};
1506
1507
struct radv_image;
1508
struct radv_image_view;
1509
1510
bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
1511
1512
void si_emit_graphics(struct radv_device *device, struct radeon_cmdbuf *cs);
1513
void si_emit_compute(struct radv_device *device, struct radeon_cmdbuf *cs);
1514
1515
void cik_create_gfx_config(struct radv_device *device);
1516
1517
void si_write_viewport(struct radeon_cmdbuf *cs, int first_vp, int count,
1518
const VkViewport *viewports);
1519
void si_write_scissors(struct radeon_cmdbuf *cs, int first, int count, const VkRect2D *scissors,
1520
const VkViewport *viewports, bool can_use_guardband);
1521
uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer, bool instanced_draw,
1522
bool indirect_draw, bool count_from_stream_output,
1523
uint32_t draw_vertex_count, unsigned topology,
1524
bool prim_restart_enable);
1525
void si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs, enum chip_class chip_class, bool is_mec,
1526
unsigned event, unsigned event_flags, unsigned dst_sel,
1527
unsigned data_sel, uint64_t va, uint32_t new_fence,
1528
uint64_t gfx9_eop_bug_va);
1529
1530
void radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va, uint32_t ref,
1531
uint32_t mask);
1532
void si_cs_emit_cache_flush(struct radeon_cmdbuf *cs, enum chip_class chip_class,
1533
uint32_t *fence_ptr, uint64_t va, bool is_mec,
1534
enum radv_cmd_flush_bits flush_bits,
1535
enum rgp_flush_bits *sqtt_flush_bits, uint64_t gfx9_eop_bug_va);
1536
void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
1537
void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer, bool draw_visible,
1538
unsigned pred_op, uint64_t va);
1539
void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer, uint64_t src_va, uint64_t dest_va,
1540
uint64_t size);
1541
void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va, unsigned size);
1542
void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va, uint64_t size,
1543
unsigned value);
1544
void si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);
1545
1546
void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
1547
bool radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer, unsigned size,
1548
unsigned *out_offset, void **ptr);
1549
void radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
1550
const struct radv_subpass *subpass);
1551
bool radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer, unsigned size,
1552
const void *data, unsigned *out_offset);
1553
1554
void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
1555
void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
1556
void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
1557
void radv_depth_stencil_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer,
1558
VkImageAspectFlags aspects,
1559
VkResolveModeFlagBits resolve_mode);
1560
void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
1561
void radv_depth_stencil_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer,
1562
VkImageAspectFlags aspects,
1563
VkResolveModeFlagBits resolve_mode);
1564
void radv_emit_default_sample_locations(struct radeon_cmdbuf *cs, int nr_samples);
1565
unsigned radv_get_default_max_sample_dist(int log_samples);
1566
void radv_device_init_msaa(struct radv_device *device);
1567
VkResult radv_device_init_vrs_image(struct radv_device *device);
1568
1569
void radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1570
const struct radv_image_view *iview,
1571
VkClearDepthStencilValue ds_clear_value,
1572
VkImageAspectFlags aspects);
1573
1574
void radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1575
const struct radv_image_view *iview, int cb_idx,
1576
uint32_t color_values[2]);
1577
1578
bool radv_image_use_dcc_image_stores(const struct radv_device *device,
1579
const struct radv_image *image);
1580
bool radv_image_use_dcc_predication(const struct radv_device *device,
1581
const struct radv_image *image);
1582
void radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
1583
const VkImageSubresourceRange *range, bool value);
1584
1585
void radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
1586
const VkImageSubresourceRange *range, bool value);
1587
enum radv_cmd_flush_bits radv_src_access_flush(struct radv_cmd_buffer *cmd_buffer,
1588
VkAccessFlags src_flags,
1589
const struct radv_image *image);
1590
enum radv_cmd_flush_bits radv_dst_access_flush(struct radv_cmd_buffer *cmd_buffer,
1591
VkAccessFlags dst_flags,
1592
const struct radv_image *image);
1593
uint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer, const struct radv_image *image,
1594
struct radeon_winsys_bo *bo, uint64_t offset, uint64_t size,
1595
uint32_t value);
1596
void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
1597
bool radv_get_memory_fd(struct radv_device *device, struct radv_device_memory *memory, int *pFD);
1598
void radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator,
1599
struct radv_device_memory *mem);
1600
1601
static inline void
1602
radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs, unsigned sh_offset, unsigned pointer_count,
1603
bool use_32bit_pointers)
1604
{
1605
radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));
1606
radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);
1607
}
1608
1609
static inline void
1610
radv_emit_shader_pointer_body(struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t va,
1611
bool use_32bit_pointers)
1612
{
1613
radeon_emit(cs, va);
1614
1615
if (use_32bit_pointers) {
1616
assert(va == 0 || (va >> 32) == device->physical_device->rad_info.address32_hi);
1617
} else {
1618
radeon_emit(cs, va >> 32);
1619
}
1620
}
1621
1622
static inline void
1623
radv_emit_shader_pointer(struct radv_device *device, struct radeon_cmdbuf *cs, uint32_t sh_offset,
1624
uint64_t va, bool global)
1625
{
1626
bool use_32bit_pointers = !global;
1627
1628
radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);
1629
radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);
1630
}
1631
1632
static inline struct radv_descriptor_state *
1633
radv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point)
1634
{
1635
switch (bind_point) {
1636
case VK_PIPELINE_BIND_POINT_GRAPHICS:
1637
case VK_PIPELINE_BIND_POINT_COMPUTE:
1638
return &cmd_buffer->descriptors[bind_point];
1639
case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:
1640
return &cmd_buffer->descriptors[2];
1641
default:
1642
unreachable("Unhandled bind point");
1643
}
1644
}
1645
1646
void
1647
radv_get_viewport_xform(const VkViewport *viewport, float scale[3], float translate[3]);
1648
1649
/*
1650
* Takes x,y,z as exact numbers of invocations, instead of blocks.
1651
*
1652
* Limitations: Can't call normal dispatch functions without binding or rebinding
1653
* the compute pipeline.
1654
*/
1655
void radv_unaligned_dispatch(struct radv_cmd_buffer *cmd_buffer, uint32_t x, uint32_t y,
1656
uint32_t z);
1657
1658
struct radv_event {
1659
struct vk_object_base base;
1660
struct radeon_winsys_bo *bo;
1661
uint64_t *map;
1662
};
1663
1664
#define RADV_HASH_SHADER_NO_NGG (1 << 0)
1665
#define RADV_HASH_SHADER_CS_WAVE32 (1 << 1)
1666
#define RADV_HASH_SHADER_PS_WAVE32 (1 << 2)
1667
#define RADV_HASH_SHADER_GE_WAVE32 (1 << 3)
1668
#define RADV_HASH_SHADER_LLVM (1 << 4)
1669
#define RADV_HASH_SHADER_DISCARD_TO_DEMOTE (1 << 5)
1670
#define RADV_HASH_SHADER_MRT_NAN_FIXUP (1 << 6)
1671
#define RADV_HASH_SHADER_INVARIANT_GEOM (1 << 7)
1672
#define RADV_HASH_SHADER_KEEP_STATISTICS (1 << 8)
1673
#define RADV_HASH_SHADER_FORCE_VRS_2x2 (1 << 9)
1674
#define RADV_HASH_SHADER_FORCE_VRS_2x1 (1 << 10)
1675
#define RADV_HASH_SHADER_FORCE_VRS_1x2 (1 << 11)
1676
#define RADV_HASH_SHADER_FORCE_NGG_CULLING (1 << 13)
1677
1678
void radv_hash_shaders(unsigned char *hash, const VkPipelineShaderStageCreateInfo **stages,
1679
const struct radv_pipeline_layout *layout,
1680
const struct radv_pipeline_key *key, uint32_t flags);
1681
1682
#define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1683
1684
#define radv_foreach_stage(stage, stage_bits) \
1685
for (gl_shader_stage stage, __tmp = (gl_shader_stage)((stage_bits)&RADV_STAGE_MASK); \
1686
stage = ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
1687
1688
extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
1689
unsigned radv_format_meta_fs_key(struct radv_device *device, VkFormat format);
1690
1691
struct radv_multisample_state {
1692
uint32_t db_eqaa;
1693
uint32_t pa_sc_mode_cntl_0;
1694
uint32_t pa_sc_mode_cntl_1;
1695
uint32_t pa_sc_aa_config;
1696
uint32_t pa_sc_aa_mask[2];
1697
unsigned num_samples;
1698
};
1699
1700
struct radv_vrs_state {
1701
uint32_t pa_cl_vrs_cntl;
1702
};
1703
1704
struct radv_prim_vertex_count {
1705
uint8_t min;
1706
uint8_t incr;
1707
};
1708
1709
struct radv_ia_multi_vgt_param_helpers {
1710
uint32_t base;
1711
bool partial_es_wave;
1712
uint8_t primgroup_size;
1713
bool ia_switch_on_eoi;
1714
bool partial_vs_wave;
1715
};
1716
1717
struct radv_binning_state {
1718
uint32_t pa_sc_binner_cntl_0;
1719
};
1720
1721
#define SI_GS_PER_ES 128
1722
1723
struct radv_pipeline {
1724
struct vk_object_base base;
1725
struct radv_device *device;
1726
struct radv_dynamic_state dynamic_state;
1727
1728
struct radv_pipeline_layout *layout;
1729
1730
bool need_indirect_descriptor_sets;
1731
struct radv_shader_variant *shaders[MESA_SHADER_STAGES];
1732
struct radv_shader_variant *gs_copy_shader;
1733
VkShaderStageFlags active_stages;
1734
1735
struct radeon_cmdbuf cs;
1736
uint32_t ctx_cs_hash;
1737
struct radeon_cmdbuf ctx_cs;
1738
1739
uint32_t binding_stride[MAX_VBS];
1740
1741
uint8_t attrib_bindings[MAX_VERTEX_ATTRIBS];
1742
uint32_t attrib_ends[MAX_VERTEX_ATTRIBS];
1743
uint32_t attrib_index_offset[MAX_VERTEX_ATTRIBS];
1744
1745
bool use_per_attribute_vb_descs;
1746
uint32_t vb_desc_usage_mask;
1747
uint32_t vb_desc_alloc_size;
1748
1749
uint32_t user_data_0[MESA_SHADER_STAGES];
1750
union {
1751
struct {
1752
struct radv_multisample_state ms;
1753
struct radv_binning_state binning;
1754
struct radv_vrs_state vrs;
1755
uint32_t spi_baryc_cntl;
1756
unsigned esgs_ring_size;
1757
unsigned gsvs_ring_size;
1758
uint32_t vtx_base_sgpr;
1759
struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
1760
uint8_t vtx_emit_num;
1761
bool uses_drawid;
1762
bool uses_baseinstance;
1763
bool can_use_guardband;
1764
uint64_t needed_dynamic_state;
1765
bool disable_out_of_order_rast_for_occlusion;
1766
unsigned tess_patch_control_points;
1767
unsigned pa_su_sc_mode_cntl;
1768
unsigned db_depth_control;
1769
unsigned pa_cl_clip_cntl;
1770
unsigned cb_color_control;
1771
bool uses_dynamic_stride;
1772
bool uses_conservative_overestimate;
1773
1774
/* Used for rbplus */
1775
uint32_t col_format;
1776
uint32_t cb_target_mask;
1777
1778
/* Whether the pipeline uses NGG (GFX10+). */
1779
bool is_ngg;
1780
bool has_ngg_culling;
1781
1782
/* Last pre-PS API stage */
1783
gl_shader_stage last_vgt_api_stage;
1784
} graphics;
1785
};
1786
1787
unsigned max_waves;
1788
unsigned scratch_bytes_per_wave;
1789
1790
/* Not NULL if graphics pipeline uses streamout. */
1791
struct radv_shader_variant *streamout_shader;
1792
1793
/* Unique pipeline hash identifier. */
1794
uint64_t pipeline_hash;
1795
};
1796
1797
static inline bool
1798
radv_pipeline_has_gs(const struct radv_pipeline *pipeline)
1799
{
1800
return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1801
}
1802
1803
static inline bool
1804
radv_pipeline_has_tess(const struct radv_pipeline *pipeline)
1805
{
1806
return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;
1807
}
1808
1809
bool radv_pipeline_has_ngg_passthrough(const struct radv_pipeline *pipeline);
1810
1811
bool radv_pipeline_has_gs_copy_shader(const struct radv_pipeline *pipeline);
1812
1813
struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
1814
gl_shader_stage stage, int idx);
1815
1816
struct radv_shader_variant *radv_get_shader(const struct radv_pipeline *pipeline,
1817
gl_shader_stage stage);
1818
1819
struct radv_graphics_pipeline_create_info {
1820
bool use_rectlist;
1821
bool db_depth_clear;
1822
bool db_stencil_clear;
1823
bool db_depth_disable_expclear;
1824
bool db_stencil_disable_expclear;
1825
bool depth_compress_disable;
1826
bool stencil_compress_disable;
1827
bool resummarize_enable;
1828
uint32_t custom_blend_mode;
1829
};
1830
1831
VkResult radv_graphics_pipeline_create(VkDevice device, VkPipelineCache cache,
1832
const VkGraphicsPipelineCreateInfo *pCreateInfo,
1833
const struct radv_graphics_pipeline_create_info *extra,
1834
const VkAllocationCallbacks *alloc, VkPipeline *pPipeline);
1835
1836
struct radv_binning_settings {
1837
unsigned context_states_per_bin; /* allowed range: [1, 6] */
1838
unsigned persistent_states_per_bin; /* allowed range: [1, 32] */
1839
unsigned fpovs_per_batch; /* allowed range: [0, 255], 0 = unlimited */
1840
};
1841
1842
struct radv_binning_settings radv_get_binning_settings(const struct radv_physical_device *pdev);
1843
1844
struct vk_format_description;
1845
uint32_t radv_translate_buffer_dataformat(const struct util_format_description *desc,
1846
int first_non_void);
1847
uint32_t radv_translate_buffer_numformat(const struct util_format_description *desc,
1848
int first_non_void);
1849
bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
1850
uint32_t radv_translate_colorformat(VkFormat format);
1851
uint32_t radv_translate_color_numformat(VkFormat format, const struct util_format_description *desc,
1852
int first_non_void);
1853
uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1854
unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1855
uint32_t radv_translate_dbformat(VkFormat format);
1856
uint32_t radv_translate_tex_dataformat(VkFormat format, const struct util_format_description *desc,
1857
int first_non_void);
1858
uint32_t radv_translate_tex_numformat(VkFormat format, const struct util_format_description *desc,
1859
int first_non_void);
1860
bool radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2],
1861
VkClearColorValue *value);
1862
bool radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,
1863
VkFormat format);
1864
bool radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdevice,
1865
VkFormat format, bool *blendable);
1866
bool radv_dcc_formats_compatible(VkFormat format1, VkFormat format2);
1867
bool radv_is_atomic_format_supported(VkFormat format);
1868
bool radv_device_supports_etc(struct radv_physical_device *physical_device);
1869
1870
struct radv_image_plane {
1871
VkFormat format;
1872
struct radeon_surf surface;
1873
};
1874
1875
struct radv_image {
1876
struct vk_object_base base;
1877
VkImageType type;
1878
/* The original VkFormat provided by the client. This may not match any
1879
* of the actual surface formats.
1880
*/
1881
VkFormat vk_format;
1882
VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1883
struct ac_surf_info info;
1884
VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1885
VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1886
1887
VkDeviceSize size;
1888
uint32_t alignment;
1889
1890
unsigned queue_family_mask;
1891
bool exclusive;
1892
bool shareable;
1893
bool l2_coherent;
1894
1895
/* Set when bound */
1896
struct radeon_winsys_bo *bo;
1897
VkDeviceSize offset;
1898
bool tc_compatible_cmask;
1899
1900
uint64_t clear_value_offset;
1901
uint64_t fce_pred_offset;
1902
uint64_t dcc_pred_offset;
1903
1904
/*
1905
* Metadata for the TC-compat zrange workaround. If the 32-bit value
1906
* stored at this offset is UINT_MAX, the driver will emit
1907
* DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
1908
* SET_CONTEXT_REG packet.
1909
*/
1910
uint64_t tc_compat_zrange_offset;
1911
1912
/* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1913
VkDeviceMemory owned_memory;
1914
1915
unsigned plane_count;
1916
struct radv_image_plane planes[0];
1917
};
1918
1919
/* Whether the image has a htile that is known consistent with the contents of
1920
* the image and is allowed to be in compressed form.
1921
*
1922
* If this is false reads that don't use the htile should be able to return
1923
* correct results.
1924
*/
1925
bool radv_layout_is_htile_compressed(const struct radv_device *device,
1926
const struct radv_image *image, VkImageLayout layout,
1927
bool in_render_loop, unsigned queue_mask);
1928
1929
bool radv_layout_can_fast_clear(const struct radv_device *device, const struct radv_image *image,
1930
unsigned level, VkImageLayout layout, bool in_render_loop,
1931
unsigned queue_mask);
1932
1933
bool radv_layout_dcc_compressed(const struct radv_device *device, const struct radv_image *image,
1934
unsigned level, VkImageLayout layout, bool in_render_loop,
1935
unsigned queue_mask);
1936
1937
bool radv_layout_fmask_compressed(const struct radv_device *device, const struct radv_image *image,
1938
VkImageLayout layout, unsigned queue_mask);
1939
1940
/**
1941
* Return whether the image has CMASK metadata for color surfaces.
1942
*/
1943
static inline bool
1944
radv_image_has_cmask(const struct radv_image *image)
1945
{
1946
return image->planes[0].surface.cmask_offset;
1947
}
1948
1949
/**
1950
* Return whether the image has FMASK metadata for color surfaces.
1951
*/
1952
static inline bool
1953
radv_image_has_fmask(const struct radv_image *image)
1954
{
1955
return image->planes[0].surface.fmask_offset;
1956
}
1957
1958
/**
1959
* Return whether the image has DCC metadata for color surfaces.
1960
*/
1961
static inline bool
1962
radv_image_has_dcc(const struct radv_image *image)
1963
{
1964
return !(image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER) &&
1965
image->planes[0].surface.meta_offset;
1966
}
1967
1968
/**
1969
* Return whether the image is TC-compatible CMASK.
1970
*/
1971
static inline bool
1972
radv_image_is_tc_compat_cmask(const struct radv_image *image)
1973
{
1974
return radv_image_has_fmask(image) && image->tc_compatible_cmask;
1975
}
1976
1977
/**
1978
* Return whether DCC metadata is enabled for a level.
1979
*/
1980
static inline bool
1981
radv_dcc_enabled(const struct radv_image *image, unsigned level)
1982
{
1983
return radv_image_has_dcc(image) && level < image->planes[0].surface.num_meta_levels;
1984
}
1985
1986
/**
1987
* Return whether the image has CB metadata.
1988
*/
1989
static inline bool
1990
radv_image_has_CB_metadata(const struct radv_image *image)
1991
{
1992
return radv_image_has_cmask(image) || radv_image_has_fmask(image) || radv_image_has_dcc(image);
1993
}
1994
1995
/**
1996
* Return whether the image has HTILE metadata for depth surfaces.
1997
*/
1998
static inline bool
1999
radv_image_has_htile(const struct radv_image *image)
2000
{
2001
return image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER &&
2002
image->planes[0].surface.meta_size;
2003
}
2004
2005
/**
2006
* Return whether the image has VRS HTILE metadata for depth surfaces
2007
*/
2008
static inline bool
2009
radv_image_has_vrs_htile(const struct radv_device *device, const struct radv_image *image)
2010
{
2011
/* Any depth buffer can potentially use VRS. */
2012
return device->attachment_vrs_enabled && radv_image_has_htile(image) &&
2013
(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
2014
}
2015
2016
/**
2017
* Return whether HTILE metadata is enabled for a level.
2018
*/
2019
static inline bool
2020
radv_htile_enabled(const struct radv_image *image, unsigned level)
2021
{
2022
return radv_image_has_htile(image) && level < image->planes[0].surface.num_meta_levels;
2023
}
2024
2025
/**
2026
* Return whether the image is TC-compatible HTILE.
2027
*/
2028
static inline bool
2029
radv_image_is_tc_compat_htile(const struct radv_image *image)
2030
{
2031
return radv_image_has_htile(image) &&
2032
(image->planes[0].surface.flags & RADEON_SURF_TC_COMPATIBLE_HTILE);
2033
}
2034
2035
/**
2036
* Return whether the entire HTILE buffer can be used for depth in order to
2037
* improve HiZ Z-Range precision.
2038
*/
2039
static inline bool
2040
radv_image_tile_stencil_disabled(const struct radv_device *device, const struct radv_image *image)
2041
{
2042
if (device->physical_device->rad_info.chip_class >= GFX9) {
2043
return !vk_format_has_stencil(image->vk_format) && !radv_image_has_vrs_htile(device, image);
2044
} else {
2045
/* Due to a hw bug, TILE_STENCIL_DISABLE must be set to 0 for
2046
* the TC-compat ZRANGE issue even if no stencil is used.
2047
*/
2048
return !vk_format_has_stencil(image->vk_format) && !radv_image_is_tc_compat_htile(image);
2049
}
2050
}
2051
2052
static inline bool
2053
radv_image_has_clear_value(const struct radv_image *image)
2054
{
2055
return image->clear_value_offset != 0;
2056
}
2057
2058
static inline uint64_t
2059
radv_image_get_fast_clear_va(const struct radv_image *image, uint32_t base_level)
2060
{
2061
assert(radv_image_has_clear_value(image));
2062
2063
uint64_t va = radv_buffer_get_va(image->bo);
2064
va += image->offset + image->clear_value_offset + base_level * 8;
2065
return va;
2066
}
2067
2068
static inline uint64_t
2069
radv_image_get_fce_pred_va(const struct radv_image *image, uint32_t base_level)
2070
{
2071
assert(image->fce_pred_offset != 0);
2072
2073
uint64_t va = radv_buffer_get_va(image->bo);
2074
va += image->offset + image->fce_pred_offset + base_level * 8;
2075
return va;
2076
}
2077
2078
static inline uint64_t
2079
radv_image_get_dcc_pred_va(const struct radv_image *image, uint32_t base_level)
2080
{
2081
assert(image->dcc_pred_offset != 0);
2082
2083
uint64_t va = radv_buffer_get_va(image->bo);
2084
va += image->offset + image->dcc_pred_offset + base_level * 8;
2085
return va;
2086
}
2087
2088
static inline uint64_t
2089
radv_get_tc_compat_zrange_va(const struct radv_image *image, uint32_t base_level)
2090
{
2091
assert(image->tc_compat_zrange_offset != 0);
2092
2093
uint64_t va = radv_buffer_get_va(image->bo);
2094
va += image->offset + image->tc_compat_zrange_offset + base_level * 4;
2095
return va;
2096
}
2097
2098
static inline uint64_t
2099
radv_get_ds_clear_value_va(const struct radv_image *image, uint32_t base_level)
2100
{
2101
assert(radv_image_has_clear_value(image));
2102
2103
uint64_t va = radv_buffer_get_va(image->bo);
2104
va += image->offset + image->clear_value_offset + base_level * 8;
2105
return va;
2106
}
2107
2108
static inline uint32_t
2109
radv_get_htile_initial_value(const struct radv_device *device, const struct radv_image *image)
2110
{
2111
uint32_t initial_value;
2112
2113
if (radv_image_tile_stencil_disabled(device, image)) {
2114
/* Z only (no stencil):
2115
*
2116
* |31 18|17 4|3 0|
2117
* +---------+---------+-------+
2118
* | Max Z | Min Z | ZMask |
2119
*/
2120
initial_value = 0xfffc000f;
2121
} else {
2122
/* Z and stencil:
2123
*
2124
* |31 12|11 10|9 8|7 6|5 4|3 0|
2125
* +-----------+-----+------+-----+-----+-------+
2126
* | Z Range | | SMem | SR1 | SR0 | ZMask |
2127
*
2128
* SR0/SR1 contains the stencil test results. Initializing
2129
* SR0/SR1 to 0x3 means the stencil test result is unknown.
2130
*
2131
* Z, stencil and 4 bit VRS encoding:
2132
* |31 12|11 10|9 8|7 6|5 4|3 0|
2133
* +-----------+------------+------+------------+-----+-------+
2134
* | Z Range | VRS y-rate | SMem | VRS x-rate | SR0 | ZMask |
2135
*/
2136
if (radv_image_has_vrs_htile(device, image)) {
2137
/* Initialize the VRS x-rate value at 0, so the hw interprets it as 1 sample. */
2138
initial_value = 0xfffff33f;
2139
} else {
2140
initial_value = 0xfffff3ff;
2141
}
2142
}
2143
2144
return initial_value;
2145
}
2146
2147
static inline bool
2148
radv_image_get_iterate256(struct radv_device *device, struct radv_image *image)
2149
{
2150
/* ITERATE_256 is required for depth or stencil MSAA images that are TC-compatible HTILE. */
2151
return device->physical_device->rad_info.chip_class >= GFX10 &&
2152
(image->usage & (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2153
VK_IMAGE_USAGE_TRANSFER_DST_BIT)) &&
2154
radv_image_is_tc_compat_htile(image) &&
2155
image->info.samples > 1;
2156
}
2157
2158
unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family,
2159
uint32_t queue_family);
2160
2161
static inline uint32_t
2162
radv_get_layerCount(const struct radv_image *image, const VkImageSubresourceRange *range)
2163
{
2164
return range->layerCount == VK_REMAINING_ARRAY_LAYERS
2165
? image->info.array_size - range->baseArrayLayer
2166
: range->layerCount;
2167
}
2168
2169
static inline uint32_t
2170
radv_get_levelCount(const struct radv_image *image, const VkImageSubresourceRange *range)
2171
{
2172
return range->levelCount == VK_REMAINING_MIP_LEVELS ? image->info.levels - range->baseMipLevel
2173
: range->levelCount;
2174
}
2175
2176
bool radv_image_is_renderable(struct radv_device *device, struct radv_image *image);
2177
2178
struct radeon_bo_metadata;
2179
void radv_init_metadata(struct radv_device *device, struct radv_image *image,
2180
struct radeon_bo_metadata *metadata);
2181
2182
void radv_image_override_offset_stride(struct radv_device *device, struct radv_image *image,
2183
uint64_t offset, uint32_t stride);
2184
2185
union radv_descriptor {
2186
struct {
2187
uint32_t plane0_descriptor[8];
2188
uint32_t fmask_descriptor[8];
2189
};
2190
struct {
2191
uint32_t plane_descriptors[3][8];
2192
};
2193
};
2194
2195
struct radv_image_view {
2196
struct vk_object_base base;
2197
struct radv_image *image; /**< VkImageViewCreateInfo::image */
2198
2199
VkImageViewType type;
2200
VkImageAspectFlags aspect_mask;
2201
VkFormat vk_format;
2202
unsigned plane_id;
2203
uint32_t base_layer;
2204
uint32_t layer_count;
2205
uint32_t base_mip;
2206
uint32_t level_count;
2207
VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2208
2209
/* Whether the image iview supports fast clear. */
2210
bool support_fast_clear;
2211
2212
union radv_descriptor descriptor;
2213
2214
/* Descriptor for use as a storage image as opposed to a sampled image.
2215
* This has a few differences for cube maps (e.g. type).
2216
*/
2217
union radv_descriptor storage_descriptor;
2218
};
2219
2220
struct radv_image_create_info {
2221
const VkImageCreateInfo *vk_info;
2222
bool scanout;
2223
bool no_metadata_planes;
2224
const struct radeon_bo_metadata *bo_metadata;
2225
};
2226
2227
VkResult
2228
radv_image_create_layout(struct radv_device *device, struct radv_image_create_info create_info,
2229
const struct VkImageDrmFormatModifierExplicitCreateInfoEXT *mod_info,
2230
struct radv_image *image);
2231
2232
VkResult radv_image_create(VkDevice _device, const struct radv_image_create_info *info,
2233
const VkAllocationCallbacks *alloc, VkImage *pImage);
2234
2235
bool radv_are_formats_dcc_compatible(const struct radv_physical_device *pdev, const void *pNext,
2236
VkFormat format, VkImageCreateFlags flags);
2237
2238
bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format);
2239
2240
VkResult radv_image_from_gralloc(VkDevice device_h, const VkImageCreateInfo *base_info,
2241
const VkNativeBufferANDROID *gralloc_info,
2242
const VkAllocationCallbacks *alloc, VkImage *out_image_h);
2243
uint64_t radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
2244
const VkImageUsageFlags vk_usage);
2245
VkResult radv_import_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,
2246
unsigned priority,
2247
const VkImportAndroidHardwareBufferInfoANDROID *info);
2248
VkResult radv_create_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,
2249
unsigned priority, const VkMemoryAllocateInfo *pAllocateInfo);
2250
2251
VkFormat radv_select_android_external_format(const void *next, VkFormat default_format);
2252
2253
bool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage);
2254
2255
struct radv_image_view_extra_create_info {
2256
bool disable_compression;
2257
bool enable_compression;
2258
};
2259
2260
void radv_image_view_init(struct radv_image_view *view, struct radv_device *device,
2261
const VkImageViewCreateInfo *pCreateInfo,
2262
const struct radv_image_view_extra_create_info *extra_create_info);
2263
2264
VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
2265
2266
struct radv_sampler_ycbcr_conversion {
2267
struct vk_object_base base;
2268
VkFormat format;
2269
VkSamplerYcbcrModelConversion ycbcr_model;
2270
VkSamplerYcbcrRange ycbcr_range;
2271
VkComponentMapping components;
2272
VkChromaLocation chroma_offsets[2];
2273
VkFilter chroma_filter;
2274
};
2275
2276
struct radv_buffer_view {
2277
struct vk_object_base base;
2278
struct radeon_winsys_bo *bo;
2279
VkFormat vk_format;
2280
uint64_t range; /**< VkBufferViewCreateInfo::range */
2281
uint32_t state[4];
2282
};
2283
void radv_buffer_view_init(struct radv_buffer_view *view, struct radv_device *device,
2284
const VkBufferViewCreateInfo *pCreateInfo);
2285
2286
static inline struct VkExtent3D
2287
radv_sanitize_image_extent(const VkImageType imageType, const struct VkExtent3D imageExtent)
2288
{
2289
switch (imageType) {
2290
case VK_IMAGE_TYPE_1D:
2291
return (VkExtent3D){imageExtent.width, 1, 1};
2292
case VK_IMAGE_TYPE_2D:
2293
return (VkExtent3D){imageExtent.width, imageExtent.height, 1};
2294
case VK_IMAGE_TYPE_3D:
2295
return imageExtent;
2296
default:
2297
unreachable("invalid image type");
2298
}
2299
}
2300
2301
static inline struct VkOffset3D
2302
radv_sanitize_image_offset(const VkImageType imageType, const struct VkOffset3D imageOffset)
2303
{
2304
switch (imageType) {
2305
case VK_IMAGE_TYPE_1D:
2306
return (VkOffset3D){imageOffset.x, 0, 0};
2307
case VK_IMAGE_TYPE_2D:
2308
return (VkOffset3D){imageOffset.x, imageOffset.y, 0};
2309
case VK_IMAGE_TYPE_3D:
2310
return imageOffset;
2311
default:
2312
unreachable("invalid image type");
2313
}
2314
}
2315
2316
static inline bool
2317
radv_image_extent_compare(const struct radv_image *image, const VkExtent3D *extent)
2318
{
2319
if (extent->width != image->info.width || extent->height != image->info.height ||
2320
extent->depth != image->info.depth)
2321
return false;
2322
return true;
2323
}
2324
2325
struct radv_sampler {
2326
struct vk_object_base base;
2327
uint32_t state[4];
2328
struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
2329
uint32_t border_color_slot;
2330
};
2331
2332
struct radv_framebuffer {
2333
struct vk_object_base base;
2334
uint32_t width;
2335
uint32_t height;
2336
uint32_t layers;
2337
2338
bool imageless;
2339
2340
uint32_t attachment_count;
2341
struct radv_image_view *attachments[0];
2342
};
2343
2344
struct radv_subpass_barrier {
2345
VkPipelineStageFlags src_stage_mask;
2346
VkAccessFlags src_access_mask;
2347
VkAccessFlags dst_access_mask;
2348
};
2349
2350
void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
2351
const struct radv_subpass_barrier *barrier);
2352
2353
struct radv_subpass_attachment {
2354
uint32_t attachment;
2355
VkImageLayout layout;
2356
VkImageLayout stencil_layout;
2357
bool in_render_loop;
2358
};
2359
2360
struct radv_subpass {
2361
uint32_t attachment_count;
2362
struct radv_subpass_attachment *attachments;
2363
2364
uint32_t input_count;
2365
uint32_t color_count;
2366
struct radv_subpass_attachment *input_attachments;
2367
struct radv_subpass_attachment *color_attachments;
2368
struct radv_subpass_attachment *resolve_attachments;
2369
struct radv_subpass_attachment *depth_stencil_attachment;
2370
struct radv_subpass_attachment *ds_resolve_attachment;
2371
struct radv_subpass_attachment *vrs_attachment;
2372
VkResolveModeFlagBits depth_resolve_mode;
2373
VkResolveModeFlagBits stencil_resolve_mode;
2374
2375
/** Subpass has at least one color resolve attachment */
2376
bool has_color_resolve;
2377
2378
/** Subpass has at least one color attachment */
2379
bool has_color_att;
2380
2381
struct radv_subpass_barrier start_barrier;
2382
2383
uint32_t view_mask;
2384
2385
VkSampleCountFlagBits color_sample_count;
2386
VkSampleCountFlagBits depth_sample_count;
2387
VkSampleCountFlagBits max_sample_count;
2388
2389
/* Whether the subpass has ingoing/outgoing external dependencies. */
2390
bool has_ingoing_dep;
2391
bool has_outgoing_dep;
2392
};
2393
2394
uint32_t radv_get_subpass_id(struct radv_cmd_buffer *cmd_buffer);
2395
2396
struct radv_render_pass_attachment {
2397
VkFormat format;
2398
uint32_t samples;
2399
VkAttachmentLoadOp load_op;
2400
VkAttachmentLoadOp stencil_load_op;
2401
VkImageLayout initial_layout;
2402
VkImageLayout final_layout;
2403
VkImageLayout stencil_initial_layout;
2404
VkImageLayout stencil_final_layout;
2405
2406
/* The subpass id in which the attachment will be used first/last. */
2407
uint32_t first_subpass_idx;
2408
uint32_t last_subpass_idx;
2409
};
2410
2411
struct radv_render_pass {
2412
struct vk_object_base base;
2413
uint32_t attachment_count;
2414
uint32_t subpass_count;
2415
struct radv_subpass_attachment *subpass_attachments;
2416
struct radv_render_pass_attachment *attachments;
2417
struct radv_subpass_barrier end_barrier;
2418
struct radv_subpass subpasses[0];
2419
};
2420
2421
VkResult radv_device_init_meta(struct radv_device *device);
2422
void radv_device_finish_meta(struct radv_device *device);
2423
2424
struct radv_query_pool {
2425
struct vk_object_base base;
2426
struct radeon_winsys_bo *bo;
2427
uint32_t stride;
2428
uint32_t availability_offset;
2429
uint64_t size;
2430
char *ptr;
2431
VkQueryType type;
2432
uint32_t pipeline_stats_mask;
2433
};
2434
2435
typedef enum {
2436
RADV_SEMAPHORE_NONE,
2437
RADV_SEMAPHORE_SYNCOBJ,
2438
RADV_SEMAPHORE_TIMELINE_SYNCOBJ,
2439
RADV_SEMAPHORE_TIMELINE,
2440
} radv_semaphore_kind;
2441
2442
struct radv_deferred_queue_submission;
2443
2444
struct radv_timeline_waiter {
2445
struct list_head list;
2446
struct radv_deferred_queue_submission *submission;
2447
uint64_t value;
2448
};
2449
2450
struct radv_timeline_point {
2451
struct list_head list;
2452
2453
uint64_t value;
2454
uint32_t syncobj;
2455
2456
/* Separate from the list to accomodate CPU wait being async, as well
2457
* as prevent point deletion during submission. */
2458
unsigned wait_count;
2459
};
2460
2461
struct radv_timeline {
2462
mtx_t mutex;
2463
2464
uint64_t highest_signaled;
2465
uint64_t highest_submitted;
2466
2467
struct list_head points;
2468
2469
/* Keep free points on hand so we do not have to recreate syncobjs all
2470
* the time. */
2471
struct list_head free_points;
2472
2473
/* Submissions that are deferred waiting for a specific value to be
2474
* submitted. */
2475
struct list_head waiters;
2476
};
2477
2478
struct radv_timeline_syncobj {
2479
/* Keep syncobj first, so common-code can just handle this as
2480
* non-timeline syncobj. */
2481
uint32_t syncobj;
2482
uint64_t max_point; /* max submitted point. */
2483
};
2484
2485
struct radv_semaphore_part {
2486
radv_semaphore_kind kind;
2487
union {
2488
uint32_t syncobj;
2489
struct radv_timeline timeline;
2490
struct radv_timeline_syncobj timeline_syncobj;
2491
};
2492
};
2493
2494
struct radv_semaphore {
2495
struct vk_object_base base;
2496
struct radv_semaphore_part permanent;
2497
struct radv_semaphore_part temporary;
2498
};
2499
2500
bool radv_queue_internal_submit(struct radv_queue *queue, struct radeon_cmdbuf *cs);
2501
2502
void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point,
2503
struct radv_descriptor_set *set, unsigned idx);
2504
2505
void radv_update_descriptor_sets(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
2506
VkDescriptorSet overrideSet, uint32_t descriptorWriteCount,
2507
const VkWriteDescriptorSet *pDescriptorWrites,
2508
uint32_t descriptorCopyCount,
2509
const VkCopyDescriptorSet *pDescriptorCopies);
2510
2511
void radv_update_descriptor_set_with_template(struct radv_device *device,
2512
struct radv_cmd_buffer *cmd_buffer,
2513
struct radv_descriptor_set *set,
2514
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
2515
const void *pData);
2516
2517
void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2518
VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout _layout,
2519
uint32_t set, uint32_t descriptorWriteCount,
2520
const VkWriteDescriptorSet *pDescriptorWrites);
2521
2522
uint32_t radv_init_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
2523
const VkImageSubresourceRange *range, uint32_t value);
2524
2525
uint32_t radv_init_fmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
2526
const VkImageSubresourceRange *range);
2527
2528
typedef enum {
2529
RADV_FENCE_NONE,
2530
RADV_FENCE_SYNCOBJ,
2531
} radv_fence_kind;
2532
2533
struct radv_fence_part {
2534
radv_fence_kind kind;
2535
2536
/* DRM syncobj handle for syncobj-based fences. */
2537
uint32_t syncobj;
2538
};
2539
2540
struct radv_fence {
2541
struct vk_object_base base;
2542
struct radv_fence_part permanent;
2543
struct radv_fence_part temporary;
2544
};
2545
2546
/* radv_nir_to_llvm.c */
2547
struct radv_shader_args;
2548
2549
void llvm_compile_shader(struct radv_device *device, unsigned shader_count,
2550
struct nir_shader *const *shaders, struct radv_shader_binary **binary,
2551
struct radv_shader_args *args);
2552
2553
unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class, gl_shader_stage stage,
2554
const struct nir_shader *nir);
2555
2556
/* radv_shader_info.h */
2557
struct radv_shader_info;
2558
struct radv_shader_variant_key;
2559
2560
void radv_nir_shader_info_pass(struct radv_device *device, const struct nir_shader *nir,
2561
const struct radv_pipeline_layout *layout,
2562
const struct radv_shader_variant_key *key,
2563
struct radv_shader_info *info);
2564
2565
void radv_nir_shader_info_init(struct radv_shader_info *info);
2566
2567
bool radv_thread_trace_init(struct radv_device *device);
2568
void radv_thread_trace_finish(struct radv_device *device);
2569
bool radv_begin_thread_trace(struct radv_queue *queue);
2570
bool radv_end_thread_trace(struct radv_queue *queue);
2571
bool radv_get_thread_trace(struct radv_queue *queue, struct ac_thread_trace *thread_trace);
2572
void radv_emit_thread_trace_userdata(const struct radv_device *device, struct radeon_cmdbuf *cs,
2573
const void *data, uint32_t num_dwords);
2574
/* radv_sqtt_layer_.c */
2575
struct radv_barrier_data {
2576
union {
2577
struct {
2578
uint16_t depth_stencil_expand : 1;
2579
uint16_t htile_hiz_range_expand : 1;
2580
uint16_t depth_stencil_resummarize : 1;
2581
uint16_t dcc_decompress : 1;
2582
uint16_t fmask_decompress : 1;
2583
uint16_t fast_clear_eliminate : 1;
2584
uint16_t fmask_color_expand : 1;
2585
uint16_t init_mask_ram : 1;
2586
uint16_t reserved : 8;
2587
};
2588
uint16_t all;
2589
} layout_transitions;
2590
};
2591
2592
/**
2593
* Value for the reason field of an RGP barrier start marker originating from
2594
* the Vulkan client (does not include PAL-defined values). (Table 15)
2595
*/
2596
enum rgp_barrier_reason {
2597
RGP_BARRIER_UNKNOWN_REASON = 0xFFFFFFFF,
2598
2599
/* External app-generated barrier reasons, i.e. API synchronization
2600
* commands Range of valid values: [0x00000001 ... 0x7FFFFFFF].
2601
*/
2602
RGP_BARRIER_EXTERNAL_CMD_PIPELINE_BARRIER = 0x00000001,
2603
RGP_BARRIER_EXTERNAL_RENDER_PASS_SYNC = 0x00000002,
2604
RGP_BARRIER_EXTERNAL_CMD_WAIT_EVENTS = 0x00000003,
2605
2606
/* Internal barrier reasons, i.e. implicit synchronization inserted by
2607
* the Vulkan driver Range of valid values: [0xC0000000 ... 0xFFFFFFFE].
2608
*/
2609
RGP_BARRIER_INTERNAL_BASE = 0xC0000000,
2610
RGP_BARRIER_INTERNAL_PRE_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 0,
2611
RGP_BARRIER_INTERNAL_POST_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 1,
2612
RGP_BARRIER_INTERNAL_GPU_EVENT_RECYCLE_STALL = RGP_BARRIER_INTERNAL_BASE + 2,
2613
RGP_BARRIER_INTERNAL_PRE_COPY_QUERY_POOL_RESULTS_SYNC = RGP_BARRIER_INTERNAL_BASE + 3
2614
};
2615
2616
void radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
2617
void radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
2618
void radv_describe_draw(struct radv_cmd_buffer *cmd_buffer);
2619
void radv_describe_dispatch(struct radv_cmd_buffer *cmd_buffer, int x, int y, int z);
2620
void radv_describe_begin_render_pass_clear(struct radv_cmd_buffer *cmd_buffer,
2621
VkImageAspectFlagBits aspects);
2622
void radv_describe_end_render_pass_clear(struct radv_cmd_buffer *cmd_buffer);
2623
void radv_describe_begin_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);
2624
void radv_describe_end_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);
2625
void radv_describe_barrier_start(struct radv_cmd_buffer *cmd_buffer,
2626
enum rgp_barrier_reason reason);
2627
void radv_describe_barrier_end(struct radv_cmd_buffer *cmd_buffer);
2628
void radv_describe_barrier_end_delayed(struct radv_cmd_buffer *cmd_buffer);
2629
void radv_describe_layout_transition(struct radv_cmd_buffer *cmd_buffer,
2630
const struct radv_barrier_data *barrier);
2631
2632
uint64_t radv_get_current_time(void);
2633
2634
static inline uint32_t
2635
si_conv_gl_prim_to_vertices(unsigned gl_prim)
2636
{
2637
switch (gl_prim) {
2638
case 0: /* GL_POINTS */
2639
return 1;
2640
case 1: /* GL_LINES */
2641
case 3: /* GL_LINE_STRIP */
2642
return 2;
2643
case 4: /* GL_TRIANGLES */
2644
case 5: /* GL_TRIANGLE_STRIP */
2645
return 3;
2646
case 0xA: /* GL_LINE_STRIP_ADJACENCY_ARB */
2647
return 4;
2648
case 0xc: /* GL_TRIANGLES_ADJACENCY_ARB */
2649
return 6;
2650
case 7: /* GL_QUADS */
2651
return V_028A6C_TRISTRIP;
2652
default:
2653
assert(0);
2654
return 0;
2655
}
2656
}
2657
2658
struct radv_extra_render_pass_begin_info {
2659
bool disable_dcc;
2660
};
2661
2662
void radv_cmd_buffer_begin_render_pass(struct radv_cmd_buffer *cmd_buffer,
2663
const VkRenderPassBeginInfo *pRenderPassBegin,
2664
const struct radv_extra_render_pass_begin_info *extra_info);
2665
void radv_cmd_buffer_end_render_pass(struct radv_cmd_buffer *cmd_buffer);
2666
2667
static inline uint32_t
2668
si_translate_prim(unsigned topology)
2669
{
2670
switch (topology) {
2671
case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
2672
return V_008958_DI_PT_POINTLIST;
2673
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
2674
return V_008958_DI_PT_LINELIST;
2675
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
2676
return V_008958_DI_PT_LINESTRIP;
2677
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
2678
return V_008958_DI_PT_TRILIST;
2679
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
2680
return V_008958_DI_PT_TRISTRIP;
2681
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
2682
return V_008958_DI_PT_TRIFAN;
2683
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
2684
return V_008958_DI_PT_LINELIST_ADJ;
2685
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
2686
return V_008958_DI_PT_LINESTRIP_ADJ;
2687
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
2688
return V_008958_DI_PT_TRILIST_ADJ;
2689
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
2690
return V_008958_DI_PT_TRISTRIP_ADJ;
2691
case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
2692
return V_008958_DI_PT_PATCH;
2693
default:
2694
assert(0);
2695
return 0;
2696
}
2697
}
2698
2699
static inline uint32_t
2700
si_translate_stencil_op(enum VkStencilOp op)
2701
{
2702
switch (op) {
2703
case VK_STENCIL_OP_KEEP:
2704
return V_02842C_STENCIL_KEEP;
2705
case VK_STENCIL_OP_ZERO:
2706
return V_02842C_STENCIL_ZERO;
2707
case VK_STENCIL_OP_REPLACE:
2708
return V_02842C_STENCIL_REPLACE_TEST;
2709
case VK_STENCIL_OP_INCREMENT_AND_CLAMP:
2710
return V_02842C_STENCIL_ADD_CLAMP;
2711
case VK_STENCIL_OP_DECREMENT_AND_CLAMP:
2712
return V_02842C_STENCIL_SUB_CLAMP;
2713
case VK_STENCIL_OP_INVERT:
2714
return V_02842C_STENCIL_INVERT;
2715
case VK_STENCIL_OP_INCREMENT_AND_WRAP:
2716
return V_02842C_STENCIL_ADD_WRAP;
2717
case VK_STENCIL_OP_DECREMENT_AND_WRAP:
2718
return V_02842C_STENCIL_SUB_WRAP;
2719
default:
2720
return 0;
2721
}
2722
}
2723
2724
static inline uint32_t
2725
si_translate_blend_logic_op(VkLogicOp op)
2726
{
2727
switch (op) {
2728
case VK_LOGIC_OP_CLEAR:
2729
return V_028808_ROP3_CLEAR;
2730
case VK_LOGIC_OP_AND:
2731
return V_028808_ROP3_AND;
2732
case VK_LOGIC_OP_AND_REVERSE:
2733
return V_028808_ROP3_AND_REVERSE;
2734
case VK_LOGIC_OP_COPY:
2735
return V_028808_ROP3_COPY;
2736
case VK_LOGIC_OP_AND_INVERTED:
2737
return V_028808_ROP3_AND_INVERTED;
2738
case VK_LOGIC_OP_NO_OP:
2739
return V_028808_ROP3_NO_OP;
2740
case VK_LOGIC_OP_XOR:
2741
return V_028808_ROP3_XOR;
2742
case VK_LOGIC_OP_OR:
2743
return V_028808_ROP3_OR;
2744
case VK_LOGIC_OP_NOR:
2745
return V_028808_ROP3_NOR;
2746
case VK_LOGIC_OP_EQUIVALENT:
2747
return V_028808_ROP3_EQUIVALENT;
2748
case VK_LOGIC_OP_INVERT:
2749
return V_028808_ROP3_INVERT;
2750
case VK_LOGIC_OP_OR_REVERSE:
2751
return V_028808_ROP3_OR_REVERSE;
2752
case VK_LOGIC_OP_COPY_INVERTED:
2753
return V_028808_ROP3_COPY_INVERTED;
2754
case VK_LOGIC_OP_OR_INVERTED:
2755
return V_028808_ROP3_OR_INVERTED;
2756
case VK_LOGIC_OP_NAND:
2757
return V_028808_ROP3_NAND;
2758
case VK_LOGIC_OP_SET:
2759
return V_028808_ROP3_SET;
2760
default:
2761
unreachable("Unhandled logic op");
2762
}
2763
}
2764
2765
/**
2766
* Helper used for debugging compiler issues by enabling/disabling LLVM for a
2767
* specific shader stage (developers only).
2768
*/
2769
static inline bool
2770
radv_use_llvm_for_stage(struct radv_device *device, UNUSED gl_shader_stage stage)
2771
{
2772
return device->physical_device->use_llvm;
2773
}
2774
2775
struct radv_acceleration_structure {
2776
struct vk_object_base base;
2777
2778
struct radeon_winsys_bo *bo;
2779
uint64_t mem_offset;
2780
uint64_t size;
2781
};
2782
2783
static inline uint64_t
2784
radv_accel_struct_get_va(const struct radv_acceleration_structure *accel)
2785
{
2786
return radv_buffer_get_va(accel->bo) + accel->mem_offset;
2787
}
2788
2789
#define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
2790
\
2791
static inline struct __radv_type *__radv_type##_from_handle(__VkType _handle) \
2792
{ \
2793
return (struct __radv_type *)_handle; \
2794
} \
2795
\
2796
static inline __VkType __radv_type##_to_handle(struct __radv_type *_obj) \
2797
{ \
2798
return (__VkType)_obj; \
2799
}
2800
2801
#define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
2802
\
2803
static inline struct __radv_type *__radv_type##_from_handle(__VkType _handle) \
2804
{ \
2805
return (struct __radv_type *)(uintptr_t)_handle; \
2806
} \
2807
\
2808
static inline __VkType __radv_type##_to_handle(struct __radv_type *_obj) \
2809
{ \
2810
return (__VkType)(uintptr_t)_obj; \
2811
}
2812
2813
#define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
2814
struct __radv_type *__name = __radv_type##_from_handle(__handle)
2815
2816
RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
2817
RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
2818
RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
2819
RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
2820
RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
2821
2822
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_acceleration_structure, VkAccelerationStructureKHR)
2823
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
2824
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
2825
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
2826
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
2827
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
2828
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
2829
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)
2830
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
2831
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
2832
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
2833
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
2834
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
2835
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
2836
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
2837
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
2838
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
2839
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
2840
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
2841
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
2842
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
2843
RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
2844
2845
#endif /* RADV_PRIVATE_H */
2846
2847