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