2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
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:
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
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.
43 #define VG(x) ((void)0)
46 #include "c11/threads.h"
47 #include "main/macros.h"
48 #include "util/list.h"
49 #include "util/macros.h"
51 #include "vk_debug_report.h"
52 #include "wsi_common.h"
54 #include "drm-uapi/msm_drm.h"
55 #include "ir3/ir3_compiler.h"
56 #include "ir3/ir3_shader.h"
58 #include "adreno_common.xml.h"
59 #include "adreno_pm4.xml.h"
61 #include "fdl/freedreno_layout.h"
63 #include "tu_descriptor_set.h"
64 #include "tu_extensions.h"
67 /* Pre-declarations needed for WSI entrypoints */
70 typedef struct xcb_connection_t xcb_connection_t
;
71 typedef uint32_t xcb_visualid_t
;
72 typedef uint32_t xcb_window_t
;
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>
79 #include "tu_entrypoints.h"
81 #include "vk_format.h"
84 #define MAX_VERTEX_ATTRIBS 32
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
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.
106 #define MAX_UNIFORM_BUFFER_RANGE 0x10000
108 #define A6XX_TEX_CONST_DWORDS 16
109 #define A6XX_TEX_SAMP_DWORDS 4
111 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
113 static inline uint32_t
114 tu_minify(uint32_t n
, uint32_t levels
)
116 if (unlikely(n
== 0))
119 return MAX2(n
>> levels
, 1);
122 #define for_each_bit(b, dword) \
123 for (uint32_t __dword = (dword); \
124 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
126 #define typed_memcpy(dest, src, count) \
128 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
129 memcpy((dest), (src), (count) * sizeof(*(src))); \
132 #define COND(bool, val) ((bool) ? (val) : 0)
133 #define BIT(bit) (1u << (bit))
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.
143 __vk_errorf(struct tu_instance
*instance
,
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__);
156 __tu_finishme(const char *file
, int line
, const char *format
, ...)
159 tu_loge(const char *format
, ...) tu_printflike(1, 2);
161 tu_logi(const char *format
, ...) tu_printflike(1, 2);
164 * Print a FINISHME message, including its source location.
166 #define tu_finishme(format, ...) \
168 static bool reported = false; \
170 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
177 tu_finishme("stub %s", __func__); \
181 tu_lookup_entrypoint_unchecked(const char *name
);
183 tu_lookup_entrypoint_checked(
185 uint32_t core_version
,
186 const struct tu_instance_extension_table
*instance
,
187 const struct tu_device_extension_table
*device
);
189 struct tu_physical_device
191 VK_LOADER_DATA _loader_data
;
193 struct tu_instance
*instance
;
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
];
201 struct wsi_device wsi_device
;
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
219 uint32_t PC_UNKNOWN_9805
;
220 uint32_t SP_UNKNOWN_A0F8
;
223 /* This is the drivers on-disk cache used as a fallback as opposed to
224 * the pipeline cache defined by apps.
226 struct disk_cache
*disk_cache
;
228 struct tu_device_extension_table supported_extensions
;
233 TU_DEBUG_STARTUP
= 1 << 0,
234 TU_DEBUG_NIR
= 1 << 1,
235 TU_DEBUG_IR3
= 1 << 2,
236 TU_DEBUG_NOBIN
= 1 << 3,
237 TU_DEBUG_SYSMEM
= 1 << 4,
238 TU_DEBUG_FORCEBIN
= 1 << 5,
239 TU_DEBUG_NOUBWC
= 1 << 6,
244 VK_LOADER_DATA _loader_data
;
246 VkAllocationCallbacks alloc
;
248 uint32_t api_version
;
249 int physical_device_count
;
250 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
252 enum tu_debug_flags debug_flags
;
254 struct vk_debug_report_instance debug_report_callbacks
;
256 struct tu_instance_extension_table enabled_extensions
;
260 tu_wsi_init(struct tu_physical_device
*physical_device
);
262 tu_wsi_finish(struct tu_physical_device
*physical_device
);
265 tu_instance_extension_supported(const char *name
);
267 tu_physical_device_api_version(struct tu_physical_device
*dev
);
269 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
274 struct tu_pipeline_cache
276 struct tu_device
*device
;
277 pthread_mutex_t mutex
;
281 uint32_t kernel_count
;
282 struct cache_entry
**hash_table
;
285 VkAllocationCallbacks alloc
;
288 struct tu_pipeline_key
294 #define TU_QUEUE_GENERAL 0
296 #define TU_MAX_QUEUE_FAMILIES 1
300 struct wsi_fence
*fence_wsi
;
306 tu_fence_init(struct tu_fence
*fence
, bool signaled
);
308 tu_fence_finish(struct tu_fence
*fence
);
310 tu_fence_update_fd(struct tu_fence
*fence
, int fd
);
312 tu_fence_copy(struct tu_fence
*fence
, const struct tu_fence
*src
);
314 tu_fence_signal(struct tu_fence
*fence
);
316 tu_fence_wait_idle(struct tu_fence
*fence
);
320 VK_LOADER_DATA _loader_data
;
321 struct tu_device
*device
;
322 uint32_t queue_family_index
;
324 VkDeviceQueueCreateFlags flags
;
326 uint32_t msm_queue_id
;
327 struct tu_fence submit_fence
;
340 VK_LOADER_DATA _loader_data
;
342 VkAllocationCallbacks alloc
;
344 struct tu_instance
*instance
;
346 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
347 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
349 struct tu_physical_device
*physical_device
;
351 struct ir3_compiler
*compiler
;
353 /* Backup in-memory cache to be used if the app doesn't provide one */
354 struct tu_pipeline_cache
*mem_cache
;
356 struct tu_bo vsc_draw_strm
;
357 struct tu_bo vsc_prim_strm
;
358 uint32_t vsc_draw_strm_pitch
;
359 uint32_t vsc_prim_strm_pitch
;
361 #define MIN_SCRATCH_BO_SIZE_LOG2 12 /* A page */
363 /* Currently the kernel driver uses a 32-bit GPU address space, but it
364 * should be impossible to go beyond 48 bits.
370 } scratch_bos
[48 - MIN_SCRATCH_BO_SIZE_LOG2
];
372 struct tu_bo border_color
;
374 struct tu_device_extension_table enabled_extensions
;
378 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
380 tu_bo_init_dmabuf(struct tu_device
*dev
,
385 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
);
387 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
389 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
391 /* Get a scratch bo for use inside a command buffer. This will always return
392 * the same bo given the same size or similar sizes, so only one scratch bo
393 * can be used at the same time. It's meant for short-lived things where we
394 * need to write to some piece of memory, read from it, and then immediately
398 tu_get_scratch_bo(struct tu_device
*dev
, uint64_t size
, struct tu_bo
**bo
);
403 const struct tu_bo
*bo
;
409 struct ts_cs_memory
{
414 struct tu_draw_state
{
419 enum tu_dynamic_state
421 /* re-use VK_DYNAMIC_STATE_ enums for non-extended dynamic states */
422 TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
= VK_DYNAMIC_STATE_STENCIL_REFERENCE
+ 1,
423 TU_DYNAMIC_STATE_COUNT
,
426 enum tu_draw_state_group_id
428 TU_DRAW_STATE_PROGRAM
,
429 TU_DRAW_STATE_PROGRAM_BINNING
,
433 TU_DRAW_STATE_VI_BINNING
,
437 TU_DRAW_STATE_VS_CONST
,
438 TU_DRAW_STATE_GS_CONST
,
439 TU_DRAW_STATE_FS_CONST
,
440 TU_DRAW_STATE_DESC_SETS
,
441 TU_DRAW_STATE_DESC_SETS_LOAD
,
442 TU_DRAW_STATE_VS_PARAMS
,
443 TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM
,
444 TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM
,
446 /* dynamic state related draw states */
447 TU_DRAW_STATE_DYNAMIC
,
448 TU_DRAW_STATE_COUNT
= TU_DRAW_STATE_DYNAMIC
+ TU_DYNAMIC_STATE_COUNT
,
455 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
456 * is full. tu_cs_begin must be called before command packet emission and
457 * tu_cs_end must be called after.
459 * This mode may create multiple entries internally. The entries must be
460 * submitted together.
465 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
466 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
469 * This mode does not create any entry or any BO.
474 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
475 * command packet emission. tu_cs_begin_sub_stream must be called to get a
476 * sub-stream to emit comamnd packets to. When done with the sub-stream,
477 * tu_cs_end_sub_stream must be called.
479 * This mode does not create any entry internally.
481 TU_CS_MODE_SUB_STREAM
,
488 uint32_t *reserved_end
;
491 struct tu_device
*device
;
492 enum tu_cs_mode mode
;
493 uint32_t next_bo_size
;
495 struct tu_cs_entry
*entries
;
496 uint32_t entry_count
;
497 uint32_t entry_capacity
;
501 uint32_t bo_capacity
;
503 /* state for cond_exec_start/cond_exec_end */
505 uint32_t *cond_dwords
;
508 struct tu_device_memory
513 /* for dedicated allocations */
514 struct tu_image
*image
;
515 struct tu_buffer
*buffer
;
522 struct tu_descriptor_range
528 struct tu_descriptor_set
530 const struct tu_descriptor_set_layout
*layout
;
531 struct tu_descriptor_pool
*pool
;
535 uint32_t *mapped_ptr
;
537 uint32_t *dynamic_descriptors
;
539 struct tu_bo
*buffers
[0];
542 struct tu_push_descriptor_set
544 struct tu_descriptor_set set
;
548 struct tu_descriptor_pool_entry
552 struct tu_descriptor_set
*set
;
555 struct tu_descriptor_pool
558 uint64_t current_offset
;
561 uint8_t *host_memory_base
;
562 uint8_t *host_memory_ptr
;
563 uint8_t *host_memory_end
;
565 uint32_t entry_count
;
566 uint32_t max_entry_count
;
567 struct tu_descriptor_pool_entry entries
[0];
570 struct tu_descriptor_update_template_entry
572 VkDescriptorType descriptor_type
;
574 /* The number of descriptors to update */
575 uint32_t descriptor_count
;
577 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
581 /* In dwords. Not valid/used for dynamic descriptors */
584 uint32_t buffer_offset
;
586 /* Only valid for combined image samplers and samplers */
587 uint16_t has_sampler
;
593 /* For push descriptors */
594 const uint32_t *immutable_samplers
;
597 struct tu_descriptor_update_template
599 uint32_t entry_count
;
600 struct tu_descriptor_update_template_entry entry
[0];
607 VkBufferUsageFlags usage
;
608 VkBufferCreateFlags flags
;
611 VkDeviceSize bo_offset
;
614 static inline uint64_t
615 tu_buffer_iova(struct tu_buffer
*buffer
)
617 return buffer
->bo
->iova
+ buffer
->bo_offset
;
620 struct tu_vertex_binding
622 struct tu_buffer
*buffer
;
627 tu_get_debug_option_name(int id
);
630 tu_get_perftest_option_name(int id
);
632 struct tu_descriptor_state
634 struct tu_descriptor_set
*sets
[MAX_SETS
];
635 uint32_t dynamic_descriptors
[MAX_DYNAMIC_BUFFERS
* A6XX_TEX_CONST_DWORDS
];
646 struct tu_tiling_config
648 VkRect2D render_area
;
650 /* position and size of the first tile */
652 /* number of tiles */
653 VkExtent2D tile_count
;
655 /* size of the first VSC pipe */
657 /* number of VSC pipes */
658 VkExtent2D pipe_count
;
660 /* pipe register values */
661 uint32_t pipe_config
[MAX_VSC_PIPES
];
662 uint32_t pipe_sizes
[MAX_VSC_PIPES
];
664 /* Whether sysmem rendering must be used */
668 enum tu_cmd_dirty_bits
670 TU_CMD_DIRTY_COMPUTE_PIPELINE
= 1 << 1,
671 TU_CMD_DIRTY_VERTEX_BUFFERS
= 1 << 2,
672 TU_CMD_DIRTY_DESCRIPTOR_SETS
= 1 << 3,
673 TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
= 1 << 4,
674 TU_CMD_DIRTY_SHADER_CONSTS
= 1 << 5,
675 TU_CMD_DIRTY_STREAMOUT_BUFFERS
= 1 << 6,
676 /* all draw states were disabled and need to be re-enabled: */
677 TU_CMD_DIRTY_DRAW_STATE
= 1 << 7,
680 struct tu_streamout_state
{
681 uint16_t stride
[IR3_MAX_SO_BUFFERS
];
682 uint32_t ncomp
[IR3_MAX_SO_BUFFERS
];
683 uint32_t prog
[IR3_MAX_SO_OUTPUTS
* 2];
685 uint32_t vpc_so_buf_cntl
;
688 /* There are only three cache domains we have to care about: the CCU, or
689 * color cache unit, which is used for color and depth/stencil attachments
690 * and copy/blit destinations, and is split conceptually into color and depth,
691 * and the universal cache or UCHE which is used for pretty much everything
692 * else, except for the CP (uncached) and host. We need to flush whenever data
693 * crosses these boundaries.
696 enum tu_cmd_access_mask
{
697 TU_ACCESS_UCHE_READ
= 1 << 0,
698 TU_ACCESS_UCHE_WRITE
= 1 << 1,
699 TU_ACCESS_CCU_COLOR_READ
= 1 << 2,
700 TU_ACCESS_CCU_COLOR_WRITE
= 1 << 3,
701 TU_ACCESS_CCU_DEPTH_READ
= 1 << 4,
702 TU_ACCESS_CCU_DEPTH_WRITE
= 1 << 5,
704 /* Experiments have shown that while it's safe to avoid flushing the CCU
705 * after each blit/renderpass, it's not safe to assume that subsequent
706 * lookups with a different attachment state will hit unflushed cache
707 * entries. That is, the CCU needs to be flushed and possibly invalidated
708 * when accessing memory with a different attachment state. Writing to an
709 * attachment under the following conditions after clearing using the
710 * normal 2d engine path is known to have issues:
712 * - It isn't the 0'th layer.
713 * - There are more than one attachment, and this isn't the 0'th attachment
714 * (this seems to also depend on the cpp of the attachments).
716 * Our best guess is that the layer/MRT state is used when computing
717 * the location of a cache entry in CCU, to avoid conflicts. We assume that
718 * any access in a renderpass after or before an access by a transfer needs
719 * a flush/invalidate, and use the _INCOHERENT variants to represent access
722 TU_ACCESS_CCU_COLOR_INCOHERENT_READ
= 1 << 6,
723 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
= 1 << 7,
724 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
= 1 << 8,
725 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
= 1 << 9,
727 TU_ACCESS_SYSMEM_READ
= 1 << 10,
728 TU_ACCESS_SYSMEM_WRITE
= 1 << 11,
730 /* Set if a WFI is required due to data being read by the CP or the 2D
733 TU_ACCESS_WFI_READ
= 1 << 12,
736 TU_ACCESS_UCHE_READ
|
737 TU_ACCESS_CCU_COLOR_READ
|
738 TU_ACCESS_CCU_DEPTH_READ
|
739 TU_ACCESS_CCU_COLOR_INCOHERENT_READ
|
740 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
|
741 TU_ACCESS_SYSMEM_READ
,
744 TU_ACCESS_UCHE_WRITE
|
745 TU_ACCESS_CCU_COLOR_WRITE
|
746 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
|
747 TU_ACCESS_CCU_DEPTH_WRITE
|
748 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
|
749 TU_ACCESS_SYSMEM_WRITE
,
756 enum tu_cmd_flush_bits
{
757 TU_CMD_FLAG_CCU_FLUSH_DEPTH
= 1 << 0,
758 TU_CMD_FLAG_CCU_FLUSH_COLOR
= 1 << 1,
759 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
= 1 << 2,
760 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
= 1 << 3,
761 TU_CMD_FLAG_CACHE_FLUSH
= 1 << 4,
762 TU_CMD_FLAG_CACHE_INVALIDATE
= 1 << 5,
764 TU_CMD_FLAG_ALL_FLUSH
=
765 TU_CMD_FLAG_CCU_FLUSH_DEPTH
|
766 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
767 TU_CMD_FLAG_CACHE_FLUSH
,
769 TU_CMD_FLAG_ALL_INVALIDATE
=
770 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
|
771 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
|
772 TU_CMD_FLAG_CACHE_INVALIDATE
,
774 TU_CMD_FLAG_WFI
= 1 << 6,
777 /* Changing the CCU from sysmem mode to gmem mode or vice-versa is pretty
778 * heavy, involving a CCU cache flush/invalidate and a WFI in order to change
779 * which part of the gmem is used by the CCU. Here we keep track of what the
782 enum tu_cmd_ccu_state
{
788 struct tu_cache_state
{
789 /* Caches which must be made available (flushed) eventually if there are
790 * any users outside that cache domain, and caches which must be
791 * invalidated eventually if there are any reads.
793 enum tu_cmd_flush_bits pending_flush_bits
;
794 /* Pending flushes */
795 enum tu_cmd_flush_bits flush_bits
;
802 struct tu_pipeline
*pipeline
;
803 struct tu_pipeline
*compute_pipeline
;
808 struct tu_buffer
*buffers
[MAX_VBS
];
809 VkDeviceSize offsets
[MAX_VBS
];
812 /* for dynamic states that can't be emitted directly */
813 uint32_t dynamic_stencil_mask
;
814 uint32_t dynamic_stencil_wrmask
;
815 uint32_t dynamic_stencil_ref
;
816 uint32_t dynamic_gras_su_cntl
;
818 /* saved states to re-emit in TU_CMD_DIRTY_DRAW_STATE case */
819 struct tu_draw_state dynamic_state
[TU_DYNAMIC_STATE_COUNT
];
820 struct tu_cs_entry vertex_buffers_ib
;
821 struct tu_cs_entry shader_const_ib
[MESA_SHADER_STAGES
];
822 struct tu_cs_entry desc_sets_ib
, desc_sets_load_ib
;
823 struct tu_cs_entry ia_gmem_ib
, ia_sysmem_ib
;
825 /* Stream output buffers */
828 struct tu_buffer
*buffers
[IR3_MAX_SO_BUFFERS
];
829 VkDeviceSize offsets
[IR3_MAX_SO_BUFFERS
];
830 VkDeviceSize sizes
[IR3_MAX_SO_BUFFERS
];
833 uint8_t streamout_reset
;
834 uint8_t streamout_enabled
;
837 struct tu_buffer
*index_buffer
;
838 uint64_t index_offset
;
840 uint32_t max_index_count
;
843 /* Renderpasses are tricky, because we may need to flush differently if
844 * using sysmem vs. gmem and therefore we have to delay any flushing that
845 * happens before a renderpass. So we have to have two copies of the flush
846 * state, one for intra-renderpass flushes (i.e. renderpass dependencies)
847 * and one for outside a renderpass.
849 struct tu_cache_state cache
;
850 struct tu_cache_state renderpass_cache
;
852 enum tu_cmd_ccu_state ccu_state
;
854 const struct tu_render_pass
*pass
;
855 const struct tu_subpass
*subpass
;
856 const struct tu_framebuffer
*framebuffer
;
858 struct tu_tiling_config tiling_config
;
860 struct tu_cs_entry tile_store_ib
;
865 VkAllocationCallbacks alloc
;
866 struct list_head cmd_buffers
;
867 struct list_head free_cmd_buffers
;
868 uint32_t queue_family_index
;
871 struct tu_cmd_buffer_upload
876 struct list_head list
;
879 enum tu_cmd_buffer_status
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
,
892 struct drm_msm_gem_submit_bo
*bo_infos
;
895 #define TU_BO_LIST_FAILED (~0)
898 tu_bo_list_init(struct tu_bo_list
*list
);
900 tu_bo_list_destroy(struct tu_bo_list
*list
);
902 tu_bo_list_reset(struct tu_bo_list
*list
);
904 tu_bo_list_add(struct tu_bo_list
*list
,
905 const struct tu_bo
*bo
,
908 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
);
910 /* This struct defines the layout of the scratch_bo */
913 uint32_t seqno_dummy
; /* dummy seqno for CP_EVENT_WRITE */
915 volatile uint32_t vsc_overflow
;
917 /* flag set from cmdstream when VSC overflow detected: */
918 uint32_t vsc_scratch
;
923 /* scratch space for VPC_SO[i].FLUSH_BASE_LO/HI, start on 32 byte boundary. */
930 #define ctrl_offset(member) offsetof(struct tu6_control, member)
934 VK_LOADER_DATA _loader_data
;
936 struct tu_device
*device
;
938 struct tu_cmd_pool
*pool
;
939 struct list_head pool_link
;
941 VkCommandBufferUsageFlags usage_flags
;
942 VkCommandBufferLevel level
;
943 enum tu_cmd_buffer_status status
;
945 struct tu_cmd_state state
;
946 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
947 uint32_t vertex_bindings_set
;
948 uint32_t queue_family_index
;
950 uint32_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
/ 4];
951 VkShaderStageFlags push_constant_stages
;
952 struct tu_descriptor_set meta_push_descriptors
;
954 struct tu_descriptor_state descriptors
[MAX_BIND_POINTS
];
956 struct tu_cmd_buffer_upload upload
;
958 VkResult record_result
;
960 struct tu_bo_list bo_list
;
962 struct tu_cs draw_cs
;
963 struct tu_cs draw_epilogue_cs
;
966 struct tu_bo scratch_bo
;
968 struct tu_bo vsc_draw_strm
;
969 struct tu_bo vsc_prim_strm
;
970 uint32_t vsc_draw_strm_pitch
;
971 uint32_t vsc_prim_strm_pitch
;
975 /* Temporary struct for tracking a register state to be written, used by
976 * a6xx-pack.h and tu_cs_emit_regs()
978 struct tu_reg_value
{
989 void tu_emit_cache_flush_renderpass(struct tu_cmd_buffer
*cmd_buffer
,
992 void tu_emit_cache_flush_ccu(struct tu_cmd_buffer
*cmd_buffer
,
994 enum tu_cmd_ccu_state ccu_state
);
997 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
999 enum vgt_event_type event
);
1001 static inline struct tu_descriptor_state
*
1002 tu_get_descriptors_state(struct tu_cmd_buffer
*cmd_buffer
,
1003 VkPipelineBindPoint bind_point
)
1005 return &cmd_buffer
->descriptors
[bind_point
];
1013 struct tu_shader_module
1015 unsigned char sha1
[20];
1018 const uint32_t *code
[0];
1021 struct tu_push_constant_range
1029 struct ir3_shader
*ir3_shader
;
1031 struct tu_push_constant_range push_consts
;
1032 uint8_t active_desc_sets
;
1036 tu_shader_create(struct tu_device
*dev
,
1037 gl_shader_stage stage
,
1038 const VkPipelineShaderStageCreateInfo
*stage_info
,
1039 struct tu_pipeline_layout
*layout
,
1040 const VkAllocationCallbacks
*alloc
);
1043 tu_shader_destroy(struct tu_device
*dev
,
1044 struct tu_shader
*shader
,
1045 const VkAllocationCallbacks
*alloc
);
1047 struct tu_program_descriptor_linkage
1049 struct ir3_const_state const_state
;
1053 struct tu_push_constant_range push_consts
;
1060 struct tu_pipeline_layout
*layout
;
1062 bool need_indirect_descriptor_sets
;
1063 VkShaderStageFlags active_stages
;
1064 uint32_t active_desc_sets
;
1066 struct tu_streamout_state streamout
;
1068 /* mask of enabled dynamic states
1069 * if BIT(i) is set, pipeline->dynamic_state[i] is *NOT* used
1071 uint32_t dynamic_state_mask
;
1072 struct tu_draw_state dynamic_state
[TU_DYNAMIC_STATE_COUNT
];
1074 /* gras_su_cntl without line width, used for dynamic line width state */
1075 uint32_t gras_su_cntl
;
1079 struct tu_bo binary_bo
;
1080 struct tu_cs_entry state_ib
;
1081 struct tu_cs_entry binning_state_ib
;
1083 struct tu_program_descriptor_linkage link
[MESA_SHADER_STAGES
];
1088 struct tu_cs_entry state_ib
;
1093 struct tu_cs_entry state_ib
;
1094 struct tu_cs_entry binning_state_ib
;
1095 uint32_t bindings_used
;
1100 enum pc_di_primtype primtype
;
1101 bool primitive_restart
;
1106 uint32_t patch_type
;
1107 uint32_t per_vertex_output_size
;
1108 uint32_t per_patch_output_size
;
1109 uint32_t hs_bo_regid
;
1110 uint32_t ds_bo_regid
;
1115 struct tu_cs_entry state_ib
;
1120 struct tu_cs_entry state_ib
;
1125 struct tu_cs_entry state_ib
;
1130 uint32_t local_size
[3];
1135 tu6_emit_viewport(struct tu_cs
*cs
, const VkViewport
*viewport
);
1138 tu6_emit_scissor(struct tu_cs
*cs
, const VkRect2D
*scissor
);
1141 tu6_emit_sample_locations(struct tu_cs
*cs
, const VkSampleLocationsInfoEXT
*samp_loc
);
1144 tu6_emit_depth_bias(struct tu_cs
*cs
,
1145 float constant_factor
,
1147 float slope_factor
);
1149 void tu6_emit_msaa(struct tu_cs
*cs
, VkSampleCountFlagBits samples
);
1151 void tu6_emit_window_scissor(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
, uint32_t x2
, uint32_t y2
);
1153 void tu6_emit_window_offset(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
);
1156 tu6_emit_xs_config(struct tu_cs
*cs
,
1157 gl_shader_stage stage
,
1158 const struct ir3_shader_variant
*xs
,
1159 uint64_t binary_iova
);
1162 tu6_emit_vpc(struct tu_cs
*cs
,
1163 const struct ir3_shader_variant
*vs
,
1164 const struct ir3_shader_variant
*hs
,
1165 const struct ir3_shader_variant
*ds
,
1166 const struct ir3_shader_variant
*gs
,
1167 const struct ir3_shader_variant
*fs
,
1168 struct tu_streamout_state
*tf
);
1171 tu6_emit_fs_inputs(struct tu_cs
*cs
, const struct ir3_shader_variant
*fs
);
1173 struct tu_image_view
;
1176 tu_resolve_sysmem(struct tu_cmd_buffer
*cmd
,
1178 struct tu_image_view
*src
,
1179 struct tu_image_view
*dst
,
1181 const VkRect2D
*rect
);
1184 tu_clear_sysmem_attachment(struct tu_cmd_buffer
*cmd
,
1187 const VkRenderPassBeginInfo
*info
);
1190 tu_clear_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1193 const VkRenderPassBeginInfo
*info
);
1196 tu_load_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1201 /* expose this function to be able to emit load without checking LOAD_OP */
1203 tu_emit_load_gmem_attachment(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
, uint32_t a
);
1205 /* note: gmem store can also resolve */
1207 tu_store_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1212 enum tu_supported_formats
{
1218 struct tu_native_format
1220 enum a6xx_format fmt
: 8;
1221 enum a3xx_color_swap swap
: 8;
1222 enum a6xx_tile_mode tile_mode
: 8;
1223 enum tu_supported_formats supported
: 8;
1226 struct tu_native_format
tu6_format_vtx(VkFormat format
);
1227 struct tu_native_format
tu6_format_color(VkFormat format
, enum a6xx_tile_mode tile_mode
);
1228 struct tu_native_format
tu6_format_texture(VkFormat format
, enum a6xx_tile_mode tile_mode
);
1230 static inline enum a6xx_format
1231 tu6_base_format(VkFormat format
)
1233 /* note: tu6_format_color doesn't care about tiling for .fmt field */
1234 return tu6_format_color(format
, TILE6_LINEAR
).fmt
;
1240 /* The original VkFormat provided by the client. This may not match any
1241 * of the actual surface formats.
1244 VkImageAspectFlags aspects
;
1245 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1246 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1247 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
1249 uint32_t level_count
;
1250 uint32_t layer_count
;
1251 VkSampleCountFlagBits samples
;
1253 struct fdl_layout layout
;
1255 unsigned queue_family_mask
;
1259 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1260 VkDeviceMemory owned_memory
;
1262 /* Set when bound */
1264 VkDeviceSize bo_offset
;
1267 static inline uint32_t
1268 tu_get_layerCount(const struct tu_image
*image
,
1269 const VkImageSubresourceRange
*range
)
1271 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
1272 ? image
->layer_count
- range
->baseArrayLayer
1273 : range
->layerCount
;
1276 static inline uint32_t
1277 tu_get_levelCount(const struct tu_image
*image
,
1278 const VkImageSubresourceRange
*range
)
1280 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
1281 ? image
->level_count
- range
->baseMipLevel
1282 : range
->levelCount
;
1285 struct tu_image_view
1287 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
1291 uint32_t layer_size
;
1292 uint32_t ubwc_layer_size
;
1294 /* used to determine if fast gmem store path can be used */
1300 uint32_t descriptor
[A6XX_TEX_CONST_DWORDS
];
1302 /* Descriptor for use as a storage image as opposed to a sampled image.
1303 * This has a few differences for cube maps (e.g. type).
1305 uint32_t storage_descriptor
[A6XX_TEX_CONST_DWORDS
];
1307 /* pre-filled register values */
1309 uint32_t FLAG_BUFFER_PITCH
;
1311 uint32_t RB_MRT_BUF_INFO
;
1312 uint32_t SP_FS_MRT_REG
;
1314 uint32_t SP_PS_2D_SRC_INFO
;
1315 uint32_t SP_PS_2D_SRC_SIZE
;
1317 uint32_t RB_2D_DST_INFO
;
1319 uint32_t RB_BLIT_DST_INFO
;
1322 struct tu_sampler_ycbcr_conversion
{
1324 VkSamplerYcbcrModelConversion ycbcr_model
;
1325 VkSamplerYcbcrRange ycbcr_range
;
1326 VkComponentMapping components
;
1327 VkChromaLocation chroma_offsets
[2];
1328 VkFilter chroma_filter
;
1332 uint32_t descriptor
[A6XX_TEX_SAMP_DWORDS
];
1333 struct tu_sampler_ycbcr_conversion
*ycbcr_sampler
;
1337 tu_cs_image_ref(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
);
1340 tu_cs_image_ref_2d(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
, bool src
);
1343 tu_cs_image_flag_ref(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
);
1346 tu_image_create(VkDevice _device
,
1347 const VkImageCreateInfo
*pCreateInfo
,
1348 const VkAllocationCallbacks
*alloc
,
1351 const VkSubresourceLayout
*plane_layouts
);
1354 tu_image_from_gralloc(VkDevice device_h
,
1355 const VkImageCreateInfo
*base_info
,
1356 const VkNativeBufferANDROID
*gralloc_info
,
1357 const VkAllocationCallbacks
*alloc
,
1358 VkImage
*out_image_h
);
1361 tu_image_view_init(struct tu_image_view
*view
,
1362 const VkImageViewCreateInfo
*pCreateInfo
);
1364 struct tu_buffer_view
1366 uint32_t descriptor
[A6XX_TEX_CONST_DWORDS
];
1368 struct tu_buffer
*buffer
;
1371 tu_buffer_view_init(struct tu_buffer_view
*view
,
1372 struct tu_device
*device
,
1373 const VkBufferViewCreateInfo
*pCreateInfo
);
1375 struct tu_attachment_info
1377 struct tu_image_view
*attachment
;
1380 struct tu_framebuffer
1386 uint32_t attachment_count
;
1387 struct tu_attachment_info attachments
[0];
1390 struct tu_subpass_barrier
{
1391 VkPipelineStageFlags src_stage_mask
;
1392 VkAccessFlags src_access_mask
;
1393 VkAccessFlags dst_access_mask
;
1394 bool incoherent_ccu_color
, incoherent_ccu_depth
;
1397 struct tu_subpass_attachment
1399 uint32_t attachment
;
1400 VkImageLayout layout
;
1405 uint32_t input_count
;
1406 uint32_t color_count
;
1407 struct tu_subpass_attachment
*input_attachments
;
1408 struct tu_subpass_attachment
*color_attachments
;
1409 struct tu_subpass_attachment
*resolve_attachments
;
1410 struct tu_subpass_attachment depth_stencil_attachment
;
1412 VkSampleCountFlagBits samples
;
1413 bool has_external_src
, has_external_dst
;
1417 struct tu_subpass_barrier start_barrier
;
1420 struct tu_render_pass_attachment
1425 VkImageAspectFlags clear_mask
;
1428 VkImageLayout initial_layout
, final_layout
;
1429 int32_t gmem_offset
;
1432 struct tu_render_pass
1434 uint32_t attachment_count
;
1435 uint32_t subpass_count
;
1436 uint32_t gmem_pixels
;
1437 uint32_t tile_align_w
;
1438 struct tu_subpass_attachment
*subpass_attachments
;
1439 struct tu_render_pass_attachment
*attachments
;
1440 struct tu_subpass_barrier end_barrier
;
1441 struct tu_subpass subpasses
[0];
1444 struct tu_query_pool
1449 uint32_t pipeline_statistics
;
1456 uint32_t temp_syncobj
;
1460 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1461 VkPipelineBindPoint bind_point
,
1462 struct tu_descriptor_set
*set
,
1466 tu_update_descriptor_sets(struct tu_device
*device
,
1467 struct tu_cmd_buffer
*cmd_buffer
,
1468 VkDescriptorSet overrideSet
,
1469 uint32_t descriptorWriteCount
,
1470 const VkWriteDescriptorSet
*pDescriptorWrites
,
1471 uint32_t descriptorCopyCount
,
1472 const VkCopyDescriptorSet
*pDescriptorCopies
);
1475 tu_update_descriptor_set_with_template(
1476 struct tu_device
*device
,
1477 struct tu_cmd_buffer
*cmd_buffer
,
1478 struct tu_descriptor_set
*set
,
1479 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1483 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
);
1486 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
);
1489 tu_drm_get_gmem_base(const struct tu_physical_device
*dev
, uint64_t *base
);
1492 tu_drm_submitqueue_new(const struct tu_device
*dev
,
1494 uint32_t *queue_id
);
1497 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
);
1500 tu_gem_new(const struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1502 tu_gem_import_dmabuf(const struct tu_device
*dev
,
1506 tu_gem_export_dmabuf(const struct tu_device
*dev
, uint32_t gem_handle
);
1508 tu_gem_close(const struct tu_device
*dev
, uint32_t gem_handle
);
1510 tu_gem_info_offset(const struct tu_device
*dev
, uint32_t gem_handle
);
1512 tu_gem_info_iova(const struct tu_device
*dev
, uint32_t gem_handle
);
1514 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1516 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1518 return (struct __tu_type *) _handle; \
1521 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1523 return (__VkType) _obj; \
1526 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1528 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1530 return (struct __tu_type *) (uintptr_t) _handle; \
1533 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1535 return (__VkType)(uintptr_t) _obj; \
1538 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1539 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1541 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1542 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1543 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1544 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1545 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1547 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1548 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1549 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1550 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1551 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1552 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1553 VkDescriptorSetLayout
)
1554 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1555 VkDescriptorUpdateTemplate
)
1556 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1557 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1558 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1559 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1560 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1561 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1562 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1563 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1564 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1565 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1566 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1567 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1568 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler_ycbcr_conversion
, VkSamplerYcbcrConversion
)
1569 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1570 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1572 #endif /* TU_PRIVATE_H */