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