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