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