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