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