e3413735c09511125701bcb9a4c3eb991c92a517
[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 <amdgpu.h>
47 #include "compiler/shader_enums.h"
48 #include "util/macros.h"
49 #include "util/list.h"
50 #include "util/vk_alloc.h"
51 #include "main/macros.h"
52
53 #include "radv_radeon_winsys.h"
54 #include "ac_binary.h"
55 #include "ac_nir_to_llvm.h"
56 #include "radv_debug.h"
57 #include "radv_descriptor_set.h"
58
59 #include <llvm-c/TargetMachine.h>
60
61 /* Pre-declarations needed for WSI entrypoints */
62 struct wl_surface;
63 struct wl_display;
64 typedef struct xcb_connection_t xcb_connection_t;
65 typedef uint32_t xcb_visualid_t;
66 typedef uint32_t xcb_window_t;
67
68 #include <vulkan/vulkan.h>
69 #include <vulkan/vulkan_intel.h>
70 #include <vulkan/vk_icd.h>
71
72 #include "radv_entrypoints.h"
73
74 #include "wsi_common.h"
75
76 #define MAX_VBS 32
77 #define MAX_VERTEX_ATTRIBS 32
78 #define MAX_RTS 8
79 #define MAX_VIEWPORTS 16
80 #define MAX_SCISSORS 16
81 #define MAX_PUSH_CONSTANTS_SIZE 128
82 #define MAX_PUSH_DESCRIPTORS 32
83 #define MAX_DYNAMIC_BUFFERS 16
84 #define MAX_SAMPLES_LOG2 4
85 #define NUM_META_FS_KEYS 11
86 #define RADV_MAX_DRM_DEVICES 8
87
88 #define NUM_DEPTH_CLEAR_PIPELINES 3
89
90 enum radv_mem_heap {
91 RADV_MEM_HEAP_VRAM,
92 RADV_MEM_HEAP_VRAM_CPU_ACCESS,
93 RADV_MEM_HEAP_GTT,
94 RADV_MEM_HEAP_COUNT
95 };
96
97 enum radv_mem_type {
98 RADV_MEM_TYPE_VRAM,
99 RADV_MEM_TYPE_GTT_WRITE_COMBINE,
100 RADV_MEM_TYPE_VRAM_CPU_ACCESS,
101 RADV_MEM_TYPE_GTT_CACHED,
102 RADV_MEM_TYPE_COUNT
103 };
104
105 #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
106
107 static inline uint32_t
108 align_u32(uint32_t v, uint32_t a)
109 {
110 assert(a != 0 && a == (a & -a));
111 return (v + a - 1) & ~(a - 1);
112 }
113
114 static inline uint32_t
115 align_u32_npot(uint32_t v, uint32_t a)
116 {
117 return (v + a - 1) / a * a;
118 }
119
120 static inline uint64_t
121 align_u64(uint64_t v, uint64_t a)
122 {
123 assert(a != 0 && a == (a & -a));
124 return (v + a - 1) & ~(a - 1);
125 }
126
127 static inline int32_t
128 align_i32(int32_t v, int32_t a)
129 {
130 assert(a != 0 && a == (a & -a));
131 return (v + a - 1) & ~(a - 1);
132 }
133
134 /** Alignment must be a power of 2. */
135 static inline bool
136 radv_is_aligned(uintmax_t n, uintmax_t a)
137 {
138 assert(a == (a & -a));
139 return (n & (a - 1)) == 0;
140 }
141
142 static inline uint32_t
143 round_up_u32(uint32_t v, uint32_t a)
144 {
145 return (v + a - 1) / a;
146 }
147
148 static inline uint64_t
149 round_up_u64(uint64_t v, uint64_t a)
150 {
151 return (v + a - 1) / a;
152 }
153
154 static inline uint32_t
155 radv_minify(uint32_t n, uint32_t levels)
156 {
157 if (unlikely(n == 0))
158 return 0;
159 else
160 return MAX2(n >> levels, 1);
161 }
162 static inline float
163 radv_clamp_f(float f, float min, float max)
164 {
165 assert(min < max);
166
167 if (f > max)
168 return max;
169 else if (f < min)
170 return min;
171 else
172 return f;
173 }
174
175 static inline bool
176 radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
177 {
178 if (*inout_mask & clear_mask) {
179 *inout_mask &= ~clear_mask;
180 return true;
181 } else {
182 return false;
183 }
184 }
185
186 #define for_each_bit(b, dword) \
187 for (uint32_t __dword = (dword); \
188 (b) = __builtin_ffs(__dword) - 1, __dword; \
189 __dword &= ~(1 << (b)))
190
191 #define typed_memcpy(dest, src, count) ({ \
192 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
193 memcpy((dest), (src), (count) * sizeof(*(src))); \
194 })
195
196 #define zero(x) (memset(&(x), 0, sizeof(x)))
197
198 /* Whenever we generate an error, pass it through this function. Useful for
199 * debugging, where we can break on it. Only call at error site, not when
200 * propagating errors. Might be useful to plug in a stack trace here.
201 */
202
203 VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
204
205 #ifdef DEBUG
206 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
207 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
208 #else
209 #define vk_error(error) error
210 #define vk_errorf(error, format, ...) error
211 #endif
212
213 void __radv_finishme(const char *file, int line, const char *format, ...)
214 radv_printflike(3, 4);
215 void radv_loge(const char *format, ...) radv_printflike(1, 2);
216 void radv_loge_v(const char *format, va_list va);
217
218 /**
219 * Print a FINISHME message, including its source location.
220 */
221 #define radv_finishme(format, ...) \
222 do { \
223 static bool reported = false; \
224 if (!reported) { \
225 __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
226 reported = true; \
227 } \
228 } while (0)
229
230 /* A non-fatal assert. Useful for debugging. */
231 #ifdef DEBUG
232 #define radv_assert(x) ({ \
233 if (unlikely(!(x))) \
234 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
235 })
236 #else
237 #define radv_assert(x)
238 #endif
239
240 #define stub_return(v) \
241 do { \
242 radv_finishme("stub %s", __func__); \
243 return (v); \
244 } while (0)
245
246 #define stub() \
247 do { \
248 radv_finishme("stub %s", __func__); \
249 return; \
250 } while (0)
251
252 void *radv_lookup_entrypoint(const char *name);
253
254 struct radv_extensions {
255 VkExtensionProperties *ext_array;
256 uint32_t num_ext;
257 };
258
259 struct radv_physical_device {
260 VK_LOADER_DATA _loader_data;
261
262 struct radv_instance * instance;
263
264 struct radeon_winsys *ws;
265 struct radeon_info rad_info;
266 char path[20];
267 const char * name;
268 uint8_t uuid[VK_UUID_SIZE];
269
270 int local_fd;
271 struct wsi_device wsi_device;
272 struct radv_extensions extensions;
273 };
274
275 struct radv_instance {
276 VK_LOADER_DATA _loader_data;
277
278 VkAllocationCallbacks alloc;
279
280 uint32_t apiVersion;
281 int physicalDeviceCount;
282 struct radv_physical_device physicalDevices[RADV_MAX_DRM_DEVICES];
283
284 uint64_t debug_flags;
285 };
286
287 VkResult radv_init_wsi(struct radv_physical_device *physical_device);
288 void radv_finish_wsi(struct radv_physical_device *physical_device);
289
290 struct cache_entry;
291
292 struct radv_pipeline_cache {
293 struct radv_device * device;
294 pthread_mutex_t mutex;
295
296 uint32_t total_size;
297 uint32_t table_size;
298 uint32_t kernel_count;
299 struct cache_entry ** hash_table;
300 bool modified;
301
302 VkAllocationCallbacks alloc;
303 };
304
305 void
306 radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
307 struct radv_device *device);
308 void
309 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
310 void
311 radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
312 const void *data, size_t size);
313
314 struct radv_shader_variant *
315 radv_create_shader_variant_from_pipeline_cache(struct radv_device *device,
316 struct radv_pipeline_cache *cache,
317 const unsigned char *sha1);
318
319 struct radv_shader_variant *
320 radv_pipeline_cache_insert_shader(struct radv_pipeline_cache *cache,
321 const unsigned char *sha1,
322 struct radv_shader_variant *variant,
323 const void *code, unsigned code_size);
324
325 void radv_shader_variant_destroy(struct radv_device *device,
326 struct radv_shader_variant *variant);
327
328 struct radv_meta_state {
329 VkAllocationCallbacks alloc;
330
331 struct radv_pipeline_cache cache;
332
333 /**
334 * Use array element `i` for images with `2^i` samples.
335 */
336 struct {
337 VkRenderPass render_pass[NUM_META_FS_KEYS];
338 struct radv_pipeline *color_pipelines[NUM_META_FS_KEYS];
339
340 VkRenderPass depthstencil_rp;
341 struct radv_pipeline *depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
342 struct radv_pipeline *stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
343 struct radv_pipeline *depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
344 } clear[1 + MAX_SAMPLES_LOG2];
345
346 struct {
347 VkRenderPass render_pass[NUM_META_FS_KEYS];
348
349 /** Pipeline that blits from a 1D image. */
350 VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
351
352 /** Pipeline that blits from a 2D image. */
353 VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
354
355 /** Pipeline that blits from a 3D image. */
356 VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
357
358 VkRenderPass depth_only_rp;
359 VkPipeline depth_only_1d_pipeline;
360 VkPipeline depth_only_2d_pipeline;
361 VkPipeline depth_only_3d_pipeline;
362
363 VkRenderPass stencil_only_rp;
364 VkPipeline stencil_only_1d_pipeline;
365 VkPipeline stencil_only_2d_pipeline;
366 VkPipeline stencil_only_3d_pipeline;
367 VkPipelineLayout pipeline_layout;
368 VkDescriptorSetLayout ds_layout;
369 } blit;
370
371 struct {
372 VkRenderPass render_passes[NUM_META_FS_KEYS];
373
374 VkPipelineLayout p_layouts[2];
375 VkDescriptorSetLayout ds_layouts[2];
376 VkPipeline pipelines[2][NUM_META_FS_KEYS];
377
378 VkRenderPass depth_only_rp;
379 VkPipeline depth_only_pipeline[2];
380
381 VkRenderPass stencil_only_rp;
382 VkPipeline stencil_only_pipeline[2];
383 } blit2d;
384
385 struct {
386 VkPipelineLayout img_p_layout;
387 VkDescriptorSetLayout img_ds_layout;
388 VkPipeline pipeline;
389 } itob;
390 struct {
391 VkRenderPass render_pass;
392 VkPipelineLayout img_p_layout;
393 VkDescriptorSetLayout img_ds_layout;
394 VkPipeline pipeline;
395 } btoi;
396 struct {
397 VkPipelineLayout img_p_layout;
398 VkDescriptorSetLayout img_ds_layout;
399 VkPipeline pipeline;
400 } itoi;
401 struct {
402 VkPipelineLayout img_p_layout;
403 VkDescriptorSetLayout img_ds_layout;
404 VkPipeline pipeline;
405 } cleari;
406
407 struct {
408 VkPipeline pipeline;
409 VkRenderPass pass;
410 } resolve;
411
412 struct {
413 VkDescriptorSetLayout ds_layout;
414 VkPipelineLayout p_layout;
415 struct {
416 VkPipeline pipeline;
417 VkPipeline i_pipeline;
418 VkPipeline srgb_pipeline;
419 } rc[MAX_SAMPLES_LOG2];
420 } resolve_compute;
421
422 struct {
423 VkPipeline decompress_pipeline;
424 VkPipeline resummarize_pipeline;
425 VkRenderPass pass;
426 } depth_decomp;
427
428 struct {
429 VkPipeline cmask_eliminate_pipeline;
430 VkPipeline fmask_decompress_pipeline;
431 VkRenderPass pass;
432 } fast_clear_flush;
433
434 struct {
435 VkPipelineLayout fill_p_layout;
436 VkPipelineLayout copy_p_layout;
437 VkDescriptorSetLayout fill_ds_layout;
438 VkDescriptorSetLayout copy_ds_layout;
439 VkPipeline fill_pipeline;
440 VkPipeline copy_pipeline;
441 } buffer;
442
443 struct {
444 VkDescriptorSetLayout ds_layout;
445 VkPipelineLayout p_layout;
446 VkPipeline occlusion_query_pipeline;
447 VkPipeline pipeline_statistics_query_pipeline;
448 } query;
449 };
450
451 /* queue types */
452 #define RADV_QUEUE_GENERAL 0
453 #define RADV_QUEUE_COMPUTE 1
454 #define RADV_QUEUE_TRANSFER 2
455
456 #define RADV_MAX_QUEUE_FAMILIES 3
457
458 enum ring_type radv_queue_family_to_ring(int f);
459
460 struct radv_queue {
461 VK_LOADER_DATA _loader_data;
462 struct radv_device * device;
463 struct radeon_winsys_ctx *hw_ctx;
464 int queue_family_index;
465 int queue_idx;
466
467 uint32_t scratch_size;
468 uint32_t compute_scratch_size;
469 uint32_t esgs_ring_size;
470 uint32_t gsvs_ring_size;
471 bool has_tess_rings;
472 bool has_sample_positions;
473
474 struct radeon_winsys_bo *scratch_bo;
475 struct radeon_winsys_bo *descriptor_bo;
476 struct radeon_winsys_bo *compute_scratch_bo;
477 struct radeon_winsys_bo *esgs_ring_bo;
478 struct radeon_winsys_bo *gsvs_ring_bo;
479 struct radeon_winsys_bo *tess_factor_ring_bo;
480 struct radeon_winsys_bo *tess_offchip_ring_bo;
481 struct radeon_winsys_cs *initial_preamble_cs;
482 struct radeon_winsys_cs *continue_preamble_cs;
483 };
484
485 struct radv_device {
486 VK_LOADER_DATA _loader_data;
487
488 VkAllocationCallbacks alloc;
489
490 struct radv_instance * instance;
491 struct radeon_winsys *ws;
492
493 struct radv_meta_state meta_state;
494
495 struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
496 int queue_count[RADV_MAX_QUEUE_FAMILIES];
497 struct radeon_winsys_cs *empty_cs[RADV_MAX_QUEUE_FAMILIES];
498 struct radeon_winsys_cs *flush_cs[RADV_MAX_QUEUE_FAMILIES];
499 struct radeon_winsys_cs *flush_shader_cs[RADV_MAX_QUEUE_FAMILIES];
500 uint64_t debug_flags;
501
502 bool llvm_supports_spill;
503 bool has_distributed_tess;
504 uint32_t tess_offchip_block_dw_size;
505 uint32_t scratch_waves;
506
507 uint32_t gs_table_depth;
508
509 /* MSAA sample locations.
510 * The first index is the sample index.
511 * The second index is the coordinate: X, Y. */
512 float sample_locations_1x[1][2];
513 float sample_locations_2x[2][2];
514 float sample_locations_4x[4][2];
515 float sample_locations_8x[8][2];
516 float sample_locations_16x[16][2];
517
518 /* CIK and later */
519 uint32_t gfx_init_size_dw;
520 struct radeon_winsys_bo *gfx_init;
521
522 struct radeon_winsys_bo *trace_bo;
523 uint32_t *trace_id_ptr;
524
525 struct radv_physical_device *physical_device;
526
527 /* Backup in-memory cache to be used if the app doesn't provide one */
528 struct radv_pipeline_cache * mem_cache;
529 };
530
531 struct radv_device_memory {
532 struct radeon_winsys_bo *bo;
533 /* for dedicated allocations */
534 struct radv_image *image;
535 struct radv_buffer *buffer;
536 uint32_t type_index;
537 VkDeviceSize map_size;
538 void * map;
539 };
540
541
542 struct radv_descriptor_range {
543 uint64_t va;
544 uint32_t size;
545 };
546
547 struct radv_descriptor_set {
548 const struct radv_descriptor_set_layout *layout;
549 uint32_t size;
550
551 struct radeon_winsys_bo *bo;
552 uint64_t va;
553 uint32_t *mapped_ptr;
554 struct radv_descriptor_range *dynamic_descriptors;
555
556 struct list_head vram_list;
557
558 struct radeon_winsys_bo *descriptors[0];
559 };
560
561 struct radv_push_descriptor_set
562 {
563 struct radv_descriptor_set set;
564 uint32_t capacity;
565 };
566
567 struct radv_descriptor_pool {
568 struct radeon_winsys_bo *bo;
569 uint8_t *mapped_ptr;
570 uint64_t current_offset;
571 uint64_t size;
572
573 struct list_head vram_list;
574
575 uint8_t *host_memory_base;
576 uint8_t *host_memory_ptr;
577 uint8_t *host_memory_end;
578 };
579
580 struct radv_descriptor_update_template_entry {
581 VkDescriptorType descriptor_type;
582
583 /* The number of descriptors to update */
584 uint32_t descriptor_count;
585
586 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
587 uint32_t dst_offset;
588
589 /* In dwords. Not valid/used for dynamic descriptors */
590 uint32_t dst_stride;
591
592 uint32_t buffer_offset;
593
594 /* Only valid for combined image samplers and samplers */
595 uint16_t has_sampler;
596
597 /* In bytes */
598 size_t src_offset;
599 size_t src_stride;
600
601 /* For push descriptors */
602 const uint32_t *immutable_samplers;
603 };
604
605 struct radv_descriptor_update_template {
606 uint32_t entry_count;
607 struct radv_descriptor_update_template_entry entry[0];
608 };
609
610 struct radv_buffer {
611 struct radv_device * device;
612 VkDeviceSize size;
613
614 VkBufferUsageFlags usage;
615 VkBufferCreateFlags flags;
616
617 /* Set when bound */
618 struct radeon_winsys_bo * bo;
619 VkDeviceSize offset;
620 };
621
622
623 enum radv_cmd_dirty_bits {
624 RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
625 RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
626 RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
627 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
628 RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
629 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
630 RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
631 RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
632 RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
633 RADV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
634 RADV_CMD_DIRTY_PIPELINE = 1 << 9,
635 RADV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
636 RADV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
637 };
638 typedef uint32_t radv_cmd_dirty_mask_t;
639
640 enum radv_cmd_flush_bits {
641 RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
642 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
643 RADV_CMD_FLAG_INV_SMEM_L1 = 1 << 1,
644 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
645 RADV_CMD_FLAG_INV_VMEM_L1 = 1 << 2,
646 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
647 RADV_CMD_FLAG_INV_GLOBAL_L2 = 1 << 3,
648 /* Same as above, but only writes back and doesn't invalidate */
649 RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2 = 1 << 4,
650 /* Framebuffer caches */
651 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 5,
652 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 6,
653 RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 7,
654 RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 8,
655 /* Engine synchronization. */
656 RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 9,
657 RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 10,
658 RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 11,
659 RADV_CMD_FLAG_VGT_FLUSH = 1 << 12,
660
661 RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER = (RADV_CMD_FLAG_FLUSH_AND_INV_CB |
662 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
663 RADV_CMD_FLAG_FLUSH_AND_INV_DB |
664 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
665 };
666
667 struct radv_vertex_binding {
668 struct radv_buffer * buffer;
669 VkDeviceSize offset;
670 };
671
672 struct radv_dynamic_state {
673 struct {
674 uint32_t count;
675 VkViewport viewports[MAX_VIEWPORTS];
676 } viewport;
677
678 struct {
679 uint32_t count;
680 VkRect2D scissors[MAX_SCISSORS];
681 } scissor;
682
683 float line_width;
684
685 struct {
686 float bias;
687 float clamp;
688 float slope;
689 } depth_bias;
690
691 float blend_constants[4];
692
693 struct {
694 float min;
695 float max;
696 } depth_bounds;
697
698 struct {
699 uint32_t front;
700 uint32_t back;
701 } stencil_compare_mask;
702
703 struct {
704 uint32_t front;
705 uint32_t back;
706 } stencil_write_mask;
707
708 struct {
709 uint32_t front;
710 uint32_t back;
711 } stencil_reference;
712 };
713
714 extern const struct radv_dynamic_state default_dynamic_state;
715
716 void radv_dynamic_state_copy(struct radv_dynamic_state *dest,
717 const struct radv_dynamic_state *src,
718 uint32_t copy_mask);
719 /**
720 * Attachment state when recording a renderpass instance.
721 *
722 * The clear value is valid only if there exists a pending clear.
723 */
724 struct radv_attachment_state {
725 VkImageAspectFlags pending_clear_aspects;
726 VkClearValue clear_value;
727 VkImageLayout current_layout;
728 };
729
730 struct radv_cmd_state {
731 uint32_t vb_dirty;
732 radv_cmd_dirty_mask_t dirty;
733 bool vertex_descriptors_dirty;
734 bool push_descriptors_dirty;
735
736 struct radv_pipeline * pipeline;
737 struct radv_pipeline * emitted_pipeline;
738 struct radv_pipeline * compute_pipeline;
739 struct radv_pipeline * emitted_compute_pipeline;
740 struct radv_framebuffer * framebuffer;
741 struct radv_render_pass * pass;
742 const struct radv_subpass * subpass;
743 struct radv_dynamic_state dynamic;
744 struct radv_vertex_binding vertex_bindings[MAX_VBS];
745 struct radv_descriptor_set * descriptors[MAX_SETS];
746 struct radv_attachment_state * attachments;
747 VkRect2D render_area;
748 struct radv_buffer * index_buffer;
749 uint32_t index_type;
750 uint32_t index_offset;
751 int32_t last_primitive_reset_en;
752 uint32_t last_primitive_reset_index;
753 enum radv_cmd_flush_bits flush_bits;
754 unsigned active_occlusion_queries;
755 float offset_scale;
756 uint32_t descriptors_dirty;
757 uint32_t trace_id;
758 uint32_t last_ia_multi_vgt_param;
759 };
760
761 struct radv_cmd_pool {
762 VkAllocationCallbacks alloc;
763 struct list_head cmd_buffers;
764 struct list_head free_cmd_buffers;
765 uint32_t queue_family_index;
766 };
767
768 struct radv_cmd_buffer_upload {
769 uint8_t *map;
770 unsigned offset;
771 uint64_t size;
772 struct radeon_winsys_bo *upload_bo;
773 struct list_head list;
774 };
775
776 struct radv_cmd_buffer {
777 VK_LOADER_DATA _loader_data;
778
779 struct radv_device * device;
780
781 struct radv_cmd_pool * pool;
782 struct list_head pool_link;
783
784 VkCommandBufferUsageFlags usage_flags;
785 VkCommandBufferLevel level;
786 struct radeon_winsys_cs *cs;
787 struct radv_cmd_state state;
788 uint32_t queue_family_index;
789
790 uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
791 uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
792 VkShaderStageFlags push_constant_stages;
793 struct radv_push_descriptor_set push_descriptors;
794 struct radv_descriptor_set meta_push_descriptors;
795
796 struct radv_cmd_buffer_upload upload;
797
798 uint32_t scratch_size_needed;
799 uint32_t compute_scratch_size_needed;
800 uint32_t esgs_ring_size_needed;
801 uint32_t gsvs_ring_size_needed;
802 bool tess_rings_needed;
803 bool sample_positions_needed;
804
805 bool record_fail;
806
807 int ring_offsets_idx; /* just used for verification */
808 };
809
810 struct radv_image;
811
812 bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
813
814 void si_init_compute(struct radv_cmd_buffer *cmd_buffer);
815 void si_init_config(struct radv_cmd_buffer *cmd_buffer);
816
817 void cik_create_gfx_config(struct radv_device *device);
818
819 void si_write_viewport(struct radeon_winsys_cs *cs, int first_vp,
820 int count, const VkViewport *viewports);
821 void si_write_scissors(struct radeon_winsys_cs *cs, int first,
822 int count, const VkRect2D *scissors,
823 const VkViewport *viewports, bool can_use_guardband);
824 uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer,
825 bool instanced_draw, bool indirect_draw,
826 uint32_t draw_vertex_count);
827 void si_cs_emit_cache_flush(struct radeon_winsys_cs *cs,
828 enum chip_class chip_class,
829 bool is_mec,
830 enum radv_cmd_flush_bits flush_bits);
831 void si_cs_emit_cache_flush(struct radeon_winsys_cs *cs,
832 enum chip_class chip_class,
833 bool is_mec,
834 enum radv_cmd_flush_bits flush_bits);
835 void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
836 void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer,
837 uint64_t src_va, uint64_t dest_va,
838 uint64_t size);
839 void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
840 unsigned size);
841 void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
842 uint64_t size, unsigned value);
843 void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
844 void radv_bind_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
845 struct radv_descriptor_set *set,
846 unsigned idx);
847 bool
848 radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer,
849 unsigned size,
850 unsigned alignment,
851 unsigned *out_offset,
852 void **ptr);
853 void
854 radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
855 const struct radv_subpass *subpass,
856 bool transitions);
857 bool
858 radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer,
859 unsigned size, unsigned alignmnet,
860 const void *data, unsigned *out_offset);
861 void
862 radv_emit_framebuffer_state(struct radv_cmd_buffer *cmd_buffer);
863 void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
864 void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
865 void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
866 void radv_cayman_emit_msaa_sample_locs(struct radeon_winsys_cs *cs, int nr_samples);
867 unsigned radv_cayman_get_maxdist(int log_samples);
868 void radv_device_init_msaa(struct radv_device *device);
869 void radv_set_depth_clear_regs(struct radv_cmd_buffer *cmd_buffer,
870 struct radv_image *image,
871 VkClearDepthStencilValue ds_clear_value,
872 VkImageAspectFlags aspects);
873 void radv_set_color_clear_regs(struct radv_cmd_buffer *cmd_buffer,
874 struct radv_image *image,
875 int idx,
876 uint32_t color_values[2]);
877 void radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
878 struct radeon_winsys_bo *bo,
879 uint64_t offset, uint64_t size, uint32_t value);
880 void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
881 bool radv_get_memory_fd(struct radv_device *device,
882 struct radv_device_memory *memory,
883 int *pFD);
884 /*
885 * Takes x,y,z as exact numbers of invocations, instead of blocks.
886 *
887 * Limitations: Can't call normal dispatch functions without binding or rebinding
888 * the compute pipeline.
889 */
890 void radv_unaligned_dispatch(
891 struct radv_cmd_buffer *cmd_buffer,
892 uint32_t x,
893 uint32_t y,
894 uint32_t z);
895
896 struct radv_event {
897 struct radeon_winsys_bo *bo;
898 uint64_t *map;
899 };
900
901 struct nir_shader;
902
903 struct radv_shader_module {
904 struct nir_shader * nir;
905 unsigned char sha1[20];
906 uint32_t size;
907 char data[0];
908 };
909
910 union ac_shader_variant_key;
911
912 void
913 radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
914 const char *entrypoint,
915 const VkSpecializationInfo *spec_info,
916 const struct radv_pipeline_layout *layout,
917 const union ac_shader_variant_key *key,
918 uint32_t is_geom_copy_shader);
919
920 static inline gl_shader_stage
921 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
922 {
923 assert(__builtin_popcount(vk_stage) == 1);
924 return ffs(vk_stage) - 1;
925 }
926
927 static inline VkShaderStageFlagBits
928 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
929 {
930 return (1 << mesa_stage);
931 }
932
933 #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
934
935 #define radv_foreach_stage(stage, stage_bits) \
936 for (gl_shader_stage stage, \
937 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
938 stage = __builtin_ffs(__tmp) - 1, __tmp; \
939 __tmp &= ~(1 << (stage)))
940
941 struct radv_shader_variant {
942 uint32_t ref_count;
943
944 struct radeon_winsys_bo *bo;
945 struct ac_shader_config config;
946 struct ac_shader_variant_info info;
947 unsigned rsrc1;
948 unsigned rsrc2;
949 uint32_t code_size;
950 };
951
952 struct radv_depth_stencil_state {
953 uint32_t db_depth_control;
954 uint32_t db_stencil_control;
955 uint32_t db_render_control;
956 uint32_t db_render_override2;
957 };
958
959 struct radv_blend_state {
960 uint32_t cb_color_control;
961 uint32_t cb_target_mask;
962 uint32_t sx_mrt0_blend_opt[8];
963 uint32_t cb_blend_control[8];
964
965 uint32_t spi_shader_col_format;
966 uint32_t cb_shader_mask;
967 uint32_t db_alpha_to_mask;
968 };
969
970 unsigned radv_format_meta_fs_key(VkFormat format);
971
972 struct radv_raster_state {
973 uint32_t pa_cl_clip_cntl;
974 uint32_t spi_interp_control;
975 uint32_t pa_su_point_size;
976 uint32_t pa_su_point_minmax;
977 uint32_t pa_su_line_cntl;
978 uint32_t pa_su_vtx_cntl;
979 uint32_t pa_su_sc_mode_cntl;
980 };
981
982 struct radv_multisample_state {
983 uint32_t db_eqaa;
984 uint32_t pa_sc_line_cntl;
985 uint32_t pa_sc_mode_cntl_0;
986 uint32_t pa_sc_mode_cntl_1;
987 uint32_t pa_sc_aa_config;
988 uint32_t pa_sc_aa_mask[2];
989 unsigned num_samples;
990 };
991
992 struct radv_prim_vertex_count {
993 uint8_t min;
994 uint8_t incr;
995 };
996
997 struct radv_tessellation_state {
998 uint32_t ls_hs_config;
999 uint32_t tcs_in_layout;
1000 uint32_t tcs_out_layout;
1001 uint32_t tcs_out_offsets;
1002 uint32_t offchip_layout;
1003 unsigned num_patches;
1004 unsigned lds_size;
1005 unsigned num_tcs_input_cp;
1006 uint32_t tf_param;
1007 };
1008
1009 struct radv_pipeline {
1010 struct radv_device * device;
1011 uint32_t dynamic_state_mask;
1012 struct radv_dynamic_state dynamic_state;
1013
1014 struct radv_pipeline_layout * layout;
1015
1016 bool needs_data_cache;
1017 bool need_indirect_descriptor_sets;
1018 struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
1019 struct radv_shader_variant *gs_copy_shader;
1020 VkShaderStageFlags active_stages;
1021
1022 uint32_t va_rsrc_word3[MAX_VERTEX_ATTRIBS];
1023 uint32_t va_format_size[MAX_VERTEX_ATTRIBS];
1024 uint32_t va_binding[MAX_VERTEX_ATTRIBS];
1025 uint32_t va_offset[MAX_VERTEX_ATTRIBS];
1026 uint32_t num_vertex_attribs;
1027 uint32_t binding_stride[MAX_VBS];
1028
1029 union {
1030 struct {
1031 struct radv_blend_state blend;
1032 struct radv_depth_stencil_state ds;
1033 struct radv_raster_state raster;
1034 struct radv_multisample_state ms;
1035 struct radv_tessellation_state tess;
1036 uint32_t db_shader_control;
1037 uint32_t shader_z_format;
1038 unsigned prim;
1039 unsigned gs_out;
1040 uint32_t vgt_gs_mode;
1041 bool prim_restart_enable;
1042 unsigned esgs_ring_size;
1043 unsigned gsvs_ring_size;
1044 uint32_t ps_input_cntl[32];
1045 uint32_t ps_input_cntl_num;
1046 uint32_t pa_cl_vs_out_cntl;
1047 uint32_t vgt_shader_stages_en;
1048 struct radv_prim_vertex_count prim_vertex_count;
1049 bool can_use_guardband;
1050 } graphics;
1051 };
1052
1053 unsigned max_waves;
1054 unsigned scratch_bytes_per_wave;
1055 };
1056
1057 static inline bool radv_pipeline_has_gs(struct radv_pipeline *pipeline)
1058 {
1059 return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1060 }
1061
1062 static inline bool radv_pipeline_has_tess(struct radv_pipeline *pipeline)
1063 {
1064 return pipeline->shaders[MESA_SHADER_TESS_EVAL] ? true : false;
1065 }
1066
1067 struct radv_graphics_pipeline_create_info {
1068 bool use_rectlist;
1069 bool db_depth_clear;
1070 bool db_stencil_clear;
1071 bool db_depth_disable_expclear;
1072 bool db_stencil_disable_expclear;
1073 bool db_flush_depth_inplace;
1074 bool db_flush_stencil_inplace;
1075 bool db_resummarize;
1076 uint32_t custom_blend_mode;
1077 };
1078
1079 VkResult
1080 radv_pipeline_init(struct radv_pipeline *pipeline, struct radv_device *device,
1081 struct radv_pipeline_cache *cache,
1082 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1083 const struct radv_graphics_pipeline_create_info *extra,
1084 const VkAllocationCallbacks *alloc);
1085
1086 VkResult
1087 radv_graphics_pipeline_create(VkDevice device,
1088 VkPipelineCache cache,
1089 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1090 const struct radv_graphics_pipeline_create_info *extra,
1091 const VkAllocationCallbacks *alloc,
1092 VkPipeline *pPipeline);
1093
1094 struct vk_format_description;
1095 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
1096 int first_non_void);
1097 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
1098 int first_non_void);
1099 uint32_t radv_translate_colorformat(VkFormat format);
1100 uint32_t radv_translate_color_numformat(VkFormat format,
1101 const struct vk_format_description *desc,
1102 int first_non_void);
1103 uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1104 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1105 uint32_t radv_translate_dbformat(VkFormat format);
1106 uint32_t radv_translate_tex_dataformat(VkFormat format,
1107 const struct vk_format_description *desc,
1108 int first_non_void);
1109 uint32_t radv_translate_tex_numformat(VkFormat format,
1110 const struct vk_format_description *desc,
1111 int first_non_void);
1112 bool radv_format_pack_clear_color(VkFormat format,
1113 uint32_t clear_vals[2],
1114 VkClearColorValue *value);
1115 bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
1116
1117 struct radv_fmask_info {
1118 uint64_t offset;
1119 uint64_t size;
1120 unsigned alignment;
1121 unsigned pitch_in_pixels;
1122 unsigned bank_height;
1123 unsigned slice_tile_max;
1124 unsigned tile_mode_index;
1125 };
1126
1127 struct radv_cmask_info {
1128 uint64_t offset;
1129 uint64_t size;
1130 unsigned alignment;
1131 unsigned slice_tile_max;
1132 unsigned base_address_reg;
1133 };
1134
1135 struct r600_htile_info {
1136 uint64_t offset;
1137 uint64_t size;
1138 unsigned pitch;
1139 unsigned height;
1140 unsigned xalign;
1141 unsigned yalign;
1142 };
1143
1144 struct radv_image {
1145 VkImageType type;
1146 /* The original VkFormat provided by the client. This may not match any
1147 * of the actual surface formats.
1148 */
1149 VkFormat vk_format;
1150 VkImageAspectFlags aspects;
1151 struct radeon_surf_info info;
1152 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1153 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1154 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1155
1156 VkDeviceSize size;
1157 uint32_t alignment;
1158
1159 bool exclusive;
1160 unsigned queue_family_mask;
1161
1162 /* Set when bound */
1163 struct radeon_winsys_bo *bo;
1164 VkDeviceSize offset;
1165 uint32_t dcc_offset;
1166 uint32_t htile_offset;
1167 struct radeon_surf surface;
1168
1169 struct radv_fmask_info fmask;
1170 struct radv_cmask_info cmask;
1171 uint32_t clear_value_offset;
1172 };
1173
1174 bool radv_layout_has_htile(const struct radv_image *image,
1175 VkImageLayout layout);
1176 bool radv_layout_is_htile_compressed(const struct radv_image *image,
1177 VkImageLayout layout);
1178 bool radv_layout_can_expclear(const struct radv_image *image,
1179 VkImageLayout layout);
1180 bool radv_layout_can_fast_clear(const struct radv_image *image,
1181 VkImageLayout layout,
1182 unsigned queue_mask);
1183
1184
1185 unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
1186
1187 static inline uint32_t
1188 radv_get_layerCount(const struct radv_image *image,
1189 const VkImageSubresourceRange *range)
1190 {
1191 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1192 image->info.array_size - range->baseArrayLayer : range->layerCount;
1193 }
1194
1195 static inline uint32_t
1196 radv_get_levelCount(const struct radv_image *image,
1197 const VkImageSubresourceRange *range)
1198 {
1199 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1200 image->info.levels - range->baseMipLevel : range->levelCount;
1201 }
1202
1203 struct radeon_bo_metadata;
1204 void
1205 radv_init_metadata(struct radv_device *device,
1206 struct radv_image *image,
1207 struct radeon_bo_metadata *metadata);
1208
1209 struct radv_image_view {
1210 struct radv_image *image; /**< VkImageViewCreateInfo::image */
1211 struct radeon_winsys_bo *bo;
1212
1213 VkImageViewType type;
1214 VkImageAspectFlags aspect_mask;
1215 VkFormat vk_format;
1216 uint32_t base_layer;
1217 uint32_t layer_count;
1218 uint32_t base_mip;
1219 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1220
1221 uint32_t descriptor[8];
1222 uint32_t fmask_descriptor[8];
1223 };
1224
1225 struct radv_image_create_info {
1226 const VkImageCreateInfo *vk_info;
1227 uint32_t stride;
1228 bool scanout;
1229 };
1230
1231 VkResult radv_image_create(VkDevice _device,
1232 const struct radv_image_create_info *info,
1233 const VkAllocationCallbacks* alloc,
1234 VkImage *pImage);
1235
1236 void radv_image_view_init(struct radv_image_view *view,
1237 struct radv_device *device,
1238 const VkImageViewCreateInfo* pCreateInfo,
1239 struct radv_cmd_buffer *cmd_buffer,
1240 VkImageUsageFlags usage_mask);
1241 void radv_image_set_optimal_micro_tile_mode(struct radv_device *device,
1242 struct radv_image *image, uint32_t micro_tile_mode);
1243 struct radv_buffer_view {
1244 struct radeon_winsys_bo *bo;
1245 VkFormat vk_format;
1246 uint64_t range; /**< VkBufferViewCreateInfo::range */
1247 uint32_t state[4];
1248 };
1249 void radv_buffer_view_init(struct radv_buffer_view *view,
1250 struct radv_device *device,
1251 const VkBufferViewCreateInfo* pCreateInfo,
1252 struct radv_cmd_buffer *cmd_buffer);
1253
1254 static inline struct VkExtent3D
1255 radv_sanitize_image_extent(const VkImageType imageType,
1256 const struct VkExtent3D imageExtent)
1257 {
1258 switch (imageType) {
1259 case VK_IMAGE_TYPE_1D:
1260 return (VkExtent3D) { imageExtent.width, 1, 1 };
1261 case VK_IMAGE_TYPE_2D:
1262 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1263 case VK_IMAGE_TYPE_3D:
1264 return imageExtent;
1265 default:
1266 unreachable("invalid image type");
1267 }
1268 }
1269
1270 static inline struct VkOffset3D
1271 radv_sanitize_image_offset(const VkImageType imageType,
1272 const struct VkOffset3D imageOffset)
1273 {
1274 switch (imageType) {
1275 case VK_IMAGE_TYPE_1D:
1276 return (VkOffset3D) { imageOffset.x, 0, 0 };
1277 case VK_IMAGE_TYPE_2D:
1278 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1279 case VK_IMAGE_TYPE_3D:
1280 return imageOffset;
1281 default:
1282 unreachable("invalid image type");
1283 }
1284 }
1285
1286 static inline bool
1287 radv_image_extent_compare(const struct radv_image *image,
1288 const VkExtent3D *extent)
1289 {
1290 if (extent->width != image->info.width ||
1291 extent->height != image->info.height ||
1292 extent->depth != image->info.depth)
1293 return false;
1294 return true;
1295 }
1296
1297 struct radv_sampler {
1298 uint32_t state[4];
1299 };
1300
1301 struct radv_color_buffer_info {
1302 uint32_t cb_color_base;
1303 uint32_t cb_color_pitch;
1304 uint32_t cb_color_slice;
1305 uint32_t cb_color_view;
1306 uint32_t cb_color_info;
1307 uint32_t cb_color_attrib;
1308 uint32_t cb_dcc_control;
1309 uint32_t cb_color_cmask;
1310 uint32_t cb_color_cmask_slice;
1311 uint32_t cb_color_fmask;
1312 uint32_t cb_color_fmask_slice;
1313 uint32_t cb_clear_value0;
1314 uint32_t cb_clear_value1;
1315 uint32_t cb_dcc_base;
1316 uint32_t micro_tile_mode;
1317 };
1318
1319 struct radv_ds_buffer_info {
1320 uint32_t db_depth_info;
1321 uint32_t db_z_info;
1322 uint32_t db_stencil_info;
1323 uint32_t db_z_read_base;
1324 uint32_t db_stencil_read_base;
1325 uint32_t db_z_write_base;
1326 uint32_t db_stencil_write_base;
1327 uint32_t db_depth_view;
1328 uint32_t db_depth_size;
1329 uint32_t db_depth_slice;
1330 uint32_t db_htile_surface;
1331 uint32_t db_htile_data_base;
1332 uint32_t pa_su_poly_offset_db_fmt_cntl;
1333 float offset_scale;
1334 };
1335
1336 struct radv_attachment_info {
1337 union {
1338 struct radv_color_buffer_info cb;
1339 struct radv_ds_buffer_info ds;
1340 };
1341 struct radv_image_view *attachment;
1342 };
1343
1344 struct radv_framebuffer {
1345 uint32_t width;
1346 uint32_t height;
1347 uint32_t layers;
1348
1349 uint32_t attachment_count;
1350 struct radv_attachment_info attachments[0];
1351 };
1352
1353 struct radv_subpass_barrier {
1354 VkPipelineStageFlags src_stage_mask;
1355 VkAccessFlags src_access_mask;
1356 VkAccessFlags dst_access_mask;
1357 };
1358
1359 struct radv_subpass {
1360 uint32_t input_count;
1361 uint32_t color_count;
1362 VkAttachmentReference * input_attachments;
1363 VkAttachmentReference * color_attachments;
1364 VkAttachmentReference * resolve_attachments;
1365 VkAttachmentReference depth_stencil_attachment;
1366
1367 /** Subpass has at least one resolve attachment */
1368 bool has_resolve;
1369
1370 struct radv_subpass_barrier start_barrier;
1371 };
1372
1373 struct radv_render_pass_attachment {
1374 VkFormat format;
1375 uint32_t samples;
1376 VkAttachmentLoadOp load_op;
1377 VkAttachmentLoadOp stencil_load_op;
1378 VkImageLayout initial_layout;
1379 VkImageLayout final_layout;
1380 };
1381
1382 struct radv_render_pass {
1383 uint32_t attachment_count;
1384 uint32_t subpass_count;
1385 VkAttachmentReference * subpass_attachments;
1386 struct radv_render_pass_attachment * attachments;
1387 struct radv_subpass_barrier end_barrier;
1388 struct radv_subpass subpasses[0];
1389 };
1390
1391 VkResult radv_device_init_meta(struct radv_device *device);
1392 void radv_device_finish_meta(struct radv_device *device);
1393
1394 struct radv_query_pool {
1395 struct radeon_winsys_bo *bo;
1396 uint32_t stride;
1397 uint32_t availability_offset;
1398 char *ptr;
1399 VkQueryType type;
1400 uint32_t pipeline_stats_mask;
1401 };
1402
1403 void
1404 radv_update_descriptor_sets(struct radv_device *device,
1405 struct radv_cmd_buffer *cmd_buffer,
1406 VkDescriptorSet overrideSet,
1407 uint32_t descriptorWriteCount,
1408 const VkWriteDescriptorSet *pDescriptorWrites,
1409 uint32_t descriptorCopyCount,
1410 const VkCopyDescriptorSet *pDescriptorCopies);
1411
1412 void
1413 radv_update_descriptor_set_with_template(struct radv_device *device,
1414 struct radv_cmd_buffer *cmd_buffer,
1415 struct radv_descriptor_set *set,
1416 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1417 const void *pData);
1418
1419 void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
1420 VkPipelineBindPoint pipelineBindPoint,
1421 VkPipelineLayout _layout,
1422 uint32_t set,
1423 uint32_t descriptorWriteCount,
1424 const VkWriteDescriptorSet *pDescriptorWrites);
1425
1426 void radv_initialise_cmask(struct radv_cmd_buffer *cmd_buffer,
1427 struct radv_image *image, uint32_t value);
1428 void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
1429 struct radv_image *image, uint32_t value);
1430
1431 struct radv_fence {
1432 struct radeon_winsys_fence *fence;
1433 bool submitted;
1434 bool signalled;
1435 };
1436
1437 struct radeon_winsys_sem;
1438
1439 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
1440 \
1441 static inline struct __radv_type * \
1442 __radv_type ## _from_handle(__VkType _handle) \
1443 { \
1444 return (struct __radv_type *) _handle; \
1445 } \
1446 \
1447 static inline __VkType \
1448 __radv_type ## _to_handle(struct __radv_type *_obj) \
1449 { \
1450 return (__VkType) _obj; \
1451 }
1452
1453 #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
1454 \
1455 static inline struct __radv_type * \
1456 __radv_type ## _from_handle(__VkType _handle) \
1457 { \
1458 return (struct __radv_type *)(uintptr_t) _handle; \
1459 } \
1460 \
1461 static inline __VkType \
1462 __radv_type ## _to_handle(struct __radv_type *_obj) \
1463 { \
1464 return (__VkType)(uintptr_t) _obj; \
1465 }
1466
1467 #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
1468 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
1469
1470 RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
1471 RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
1472 RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
1473 RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
1474 RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
1475
1476 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
1477 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
1478 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
1479 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
1480 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
1481 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
1482 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
1483 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
1484 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
1485 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
1486 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
1487 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
1488 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
1489 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
1490 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
1491 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
1492 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
1493 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
1494 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
1495 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
1496 RADV_DEFINE_NONDISP_HANDLE_CASTS(radeon_winsys_sem, VkSemaphore)
1497
1498 #endif /* RADV_PRIVATE_H */