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