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