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"
66 /* Pre-declarations needed for WSI entrypoints */
69 typedef struct xcb_connection_t xcb_connection_t
;
70 typedef uint32_t xcb_visualid_t
;
71 typedef uint32_t xcb_window_t
;
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>
78 #include "tu_entrypoints.h"
80 #include "vk_format.h"
83 #define MAX_VERTEX_ATTRIBS 32
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
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.
105 #define MAX_UNIFORM_BUFFER_RANGE 0x10000
107 #define A6XX_TEX_CONST_DWORDS 16
108 #define A6XX_TEX_SAMP_DWORDS 4
110 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
112 static inline uint32_t
113 tu_minify(uint32_t n
, uint32_t levels
)
115 if (unlikely(n
== 0))
118 return MAX2(n
>> levels
, 1);
121 #define for_each_bit(b, dword) \
122 for (uint32_t __dword = (dword); \
123 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
125 #define typed_memcpy(dest, src, count) \
127 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
128 memcpy((dest), (src), (count) * sizeof(*(src))); \
131 #define COND(bool, val) ((bool) ? (val) : 0)
132 #define BIT(bit) (1u << (bit))
134 /* Whenever we generate an error, pass it through this function. Useful for
135 * debugging, where we can break on it. Only call at error site, not when
136 * propagating errors. Might be useful to plug in a stack trace here.
142 __vk_errorf(struct tu_instance
*instance
,
149 #define vk_error(instance, error) \
150 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
151 #define vk_errorf(instance, error, format, ...) \
152 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
155 __tu_finishme(const char *file
, int line
, const char *format
, ...)
158 tu_loge(const char *format
, ...) tu_printflike(1, 2);
160 tu_logi(const char *format
, ...) tu_printflike(1, 2);
163 * Print a FINISHME message, including its source location.
165 #define tu_finishme(format, ...) \
167 static bool reported = false; \
169 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
176 tu_finishme("stub %s", __func__); \
180 tu_lookup_entrypoint_unchecked(const char *name
);
182 tu_lookup_entrypoint_checked(
184 uint32_t core_version
,
185 const struct tu_instance_extension_table
*instance
,
186 const struct tu_device_extension_table
*device
);
188 struct tu_physical_device
190 VK_LOADER_DATA _loader_data
;
192 struct tu_instance
*instance
;
195 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
196 uint8_t driver_uuid
[VK_UUID_SIZE
];
197 uint8_t device_uuid
[VK_UUID_SIZE
];
198 uint8_t cache_uuid
[VK_UUID_SIZE
];
200 struct wsi_device wsi_device
;
208 uint32_t ccu_offset_gmem
;
209 uint32_t ccu_offset_bypass
;
210 /* alignment for size of tiles */
211 uint32_t tile_align_w
;
212 #define TILE_ALIGN_H 16
213 /* gmem store/load granularity */
214 #define GMEM_ALIGN_W 16
215 #define GMEM_ALIGN_H 4
218 uint32_t PC_UNKNOWN_9805
;
219 uint32_t SP_UNKNOWN_A0F8
;
222 /* This is the drivers on-disk cache used as a fallback as opposed to
223 * the pipeline cache defined by apps.
225 struct disk_cache
*disk_cache
;
227 struct tu_device_extension_table supported_extensions
;
232 TU_DEBUG_STARTUP
= 1 << 0,
233 TU_DEBUG_NIR
= 1 << 1,
234 TU_DEBUG_IR3
= 1 << 2,
235 TU_DEBUG_NOBIN
= 1 << 3,
236 TU_DEBUG_SYSMEM
= 1 << 4,
237 TU_DEBUG_FORCEBIN
= 1 << 5,
238 TU_DEBUG_NOUBWC
= 1 << 6,
243 VK_LOADER_DATA _loader_data
;
245 VkAllocationCallbacks alloc
;
247 uint32_t api_version
;
248 int physical_device_count
;
249 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
251 enum tu_debug_flags debug_flags
;
253 struct vk_debug_report_instance debug_report_callbacks
;
255 struct tu_instance_extension_table enabled_extensions
;
259 tu_wsi_init(struct tu_physical_device
*physical_device
);
261 tu_wsi_finish(struct tu_physical_device
*physical_device
);
264 tu_instance_extension_supported(const char *name
);
266 tu_physical_device_api_version(struct tu_physical_device
*dev
);
268 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
273 struct tu_pipeline_cache
275 struct tu_device
*device
;
276 pthread_mutex_t mutex
;
280 uint32_t kernel_count
;
281 struct cache_entry
**hash_table
;
284 VkAllocationCallbacks alloc
;
287 struct tu_pipeline_key
293 #define TU_QUEUE_GENERAL 0
295 #define TU_MAX_QUEUE_FAMILIES 1
299 struct wsi_fence
*fence_wsi
;
305 tu_fence_init(struct tu_fence
*fence
, bool signaled
);
307 tu_fence_finish(struct tu_fence
*fence
);
309 tu_fence_update_fd(struct tu_fence
*fence
, int fd
);
311 tu_fence_copy(struct tu_fence
*fence
, const struct tu_fence
*src
);
313 tu_fence_signal(struct tu_fence
*fence
);
315 tu_fence_wait_idle(struct tu_fence
*fence
);
319 VK_LOADER_DATA _loader_data
;
320 struct tu_device
*device
;
321 uint32_t queue_family_index
;
323 VkDeviceQueueCreateFlags flags
;
325 uint32_t msm_queue_id
;
326 struct tu_fence submit_fence
;
339 VK_LOADER_DATA _loader_data
;
341 VkAllocationCallbacks alloc
;
343 struct tu_instance
*instance
;
345 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
346 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
348 struct tu_physical_device
*physical_device
;
350 struct ir3_compiler
*compiler
;
352 /* Backup in-memory cache to be used if the app doesn't provide one */
353 struct tu_pipeline_cache
*mem_cache
;
355 struct tu_bo vsc_draw_strm
;
356 struct tu_bo vsc_prim_strm
;
357 uint32_t vsc_draw_strm_pitch
;
358 uint32_t vsc_prim_strm_pitch
;
360 #define MIN_SCRATCH_BO_SIZE_LOG2 12 /* A page */
362 /* Currently the kernel driver uses a 32-bit GPU address space, but it
363 * should be impossible to go beyond 48 bits.
369 } scratch_bos
[48 - MIN_SCRATCH_BO_SIZE_LOG2
];
371 struct tu_bo border_color
;
373 struct tu_device_extension_table enabled_extensions
;
377 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
379 tu_bo_init_dmabuf(struct tu_device
*dev
,
384 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
);
386 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
388 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
390 /* Get a scratch bo for use inside a command buffer. This will always return
391 * the same bo given the same size or similar sizes, so only one scratch bo
392 * can be used at the same time. It's meant for short-lived things where we
393 * need to write to some piece of memory, read from it, and then immediately
397 tu_get_scratch_bo(struct tu_device
*dev
, uint64_t size
, struct tu_bo
**bo
);
402 const struct tu_bo
*bo
;
408 struct ts_cs_memory
{
413 struct tu_draw_state
{
418 enum tu_dynamic_state
420 /* re-use VK_DYNAMIC_STATE_ enums for non-extended dynamic states */
421 TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
= VK_DYNAMIC_STATE_STENCIL_REFERENCE
+ 1,
422 TU_DYNAMIC_STATE_COUNT
,
425 enum tu_draw_state_group_id
427 TU_DRAW_STATE_PROGRAM
,
428 TU_DRAW_STATE_PROGRAM_BINNING
,
431 TU_DRAW_STATE_VI_BINNING
,
435 TU_DRAW_STATE_VS_CONST
,
436 TU_DRAW_STATE_GS_CONST
,
437 TU_DRAW_STATE_FS_CONST
,
438 TU_DRAW_STATE_DESC_SETS
,
439 TU_DRAW_STATE_DESC_SETS_LOAD
,
440 TU_DRAW_STATE_VS_PARAMS
,
441 TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM
,
442 TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM
,
444 /* dynamic state related draw states */
445 TU_DRAW_STATE_DYNAMIC
,
446 TU_DRAW_STATE_COUNT
= TU_DRAW_STATE_DYNAMIC
+ TU_DYNAMIC_STATE_COUNT
,
453 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
454 * is full. tu_cs_begin must be called before command packet emission and
455 * tu_cs_end must be called after.
457 * This mode may create multiple entries internally. The entries must be
458 * submitted together.
463 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
464 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
467 * This mode does not create any entry or any BO.
472 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
473 * command packet emission. tu_cs_begin_sub_stream must be called to get a
474 * sub-stream to emit comamnd packets to. When done with the sub-stream,
475 * tu_cs_end_sub_stream must be called.
477 * This mode does not create any entry internally.
479 TU_CS_MODE_SUB_STREAM
,
486 uint32_t *reserved_end
;
489 struct tu_device
*device
;
490 enum tu_cs_mode mode
;
491 uint32_t next_bo_size
;
493 struct tu_cs_entry
*entries
;
494 uint32_t entry_count
;
495 uint32_t entry_capacity
;
499 uint32_t bo_capacity
;
501 /* state for cond_exec_start/cond_exec_end */
503 uint32_t *cond_dwords
;
506 struct tu_device_memory
511 /* for dedicated allocations */
512 struct tu_image
*image
;
513 struct tu_buffer
*buffer
;
520 struct tu_descriptor_range
526 struct tu_descriptor_set
528 const struct tu_descriptor_set_layout
*layout
;
529 struct tu_descriptor_pool
*pool
;
533 uint32_t *mapped_ptr
;
535 uint32_t *dynamic_descriptors
;
537 struct tu_bo
*buffers
[0];
540 struct tu_push_descriptor_set
542 struct tu_descriptor_set set
;
546 struct tu_descriptor_pool_entry
550 struct tu_descriptor_set
*set
;
553 struct tu_descriptor_pool
556 uint64_t current_offset
;
559 uint8_t *host_memory_base
;
560 uint8_t *host_memory_ptr
;
561 uint8_t *host_memory_end
;
563 uint32_t entry_count
;
564 uint32_t max_entry_count
;
565 struct tu_descriptor_pool_entry entries
[0];
568 struct tu_descriptor_update_template_entry
570 VkDescriptorType descriptor_type
;
572 /* The number of descriptors to update */
573 uint32_t descriptor_count
;
575 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
579 /* In dwords. Not valid/used for dynamic descriptors */
582 uint32_t buffer_offset
;
584 /* Only valid for combined image samplers and samplers */
585 uint16_t has_sampler
;
591 /* For push descriptors */
592 const uint32_t *immutable_samplers
;
595 struct tu_descriptor_update_template
597 uint32_t entry_count
;
598 struct tu_descriptor_update_template_entry entry
[0];
605 VkBufferUsageFlags usage
;
606 VkBufferCreateFlags flags
;
609 VkDeviceSize bo_offset
;
612 static inline uint64_t
613 tu_buffer_iova(struct tu_buffer
*buffer
)
615 return buffer
->bo
->iova
+ buffer
->bo_offset
;
618 struct tu_vertex_binding
620 struct tu_buffer
*buffer
;
625 tu_get_debug_option_name(int id
);
628 tu_get_perftest_option_name(int id
);
630 struct tu_descriptor_state
632 struct tu_descriptor_set
*sets
[MAX_SETS
];
633 uint32_t dynamic_descriptors
[MAX_DYNAMIC_BUFFERS
* A6XX_TEX_CONST_DWORDS
];
644 struct tu_tiling_config
646 VkRect2D render_area
;
648 /* position and size of the first tile */
650 /* number of tiles */
651 VkExtent2D tile_count
;
653 /* size of the first VSC pipe */
655 /* number of VSC pipes */
656 VkExtent2D pipe_count
;
658 /* pipe register values */
659 uint32_t pipe_config
[MAX_VSC_PIPES
];
660 uint32_t pipe_sizes
[MAX_VSC_PIPES
];
662 /* Whether sysmem rendering must be used */
666 enum tu_cmd_dirty_bits
668 TU_CMD_DIRTY_COMPUTE_PIPELINE
= 1 << 1,
669 TU_CMD_DIRTY_VERTEX_BUFFERS
= 1 << 2,
670 TU_CMD_DIRTY_DESCRIPTOR_SETS
= 1 << 3,
671 TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
= 1 << 4,
672 TU_CMD_DIRTY_SHADER_CONSTS
= 1 << 5,
673 TU_CMD_DIRTY_STREAMOUT_BUFFERS
= 1 << 6,
674 /* all draw states were disabled and need to be re-enabled: */
675 TU_CMD_DIRTY_DRAW_STATE
= 1 << 7,
678 struct tu_streamout_state
{
679 uint16_t stride
[IR3_MAX_SO_BUFFERS
];
680 uint32_t ncomp
[IR3_MAX_SO_BUFFERS
];
681 uint32_t prog
[IR3_MAX_SO_OUTPUTS
* 2];
683 uint32_t vpc_so_buf_cntl
;
686 /* There are only three cache domains we have to care about: the CCU, or
687 * color cache unit, which is used for color and depth/stencil attachments
688 * and copy/blit destinations, and is split conceptually into color and depth,
689 * and the universal cache or UCHE which is used for pretty much everything
690 * else, except for the CP (uncached) and host. We need to flush whenever data
691 * crosses these boundaries.
694 enum tu_cmd_access_mask
{
695 TU_ACCESS_UCHE_READ
= 1 << 0,
696 TU_ACCESS_UCHE_WRITE
= 1 << 1,
697 TU_ACCESS_CCU_COLOR_READ
= 1 << 2,
698 TU_ACCESS_CCU_COLOR_WRITE
= 1 << 3,
699 TU_ACCESS_CCU_DEPTH_READ
= 1 << 4,
700 TU_ACCESS_CCU_DEPTH_WRITE
= 1 << 5,
702 /* Experiments have shown that while it's safe to avoid flushing the CCU
703 * after each blit/renderpass, it's not safe to assume that subsequent
704 * lookups with a different attachment state will hit unflushed cache
705 * entries. That is, the CCU needs to be flushed and possibly invalidated
706 * when accessing memory with a different attachment state. Writing to an
707 * attachment under the following conditions after clearing using the
708 * normal 2d engine path is known to have issues:
710 * - It isn't the 0'th layer.
711 * - There are more than one attachment, and this isn't the 0'th attachment
712 * (this seems to also depend on the cpp of the attachments).
714 * Our best guess is that the layer/MRT state is used when computing
715 * the location of a cache entry in CCU, to avoid conflicts. We assume that
716 * any access in a renderpass after or before an access by a transfer needs
717 * a flush/invalidate, and use the _INCOHERENT variants to represent access
720 TU_ACCESS_CCU_COLOR_INCOHERENT_READ
= 1 << 6,
721 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
= 1 << 7,
722 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
= 1 << 8,
723 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
= 1 << 9,
725 TU_ACCESS_SYSMEM_READ
= 1 << 10,
726 TU_ACCESS_SYSMEM_WRITE
= 1 << 11,
728 /* Set if a WFI is required due to data being read by the CP or the 2D
731 TU_ACCESS_WFI_READ
= 1 << 12,
734 TU_ACCESS_UCHE_READ
|
735 TU_ACCESS_CCU_COLOR_READ
|
736 TU_ACCESS_CCU_DEPTH_READ
|
737 TU_ACCESS_CCU_COLOR_INCOHERENT_READ
|
738 TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
|
739 TU_ACCESS_SYSMEM_READ
,
742 TU_ACCESS_UCHE_WRITE
|
743 TU_ACCESS_CCU_COLOR_WRITE
|
744 TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
|
745 TU_ACCESS_CCU_DEPTH_WRITE
|
746 TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
|
747 TU_ACCESS_SYSMEM_WRITE
,
754 enum tu_cmd_flush_bits
{
755 TU_CMD_FLAG_CCU_FLUSH_DEPTH
= 1 << 0,
756 TU_CMD_FLAG_CCU_FLUSH_COLOR
= 1 << 1,
757 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
= 1 << 2,
758 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
= 1 << 3,
759 TU_CMD_FLAG_CACHE_FLUSH
= 1 << 4,
760 TU_CMD_FLAG_CACHE_INVALIDATE
= 1 << 5,
762 TU_CMD_FLAG_ALL_FLUSH
=
763 TU_CMD_FLAG_CCU_FLUSH_DEPTH
|
764 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
765 TU_CMD_FLAG_CACHE_FLUSH
,
767 TU_CMD_FLAG_ALL_INVALIDATE
=
768 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
|
769 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
|
770 TU_CMD_FLAG_CACHE_INVALIDATE
,
772 TU_CMD_FLAG_WFI
= 1 << 6,
775 /* Changing the CCU from sysmem mode to gmem mode or vice-versa is pretty
776 * heavy, involving a CCU cache flush/invalidate and a WFI in order to change
777 * which part of the gmem is used by the CCU. Here we keep track of what the
780 enum tu_cmd_ccu_state
{
786 struct tu_cache_state
{
787 /* Caches which must be made available (flushed) eventually if there are
788 * any users outside that cache domain, and caches which must be
789 * invalidated eventually if there are any reads.
791 enum tu_cmd_flush_bits pending_flush_bits
;
792 /* Pending flushes */
793 enum tu_cmd_flush_bits flush_bits
;
800 struct tu_pipeline
*pipeline
;
801 struct tu_pipeline
*compute_pipeline
;
806 struct tu_buffer
*buffers
[MAX_VBS
];
807 VkDeviceSize offsets
[MAX_VBS
];
810 /* for dynamic states that can't be emitted directly */
811 uint32_t dynamic_stencil_mask
;
812 uint32_t dynamic_stencil_wrmask
;
813 uint32_t dynamic_stencil_ref
;
814 uint32_t dynamic_gras_su_cntl
;
816 /* saved states to re-emit in TU_CMD_DIRTY_DRAW_STATE case */
817 struct tu_draw_state dynamic_state
[TU_DYNAMIC_STATE_COUNT
];
818 struct tu_cs_entry vertex_buffers_ib
;
819 struct tu_cs_entry shader_const_ib
[MESA_SHADER_STAGES
];
820 struct tu_cs_entry desc_sets_ib
, desc_sets_load_ib
;
821 struct tu_cs_entry ia_gmem_ib
, ia_sysmem_ib
;
823 /* Stream output buffers */
826 struct tu_buffer
*buffers
[IR3_MAX_SO_BUFFERS
];
827 VkDeviceSize offsets
[IR3_MAX_SO_BUFFERS
];
828 VkDeviceSize sizes
[IR3_MAX_SO_BUFFERS
];
831 uint8_t streamout_reset
;
832 uint8_t streamout_enabled
;
835 struct tu_buffer
*index_buffer
;
836 uint64_t index_offset
;
838 uint32_t max_index_count
;
841 /* Renderpasses are tricky, because we may need to flush differently if
842 * using sysmem vs. gmem and therefore we have to delay any flushing that
843 * happens before a renderpass. So we have to have two copies of the flush
844 * state, one for intra-renderpass flushes (i.e. renderpass dependencies)
845 * and one for outside a renderpass.
847 struct tu_cache_state cache
;
848 struct tu_cache_state renderpass_cache
;
850 enum tu_cmd_ccu_state ccu_state
;
852 const struct tu_render_pass
*pass
;
853 const struct tu_subpass
*subpass
;
854 const struct tu_framebuffer
*framebuffer
;
856 struct tu_tiling_config tiling_config
;
858 struct tu_cs_entry tile_store_ib
;
863 VkAllocationCallbacks alloc
;
864 struct list_head cmd_buffers
;
865 struct list_head free_cmd_buffers
;
866 uint32_t queue_family_index
;
869 struct tu_cmd_buffer_upload
874 struct list_head list
;
877 enum tu_cmd_buffer_status
879 TU_CMD_BUFFER_STATUS_INVALID
,
880 TU_CMD_BUFFER_STATUS_INITIAL
,
881 TU_CMD_BUFFER_STATUS_RECORDING
,
882 TU_CMD_BUFFER_STATUS_EXECUTABLE
,
883 TU_CMD_BUFFER_STATUS_PENDING
,
890 struct drm_msm_gem_submit_bo
*bo_infos
;
893 #define TU_BO_LIST_FAILED (~0)
896 tu_bo_list_init(struct tu_bo_list
*list
);
898 tu_bo_list_destroy(struct tu_bo_list
*list
);
900 tu_bo_list_reset(struct tu_bo_list
*list
);
902 tu_bo_list_add(struct tu_bo_list
*list
,
903 const struct tu_bo
*bo
,
906 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
);
908 /* This struct defines the layout of the scratch_bo */
911 uint32_t seqno_dummy
; /* dummy seqno for CP_EVENT_WRITE */
913 volatile uint32_t vsc_overflow
;
915 /* flag set from cmdstream when VSC overflow detected: */
916 uint32_t vsc_scratch
;
921 /* scratch space for VPC_SO[i].FLUSH_BASE_LO/HI, start on 32 byte boundary. */
928 #define ctrl_offset(member) offsetof(struct tu6_control, member)
932 VK_LOADER_DATA _loader_data
;
934 struct tu_device
*device
;
936 struct tu_cmd_pool
*pool
;
937 struct list_head pool_link
;
939 VkCommandBufferUsageFlags usage_flags
;
940 VkCommandBufferLevel level
;
941 enum tu_cmd_buffer_status status
;
943 struct tu_cmd_state state
;
944 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
945 uint32_t vertex_bindings_set
;
946 uint32_t queue_family_index
;
948 uint32_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
/ 4];
949 VkShaderStageFlags push_constant_stages
;
950 struct tu_descriptor_set meta_push_descriptors
;
952 struct tu_descriptor_state descriptors
[MAX_BIND_POINTS
];
954 struct tu_cmd_buffer_upload upload
;
956 VkResult record_result
;
958 struct tu_bo_list bo_list
;
960 struct tu_cs draw_cs
;
961 struct tu_cs draw_epilogue_cs
;
964 struct tu_bo scratch_bo
;
966 struct tu_bo vsc_draw_strm
;
967 struct tu_bo vsc_prim_strm
;
968 uint32_t vsc_draw_strm_pitch
;
969 uint32_t vsc_prim_strm_pitch
;
973 /* Temporary struct for tracking a register state to be written, used by
974 * a6xx-pack.h and tu_cs_emit_regs()
976 struct tu_reg_value
{
987 void tu_emit_cache_flush_renderpass(struct tu_cmd_buffer
*cmd_buffer
,
990 void tu_emit_cache_flush_ccu(struct tu_cmd_buffer
*cmd_buffer
,
992 enum tu_cmd_ccu_state ccu_state
);
995 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
997 enum vgt_event_type event
);
999 static inline struct tu_descriptor_state
*
1000 tu_get_descriptors_state(struct tu_cmd_buffer
*cmd_buffer
,
1001 VkPipelineBindPoint bind_point
)
1003 return &cmd_buffer
->descriptors
[bind_point
];
1011 static inline gl_shader_stage
1012 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1014 assert(__builtin_popcount(vk_stage
) == 1);
1015 return ffs(vk_stage
) - 1;
1018 static inline VkShaderStageFlagBits
1019 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1021 return (1 << mesa_stage
);
1024 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1026 #define tu_foreach_stage(stage, stage_bits) \
1027 for (gl_shader_stage stage, \
1028 __tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
1029 stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
1032 tu6_stage2opcode(gl_shader_stage type
);
1033 enum a6xx_state_block
1034 tu6_stage2shadersb(gl_shader_stage type
);
1036 struct tu_shader_module
1038 unsigned char sha1
[20];
1041 const uint32_t *code
[0];
1044 struct tu_push_constant_range
1052 struct ir3_shader
*ir3_shader
;
1054 struct tu_push_constant_range push_consts
;
1055 uint8_t active_desc_sets
;
1059 tu_shader_create(struct tu_device
*dev
,
1060 gl_shader_stage stage
,
1061 const VkPipelineShaderStageCreateInfo
*stage_info
,
1062 struct tu_pipeline_layout
*layout
,
1063 const VkAllocationCallbacks
*alloc
);
1066 tu_shader_destroy(struct tu_device
*dev
,
1067 struct tu_shader
*shader
,
1068 const VkAllocationCallbacks
*alloc
);
1070 struct tu_program_descriptor_linkage
1072 struct ir3_ubo_analysis_state ubo_state
;
1073 struct ir3_const_state const_state
;
1077 struct tu_push_constant_range push_consts
;
1084 struct tu_pipeline_layout
*layout
;
1086 bool need_indirect_descriptor_sets
;
1087 VkShaderStageFlags active_stages
;
1088 uint32_t active_desc_sets
;
1090 struct tu_streamout_state streamout
;
1092 /* mask of enabled dynamic states
1093 * if BIT(i) is set, pipeline->dynamic_state[i] is *NOT* used
1095 uint32_t dynamic_state_mask
;
1096 struct tu_draw_state dynamic_state
[TU_DYNAMIC_STATE_COUNT
];
1098 /* gras_su_cntl without line width, used for dynamic line width state */
1099 uint32_t gras_su_cntl
;
1103 struct tu_bo binary_bo
;
1104 struct tu_cs_entry state_ib
;
1105 struct tu_cs_entry binning_state_ib
;
1107 struct tu_program_descriptor_linkage link
[MESA_SHADER_STAGES
];
1112 struct tu_cs_entry state_ib
;
1117 struct tu_cs_entry state_ib
;
1118 struct tu_cs_entry binning_state_ib
;
1119 uint32_t bindings_used
;
1124 enum pc_di_primtype primtype
;
1125 bool primitive_restart
;
1130 struct tu_cs_entry state_ib
;
1135 struct tu_cs_entry state_ib
;
1140 struct tu_cs_entry state_ib
;
1145 uint32_t local_size
[3];
1150 tu6_emit_viewport(struct tu_cs
*cs
, const VkViewport
*viewport
);
1153 tu6_emit_scissor(struct tu_cs
*cs
, const VkRect2D
*scissor
);
1156 tu6_emit_sample_locations(struct tu_cs
*cs
, const VkSampleLocationsInfoEXT
*samp_loc
);
1159 tu6_emit_depth_bias(struct tu_cs
*cs
,
1160 float constant_factor
,
1162 float slope_factor
);
1164 void tu6_emit_msaa(struct tu_cs
*cs
, VkSampleCountFlagBits samples
);
1166 void tu6_emit_window_scissor(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
, uint32_t x2
, uint32_t y2
);
1168 void tu6_emit_window_offset(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
);
1171 tu6_emit_xs_config(struct tu_cs
*cs
,
1172 gl_shader_stage stage
,
1173 const struct ir3_shader_variant
*xs
,
1174 uint64_t binary_iova
);
1177 tu6_emit_vpc(struct tu_cs
*cs
,
1178 const struct ir3_shader_variant
*vs
,
1179 const struct ir3_shader_variant
*gs
,
1180 const struct ir3_shader_variant
*fs
,
1181 struct tu_streamout_state
*tf
);
1184 tu6_emit_fs_inputs(struct tu_cs
*cs
, const struct ir3_shader_variant
*fs
);
1186 struct tu_image_view
;
1189 tu_resolve_sysmem(struct tu_cmd_buffer
*cmd
,
1191 struct tu_image_view
*src
,
1192 struct tu_image_view
*dst
,
1194 const VkRect2D
*rect
);
1197 tu_clear_sysmem_attachment(struct tu_cmd_buffer
*cmd
,
1200 const VkRenderPassBeginInfo
*info
);
1203 tu_clear_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1206 const VkRenderPassBeginInfo
*info
);
1209 tu_load_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1214 /* expose this function to be able to emit load without checking LOAD_OP */
1216 tu_emit_load_gmem_attachment(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
, uint32_t a
);
1218 /* note: gmem store can also resolve */
1220 tu_store_gmem_attachment(struct tu_cmd_buffer
*cmd
,
1225 enum tu_supported_formats
{
1231 struct tu_native_format
1233 enum a6xx_format fmt
: 8;
1234 enum a3xx_color_swap swap
: 8;
1235 enum a6xx_tile_mode tile_mode
: 8;
1236 enum tu_supported_formats supported
: 8;
1239 struct tu_native_format
tu6_format_vtx(VkFormat format
);
1240 struct tu_native_format
tu6_format_color(VkFormat format
, enum a6xx_tile_mode tile_mode
);
1241 struct tu_native_format
tu6_format_texture(VkFormat format
, enum a6xx_tile_mode tile_mode
);
1243 static inline enum a6xx_format
1244 tu6_base_format(VkFormat format
)
1246 /* note: tu6_format_color doesn't care about tiling for .fmt field */
1247 return tu6_format_color(format
, TILE6_LINEAR
).fmt
;
1250 enum a6xx_depth_format
tu6_pipe2depth(VkFormat format
);
1255 /* The original VkFormat provided by the client. This may not match any
1256 * of the actual surface formats.
1259 VkImageAspectFlags aspects
;
1260 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1261 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1262 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
1264 uint32_t level_count
;
1265 uint32_t layer_count
;
1266 VkSampleCountFlagBits samples
;
1268 struct fdl_layout layout
;
1270 unsigned queue_family_mask
;
1274 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1275 VkDeviceMemory owned_memory
;
1277 /* Set when bound */
1279 VkDeviceSize bo_offset
;
1282 static inline uint32_t
1283 tu_get_layerCount(const struct tu_image
*image
,
1284 const VkImageSubresourceRange
*range
)
1286 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
1287 ? image
->layer_count
- range
->baseArrayLayer
1288 : range
->layerCount
;
1291 static inline uint32_t
1292 tu_get_levelCount(const struct tu_image
*image
,
1293 const VkImageSubresourceRange
*range
)
1295 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
1296 ? image
->level_count
- range
->baseMipLevel
1297 : range
->levelCount
;
1300 enum a3xx_msaa_samples
1301 tu_msaa_samples(uint32_t samples
);
1303 struct tu_image_view
1305 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
1309 uint32_t layer_size
;
1310 uint32_t ubwc_layer_size
;
1312 /* used to determine if fast gmem store path can be used */
1318 uint32_t descriptor
[A6XX_TEX_CONST_DWORDS
];
1320 /* Descriptor for use as a storage image as opposed to a sampled image.
1321 * This has a few differences for cube maps (e.g. type).
1323 uint32_t storage_descriptor
[A6XX_TEX_CONST_DWORDS
];
1325 /* pre-filled register values */
1327 uint32_t FLAG_BUFFER_PITCH
;
1329 uint32_t RB_MRT_BUF_INFO
;
1330 uint32_t SP_FS_MRT_REG
;
1332 uint32_t SP_PS_2D_SRC_INFO
;
1333 uint32_t SP_PS_2D_SRC_SIZE
;
1335 uint32_t RB_2D_DST_INFO
;
1337 uint32_t RB_BLIT_DST_INFO
;
1340 struct tu_sampler_ycbcr_conversion
{
1342 VkSamplerYcbcrModelConversion ycbcr_model
;
1343 VkSamplerYcbcrRange ycbcr_range
;
1344 VkComponentMapping components
;
1345 VkChromaLocation chroma_offsets
[2];
1346 VkFilter chroma_filter
;
1350 uint32_t descriptor
[A6XX_TEX_SAMP_DWORDS
];
1351 struct tu_sampler_ycbcr_conversion
*ycbcr_sampler
;
1355 tu_cs_image_ref(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
);
1358 tu_cs_image_ref_2d(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
, bool src
);
1361 tu_cs_image_flag_ref(struct tu_cs
*cs
, const struct tu_image_view
*iview
, uint32_t layer
);
1363 enum a6xx_tex_filter
1364 tu6_tex_filter(VkFilter filter
, unsigned aniso
);
1367 tu_image_create(VkDevice _device
,
1368 const VkImageCreateInfo
*pCreateInfo
,
1369 const VkAllocationCallbacks
*alloc
,
1372 const VkSubresourceLayout
*plane_layouts
);
1375 tu_image_from_gralloc(VkDevice device_h
,
1376 const VkImageCreateInfo
*base_info
,
1377 const VkNativeBufferANDROID
*gralloc_info
,
1378 const VkAllocationCallbacks
*alloc
,
1379 VkImage
*out_image_h
);
1382 tu_image_view_init(struct tu_image_view
*view
,
1383 const VkImageViewCreateInfo
*pCreateInfo
);
1385 struct tu_buffer_view
1387 uint32_t descriptor
[A6XX_TEX_CONST_DWORDS
];
1389 struct tu_buffer
*buffer
;
1392 tu_buffer_view_init(struct tu_buffer_view
*view
,
1393 struct tu_device
*device
,
1394 const VkBufferViewCreateInfo
*pCreateInfo
);
1396 struct tu_attachment_info
1398 struct tu_image_view
*attachment
;
1401 struct tu_framebuffer
1407 uint32_t attachment_count
;
1408 struct tu_attachment_info attachments
[0];
1411 struct tu_subpass_barrier
{
1412 VkPipelineStageFlags src_stage_mask
;
1413 VkAccessFlags src_access_mask
;
1414 VkAccessFlags dst_access_mask
;
1415 bool incoherent_ccu_color
, incoherent_ccu_depth
;
1418 struct tu_subpass_attachment
1420 uint32_t attachment
;
1421 VkImageLayout layout
;
1426 uint32_t input_count
;
1427 uint32_t color_count
;
1428 struct tu_subpass_attachment
*input_attachments
;
1429 struct tu_subpass_attachment
*color_attachments
;
1430 struct tu_subpass_attachment
*resolve_attachments
;
1431 struct tu_subpass_attachment depth_stencil_attachment
;
1433 VkSampleCountFlagBits samples
;
1434 bool has_external_src
, has_external_dst
;
1438 struct tu_subpass_barrier start_barrier
;
1441 struct tu_render_pass_attachment
1446 VkImageAspectFlags clear_mask
;
1449 VkImageLayout initial_layout
, final_layout
;
1450 int32_t gmem_offset
;
1453 struct tu_render_pass
1455 uint32_t attachment_count
;
1456 uint32_t subpass_count
;
1457 uint32_t gmem_pixels
;
1458 uint32_t tile_align_w
;
1459 struct tu_subpass_attachment
*subpass_attachments
;
1460 struct tu_render_pass_attachment
*attachments
;
1461 struct tu_subpass_barrier end_barrier
;
1462 struct tu_subpass subpasses
[0];
1465 struct tu_query_pool
1470 uint32_t pipeline_statistics
;
1477 uint32_t temp_syncobj
;
1481 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1482 VkPipelineBindPoint bind_point
,
1483 struct tu_descriptor_set
*set
,
1487 tu_update_descriptor_sets(struct tu_device
*device
,
1488 struct tu_cmd_buffer
*cmd_buffer
,
1489 VkDescriptorSet overrideSet
,
1490 uint32_t descriptorWriteCount
,
1491 const VkWriteDescriptorSet
*pDescriptorWrites
,
1492 uint32_t descriptorCopyCount
,
1493 const VkCopyDescriptorSet
*pDescriptorCopies
);
1496 tu_update_descriptor_set_with_template(
1497 struct tu_device
*device
,
1498 struct tu_cmd_buffer
*cmd_buffer
,
1499 struct tu_descriptor_set
*set
,
1500 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1504 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
);
1507 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
);
1510 tu_drm_get_gmem_base(const struct tu_physical_device
*dev
, uint64_t *base
);
1513 tu_drm_submitqueue_new(const struct tu_device
*dev
,
1515 uint32_t *queue_id
);
1518 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
);
1521 tu_gem_new(const struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1523 tu_gem_import_dmabuf(const struct tu_device
*dev
,
1527 tu_gem_export_dmabuf(const struct tu_device
*dev
, uint32_t gem_handle
);
1529 tu_gem_close(const struct tu_device
*dev
, uint32_t gem_handle
);
1531 tu_gem_info_offset(const struct tu_device
*dev
, uint32_t gem_handle
);
1533 tu_gem_info_iova(const struct tu_device
*dev
, uint32_t gem_handle
);
1535 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1537 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1539 return (struct __tu_type *) _handle; \
1542 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1544 return (__VkType) _obj; \
1547 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1549 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1551 return (struct __tu_type *) (uintptr_t) _handle; \
1554 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1556 return (__VkType)(uintptr_t) _obj; \
1559 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1560 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1562 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1563 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1564 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1565 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1566 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1568 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1569 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1570 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1571 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1572 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1573 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1574 VkDescriptorSetLayout
)
1575 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1576 VkDescriptorUpdateTemplate
)
1577 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1578 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1579 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1580 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1581 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1582 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1583 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1584 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1585 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1586 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1587 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1588 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1589 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler_ycbcr_conversion
, VkSamplerYcbcrConversion
)
1590 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1591 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1593 #endif /* TU_PRIVATE_H */