radv: use the base object struct types
[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) ((void)0)
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 "util/xmlconfig.h"
52 #include "vk_alloc.h"
53 #include "vk_debug_report.h"
54 #include "vk_object.h"
55
56 #include "radv_radeon_winsys.h"
57 #include "ac_binary.h"
58 #include "ac_nir_to_llvm.h"
59 #include "ac_gpu_info.h"
60 #include "ac_surface.h"
61 #include "ac_llvm_build.h"
62 #include "ac_llvm_util.h"
63 #include "radv_constants.h"
64 #include "radv_descriptor_set.h"
65 #include "radv_extensions.h"
66 #include "sid.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/vulkan_android.h>
78 #include <vulkan/vk_icd.h>
79 #include <vulkan/vk_android_native_buffer.h>
80
81 #include "radv_entrypoints.h"
82
83 #include "wsi_common.h"
84 #include "wsi_common_display.h"
85
86 /* Helper to determine if we should compile
87 * any of the Android AHB support.
88 *
89 * To actually enable the ext we also need
90 * the necessary kernel support.
91 */
92 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
93 #define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 1
94 #else
95 #define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 0
96 #endif
97
98
99 struct gfx10_format {
100 unsigned img_format:9;
101
102 /* Various formats are only supported with workarounds for vertex fetch,
103 * and some 32_32_32 formats are supported natively, but only for buffers
104 * (possibly with some image support, actually, but no filtering). */
105 bool buffers_only:1;
106 };
107
108 #include "gfx10_format_table.h"
109
110 enum radv_secure_compile_type {
111 RADV_SC_TYPE_INIT_SUCCESS,
112 RADV_SC_TYPE_INIT_FAILURE,
113 RADV_SC_TYPE_COMPILE_PIPELINE,
114 RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED,
115 RADV_SC_TYPE_READ_DISK_CACHE,
116 RADV_SC_TYPE_WRITE_DISK_CACHE,
117 RADV_SC_TYPE_FORK_DEVICE,
118 RADV_SC_TYPE_DESTROY_DEVICE,
119 RADV_SC_TYPE_COUNT
120 };
121
122 #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
123
124 static inline uint32_t
125 align_u32(uint32_t v, uint32_t a)
126 {
127 assert(a != 0 && a == (a & -a));
128 return (v + a - 1) & ~(a - 1);
129 }
130
131 static inline uint32_t
132 align_u32_npot(uint32_t v, uint32_t a)
133 {
134 return (v + a - 1) / a * a;
135 }
136
137 static inline uint64_t
138 align_u64(uint64_t v, uint64_t a)
139 {
140 assert(a != 0 && a == (a & -a));
141 return (v + a - 1) & ~(a - 1);
142 }
143
144 static inline int32_t
145 align_i32(int32_t v, int32_t a)
146 {
147 assert(a != 0 && a == (a & -a));
148 return (v + a - 1) & ~(a - 1);
149 }
150
151 /** Alignment must be a power of 2. */
152 static inline bool
153 radv_is_aligned(uintmax_t n, uintmax_t a)
154 {
155 assert(a == (a & -a));
156 return (n & (a - 1)) == 0;
157 }
158
159 static inline uint32_t
160 round_up_u32(uint32_t v, uint32_t a)
161 {
162 return (v + a - 1) / a;
163 }
164
165 static inline uint64_t
166 round_up_u64(uint64_t v, uint64_t a)
167 {
168 return (v + a - 1) / a;
169 }
170
171 static inline uint32_t
172 radv_minify(uint32_t n, uint32_t levels)
173 {
174 if (unlikely(n == 0))
175 return 0;
176 else
177 return MAX2(n >> levels, 1);
178 }
179 static inline float
180 radv_clamp_f(float f, float min, float max)
181 {
182 assert(min < max);
183
184 if (f > max)
185 return max;
186 else if (f < min)
187 return min;
188 else
189 return f;
190 }
191
192 static inline bool
193 radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
194 {
195 if (*inout_mask & clear_mask) {
196 *inout_mask &= ~clear_mask;
197 return true;
198 } else {
199 return false;
200 }
201 }
202
203 #define for_each_bit(b, dword) \
204 for (uint32_t __dword = (dword); \
205 (b) = __builtin_ffs(__dword) - 1, __dword; \
206 __dword &= ~(1 << (b)))
207
208 #define typed_memcpy(dest, src, count) ({ \
209 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
210 memcpy((dest), (src), (count) * sizeof(*(src))); \
211 })
212
213 /* Whenever we generate an error, pass it through this function. Useful for
214 * debugging, where we can break on it. Only call at error site, not when
215 * propagating errors. Might be useful to plug in a stack trace here.
216 */
217
218 struct radv_image_view;
219 struct radv_instance;
220
221 VkResult __vk_errorf(struct radv_instance *instance, VkResult error, const char *file, int line, const char *format, ...);
222
223 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
224 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
225
226 void __radv_finishme(const char *file, int line, const char *format, ...)
227 radv_printflike(3, 4);
228 void radv_loge(const char *format, ...) radv_printflike(1, 2);
229 void radv_loge_v(const char *format, va_list va);
230 void radv_logi(const char *format, ...) radv_printflike(1, 2);
231 void radv_logi_v(const char *format, va_list va);
232
233 /**
234 * Print a FINISHME message, including its source location.
235 */
236 #define radv_finishme(format, ...) \
237 do { \
238 static bool reported = false; \
239 if (!reported) { \
240 __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
241 reported = true; \
242 } \
243 } while (0)
244
245 /* A non-fatal assert. Useful for debugging. */
246 #ifdef DEBUG
247 #define radv_assert(x) ({ \
248 if (unlikely(!(x))) \
249 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
250 })
251 #else
252 #define radv_assert(x) do {} while(0)
253 #endif
254
255 #define stub_return(v) \
256 do { \
257 radv_finishme("stub %s", __func__); \
258 return (v); \
259 } while (0)
260
261 #define stub() \
262 do { \
263 radv_finishme("stub %s", __func__); \
264 return; \
265 } while (0)
266
267 int radv_get_instance_entrypoint_index(const char *name);
268 int radv_get_device_entrypoint_index(const char *name);
269 int radv_get_physical_device_entrypoint_index(const char *name);
270
271 const char *radv_get_instance_entry_name(int index);
272 const char *radv_get_physical_device_entry_name(int index);
273 const char *radv_get_device_entry_name(int index);
274
275 bool radv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
276 const struct radv_instance_extension_table *instance);
277 bool radv_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
278 const struct radv_instance_extension_table *instance);
279 bool radv_device_entrypoint_is_enabled(int index, uint32_t core_version,
280 const struct radv_instance_extension_table *instance,
281 const struct radv_device_extension_table *device);
282
283 void *radv_lookup_entrypoint(const char *name);
284
285 struct radv_physical_device {
286 VK_LOADER_DATA _loader_data;
287
288 /* Link in radv_instance::physical_devices */
289 struct list_head link;
290
291 struct radv_instance * instance;
292
293 struct radeon_winsys *ws;
294 struct radeon_info rad_info;
295 char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
296 uint8_t driver_uuid[VK_UUID_SIZE];
297 uint8_t device_uuid[VK_UUID_SIZE];
298 uint8_t cache_uuid[VK_UUID_SIZE];
299
300 int local_fd;
301 int master_fd;
302 struct wsi_device wsi_device;
303
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 to enable the AMD_shader_ballot extension */
310 bool use_shader_ballot;
311
312 /* Whether to enable NGG. */
313 bool use_ngg;
314
315 /* Whether to enable NGG GS. */
316 bool use_ngg_gs;
317
318 /* Whether to enable NGG streamout. */
319 bool use_ngg_streamout;
320
321 /* Number of threads per wave. */
322 uint8_t ps_wave_size;
323 uint8_t cs_wave_size;
324 uint8_t ge_wave_size;
325
326 /* Whether to use the experimental compiler backend */
327 bool use_aco;
328
329 /* This is the drivers on-disk cache used as a fallback as opposed to
330 * the pipeline cache defined by apps.
331 */
332 struct disk_cache * disk_cache;
333
334 VkPhysicalDeviceMemoryProperties memory_properties;
335 enum radeon_bo_domain memory_domains[VK_MAX_MEMORY_TYPES];
336 enum radeon_bo_flag memory_flags[VK_MAX_MEMORY_TYPES];
337
338 drmPciBusInfo bus_info;
339
340 struct radv_device_extension_table supported_extensions;
341 };
342
343 struct radv_instance {
344 struct vk_object_base base;
345
346 VkAllocationCallbacks alloc;
347
348 uint32_t apiVersion;
349
350 char * engineName;
351 uint32_t engineVersion;
352
353 uint64_t debug_flags;
354 uint64_t perftest_flags;
355 uint8_t num_sc_threads;
356
357 struct vk_debug_report_instance debug_report_callbacks;
358
359 struct radv_instance_extension_table enabled_extensions;
360 struct radv_instance_dispatch_table dispatch;
361 struct radv_physical_device_dispatch_table physical_device_dispatch;
362 struct radv_device_dispatch_table device_dispatch;
363
364 bool physical_devices_enumerated;
365 struct list_head physical_devices;
366
367 struct driOptionCache dri_options;
368 struct driOptionCache available_dri_options;
369 };
370
371 static inline
372 bool radv_device_use_secure_compile(struct radv_instance *instance)
373 {
374 return instance->num_sc_threads;
375 }
376
377 VkResult radv_init_wsi(struct radv_physical_device *physical_device);
378 void radv_finish_wsi(struct radv_physical_device *physical_device);
379
380 bool radv_instance_extension_supported(const char *name);
381 uint32_t radv_physical_device_api_version(struct radv_physical_device *dev);
382 bool radv_physical_device_extension_supported(struct radv_physical_device *dev,
383 const char *name);
384
385 struct cache_entry;
386
387 struct radv_pipeline_cache {
388 struct vk_object_base base;
389 struct radv_device * device;
390 pthread_mutex_t mutex;
391
392 uint32_t total_size;
393 uint32_t table_size;
394 uint32_t kernel_count;
395 struct cache_entry ** hash_table;
396 bool modified;
397
398 VkAllocationCallbacks alloc;
399 };
400
401 struct radv_pipeline_key {
402 uint32_t instance_rate_inputs;
403 uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];
404 uint8_t vertex_attribute_formats[MAX_VERTEX_ATTRIBS];
405 uint32_t vertex_attribute_bindings[MAX_VERTEX_ATTRIBS];
406 uint32_t vertex_attribute_offsets[MAX_VERTEX_ATTRIBS];
407 uint32_t vertex_attribute_strides[MAX_VERTEX_ATTRIBS];
408 uint64_t vertex_alpha_adjust;
409 uint32_t vertex_post_shuffle;
410 unsigned tess_input_vertices;
411 uint32_t col_format;
412 uint32_t is_int8;
413 uint32_t is_int10;
414 uint8_t log2_ps_iter_samples;
415 uint8_t num_samples;
416 uint32_t has_multiview_view_index : 1;
417 uint32_t optimisations_disabled : 1;
418 uint8_t topology;
419
420 /* Non-zero if a required subgroup size is specified via
421 * VK_EXT_subgroup_size_control.
422 */
423 uint8_t compute_subgroup_size;
424 };
425
426 struct radv_shader_binary;
427 struct radv_shader_variant;
428
429 void
430 radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
431 struct radv_device *device);
432 void
433 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
434 bool
435 radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
436 const void *data, size_t size);
437
438 bool
439 radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
440 struct radv_pipeline_cache *cache,
441 const unsigned char *sha1,
442 struct radv_shader_variant **variants,
443 bool *found_in_application_cache);
444
445 void
446 radv_pipeline_cache_insert_shaders(struct radv_device *device,
447 struct radv_pipeline_cache *cache,
448 const unsigned char *sha1,
449 struct radv_shader_variant **variants,
450 struct radv_shader_binary *const *binaries);
451
452 enum radv_blit_ds_layout {
453 RADV_BLIT_DS_LAYOUT_TILE_ENABLE,
454 RADV_BLIT_DS_LAYOUT_TILE_DISABLE,
455 RADV_BLIT_DS_LAYOUT_COUNT,
456 };
457
458 static inline enum radv_blit_ds_layout radv_meta_blit_ds_to_type(VkImageLayout layout)
459 {
460 return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE : RADV_BLIT_DS_LAYOUT_TILE_ENABLE;
461 }
462
463 static inline VkImageLayout radv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)
464 {
465 return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
466 }
467
468 enum radv_meta_dst_layout {
469 RADV_META_DST_LAYOUT_GENERAL,
470 RADV_META_DST_LAYOUT_OPTIMAL,
471 RADV_META_DST_LAYOUT_COUNT,
472 };
473
474 static inline enum radv_meta_dst_layout radv_meta_dst_layout_from_layout(VkImageLayout layout)
475 {
476 return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL : RADV_META_DST_LAYOUT_OPTIMAL;
477 }
478
479 static inline VkImageLayout radv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)
480 {
481 return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
482 }
483
484 struct radv_meta_state {
485 VkAllocationCallbacks alloc;
486
487 struct radv_pipeline_cache cache;
488
489 /*
490 * For on-demand pipeline creation, makes sure that
491 * only one thread tries to build a pipeline at the same time.
492 */
493 mtx_t mtx;
494
495 /**
496 * Use array element `i` for images with `2^i` samples.
497 */
498 struct {
499 VkRenderPass render_pass[NUM_META_FS_KEYS];
500 VkPipeline color_pipelines[NUM_META_FS_KEYS];
501
502 VkRenderPass depthstencil_rp;
503 VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
504 VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
505 VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
506
507 VkPipeline depth_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
508 VkPipeline stencil_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
509 VkPipeline depthstencil_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
510 } clear[MAX_SAMPLES_LOG2];
511
512 VkPipelineLayout clear_color_p_layout;
513 VkPipelineLayout clear_depth_p_layout;
514 VkPipelineLayout clear_depth_unrestricted_p_layout;
515
516 /* Optimized compute fast HTILE clear for stencil or depth only. */
517 VkPipeline clear_htile_mask_pipeline;
518 VkPipelineLayout clear_htile_mask_p_layout;
519 VkDescriptorSetLayout clear_htile_mask_ds_layout;
520
521 struct {
522 VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
523
524 /** Pipeline that blits from a 1D image. */
525 VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
526
527 /** Pipeline that blits from a 2D image. */
528 VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
529
530 /** Pipeline that blits from a 3D image. */
531 VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
532
533 VkRenderPass depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
534 VkPipeline depth_only_1d_pipeline;
535 VkPipeline depth_only_2d_pipeline;
536 VkPipeline depth_only_3d_pipeline;
537
538 VkRenderPass stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
539 VkPipeline stencil_only_1d_pipeline;
540 VkPipeline stencil_only_2d_pipeline;
541 VkPipeline stencil_only_3d_pipeline;
542 VkPipelineLayout pipeline_layout;
543 VkDescriptorSetLayout ds_layout;
544 } blit;
545
546 struct {
547 VkPipelineLayout p_layouts[5];
548 VkDescriptorSetLayout ds_layouts[5];
549 VkPipeline pipelines[5][NUM_META_FS_KEYS];
550
551 VkPipeline depth_only_pipeline[5];
552
553 VkPipeline stencil_only_pipeline[5];
554 } blit2d[MAX_SAMPLES_LOG2];
555
556 VkRenderPass blit2d_render_passes[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
557 VkRenderPass blit2d_depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
558 VkRenderPass blit2d_stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
559
560 struct {
561 VkPipelineLayout img_p_layout;
562 VkDescriptorSetLayout img_ds_layout;
563 VkPipeline pipeline;
564 VkPipeline pipeline_3d;
565 } itob;
566 struct {
567 VkPipelineLayout img_p_layout;
568 VkDescriptorSetLayout img_ds_layout;
569 VkPipeline pipeline;
570 VkPipeline pipeline_3d;
571 } btoi;
572 struct {
573 VkPipelineLayout img_p_layout;
574 VkDescriptorSetLayout img_ds_layout;
575 VkPipeline pipeline;
576 } btoi_r32g32b32;
577 struct {
578 VkPipelineLayout img_p_layout;
579 VkDescriptorSetLayout img_ds_layout;
580 VkPipeline pipeline;
581 VkPipeline pipeline_3d;
582 } itoi;
583 struct {
584 VkPipelineLayout img_p_layout;
585 VkDescriptorSetLayout img_ds_layout;
586 VkPipeline pipeline;
587 } itoi_r32g32b32;
588 struct {
589 VkPipelineLayout img_p_layout;
590 VkDescriptorSetLayout img_ds_layout;
591 VkPipeline pipeline;
592 VkPipeline pipeline_3d;
593 } cleari;
594 struct {
595 VkPipelineLayout img_p_layout;
596 VkDescriptorSetLayout img_ds_layout;
597 VkPipeline pipeline;
598 } cleari_r32g32b32;
599
600 struct {
601 VkPipelineLayout p_layout;
602 VkPipeline pipeline[NUM_META_FS_KEYS];
603 VkRenderPass pass[NUM_META_FS_KEYS];
604 } resolve;
605
606 struct {
607 VkDescriptorSetLayout ds_layout;
608 VkPipelineLayout p_layout;
609 struct {
610 VkPipeline pipeline;
611 VkPipeline i_pipeline;
612 VkPipeline srgb_pipeline;
613 } rc[MAX_SAMPLES_LOG2];
614
615 VkPipeline depth_zero_pipeline;
616 struct {
617 VkPipeline average_pipeline;
618 VkPipeline max_pipeline;
619 VkPipeline min_pipeline;
620 } depth[MAX_SAMPLES_LOG2];
621
622 VkPipeline stencil_zero_pipeline;
623 struct {
624 VkPipeline max_pipeline;
625 VkPipeline min_pipeline;
626 } stencil[MAX_SAMPLES_LOG2];
627 } resolve_compute;
628
629 struct {
630 VkDescriptorSetLayout ds_layout;
631 VkPipelineLayout p_layout;
632
633 struct {
634 VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
635 VkPipeline pipeline[NUM_META_FS_KEYS];
636 } rc[MAX_SAMPLES_LOG2];
637
638 VkRenderPass depth_render_pass;
639 VkPipeline depth_zero_pipeline;
640 struct {
641 VkPipeline average_pipeline;
642 VkPipeline max_pipeline;
643 VkPipeline min_pipeline;
644 } depth[MAX_SAMPLES_LOG2];
645
646 VkRenderPass stencil_render_pass;
647 VkPipeline stencil_zero_pipeline;
648 struct {
649 VkPipeline max_pipeline;
650 VkPipeline min_pipeline;
651 } stencil[MAX_SAMPLES_LOG2];
652 } resolve_fragment;
653
654 struct {
655 VkPipelineLayout p_layout;
656 VkPipeline decompress_pipeline[NUM_DEPTH_DECOMPRESS_PIPELINES];
657 VkPipeline resummarize_pipeline;
658 VkRenderPass pass;
659 } depth_decomp[MAX_SAMPLES_LOG2];
660
661 struct {
662 VkPipelineLayout p_layout;
663 VkPipeline cmask_eliminate_pipeline;
664 VkPipeline fmask_decompress_pipeline;
665 VkPipeline dcc_decompress_pipeline;
666 VkRenderPass pass;
667
668 VkDescriptorSetLayout dcc_decompress_compute_ds_layout;
669 VkPipelineLayout dcc_decompress_compute_p_layout;
670 VkPipeline dcc_decompress_compute_pipeline;
671 } fast_clear_flush;
672
673 struct {
674 VkPipelineLayout fill_p_layout;
675 VkPipelineLayout copy_p_layout;
676 VkDescriptorSetLayout fill_ds_layout;
677 VkDescriptorSetLayout copy_ds_layout;
678 VkPipeline fill_pipeline;
679 VkPipeline copy_pipeline;
680 } buffer;
681
682 struct {
683 VkDescriptorSetLayout ds_layout;
684 VkPipelineLayout p_layout;
685 VkPipeline occlusion_query_pipeline;
686 VkPipeline pipeline_statistics_query_pipeline;
687 VkPipeline tfb_query_pipeline;
688 VkPipeline timestamp_query_pipeline;
689 } query;
690
691 struct {
692 VkDescriptorSetLayout ds_layout;
693 VkPipelineLayout p_layout;
694 VkPipeline pipeline[MAX_SAMPLES_LOG2];
695 } fmask_expand;
696 };
697
698 /* queue types */
699 #define RADV_QUEUE_GENERAL 0
700 #define RADV_QUEUE_COMPUTE 1
701 #define RADV_QUEUE_TRANSFER 2
702
703 #define RADV_MAX_QUEUE_FAMILIES 3
704
705 enum ring_type radv_queue_family_to_ring(int f);
706
707 struct radv_queue {
708 VK_LOADER_DATA _loader_data;
709 struct radv_device * device;
710 struct radeon_winsys_ctx *hw_ctx;
711 enum radeon_ctx_priority priority;
712 uint32_t queue_family_index;
713 int queue_idx;
714 VkDeviceQueueCreateFlags flags;
715
716 uint32_t scratch_size_per_wave;
717 uint32_t scratch_waves;
718 uint32_t compute_scratch_size_per_wave;
719 uint32_t compute_scratch_waves;
720 uint32_t esgs_ring_size;
721 uint32_t gsvs_ring_size;
722 bool has_tess_rings;
723 bool has_gds;
724 bool has_gds_oa;
725 bool has_sample_positions;
726
727 struct radeon_winsys_bo *scratch_bo;
728 struct radeon_winsys_bo *descriptor_bo;
729 struct radeon_winsys_bo *compute_scratch_bo;
730 struct radeon_winsys_bo *esgs_ring_bo;
731 struct radeon_winsys_bo *gsvs_ring_bo;
732 struct radeon_winsys_bo *tess_rings_bo;
733 struct radeon_winsys_bo *gds_bo;
734 struct radeon_winsys_bo *gds_oa_bo;
735 struct radeon_cmdbuf *initial_preamble_cs;
736 struct radeon_cmdbuf *initial_full_flush_preamble_cs;
737 struct radeon_cmdbuf *continue_preamble_cs;
738
739 struct list_head pending_submissions;
740 pthread_mutex_t pending_mutex;
741 };
742
743 struct radv_bo_list {
744 struct radv_winsys_bo_list list;
745 unsigned capacity;
746 pthread_mutex_t mutex;
747 };
748
749 VkResult radv_bo_list_add(struct radv_device *device,
750 struct radeon_winsys_bo *bo);
751 void radv_bo_list_remove(struct radv_device *device,
752 struct radeon_winsys_bo *bo);
753
754 struct radv_secure_compile_process {
755 /* Secure process file descriptors. Used to communicate between the
756 * user facing device and the idle forked device used to fork a clean
757 * process for each new pipeline compile.
758 */
759 int fd_secure_input;
760 int fd_secure_output;
761
762 /* FIFO file descriptors used to communicate between the user facing
763 * device and the secure process that does the actual secure compile.
764 */
765 int fd_server;
766 int fd_client;
767
768 /* Secure compile process id */
769 pid_t sc_pid;
770
771 /* Is the secure compile process currently in use by a thread */
772 bool in_use;
773 };
774
775 struct radv_secure_compile_state {
776 struct radv_secure_compile_process *secure_compile_processes;
777 uint32_t secure_compile_thread_counter;
778 mtx_t secure_compile_mutex;
779
780 /* Unique process ID used to build name for FIFO file descriptor */
781 char *uid;
782 };
783
784 struct radv_device {
785 struct vk_device vk;
786
787 struct radv_instance * instance;
788 struct radeon_winsys *ws;
789
790 struct radv_meta_state meta_state;
791
792 struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
793 int queue_count[RADV_MAX_QUEUE_FAMILIES];
794 struct radeon_cmdbuf *empty_cs[RADV_MAX_QUEUE_FAMILIES];
795
796 bool always_use_syncobj;
797 bool pbb_allowed;
798 bool dfsm_allowed;
799 uint32_t tess_offchip_block_dw_size;
800 uint32_t scratch_waves;
801 uint32_t dispatch_initiator;
802
803 uint32_t gs_table_depth;
804
805 /* MSAA sample locations.
806 * The first index is the sample index.
807 * The second index is the coordinate: X, Y. */
808 float sample_locations_1x[1][2];
809 float sample_locations_2x[2][2];
810 float sample_locations_4x[4][2];
811 float sample_locations_8x[8][2];
812
813 /* GFX7 and later */
814 uint32_t gfx_init_size_dw;
815 struct radeon_winsys_bo *gfx_init;
816
817 struct radeon_winsys_bo *trace_bo;
818 uint32_t *trace_id_ptr;
819
820 /* Whether to keep shader debug info, for tracing or VK_AMD_shader_info */
821 bool keep_shader_info;
822
823 struct radv_physical_device *physical_device;
824
825 /* Backup in-memory cache to be used if the app doesn't provide one */
826 struct radv_pipeline_cache * mem_cache;
827
828 /*
829 * use different counters so MSAA MRTs get consecutive surface indices,
830 * even if MASK is allocated in between.
831 */
832 uint32_t image_mrt_offset_counter;
833 uint32_t fmask_mrt_offset_counter;
834 struct list_head shader_slabs;
835 mtx_t shader_slab_mutex;
836
837 /* For detecting VM faults reported by dmesg. */
838 uint64_t dmesg_timestamp;
839
840 struct radv_device_extension_table enabled_extensions;
841 struct radv_device_dispatch_table dispatch;
842
843 /* Whether the app has enabled the robustBufferAccess feature. */
844 bool robust_buffer_access;
845
846 /* Whether the driver uses a global BO list. */
847 bool use_global_bo_list;
848
849 struct radv_bo_list bo_list;
850
851 /* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */
852 int force_aniso;
853
854 struct radv_secure_compile_state *sc_state;
855
856 /* Condition variable for legacy timelines, to notify waiters when a
857 * new point gets submitted. */
858 pthread_cond_t timeline_cond;
859
860 /* Thread trace. */
861 struct radeon_cmdbuf *thread_trace_start_cs[2];
862 struct radeon_cmdbuf *thread_trace_stop_cs[2];
863 struct radeon_winsys_bo *thread_trace_bo;
864 void *thread_trace_ptr;
865 uint32_t thread_trace_buffer_size;
866 int thread_trace_start_frame;
867
868 /* Overallocation. */
869 bool overallocation_disallowed;
870 uint64_t allocated_memory_size[VK_MAX_MEMORY_HEAPS];
871 mtx_t overallocation_mutex;
872 };
873
874 struct radv_device_memory {
875 struct vk_object_base base;
876 struct radeon_winsys_bo *bo;
877 /* for dedicated allocations */
878 struct radv_image *image;
879 struct radv_buffer *buffer;
880 uint32_t heap_index;
881 uint64_t alloc_size;
882 void * map;
883 void * user_ptr;
884
885 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
886 struct AHardwareBuffer * android_hardware_buffer;
887 #endif
888 };
889
890
891 struct radv_descriptor_range {
892 uint64_t va;
893 uint32_t size;
894 };
895
896 struct radv_descriptor_set {
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 struct radeon_winsys_bo *descriptors[0];
908 };
909
910 struct radv_push_descriptor_set
911 {
912 struct radv_descriptor_set set;
913 uint32_t capacity;
914 };
915
916 struct radv_descriptor_pool_entry {
917 uint32_t offset;
918 uint32_t size;
919 struct radv_descriptor_set *set;
920 };
921
922 struct radv_descriptor_pool {
923 struct vk_object_base base;
924 struct radeon_winsys_bo *bo;
925 uint8_t *mapped_ptr;
926 uint64_t current_offset;
927 uint64_t size;
928
929 uint8_t *host_memory_base;
930 uint8_t *host_memory_ptr;
931 uint8_t *host_memory_end;
932
933 uint32_t entry_count;
934 uint32_t max_entry_count;
935 struct radv_descriptor_pool_entry entries[0];
936 };
937
938 struct radv_descriptor_update_template_entry {
939 VkDescriptorType descriptor_type;
940
941 /* The number of descriptors to update */
942 uint32_t descriptor_count;
943
944 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
945 uint32_t dst_offset;
946
947 /* In dwords. Not valid/used for dynamic descriptors */
948 uint32_t dst_stride;
949
950 uint32_t buffer_offset;
951
952 /* Only valid for combined image samplers and samplers */
953 uint8_t has_sampler;
954 uint8_t sampler_offset;
955
956 /* In bytes */
957 size_t src_offset;
958 size_t src_stride;
959
960 /* For push descriptors */
961 const uint32_t *immutable_samplers;
962 };
963
964 struct radv_descriptor_update_template {
965 struct vk_object_base base;
966 uint32_t entry_count;
967 VkPipelineBindPoint bind_point;
968 struct radv_descriptor_update_template_entry entry[0];
969 };
970
971 struct radv_buffer {
972 struct vk_object_base base;
973 VkDeviceSize size;
974
975 VkBufferUsageFlags usage;
976 VkBufferCreateFlags flags;
977
978 /* Set when bound */
979 struct radeon_winsys_bo * bo;
980 VkDeviceSize offset;
981
982 bool shareable;
983 };
984
985 enum radv_dynamic_state_bits {
986 RADV_DYNAMIC_VIEWPORT = 1 << 0,
987 RADV_DYNAMIC_SCISSOR = 1 << 1,
988 RADV_DYNAMIC_LINE_WIDTH = 1 << 2,
989 RADV_DYNAMIC_DEPTH_BIAS = 1 << 3,
990 RADV_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
991 RADV_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
992 RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
993 RADV_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
994 RADV_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
995 RADV_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
996 RADV_DYNAMIC_SAMPLE_LOCATIONS = 1 << 10,
997 RADV_DYNAMIC_LINE_STIPPLE = 1 << 11,
998 RADV_DYNAMIC_ALL = (1 << 12) - 1,
999 };
1000
1001 enum radv_cmd_dirty_bits {
1002 /* Keep the dynamic state dirty bits in sync with
1003 * enum radv_dynamic_state_bits */
1004 RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0,
1005 RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1,
1006 RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2,
1007 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3,
1008 RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
1009 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
1010 RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
1011 RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
1012 RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
1013 RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
1014 RADV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS = 1 << 10,
1015 RADV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE = 1 << 11,
1016 RADV_CMD_DIRTY_DYNAMIC_ALL = (1 << 12) - 1,
1017 RADV_CMD_DIRTY_PIPELINE = 1 << 12,
1018 RADV_CMD_DIRTY_INDEX_BUFFER = 1 << 13,
1019 RADV_CMD_DIRTY_FRAMEBUFFER = 1 << 14,
1020 RADV_CMD_DIRTY_VERTEX_BUFFER = 1 << 15,
1021 RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1 << 16,
1022 };
1023
1024 enum radv_cmd_flush_bits {
1025 /* Instruction cache. */
1026 RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
1027 /* Scalar L1 cache. */
1028 RADV_CMD_FLAG_INV_SCACHE = 1 << 1,
1029 /* Vector L1 cache. */
1030 RADV_CMD_FLAG_INV_VCACHE = 1 << 2,
1031 /* L2 cache + L2 metadata cache writeback & invalidate.
1032 * GFX6-8: Used by shaders only. GFX9-10: Used by everything. */
1033 RADV_CMD_FLAG_INV_L2 = 1 << 3,
1034 /* L2 writeback (write dirty L2 lines to memory for non-L2 clients).
1035 * Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8.
1036 * GFX6-7 will do complete invalidation, because the writeback is unsupported. */
1037 RADV_CMD_FLAG_WB_L2 = 1 << 4,
1038 /* Framebuffer caches */
1039 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 5,
1040 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 6,
1041 RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 7,
1042 RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 8,
1043 /* Engine synchronization. */
1044 RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 9,
1045 RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 10,
1046 RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 11,
1047 RADV_CMD_FLAG_VGT_FLUSH = 1 << 12,
1048 /* Pipeline query controls. */
1049 RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 13,
1050 RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 14,
1051 RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 15,
1052
1053 RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER = (RADV_CMD_FLAG_FLUSH_AND_INV_CB |
1054 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
1055 RADV_CMD_FLAG_FLUSH_AND_INV_DB |
1056 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
1057 };
1058
1059 struct radv_vertex_binding {
1060 struct radv_buffer * buffer;
1061 VkDeviceSize offset;
1062 };
1063
1064 struct radv_streamout_binding {
1065 struct radv_buffer *buffer;
1066 VkDeviceSize offset;
1067 VkDeviceSize size;
1068 };
1069
1070 struct radv_streamout_state {
1071 /* Mask of bound streamout buffers. */
1072 uint8_t enabled_mask;
1073
1074 /* External state that comes from the last vertex stage, it must be
1075 * set explicitely when binding a new graphics pipeline.
1076 */
1077 uint16_t stride_in_dw[MAX_SO_BUFFERS];
1078 uint32_t enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
1079
1080 /* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */
1081 uint32_t hw_enabled_mask;
1082
1083 /* State of VGT_STRMOUT_(CONFIG|EN) */
1084 bool streamout_enabled;
1085 };
1086
1087 struct radv_viewport_state {
1088 uint32_t count;
1089 VkViewport viewports[MAX_VIEWPORTS];
1090 };
1091
1092 struct radv_scissor_state {
1093 uint32_t count;
1094 VkRect2D scissors[MAX_SCISSORS];
1095 };
1096
1097 struct radv_discard_rectangle_state {
1098 uint32_t count;
1099 VkRect2D rectangles[MAX_DISCARD_RECTANGLES];
1100 };
1101
1102 struct radv_sample_locations_state {
1103 VkSampleCountFlagBits per_pixel;
1104 VkExtent2D grid_size;
1105 uint32_t count;
1106 VkSampleLocationEXT locations[MAX_SAMPLE_LOCATIONS];
1107 };
1108
1109 struct radv_dynamic_state {
1110 /**
1111 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
1112 * Defines the set of saved dynamic state.
1113 */
1114 uint32_t mask;
1115
1116 struct radv_viewport_state viewport;
1117
1118 struct radv_scissor_state scissor;
1119
1120 float line_width;
1121
1122 struct {
1123 float bias;
1124 float clamp;
1125 float slope;
1126 } depth_bias;
1127
1128 float blend_constants[4];
1129
1130 struct {
1131 float min;
1132 float max;
1133 } depth_bounds;
1134
1135 struct {
1136 uint32_t front;
1137 uint32_t back;
1138 } stencil_compare_mask;
1139
1140 struct {
1141 uint32_t front;
1142 uint32_t back;
1143 } stencil_write_mask;
1144
1145 struct {
1146 uint32_t front;
1147 uint32_t back;
1148 } stencil_reference;
1149
1150 struct radv_discard_rectangle_state discard_rectangle;
1151
1152 struct radv_sample_locations_state sample_location;
1153
1154 struct {
1155 uint32_t factor;
1156 uint16_t pattern;
1157 } line_stipple;
1158 };
1159
1160 extern const struct radv_dynamic_state default_dynamic_state;
1161
1162 const char *
1163 radv_get_debug_option_name(int id);
1164
1165 const char *
1166 radv_get_perftest_option_name(int id);
1167
1168 struct radv_color_buffer_info {
1169 uint64_t cb_color_base;
1170 uint64_t cb_color_cmask;
1171 uint64_t cb_color_fmask;
1172 uint64_t cb_dcc_base;
1173 uint32_t cb_color_slice;
1174 uint32_t cb_color_view;
1175 uint32_t cb_color_info;
1176 uint32_t cb_color_attrib;
1177 uint32_t cb_color_attrib2; /* GFX9 and later */
1178 uint32_t cb_color_attrib3; /* GFX10 and later */
1179 uint32_t cb_dcc_control;
1180 uint32_t cb_color_cmask_slice;
1181 uint32_t cb_color_fmask_slice;
1182 union {
1183 uint32_t cb_color_pitch; // GFX6-GFX8
1184 uint32_t cb_mrt_epitch; // GFX9+
1185 };
1186 };
1187
1188 struct radv_ds_buffer_info {
1189 uint64_t db_z_read_base;
1190 uint64_t db_stencil_read_base;
1191 uint64_t db_z_write_base;
1192 uint64_t db_stencil_write_base;
1193 uint64_t db_htile_data_base;
1194 uint32_t db_depth_info;
1195 uint32_t db_z_info;
1196 uint32_t db_stencil_info;
1197 uint32_t db_depth_view;
1198 uint32_t db_depth_size;
1199 uint32_t db_depth_slice;
1200 uint32_t db_htile_surface;
1201 uint32_t pa_su_poly_offset_db_fmt_cntl;
1202 uint32_t db_z_info2; /* GFX9 only */
1203 uint32_t db_stencil_info2; /* GFX9 only */
1204 float offset_scale;
1205 };
1206
1207 void
1208 radv_initialise_color_surface(struct radv_device *device,
1209 struct radv_color_buffer_info *cb,
1210 struct radv_image_view *iview);
1211 void
1212 radv_initialise_ds_surface(struct radv_device *device,
1213 struct radv_ds_buffer_info *ds,
1214 struct radv_image_view *iview);
1215
1216 bool
1217 radv_sc_read(int fd, void *buf, size_t size, bool timeout);
1218
1219 /**
1220 * Attachment state when recording a renderpass instance.
1221 *
1222 * The clear value is valid only if there exists a pending clear.
1223 */
1224 struct radv_attachment_state {
1225 VkImageAspectFlags pending_clear_aspects;
1226 uint32_t cleared_views;
1227 VkClearValue clear_value;
1228 VkImageLayout current_layout;
1229 VkImageLayout current_stencil_layout;
1230 bool current_in_render_loop;
1231 struct radv_sample_locations_state sample_location;
1232
1233 union {
1234 struct radv_color_buffer_info cb;
1235 struct radv_ds_buffer_info ds;
1236 };
1237 struct radv_image_view *iview;
1238 };
1239
1240 struct radv_descriptor_state {
1241 struct radv_descriptor_set *sets[MAX_SETS];
1242 uint32_t dirty;
1243 uint32_t valid;
1244 struct radv_push_descriptor_set push_set;
1245 bool push_dirty;
1246 uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
1247 };
1248
1249 struct radv_subpass_sample_locs_state {
1250 uint32_t subpass_idx;
1251 struct radv_sample_locations_state sample_location;
1252 };
1253
1254 struct radv_cmd_state {
1255 /* Vertex descriptors */
1256 uint64_t vb_va;
1257 unsigned vb_size;
1258
1259 bool predicating;
1260 uint32_t dirty;
1261
1262 uint32_t prefetch_L2_mask;
1263
1264 struct radv_pipeline * pipeline;
1265 struct radv_pipeline * emitted_pipeline;
1266 struct radv_pipeline * compute_pipeline;
1267 struct radv_pipeline * emitted_compute_pipeline;
1268 struct radv_framebuffer * framebuffer;
1269 struct radv_render_pass * pass;
1270 const struct radv_subpass * subpass;
1271 struct radv_dynamic_state dynamic;
1272 struct radv_attachment_state * attachments;
1273 struct radv_streamout_state streamout;
1274 VkRect2D render_area;
1275
1276 uint32_t num_subpass_sample_locs;
1277 struct radv_subpass_sample_locs_state * subpass_sample_locs;
1278
1279 /* Index buffer */
1280 struct radv_buffer *index_buffer;
1281 uint64_t index_offset;
1282 uint32_t index_type;
1283 uint32_t max_index_count;
1284 uint64_t index_va;
1285 int32_t last_index_type;
1286
1287 int32_t last_primitive_reset_en;
1288 uint32_t last_primitive_reset_index;
1289 enum radv_cmd_flush_bits flush_bits;
1290 unsigned active_occlusion_queries;
1291 bool perfect_occlusion_queries_enabled;
1292 unsigned active_pipeline_queries;
1293 unsigned active_pipeline_gds_queries;
1294 float offset_scale;
1295 uint32_t trace_id;
1296 uint32_t last_ia_multi_vgt_param;
1297
1298 uint32_t last_num_instances;
1299 uint32_t last_first_instance;
1300 uint32_t last_vertex_offset;
1301
1302 uint32_t last_sx_ps_downconvert;
1303 uint32_t last_sx_blend_opt_epsilon;
1304 uint32_t last_sx_blend_opt_control;
1305
1306 /* Whether CP DMA is busy/idle. */
1307 bool dma_is_busy;
1308
1309 /* Conditional rendering info. */
1310 int predication_type; /* -1: disabled, 0: normal, 1: inverted */
1311 uint64_t predication_va;
1312
1313 /* Inheritance info. */
1314 VkQueryPipelineStatisticFlags inherited_pipeline_statistics;
1315
1316 bool context_roll_without_scissor_emitted;
1317
1318 /* SQTT related state. */
1319 uint32_t current_event_type;
1320 uint32_t num_events;
1321 uint32_t num_layout_transitions;
1322 };
1323
1324 struct radv_cmd_pool {
1325 struct vk_object_base base;
1326 VkAllocationCallbacks alloc;
1327 struct list_head cmd_buffers;
1328 struct list_head free_cmd_buffers;
1329 uint32_t queue_family_index;
1330 };
1331
1332 struct radv_cmd_buffer_upload {
1333 uint8_t *map;
1334 unsigned offset;
1335 uint64_t size;
1336 struct radeon_winsys_bo *upload_bo;
1337 struct list_head list;
1338 };
1339
1340 enum radv_cmd_buffer_status {
1341 RADV_CMD_BUFFER_STATUS_INVALID,
1342 RADV_CMD_BUFFER_STATUS_INITIAL,
1343 RADV_CMD_BUFFER_STATUS_RECORDING,
1344 RADV_CMD_BUFFER_STATUS_EXECUTABLE,
1345 RADV_CMD_BUFFER_STATUS_PENDING,
1346 };
1347
1348 struct radv_cmd_buffer {
1349 struct vk_object_base base;
1350
1351 struct radv_device * device;
1352
1353 struct radv_cmd_pool * pool;
1354 struct list_head pool_link;
1355
1356 VkCommandBufferUsageFlags usage_flags;
1357 VkCommandBufferLevel level;
1358 enum radv_cmd_buffer_status status;
1359 struct radeon_cmdbuf *cs;
1360 struct radv_cmd_state state;
1361 struct radv_vertex_binding vertex_bindings[MAX_VBS];
1362 struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
1363 uint32_t queue_family_index;
1364
1365 uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
1366 VkShaderStageFlags push_constant_stages;
1367 struct radv_descriptor_set meta_push_descriptors;
1368
1369 struct radv_descriptor_state descriptors[MAX_BIND_POINTS];
1370
1371 struct radv_cmd_buffer_upload upload;
1372
1373 uint32_t scratch_size_per_wave_needed;
1374 uint32_t scratch_waves_wanted;
1375 uint32_t compute_scratch_size_per_wave_needed;
1376 uint32_t compute_scratch_waves_wanted;
1377 uint32_t esgs_ring_size_needed;
1378 uint32_t gsvs_ring_size_needed;
1379 bool tess_rings_needed;
1380 bool gds_needed; /* for GFX10 streamout and NGG GS queries */
1381 bool gds_oa_needed; /* for GFX10 streamout */
1382 bool sample_positions_needed;
1383
1384 VkResult record_result;
1385
1386 uint64_t gfx9_fence_va;
1387 uint32_t gfx9_fence_idx;
1388 uint64_t gfx9_eop_bug_va;
1389
1390 /**
1391 * Whether a query pool has been resetted and we have to flush caches.
1392 */
1393 bool pending_reset_query;
1394
1395 /**
1396 * Bitmask of pending active query flushes.
1397 */
1398 enum radv_cmd_flush_bits active_query_flush_bits;
1399 };
1400
1401 struct radv_image;
1402 struct radv_image_view;
1403
1404 bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
1405
1406 void si_emit_graphics(struct radv_device *device,
1407 struct radeon_cmdbuf *cs);
1408 void si_emit_compute(struct radv_physical_device *physical_device,
1409 struct radeon_cmdbuf *cs);
1410
1411 void cik_create_gfx_config(struct radv_device *device);
1412
1413 void si_write_viewport(struct radeon_cmdbuf *cs, int first_vp,
1414 int count, const VkViewport *viewports);
1415 void si_write_scissors(struct radeon_cmdbuf *cs, int first,
1416 int count, const VkRect2D *scissors,
1417 const VkViewport *viewports, bool can_use_guardband);
1418 uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer,
1419 bool instanced_draw, bool indirect_draw,
1420 bool count_from_stream_output,
1421 uint32_t draw_vertex_count);
1422 void si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs,
1423 enum chip_class chip_class,
1424 bool is_mec,
1425 unsigned event, unsigned event_flags,
1426 unsigned dst_sel, unsigned data_sel,
1427 uint64_t va,
1428 uint32_t new_fence,
1429 uint64_t gfx9_eop_bug_va);
1430
1431 void radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va,
1432 uint32_t ref, uint32_t mask);
1433 void si_cs_emit_cache_flush(struct radeon_cmdbuf *cs,
1434 enum chip_class chip_class,
1435 uint32_t *fence_ptr, uint64_t va,
1436 bool is_mec,
1437 enum radv_cmd_flush_bits flush_bits,
1438 uint64_t gfx9_eop_bug_va);
1439 void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
1440 void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer,
1441 bool inverted, uint64_t va);
1442 void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer,
1443 uint64_t src_va, uint64_t dest_va,
1444 uint64_t size);
1445 void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
1446 unsigned size);
1447 void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
1448 uint64_t size, unsigned value);
1449 void si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);
1450
1451 void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
1452 bool
1453 radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer,
1454 unsigned size,
1455 unsigned alignment,
1456 unsigned *out_offset,
1457 void **ptr);
1458 void
1459 radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
1460 const struct radv_subpass *subpass);
1461 bool
1462 radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer,
1463 unsigned size, unsigned alignmnet,
1464 const void *data, unsigned *out_offset);
1465
1466 void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
1467 void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
1468 void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
1469 void radv_depth_stencil_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer,
1470 VkImageAspectFlags aspects,
1471 VkResolveModeFlagBits resolve_mode);
1472 void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
1473 void radv_depth_stencil_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer,
1474 VkImageAspectFlags aspects,
1475 VkResolveModeFlagBits resolve_mode);
1476 void radv_emit_default_sample_locations(struct radeon_cmdbuf *cs, int nr_samples);
1477 unsigned radv_get_default_max_sample_dist(int log_samples);
1478 void radv_device_init_msaa(struct radv_device *device);
1479
1480 void radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1481 const struct radv_image_view *iview,
1482 VkClearDepthStencilValue ds_clear_value,
1483 VkImageAspectFlags aspects);
1484
1485 void radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1486 const struct radv_image_view *iview,
1487 int cb_idx,
1488 uint32_t color_values[2]);
1489
1490 void radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer,
1491 struct radv_image *image,
1492 const VkImageSubresourceRange *range, bool value);
1493
1494 void radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer,
1495 struct radv_image *image,
1496 const VkImageSubresourceRange *range, bool value);
1497
1498 uint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
1499 struct radeon_winsys_bo *bo,
1500 uint64_t offset, uint64_t size, uint32_t value);
1501 void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
1502 bool radv_get_memory_fd(struct radv_device *device,
1503 struct radv_device_memory *memory,
1504 int *pFD);
1505
1506 static inline void
1507 radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs,
1508 unsigned sh_offset, unsigned pointer_count,
1509 bool use_32bit_pointers)
1510 {
1511 radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));
1512 radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);
1513 }
1514
1515 static inline void
1516 radv_emit_shader_pointer_body(struct radv_device *device,
1517 struct radeon_cmdbuf *cs,
1518 uint64_t va, bool use_32bit_pointers)
1519 {
1520 radeon_emit(cs, va);
1521
1522 if (use_32bit_pointers) {
1523 assert(va == 0 ||
1524 (va >> 32) == device->physical_device->rad_info.address32_hi);
1525 } else {
1526 radeon_emit(cs, va >> 32);
1527 }
1528 }
1529
1530 static inline void
1531 radv_emit_shader_pointer(struct radv_device *device,
1532 struct radeon_cmdbuf *cs,
1533 uint32_t sh_offset, uint64_t va, bool global)
1534 {
1535 bool use_32bit_pointers = !global;
1536
1537 radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);
1538 radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);
1539 }
1540
1541 static inline struct radv_descriptor_state *
1542 radv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer,
1543 VkPipelineBindPoint bind_point)
1544 {
1545 assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS ||
1546 bind_point == VK_PIPELINE_BIND_POINT_COMPUTE);
1547 return &cmd_buffer->descriptors[bind_point];
1548 }
1549
1550 /*
1551 * Takes x,y,z as exact numbers of invocations, instead of blocks.
1552 *
1553 * Limitations: Can't call normal dispatch functions without binding or rebinding
1554 * the compute pipeline.
1555 */
1556 void radv_unaligned_dispatch(
1557 struct radv_cmd_buffer *cmd_buffer,
1558 uint32_t x,
1559 uint32_t y,
1560 uint32_t z);
1561
1562 struct radv_event {
1563 struct vk_object_base base;
1564 struct radeon_winsys_bo *bo;
1565 uint64_t *map;
1566 };
1567
1568 struct radv_shader_module;
1569
1570 #define RADV_HASH_SHADER_NO_NGG (1 << 0)
1571 #define RADV_HASH_SHADER_CS_WAVE32 (1 << 1)
1572 #define RADV_HASH_SHADER_PS_WAVE32 (1 << 2)
1573 #define RADV_HASH_SHADER_GE_WAVE32 (1 << 3)
1574 #define RADV_HASH_SHADER_ACO (1 << 4)
1575
1576 void
1577 radv_hash_shaders(unsigned char *hash,
1578 const VkPipelineShaderStageCreateInfo **stages,
1579 const struct radv_pipeline_layout *layout,
1580 const struct radv_pipeline_key *key,
1581 uint32_t flags);
1582
1583 static inline gl_shader_stage
1584 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1585 {
1586 assert(__builtin_popcount(vk_stage) == 1);
1587 return ffs(vk_stage) - 1;
1588 }
1589
1590 static inline VkShaderStageFlagBits
1591 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1592 {
1593 return (1 << mesa_stage);
1594 }
1595
1596 #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1597
1598 #define radv_foreach_stage(stage, stage_bits) \
1599 for (gl_shader_stage stage, \
1600 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
1601 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1602 __tmp &= ~(1 << (stage)))
1603
1604 extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
1605 unsigned radv_format_meta_fs_key(VkFormat format);
1606
1607 struct radv_multisample_state {
1608 uint32_t db_eqaa;
1609 uint32_t pa_sc_line_cntl;
1610 uint32_t pa_sc_mode_cntl_0;
1611 uint32_t pa_sc_mode_cntl_1;
1612 uint32_t pa_sc_aa_config;
1613 uint32_t pa_sc_aa_mask[2];
1614 unsigned num_samples;
1615 };
1616
1617 struct radv_prim_vertex_count {
1618 uint8_t min;
1619 uint8_t incr;
1620 };
1621
1622 struct radv_vertex_elements_info {
1623 uint32_t format_size[MAX_VERTEX_ATTRIBS];
1624 };
1625
1626 struct radv_ia_multi_vgt_param_helpers {
1627 uint32_t base;
1628 bool partial_es_wave;
1629 uint8_t primgroup_size;
1630 bool wd_switch_on_eop;
1631 bool ia_switch_on_eoi;
1632 bool partial_vs_wave;
1633 };
1634
1635 struct radv_binning_state {
1636 uint32_t pa_sc_binner_cntl_0;
1637 uint32_t db_dfsm_control;
1638 };
1639
1640 #define SI_GS_PER_ES 128
1641
1642 struct radv_pipeline {
1643 struct vk_object_base base;
1644 struct radv_device * device;
1645 struct radv_dynamic_state dynamic_state;
1646
1647 struct radv_pipeline_layout * layout;
1648
1649 bool need_indirect_descriptor_sets;
1650 struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
1651 struct radv_shader_variant *gs_copy_shader;
1652 VkShaderStageFlags active_stages;
1653
1654 struct radeon_cmdbuf cs;
1655 uint32_t ctx_cs_hash;
1656 struct radeon_cmdbuf ctx_cs;
1657
1658 struct radv_vertex_elements_info vertex_elements;
1659
1660 uint32_t binding_stride[MAX_VBS];
1661 uint8_t num_vertex_bindings;
1662
1663 uint32_t user_data_0[MESA_SHADER_STAGES];
1664 union {
1665 struct {
1666 struct radv_multisample_state ms;
1667 struct radv_binning_state binning;
1668 uint32_t spi_baryc_cntl;
1669 bool prim_restart_enable;
1670 unsigned esgs_ring_size;
1671 unsigned gsvs_ring_size;
1672 uint32_t vtx_base_sgpr;
1673 struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
1674 uint8_t vtx_emit_num;
1675 struct radv_prim_vertex_count prim_vertex_count;
1676 bool can_use_guardband;
1677 uint32_t needed_dynamic_state;
1678 bool disable_out_of_order_rast_for_occlusion;
1679 uint8_t topology;
1680
1681 /* Used for rbplus */
1682 uint32_t col_format;
1683 uint32_t cb_target_mask;
1684 } graphics;
1685 };
1686
1687 unsigned max_waves;
1688 unsigned scratch_bytes_per_wave;
1689
1690 /* Not NULL if graphics pipeline uses streamout. */
1691 struct radv_shader_variant *streamout_shader;
1692 };
1693
1694 static inline bool radv_pipeline_has_gs(const struct radv_pipeline *pipeline)
1695 {
1696 return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1697 }
1698
1699 static inline bool radv_pipeline_has_tess(const struct radv_pipeline *pipeline)
1700 {
1701 return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;
1702 }
1703
1704 bool radv_pipeline_has_ngg(const struct radv_pipeline *pipeline);
1705
1706 bool radv_pipeline_has_ngg_passthrough(const struct radv_pipeline *pipeline);
1707
1708 bool radv_pipeline_has_gs_copy_shader(const struct radv_pipeline *pipeline);
1709
1710 struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
1711 gl_shader_stage stage,
1712 int idx);
1713
1714 struct radv_shader_variant *radv_get_shader(struct radv_pipeline *pipeline,
1715 gl_shader_stage stage);
1716
1717 struct radv_graphics_pipeline_create_info {
1718 bool use_rectlist;
1719 bool db_depth_clear;
1720 bool db_stencil_clear;
1721 bool db_depth_disable_expclear;
1722 bool db_stencil_disable_expclear;
1723 bool depth_compress_disable;
1724 bool stencil_compress_disable;
1725 bool resummarize_enable;
1726 uint32_t custom_blend_mode;
1727 };
1728
1729 VkResult
1730 radv_graphics_pipeline_create(VkDevice device,
1731 VkPipelineCache cache,
1732 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1733 const struct radv_graphics_pipeline_create_info *extra,
1734 const VkAllocationCallbacks *alloc,
1735 VkPipeline *pPipeline);
1736
1737 struct radv_binning_settings {
1738 unsigned context_states_per_bin; /* allowed range: [1, 6] */
1739 unsigned persistent_states_per_bin; /* allowed range: [1, 32] */
1740 unsigned fpovs_per_batch; /* allowed range: [0, 255], 0 = unlimited */
1741 };
1742
1743 struct radv_binning_settings
1744 radv_get_binning_settings(const struct radv_physical_device *pdev);
1745
1746 struct vk_format_description;
1747 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
1748 int first_non_void);
1749 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
1750 int first_non_void);
1751 bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
1752 uint32_t radv_translate_colorformat(VkFormat format);
1753 uint32_t radv_translate_color_numformat(VkFormat format,
1754 const struct vk_format_description *desc,
1755 int first_non_void);
1756 uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1757 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1758 uint32_t radv_translate_dbformat(VkFormat format);
1759 uint32_t radv_translate_tex_dataformat(VkFormat format,
1760 const struct vk_format_description *desc,
1761 int first_non_void);
1762 uint32_t radv_translate_tex_numformat(VkFormat format,
1763 const struct vk_format_description *desc,
1764 int first_non_void);
1765 bool radv_format_pack_clear_color(VkFormat format,
1766 uint32_t clear_vals[2],
1767 VkClearColorValue *value);
1768 bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
1769 bool radv_dcc_formats_compatible(VkFormat format1,
1770 VkFormat format2);
1771 bool radv_device_supports_etc(struct radv_physical_device *physical_device);
1772
1773 struct radv_image_plane {
1774 VkFormat format;
1775 struct radeon_surf surface;
1776 uint64_t offset;
1777 };
1778
1779 struct radv_image {
1780 struct vk_object_base base;
1781 VkImageType type;
1782 /* The original VkFormat provided by the client. This may not match any
1783 * of the actual surface formats.
1784 */
1785 VkFormat vk_format;
1786 VkImageAspectFlags aspects;
1787 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1788 struct ac_surf_info info;
1789 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1790 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1791
1792 VkDeviceSize size;
1793 uint32_t alignment;
1794
1795 unsigned queue_family_mask;
1796 bool exclusive;
1797 bool shareable;
1798
1799 /* Set when bound */
1800 struct radeon_winsys_bo *bo;
1801 VkDeviceSize offset;
1802 uint64_t dcc_offset;
1803 uint64_t htile_offset;
1804 bool tc_compatible_htile;
1805 bool tc_compatible_cmask;
1806
1807 uint64_t cmask_offset;
1808 uint64_t fmask_offset;
1809 uint64_t clear_value_offset;
1810 uint64_t fce_pred_offset;
1811 uint64_t dcc_pred_offset;
1812
1813 /*
1814 * Metadata for the TC-compat zrange workaround. If the 32-bit value
1815 * stored at this offset is UINT_MAX, the driver will emit
1816 * DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
1817 * SET_CONTEXT_REG packet.
1818 */
1819 uint64_t tc_compat_zrange_offset;
1820
1821 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1822 VkDeviceMemory owned_memory;
1823
1824 unsigned plane_count;
1825 struct radv_image_plane planes[0];
1826 };
1827
1828 /* Whether the image has a htile that is known consistent with the contents of
1829 * the image and is allowed to be in compressed form.
1830 *
1831 * If this is false reads that don't use the htile should be able to return
1832 * correct results.
1833 */
1834 bool radv_layout_is_htile_compressed(const struct radv_image *image,
1835 VkImageLayout layout,
1836 bool in_render_loop,
1837 unsigned queue_mask);
1838
1839 bool radv_layout_can_fast_clear(const struct radv_image *image,
1840 VkImageLayout layout,
1841 bool in_render_loop,
1842 unsigned queue_mask);
1843
1844 bool radv_layout_dcc_compressed(const struct radv_device *device,
1845 const struct radv_image *image,
1846 VkImageLayout layout,
1847 bool in_render_loop,
1848 unsigned queue_mask);
1849
1850 /**
1851 * Return whether the image has CMASK metadata for color surfaces.
1852 */
1853 static inline bool
1854 radv_image_has_cmask(const struct radv_image *image)
1855 {
1856 return image->cmask_offset;
1857 }
1858
1859 /**
1860 * Return whether the image has FMASK metadata for color surfaces.
1861 */
1862 static inline bool
1863 radv_image_has_fmask(const struct radv_image *image)
1864 {
1865 return image->fmask_offset;
1866 }
1867
1868 /**
1869 * Return whether the image has DCC metadata for color surfaces.
1870 */
1871 static inline bool
1872 radv_image_has_dcc(const struct radv_image *image)
1873 {
1874 return image->planes[0].surface.dcc_size;
1875 }
1876
1877 /**
1878 * Return whether the image is TC-compatible CMASK.
1879 */
1880 static inline bool
1881 radv_image_is_tc_compat_cmask(const struct radv_image *image)
1882 {
1883 return radv_image_has_fmask(image) && image->tc_compatible_cmask;
1884 }
1885
1886 /**
1887 * Return whether DCC metadata is enabled for a level.
1888 */
1889 static inline bool
1890 radv_dcc_enabled(const struct radv_image *image, unsigned level)
1891 {
1892 return radv_image_has_dcc(image) &&
1893 level < image->planes[0].surface.num_dcc_levels;
1894 }
1895
1896 /**
1897 * Return whether the image has CB metadata.
1898 */
1899 static inline bool
1900 radv_image_has_CB_metadata(const struct radv_image *image)
1901 {
1902 return radv_image_has_cmask(image) ||
1903 radv_image_has_fmask(image) ||
1904 radv_image_has_dcc(image);
1905 }
1906
1907 /**
1908 * Return whether the image has HTILE metadata for depth surfaces.
1909 */
1910 static inline bool
1911 radv_image_has_htile(const struct radv_image *image)
1912 {
1913 return image->planes[0].surface.htile_size;
1914 }
1915
1916 /**
1917 * Return whether HTILE metadata is enabled for a level.
1918 */
1919 static inline bool
1920 radv_htile_enabled(const struct radv_image *image, unsigned level)
1921 {
1922 return radv_image_has_htile(image) && level == 0;
1923 }
1924
1925 /**
1926 * Return whether the image is TC-compatible HTILE.
1927 */
1928 static inline bool
1929 radv_image_is_tc_compat_htile(const struct radv_image *image)
1930 {
1931 return radv_image_has_htile(image) && image->tc_compatible_htile;
1932 }
1933
1934 static inline uint64_t
1935 radv_image_get_fast_clear_va(const struct radv_image *image,
1936 uint32_t base_level)
1937 {
1938 uint64_t va = radv_buffer_get_va(image->bo);
1939 va += image->offset + image->clear_value_offset + base_level * 8;
1940 return va;
1941 }
1942
1943 static inline uint64_t
1944 radv_image_get_fce_pred_va(const struct radv_image *image,
1945 uint32_t base_level)
1946 {
1947 uint64_t va = radv_buffer_get_va(image->bo);
1948 va += image->offset + image->fce_pred_offset + base_level * 8;
1949 return va;
1950 }
1951
1952 static inline uint64_t
1953 radv_image_get_dcc_pred_va(const struct radv_image *image,
1954 uint32_t base_level)
1955 {
1956 uint64_t va = radv_buffer_get_va(image->bo);
1957 va += image->offset + image->dcc_pred_offset + base_level * 8;
1958 return va;
1959 }
1960
1961 static inline uint64_t
1962 radv_get_tc_compat_zrange_va(const struct radv_image *image,
1963 uint32_t base_level)
1964 {
1965 uint64_t va = radv_buffer_get_va(image->bo);
1966 va += image->offset + image->tc_compat_zrange_offset + base_level * 4;
1967 return va;
1968 }
1969
1970 static inline uint64_t
1971 radv_get_ds_clear_value_va(const struct radv_image *image,
1972 uint32_t base_level)
1973 {
1974 uint64_t va = radv_buffer_get_va(image->bo);
1975 va += image->offset + image->clear_value_offset + base_level * 8;
1976 return va;
1977 }
1978
1979 unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
1980
1981 static inline uint32_t
1982 radv_get_layerCount(const struct radv_image *image,
1983 const VkImageSubresourceRange *range)
1984 {
1985 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1986 image->info.array_size - range->baseArrayLayer : range->layerCount;
1987 }
1988
1989 static inline uint32_t
1990 radv_get_levelCount(const struct radv_image *image,
1991 const VkImageSubresourceRange *range)
1992 {
1993 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1994 image->info.levels - range->baseMipLevel : range->levelCount;
1995 }
1996
1997 struct radeon_bo_metadata;
1998 void
1999 radv_init_metadata(struct radv_device *device,
2000 struct radv_image *image,
2001 struct radeon_bo_metadata *metadata);
2002
2003 void
2004 radv_image_override_offset_stride(struct radv_device *device,
2005 struct radv_image *image,
2006 uint64_t offset, uint32_t stride);
2007
2008 union radv_descriptor {
2009 struct {
2010 uint32_t plane0_descriptor[8];
2011 uint32_t fmask_descriptor[8];
2012 };
2013 struct {
2014 uint32_t plane_descriptors[3][8];
2015 };
2016 };
2017
2018 struct radv_image_view {
2019 struct vk_object_base base;
2020 struct radv_image *image; /**< VkImageViewCreateInfo::image */
2021 struct radeon_winsys_bo *bo;
2022
2023 VkImageViewType type;
2024 VkImageAspectFlags aspect_mask;
2025 VkFormat vk_format;
2026 unsigned plane_id;
2027 bool multiple_planes;
2028 uint32_t base_layer;
2029 uint32_t layer_count;
2030 uint32_t base_mip;
2031 uint32_t level_count;
2032 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2033
2034 union radv_descriptor descriptor;
2035
2036 /* Descriptor for use as a storage image as opposed to a sampled image.
2037 * This has a few differences for cube maps (e.g. type).
2038 */
2039 union radv_descriptor storage_descriptor;
2040 };
2041
2042 struct radv_image_create_info {
2043 const VkImageCreateInfo *vk_info;
2044 bool scanout;
2045 bool no_metadata_planes;
2046 const struct radeon_bo_metadata *bo_metadata;
2047 };
2048
2049 VkResult
2050 radv_image_create_layout(struct radv_device *device,
2051 struct radv_image_create_info create_info,
2052 struct radv_image *image);
2053
2054 VkResult radv_image_create(VkDevice _device,
2055 const struct radv_image_create_info *info,
2056 const VkAllocationCallbacks* alloc,
2057 VkImage *pImage);
2058
2059 bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format);
2060
2061 VkResult
2062 radv_image_from_gralloc(VkDevice device_h,
2063 const VkImageCreateInfo *base_info,
2064 const VkNativeBufferANDROID *gralloc_info,
2065 const VkAllocationCallbacks *alloc,
2066 VkImage *out_image_h);
2067 uint64_t
2068 radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
2069 const VkImageUsageFlags vk_usage);
2070 VkResult
2071 radv_import_ahb_memory(struct radv_device *device,
2072 struct radv_device_memory *mem,
2073 unsigned priority,
2074 const VkImportAndroidHardwareBufferInfoANDROID *info);
2075 VkResult
2076 radv_create_ahb_memory(struct radv_device *device,
2077 struct radv_device_memory *mem,
2078 unsigned priority,
2079 const VkMemoryAllocateInfo *pAllocateInfo);
2080
2081 VkFormat
2082 radv_select_android_external_format(const void *next, VkFormat default_format);
2083
2084 bool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage);
2085
2086 struct radv_image_view_extra_create_info {
2087 bool disable_compression;
2088 };
2089
2090 void radv_image_view_init(struct radv_image_view *view,
2091 struct radv_device *device,
2092 const VkImageViewCreateInfo *pCreateInfo,
2093 const struct radv_image_view_extra_create_info* extra_create_info);
2094
2095 VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
2096
2097 struct radv_sampler_ycbcr_conversion {
2098 struct vk_object_base base;
2099 VkFormat format;
2100 VkSamplerYcbcrModelConversion ycbcr_model;
2101 VkSamplerYcbcrRange ycbcr_range;
2102 VkComponentMapping components;
2103 VkChromaLocation chroma_offsets[2];
2104 VkFilter chroma_filter;
2105 };
2106
2107 struct radv_buffer_view {
2108 struct vk_object_base base;
2109 struct radeon_winsys_bo *bo;
2110 VkFormat vk_format;
2111 uint64_t range; /**< VkBufferViewCreateInfo::range */
2112 uint32_t state[4];
2113 };
2114 void radv_buffer_view_init(struct radv_buffer_view *view,
2115 struct radv_device *device,
2116 const VkBufferViewCreateInfo* pCreateInfo);
2117
2118 static inline struct VkExtent3D
2119 radv_sanitize_image_extent(const VkImageType imageType,
2120 const struct VkExtent3D imageExtent)
2121 {
2122 switch (imageType) {
2123 case VK_IMAGE_TYPE_1D:
2124 return (VkExtent3D) { imageExtent.width, 1, 1 };
2125 case VK_IMAGE_TYPE_2D:
2126 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
2127 case VK_IMAGE_TYPE_3D:
2128 return imageExtent;
2129 default:
2130 unreachable("invalid image type");
2131 }
2132 }
2133
2134 static inline struct VkOffset3D
2135 radv_sanitize_image_offset(const VkImageType imageType,
2136 const struct VkOffset3D imageOffset)
2137 {
2138 switch (imageType) {
2139 case VK_IMAGE_TYPE_1D:
2140 return (VkOffset3D) { imageOffset.x, 0, 0 };
2141 case VK_IMAGE_TYPE_2D:
2142 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
2143 case VK_IMAGE_TYPE_3D:
2144 return imageOffset;
2145 default:
2146 unreachable("invalid image type");
2147 }
2148 }
2149
2150 static inline bool
2151 radv_image_extent_compare(const struct radv_image *image,
2152 const VkExtent3D *extent)
2153 {
2154 if (extent->width != image->info.width ||
2155 extent->height != image->info.height ||
2156 extent->depth != image->info.depth)
2157 return false;
2158 return true;
2159 }
2160
2161 struct radv_sampler {
2162 struct vk_object_base base;
2163 uint32_t state[4];
2164 struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
2165 };
2166
2167 struct radv_framebuffer {
2168 struct vk_object_base base;
2169 uint32_t width;
2170 uint32_t height;
2171 uint32_t layers;
2172
2173 uint32_t attachment_count;
2174 struct radv_image_view *attachments[0];
2175 };
2176
2177 struct radv_subpass_barrier {
2178 VkPipelineStageFlags src_stage_mask;
2179 VkAccessFlags src_access_mask;
2180 VkAccessFlags dst_access_mask;
2181 };
2182
2183 void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
2184 const struct radv_subpass_barrier *barrier);
2185
2186 struct radv_subpass_attachment {
2187 uint32_t attachment;
2188 VkImageLayout layout;
2189 VkImageLayout stencil_layout;
2190 bool in_render_loop;
2191 };
2192
2193 struct radv_subpass {
2194 uint32_t attachment_count;
2195 struct radv_subpass_attachment * attachments;
2196
2197 uint32_t input_count;
2198 uint32_t color_count;
2199 struct radv_subpass_attachment * input_attachments;
2200 struct radv_subpass_attachment * color_attachments;
2201 struct radv_subpass_attachment * resolve_attachments;
2202 struct radv_subpass_attachment * depth_stencil_attachment;
2203 struct radv_subpass_attachment * ds_resolve_attachment;
2204 VkResolveModeFlagBits depth_resolve_mode;
2205 VkResolveModeFlagBits stencil_resolve_mode;
2206
2207 /** Subpass has at least one color resolve attachment */
2208 bool has_color_resolve;
2209
2210 /** Subpass has at least one color attachment */
2211 bool has_color_att;
2212
2213 struct radv_subpass_barrier start_barrier;
2214
2215 uint32_t view_mask;
2216
2217 VkSampleCountFlagBits color_sample_count;
2218 VkSampleCountFlagBits depth_sample_count;
2219 VkSampleCountFlagBits max_sample_count;
2220 };
2221
2222 uint32_t
2223 radv_get_subpass_id(struct radv_cmd_buffer *cmd_buffer);
2224
2225 struct radv_render_pass_attachment {
2226 VkFormat format;
2227 uint32_t samples;
2228 VkAttachmentLoadOp load_op;
2229 VkAttachmentLoadOp stencil_load_op;
2230 VkImageLayout initial_layout;
2231 VkImageLayout final_layout;
2232 VkImageLayout stencil_initial_layout;
2233 VkImageLayout stencil_final_layout;
2234
2235 /* The subpass id in which the attachment will be used first/last. */
2236 uint32_t first_subpass_idx;
2237 uint32_t last_subpass_idx;
2238 };
2239
2240 struct radv_render_pass {
2241 struct vk_object_base base;
2242 uint32_t attachment_count;
2243 uint32_t subpass_count;
2244 struct radv_subpass_attachment * subpass_attachments;
2245 struct radv_render_pass_attachment * attachments;
2246 struct radv_subpass_barrier end_barrier;
2247 struct radv_subpass subpasses[0];
2248 };
2249
2250 VkResult radv_device_init_meta(struct radv_device *device);
2251 void radv_device_finish_meta(struct radv_device *device);
2252
2253 struct radv_query_pool {
2254 struct vk_object_base base;
2255 struct radeon_winsys_bo *bo;
2256 uint32_t stride;
2257 uint32_t availability_offset;
2258 uint64_t size;
2259 char *ptr;
2260 VkQueryType type;
2261 uint32_t pipeline_stats_mask;
2262 };
2263
2264 typedef enum {
2265 RADV_SEMAPHORE_NONE,
2266 RADV_SEMAPHORE_WINSYS,
2267 RADV_SEMAPHORE_SYNCOBJ,
2268 RADV_SEMAPHORE_TIMELINE,
2269 } radv_semaphore_kind;
2270
2271 struct radv_deferred_queue_submission;
2272
2273 struct radv_timeline_waiter {
2274 struct list_head list;
2275 struct radv_deferred_queue_submission *submission;
2276 uint64_t value;
2277 };
2278
2279 struct radv_timeline_point {
2280 struct list_head list;
2281
2282 uint64_t value;
2283 uint32_t syncobj;
2284
2285 /* Separate from the list to accomodate CPU wait being async, as well
2286 * as prevent point deletion during submission. */
2287 unsigned wait_count;
2288 };
2289
2290 struct radv_timeline {
2291 /* Using a pthread mutex to be compatible with condition variables. */
2292 pthread_mutex_t mutex;
2293
2294 uint64_t highest_signaled;
2295 uint64_t highest_submitted;
2296
2297 struct list_head points;
2298
2299 /* Keep free points on hand so we do not have to recreate syncobjs all
2300 * the time. */
2301 struct list_head free_points;
2302
2303 /* Submissions that are deferred waiting for a specific value to be
2304 * submitted. */
2305 struct list_head waiters;
2306 };
2307
2308 struct radv_semaphore_part {
2309 radv_semaphore_kind kind;
2310 union {
2311 uint32_t syncobj;
2312 struct radeon_winsys_sem *ws_sem;
2313 struct radv_timeline timeline;
2314 };
2315 };
2316
2317 struct radv_semaphore {
2318 struct vk_object_base base;
2319 struct radv_semaphore_part permanent;
2320 struct radv_semaphore_part temporary;
2321 };
2322
2323 bool radv_queue_internal_submit(struct radv_queue *queue,
2324 struct radeon_cmdbuf *cs);
2325
2326 void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2327 VkPipelineBindPoint bind_point,
2328 struct radv_descriptor_set *set,
2329 unsigned idx);
2330
2331 void
2332 radv_update_descriptor_sets(struct radv_device *device,
2333 struct radv_cmd_buffer *cmd_buffer,
2334 VkDescriptorSet overrideSet,
2335 uint32_t descriptorWriteCount,
2336 const VkWriteDescriptorSet *pDescriptorWrites,
2337 uint32_t descriptorCopyCount,
2338 const VkCopyDescriptorSet *pDescriptorCopies);
2339
2340 void
2341 radv_update_descriptor_set_with_template(struct radv_device *device,
2342 struct radv_cmd_buffer *cmd_buffer,
2343 struct radv_descriptor_set *set,
2344 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
2345 const void *pData);
2346
2347 void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2348 VkPipelineBindPoint pipelineBindPoint,
2349 VkPipelineLayout _layout,
2350 uint32_t set,
2351 uint32_t descriptorWriteCount,
2352 const VkWriteDescriptorSet *pDescriptorWrites);
2353
2354 void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
2355 struct radv_image *image,
2356 const VkImageSubresourceRange *range, uint32_t value);
2357
2358 void radv_initialize_fmask(struct radv_cmd_buffer *cmd_buffer,
2359 struct radv_image *image,
2360 const VkImageSubresourceRange *range);
2361
2362 struct radv_fence {
2363 struct vk_object_base base;
2364 struct radeon_winsys_fence *fence;
2365 struct wsi_fence *fence_wsi;
2366
2367 uint32_t syncobj;
2368 uint32_t temp_syncobj;
2369 };
2370
2371 /* radv_nir_to_llvm.c */
2372 struct radv_shader_args;
2373
2374 void llvm_compile_shader(struct radv_device *device,
2375 unsigned shader_count,
2376 struct nir_shader *const *shaders,
2377 struct radv_shader_binary **binary,
2378 struct radv_shader_args *args);
2379
2380 unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class,
2381 gl_shader_stage stage,
2382 const struct nir_shader *nir);
2383
2384 /* radv_shader_info.h */
2385 struct radv_shader_info;
2386 struct radv_shader_variant_key;
2387
2388 void radv_nir_shader_info_pass(const struct nir_shader *nir,
2389 const struct radv_pipeline_layout *layout,
2390 const struct radv_shader_variant_key *key,
2391 struct radv_shader_info *info,
2392 bool use_aco);
2393
2394 void radv_nir_shader_info_init(struct radv_shader_info *info);
2395
2396 /* radv_sqtt.c */
2397 struct radv_thread_trace_info {
2398 uint32_t cur_offset;
2399 uint32_t trace_status;
2400 union {
2401 uint32_t gfx9_write_counter;
2402 uint32_t gfx10_dropped_cntr;
2403 };
2404 };
2405
2406 struct radv_thread_trace_se {
2407 struct radv_thread_trace_info info;
2408 void *data_ptr;
2409 uint32_t shader_engine;
2410 uint32_t compute_unit;
2411 };
2412
2413 struct radv_thread_trace {
2414 uint32_t num_traces;
2415 struct radv_thread_trace_se traces[4];
2416 };
2417
2418 bool radv_thread_trace_init(struct radv_device *device);
2419 void radv_thread_trace_finish(struct radv_device *device);
2420 bool radv_begin_thread_trace(struct radv_queue *queue);
2421 bool radv_end_thread_trace(struct radv_queue *queue);
2422 bool radv_get_thread_trace(struct radv_queue *queue,
2423 struct radv_thread_trace *thread_trace);
2424 void radv_emit_thread_trace_userdata(struct radeon_cmdbuf *cs,
2425 const void *data, uint32_t num_dwords);
2426
2427 /* radv_rgp.c */
2428 int radv_dump_thread_trace(struct radv_device *device,
2429 const struct radv_thread_trace *trace);
2430
2431 /* radv_sqtt_layer_.c */
2432 struct radv_barrier_data {
2433 union {
2434 struct {
2435 uint16_t depth_stencil_expand : 1;
2436 uint16_t htile_hiz_range_expand : 1;
2437 uint16_t depth_stencil_resummarize : 1;
2438 uint16_t dcc_decompress : 1;
2439 uint16_t fmask_decompress : 1;
2440 uint16_t fast_clear_eliminate : 1;
2441 uint16_t fmask_color_expand : 1;
2442 uint16_t init_mask_ram : 1;
2443 uint16_t reserved : 8;
2444 };
2445 uint16_t all;
2446 } layout_transitions;
2447 };
2448
2449 /**
2450 * Value for the reason field of an RGP barrier start marker originating from
2451 * the Vulkan client (does not include PAL-defined values). (Table 15)
2452 */
2453 enum rgp_barrier_reason {
2454 RGP_BARRIER_UNKNOWN_REASON = 0xFFFFFFFF,
2455
2456 /* External app-generated barrier reasons, i.e. API synchronization
2457 * commands Range of valid values: [0x00000001 ... 0x7FFFFFFF].
2458 */
2459 RGP_BARRIER_EXTERNAL_CMD_PIPELINE_BARRIER = 0x00000001,
2460 RGP_BARRIER_EXTERNAL_RENDER_PASS_SYNC = 0x00000002,
2461 RGP_BARRIER_EXTERNAL_CMD_WAIT_EVENTS = 0x00000003,
2462
2463 /* Internal barrier reasons, i.e. implicit synchronization inserted by
2464 * the Vulkan driver Range of valid values: [0xC0000000 ... 0xFFFFFFFE].
2465 */
2466 RGP_BARRIER_INTERNAL_BASE = 0xC0000000,
2467 RGP_BARRIER_INTERNAL_PRE_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 0,
2468 RGP_BARRIER_INTERNAL_POST_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 1,
2469 RGP_BARRIER_INTERNAL_GPU_EVENT_RECYCLE_STALL = RGP_BARRIER_INTERNAL_BASE + 2,
2470 RGP_BARRIER_INTERNAL_PRE_COPY_QUERY_POOL_RESULTS_SYNC = RGP_BARRIER_INTERNAL_BASE + 3
2471 };
2472
2473 void radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
2474 void radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
2475 void radv_describe_draw(struct radv_cmd_buffer *cmd_buffer);
2476 void radv_describe_dispatch(struct radv_cmd_buffer *cmd_buffer, int x, int y, int z);
2477 void radv_describe_begin_render_pass_clear(struct radv_cmd_buffer *cmd_buffer,
2478 VkImageAspectFlagBits aspects);
2479 void radv_describe_end_render_pass_clear(struct radv_cmd_buffer *cmd_buffer);
2480 void radv_describe_barrier_start(struct radv_cmd_buffer *cmd_buffer,
2481 enum rgp_barrier_reason reason);
2482 void radv_describe_barrier_end(struct radv_cmd_buffer *cmd_buffer);
2483 void radv_describe_layout_transition(struct radv_cmd_buffer *cmd_buffer,
2484 const struct radv_barrier_data *barrier);
2485
2486 struct radeon_winsys_sem;
2487
2488 uint64_t radv_get_current_time(void);
2489
2490 static inline uint32_t
2491 si_conv_gl_prim_to_vertices(unsigned gl_prim)
2492 {
2493 switch (gl_prim) {
2494 case 0: /* GL_POINTS */
2495 return 1;
2496 case 1: /* GL_LINES */
2497 case 3: /* GL_LINE_STRIP */
2498 return 2;
2499 case 4: /* GL_TRIANGLES */
2500 case 5: /* GL_TRIANGLE_STRIP */
2501 return 3;
2502 case 0xA: /* GL_LINE_STRIP_ADJACENCY_ARB */
2503 return 4;
2504 case 0xc: /* GL_TRIANGLES_ADJACENCY_ARB */
2505 return 6;
2506 case 7: /* GL_QUADS */
2507 return V_028A6C_OUTPRIM_TYPE_TRISTRIP;
2508 default:
2509 assert(0);
2510 return 0;
2511 }
2512 }
2513
2514 void radv_cmd_buffer_begin_render_pass(struct radv_cmd_buffer *cmd_buffer,
2515 const VkRenderPassBeginInfo *pRenderPassBegin);
2516 void radv_cmd_buffer_end_render_pass(struct radv_cmd_buffer *cmd_buffer);
2517
2518 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
2519 \
2520 static inline struct __radv_type * \
2521 __radv_type ## _from_handle(__VkType _handle) \
2522 { \
2523 return (struct __radv_type *) _handle; \
2524 } \
2525 \
2526 static inline __VkType \
2527 __radv_type ## _to_handle(struct __radv_type *_obj) \
2528 { \
2529 return (__VkType) _obj; \
2530 }
2531
2532 #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
2533 \
2534 static inline struct __radv_type * \
2535 __radv_type ## _from_handle(__VkType _handle) \
2536 { \
2537 return (struct __radv_type *)(uintptr_t) _handle; \
2538 } \
2539 \
2540 static inline __VkType \
2541 __radv_type ## _to_handle(struct __radv_type *_obj) \
2542 { \
2543 return (__VkType)(uintptr_t) _obj; \
2544 }
2545
2546 #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
2547 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
2548
2549 RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
2550 RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
2551 RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
2552 RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
2553 RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
2554
2555 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
2556 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
2557 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
2558 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
2559 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
2560 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
2561 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)
2562 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
2563 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
2564 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
2565 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
2566 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
2567 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
2568 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
2569 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
2570 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
2571 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
2572 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
2573 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
2574 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
2575 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
2576 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
2577
2578 #endif /* RADV_PRIVATE_H */