radv: fix using LOAD_CONTEXT_REG with old GFX ME firmwares on GFX8
[mesa.git] / src / amd / vulkan / radv_private.h
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 <stdlib.h>
32 #include <stdio.h>
33 #include <stdbool.h>
34 #include <pthread.h>
35 #include <assert.h>
36 #include <stdint.h>
37 #include <string.h>
38 #ifdef HAVE_VALGRIND
39 #include <valgrind.h>
40 #include <memcheck.h>
41 #define VG(x) x
42 #else
43 #define VG(x)
44 #endif
45
46 #include "c11/threads.h"
47 #include <amdgpu.h>
48 #include "compiler/shader_enums.h"
49 #include "util/macros.h"
50 #include "util/list.h"
51 #include "main/macros.h"
52 #include "vk_alloc.h"
53 #include "vk_debug_report.h"
54
55 #include "radv_radeon_winsys.h"
56 #include "ac_binary.h"
57 #include "ac_nir_to_llvm.h"
58 #include "ac_gpu_info.h"
59 #include "ac_surface.h"
60 #include "ac_llvm_build.h"
61 #include "ac_llvm_util.h"
62 #include "radv_descriptor_set.h"
63 #include "radv_extensions.h"
64 #include "radv_cs.h"
65
66 #include <llvm-c/TargetMachine.h>
67
68 /* Pre-declarations needed for WSI entrypoints */
69 struct wl_surface;
70 struct wl_display;
71 typedef struct xcb_connection_t xcb_connection_t;
72 typedef uint32_t xcb_visualid_t;
73 typedef uint32_t xcb_window_t;
74
75 #include <vulkan/vulkan.h>
76 #include <vulkan/vulkan_intel.h>
77 #include <vulkan/vk_icd.h>
78 #include <vulkan/vk_android_native_buffer.h>
79
80 #include "radv_entrypoints.h"
81
82 #include "wsi_common.h"
83 #include "wsi_common_display.h"
84
85 #define ATI_VENDOR_ID 0x1002
86
87 #define MAX_VBS 32
88 #define MAX_VERTEX_ATTRIBS 32
89 #define MAX_RTS 8
90 #define MAX_VIEWPORTS 16
91 #define MAX_SCISSORS 16
92 #define MAX_DISCARD_RECTANGLES 4
93 #define MAX_PUSH_CONSTANTS_SIZE 128
94 #define MAX_PUSH_DESCRIPTORS 32
95 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
96 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
97 #define MAX_DYNAMIC_BUFFERS (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
98 #define MAX_SAMPLES_LOG2 4
99 #define NUM_META_FS_KEYS 12
100 #define RADV_MAX_DRM_DEVICES 8
101 #define MAX_VIEWS 8
102 #define MAX_SO_STREAMS 4
103 #define MAX_SO_BUFFERS 4
104 #define MAX_SO_OUTPUTS 64
105
106 #define NUM_DEPTH_CLEAR_PIPELINES 3
107
108 /*
109 * This is the point we switch from using CP to compute shader
110 * for certain buffer operations.
111 */
112 #define RADV_BUFFER_OPS_CS_THRESHOLD 4096
113
114 #define RADV_BUFFER_UPDATE_THRESHOLD 1024
115
116 enum radv_mem_heap {
117 RADV_MEM_HEAP_VRAM,
118 RADV_MEM_HEAP_VRAM_CPU_ACCESS,
119 RADV_MEM_HEAP_GTT,
120 RADV_MEM_HEAP_COUNT
121 };
122
123 enum radv_mem_type {
124 RADV_MEM_TYPE_VRAM,
125 RADV_MEM_TYPE_GTT_WRITE_COMBINE,
126 RADV_MEM_TYPE_VRAM_CPU_ACCESS,
127 RADV_MEM_TYPE_GTT_CACHED,
128 RADV_MEM_TYPE_COUNT
129 };
130
131 #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
132
133 static inline uint32_t
134 align_u32(uint32_t v, uint32_t a)
135 {
136 assert(a != 0 && a == (a & -a));
137 return (v + a - 1) & ~(a - 1);
138 }
139
140 static inline uint32_t
141 align_u32_npot(uint32_t v, uint32_t a)
142 {
143 return (v + a - 1) / a * a;
144 }
145
146 static inline uint64_t
147 align_u64(uint64_t v, uint64_t a)
148 {
149 assert(a != 0 && a == (a & -a));
150 return (v + a - 1) & ~(a - 1);
151 }
152
153 static inline int32_t
154 align_i32(int32_t v, int32_t a)
155 {
156 assert(a != 0 && a == (a & -a));
157 return (v + a - 1) & ~(a - 1);
158 }
159
160 /** Alignment must be a power of 2. */
161 static inline bool
162 radv_is_aligned(uintmax_t n, uintmax_t a)
163 {
164 assert(a == (a & -a));
165 return (n & (a - 1)) == 0;
166 }
167
168 static inline uint32_t
169 round_up_u32(uint32_t v, uint32_t a)
170 {
171 return (v + a - 1) / a;
172 }
173
174 static inline uint64_t
175 round_up_u64(uint64_t v, uint64_t a)
176 {
177 return (v + a - 1) / a;
178 }
179
180 static inline uint32_t
181 radv_minify(uint32_t n, uint32_t levels)
182 {
183 if (unlikely(n == 0))
184 return 0;
185 else
186 return MAX2(n >> levels, 1);
187 }
188 static inline float
189 radv_clamp_f(float f, float min, float max)
190 {
191 assert(min < max);
192
193 if (f > max)
194 return max;
195 else if (f < min)
196 return min;
197 else
198 return f;
199 }
200
201 static inline bool
202 radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
203 {
204 if (*inout_mask & clear_mask) {
205 *inout_mask &= ~clear_mask;
206 return true;
207 } else {
208 return false;
209 }
210 }
211
212 #define for_each_bit(b, dword) \
213 for (uint32_t __dword = (dword); \
214 (b) = __builtin_ffs(__dword) - 1, __dword; \
215 __dword &= ~(1 << (b)))
216
217 #define typed_memcpy(dest, src, count) ({ \
218 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
219 memcpy((dest), (src), (count) * sizeof(*(src))); \
220 })
221
222 /* Whenever we generate an error, pass it through this function. Useful for
223 * debugging, where we can break on it. Only call at error site, not when
224 * propagating errors. Might be useful to plug in a stack trace here.
225 */
226
227 struct radv_instance;
228
229 VkResult __vk_errorf(struct radv_instance *instance, VkResult error, const char *file, int line, const char *format, ...);
230
231 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
232 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
233
234 void __radv_finishme(const char *file, int line, const char *format, ...)
235 radv_printflike(3, 4);
236 void radv_loge(const char *format, ...) radv_printflike(1, 2);
237 void radv_loge_v(const char *format, va_list va);
238 void radv_logi(const char *format, ...) radv_printflike(1, 2);
239 void radv_logi_v(const char *format, va_list va);
240
241 /**
242 * Print a FINISHME message, including its source location.
243 */
244 #define radv_finishme(format, ...) \
245 do { \
246 static bool reported = false; \
247 if (!reported) { \
248 __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
249 reported = true; \
250 } \
251 } while (0)
252
253 /* A non-fatal assert. Useful for debugging. */
254 #ifdef DEBUG
255 #define radv_assert(x) ({ \
256 if (unlikely(!(x))) \
257 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
258 })
259 #else
260 #define radv_assert(x)
261 #endif
262
263 #define stub_return(v) \
264 do { \
265 radv_finishme("stub %s", __func__); \
266 return (v); \
267 } while (0)
268
269 #define stub() \
270 do { \
271 radv_finishme("stub %s", __func__); \
272 return; \
273 } while (0)
274
275 void *radv_lookup_entrypoint_unchecked(const char *name);
276 void *radv_lookup_entrypoint_checked(const char *name,
277 uint32_t core_version,
278 const struct radv_instance_extension_table *instance,
279 const struct radv_device_extension_table *device);
280
281 struct radv_physical_device {
282 VK_LOADER_DATA _loader_data;
283
284 struct radv_instance * instance;
285
286 struct radeon_winsys *ws;
287 struct radeon_info rad_info;
288 char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
289 uint8_t driver_uuid[VK_UUID_SIZE];
290 uint8_t device_uuid[VK_UUID_SIZE];
291 uint8_t cache_uuid[VK_UUID_SIZE];
292
293 int local_fd;
294 int master_fd;
295 struct wsi_device wsi_device;
296
297 bool has_rbplus; /* if RB+ register exist */
298 bool rbplus_allowed; /* if RB+ is allowed */
299 bool has_clear_state;
300 bool cpdma_prefetch_writes_memory;
301 bool has_scissor_bug;
302
303 bool has_out_of_order_rast;
304 bool out_of_order_rast_allowed;
305
306 /* Whether DCC should be enabled for MSAA textures. */
307 bool dcc_msaa_allowed;
308
309 /* Whether LOAD_CONTEXT_REG packets are supported. */
310 bool has_load_ctx_reg_pkt;
311
312 /* This is the drivers on-disk cache used as a fallback as opposed to
313 * the pipeline cache defined by apps.
314 */
315 struct disk_cache * disk_cache;
316
317 VkPhysicalDeviceMemoryProperties memory_properties;
318 enum radv_mem_type mem_type_indices[RADV_MEM_TYPE_COUNT];
319
320 drmPciBusInfo bus_info;
321
322 struct radv_device_extension_table supported_extensions;
323 };
324
325 struct radv_instance {
326 VK_LOADER_DATA _loader_data;
327
328 VkAllocationCallbacks alloc;
329
330 uint32_t apiVersion;
331 int physicalDeviceCount;
332 struct radv_physical_device physicalDevices[RADV_MAX_DRM_DEVICES];
333
334 uint64_t debug_flags;
335 uint64_t perftest_flags;
336
337 struct vk_debug_report_instance debug_report_callbacks;
338
339 struct radv_instance_extension_table enabled_extensions;
340 };
341
342 VkResult radv_init_wsi(struct radv_physical_device *physical_device);
343 void radv_finish_wsi(struct radv_physical_device *physical_device);
344
345 bool radv_instance_extension_supported(const char *name);
346 uint32_t radv_physical_device_api_version(struct radv_physical_device *dev);
347 bool radv_physical_device_extension_supported(struct radv_physical_device *dev,
348 const char *name);
349
350 struct cache_entry;
351
352 struct radv_pipeline_cache {
353 struct radv_device * device;
354 pthread_mutex_t mutex;
355
356 uint32_t total_size;
357 uint32_t table_size;
358 uint32_t kernel_count;
359 struct cache_entry ** hash_table;
360 bool modified;
361
362 VkAllocationCallbacks alloc;
363 };
364
365 struct radv_pipeline_key {
366 uint32_t instance_rate_inputs;
367 uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];
368 uint64_t vertex_alpha_adjust;
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 };
378
379 void
380 radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
381 struct radv_device *device);
382 void
383 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
384 bool
385 radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
386 const void *data, size_t size);
387
388 struct radv_shader_variant;
389
390 bool
391 radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
392 struct radv_pipeline_cache *cache,
393 const unsigned char *sha1,
394 struct radv_shader_variant **variants);
395
396 void
397 radv_pipeline_cache_insert_shaders(struct radv_device *device,
398 struct radv_pipeline_cache *cache,
399 const unsigned char *sha1,
400 struct radv_shader_variant **variants,
401 const void *const *codes,
402 const unsigned *code_sizes);
403
404 enum radv_blit_ds_layout {
405 RADV_BLIT_DS_LAYOUT_TILE_ENABLE,
406 RADV_BLIT_DS_LAYOUT_TILE_DISABLE,
407 RADV_BLIT_DS_LAYOUT_COUNT,
408 };
409
410 static inline enum radv_blit_ds_layout radv_meta_blit_ds_to_type(VkImageLayout layout)
411 {
412 return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE : RADV_BLIT_DS_LAYOUT_TILE_ENABLE;
413 }
414
415 static inline VkImageLayout radv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)
416 {
417 return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
418 }
419
420 enum radv_meta_dst_layout {
421 RADV_META_DST_LAYOUT_GENERAL,
422 RADV_META_DST_LAYOUT_OPTIMAL,
423 RADV_META_DST_LAYOUT_COUNT,
424 };
425
426 static inline enum radv_meta_dst_layout radv_meta_dst_layout_from_layout(VkImageLayout layout)
427 {
428 return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL : RADV_META_DST_LAYOUT_OPTIMAL;
429 }
430
431 static inline VkImageLayout radv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)
432 {
433 return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
434 }
435
436 struct radv_meta_state {
437 VkAllocationCallbacks alloc;
438
439 struct radv_pipeline_cache cache;
440
441 /*
442 * For on-demand pipeline creation, makes sure that
443 * only one thread tries to build a pipeline at the same time.
444 */
445 mtx_t mtx;
446
447 /**
448 * Use array element `i` for images with `2^i` samples.
449 */
450 struct {
451 VkRenderPass render_pass[NUM_META_FS_KEYS];
452 VkPipeline color_pipelines[NUM_META_FS_KEYS];
453
454 VkRenderPass depthstencil_rp;
455 VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
456 VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
457 VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
458 } clear[1 + MAX_SAMPLES_LOG2];
459
460 VkPipelineLayout clear_color_p_layout;
461 VkPipelineLayout clear_depth_p_layout;
462
463 /* Optimized compute fast HTILE clear for stencil or depth only. */
464 VkPipeline clear_htile_mask_pipeline;
465 VkPipelineLayout clear_htile_mask_p_layout;
466 VkDescriptorSetLayout clear_htile_mask_ds_layout;
467
468 struct {
469 VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
470
471 /** Pipeline that blits from a 1D image. */
472 VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
473
474 /** Pipeline that blits from a 2D image. */
475 VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
476
477 /** Pipeline that blits from a 3D image. */
478 VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
479
480 VkRenderPass depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
481 VkPipeline depth_only_1d_pipeline;
482 VkPipeline depth_only_2d_pipeline;
483 VkPipeline depth_only_3d_pipeline;
484
485 VkRenderPass stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
486 VkPipeline stencil_only_1d_pipeline;
487 VkPipeline stencil_only_2d_pipeline;
488 VkPipeline stencil_only_3d_pipeline;
489 VkPipelineLayout pipeline_layout;
490 VkDescriptorSetLayout ds_layout;
491 } blit;
492
493 struct {
494 VkPipelineLayout p_layouts[5];
495 VkDescriptorSetLayout ds_layouts[5];
496 VkPipeline pipelines[5][NUM_META_FS_KEYS];
497
498 VkPipeline depth_only_pipeline[5];
499
500 VkPipeline stencil_only_pipeline[5];
501 } blit2d[1 + MAX_SAMPLES_LOG2];
502
503 VkRenderPass blit2d_render_passes[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
504 VkRenderPass blit2d_depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
505 VkRenderPass blit2d_stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
506
507 struct {
508 VkPipelineLayout img_p_layout;
509 VkDescriptorSetLayout img_ds_layout;
510 VkPipeline pipeline;
511 VkPipeline pipeline_3d;
512 } itob;
513 struct {
514 VkPipelineLayout img_p_layout;
515 VkDescriptorSetLayout img_ds_layout;
516 VkPipeline pipeline;
517 VkPipeline pipeline_3d;
518 } btoi;
519 struct {
520 VkPipelineLayout img_p_layout;
521 VkDescriptorSetLayout img_ds_layout;
522 VkPipeline pipeline;
523 } btoi_r32g32b32;
524 struct {
525 VkPipelineLayout img_p_layout;
526 VkDescriptorSetLayout img_ds_layout;
527 VkPipeline pipeline;
528 VkPipeline pipeline_3d;
529 } itoi;
530 struct {
531 VkPipelineLayout img_p_layout;
532 VkDescriptorSetLayout img_ds_layout;
533 VkPipeline pipeline;
534 } itoi_r32g32b32;
535 struct {
536 VkPipelineLayout img_p_layout;
537 VkDescriptorSetLayout img_ds_layout;
538 VkPipeline pipeline;
539 VkPipeline pipeline_3d;
540 } cleari;
541 struct {
542 VkPipelineLayout img_p_layout;
543 VkDescriptorSetLayout img_ds_layout;
544 VkPipeline pipeline;
545 } cleari_r32g32b32;
546
547 struct {
548 VkPipelineLayout p_layout;
549 VkPipeline pipeline[NUM_META_FS_KEYS];
550 VkRenderPass pass[NUM_META_FS_KEYS];
551 } resolve;
552
553 struct {
554 VkDescriptorSetLayout ds_layout;
555 VkPipelineLayout p_layout;
556 struct {
557 VkPipeline pipeline;
558 VkPipeline i_pipeline;
559 VkPipeline srgb_pipeline;
560 } rc[MAX_SAMPLES_LOG2];
561 } resolve_compute;
562
563 struct {
564 VkDescriptorSetLayout ds_layout;
565 VkPipelineLayout p_layout;
566
567 struct {
568 VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
569 VkPipeline pipeline[NUM_META_FS_KEYS];
570 } rc[MAX_SAMPLES_LOG2];
571 } resolve_fragment;
572
573 struct {
574 VkPipelineLayout p_layout;
575 VkPipeline decompress_pipeline;
576 VkPipeline resummarize_pipeline;
577 VkRenderPass pass;
578 } depth_decomp[1 + MAX_SAMPLES_LOG2];
579
580 struct {
581 VkPipelineLayout p_layout;
582 VkPipeline cmask_eliminate_pipeline;
583 VkPipeline fmask_decompress_pipeline;
584 VkPipeline dcc_decompress_pipeline;
585 VkRenderPass pass;
586
587 VkDescriptorSetLayout dcc_decompress_compute_ds_layout;
588 VkPipelineLayout dcc_decompress_compute_p_layout;
589 VkPipeline dcc_decompress_compute_pipeline;
590 } fast_clear_flush;
591
592 struct {
593 VkPipelineLayout fill_p_layout;
594 VkPipelineLayout copy_p_layout;
595 VkDescriptorSetLayout fill_ds_layout;
596 VkDescriptorSetLayout copy_ds_layout;
597 VkPipeline fill_pipeline;
598 VkPipeline copy_pipeline;
599 } buffer;
600
601 struct {
602 VkDescriptorSetLayout ds_layout;
603 VkPipelineLayout p_layout;
604 VkPipeline occlusion_query_pipeline;
605 VkPipeline pipeline_statistics_query_pipeline;
606 VkPipeline tfb_query_pipeline;
607 } query;
608
609 struct {
610 VkDescriptorSetLayout ds_layout;
611 VkPipelineLayout p_layout;
612 VkPipeline pipeline[MAX_SAMPLES_LOG2];
613 } fmask_expand;
614 };
615
616 /* queue types */
617 #define RADV_QUEUE_GENERAL 0
618 #define RADV_QUEUE_COMPUTE 1
619 #define RADV_QUEUE_TRANSFER 2
620
621 #define RADV_MAX_QUEUE_FAMILIES 3
622
623 enum ring_type radv_queue_family_to_ring(int f);
624
625 struct radv_queue {
626 VK_LOADER_DATA _loader_data;
627 struct radv_device * device;
628 struct radeon_winsys_ctx *hw_ctx;
629 enum radeon_ctx_priority priority;
630 uint32_t queue_family_index;
631 int queue_idx;
632 VkDeviceQueueCreateFlags flags;
633
634 uint32_t scratch_size;
635 uint32_t compute_scratch_size;
636 uint32_t esgs_ring_size;
637 uint32_t gsvs_ring_size;
638 bool has_tess_rings;
639 bool has_sample_positions;
640
641 struct radeon_winsys_bo *scratch_bo;
642 struct radeon_winsys_bo *descriptor_bo;
643 struct radeon_winsys_bo *compute_scratch_bo;
644 struct radeon_winsys_bo *esgs_ring_bo;
645 struct radeon_winsys_bo *gsvs_ring_bo;
646 struct radeon_winsys_bo *tess_rings_bo;
647 struct radeon_cmdbuf *initial_preamble_cs;
648 struct radeon_cmdbuf *initial_full_flush_preamble_cs;
649 struct radeon_cmdbuf *continue_preamble_cs;
650 };
651
652 struct radv_bo_list {
653 struct radv_winsys_bo_list list;
654 unsigned capacity;
655 pthread_mutex_t mutex;
656 };
657
658 struct radv_device {
659 VK_LOADER_DATA _loader_data;
660
661 VkAllocationCallbacks alloc;
662
663 struct radv_instance * instance;
664 struct radeon_winsys *ws;
665
666 struct radv_meta_state meta_state;
667
668 struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
669 int queue_count[RADV_MAX_QUEUE_FAMILIES];
670 struct radeon_cmdbuf *empty_cs[RADV_MAX_QUEUE_FAMILIES];
671
672 bool always_use_syncobj;
673 bool has_distributed_tess;
674 bool pbb_allowed;
675 bool dfsm_allowed;
676 uint32_t tess_offchip_block_dw_size;
677 uint32_t scratch_waves;
678 uint32_t dispatch_initiator;
679
680 uint32_t gs_table_depth;
681
682 /* MSAA sample locations.
683 * The first index is the sample index.
684 * The second index is the coordinate: X, Y. */
685 float sample_locations_1x[1][2];
686 float sample_locations_2x[2][2];
687 float sample_locations_4x[4][2];
688 float sample_locations_8x[8][2];
689 float sample_locations_16x[16][2];
690
691 /* CIK and later */
692 uint32_t gfx_init_size_dw;
693 struct radeon_winsys_bo *gfx_init;
694
695 struct radeon_winsys_bo *trace_bo;
696 uint32_t *trace_id_ptr;
697
698 /* Whether to keep shader debug info, for tracing or VK_AMD_shader_info */
699 bool keep_shader_info;
700
701 struct radv_physical_device *physical_device;
702
703 /* Backup in-memory cache to be used if the app doesn't provide one */
704 struct radv_pipeline_cache * mem_cache;
705
706 /*
707 * use different counters so MSAA MRTs get consecutive surface indices,
708 * even if MASK is allocated in between.
709 */
710 uint32_t image_mrt_offset_counter;
711 uint32_t fmask_mrt_offset_counter;
712 struct list_head shader_slabs;
713 mtx_t shader_slab_mutex;
714
715 /* For detecting VM faults reported by dmesg. */
716 uint64_t dmesg_timestamp;
717
718 struct radv_device_extension_table enabled_extensions;
719
720 /* Whether the driver uses a global BO list. */
721 bool use_global_bo_list;
722
723 struct radv_bo_list bo_list;
724
725 /* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */
726 int force_aniso;
727 };
728
729 struct radv_device_memory {
730 struct radeon_winsys_bo *bo;
731 /* for dedicated allocations */
732 struct radv_image *image;
733 struct radv_buffer *buffer;
734 uint32_t type_index;
735 VkDeviceSize map_size;
736 void * map;
737 void * user_ptr;
738 };
739
740
741 struct radv_descriptor_range {
742 uint64_t va;
743 uint32_t size;
744 };
745
746 struct radv_descriptor_set {
747 const struct radv_descriptor_set_layout *layout;
748 uint32_t size;
749
750 struct radeon_winsys_bo *bo;
751 uint64_t va;
752 uint32_t *mapped_ptr;
753 struct radv_descriptor_range *dynamic_descriptors;
754
755 struct radeon_winsys_bo *descriptors[0];
756 };
757
758 struct radv_push_descriptor_set
759 {
760 struct radv_descriptor_set set;
761 uint32_t capacity;
762 };
763
764 struct radv_descriptor_pool_entry {
765 uint32_t offset;
766 uint32_t size;
767 struct radv_descriptor_set *set;
768 };
769
770 struct radv_descriptor_pool {
771 struct radeon_winsys_bo *bo;
772 uint8_t *mapped_ptr;
773 uint64_t current_offset;
774 uint64_t size;
775
776 uint8_t *host_memory_base;
777 uint8_t *host_memory_ptr;
778 uint8_t *host_memory_end;
779
780 uint32_t entry_count;
781 uint32_t max_entry_count;
782 struct radv_descriptor_pool_entry entries[0];
783 };
784
785 struct radv_descriptor_update_template_entry {
786 VkDescriptorType descriptor_type;
787
788 /* The number of descriptors to update */
789 uint32_t descriptor_count;
790
791 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
792 uint32_t dst_offset;
793
794 /* In dwords. Not valid/used for dynamic descriptors */
795 uint32_t dst_stride;
796
797 uint32_t buffer_offset;
798
799 /* Only valid for combined image samplers and samplers */
800 uint16_t has_sampler;
801
802 /* In bytes */
803 size_t src_offset;
804 size_t src_stride;
805
806 /* For push descriptors */
807 const uint32_t *immutable_samplers;
808 };
809
810 struct radv_descriptor_update_template {
811 uint32_t entry_count;
812 VkPipelineBindPoint bind_point;
813 struct radv_descriptor_update_template_entry entry[0];
814 };
815
816 struct radv_buffer {
817 VkDeviceSize size;
818
819 VkBufferUsageFlags usage;
820 VkBufferCreateFlags flags;
821
822 /* Set when bound */
823 struct radeon_winsys_bo * bo;
824 VkDeviceSize offset;
825
826 bool shareable;
827 };
828
829 enum radv_dynamic_state_bits {
830 RADV_DYNAMIC_VIEWPORT = 1 << 0,
831 RADV_DYNAMIC_SCISSOR = 1 << 1,
832 RADV_DYNAMIC_LINE_WIDTH = 1 << 2,
833 RADV_DYNAMIC_DEPTH_BIAS = 1 << 3,
834 RADV_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
835 RADV_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
836 RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
837 RADV_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
838 RADV_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
839 RADV_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
840 RADV_DYNAMIC_ALL = (1 << 10) - 1,
841 };
842
843 enum radv_cmd_dirty_bits {
844 /* Keep the dynamic state dirty bits in sync with
845 * enum radv_dynamic_state_bits */
846 RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0,
847 RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1,
848 RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2,
849 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3,
850 RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
851 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
852 RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
853 RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
854 RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
855 RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
856 RADV_CMD_DIRTY_DYNAMIC_ALL = (1 << 10) - 1,
857 RADV_CMD_DIRTY_PIPELINE = 1 << 10,
858 RADV_CMD_DIRTY_INDEX_BUFFER = 1 << 11,
859 RADV_CMD_DIRTY_FRAMEBUFFER = 1 << 12,
860 RADV_CMD_DIRTY_VERTEX_BUFFER = 1 << 13,
861 RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1 << 14,
862 };
863
864 enum radv_cmd_flush_bits {
865 RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
866 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
867 RADV_CMD_FLAG_INV_SMEM_L1 = 1 << 1,
868 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
869 RADV_CMD_FLAG_INV_VMEM_L1 = 1 << 2,
870 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
871 RADV_CMD_FLAG_INV_GLOBAL_L2 = 1 << 3,
872 /* Same as above, but only writes back and doesn't invalidate */
873 RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2 = 1 << 4,
874 /* Framebuffer caches */
875 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 5,
876 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 6,
877 RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 7,
878 RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 8,
879 /* Engine synchronization. */
880 RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 9,
881 RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 10,
882 RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 11,
883 RADV_CMD_FLAG_VGT_FLUSH = 1 << 12,
884 /* Pipeline query controls. */
885 RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 13,
886 RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 14,
887 RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 15,
888
889 RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER = (RADV_CMD_FLAG_FLUSH_AND_INV_CB |
890 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
891 RADV_CMD_FLAG_FLUSH_AND_INV_DB |
892 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
893 };
894
895 struct radv_vertex_binding {
896 struct radv_buffer * buffer;
897 VkDeviceSize offset;
898 };
899
900 struct radv_streamout_binding {
901 struct radv_buffer *buffer;
902 VkDeviceSize offset;
903 VkDeviceSize size;
904 };
905
906 struct radv_streamout_state {
907 /* Mask of bound streamout buffers. */
908 uint8_t enabled_mask;
909
910 /* External state that comes from the last vertex stage, it must be
911 * set explicitely when binding a new graphics pipeline.
912 */
913 uint16_t stride_in_dw[MAX_SO_BUFFERS];
914 uint32_t enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
915
916 /* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */
917 uint32_t hw_enabled_mask;
918
919 /* State of VGT_STRMOUT_(CONFIG|EN) */
920 bool streamout_enabled;
921 };
922
923 struct radv_viewport_state {
924 uint32_t count;
925 VkViewport viewports[MAX_VIEWPORTS];
926 };
927
928 struct radv_scissor_state {
929 uint32_t count;
930 VkRect2D scissors[MAX_SCISSORS];
931 };
932
933 struct radv_discard_rectangle_state {
934 uint32_t count;
935 VkRect2D rectangles[MAX_DISCARD_RECTANGLES];
936 };
937
938 struct radv_dynamic_state {
939 /**
940 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
941 * Defines the set of saved dynamic state.
942 */
943 uint32_t mask;
944
945 struct radv_viewport_state viewport;
946
947 struct radv_scissor_state scissor;
948
949 float line_width;
950
951 struct {
952 float bias;
953 float clamp;
954 float slope;
955 } depth_bias;
956
957 float blend_constants[4];
958
959 struct {
960 float min;
961 float max;
962 } depth_bounds;
963
964 struct {
965 uint32_t front;
966 uint32_t back;
967 } stencil_compare_mask;
968
969 struct {
970 uint32_t front;
971 uint32_t back;
972 } stencil_write_mask;
973
974 struct {
975 uint32_t front;
976 uint32_t back;
977 } stencil_reference;
978
979 struct radv_discard_rectangle_state discard_rectangle;
980 };
981
982 extern const struct radv_dynamic_state default_dynamic_state;
983
984 const char *
985 radv_get_debug_option_name(int id);
986
987 const char *
988 radv_get_perftest_option_name(int id);
989
990 /**
991 * Attachment state when recording a renderpass instance.
992 *
993 * The clear value is valid only if there exists a pending clear.
994 */
995 struct radv_attachment_state {
996 VkImageAspectFlags pending_clear_aspects;
997 uint32_t cleared_views;
998 VkClearValue clear_value;
999 VkImageLayout current_layout;
1000 };
1001
1002 struct radv_descriptor_state {
1003 struct radv_descriptor_set *sets[MAX_SETS];
1004 uint32_t dirty;
1005 uint32_t valid;
1006 struct radv_push_descriptor_set push_set;
1007 bool push_dirty;
1008 uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
1009 };
1010
1011 struct radv_cmd_state {
1012 /* Vertex descriptors */
1013 uint64_t vb_va;
1014 unsigned vb_size;
1015
1016 bool predicating;
1017 uint32_t dirty;
1018
1019 uint32_t prefetch_L2_mask;
1020
1021 struct radv_pipeline * pipeline;
1022 struct radv_pipeline * emitted_pipeline;
1023 struct radv_pipeline * compute_pipeline;
1024 struct radv_pipeline * emitted_compute_pipeline;
1025 struct radv_framebuffer * framebuffer;
1026 struct radv_render_pass * pass;
1027 const struct radv_subpass * subpass;
1028 struct radv_dynamic_state dynamic;
1029 struct radv_attachment_state * attachments;
1030 struct radv_streamout_state streamout;
1031 VkRect2D render_area;
1032
1033 /* Index buffer */
1034 struct radv_buffer *index_buffer;
1035 uint64_t index_offset;
1036 uint32_t index_type;
1037 uint32_t max_index_count;
1038 uint64_t index_va;
1039 int32_t last_index_type;
1040
1041 int32_t last_primitive_reset_en;
1042 uint32_t last_primitive_reset_index;
1043 enum radv_cmd_flush_bits flush_bits;
1044 unsigned active_occlusion_queries;
1045 bool perfect_occlusion_queries_enabled;
1046 unsigned active_pipeline_queries;
1047 float offset_scale;
1048 uint32_t trace_id;
1049 uint32_t last_ia_multi_vgt_param;
1050
1051 uint32_t last_num_instances;
1052 uint32_t last_first_instance;
1053 uint32_t last_vertex_offset;
1054
1055 /* Whether CP DMA is busy/idle. */
1056 bool dma_is_busy;
1057
1058 /* Conditional rendering info. */
1059 int predication_type; /* -1: disabled, 0: normal, 1: inverted */
1060 uint64_t predication_va;
1061
1062 bool context_roll_without_scissor_emitted;
1063 };
1064
1065 struct radv_cmd_pool {
1066 VkAllocationCallbacks alloc;
1067 struct list_head cmd_buffers;
1068 struct list_head free_cmd_buffers;
1069 uint32_t queue_family_index;
1070 };
1071
1072 struct radv_cmd_buffer_upload {
1073 uint8_t *map;
1074 unsigned offset;
1075 uint64_t size;
1076 struct radeon_winsys_bo *upload_bo;
1077 struct list_head list;
1078 };
1079
1080 enum radv_cmd_buffer_status {
1081 RADV_CMD_BUFFER_STATUS_INVALID,
1082 RADV_CMD_BUFFER_STATUS_INITIAL,
1083 RADV_CMD_BUFFER_STATUS_RECORDING,
1084 RADV_CMD_BUFFER_STATUS_EXECUTABLE,
1085 RADV_CMD_BUFFER_STATUS_PENDING,
1086 };
1087
1088 struct radv_cmd_buffer {
1089 VK_LOADER_DATA _loader_data;
1090
1091 struct radv_device * device;
1092
1093 struct radv_cmd_pool * pool;
1094 struct list_head pool_link;
1095
1096 VkCommandBufferUsageFlags usage_flags;
1097 VkCommandBufferLevel level;
1098 enum radv_cmd_buffer_status status;
1099 struct radeon_cmdbuf *cs;
1100 struct radv_cmd_state state;
1101 struct radv_vertex_binding vertex_bindings[MAX_VBS];
1102 struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
1103 uint32_t queue_family_index;
1104
1105 uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
1106 VkShaderStageFlags push_constant_stages;
1107 struct radv_descriptor_set meta_push_descriptors;
1108
1109 struct radv_descriptor_state descriptors[VK_PIPELINE_BIND_POINT_RANGE_SIZE];
1110
1111 struct radv_cmd_buffer_upload upload;
1112
1113 uint32_t scratch_size_needed;
1114 uint32_t compute_scratch_size_needed;
1115 uint32_t esgs_ring_size_needed;
1116 uint32_t gsvs_ring_size_needed;
1117 bool tess_rings_needed;
1118 bool sample_positions_needed;
1119
1120 VkResult record_result;
1121
1122 uint64_t gfx9_fence_va;
1123 uint32_t gfx9_fence_idx;
1124 uint64_t gfx9_eop_bug_va;
1125
1126 /**
1127 * Whether a query pool has been resetted and we have to flush caches.
1128 */
1129 bool pending_reset_query;
1130 };
1131
1132 struct radv_image;
1133
1134 bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
1135
1136 void si_emit_graphics(struct radv_physical_device *physical_device,
1137 struct radeon_cmdbuf *cs);
1138 void si_emit_compute(struct radv_physical_device *physical_device,
1139 struct radeon_cmdbuf *cs);
1140
1141 void cik_create_gfx_config(struct radv_device *device);
1142
1143 void si_write_viewport(struct radeon_cmdbuf *cs, int first_vp,
1144 int count, const VkViewport *viewports);
1145 void si_write_scissors(struct radeon_cmdbuf *cs, int first,
1146 int count, const VkRect2D *scissors,
1147 const VkViewport *viewports, bool can_use_guardband);
1148 uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer,
1149 bool instanced_draw, bool indirect_draw,
1150 uint32_t draw_vertex_count);
1151 void si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs,
1152 enum chip_class chip_class,
1153 bool is_mec,
1154 unsigned event, unsigned event_flags,
1155 unsigned data_sel,
1156 uint64_t va,
1157 uint32_t new_fence,
1158 uint64_t gfx9_eop_bug_va);
1159
1160 void radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va,
1161 uint32_t ref, uint32_t mask);
1162 void si_cs_emit_cache_flush(struct radeon_cmdbuf *cs,
1163 enum chip_class chip_class,
1164 uint32_t *fence_ptr, uint64_t va,
1165 bool is_mec,
1166 enum radv_cmd_flush_bits flush_bits,
1167 uint64_t gfx9_eop_bug_va);
1168 void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
1169 void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer,
1170 bool inverted, uint64_t va);
1171 void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer,
1172 uint64_t src_va, uint64_t dest_va,
1173 uint64_t size);
1174 void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
1175 unsigned size);
1176 void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
1177 uint64_t size, unsigned value);
1178 void si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);
1179
1180 void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
1181 bool
1182 radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer,
1183 unsigned size,
1184 unsigned alignment,
1185 unsigned *out_offset,
1186 void **ptr);
1187 void
1188 radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
1189 const struct radv_subpass *subpass);
1190 bool
1191 radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer,
1192 unsigned size, unsigned alignmnet,
1193 const void *data, unsigned *out_offset);
1194
1195 void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
1196 void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
1197 void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
1198 void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
1199 void radv_cayman_emit_msaa_sample_locs(struct radeon_cmdbuf *cs, int nr_samples);
1200 unsigned radv_cayman_get_maxdist(int log_samples);
1201 void radv_device_init_msaa(struct radv_device *device);
1202
1203 void radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1204 struct radv_image *image,
1205 VkClearDepthStencilValue ds_clear_value,
1206 VkImageAspectFlags aspects);
1207
1208 void radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1209 struct radv_image *image,
1210 int cb_idx,
1211 uint32_t color_values[2]);
1212
1213 void radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer,
1214 struct radv_image *image, bool value);
1215
1216 void radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer,
1217 struct radv_image *image, bool value);
1218
1219 uint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
1220 struct radeon_winsys_bo *bo,
1221 uint64_t offset, uint64_t size, uint32_t value);
1222 void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
1223 bool radv_get_memory_fd(struct radv_device *device,
1224 struct radv_device_memory *memory,
1225 int *pFD);
1226
1227 static inline void
1228 radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs,
1229 unsigned sh_offset, unsigned pointer_count,
1230 bool use_32bit_pointers)
1231 {
1232 radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));
1233 radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);
1234 }
1235
1236 static inline void
1237 radv_emit_shader_pointer_body(struct radv_device *device,
1238 struct radeon_cmdbuf *cs,
1239 uint64_t va, bool use_32bit_pointers)
1240 {
1241 radeon_emit(cs, va);
1242
1243 if (use_32bit_pointers) {
1244 assert(va == 0 ||
1245 (va >> 32) == device->physical_device->rad_info.address32_hi);
1246 } else {
1247 radeon_emit(cs, va >> 32);
1248 }
1249 }
1250
1251 static inline void
1252 radv_emit_shader_pointer(struct radv_device *device,
1253 struct radeon_cmdbuf *cs,
1254 uint32_t sh_offset, uint64_t va, bool global)
1255 {
1256 bool use_32bit_pointers = !global;
1257
1258 radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);
1259 radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);
1260 }
1261
1262 static inline struct radv_descriptor_state *
1263 radv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer,
1264 VkPipelineBindPoint bind_point)
1265 {
1266 assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS ||
1267 bind_point == VK_PIPELINE_BIND_POINT_COMPUTE);
1268 return &cmd_buffer->descriptors[bind_point];
1269 }
1270
1271 /*
1272 * Takes x,y,z as exact numbers of invocations, instead of blocks.
1273 *
1274 * Limitations: Can't call normal dispatch functions without binding or rebinding
1275 * the compute pipeline.
1276 */
1277 void radv_unaligned_dispatch(
1278 struct radv_cmd_buffer *cmd_buffer,
1279 uint32_t x,
1280 uint32_t y,
1281 uint32_t z);
1282
1283 struct radv_event {
1284 struct radeon_winsys_bo *bo;
1285 uint64_t *map;
1286 };
1287
1288 struct radv_shader_module;
1289
1290 #define RADV_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
1291 #define RADV_HASH_SHADER_SISCHED (1 << 1)
1292 #define RADV_HASH_SHADER_UNSAFE_MATH (1 << 2)
1293 void
1294 radv_hash_shaders(unsigned char *hash,
1295 const VkPipelineShaderStageCreateInfo **stages,
1296 const struct radv_pipeline_layout *layout,
1297 const struct radv_pipeline_key *key,
1298 uint32_t flags);
1299
1300 static inline gl_shader_stage
1301 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1302 {
1303 assert(__builtin_popcount(vk_stage) == 1);
1304 return ffs(vk_stage) - 1;
1305 }
1306
1307 static inline VkShaderStageFlagBits
1308 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1309 {
1310 return (1 << mesa_stage);
1311 }
1312
1313 #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1314
1315 #define radv_foreach_stage(stage, stage_bits) \
1316 for (gl_shader_stage stage, \
1317 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
1318 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1319 __tmp &= ~(1 << (stage)))
1320
1321 extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
1322 unsigned radv_format_meta_fs_key(VkFormat format);
1323
1324 struct radv_multisample_state {
1325 uint32_t db_eqaa;
1326 uint32_t pa_sc_line_cntl;
1327 uint32_t pa_sc_mode_cntl_0;
1328 uint32_t pa_sc_mode_cntl_1;
1329 uint32_t pa_sc_aa_config;
1330 uint32_t pa_sc_aa_mask[2];
1331 unsigned num_samples;
1332 };
1333
1334 struct radv_prim_vertex_count {
1335 uint8_t min;
1336 uint8_t incr;
1337 };
1338
1339 struct radv_vertex_elements_info {
1340 uint32_t rsrc_word3[MAX_VERTEX_ATTRIBS];
1341 uint32_t format_size[MAX_VERTEX_ATTRIBS];
1342 uint32_t binding[MAX_VERTEX_ATTRIBS];
1343 uint32_t offset[MAX_VERTEX_ATTRIBS];
1344 uint32_t count;
1345 };
1346
1347 struct radv_ia_multi_vgt_param_helpers {
1348 uint32_t base;
1349 bool partial_es_wave;
1350 uint8_t primgroup_size;
1351 bool wd_switch_on_eop;
1352 bool ia_switch_on_eoi;
1353 bool partial_vs_wave;
1354 };
1355
1356 #define SI_GS_PER_ES 128
1357
1358 struct radv_pipeline {
1359 struct radv_device * device;
1360 struct radv_dynamic_state dynamic_state;
1361
1362 struct radv_pipeline_layout * layout;
1363
1364 bool need_indirect_descriptor_sets;
1365 struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
1366 struct radv_shader_variant *gs_copy_shader;
1367 VkShaderStageFlags active_stages;
1368
1369 struct radeon_cmdbuf cs;
1370 uint32_t ctx_cs_hash;
1371 struct radeon_cmdbuf ctx_cs;
1372
1373 struct radv_vertex_elements_info vertex_elements;
1374
1375 uint32_t binding_stride[MAX_VBS];
1376
1377 uint32_t user_data_0[MESA_SHADER_STAGES];
1378 union {
1379 struct {
1380 struct radv_multisample_state ms;
1381 uint32_t spi_baryc_cntl;
1382 bool prim_restart_enable;
1383 unsigned esgs_ring_size;
1384 unsigned gsvs_ring_size;
1385 uint32_t vtx_base_sgpr;
1386 struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
1387 uint8_t vtx_emit_num;
1388 struct radv_prim_vertex_count prim_vertex_count;
1389 bool can_use_guardband;
1390 uint32_t needed_dynamic_state;
1391 bool disable_out_of_order_rast_for_occlusion;
1392
1393 /* Used for rbplus */
1394 uint32_t col_format;
1395 uint32_t cb_target_mask;
1396 } graphics;
1397 };
1398
1399 unsigned max_waves;
1400 unsigned scratch_bytes_per_wave;
1401
1402 /* Not NULL if graphics pipeline uses streamout. */
1403 struct radv_shader_variant *streamout_shader;
1404 };
1405
1406 static inline bool radv_pipeline_has_gs(const struct radv_pipeline *pipeline)
1407 {
1408 return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1409 }
1410
1411 static inline bool radv_pipeline_has_tess(const struct radv_pipeline *pipeline)
1412 {
1413 return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;
1414 }
1415
1416 struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
1417 gl_shader_stage stage,
1418 int idx);
1419
1420 struct radv_shader_variant *radv_get_shader(struct radv_pipeline *pipeline,
1421 gl_shader_stage stage);
1422
1423 struct radv_graphics_pipeline_create_info {
1424 bool use_rectlist;
1425 bool db_depth_clear;
1426 bool db_stencil_clear;
1427 bool db_depth_disable_expclear;
1428 bool db_stencil_disable_expclear;
1429 bool db_flush_depth_inplace;
1430 bool db_flush_stencil_inplace;
1431 bool db_resummarize;
1432 uint32_t custom_blend_mode;
1433 };
1434
1435 VkResult
1436 radv_graphics_pipeline_create(VkDevice device,
1437 VkPipelineCache cache,
1438 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1439 const struct radv_graphics_pipeline_create_info *extra,
1440 const VkAllocationCallbacks *alloc,
1441 VkPipeline *pPipeline);
1442
1443 struct vk_format_description;
1444 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
1445 int first_non_void);
1446 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
1447 int first_non_void);
1448 uint32_t radv_translate_colorformat(VkFormat format);
1449 uint32_t radv_translate_color_numformat(VkFormat format,
1450 const struct vk_format_description *desc,
1451 int first_non_void);
1452 uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1453 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1454 uint32_t radv_translate_dbformat(VkFormat format);
1455 uint32_t radv_translate_tex_dataformat(VkFormat format,
1456 const struct vk_format_description *desc,
1457 int first_non_void);
1458 uint32_t radv_translate_tex_numformat(VkFormat format,
1459 const struct vk_format_description *desc,
1460 int first_non_void);
1461 bool radv_format_pack_clear_color(VkFormat format,
1462 uint32_t clear_vals[2],
1463 VkClearColorValue *value);
1464 bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
1465 bool radv_dcc_formats_compatible(VkFormat format1,
1466 VkFormat format2);
1467
1468 struct radv_fmask_info {
1469 uint64_t offset;
1470 uint64_t size;
1471 unsigned alignment;
1472 unsigned pitch_in_pixels;
1473 unsigned bank_height;
1474 unsigned slice_tile_max;
1475 unsigned tile_mode_index;
1476 unsigned tile_swizzle;
1477 };
1478
1479 struct radv_cmask_info {
1480 uint64_t offset;
1481 uint64_t size;
1482 unsigned alignment;
1483 unsigned slice_tile_max;
1484 };
1485
1486 struct radv_image {
1487 VkImageType type;
1488 /* The original VkFormat provided by the client. This may not match any
1489 * of the actual surface formats.
1490 */
1491 VkFormat vk_format;
1492 VkImageAspectFlags aspects;
1493 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1494 struct ac_surf_info info;
1495 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1496 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1497
1498 VkDeviceSize size;
1499 uint32_t alignment;
1500
1501 unsigned queue_family_mask;
1502 bool exclusive;
1503 bool shareable;
1504
1505 /* Set when bound */
1506 struct radeon_winsys_bo *bo;
1507 VkDeviceSize offset;
1508 uint64_t dcc_offset;
1509 uint64_t htile_offset;
1510 bool tc_compatible_htile;
1511 struct radeon_surf surface;
1512
1513 struct radv_fmask_info fmask;
1514 struct radv_cmask_info cmask;
1515 uint64_t clear_value_offset;
1516 uint64_t fce_pred_offset;
1517 uint64_t dcc_pred_offset;
1518
1519 /*
1520 * Metadata for the TC-compat zrange workaround. If the 32-bit value
1521 * stored at this offset is UINT_MAX, the driver will emit
1522 * DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
1523 * SET_CONTEXT_REG packet.
1524 */
1525 uint64_t tc_compat_zrange_offset;
1526
1527 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1528 VkDeviceMemory owned_memory;
1529 };
1530
1531 /* Whether the image has a htile that is known consistent with the contents of
1532 * the image. */
1533 bool radv_layout_has_htile(const struct radv_image *image,
1534 VkImageLayout layout,
1535 unsigned queue_mask);
1536
1537 /* Whether the image has a htile that is known consistent with the contents of
1538 * the image and is allowed to be in compressed form.
1539 *
1540 * If this is false reads that don't use the htile should be able to return
1541 * correct results.
1542 */
1543 bool radv_layout_is_htile_compressed(const struct radv_image *image,
1544 VkImageLayout layout,
1545 unsigned queue_mask);
1546
1547 bool radv_layout_can_fast_clear(const struct radv_image *image,
1548 VkImageLayout layout,
1549 unsigned queue_mask);
1550
1551 bool radv_layout_dcc_compressed(const struct radv_image *image,
1552 VkImageLayout layout,
1553 unsigned queue_mask);
1554
1555 /**
1556 * Return whether the image has CMASK metadata for color surfaces.
1557 */
1558 static inline bool
1559 radv_image_has_cmask(const struct radv_image *image)
1560 {
1561 return image->cmask.size;
1562 }
1563
1564 /**
1565 * Return whether the image has FMASK metadata for color surfaces.
1566 */
1567 static inline bool
1568 radv_image_has_fmask(const struct radv_image *image)
1569 {
1570 return image->fmask.size;
1571 }
1572
1573 /**
1574 * Return whether the image has DCC metadata for color surfaces.
1575 */
1576 static inline bool
1577 radv_image_has_dcc(const struct radv_image *image)
1578 {
1579 return image->surface.dcc_size;
1580 }
1581
1582 /**
1583 * Return whether DCC metadata is enabled for a level.
1584 */
1585 static inline bool
1586 radv_dcc_enabled(const struct radv_image *image, unsigned level)
1587 {
1588 return radv_image_has_dcc(image) &&
1589 level < image->surface.num_dcc_levels;
1590 }
1591
1592 /**
1593 * Return whether the image has CB metadata.
1594 */
1595 static inline bool
1596 radv_image_has_CB_metadata(const struct radv_image *image)
1597 {
1598 return radv_image_has_cmask(image) ||
1599 radv_image_has_fmask(image) ||
1600 radv_image_has_dcc(image);
1601 }
1602
1603 /**
1604 * Return whether the image has HTILE metadata for depth surfaces.
1605 */
1606 static inline bool
1607 radv_image_has_htile(const struct radv_image *image)
1608 {
1609 return image->surface.htile_size;
1610 }
1611
1612 /**
1613 * Return whether HTILE metadata is enabled for a level.
1614 */
1615 static inline bool
1616 radv_htile_enabled(const struct radv_image *image, unsigned level)
1617 {
1618 return radv_image_has_htile(image) && level == 0;
1619 }
1620
1621 /**
1622 * Return whether the image is TC-compatible HTILE.
1623 */
1624 static inline bool
1625 radv_image_is_tc_compat_htile(const struct radv_image *image)
1626 {
1627 return radv_image_has_htile(image) && image->tc_compatible_htile;
1628 }
1629
1630 unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
1631
1632 static inline uint32_t
1633 radv_get_layerCount(const struct radv_image *image,
1634 const VkImageSubresourceRange *range)
1635 {
1636 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1637 image->info.array_size - range->baseArrayLayer : range->layerCount;
1638 }
1639
1640 static inline uint32_t
1641 radv_get_levelCount(const struct radv_image *image,
1642 const VkImageSubresourceRange *range)
1643 {
1644 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1645 image->info.levels - range->baseMipLevel : range->levelCount;
1646 }
1647
1648 struct radeon_bo_metadata;
1649 void
1650 radv_init_metadata(struct radv_device *device,
1651 struct radv_image *image,
1652 struct radeon_bo_metadata *metadata);
1653
1654 struct radv_image_view {
1655 struct radv_image *image; /**< VkImageViewCreateInfo::image */
1656 struct radeon_winsys_bo *bo;
1657
1658 VkImageViewType type;
1659 VkImageAspectFlags aspect_mask;
1660 VkFormat vk_format;
1661 uint32_t base_layer;
1662 uint32_t layer_count;
1663 uint32_t base_mip;
1664 uint32_t level_count;
1665 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1666
1667 uint32_t descriptor[16];
1668
1669 /* Descriptor for use as a storage image as opposed to a sampled image.
1670 * This has a few differences for cube maps (e.g. type).
1671 */
1672 uint32_t storage_descriptor[16];
1673 };
1674
1675 struct radv_image_create_info {
1676 const VkImageCreateInfo *vk_info;
1677 bool scanout;
1678 bool no_metadata_planes;
1679 };
1680
1681 VkResult radv_image_create(VkDevice _device,
1682 const struct radv_image_create_info *info,
1683 const VkAllocationCallbacks* alloc,
1684 VkImage *pImage);
1685
1686 VkResult
1687 radv_image_from_gralloc(VkDevice device_h,
1688 const VkImageCreateInfo *base_info,
1689 const VkNativeBufferANDROID *gralloc_info,
1690 const VkAllocationCallbacks *alloc,
1691 VkImage *out_image_h);
1692
1693 void radv_image_view_init(struct radv_image_view *view,
1694 struct radv_device *device,
1695 const VkImageViewCreateInfo* pCreateInfo);
1696
1697 struct radv_buffer_view {
1698 struct radeon_winsys_bo *bo;
1699 VkFormat vk_format;
1700 uint64_t range; /**< VkBufferViewCreateInfo::range */
1701 uint32_t state[4];
1702 };
1703 void radv_buffer_view_init(struct radv_buffer_view *view,
1704 struct radv_device *device,
1705 const VkBufferViewCreateInfo* pCreateInfo);
1706
1707 static inline struct VkExtent3D
1708 radv_sanitize_image_extent(const VkImageType imageType,
1709 const struct VkExtent3D imageExtent)
1710 {
1711 switch (imageType) {
1712 case VK_IMAGE_TYPE_1D:
1713 return (VkExtent3D) { imageExtent.width, 1, 1 };
1714 case VK_IMAGE_TYPE_2D:
1715 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1716 case VK_IMAGE_TYPE_3D:
1717 return imageExtent;
1718 default:
1719 unreachable("invalid image type");
1720 }
1721 }
1722
1723 static inline struct VkOffset3D
1724 radv_sanitize_image_offset(const VkImageType imageType,
1725 const struct VkOffset3D imageOffset)
1726 {
1727 switch (imageType) {
1728 case VK_IMAGE_TYPE_1D:
1729 return (VkOffset3D) { imageOffset.x, 0, 0 };
1730 case VK_IMAGE_TYPE_2D:
1731 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1732 case VK_IMAGE_TYPE_3D:
1733 return imageOffset;
1734 default:
1735 unreachable("invalid image type");
1736 }
1737 }
1738
1739 static inline bool
1740 radv_image_extent_compare(const struct radv_image *image,
1741 const VkExtent3D *extent)
1742 {
1743 if (extent->width != image->info.width ||
1744 extent->height != image->info.height ||
1745 extent->depth != image->info.depth)
1746 return false;
1747 return true;
1748 }
1749
1750 struct radv_sampler {
1751 uint32_t state[4];
1752 };
1753
1754 struct radv_color_buffer_info {
1755 uint64_t cb_color_base;
1756 uint64_t cb_color_cmask;
1757 uint64_t cb_color_fmask;
1758 uint64_t cb_dcc_base;
1759 uint32_t cb_color_pitch;
1760 uint32_t cb_color_slice;
1761 uint32_t cb_color_view;
1762 uint32_t cb_color_info;
1763 uint32_t cb_color_attrib;
1764 uint32_t cb_color_attrib2;
1765 uint32_t cb_dcc_control;
1766 uint32_t cb_color_cmask_slice;
1767 uint32_t cb_color_fmask_slice;
1768 };
1769
1770 struct radv_ds_buffer_info {
1771 uint64_t db_z_read_base;
1772 uint64_t db_stencil_read_base;
1773 uint64_t db_z_write_base;
1774 uint64_t db_stencil_write_base;
1775 uint64_t db_htile_data_base;
1776 uint32_t db_depth_info;
1777 uint32_t db_z_info;
1778 uint32_t db_stencil_info;
1779 uint32_t db_depth_view;
1780 uint32_t db_depth_size;
1781 uint32_t db_depth_slice;
1782 uint32_t db_htile_surface;
1783 uint32_t pa_su_poly_offset_db_fmt_cntl;
1784 uint32_t db_z_info2;
1785 uint32_t db_stencil_info2;
1786 float offset_scale;
1787 };
1788
1789 struct radv_attachment_info {
1790 union {
1791 struct radv_color_buffer_info cb;
1792 struct radv_ds_buffer_info ds;
1793 };
1794 struct radv_image_view *attachment;
1795 };
1796
1797 struct radv_framebuffer {
1798 uint32_t width;
1799 uint32_t height;
1800 uint32_t layers;
1801
1802 uint32_t attachment_count;
1803 struct radv_attachment_info attachments[0];
1804 };
1805
1806 struct radv_subpass_barrier {
1807 VkPipelineStageFlags src_stage_mask;
1808 VkAccessFlags src_access_mask;
1809 VkAccessFlags dst_access_mask;
1810 };
1811
1812 void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
1813 const struct radv_subpass_barrier *barrier);
1814
1815 struct radv_subpass_attachment {
1816 uint32_t attachment;
1817 VkImageLayout layout;
1818 };
1819
1820 struct radv_subpass {
1821 uint32_t attachment_count;
1822 struct radv_subpass_attachment * attachments;
1823
1824 uint32_t input_count;
1825 uint32_t color_count;
1826 struct radv_subpass_attachment * input_attachments;
1827 struct radv_subpass_attachment * color_attachments;
1828 struct radv_subpass_attachment * resolve_attachments;
1829 struct radv_subpass_attachment * depth_stencil_attachment;
1830
1831 /** Subpass has at least one resolve attachment */
1832 bool has_resolve;
1833
1834 /** Subpass has at least one color attachment */
1835 bool has_color_att;
1836
1837 struct radv_subpass_barrier start_barrier;
1838
1839 uint32_t view_mask;
1840 VkSampleCountFlagBits max_sample_count;
1841 };
1842
1843 struct radv_render_pass_attachment {
1844 VkFormat format;
1845 uint32_t samples;
1846 VkAttachmentLoadOp load_op;
1847 VkAttachmentLoadOp stencil_load_op;
1848 VkImageLayout initial_layout;
1849 VkImageLayout final_layout;
1850
1851 /* The subpass id in which the attachment will be used last. */
1852 uint32_t last_subpass_idx;
1853 };
1854
1855 struct radv_render_pass {
1856 uint32_t attachment_count;
1857 uint32_t subpass_count;
1858 struct radv_subpass_attachment * subpass_attachments;
1859 struct radv_render_pass_attachment * attachments;
1860 struct radv_subpass_barrier end_barrier;
1861 struct radv_subpass subpasses[0];
1862 };
1863
1864 VkResult radv_device_init_meta(struct radv_device *device);
1865 void radv_device_finish_meta(struct radv_device *device);
1866
1867 struct radv_query_pool {
1868 struct radeon_winsys_bo *bo;
1869 uint32_t stride;
1870 uint32_t availability_offset;
1871 uint64_t size;
1872 char *ptr;
1873 VkQueryType type;
1874 uint32_t pipeline_stats_mask;
1875 };
1876
1877 struct radv_semaphore {
1878 /* use a winsys sem for non-exportable */
1879 struct radeon_winsys_sem *sem;
1880 uint32_t syncobj;
1881 uint32_t temp_syncobj;
1882 };
1883
1884 void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
1885 VkPipelineBindPoint bind_point,
1886 struct radv_descriptor_set *set,
1887 unsigned idx);
1888
1889 void
1890 radv_update_descriptor_sets(struct radv_device *device,
1891 struct radv_cmd_buffer *cmd_buffer,
1892 VkDescriptorSet overrideSet,
1893 uint32_t descriptorWriteCount,
1894 const VkWriteDescriptorSet *pDescriptorWrites,
1895 uint32_t descriptorCopyCount,
1896 const VkCopyDescriptorSet *pDescriptorCopies);
1897
1898 void
1899 radv_update_descriptor_set_with_template(struct radv_device *device,
1900 struct radv_cmd_buffer *cmd_buffer,
1901 struct radv_descriptor_set *set,
1902 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1903 const void *pData);
1904
1905 void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
1906 VkPipelineBindPoint pipelineBindPoint,
1907 VkPipelineLayout _layout,
1908 uint32_t set,
1909 uint32_t descriptorWriteCount,
1910 const VkWriteDescriptorSet *pDescriptorWrites);
1911
1912 void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
1913 struct radv_image *image, uint32_t value);
1914
1915 void radv_initialize_fmask(struct radv_cmd_buffer *cmd_buffer,
1916 struct radv_image *image);
1917
1918 struct radv_fence {
1919 struct radeon_winsys_fence *fence;
1920 struct wsi_fence *fence_wsi;
1921 bool submitted;
1922 bool signalled;
1923
1924 uint32_t syncobj;
1925 uint32_t temp_syncobj;
1926 };
1927
1928 /* radv_nir_to_llvm.c */
1929 struct radv_shader_variant_info;
1930 struct radv_nir_compiler_options;
1931
1932 void radv_compile_gs_copy_shader(struct ac_llvm_compiler *ac_llvm,
1933 struct nir_shader *geom_shader,
1934 struct ac_shader_binary *binary,
1935 struct ac_shader_config *config,
1936 struct radv_shader_variant_info *shader_info,
1937 const struct radv_nir_compiler_options *option);
1938
1939 void radv_compile_nir_shader(struct ac_llvm_compiler *ac_llvm,
1940 struct ac_shader_binary *binary,
1941 struct ac_shader_config *config,
1942 struct radv_shader_variant_info *shader_info,
1943 struct nir_shader *const *nir,
1944 int nir_count,
1945 const struct radv_nir_compiler_options *options);
1946
1947 unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class,
1948 const struct nir_shader *nir);
1949
1950 /* radv_shader_info.h */
1951 struct radv_shader_info;
1952
1953 void radv_nir_shader_info_pass(const struct nir_shader *nir,
1954 const struct radv_nir_compiler_options *options,
1955 struct radv_shader_info *info);
1956
1957 void radv_nir_shader_info_init(struct radv_shader_info *info);
1958
1959 struct radeon_winsys_sem;
1960
1961 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
1962 \
1963 static inline struct __radv_type * \
1964 __radv_type ## _from_handle(__VkType _handle) \
1965 { \
1966 return (struct __radv_type *) _handle; \
1967 } \
1968 \
1969 static inline __VkType \
1970 __radv_type ## _to_handle(struct __radv_type *_obj) \
1971 { \
1972 return (__VkType) _obj; \
1973 }
1974
1975 #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
1976 \
1977 static inline struct __radv_type * \
1978 __radv_type ## _from_handle(__VkType _handle) \
1979 { \
1980 return (struct __radv_type *)(uintptr_t) _handle; \
1981 } \
1982 \
1983 static inline __VkType \
1984 __radv_type ## _to_handle(struct __radv_type *_obj) \
1985 { \
1986 return (__VkType)(uintptr_t) _obj; \
1987 }
1988
1989 #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
1990 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
1991
1992 RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
1993 RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
1994 RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
1995 RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
1996 RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
1997
1998 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
1999 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
2000 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
2001 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
2002 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
2003 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
2004 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)
2005 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
2006 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
2007 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
2008 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
2009 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
2010 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
2011 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
2012 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
2013 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
2014 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
2015 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
2016 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
2017 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
2018 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
2019
2020 #endif /* RADV_PRIVATE_H */