a70bb3b7dce5ca205e0b51886faf57626092a709
[mesa.git] / src / freedreno / vulkan / tu_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
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28 #ifndef TU_PRIVATE_H
29 #define TU_PRIVATE_H
30
31 #include <assert.h>
32 #include <pthread.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #ifdef HAVE_VALGRIND
39 #include <memcheck.h>
40 #include <valgrind.h>
41 #define VG(x) x
42 #else
43 #define VG(x) ((void)0)
44 #endif
45
46 #include "c11/threads.h"
47 #include "main/macros.h"
48 #include "util/list.h"
49 #include "util/macros.h"
50 #include "vk_alloc.h"
51 #include "vk_debug_report.h"
52 #include "wsi_common.h"
53
54 #include "drm-uapi/msm_drm.h"
55 #include "ir3/ir3_compiler.h"
56 #include "ir3/ir3_shader.h"
57
58 #include "adreno_common.xml.h"
59 #include "adreno_pm4.xml.h"
60 #include "a6xx.xml.h"
61 #include "fdl/freedreno_layout.h"
62
63 #include "tu_descriptor_set.h"
64 #include "tu_extensions.h"
65 #include "tu_util.h"
66
67 /* Pre-declarations needed for WSI entrypoints */
68 struct wl_surface;
69 struct wl_display;
70 typedef struct xcb_connection_t xcb_connection_t;
71 typedef uint32_t xcb_visualid_t;
72 typedef uint32_t xcb_window_t;
73
74 #include <vulkan/vk_android_native_buffer.h>
75 #include <vulkan/vk_icd.h>
76 #include <vulkan/vulkan.h>
77 #include <vulkan/vulkan_intel.h>
78
79 #include "tu_entrypoints.h"
80
81 #include "vk_format.h"
82
83 #define MAX_VBS 32
84 #define MAX_VERTEX_ATTRIBS 32
85 #define MAX_RTS 8
86 #define MAX_VSC_PIPES 32
87 #define MAX_VIEWPORTS 1
88 #define MAX_SCISSORS 16
89 #define MAX_DISCARD_RECTANGLES 4
90 #define MAX_PUSH_CONSTANTS_SIZE 128
91 #define MAX_PUSH_DESCRIPTORS 32
92 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
93 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
94 #define MAX_DYNAMIC_BUFFERS \
95 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
96 #define TU_MAX_DRM_DEVICES 8
97 #define MAX_VIEWS 8
98 #define MAX_BIND_POINTS 2 /* compute + graphics */
99 /* The Qualcomm driver exposes 0x20000058 */
100 #define MAX_STORAGE_BUFFER_RANGE 0x20000000
101 /* We use ldc for uniform buffer loads, just like the Qualcomm driver, so
102 * expose the same maximum range.
103 * TODO: The SIZE bitfield is 15 bits, and in 4-dword units, so the actual
104 * range might be higher.
105 */
106 #define MAX_UNIFORM_BUFFER_RANGE 0x10000
107
108 #define A6XX_TEX_CONST_DWORDS 16
109 #define A6XX_TEX_SAMP_DWORDS 4
110
111 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
112
113 static inline uint32_t
114 tu_minify(uint32_t n, uint32_t levels)
115 {
116 if (unlikely(n == 0))
117 return 0;
118 else
119 return MAX2(n >> levels, 1);
120 }
121
122 #define for_each_bit(b, dword) \
123 for (uint32_t __dword = (dword); \
124 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
125
126 #define typed_memcpy(dest, src, count) \
127 ({ \
128 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
129 memcpy((dest), (src), (count) * sizeof(*(src))); \
130 })
131
132 #define COND(bool, val) ((bool) ? (val) : 0)
133 #define BIT(bit) (1u << (bit))
134
135 /* Whenever we generate an error, pass it through this function. Useful for
136 * debugging, where we can break on it. Only call at error site, not when
137 * propagating errors. Might be useful to plug in a stack trace here.
138 */
139
140 struct tu_instance;
141
142 VkResult
143 __vk_errorf(struct tu_instance *instance,
144 VkResult error,
145 const char *file,
146 int line,
147 const char *format,
148 ...);
149
150 #define vk_error(instance, error) \
151 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
152 #define vk_errorf(instance, error, format, ...) \
153 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
154
155 void
156 __tu_finishme(const char *file, int line, const char *format, ...)
157 tu_printflike(3, 4);
158 void
159 tu_loge(const char *format, ...) tu_printflike(1, 2);
160 void
161 tu_logi(const char *format, ...) tu_printflike(1, 2);
162
163 /**
164 * Print a FINISHME message, including its source location.
165 */
166 #define tu_finishme(format, ...) \
167 do { \
168 static bool reported = false; \
169 if (!reported) { \
170 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
171 reported = true; \
172 } \
173 } while (0)
174
175 #define tu_stub() \
176 do { \
177 tu_finishme("stub %s", __func__); \
178 } while (0)
179
180 void *
181 tu_lookup_entrypoint_unchecked(const char *name);
182 void *
183 tu_lookup_entrypoint_checked(
184 const char *name,
185 uint32_t core_version,
186 const struct tu_instance_extension_table *instance,
187 const struct tu_device_extension_table *device);
188
189 struct tu_physical_device
190 {
191 VK_LOADER_DATA _loader_data;
192
193 struct tu_instance *instance;
194
195 char path[20];
196 char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
197 uint8_t driver_uuid[VK_UUID_SIZE];
198 uint8_t device_uuid[VK_UUID_SIZE];
199 uint8_t cache_uuid[VK_UUID_SIZE];
200
201 struct wsi_device wsi_device;
202
203 int local_fd;
204 int master_fd;
205
206 unsigned gpu_id;
207 uint32_t gmem_size;
208 uint64_t gmem_base;
209 uint32_t ccu_offset_gmem;
210 uint32_t ccu_offset_bypass;
211 /* alignment for size of tiles */
212 uint32_t tile_align_w;
213 #define TILE_ALIGN_H 16
214 /* gmem store/load granularity */
215 #define GMEM_ALIGN_W 16
216 #define GMEM_ALIGN_H 4
217
218 struct {
219 uint32_t PC_UNKNOWN_9805;
220 uint32_t SP_UNKNOWN_A0F8;
221 } magic;
222
223 int msm_major_version;
224 int msm_minor_version;
225
226 /* This is the drivers on-disk cache used as a fallback as opposed to
227 * the pipeline cache defined by apps.
228 */
229 struct disk_cache *disk_cache;
230
231 struct tu_device_extension_table supported_extensions;
232 };
233
234 enum tu_debug_flags
235 {
236 TU_DEBUG_STARTUP = 1 << 0,
237 TU_DEBUG_NIR = 1 << 1,
238 TU_DEBUG_IR3 = 1 << 2,
239 TU_DEBUG_NOBIN = 1 << 3,
240 TU_DEBUG_SYSMEM = 1 << 4,
241 TU_DEBUG_FORCEBIN = 1 << 5,
242 TU_DEBUG_NOUBWC = 1 << 6,
243 };
244
245 struct tu_instance
246 {
247 VK_LOADER_DATA _loader_data;
248
249 VkAllocationCallbacks alloc;
250
251 uint32_t api_version;
252 int physical_device_count;
253 struct tu_physical_device physical_devices[TU_MAX_DRM_DEVICES];
254
255 enum tu_debug_flags debug_flags;
256
257 struct vk_debug_report_instance debug_report_callbacks;
258
259 struct tu_instance_extension_table enabled_extensions;
260 };
261
262 VkResult
263 tu_wsi_init(struct tu_physical_device *physical_device);
264 void
265 tu_wsi_finish(struct tu_physical_device *physical_device);
266
267 bool
268 tu_instance_extension_supported(const char *name);
269 uint32_t
270 tu_physical_device_api_version(struct tu_physical_device *dev);
271 bool
272 tu_physical_device_extension_supported(struct tu_physical_device *dev,
273 const char *name);
274
275 struct cache_entry;
276
277 struct tu_pipeline_cache
278 {
279 struct tu_device *device;
280 pthread_mutex_t mutex;
281
282 uint32_t total_size;
283 uint32_t table_size;
284 uint32_t kernel_count;
285 struct cache_entry **hash_table;
286 bool modified;
287
288 VkAllocationCallbacks alloc;
289 };
290
291 struct tu_pipeline_key
292 {
293 };
294
295
296 /* queue types */
297 #define TU_QUEUE_GENERAL 0
298
299 #define TU_MAX_QUEUE_FAMILIES 1
300
301 struct tu_fence
302 {
303 struct wsi_fence *fence_wsi;
304 bool signaled;
305 int fd;
306 };
307
308 void
309 tu_fence_init(struct tu_fence *fence, bool signaled);
310 void
311 tu_fence_finish(struct tu_fence *fence);
312 void
313 tu_fence_update_fd(struct tu_fence *fence, int fd);
314 void
315 tu_fence_copy(struct tu_fence *fence, const struct tu_fence *src);
316 void
317 tu_fence_signal(struct tu_fence *fence);
318 void
319 tu_fence_wait_idle(struct tu_fence *fence);
320
321 struct tu_queue
322 {
323 VK_LOADER_DATA _loader_data;
324 struct tu_device *device;
325 uint32_t queue_family_index;
326 int queue_idx;
327 VkDeviceQueueCreateFlags flags;
328
329 uint32_t msm_queue_id;
330 struct tu_fence submit_fence;
331 };
332
333 struct tu_bo
334 {
335 uint32_t gem_handle;
336 uint64_t size;
337 uint64_t iova;
338 void *map;
339 };
340
341 struct tu_device
342 {
343 VK_LOADER_DATA _loader_data;
344
345 VkAllocationCallbacks alloc;
346
347 struct tu_instance *instance;
348
349 struct tu_queue *queues[TU_MAX_QUEUE_FAMILIES];
350 int queue_count[TU_MAX_QUEUE_FAMILIES];
351
352 struct tu_physical_device *physical_device;
353
354 struct ir3_compiler *compiler;
355
356 /* Backup in-memory cache to be used if the app doesn't provide one */
357 struct tu_pipeline_cache *mem_cache;
358
359 struct tu_bo vsc_draw_strm;
360 struct tu_bo vsc_prim_strm;
361 uint32_t vsc_draw_strm_pitch;
362 uint32_t vsc_prim_strm_pitch;
363
364 #define MIN_SCRATCH_BO_SIZE_LOG2 12 /* A page */
365
366 /* Currently the kernel driver uses a 32-bit GPU address space, but it
367 * should be impossible to go beyond 48 bits.
368 */
369 struct {
370 struct tu_bo bo;
371 mtx_t construct_mtx;
372 bool initialized;
373 } scratch_bos[48 - MIN_SCRATCH_BO_SIZE_LOG2];
374
375 struct tu_bo border_color;
376
377 struct tu_device_extension_table enabled_extensions;
378 };
379
380 VkResult
381 tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size);
382 VkResult
383 tu_bo_init_dmabuf(struct tu_device *dev,
384 struct tu_bo *bo,
385 uint64_t size,
386 int fd);
387 int
388 tu_bo_export_dmabuf(struct tu_device *dev, struct tu_bo *bo);
389 void
390 tu_bo_finish(struct tu_device *dev, struct tu_bo *bo);
391 VkResult
392 tu_bo_map(struct tu_device *dev, struct tu_bo *bo);
393
394 /* Get a scratch bo for use inside a command buffer. This will always return
395 * the same bo given the same size or similar sizes, so only one scratch bo
396 * can be used at the same time. It's meant for short-lived things where we
397 * need to write to some piece of memory, read from it, and then immediately
398 * discard it.
399 */
400 VkResult
401 tu_get_scratch_bo(struct tu_device *dev, uint64_t size, struct tu_bo **bo);
402
403 struct tu_cs_entry
404 {
405 /* No ownership */
406 const struct tu_bo *bo;
407
408 uint32_t size;
409 uint32_t offset;
410 };
411
412 struct tu_cs_memory {
413 uint32_t *map;
414 uint64_t iova;
415 };
416
417 struct tu_draw_state {
418 uint64_t iova : 48;
419 uint32_t size : 16;
420 };
421
422 enum tu_dynamic_state
423 {
424 /* re-use VK_DYNAMIC_STATE_ enums for non-extended dynamic states */
425 TU_DYNAMIC_STATE_SAMPLE_LOCATIONS = VK_DYNAMIC_STATE_STENCIL_REFERENCE + 1,
426 TU_DYNAMIC_STATE_COUNT,
427 };
428
429 enum tu_draw_state_group_id
430 {
431 TU_DRAW_STATE_PROGRAM,
432 TU_DRAW_STATE_PROGRAM_BINNING,
433 TU_DRAW_STATE_TESS,
434 TU_DRAW_STATE_VB,
435 TU_DRAW_STATE_VI,
436 TU_DRAW_STATE_VI_BINNING,
437 TU_DRAW_STATE_RAST,
438 TU_DRAW_STATE_DS,
439 TU_DRAW_STATE_BLEND,
440 TU_DRAW_STATE_VS_CONST,
441 TU_DRAW_STATE_HS_CONST,
442 TU_DRAW_STATE_DS_CONST,
443 TU_DRAW_STATE_GS_CONST,
444 TU_DRAW_STATE_FS_CONST,
445 TU_DRAW_STATE_DESC_SETS,
446 TU_DRAW_STATE_DESC_SETS_LOAD,
447 TU_DRAW_STATE_VS_PARAMS,
448 TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM,
449 TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM,
450
451 /* dynamic state related draw states */
452 TU_DRAW_STATE_DYNAMIC,
453 TU_DRAW_STATE_COUNT = TU_DRAW_STATE_DYNAMIC + TU_DYNAMIC_STATE_COUNT,
454 };
455
456 enum tu_cs_mode
457 {
458
459 /*
460 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
461 * is full. tu_cs_begin must be called before command packet emission and
462 * tu_cs_end must be called after.
463 *
464 * This mode may create multiple entries internally. The entries must be
465 * submitted together.
466 */
467 TU_CS_MODE_GROW,
468
469 /*
470 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
471 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
472 * effect on it.
473 *
474 * This mode does not create any entry or any BO.
475 */
476 TU_CS_MODE_EXTERNAL,
477
478 /*
479 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
480 * command packet emission. tu_cs_begin_sub_stream must be called to get a
481 * sub-stream to emit comamnd packets to. When done with the sub-stream,
482 * tu_cs_end_sub_stream must be called.
483 *
484 * This mode does not create any entry internally.
485 */
486 TU_CS_MODE_SUB_STREAM,
487 };
488
489 struct tu_cs
490 {
491 uint32_t *start;
492 uint32_t *cur;
493 uint32_t *reserved_end;
494 uint32_t *end;
495
496 struct tu_device *device;
497 enum tu_cs_mode mode;
498 uint32_t next_bo_size;
499
500 struct tu_cs_entry *entries;
501 uint32_t entry_count;
502 uint32_t entry_capacity;
503
504 struct tu_bo **bos;
505 uint32_t bo_count;
506 uint32_t bo_capacity;
507
508 /* state for cond_exec_start/cond_exec_end */
509 uint32_t cond_flags;
510 uint32_t *cond_dwords;
511 };
512
513 struct tu_device_memory
514 {
515 struct tu_bo bo;
516 VkDeviceSize size;
517
518 /* for dedicated allocations */
519 struct tu_image *image;
520 struct tu_buffer *buffer;
521
522 uint32_t type_index;
523 void *map;
524 void *user_ptr;
525 };
526
527 struct tu_descriptor_range
528 {
529 uint64_t va;
530 uint32_t size;
531 };
532
533 struct tu_descriptor_set
534 {
535 const struct tu_descriptor_set_layout *layout;
536 struct tu_descriptor_pool *pool;
537 uint32_t size;
538
539 uint64_t va;
540 uint32_t *mapped_ptr;
541
542 uint32_t *dynamic_descriptors;
543
544 struct tu_bo *buffers[0];
545 };
546
547 struct tu_push_descriptor_set
548 {
549 struct tu_descriptor_set set;
550 uint32_t capacity;
551 };
552
553 struct tu_descriptor_pool_entry
554 {
555 uint32_t offset;
556 uint32_t size;
557 struct tu_descriptor_set *set;
558 };
559
560 struct tu_descriptor_pool
561 {
562 struct tu_bo bo;
563 uint64_t current_offset;
564 uint64_t size;
565
566 uint8_t *host_memory_base;
567 uint8_t *host_memory_ptr;
568 uint8_t *host_memory_end;
569
570 uint32_t entry_count;
571 uint32_t max_entry_count;
572 struct tu_descriptor_pool_entry entries[0];
573 };
574
575 struct tu_descriptor_update_template_entry
576 {
577 VkDescriptorType descriptor_type;
578
579 /* The number of descriptors to update */
580 uint32_t descriptor_count;
581
582 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
583 */
584 uint32_t dst_offset;
585
586 /* In dwords. Not valid/used for dynamic descriptors */
587 uint32_t dst_stride;
588
589 uint32_t buffer_offset;
590
591 /* Only valid for combined image samplers and samplers */
592 uint16_t has_sampler;
593
594 /* In bytes */
595 size_t src_offset;
596 size_t src_stride;
597
598 /* For push descriptors */
599 const uint32_t *immutable_samplers;
600 };
601
602 struct tu_descriptor_update_template
603 {
604 uint32_t entry_count;
605 struct tu_descriptor_update_template_entry entry[0];
606 };
607
608 struct tu_buffer
609 {
610 VkDeviceSize size;
611
612 VkBufferUsageFlags usage;
613 VkBufferCreateFlags flags;
614
615 struct tu_bo *bo;
616 VkDeviceSize bo_offset;
617 };
618
619 static inline uint64_t
620 tu_buffer_iova(struct tu_buffer *buffer)
621 {
622 return buffer->bo->iova + buffer->bo_offset;
623 }
624
625 struct tu_vertex_binding
626 {
627 struct tu_buffer *buffer;
628 VkDeviceSize offset;
629 };
630
631 const char *
632 tu_get_debug_option_name(int id);
633
634 const char *
635 tu_get_perftest_option_name(int id);
636
637 struct tu_descriptor_state
638 {
639 struct tu_descriptor_set *sets[MAX_SETS];
640 uint32_t dynamic_descriptors[MAX_DYNAMIC_BUFFERS * A6XX_TEX_CONST_DWORDS];
641 };
642
643 struct tu_tile
644 {
645 uint8_t pipe;
646 uint8_t slot;
647 VkOffset2D begin;
648 VkOffset2D end;
649 };
650
651 struct tu_tiling_config
652 {
653 VkRect2D render_area;
654
655 /* position and size of the first tile */
656 VkRect2D tile0;
657 /* number of tiles */
658 VkExtent2D tile_count;
659
660 /* size of the first VSC pipe */
661 VkExtent2D pipe0;
662 /* number of VSC pipes */
663 VkExtent2D pipe_count;
664
665 /* pipe register values */
666 uint32_t pipe_config[MAX_VSC_PIPES];
667 uint32_t pipe_sizes[MAX_VSC_PIPES];
668
669 /* Whether sysmem rendering must be used */
670 bool force_sysmem;
671 };
672
673 enum tu_cmd_dirty_bits
674 {
675 TU_CMD_DIRTY_COMPUTE_PIPELINE = 1 << 1,
676 TU_CMD_DIRTY_VERTEX_BUFFERS = 1 << 2,
677 TU_CMD_DIRTY_DESCRIPTOR_SETS = 1 << 3,
678 TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS = 1 << 4,
679 TU_CMD_DIRTY_SHADER_CONSTS = 1 << 5,
680 /* all draw states were disabled and need to be re-enabled: */
681 TU_CMD_DIRTY_DRAW_STATE = 1 << 7,
682 };
683
684 /* There are only three cache domains we have to care about: the CCU, or
685 * color cache unit, which is used for color and depth/stencil attachments
686 * and copy/blit destinations, and is split conceptually into color and depth,
687 * and the universal cache or UCHE which is used for pretty much everything
688 * else, except for the CP (uncached) and host. We need to flush whenever data
689 * crosses these boundaries.
690 */
691
692 enum tu_cmd_access_mask {
693 TU_ACCESS_UCHE_READ = 1 << 0,
694 TU_ACCESS_UCHE_WRITE = 1 << 1,
695 TU_ACCESS_CCU_COLOR_READ = 1 << 2,
696 TU_ACCESS_CCU_COLOR_WRITE = 1 << 3,
697 TU_ACCESS_CCU_DEPTH_READ = 1 << 4,
698 TU_ACCESS_CCU_DEPTH_WRITE = 1 << 5,
699
700 /* Experiments have shown that while it's safe to avoid flushing the CCU
701 * after each blit/renderpass, it's not safe to assume that subsequent
702 * lookups with a different attachment state will hit unflushed cache
703 * entries. That is, the CCU needs to be flushed and possibly invalidated
704 * when accessing memory with a different attachment state. Writing to an
705 * attachment under the following conditions after clearing using the
706 * normal 2d engine path is known to have issues:
707 *
708 * - It isn't the 0'th layer.
709 * - There are more than one attachment, and this isn't the 0'th attachment
710 * (this seems to also depend on the cpp of the attachments).
711 *
712 * Our best guess is that the layer/MRT state is used when computing
713 * the location of a cache entry in CCU, to avoid conflicts. We assume that
714 * any access in a renderpass after or before an access by a transfer needs
715 * a flush/invalidate, and use the _INCOHERENT variants to represent access
716 * by a transfer.
717 */
718 TU_ACCESS_CCU_COLOR_INCOHERENT_READ = 1 << 6,
719 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE = 1 << 7,
720 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ = 1 << 8,
721 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE = 1 << 9,
722
723 TU_ACCESS_SYSMEM_READ = 1 << 10,
724 TU_ACCESS_SYSMEM_WRITE = 1 << 11,
725
726 /* Set if a WFI is required due to data being read by the CP or the 2D
727 * engine.
728 */
729 TU_ACCESS_WFI_READ = 1 << 12,
730
731 TU_ACCESS_READ =
732 TU_ACCESS_UCHE_READ |
733 TU_ACCESS_CCU_COLOR_READ |
734 TU_ACCESS_CCU_DEPTH_READ |
735 TU_ACCESS_CCU_COLOR_INCOHERENT_READ |
736 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ |
737 TU_ACCESS_SYSMEM_READ,
738
739 TU_ACCESS_WRITE =
740 TU_ACCESS_UCHE_WRITE |
741 TU_ACCESS_CCU_COLOR_WRITE |
742 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE |
743 TU_ACCESS_CCU_DEPTH_WRITE |
744 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE |
745 TU_ACCESS_SYSMEM_WRITE,
746
747 TU_ACCESS_ALL =
748 TU_ACCESS_READ |
749 TU_ACCESS_WRITE,
750 };
751
752 enum tu_cmd_flush_bits {
753 TU_CMD_FLAG_CCU_FLUSH_DEPTH = 1 << 0,
754 TU_CMD_FLAG_CCU_FLUSH_COLOR = 1 << 1,
755 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH = 1 << 2,
756 TU_CMD_FLAG_CCU_INVALIDATE_COLOR = 1 << 3,
757 TU_CMD_FLAG_CACHE_FLUSH = 1 << 4,
758 TU_CMD_FLAG_CACHE_INVALIDATE = 1 << 5,
759
760 TU_CMD_FLAG_ALL_FLUSH =
761 TU_CMD_FLAG_CCU_FLUSH_DEPTH |
762 TU_CMD_FLAG_CCU_FLUSH_COLOR |
763 TU_CMD_FLAG_CACHE_FLUSH,
764
765 TU_CMD_FLAG_ALL_INVALIDATE =
766 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH |
767 TU_CMD_FLAG_CCU_INVALIDATE_COLOR |
768 TU_CMD_FLAG_CACHE_INVALIDATE,
769
770 TU_CMD_FLAG_WFI = 1 << 6,
771 };
772
773 /* Changing the CCU from sysmem mode to gmem mode or vice-versa is pretty
774 * heavy, involving a CCU cache flush/invalidate and a WFI in order to change
775 * which part of the gmem is used by the CCU. Here we keep track of what the
776 * state of the CCU.
777 */
778 enum tu_cmd_ccu_state {
779 TU_CMD_CCU_SYSMEM,
780 TU_CMD_CCU_GMEM,
781 TU_CMD_CCU_UNKNOWN,
782 };
783
784 struct tu_cache_state {
785 /* Caches which must be made available (flushed) eventually if there are
786 * any users outside that cache domain, and caches which must be
787 * invalidated eventually if there are any reads.
788 */
789 enum tu_cmd_flush_bits pending_flush_bits;
790 /* Pending flushes */
791 enum tu_cmd_flush_bits flush_bits;
792 };
793
794 struct tu_cmd_state
795 {
796 uint32_t dirty;
797
798 struct tu_pipeline *pipeline;
799 struct tu_pipeline *compute_pipeline;
800
801 /* Vertex buffers */
802 struct
803 {
804 struct tu_buffer *buffers[MAX_VBS];
805 VkDeviceSize offsets[MAX_VBS];
806 } vb;
807
808 /* for dynamic states that can't be emitted directly */
809 uint32_t dynamic_stencil_mask;
810 uint32_t dynamic_stencil_wrmask;
811 uint32_t dynamic_stencil_ref;
812 uint32_t dynamic_gras_su_cntl;
813
814 /* saved states to re-emit in TU_CMD_DIRTY_DRAW_STATE case */
815 struct tu_draw_state dynamic_state[TU_DYNAMIC_STATE_COUNT];
816 struct tu_cs_entry vertex_buffers_ib;
817 struct tu_cs_entry shader_const_ib[MESA_SHADER_STAGES];
818 struct tu_cs_entry desc_sets_ib, desc_sets_load_ib;
819 struct tu_cs_entry ia_gmem_ib, ia_sysmem_ib;
820
821 struct tu_draw_state vs_params;
822
823 /* Index buffer */
824 uint64_t index_va;
825 uint32_t max_index_count;
826 uint8_t index_size;
827
828 /* because streamout base has to be 32-byte aligned
829 * there is an extra offset to deal with when it is
830 * unaligned
831 */
832 uint8_t streamout_offset[IR3_MAX_SO_BUFFERS];
833
834 /* Renderpasses are tricky, because we may need to flush differently if
835 * using sysmem vs. gmem and therefore we have to delay any flushing that
836 * happens before a renderpass. So we have to have two copies of the flush
837 * state, one for intra-renderpass flushes (i.e. renderpass dependencies)
838 * and one for outside a renderpass.
839 */
840 struct tu_cache_state cache;
841 struct tu_cache_state renderpass_cache;
842
843 enum tu_cmd_ccu_state ccu_state;
844
845 const struct tu_render_pass *pass;
846 const struct tu_subpass *subpass;
847 const struct tu_framebuffer *framebuffer;
848
849 struct tu_tiling_config tiling_config;
850
851 struct tu_cs_entry tile_store_ib;
852
853 bool xfb_used;
854 };
855
856 struct tu_cmd_pool
857 {
858 VkAllocationCallbacks alloc;
859 struct list_head cmd_buffers;
860 struct list_head free_cmd_buffers;
861 uint32_t queue_family_index;
862 };
863
864 struct tu_cmd_buffer_upload
865 {
866 uint8_t *map;
867 unsigned offset;
868 uint64_t size;
869 struct list_head list;
870 };
871
872 enum tu_cmd_buffer_status
873 {
874 TU_CMD_BUFFER_STATUS_INVALID,
875 TU_CMD_BUFFER_STATUS_INITIAL,
876 TU_CMD_BUFFER_STATUS_RECORDING,
877 TU_CMD_BUFFER_STATUS_EXECUTABLE,
878 TU_CMD_BUFFER_STATUS_PENDING,
879 };
880
881 struct tu_bo_list
882 {
883 uint32_t count;
884 uint32_t capacity;
885 struct drm_msm_gem_submit_bo *bo_infos;
886 };
887
888 #define TU_BO_LIST_FAILED (~0)
889
890 void
891 tu_bo_list_init(struct tu_bo_list *list);
892 void
893 tu_bo_list_destroy(struct tu_bo_list *list);
894 void
895 tu_bo_list_reset(struct tu_bo_list *list);
896 uint32_t
897 tu_bo_list_add(struct tu_bo_list *list,
898 const struct tu_bo *bo,
899 uint32_t flags);
900 VkResult
901 tu_bo_list_merge(struct tu_bo_list *list, const struct tu_bo_list *other);
902
903 /* This struct defines the layout of the scratch_bo */
904 struct tu6_control
905 {
906 uint32_t seqno_dummy; /* dummy seqno for CP_EVENT_WRITE */
907 uint32_t _pad0;
908 volatile uint32_t vsc_overflow;
909 uint32_t _pad1;
910 /* flag set from cmdstream when VSC overflow detected: */
911 uint32_t vsc_scratch;
912 uint32_t _pad2;
913 uint32_t _pad3;
914 uint32_t _pad4;
915
916 /* scratch space for VPC_SO[i].FLUSH_BASE_LO/HI, start on 32 byte boundary. */
917 struct {
918 uint32_t offset;
919 uint32_t pad[7];
920 } flush_base[4];
921 };
922
923 #define ctrl_offset(member) offsetof(struct tu6_control, member)
924
925 struct tu_cmd_buffer
926 {
927 VK_LOADER_DATA _loader_data;
928
929 struct tu_device *device;
930
931 struct tu_cmd_pool *pool;
932 struct list_head pool_link;
933
934 VkCommandBufferUsageFlags usage_flags;
935 VkCommandBufferLevel level;
936 enum tu_cmd_buffer_status status;
937
938 struct tu_cmd_state state;
939 struct tu_vertex_binding vertex_bindings[MAX_VBS];
940 uint32_t vertex_bindings_set;
941 uint32_t queue_family_index;
942
943 uint32_t push_constants[MAX_PUSH_CONSTANTS_SIZE / 4];
944 VkShaderStageFlags push_constant_stages;
945 struct tu_descriptor_set meta_push_descriptors;
946
947 struct tu_descriptor_state descriptors[MAX_BIND_POINTS];
948
949 struct tu_cmd_buffer_upload upload;
950
951 VkResult record_result;
952
953 struct tu_bo_list bo_list;
954 struct tu_cs cs;
955 struct tu_cs draw_cs;
956 struct tu_cs draw_epilogue_cs;
957 struct tu_cs sub_cs;
958
959 struct tu_bo scratch_bo;
960
961 bool has_tess;
962
963 struct tu_bo vsc_draw_strm;
964 struct tu_bo vsc_prim_strm;
965 uint32_t vsc_draw_strm_pitch;
966 uint32_t vsc_prim_strm_pitch;
967 bool use_vsc_data;
968 };
969
970 /* Temporary struct for tracking a register state to be written, used by
971 * a6xx-pack.h and tu_cs_emit_regs()
972 */
973 struct tu_reg_value {
974 uint32_t reg;
975 uint64_t value;
976 bool is_address;
977 struct tu_bo *bo;
978 bool bo_write;
979 uint32_t bo_offset;
980 uint32_t bo_shift;
981 };
982
983
984 void tu_emit_cache_flush_renderpass(struct tu_cmd_buffer *cmd_buffer,
985 struct tu_cs *cs);
986
987 void tu_emit_cache_flush_ccu(struct tu_cmd_buffer *cmd_buffer,
988 struct tu_cs *cs,
989 enum tu_cmd_ccu_state ccu_state);
990
991 void
992 tu6_emit_event_write(struct tu_cmd_buffer *cmd,
993 struct tu_cs *cs,
994 enum vgt_event_type event);
995
996 static inline struct tu_descriptor_state *
997 tu_get_descriptors_state(struct tu_cmd_buffer *cmd_buffer,
998 VkPipelineBindPoint bind_point)
999 {
1000 return &cmd_buffer->descriptors[bind_point];
1001 }
1002
1003 struct tu_event
1004 {
1005 struct tu_bo bo;
1006 };
1007
1008 struct tu_shader_module
1009 {
1010 unsigned char sha1[20];
1011
1012 uint32_t code_size;
1013 const uint32_t *code[0];
1014 };
1015
1016 struct tu_push_constant_range
1017 {
1018 uint32_t lo;
1019 uint32_t count;
1020 };
1021
1022 struct tu_shader
1023 {
1024 struct ir3_shader *ir3_shader;
1025
1026 struct tu_push_constant_range push_consts;
1027 uint8_t active_desc_sets;
1028 };
1029
1030 struct tu_shader *
1031 tu_shader_create(struct tu_device *dev,
1032 gl_shader_stage stage,
1033 const VkPipelineShaderStageCreateInfo *stage_info,
1034 struct tu_pipeline_layout *layout,
1035 const VkAllocationCallbacks *alloc);
1036
1037 void
1038 tu_shader_destroy(struct tu_device *dev,
1039 struct tu_shader *shader,
1040 const VkAllocationCallbacks *alloc);
1041
1042 struct tu_program_descriptor_linkage
1043 {
1044 struct ir3_const_state const_state;
1045
1046 uint32_t constlen;
1047
1048 struct tu_push_constant_range push_consts;
1049 };
1050
1051 struct tu_pipeline
1052 {
1053 struct tu_cs cs;
1054
1055 struct tu_pipeline_layout *layout;
1056
1057 bool need_indirect_descriptor_sets;
1058 VkShaderStageFlags active_stages;
1059 uint32_t active_desc_sets;
1060
1061 /* mask of enabled dynamic states
1062 * if BIT(i) is set, pipeline->dynamic_state[i] is *NOT* used
1063 */
1064 uint32_t dynamic_state_mask;
1065 struct tu_draw_state dynamic_state[TU_DYNAMIC_STATE_COUNT];
1066
1067 /* gras_su_cntl without line width, used for dynamic line width state */
1068 uint32_t gras_su_cntl;
1069
1070 struct
1071 {
1072 struct tu_cs_entry state_ib;
1073 struct tu_cs_entry binning_state_ib;
1074
1075 struct tu_program_descriptor_linkage link[MESA_SHADER_STAGES];
1076 } program;
1077
1078 struct
1079 {
1080 struct tu_cs_entry state_ib;
1081 } load_state;
1082
1083 struct
1084 {
1085 struct tu_cs_entry state_ib;
1086 struct tu_cs_entry binning_state_ib;
1087 uint32_t bindings_used;
1088 } vi;
1089
1090 struct
1091 {
1092 enum pc_di_primtype primtype;
1093 bool primitive_restart;
1094 } ia;
1095
1096 struct
1097 {
1098 uint32_t patch_type;
1099 uint32_t per_vertex_output_size;
1100 uint32_t per_patch_output_size;
1101 uint32_t hs_bo_regid;
1102 uint32_t ds_bo_regid;
1103 bool upper_left_domain_origin;
1104 } tess;
1105
1106 struct
1107 {
1108 struct tu_cs_entry state_ib;
1109 } rast;
1110
1111 struct
1112 {
1113 struct tu_cs_entry state_ib;
1114 } ds;
1115
1116 struct
1117 {
1118 struct tu_cs_entry state_ib;
1119 } blend;
1120
1121 struct
1122 {
1123 uint32_t local_size[3];
1124 } compute;
1125 };
1126
1127 void
1128 tu6_emit_viewport(struct tu_cs *cs, const VkViewport *viewport);
1129
1130 void
1131 tu6_emit_scissor(struct tu_cs *cs, const VkRect2D *scissor);
1132
1133 void
1134 tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp_loc);
1135
1136 void
1137 tu6_emit_depth_bias(struct tu_cs *cs,
1138 float constant_factor,
1139 float clamp,
1140 float slope_factor);
1141
1142 void tu6_emit_msaa(struct tu_cs *cs, VkSampleCountFlagBits samples);
1143
1144 void tu6_emit_window_scissor(struct tu_cs *cs, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2);
1145
1146 void tu6_emit_window_offset(struct tu_cs *cs, uint32_t x1, uint32_t y1);
1147
1148 void
1149 tu6_emit_xs_config(struct tu_cs *cs,
1150 gl_shader_stage stage,
1151 const struct ir3_shader_variant *xs,
1152 uint64_t binary_iova);
1153
1154 void
1155 tu6_emit_vpc(struct tu_cs *cs,
1156 const struct ir3_shader_variant *vs,
1157 const struct ir3_shader_variant *hs,
1158 const struct ir3_shader_variant *ds,
1159 const struct ir3_shader_variant *gs,
1160 const struct ir3_shader_variant *fs);
1161
1162 void
1163 tu6_emit_fs_inputs(struct tu_cs *cs, const struct ir3_shader_variant *fs);
1164
1165 struct tu_image_view;
1166
1167 void
1168 tu_resolve_sysmem(struct tu_cmd_buffer *cmd,
1169 struct tu_cs *cs,
1170 struct tu_image_view *src,
1171 struct tu_image_view *dst,
1172 uint32_t layers,
1173 const VkRect2D *rect);
1174
1175 void
1176 tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
1177 struct tu_cs *cs,
1178 uint32_t a,
1179 const VkRenderPassBeginInfo *info);
1180
1181 void
1182 tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
1183 struct tu_cs *cs,
1184 uint32_t a,
1185 const VkRenderPassBeginInfo *info);
1186
1187 void
1188 tu_load_gmem_attachment(struct tu_cmd_buffer *cmd,
1189 struct tu_cs *cs,
1190 uint32_t a,
1191 bool force_load);
1192
1193 /* expose this function to be able to emit load without checking LOAD_OP */
1194 void
1195 tu_emit_load_gmem_attachment(struct tu_cmd_buffer *cmd, struct tu_cs *cs, uint32_t a);
1196
1197 /* note: gmem store can also resolve */
1198 void
1199 tu_store_gmem_attachment(struct tu_cmd_buffer *cmd,
1200 struct tu_cs *cs,
1201 uint32_t a,
1202 uint32_t gmem_a);
1203
1204 enum tu_supported_formats {
1205 FMT_VERTEX = 1,
1206 FMT_TEXTURE = 2,
1207 FMT_COLOR = 4,
1208 };
1209
1210 struct tu_native_format
1211 {
1212 enum a6xx_format fmt : 8;
1213 enum a3xx_color_swap swap : 8;
1214 enum a6xx_tile_mode tile_mode : 8;
1215 enum tu_supported_formats supported : 8;
1216 };
1217
1218 struct tu_native_format tu6_format_vtx(VkFormat format);
1219 struct tu_native_format tu6_format_color(VkFormat format, enum a6xx_tile_mode tile_mode);
1220 struct tu_native_format tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode);
1221
1222 static inline enum a6xx_format
1223 tu6_base_format(VkFormat format)
1224 {
1225 /* note: tu6_format_color doesn't care about tiling for .fmt field */
1226 return tu6_format_color(format, TILE6_LINEAR).fmt;
1227 }
1228
1229 struct tu_image
1230 {
1231 VkImageType type;
1232 /* The original VkFormat provided by the client. This may not match any
1233 * of the actual surface formats.
1234 */
1235 VkFormat vk_format;
1236 VkImageAspectFlags aspects;
1237 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1238 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1239 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
1240 VkExtent3D extent;
1241 uint32_t level_count;
1242 uint32_t layer_count;
1243 VkSampleCountFlagBits samples;
1244
1245 struct fdl_layout layout;
1246
1247 unsigned queue_family_mask;
1248 bool exclusive;
1249 bool shareable;
1250
1251 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1252 VkDeviceMemory owned_memory;
1253
1254 /* Set when bound */
1255 struct tu_bo *bo;
1256 VkDeviceSize bo_offset;
1257 };
1258
1259 static inline uint32_t
1260 tu_get_layerCount(const struct tu_image *image,
1261 const VkImageSubresourceRange *range)
1262 {
1263 return range->layerCount == VK_REMAINING_ARRAY_LAYERS
1264 ? image->layer_count - range->baseArrayLayer
1265 : range->layerCount;
1266 }
1267
1268 static inline uint32_t
1269 tu_get_levelCount(const struct tu_image *image,
1270 const VkImageSubresourceRange *range)
1271 {
1272 return range->levelCount == VK_REMAINING_MIP_LEVELS
1273 ? image->level_count - range->baseMipLevel
1274 : range->levelCount;
1275 }
1276
1277 struct tu_image_view
1278 {
1279 struct tu_image *image; /**< VkImageViewCreateInfo::image */
1280
1281 uint64_t base_addr;
1282 uint64_t ubwc_addr;
1283 uint32_t layer_size;
1284 uint32_t ubwc_layer_size;
1285
1286 /* used to determine if fast gmem store path can be used */
1287 VkExtent2D extent;
1288 bool need_y2_align;
1289
1290 bool ubwc_enabled;
1291
1292 uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
1293
1294 /* Descriptor for use as a storage image as opposed to a sampled image.
1295 * This has a few differences for cube maps (e.g. type).
1296 */
1297 uint32_t storage_descriptor[A6XX_TEX_CONST_DWORDS];
1298
1299 /* pre-filled register values */
1300 uint32_t PITCH;
1301 uint32_t FLAG_BUFFER_PITCH;
1302
1303 uint32_t RB_MRT_BUF_INFO;
1304 uint32_t SP_FS_MRT_REG;
1305
1306 uint32_t SP_PS_2D_SRC_INFO;
1307 uint32_t SP_PS_2D_SRC_SIZE;
1308
1309 uint32_t RB_2D_DST_INFO;
1310
1311 uint32_t RB_BLIT_DST_INFO;
1312 };
1313
1314 struct tu_sampler_ycbcr_conversion {
1315 VkFormat format;
1316 VkSamplerYcbcrModelConversion ycbcr_model;
1317 VkSamplerYcbcrRange ycbcr_range;
1318 VkComponentMapping components;
1319 VkChromaLocation chroma_offsets[2];
1320 VkFilter chroma_filter;
1321 };
1322
1323 struct tu_sampler {
1324 uint32_t descriptor[A6XX_TEX_SAMP_DWORDS];
1325 struct tu_sampler_ycbcr_conversion *ycbcr_sampler;
1326 };
1327
1328 void
1329 tu_cs_image_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
1330
1331 void
1332 tu_cs_image_ref_2d(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer, bool src);
1333
1334 void
1335 tu_cs_image_flag_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
1336
1337 VkResult
1338 tu_image_create(VkDevice _device,
1339 const VkImageCreateInfo *pCreateInfo,
1340 const VkAllocationCallbacks *alloc,
1341 VkImage *pImage,
1342 uint64_t modifier,
1343 const VkSubresourceLayout *plane_layouts);
1344
1345 VkResult
1346 tu_image_from_gralloc(VkDevice device_h,
1347 const VkImageCreateInfo *base_info,
1348 const VkNativeBufferANDROID *gralloc_info,
1349 const VkAllocationCallbacks *alloc,
1350 VkImage *out_image_h);
1351
1352 void
1353 tu_image_view_init(struct tu_image_view *view,
1354 const VkImageViewCreateInfo *pCreateInfo);
1355
1356 struct tu_buffer_view
1357 {
1358 uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
1359
1360 struct tu_buffer *buffer;
1361 };
1362 void
1363 tu_buffer_view_init(struct tu_buffer_view *view,
1364 struct tu_device *device,
1365 const VkBufferViewCreateInfo *pCreateInfo);
1366
1367 struct tu_attachment_info
1368 {
1369 struct tu_image_view *attachment;
1370 };
1371
1372 struct tu_framebuffer
1373 {
1374 uint32_t width;
1375 uint32_t height;
1376 uint32_t layers;
1377
1378 uint32_t attachment_count;
1379 struct tu_attachment_info attachments[0];
1380 };
1381
1382 struct tu_subpass_barrier {
1383 VkPipelineStageFlags src_stage_mask;
1384 VkAccessFlags src_access_mask;
1385 VkAccessFlags dst_access_mask;
1386 bool incoherent_ccu_color, incoherent_ccu_depth;
1387 };
1388
1389 struct tu_subpass_attachment
1390 {
1391 uint32_t attachment;
1392 };
1393
1394 struct tu_subpass
1395 {
1396 uint32_t input_count;
1397 uint32_t color_count;
1398 struct tu_subpass_attachment *input_attachments;
1399 struct tu_subpass_attachment *color_attachments;
1400 struct tu_subpass_attachment *resolve_attachments;
1401 struct tu_subpass_attachment depth_stencil_attachment;
1402
1403 VkSampleCountFlagBits samples;
1404
1405 uint32_t srgb_cntl;
1406
1407 struct tu_subpass_barrier start_barrier;
1408 };
1409
1410 struct tu_render_pass_attachment
1411 {
1412 VkFormat format;
1413 uint32_t samples;
1414 uint32_t cpp;
1415 VkImageAspectFlags clear_mask;
1416 bool load;
1417 bool store;
1418 int32_t gmem_offset;
1419 };
1420
1421 struct tu_render_pass
1422 {
1423 uint32_t attachment_count;
1424 uint32_t subpass_count;
1425 uint32_t gmem_pixels;
1426 uint32_t tile_align_w;
1427 struct tu_subpass_attachment *subpass_attachments;
1428 struct tu_render_pass_attachment *attachments;
1429 struct tu_subpass_barrier end_barrier;
1430 struct tu_subpass subpasses[0];
1431 };
1432
1433 struct tu_query_pool
1434 {
1435 VkQueryType type;
1436 uint32_t stride;
1437 uint64_t size;
1438 uint32_t pipeline_statistics;
1439 struct tu_bo bo;
1440 };
1441
1442 enum tu_semaphore_kind
1443 {
1444 TU_SEMAPHORE_NONE,
1445 TU_SEMAPHORE_SYNCOBJ,
1446 };
1447
1448 struct tu_semaphore_part
1449 {
1450 enum tu_semaphore_kind kind;
1451 union {
1452 uint32_t syncobj;
1453 };
1454 };
1455
1456 struct tu_semaphore
1457 {
1458 struct tu_semaphore_part permanent;
1459 struct tu_semaphore_part temporary;
1460 };
1461
1462 void
1463 tu_set_descriptor_set(struct tu_cmd_buffer *cmd_buffer,
1464 VkPipelineBindPoint bind_point,
1465 struct tu_descriptor_set *set,
1466 unsigned idx);
1467
1468 void
1469 tu_update_descriptor_sets(struct tu_device *device,
1470 struct tu_cmd_buffer *cmd_buffer,
1471 VkDescriptorSet overrideSet,
1472 uint32_t descriptorWriteCount,
1473 const VkWriteDescriptorSet *pDescriptorWrites,
1474 uint32_t descriptorCopyCount,
1475 const VkCopyDescriptorSet *pDescriptorCopies);
1476
1477 void
1478 tu_update_descriptor_set_with_template(
1479 struct tu_device *device,
1480 struct tu_cmd_buffer *cmd_buffer,
1481 struct tu_descriptor_set *set,
1482 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1483 const void *pData);
1484
1485 int
1486 tu_drm_get_gpu_id(const struct tu_physical_device *dev, uint32_t *id);
1487
1488 int
1489 tu_drm_get_gmem_size(const struct tu_physical_device *dev, uint32_t *size);
1490
1491 int
1492 tu_drm_get_gmem_base(const struct tu_physical_device *dev, uint64_t *base);
1493
1494 int
1495 tu_drm_submitqueue_new(const struct tu_device *dev,
1496 int priority,
1497 uint32_t *queue_id);
1498
1499 void
1500 tu_drm_submitqueue_close(const struct tu_device *dev, uint32_t queue_id);
1501
1502 uint32_t
1503 tu_gem_new(const struct tu_device *dev, uint64_t size, uint32_t flags);
1504 uint32_t
1505 tu_gem_import_dmabuf(const struct tu_device *dev,
1506 int prime_fd,
1507 uint64_t size);
1508 int
1509 tu_gem_export_dmabuf(const struct tu_device *dev, uint32_t gem_handle);
1510 void
1511 tu_gem_close(const struct tu_device *dev, uint32_t gem_handle);
1512 uint64_t
1513 tu_gem_info_offset(const struct tu_device *dev, uint32_t gem_handle);
1514 uint64_t
1515 tu_gem_info_iova(const struct tu_device *dev, uint32_t gem_handle);
1516
1517 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1518 \
1519 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1520 { \
1521 return (struct __tu_type *) _handle; \
1522 } \
1523 \
1524 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1525 { \
1526 return (__VkType) _obj; \
1527 }
1528
1529 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1530 \
1531 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1532 { \
1533 return (struct __tu_type *) (uintptr_t) _handle; \
1534 } \
1535 \
1536 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1537 { \
1538 return (__VkType)(uintptr_t) _obj; \
1539 }
1540
1541 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1542 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1543
1544 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer, VkCommandBuffer)
1545 TU_DEFINE_HANDLE_CASTS(tu_device, VkDevice)
1546 TU_DEFINE_HANDLE_CASTS(tu_instance, VkInstance)
1547 TU_DEFINE_HANDLE_CASTS(tu_physical_device, VkPhysicalDevice)
1548 TU_DEFINE_HANDLE_CASTS(tu_queue, VkQueue)
1549
1550 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool, VkCommandPool)
1551 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer, VkBuffer)
1552 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view, VkBufferView)
1553 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool, VkDescriptorPool)
1554 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set, VkDescriptorSet)
1555 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout,
1556 VkDescriptorSetLayout)
1557 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template,
1558 VkDescriptorUpdateTemplate)
1559 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory, VkDeviceMemory)
1560 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence, VkFence)
1561 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event, VkEvent)
1562 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer, VkFramebuffer)
1563 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image, VkImage)
1564 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, VkImageView);
1565 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache, VkPipelineCache)
1566 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline, VkPipeline)
1567 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout, VkPipelineLayout)
1568 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool, VkQueryPool)
1569 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass, VkRenderPass)
1570 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, VkSampler)
1571 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
1572 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module, VkShaderModule)
1573 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore, VkSemaphore)
1574
1575 #endif /* TU_PRIVATE_H */