radv/gfx10: disable the TC compat zrange workaround
[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 void
1395 radv_hash_shaders(unsigned char *hash,
1396 const VkPipelineShaderStageCreateInfo **stages,
1397 const struct radv_pipeline_layout *layout,
1398 const struct radv_pipeline_key *key,
1399 uint32_t flags);
1400
1401 static inline gl_shader_stage
1402 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1403 {
1404 assert(__builtin_popcount(vk_stage) == 1);
1405 return ffs(vk_stage) - 1;
1406 }
1407
1408 static inline VkShaderStageFlagBits
1409 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1410 {
1411 return (1 << mesa_stage);
1412 }
1413
1414 #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1415
1416 #define radv_foreach_stage(stage, stage_bits) \
1417 for (gl_shader_stage stage, \
1418 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
1419 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1420 __tmp &= ~(1 << (stage)))
1421
1422 extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
1423 unsigned radv_format_meta_fs_key(VkFormat format);
1424
1425 struct radv_multisample_state {
1426 uint32_t db_eqaa;
1427 uint32_t pa_sc_line_cntl;
1428 uint32_t pa_sc_mode_cntl_0;
1429 uint32_t pa_sc_mode_cntl_1;
1430 uint32_t pa_sc_aa_config;
1431 uint32_t pa_sc_aa_mask[2];
1432 unsigned num_samples;
1433 };
1434
1435 struct radv_prim_vertex_count {
1436 uint8_t min;
1437 uint8_t incr;
1438 };
1439
1440 struct radv_vertex_elements_info {
1441 uint32_t format_size[MAX_VERTEX_ATTRIBS];
1442 };
1443
1444 struct radv_ia_multi_vgt_param_helpers {
1445 uint32_t base;
1446 bool partial_es_wave;
1447 uint8_t primgroup_size;
1448 bool wd_switch_on_eop;
1449 bool ia_switch_on_eoi;
1450 bool partial_vs_wave;
1451 };
1452
1453 #define SI_GS_PER_ES 128
1454
1455 struct radv_pipeline {
1456 struct radv_device * device;
1457 struct radv_dynamic_state dynamic_state;
1458
1459 struct radv_pipeline_layout * layout;
1460
1461 bool need_indirect_descriptor_sets;
1462 struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
1463 struct radv_shader_variant *gs_copy_shader;
1464 VkShaderStageFlags active_stages;
1465
1466 struct radeon_cmdbuf cs;
1467 uint32_t ctx_cs_hash;
1468 struct radeon_cmdbuf ctx_cs;
1469
1470 struct radv_vertex_elements_info vertex_elements;
1471
1472 uint32_t binding_stride[MAX_VBS];
1473 uint8_t num_vertex_bindings;
1474
1475 uint32_t user_data_0[MESA_SHADER_STAGES];
1476 union {
1477 struct {
1478 struct radv_multisample_state ms;
1479 uint32_t spi_baryc_cntl;
1480 bool prim_restart_enable;
1481 unsigned esgs_ring_size;
1482 unsigned gsvs_ring_size;
1483 uint32_t vtx_base_sgpr;
1484 struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
1485 uint8_t vtx_emit_num;
1486 struct radv_prim_vertex_count prim_vertex_count;
1487 bool can_use_guardband;
1488 uint32_t needed_dynamic_state;
1489 bool disable_out_of_order_rast_for_occlusion;
1490
1491 /* Used for rbplus */
1492 uint32_t col_format;
1493 uint32_t cb_target_mask;
1494 } graphics;
1495 };
1496
1497 unsigned max_waves;
1498 unsigned scratch_bytes_per_wave;
1499
1500 /* Not NULL if graphics pipeline uses streamout. */
1501 struct radv_shader_variant *streamout_shader;
1502 };
1503
1504 static inline bool radv_pipeline_has_gs(const struct radv_pipeline *pipeline)
1505 {
1506 return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1507 }
1508
1509 static inline bool radv_pipeline_has_tess(const struct radv_pipeline *pipeline)
1510 {
1511 return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;
1512 }
1513
1514 bool radv_pipeline_has_ngg(const struct radv_pipeline *pipeline);
1515
1516 bool radv_pipeline_has_gs_copy_shader(const struct radv_pipeline *pipeline);
1517
1518 struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
1519 gl_shader_stage stage,
1520 int idx);
1521
1522 struct radv_shader_variant *radv_get_shader(struct radv_pipeline *pipeline,
1523 gl_shader_stage stage);
1524
1525 struct radv_graphics_pipeline_create_info {
1526 bool use_rectlist;
1527 bool db_depth_clear;
1528 bool db_stencil_clear;
1529 bool db_depth_disable_expclear;
1530 bool db_stencil_disable_expclear;
1531 bool db_flush_depth_inplace;
1532 bool db_flush_stencil_inplace;
1533 bool db_resummarize;
1534 uint32_t custom_blend_mode;
1535 };
1536
1537 VkResult
1538 radv_graphics_pipeline_create(VkDevice device,
1539 VkPipelineCache cache,
1540 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1541 const struct radv_graphics_pipeline_create_info *extra,
1542 const VkAllocationCallbacks *alloc,
1543 VkPipeline *pPipeline);
1544
1545 struct vk_format_description;
1546 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
1547 int first_non_void);
1548 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
1549 int first_non_void);
1550 bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
1551 uint32_t radv_translate_colorformat(VkFormat format);
1552 uint32_t radv_translate_color_numformat(VkFormat format,
1553 const struct vk_format_description *desc,
1554 int first_non_void);
1555 uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1556 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1557 uint32_t radv_translate_dbformat(VkFormat format);
1558 uint32_t radv_translate_tex_dataformat(VkFormat format,
1559 const struct vk_format_description *desc,
1560 int first_non_void);
1561 uint32_t radv_translate_tex_numformat(VkFormat format,
1562 const struct vk_format_description *desc,
1563 int first_non_void);
1564 bool radv_format_pack_clear_color(VkFormat format,
1565 uint32_t clear_vals[2],
1566 VkClearColorValue *value);
1567 bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
1568 bool radv_dcc_formats_compatible(VkFormat format1,
1569 VkFormat format2);
1570 bool radv_device_supports_etc(struct radv_physical_device *physical_device);
1571
1572 struct radv_fmask_info {
1573 uint64_t offset;
1574 uint64_t size;
1575 unsigned alignment;
1576 unsigned pitch_in_pixels;
1577 unsigned bank_height;
1578 unsigned slice_tile_max;
1579 unsigned tile_mode_index;
1580 unsigned tile_swizzle;
1581 uint64_t slice_size;
1582 };
1583
1584 struct radv_cmask_info {
1585 uint64_t offset;
1586 uint64_t size;
1587 unsigned alignment;
1588 unsigned slice_tile_max;
1589 unsigned slice_size;
1590 };
1591
1592
1593 struct radv_image_plane {
1594 VkFormat format;
1595 struct radeon_surf surface;
1596 uint64_t offset;
1597 };
1598
1599 struct radv_image {
1600 VkImageType type;
1601 /* The original VkFormat provided by the client. This may not match any
1602 * of the actual surface formats.
1603 */
1604 VkFormat vk_format;
1605 VkImageAspectFlags aspects;
1606 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1607 struct ac_surf_info info;
1608 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1609 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1610
1611 VkDeviceSize size;
1612 uint32_t alignment;
1613
1614 unsigned queue_family_mask;
1615 bool exclusive;
1616 bool shareable;
1617
1618 /* Set when bound */
1619 struct radeon_winsys_bo *bo;
1620 VkDeviceSize offset;
1621 uint64_t dcc_offset;
1622 uint64_t htile_offset;
1623 bool tc_compatible_htile;
1624 bool tc_compatible_cmask;
1625
1626 struct radv_fmask_info fmask;
1627 struct radv_cmask_info cmask;
1628 uint64_t clear_value_offset;
1629 uint64_t fce_pred_offset;
1630 uint64_t dcc_pred_offset;
1631
1632 /*
1633 * Metadata for the TC-compat zrange workaround. If the 32-bit value
1634 * stored at this offset is UINT_MAX, the driver will emit
1635 * DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
1636 * SET_CONTEXT_REG packet.
1637 */
1638 uint64_t tc_compat_zrange_offset;
1639
1640 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1641 VkDeviceMemory owned_memory;
1642
1643 unsigned plane_count;
1644 struct radv_image_plane planes[0];
1645 };
1646
1647 /* Whether the image has a htile that is known consistent with the contents of
1648 * the image. */
1649 bool radv_layout_has_htile(const struct radv_image *image,
1650 VkImageLayout layout,
1651 unsigned queue_mask);
1652
1653 /* Whether the image has a htile that is known consistent with the contents of
1654 * the image and is allowed to be in compressed form.
1655 *
1656 * If this is false reads that don't use the htile should be able to return
1657 * correct results.
1658 */
1659 bool radv_layout_is_htile_compressed(const struct radv_image *image,
1660 VkImageLayout layout,
1661 unsigned queue_mask);
1662
1663 bool radv_layout_can_fast_clear(const struct radv_image *image,
1664 VkImageLayout layout,
1665 unsigned queue_mask);
1666
1667 bool radv_layout_dcc_compressed(const struct radv_image *image,
1668 VkImageLayout layout,
1669 unsigned queue_mask);
1670
1671 /**
1672 * Return whether the image has CMASK metadata for color surfaces.
1673 */
1674 static inline bool
1675 radv_image_has_cmask(const struct radv_image *image)
1676 {
1677 return image->cmask.size;
1678 }
1679
1680 /**
1681 * Return whether the image has FMASK metadata for color surfaces.
1682 */
1683 static inline bool
1684 radv_image_has_fmask(const struct radv_image *image)
1685 {
1686 return image->fmask.size;
1687 }
1688
1689 /**
1690 * Return whether the image has DCC metadata for color surfaces.
1691 */
1692 static inline bool
1693 radv_image_has_dcc(const struct radv_image *image)
1694 {
1695 return image->planes[0].surface.dcc_size;
1696 }
1697
1698 /**
1699 * Return whether the image is TC-compatible CMASK.
1700 */
1701 static inline bool
1702 radv_image_is_tc_compat_cmask(const struct radv_image *image)
1703 {
1704 return radv_image_has_fmask(image) && image->tc_compatible_cmask;
1705 }
1706
1707 /**
1708 * Return whether DCC metadata is enabled for a level.
1709 */
1710 static inline bool
1711 radv_dcc_enabled(const struct radv_image *image, unsigned level)
1712 {
1713 return radv_image_has_dcc(image) &&
1714 level < image->planes[0].surface.num_dcc_levels;
1715 }
1716
1717 /**
1718 * Return whether the image has CB metadata.
1719 */
1720 static inline bool
1721 radv_image_has_CB_metadata(const struct radv_image *image)
1722 {
1723 return radv_image_has_cmask(image) ||
1724 radv_image_has_fmask(image) ||
1725 radv_image_has_dcc(image);
1726 }
1727
1728 /**
1729 * Return whether the image has HTILE metadata for depth surfaces.
1730 */
1731 static inline bool
1732 radv_image_has_htile(const struct radv_image *image)
1733 {
1734 return image->planes[0].surface.htile_size;
1735 }
1736
1737 /**
1738 * Return whether HTILE metadata is enabled for a level.
1739 */
1740 static inline bool
1741 radv_htile_enabled(const struct radv_image *image, unsigned level)
1742 {
1743 return radv_image_has_htile(image) && level == 0;
1744 }
1745
1746 /**
1747 * Return whether the image is TC-compatible HTILE.
1748 */
1749 static inline bool
1750 radv_image_is_tc_compat_htile(const struct radv_image *image)
1751 {
1752 return radv_image_has_htile(image) && image->tc_compatible_htile;
1753 }
1754
1755 static inline uint64_t
1756 radv_image_get_fast_clear_va(const struct radv_image *image,
1757 uint32_t base_level)
1758 {
1759 uint64_t va = radv_buffer_get_va(image->bo);
1760 va += image->offset + image->clear_value_offset + base_level * 8;
1761 return va;
1762 }
1763
1764 static inline uint64_t
1765 radv_image_get_fce_pred_va(const struct radv_image *image,
1766 uint32_t base_level)
1767 {
1768 uint64_t va = radv_buffer_get_va(image->bo);
1769 va += image->offset + image->fce_pred_offset + base_level * 8;
1770 return va;
1771 }
1772
1773 static inline uint64_t
1774 radv_image_get_dcc_pred_va(const struct radv_image *image,
1775 uint32_t base_level)
1776 {
1777 uint64_t va = radv_buffer_get_va(image->bo);
1778 va += image->offset + image->dcc_pred_offset + base_level * 8;
1779 return va;
1780 }
1781
1782 unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
1783
1784 static inline uint32_t
1785 radv_get_layerCount(const struct radv_image *image,
1786 const VkImageSubresourceRange *range)
1787 {
1788 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1789 image->info.array_size - range->baseArrayLayer : range->layerCount;
1790 }
1791
1792 static inline uint32_t
1793 radv_get_levelCount(const struct radv_image *image,
1794 const VkImageSubresourceRange *range)
1795 {
1796 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1797 image->info.levels - range->baseMipLevel : range->levelCount;
1798 }
1799
1800 struct radeon_bo_metadata;
1801 void
1802 radv_init_metadata(struct radv_device *device,
1803 struct radv_image *image,
1804 struct radeon_bo_metadata *metadata);
1805
1806 void
1807 radv_image_override_offset_stride(struct radv_device *device,
1808 struct radv_image *image,
1809 uint64_t offset, uint32_t stride);
1810
1811 union radv_descriptor {
1812 struct {
1813 uint32_t plane0_descriptor[8];
1814 uint32_t fmask_descriptor[8];
1815 };
1816 struct {
1817 uint32_t plane_descriptors[3][8];
1818 };
1819 };
1820
1821 struct radv_image_view {
1822 struct radv_image *image; /**< VkImageViewCreateInfo::image */
1823 struct radeon_winsys_bo *bo;
1824
1825 VkImageViewType type;
1826 VkImageAspectFlags aspect_mask;
1827 VkFormat vk_format;
1828 unsigned plane_id;
1829 bool multiple_planes;
1830 uint32_t base_layer;
1831 uint32_t layer_count;
1832 uint32_t base_mip;
1833 uint32_t level_count;
1834 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1835
1836 union radv_descriptor descriptor;
1837
1838 /* Descriptor for use as a storage image as opposed to a sampled image.
1839 * This has a few differences for cube maps (e.g. type).
1840 */
1841 union radv_descriptor storage_descriptor;
1842 };
1843
1844 struct radv_image_create_info {
1845 const VkImageCreateInfo *vk_info;
1846 bool scanout;
1847 bool no_metadata_planes;
1848 const struct radeon_bo_metadata *bo_metadata;
1849 };
1850
1851 VkResult radv_image_create(VkDevice _device,
1852 const struct radv_image_create_info *info,
1853 const VkAllocationCallbacks* alloc,
1854 VkImage *pImage);
1855
1856 VkResult
1857 radv_image_from_gralloc(VkDevice device_h,
1858 const VkImageCreateInfo *base_info,
1859 const VkNativeBufferANDROID *gralloc_info,
1860 const VkAllocationCallbacks *alloc,
1861 VkImage *out_image_h);
1862
1863 void radv_image_view_init(struct radv_image_view *view,
1864 struct radv_device *device,
1865 const VkImageViewCreateInfo* pCreateInfo);
1866
1867 VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
1868
1869 struct radv_sampler_ycbcr_conversion {
1870 VkFormat format;
1871 VkSamplerYcbcrModelConversion ycbcr_model;
1872 VkSamplerYcbcrRange ycbcr_range;
1873 VkComponentMapping components;
1874 VkChromaLocation chroma_offsets[2];
1875 VkFilter chroma_filter;
1876 };
1877
1878 struct radv_buffer_view {
1879 struct radeon_winsys_bo *bo;
1880 VkFormat vk_format;
1881 uint64_t range; /**< VkBufferViewCreateInfo::range */
1882 uint32_t state[4];
1883 };
1884 void radv_buffer_view_init(struct radv_buffer_view *view,
1885 struct radv_device *device,
1886 const VkBufferViewCreateInfo* pCreateInfo);
1887
1888 static inline struct VkExtent3D
1889 radv_sanitize_image_extent(const VkImageType imageType,
1890 const struct VkExtent3D imageExtent)
1891 {
1892 switch (imageType) {
1893 case VK_IMAGE_TYPE_1D:
1894 return (VkExtent3D) { imageExtent.width, 1, 1 };
1895 case VK_IMAGE_TYPE_2D:
1896 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1897 case VK_IMAGE_TYPE_3D:
1898 return imageExtent;
1899 default:
1900 unreachable("invalid image type");
1901 }
1902 }
1903
1904 static inline struct VkOffset3D
1905 radv_sanitize_image_offset(const VkImageType imageType,
1906 const struct VkOffset3D imageOffset)
1907 {
1908 switch (imageType) {
1909 case VK_IMAGE_TYPE_1D:
1910 return (VkOffset3D) { imageOffset.x, 0, 0 };
1911 case VK_IMAGE_TYPE_2D:
1912 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1913 case VK_IMAGE_TYPE_3D:
1914 return imageOffset;
1915 default:
1916 unreachable("invalid image type");
1917 }
1918 }
1919
1920 static inline bool
1921 radv_image_extent_compare(const struct radv_image *image,
1922 const VkExtent3D *extent)
1923 {
1924 if (extent->width != image->info.width ||
1925 extent->height != image->info.height ||
1926 extent->depth != image->info.depth)
1927 return false;
1928 return true;
1929 }
1930
1931 struct radv_sampler {
1932 uint32_t state[4];
1933 struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
1934 };
1935
1936 struct radv_color_buffer_info {
1937 uint64_t cb_color_base;
1938 uint64_t cb_color_cmask;
1939 uint64_t cb_color_fmask;
1940 uint64_t cb_dcc_base;
1941 uint32_t cb_color_slice;
1942 uint32_t cb_color_view;
1943 uint32_t cb_color_info;
1944 uint32_t cb_color_attrib;
1945 uint32_t cb_color_attrib2; /* GFX9 and later */
1946 uint32_t cb_color_attrib3; /* GFX10 and later */
1947 uint32_t cb_dcc_control;
1948 uint32_t cb_color_cmask_slice;
1949 uint32_t cb_color_fmask_slice;
1950 union {
1951 uint32_t cb_color_pitch; // GFX6-GFX8
1952 uint32_t cb_mrt_epitch; // GFX9+
1953 };
1954 };
1955
1956 struct radv_ds_buffer_info {
1957 uint64_t db_z_read_base;
1958 uint64_t db_stencil_read_base;
1959 uint64_t db_z_write_base;
1960 uint64_t db_stencil_write_base;
1961 uint64_t db_htile_data_base;
1962 uint32_t db_depth_info;
1963 uint32_t db_z_info;
1964 uint32_t db_stencil_info;
1965 uint32_t db_depth_view;
1966 uint32_t db_depth_size;
1967 uint32_t db_depth_slice;
1968 uint32_t db_htile_surface;
1969 uint32_t pa_su_poly_offset_db_fmt_cntl;
1970 uint32_t db_z_info2; /* GFX9 only */
1971 uint32_t db_stencil_info2; /* GFX9 only */
1972 float offset_scale;
1973 };
1974
1975 struct radv_attachment_info {
1976 union {
1977 struct radv_color_buffer_info cb;
1978 struct radv_ds_buffer_info ds;
1979 };
1980 struct radv_image_view *attachment;
1981 };
1982
1983 struct radv_framebuffer {
1984 uint32_t width;
1985 uint32_t height;
1986 uint32_t layers;
1987
1988 uint32_t attachment_count;
1989 struct radv_attachment_info attachments[0];
1990 };
1991
1992 struct radv_subpass_barrier {
1993 VkPipelineStageFlags src_stage_mask;
1994 VkAccessFlags src_access_mask;
1995 VkAccessFlags dst_access_mask;
1996 };
1997
1998 void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
1999 const struct radv_subpass_barrier *barrier);
2000
2001 struct radv_subpass_attachment {
2002 uint32_t attachment;
2003 VkImageLayout layout;
2004 };
2005
2006 struct radv_subpass {
2007 uint32_t attachment_count;
2008 struct radv_subpass_attachment * attachments;
2009
2010 uint32_t input_count;
2011 uint32_t color_count;
2012 struct radv_subpass_attachment * input_attachments;
2013 struct radv_subpass_attachment * color_attachments;
2014 struct radv_subpass_attachment * resolve_attachments;
2015 struct radv_subpass_attachment * depth_stencil_attachment;
2016 struct radv_subpass_attachment * ds_resolve_attachment;
2017 VkResolveModeFlagBitsKHR depth_resolve_mode;
2018 VkResolveModeFlagBitsKHR stencil_resolve_mode;
2019
2020 /** Subpass has at least one color resolve attachment */
2021 bool has_color_resolve;
2022
2023 /** Subpass has at least one color attachment */
2024 bool has_color_att;
2025
2026 struct radv_subpass_barrier start_barrier;
2027
2028 uint32_t view_mask;
2029 VkSampleCountFlagBits max_sample_count;
2030 };
2031
2032 uint32_t
2033 radv_get_subpass_id(struct radv_cmd_buffer *cmd_buffer);
2034
2035 struct radv_render_pass_attachment {
2036 VkFormat format;
2037 uint32_t samples;
2038 VkAttachmentLoadOp load_op;
2039 VkAttachmentLoadOp stencil_load_op;
2040 VkImageLayout initial_layout;
2041 VkImageLayout final_layout;
2042
2043 /* The subpass id in which the attachment will be used first/last. */
2044 uint32_t first_subpass_idx;
2045 uint32_t last_subpass_idx;
2046 };
2047
2048 struct radv_render_pass {
2049 uint32_t attachment_count;
2050 uint32_t subpass_count;
2051 struct radv_subpass_attachment * subpass_attachments;
2052 struct radv_render_pass_attachment * attachments;
2053 struct radv_subpass_barrier end_barrier;
2054 struct radv_subpass subpasses[0];
2055 };
2056
2057 VkResult radv_device_init_meta(struct radv_device *device);
2058 void radv_device_finish_meta(struct radv_device *device);
2059
2060 struct radv_query_pool {
2061 struct radeon_winsys_bo *bo;
2062 uint32_t stride;
2063 uint32_t availability_offset;
2064 uint64_t size;
2065 char *ptr;
2066 VkQueryType type;
2067 uint32_t pipeline_stats_mask;
2068 };
2069
2070 struct radv_semaphore {
2071 /* use a winsys sem for non-exportable */
2072 struct radeon_winsys_sem *sem;
2073 uint32_t syncobj;
2074 uint32_t temp_syncobj;
2075 };
2076
2077 void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2078 VkPipelineBindPoint bind_point,
2079 struct radv_descriptor_set *set,
2080 unsigned idx);
2081
2082 void
2083 radv_update_descriptor_sets(struct radv_device *device,
2084 struct radv_cmd_buffer *cmd_buffer,
2085 VkDescriptorSet overrideSet,
2086 uint32_t descriptorWriteCount,
2087 const VkWriteDescriptorSet *pDescriptorWrites,
2088 uint32_t descriptorCopyCount,
2089 const VkCopyDescriptorSet *pDescriptorCopies);
2090
2091 void
2092 radv_update_descriptor_set_with_template(struct radv_device *device,
2093 struct radv_cmd_buffer *cmd_buffer,
2094 struct radv_descriptor_set *set,
2095 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
2096 const void *pData);
2097
2098 void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2099 VkPipelineBindPoint pipelineBindPoint,
2100 VkPipelineLayout _layout,
2101 uint32_t set,
2102 uint32_t descriptorWriteCount,
2103 const VkWriteDescriptorSet *pDescriptorWrites);
2104
2105 void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
2106 struct radv_image *image,
2107 const VkImageSubresourceRange *range, uint32_t value);
2108
2109 void radv_initialize_fmask(struct radv_cmd_buffer *cmd_buffer,
2110 struct radv_image *image,
2111 const VkImageSubresourceRange *range);
2112
2113 struct radv_fence {
2114 struct radeon_winsys_fence *fence;
2115 struct wsi_fence *fence_wsi;
2116
2117 uint32_t syncobj;
2118 uint32_t temp_syncobj;
2119 };
2120
2121 /* radv_nir_to_llvm.c */
2122 struct radv_shader_variant_info;
2123 struct radv_nir_compiler_options;
2124
2125 void radv_compile_gs_copy_shader(struct ac_llvm_compiler *ac_llvm,
2126 struct nir_shader *geom_shader,
2127 struct radv_shader_binary **rbinary,
2128 struct radv_shader_variant_info *shader_info,
2129 const struct radv_nir_compiler_options *option);
2130
2131 void radv_compile_nir_shader(struct ac_llvm_compiler *ac_llvm,
2132 struct radv_shader_binary **rbinary,
2133 struct radv_shader_variant_info *shader_info,
2134 struct nir_shader *const *nir,
2135 int nir_count,
2136 const struct radv_nir_compiler_options *options);
2137
2138 unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class,
2139 const struct nir_shader *nir);
2140
2141 /* radv_shader_info.h */
2142 struct radv_shader_info;
2143
2144 void radv_nir_shader_info_pass(const struct nir_shader *nir,
2145 const struct radv_nir_compiler_options *options,
2146 struct radv_shader_info *info);
2147
2148 void radv_nir_shader_info_init(struct radv_shader_info *info);
2149
2150 struct radeon_winsys_sem;
2151
2152 uint64_t radv_get_current_time(void);
2153
2154 static inline uint32_t
2155 si_conv_gl_prim_to_vertices(unsigned gl_prim)
2156 {
2157 switch (gl_prim) {
2158 case 0: /* GL_POINTS */
2159 return 1;
2160 case 1: /* GL_LINES */
2161 case 3: /* GL_LINE_STRIP */
2162 return 2;
2163 case 4: /* GL_TRIANGLES */
2164 case 5: /* GL_TRIANGLE_STRIP */
2165 return 3;
2166 case 0xA: /* GL_LINE_STRIP_ADJACENCY_ARB */
2167 return 4;
2168 case 0xc: /* GL_TRIANGLES_ADJACENCY_ARB */
2169 return 6;
2170 case 7: /* GL_QUADS */
2171 return V_028A6C_OUTPRIM_TYPE_TRISTRIP;
2172 default:
2173 assert(0);
2174 return 0;
2175 }
2176 }
2177
2178 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
2179 \
2180 static inline struct __radv_type * \
2181 __radv_type ## _from_handle(__VkType _handle) \
2182 { \
2183 return (struct __radv_type *) _handle; \
2184 } \
2185 \
2186 static inline __VkType \
2187 __radv_type ## _to_handle(struct __radv_type *_obj) \
2188 { \
2189 return (__VkType) _obj; \
2190 }
2191
2192 #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
2193 \
2194 static inline struct __radv_type * \
2195 __radv_type ## _from_handle(__VkType _handle) \
2196 { \
2197 return (struct __radv_type *)(uintptr_t) _handle; \
2198 } \
2199 \
2200 static inline __VkType \
2201 __radv_type ## _to_handle(struct __radv_type *_obj) \
2202 { \
2203 return (__VkType)(uintptr_t) _obj; \
2204 }
2205
2206 #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
2207 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
2208
2209 RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
2210 RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
2211 RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
2212 RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
2213 RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
2214
2215 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
2216 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
2217 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
2218 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
2219 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
2220 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
2221 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)
2222 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
2223 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
2224 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
2225 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
2226 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
2227 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
2228 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
2229 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
2230 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
2231 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
2232 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
2233 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
2234 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
2235 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
2236 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
2237
2238 #endif /* RADV_PRIVATE_H */