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