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.
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"
62 #include "tu_descriptor_set.h"
63 #include "tu_extensions.h"
65 /* Pre-declarations needed for WSI entrypoints */
68 typedef struct xcb_connection_t xcb_connection_t
;
69 typedef uint32_t xcb_visualid_t
;
70 typedef uint32_t xcb_window_t
;
72 #include <vulkan/vk_android_native_buffer.h>
73 #include <vulkan/vk_icd.h>
74 #include <vulkan/vulkan.h>
75 #include <vulkan/vulkan_intel.h>
77 #include "tu_entrypoints.h"
80 #define MAX_VERTEX_ATTRIBS 32
82 #define MAX_VSC_PIPES 32
83 #define MAX_VIEWPORTS 1
84 #define MAX_SCISSORS 16
85 #define MAX_DISCARD_RECTANGLES 4
86 #define MAX_PUSH_CONSTANTS_SIZE 128
87 #define MAX_PUSH_DESCRIPTORS 32
88 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
89 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
90 #define MAX_DYNAMIC_BUFFERS \
91 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
92 #define MAX_SAMPLES_LOG2 4
93 #define NUM_META_FS_KEYS 13
94 #define TU_MAX_DRM_DEVICES 8
97 #define NUM_DEPTH_CLEAR_PIPELINES 3
100 * This is the point we switch from using CP to compute shader
101 * for certain buffer operations.
103 #define TU_BUFFER_OPS_CS_THRESHOLD 4096
105 #define A6XX_TEX_CONST_DWORDS 16
106 #define A6XX_TEX_SAMP_DWORDS 4
111 TU_MEM_HEAP_VRAM_CPU_ACCESS
,
119 TU_MEM_TYPE_GTT_WRITE_COMBINE
,
120 TU_MEM_TYPE_VRAM_CPU_ACCESS
,
121 TU_MEM_TYPE_GTT_CACHED
,
125 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
127 static inline uint32_t
128 align_u32(uint32_t v
, uint32_t a
)
130 assert(a
!= 0 && a
== (a
& -a
));
131 return (v
+ a
- 1) & ~(a
- 1);
134 static inline uint32_t
135 align_u32_npot(uint32_t v
, uint32_t a
)
137 return (v
+ a
- 1) / a
* a
;
140 static inline uint64_t
141 align_u64(uint64_t v
, uint64_t a
)
143 assert(a
!= 0 && a
== (a
& -a
));
144 return (v
+ a
- 1) & ~(a
- 1);
147 static inline int32_t
148 align_i32(int32_t v
, int32_t a
)
150 assert(a
!= 0 && a
== (a
& -a
));
151 return (v
+ a
- 1) & ~(a
- 1);
154 /** Alignment must be a power of 2. */
156 tu_is_aligned(uintmax_t n
, uintmax_t a
)
158 assert(a
== (a
& -a
));
159 return (n
& (a
- 1)) == 0;
162 static inline uint32_t
163 round_up_u32(uint32_t v
, uint32_t a
)
165 return (v
+ a
- 1) / a
;
168 static inline uint64_t
169 round_up_u64(uint64_t v
, uint64_t a
)
171 return (v
+ a
- 1) / a
;
174 static inline uint32_t
175 tu_minify(uint32_t n
, uint32_t levels
)
177 if (unlikely(n
== 0))
180 return MAX2(n
>> levels
, 1);
183 tu_clamp_f(float f
, float min
, float max
)
196 tu_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
198 if (*inout_mask
& clear_mask
) {
199 *inout_mask
&= ~clear_mask
;
206 #define for_each_bit(b, dword) \
207 for (uint32_t __dword = (dword); \
208 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
210 #define typed_memcpy(dest, src, count) \
212 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
213 memcpy((dest), (src), (count) * sizeof(*(src))); \
216 #define COND(bool, val) ((bool) ? (val) : 0)
218 /* Whenever we generate an error, pass it through this function. Useful for
219 * debugging, where we can break on it. Only call at error site, not when
220 * propagating errors. Might be useful to plug in a stack trace here.
226 __vk_errorf(struct tu_instance
*instance
,
233 #define vk_error(instance, error) \
234 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
235 #define vk_errorf(instance, error, format, ...) \
236 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
239 __tu_finishme(const char *file
, int line
, const char *format
, ...)
242 tu_loge(const char *format
, ...) tu_printflike(1, 2);
244 tu_loge_v(const char *format
, va_list va
);
246 tu_logi(const char *format
, ...) tu_printflike(1, 2);
248 tu_logi_v(const char *format
, va_list va
);
251 * Print a FINISHME message, including its source location.
253 #define tu_finishme(format, ...) \
255 static bool reported = false; \
257 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
262 /* A non-fatal assert. Useful for debugging. */
264 #define tu_assert(x) \
266 if (unlikely(!(x))) \
267 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
273 /* Suppress -Wunused in stub functions */
274 #define tu_use_args(...) __tu_use_args(0, ##__VA_ARGS__)
276 __tu_use_args(int ignore
, ...)
282 tu_finishme("stub %s", __func__); \
286 tu_lookup_entrypoint_unchecked(const char *name
);
288 tu_lookup_entrypoint_checked(
290 uint32_t core_version
,
291 const struct tu_instance_extension_table
*instance
,
292 const struct tu_device_extension_table
*device
);
294 struct tu_physical_device
296 VK_LOADER_DATA _loader_data
;
298 struct tu_instance
*instance
;
301 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
302 uint8_t driver_uuid
[VK_UUID_SIZE
];
303 uint8_t device_uuid
[VK_UUID_SIZE
];
304 uint8_t cache_uuid
[VK_UUID_SIZE
];
306 struct wsi_device wsi_device
;
313 uint32_t tile_align_w
;
314 uint32_t tile_align_h
;
316 /* This is the drivers on-disk cache used as a fallback as opposed to
317 * the pipeline cache defined by apps.
319 struct disk_cache
*disk_cache
;
321 struct tu_device_extension_table supported_extensions
;
326 TU_DEBUG_STARTUP
= 1 << 0,
327 TU_DEBUG_NIR
= 1 << 1,
328 TU_DEBUG_IR3
= 1 << 2,
333 VK_LOADER_DATA _loader_data
;
335 VkAllocationCallbacks alloc
;
337 uint32_t api_version
;
338 int physical_device_count
;
339 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
341 enum tu_debug_flags debug_flags
;
343 struct vk_debug_report_instance debug_report_callbacks
;
345 struct tu_instance_extension_table enabled_extensions
;
349 tu_wsi_init(struct tu_physical_device
*physical_device
);
351 tu_wsi_finish(struct tu_physical_device
*physical_device
);
354 tu_instance_extension_supported(const char *name
);
356 tu_physical_device_api_version(struct tu_physical_device
*dev
);
358 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
363 struct tu_pipeline_cache
365 struct tu_device
*device
;
366 pthread_mutex_t mutex
;
370 uint32_t kernel_count
;
371 struct cache_entry
**hash_table
;
374 VkAllocationCallbacks alloc
;
377 struct tu_pipeline_key
382 tu_pipeline_cache_init(struct tu_pipeline_cache
*cache
,
383 struct tu_device
*device
);
385 tu_pipeline_cache_finish(struct tu_pipeline_cache
*cache
);
387 tu_pipeline_cache_load(struct tu_pipeline_cache
*cache
,
391 struct tu_shader_variant
;
394 tu_create_shader_variants_from_pipeline_cache(
395 struct tu_device
*device
,
396 struct tu_pipeline_cache
*cache
,
397 const unsigned char *sha1
,
398 struct tu_shader_variant
**variants
);
401 tu_pipeline_cache_insert_shaders(struct tu_device
*device
,
402 struct tu_pipeline_cache
*cache
,
403 const unsigned char *sha1
,
404 struct tu_shader_variant
**variants
,
405 const void *const *codes
,
406 const unsigned *code_sizes
);
410 VkAllocationCallbacks alloc
;
412 struct tu_pipeline_cache cache
;
416 #define TU_QUEUE_GENERAL 0
418 #define TU_MAX_QUEUE_FAMILIES 1
427 tu_fence_init(struct tu_fence
*fence
, bool signaled
);
429 tu_fence_finish(struct tu_fence
*fence
);
431 tu_fence_update_fd(struct tu_fence
*fence
, int fd
);
433 tu_fence_copy(struct tu_fence
*fence
, const struct tu_fence
*src
);
435 tu_fence_signal(struct tu_fence
*fence
);
437 tu_fence_wait_idle(struct tu_fence
*fence
);
441 VK_LOADER_DATA _loader_data
;
442 struct tu_device
*device
;
443 uint32_t queue_family_index
;
445 VkDeviceQueueCreateFlags flags
;
447 uint32_t msm_queue_id
;
448 struct tu_fence submit_fence
;
453 VK_LOADER_DATA _loader_data
;
455 VkAllocationCallbacks alloc
;
457 struct tu_instance
*instance
;
459 struct tu_meta_state meta_state
;
461 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
462 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
464 struct tu_physical_device
*physical_device
;
466 struct ir3_compiler
*compiler
;
468 /* Backup in-memory cache to be used if the app doesn't provide one */
469 struct tu_pipeline_cache
*mem_cache
;
471 struct list_head shader_slabs
;
472 mtx_t shader_slab_mutex
;
474 struct tu_device_extension_table enabled_extensions
;
486 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
488 tu_bo_init_dmabuf(struct tu_device
*dev
,
493 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
);
495 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
497 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
502 const struct tu_bo
*bo
;
512 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
513 * is full. tu_cs_begin must be called before command packet emission and
514 * tu_cs_end must be called after.
516 * This mode may create multiple entries internally. The entries must be
517 * submitted together.
522 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
523 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
526 * This mode does not create any entry or any BO.
531 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
532 * command packet emission. tu_cs_begin_sub_stream must be called to get a
533 * sub-stream to emit comamnd packets to. When done with the sub-stream,
534 * tu_cs_end_sub_stream must be called.
536 * This mode does not create any entry internally.
538 TU_CS_MODE_SUB_STREAM
,
545 uint32_t *reserved_end
;
548 enum tu_cs_mode mode
;
549 uint32_t next_bo_size
;
551 struct tu_cs_entry
*entries
;
552 uint32_t entry_count
;
553 uint32_t entry_capacity
;
557 uint32_t bo_capacity
;
560 struct tu_device_memory
565 /* for dedicated allocations */
566 struct tu_image
*image
;
567 struct tu_buffer
*buffer
;
574 struct tu_descriptor_range
580 struct tu_descriptor_set
582 const struct tu_descriptor_set_layout
*layout
;
586 uint32_t *mapped_ptr
;
587 struct tu_descriptor_range
*dynamic_descriptors
;
589 struct tu_bo
*descriptors
[0];
592 struct tu_push_descriptor_set
594 struct tu_descriptor_set set
;
598 struct tu_descriptor_pool_entry
602 struct tu_descriptor_set
*set
;
605 struct tu_descriptor_pool
608 uint64_t current_offset
;
611 uint8_t *host_memory_base
;
612 uint8_t *host_memory_ptr
;
613 uint8_t *host_memory_end
;
615 uint32_t entry_count
;
616 uint32_t max_entry_count
;
617 struct tu_descriptor_pool_entry entries
[0];
620 struct tu_descriptor_update_template_entry
622 VkDescriptorType descriptor_type
;
624 /* The number of descriptors to update */
625 uint32_t descriptor_count
;
627 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
631 /* In dwords. Not valid/used for dynamic descriptors */
634 uint32_t buffer_offset
;
636 /* Only valid for combined image samplers and samplers */
637 uint16_t has_sampler
;
643 /* For push descriptors */
644 const uint32_t *immutable_samplers
;
647 struct tu_descriptor_update_template
649 uint32_t entry_count
;
650 VkPipelineBindPoint bind_point
;
651 struct tu_descriptor_update_template_entry entry
[0];
658 VkBufferUsageFlags usage
;
659 VkBufferCreateFlags flags
;
662 VkDeviceSize bo_offset
;
665 enum tu_dynamic_state_bits
667 TU_DYNAMIC_VIEWPORT
= 1 << 0,
668 TU_DYNAMIC_SCISSOR
= 1 << 1,
669 TU_DYNAMIC_LINE_WIDTH
= 1 << 2,
670 TU_DYNAMIC_DEPTH_BIAS
= 1 << 3,
671 TU_DYNAMIC_BLEND_CONSTANTS
= 1 << 4,
672 TU_DYNAMIC_DEPTH_BOUNDS
= 1 << 5,
673 TU_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6,
674 TU_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7,
675 TU_DYNAMIC_STENCIL_REFERENCE
= 1 << 8,
676 TU_DYNAMIC_DISCARD_RECTANGLE
= 1 << 9,
677 TU_DYNAMIC_ALL
= (1 << 10) - 1,
680 struct tu_vertex_binding
682 struct tu_buffer
*buffer
;
686 struct tu_viewport_state
689 VkViewport viewports
[MAX_VIEWPORTS
];
692 struct tu_scissor_state
695 VkRect2D scissors
[MAX_SCISSORS
];
698 struct tu_discard_rectangle_state
701 VkRect2D rectangles
[MAX_DISCARD_RECTANGLES
];
704 struct tu_dynamic_state
707 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
708 * Defines the set of saved dynamic state.
712 struct tu_viewport_state viewport
;
714 struct tu_scissor_state scissor
;
725 float blend_constants
[4];
737 } stencil_compare_mask
;
743 } stencil_write_mask
;
751 struct tu_discard_rectangle_state discard_rectangle
;
754 extern const struct tu_dynamic_state default_dynamic_state
;
757 tu_get_debug_option_name(int id
);
760 tu_get_perftest_option_name(int id
);
763 * Attachment state when recording a renderpass instance.
765 * The clear value is valid only if there exists a pending clear.
767 struct tu_attachment_state
769 VkImageAspectFlags pending_clear_aspects
;
770 uint32_t cleared_views
;
771 VkClearValue clear_value
;
772 VkImageLayout current_layout
;
775 struct tu_descriptor_state
777 struct tu_descriptor_set
*sets
[MAX_SETS
];
780 struct tu_push_descriptor_set push_set
;
782 uint64_t dynamic_buffers
[MAX_DYNAMIC_BUFFERS
];
793 struct tu_tiling_config
795 VkRect2D render_area
;
796 uint32_t buffer_cpp
[MAX_RTS
+ 2];
797 uint32_t buffer_count
;
799 /* position and size of the first tile */
801 /* number of tiles */
802 VkExtent2D tile_count
;
804 uint32_t gmem_offsets
[MAX_RTS
+ 2];
806 /* size of the first VSC pipe */
808 /* number of VSC pipes */
809 VkExtent2D pipe_count
;
811 /* pipe register values */
812 uint32_t pipe_config
[MAX_VSC_PIPES
];
813 uint32_t pipe_sizes
[MAX_VSC_PIPES
];
816 enum tu_cmd_dirty_bits
818 TU_CMD_DIRTY_PIPELINE
= 1 << 0,
819 TU_CMD_DIRTY_VERTEX_BUFFERS
= 1 << 1,
820 TU_CMD_DIRTY_DESCRIPTOR_SETS
= 1 << 2,
822 TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 16,
823 TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 17,
824 TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 18,
825 TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 19,
832 struct tu_pipeline
*pipeline
;
837 struct tu_buffer
*buffers
[MAX_VBS
];
838 VkDeviceSize offsets
[MAX_VBS
];
841 struct tu_dynamic_state dynamic
;
844 struct tu_buffer
*index_buffer
;
845 uint64_t index_offset
;
847 uint32_t max_index_count
;
850 const struct tu_render_pass
*pass
;
851 const struct tu_subpass
*subpass
;
852 const struct tu_framebuffer
*framebuffer
;
853 struct tu_attachment_state
*attachments
;
855 struct tu_tiling_config tiling_config
;
857 struct tu_cs_entry tile_load_ib
;
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
);
910 VK_LOADER_DATA _loader_data
;
912 struct tu_device
*device
;
914 struct tu_cmd_pool
*pool
;
915 struct list_head pool_link
;
917 VkCommandBufferUsageFlags usage_flags
;
918 VkCommandBufferLevel level
;
919 enum tu_cmd_buffer_status status
;
921 struct tu_cmd_state state
;
922 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
923 uint32_t queue_family_index
;
925 uint32_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
/ 4];
926 VkShaderStageFlags push_constant_stages
;
927 struct tu_descriptor_set meta_push_descriptors
;
929 struct tu_descriptor_state descriptors
[VK_PIPELINE_BIND_POINT_RANGE_SIZE
];
931 struct tu_cmd_buffer_upload upload
;
933 VkResult record_result
;
935 struct tu_bo_list bo_list
;
937 struct tu_cs draw_cs
;
938 struct tu_cs draw_state
;
939 struct tu_cs tile_cs
;
942 uint32_t marker_seqno
;
944 struct tu_bo scratch_bo
;
945 uint32_t scratch_seqno
;
951 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
953 enum vgt_event_type event
,
957 tu_get_memory_fd(struct tu_device
*device
,
958 struct tu_device_memory
*memory
,
961 static inline struct tu_descriptor_state
*
962 tu_get_descriptors_state(struct tu_cmd_buffer
*cmd_buffer
,
963 VkPipelineBindPoint bind_point
)
965 return &cmd_buffer
->descriptors
[bind_point
];
969 * Takes x,y,z as exact numbers of invocations, instead of blocks.
971 * Limitations: Can't call normal dispatch functions without binding or
973 * the compute pipeline.
976 tu_unaligned_dispatch(struct tu_cmd_buffer
*cmd_buffer
,
986 struct tu_shader_module
;
988 #define TU_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
989 #define TU_HASH_SHADER_SISCHED (1 << 1)
990 #define TU_HASH_SHADER_UNSAFE_MATH (1 << 2)
992 tu_hash_shaders(unsigned char *hash
,
993 const VkPipelineShaderStageCreateInfo
**stages
,
994 const struct tu_pipeline_layout
*layout
,
995 const struct tu_pipeline_key
*key
,
998 static inline gl_shader_stage
999 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1001 assert(__builtin_popcount(vk_stage
) == 1);
1002 return ffs(vk_stage
) - 1;
1005 static inline VkShaderStageFlagBits
1006 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1008 return (1 << mesa_stage
);
1011 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1013 #define tu_foreach_stage(stage, stage_bits) \
1014 for (gl_shader_stage stage, \
1015 __tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
1016 stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
1018 struct tu_shader_module
1020 unsigned char sha1
[20];
1023 const uint32_t *code
[0];
1026 struct tu_shader_compile_options
1028 struct ir3_shader_key key
;
1031 bool include_binning_pass
;
1034 struct tu_descriptor_map
1036 /* TODO: avoid fixed size array/justify the size */
1044 struct ir3_shader ir3_shader
;
1046 struct tu_descriptor_map texture_map
;
1047 struct tu_descriptor_map sampler_map
;
1048 struct tu_descriptor_map ubo_map
;
1049 struct tu_descriptor_map ssbo_map
;
1051 /* This may be true for vertex shaders. When true, variants[1] is the
1052 * binning variant and binning_binary is non-NULL.
1054 bool has_binning_pass
;
1057 void *binning_binary
;
1059 struct ir3_shader_variant variants
[0];
1063 tu_shader_create(struct tu_device
*dev
,
1064 gl_shader_stage stage
,
1065 const VkPipelineShaderStageCreateInfo
*stage_info
,
1066 const VkAllocationCallbacks
*alloc
);
1069 tu_shader_destroy(struct tu_device
*dev
,
1070 struct tu_shader
*shader
,
1071 const VkAllocationCallbacks
*alloc
);
1074 tu_shader_compile_options_init(
1075 struct tu_shader_compile_options
*options
,
1076 const VkGraphicsPipelineCreateInfo
*pipeline_info
);
1079 tu_shader_compile(struct tu_device
*dev
,
1080 struct tu_shader
*shader
,
1081 const struct tu_shader
*next_stage
,
1082 const struct tu_shader_compile_options
*options
,
1083 const VkAllocationCallbacks
*alloc
);
1085 struct tu_program_descriptor_linkage
1087 struct ir3_ubo_analysis_state ubo_state
;
1088 struct ir3_const_state const_state
;
1092 struct tu_descriptor_map texture_map
;
1093 struct tu_descriptor_map sampler_map
;
1094 struct tu_descriptor_map ubo_map
;
1095 struct tu_descriptor_map ssbo_map
;
1096 struct ir3_ibo_mapping image_mapping
;
1103 struct tu_dynamic_state dynamic_state
;
1105 struct tu_pipeline_layout
*layout
;
1107 bool need_indirect_descriptor_sets
;
1108 VkShaderStageFlags active_stages
;
1112 struct tu_bo binary_bo
;
1113 struct tu_cs_entry state_ib
;
1114 struct tu_cs_entry binning_state_ib
;
1116 struct tu_program_descriptor_linkage link
[MESA_SHADER_STAGES
];
1121 uint8_t bindings
[MAX_VERTEX_ATTRIBS
];
1122 uint16_t strides
[MAX_VERTEX_ATTRIBS
];
1123 uint16_t offsets
[MAX_VERTEX_ATTRIBS
];
1126 uint8_t binning_bindings
[MAX_VERTEX_ATTRIBS
];
1127 uint16_t binning_strides
[MAX_VERTEX_ATTRIBS
];
1128 uint16_t binning_offsets
[MAX_VERTEX_ATTRIBS
];
1129 uint32_t binning_count
;
1131 struct tu_cs_entry state_ib
;
1132 struct tu_cs_entry binning_state_ib
;
1137 enum pc_di_primtype primtype
;
1138 bool primitive_restart
;
1143 struct tu_cs_entry state_ib
;
1148 uint32_t gras_su_cntl
;
1149 struct tu_cs_entry state_ib
;
1154 struct tu_cs_entry state_ib
;
1159 struct tu_cs_entry state_ib
;
1164 tu6_emit_viewport(struct tu_cs
*cs
, const VkViewport
*viewport
);
1167 tu6_emit_scissor(struct tu_cs
*cs
, const VkRect2D
*scissor
);
1170 tu6_emit_gras_su_cntl(struct tu_cs
*cs
,
1171 uint32_t gras_su_cntl
,
1175 tu6_emit_depth_bias(struct tu_cs
*cs
,
1176 float constant_factor
,
1178 float slope_factor
);
1181 tu6_emit_stencil_compare_mask(struct tu_cs
*cs
,
1186 tu6_emit_stencil_write_mask(struct tu_cs
*cs
, uint32_t front
, uint32_t back
);
1189 tu6_emit_stencil_reference(struct tu_cs
*cs
, uint32_t front
, uint32_t back
);
1192 tu6_emit_blend_constants(struct tu_cs
*cs
, const float constants
[4]);
1194 struct tu_userdata_info
*
1195 tu_lookup_user_sgpr(struct tu_pipeline
*pipeline
,
1196 gl_shader_stage stage
,
1199 struct tu_shader_variant
*
1200 tu_get_shader(struct tu_pipeline
*pipeline
, gl_shader_stage stage
);
1202 struct tu_graphics_pipeline_create_info
1205 bool db_depth_clear
;
1206 bool db_stencil_clear
;
1207 bool db_depth_disable_expclear
;
1208 bool db_stencil_disable_expclear
;
1209 bool db_flush_depth_inplace
;
1210 bool db_flush_stencil_inplace
;
1211 bool db_resummarize
;
1212 uint32_t custom_blend_mode
;
1215 struct tu_native_format
1217 int vtx
; /* VFMTn_xxx or -1 */
1218 int tex
; /* TFMTn_xxx or -1 */
1219 int rb
; /* RBn_xxx or -1 */
1220 int swap
; /* enum a3xx_color_swap */
1221 bool present
; /* internal only; always true to external users */
1224 const struct tu_native_format
*
1225 tu6_get_native_format(VkFormat format
);
1228 tu_pack_clear_value(const VkClearValue
*val
,
1231 enum a6xx_2d_ifmt
tu6_rb_fmt_to_ifmt(enum a6xx_color_fmt fmt
);
1232 enum a6xx_depth_format
tu6_pipe2depth(VkFormat format
);
1234 struct tu_image_level
1236 VkDeviceSize offset
;
1244 /* The original VkFormat provided by the client. This may not match any
1245 * of the actual surface formats.
1248 VkImageAspectFlags aspects
;
1249 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1250 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1251 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
1253 uint32_t level_count
;
1254 uint32_t layer_count
;
1255 VkSampleCountFlagBits samples
;
1262 VkDeviceSize layer_size
;
1263 struct tu_image_level levels
[15];
1267 unsigned queue_family_mask
;
1271 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1272 VkDeviceMemory owned_memory
;
1274 /* Set when bound */
1276 VkDeviceSize bo_offset
;
1280 tu_image_queue_family_mask(const struct tu_image
*image
,
1282 uint32_t queue_family
);
1284 static inline uint32_t
1285 tu_get_layerCount(const struct tu_image
*image
,
1286 const VkImageSubresourceRange
*range
)
1288 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
1289 ? image
->layer_count
- range
->baseArrayLayer
1290 : range
->layerCount
;
1293 static inline uint32_t
1294 tu_get_levelCount(const struct tu_image
*image
,
1295 const VkImageSubresourceRange
*range
)
1297 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
1298 ? image
->level_count
- range
->baseMipLevel
1299 : range
->levelCount
;
1303 tu6_get_image_tile_mode(struct tu_image
*image
, int level
);
1304 enum a3xx_msaa_samples
1305 tu_msaa_samples(uint32_t samples
);
1307 struct tu_image_view
1309 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
1311 VkImageViewType type
;
1312 VkImageAspectFlags aspect_mask
;
1314 uint32_t base_layer
;
1315 uint32_t layer_count
;
1317 uint32_t level_count
;
1318 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1320 uint32_t descriptor
[A6XX_TEX_CONST_DWORDS
];
1322 /* Descriptor for use as a storage image as opposed to a sampled image.
1323 * This has a few differences for cube maps (e.g. type).
1325 uint32_t storage_descriptor
[A6XX_TEX_CONST_DWORDS
];
1330 uint32_t state
[A6XX_TEX_SAMP_DWORDS
];
1335 struct tu_image_create_info
1337 const VkImageCreateInfo
*vk_info
;
1339 bool no_metadata_planes
;
1343 tu_image_create(VkDevice _device
,
1344 const struct tu_image_create_info
*info
,
1345 const VkAllocationCallbacks
*alloc
,
1349 tu_image_from_gralloc(VkDevice device_h
,
1350 const VkImageCreateInfo
*base_info
,
1351 const VkNativeBufferANDROID
*gralloc_info
,
1352 const VkAllocationCallbacks
*alloc
,
1353 VkImage
*out_image_h
);
1356 tu_image_view_init(struct tu_image_view
*view
,
1357 struct tu_device
*device
,
1358 const VkImageViewCreateInfo
*pCreateInfo
);
1360 struct tu_buffer_view
1363 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1367 tu_buffer_view_init(struct tu_buffer_view
*view
,
1368 struct tu_device
*device
,
1369 const VkBufferViewCreateInfo
*pCreateInfo
);
1371 static inline struct VkExtent3D
1372 tu_sanitize_image_extent(const VkImageType imageType
,
1373 const struct VkExtent3D imageExtent
)
1375 switch (imageType
) {
1376 case VK_IMAGE_TYPE_1D
:
1377 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1378 case VK_IMAGE_TYPE_2D
:
1379 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1380 case VK_IMAGE_TYPE_3D
:
1383 unreachable("invalid image type");
1387 static inline struct VkOffset3D
1388 tu_sanitize_image_offset(const VkImageType imageType
,
1389 const struct VkOffset3D imageOffset
)
1391 switch (imageType
) {
1392 case VK_IMAGE_TYPE_1D
:
1393 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1394 case VK_IMAGE_TYPE_2D
:
1395 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1396 case VK_IMAGE_TYPE_3D
:
1399 unreachable("invalid image type");
1403 struct tu_attachment_info
1405 struct tu_image_view
*attachment
;
1408 struct tu_framebuffer
1414 uint32_t attachment_count
;
1415 struct tu_attachment_info attachments
[0];
1418 struct tu_subpass_barrier
1420 VkPipelineStageFlags src_stage_mask
;
1421 VkAccessFlags src_access_mask
;
1422 VkAccessFlags dst_access_mask
;
1426 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
1427 const struct tu_subpass_barrier
*barrier
);
1429 struct tu_subpass_attachment
1431 uint32_t attachment
;
1432 VkImageLayout layout
;
1437 uint32_t input_count
;
1438 uint32_t color_count
;
1439 struct tu_subpass_attachment
*input_attachments
;
1440 struct tu_subpass_attachment
*color_attachments
;
1441 struct tu_subpass_attachment
*resolve_attachments
;
1442 struct tu_subpass_attachment depth_stencil_attachment
;
1444 /** Subpass has at least one resolve attachment */
1447 struct tu_subpass_barrier start_barrier
;
1450 VkSampleCountFlagBits max_sample_count
;
1453 struct tu_render_pass_attachment
1457 VkAttachmentLoadOp load_op
;
1458 VkAttachmentLoadOp stencil_load_op
;
1459 VkImageLayout initial_layout
;
1460 VkImageLayout final_layout
;
1464 struct tu_render_pass
1466 uint32_t attachment_count
;
1467 uint32_t subpass_count
;
1468 struct tu_subpass_attachment
*subpass_attachments
;
1469 struct tu_render_pass_attachment
*attachments
;
1470 struct tu_subpass_barrier end_barrier
;
1471 struct tu_subpass subpasses
[0];
1475 tu_device_init_meta(struct tu_device
*device
);
1477 tu_device_finish_meta(struct tu_device
*device
);
1479 struct tu_query_pool
1482 uint32_t availability_offset
;
1486 uint32_t pipeline_stats_mask
;
1492 uint32_t temp_syncobj
;
1496 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1497 VkPipelineBindPoint bind_point
,
1498 struct tu_descriptor_set
*set
,
1502 tu_update_descriptor_sets(struct tu_device
*device
,
1503 struct tu_cmd_buffer
*cmd_buffer
,
1504 VkDescriptorSet overrideSet
,
1505 uint32_t descriptorWriteCount
,
1506 const VkWriteDescriptorSet
*pDescriptorWrites
,
1507 uint32_t descriptorCopyCount
,
1508 const VkCopyDescriptorSet
*pDescriptorCopies
);
1511 tu_update_descriptor_set_with_template(
1512 struct tu_device
*device
,
1513 struct tu_cmd_buffer
*cmd_buffer
,
1514 struct tu_descriptor_set
*set
,
1515 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1519 tu_meta_push_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1520 VkPipelineBindPoint pipelineBindPoint
,
1521 VkPipelineLayout _layout
,
1523 uint32_t descriptorWriteCount
,
1524 const VkWriteDescriptorSet
*pDescriptorWrites
);
1527 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
);
1530 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
);
1533 tu_drm_submitqueue_new(const struct tu_device
*dev
,
1535 uint32_t *queue_id
);
1538 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
);
1541 tu_gem_new(const struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1543 tu_gem_import_dmabuf(const struct tu_device
*dev
,
1547 tu_gem_export_dmabuf(const struct tu_device
*dev
, uint32_t gem_handle
);
1549 tu_gem_close(const struct tu_device
*dev
, uint32_t gem_handle
);
1551 tu_gem_info_offset(const struct tu_device
*dev
, uint32_t gem_handle
);
1553 tu_gem_info_iova(const struct tu_device
*dev
, uint32_t gem_handle
);
1555 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1557 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1559 return (struct __tu_type *) _handle; \
1562 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1564 return (__VkType) _obj; \
1567 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1569 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1571 return (struct __tu_type *) (uintptr_t) _handle; \
1574 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1576 return (__VkType)(uintptr_t) _obj; \
1579 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1580 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1582 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1583 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1584 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1585 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1586 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1588 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1589 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1590 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1591 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1592 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1593 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1594 VkDescriptorSetLayout
)
1595 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1596 VkDescriptorUpdateTemplate
)
1597 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1598 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1599 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1600 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1601 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1602 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1603 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1604 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1605 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1606 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1607 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1608 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1609 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1610 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1612 #endif /* TU_PRIVATE_H */