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