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 "compiler/shader_enums.h"
48 #include "main/macros.h"
49 #include "util/list.h"
50 #include "util/macros.h"
52 #include "vk_debug_report.h"
54 #include "drm/msm_drm.h"
55 #include "tu_descriptor_set.h"
56 #include "tu_extensions.h"
58 /* Pre-declarations needed for WSI entrypoints */
61 typedef struct xcb_connection_t xcb_connection_t
;
62 typedef uint32_t xcb_visualid_t
;
63 typedef uint32_t xcb_window_t
;
65 #include <vulkan/vk_android_native_buffer.h>
66 #include <vulkan/vk_icd.h>
67 #include <vulkan/vulkan.h>
68 #include <vulkan/vulkan_intel.h>
70 #include "tu_entrypoints.h"
73 #define MAX_VERTEX_ATTRIBS 32
75 #define MAX_VSC_PIPES 32
76 #define MAX_VIEWPORTS 16
77 #define MAX_SCISSORS 16
78 #define MAX_DISCARD_RECTANGLES 4
79 #define MAX_PUSH_CONSTANTS_SIZE 128
80 #define MAX_PUSH_DESCRIPTORS 32
81 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
82 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
83 #define MAX_DYNAMIC_BUFFERS \
84 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
85 #define MAX_SAMPLES_LOG2 4
86 #define NUM_META_FS_KEYS 13
87 #define TU_MAX_DRM_DEVICES 8
90 #define NUM_DEPTH_CLEAR_PIPELINES 3
93 * This is the point we switch from using CP to compute shader
94 * for certain buffer operations.
96 #define TU_BUFFER_OPS_CS_THRESHOLD 4096
101 TU_MEM_HEAP_VRAM_CPU_ACCESS
,
109 TU_MEM_TYPE_GTT_WRITE_COMBINE
,
110 TU_MEM_TYPE_VRAM_CPU_ACCESS
,
111 TU_MEM_TYPE_GTT_CACHED
,
115 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
117 static inline uint32_t
118 align_u32(uint32_t v
, uint32_t a
)
120 assert(a
!= 0 && a
== (a
& -a
));
121 return (v
+ a
- 1) & ~(a
- 1);
124 static inline uint32_t
125 align_u32_npot(uint32_t v
, uint32_t a
)
127 return (v
+ a
- 1) / a
* a
;
130 static inline uint64_t
131 align_u64(uint64_t v
, uint64_t a
)
133 assert(a
!= 0 && a
== (a
& -a
));
134 return (v
+ a
- 1) & ~(a
- 1);
137 static inline int32_t
138 align_i32(int32_t v
, int32_t a
)
140 assert(a
!= 0 && a
== (a
& -a
));
141 return (v
+ a
- 1) & ~(a
- 1);
144 /** Alignment must be a power of 2. */
146 tu_is_aligned(uintmax_t n
, uintmax_t a
)
148 assert(a
== (a
& -a
));
149 return (n
& (a
- 1)) == 0;
152 static inline uint32_t
153 round_up_u32(uint32_t v
, uint32_t a
)
155 return (v
+ a
- 1) / a
;
158 static inline uint64_t
159 round_up_u64(uint64_t v
, uint64_t a
)
161 return (v
+ a
- 1) / a
;
164 static inline uint32_t
165 tu_minify(uint32_t n
, uint32_t levels
)
167 if (unlikely(n
== 0))
170 return MAX2(n
>> levels
, 1);
173 tu_clamp_f(float f
, float min
, float max
)
186 tu_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
188 if (*inout_mask
& clear_mask
) {
189 *inout_mask
&= ~clear_mask
;
196 #define for_each_bit(b, dword) \
197 for (uint32_t __dword = (dword); \
198 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
200 #define typed_memcpy(dest, src, count) \
202 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
203 memcpy((dest), (src), (count) * sizeof(*(src))); \
206 /* Whenever we generate an error, pass it through this function. Useful for
207 * debugging, where we can break on it. Only call at error site, not when
208 * propagating errors. Might be useful to plug in a stack trace here.
214 __vk_errorf(struct tu_instance
*instance
,
221 #define vk_error(instance, error) \
222 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
223 #define vk_errorf(instance, error, format, ...) \
224 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
227 __tu_finishme(const char *file
, int line
, const char *format
, ...)
230 tu_loge(const char *format
, ...) tu_printflike(1, 2);
232 tu_loge_v(const char *format
, va_list va
);
234 tu_logi(const char *format
, ...) tu_printflike(1, 2);
236 tu_logi_v(const char *format
, va_list va
);
239 * Print a FINISHME message, including its source location.
241 #define tu_finishme(format, ...) \
243 static bool reported = false; \
245 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
250 /* A non-fatal assert. Useful for debugging. */
252 #define tu_assert(x) \
254 if (unlikely(!(x))) \
255 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
261 /* Suppress -Wunused in stub functions */
262 #define tu_use_args(...) __tu_use_args(0, ##__VA_ARGS__)
264 __tu_use_args(int ignore
, ...)
270 tu_finishme("stub %s", __func__); \
274 tu_lookup_entrypoint_unchecked(const char *name
);
276 tu_lookup_entrypoint_checked(
278 uint32_t core_version
,
279 const struct tu_instance_extension_table
*instance
,
280 const struct tu_device_extension_table
*device
);
282 struct tu_physical_device
284 VK_LOADER_DATA _loader_data
;
286 struct tu_instance
*instance
;
289 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
290 uint8_t driver_uuid
[VK_UUID_SIZE
];
291 uint8_t device_uuid
[VK_UUID_SIZE
];
292 uint8_t cache_uuid
[VK_UUID_SIZE
];
299 uint32_t tile_align_w
;
300 uint32_t tile_align_h
;
302 /* This is the drivers on-disk cache used as a fallback as opposed to
303 * the pipeline cache defined by apps.
305 struct disk_cache
*disk_cache
;
307 struct tu_device_extension_table supported_extensions
;
312 TU_DEBUG_STARTUP
= 1 << 0,
317 VK_LOADER_DATA _loader_data
;
319 VkAllocationCallbacks alloc
;
321 uint32_t api_version
;
322 int physical_device_count
;
323 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
325 enum tu_debug_flags debug_flags
;
327 struct vk_debug_report_instance debug_report_callbacks
;
329 struct tu_instance_extension_table enabled_extensions
;
333 tu_instance_extension_supported(const char *name
);
335 tu_physical_device_api_version(struct tu_physical_device
*dev
);
337 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
342 struct tu_pipeline_cache
344 struct tu_device
*device
;
345 pthread_mutex_t mutex
;
349 uint32_t kernel_count
;
350 struct cache_entry
**hash_table
;
353 VkAllocationCallbacks alloc
;
356 struct tu_pipeline_key
361 tu_pipeline_cache_init(struct tu_pipeline_cache
*cache
,
362 struct tu_device
*device
);
364 tu_pipeline_cache_finish(struct tu_pipeline_cache
*cache
);
366 tu_pipeline_cache_load(struct tu_pipeline_cache
*cache
,
370 struct tu_shader_variant
;
373 tu_create_shader_variants_from_pipeline_cache(
374 struct tu_device
*device
,
375 struct tu_pipeline_cache
*cache
,
376 const unsigned char *sha1
,
377 struct tu_shader_variant
**variants
);
380 tu_pipeline_cache_insert_shaders(struct tu_device
*device
,
381 struct tu_pipeline_cache
*cache
,
382 const unsigned char *sha1
,
383 struct tu_shader_variant
**variants
,
384 const void *const *codes
,
385 const unsigned *code_sizes
);
389 VkAllocationCallbacks alloc
;
391 struct tu_pipeline_cache cache
;
395 #define TU_QUEUE_GENERAL 0
397 #define TU_MAX_QUEUE_FAMILIES 1
406 tu_fence_init(struct tu_fence
*fence
, bool signaled
);
408 tu_fence_finish(struct tu_fence
*fence
);
410 tu_fence_update_fd(struct tu_fence
*fence
, int fd
);
412 tu_fence_copy(struct tu_fence
*fence
, const struct tu_fence
*src
);
414 tu_fence_signal(struct tu_fence
*fence
);
416 tu_fence_wait_idle(struct tu_fence
*fence
);
420 VK_LOADER_DATA _loader_data
;
421 struct tu_device
*device
;
422 uint32_t queue_family_index
;
424 VkDeviceQueueCreateFlags flags
;
426 uint32_t msm_queue_id
;
427 struct tu_fence submit_fence
;
432 VK_LOADER_DATA _loader_data
;
434 VkAllocationCallbacks alloc
;
436 struct tu_instance
*instance
;
438 struct tu_meta_state meta_state
;
440 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
441 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
443 struct tu_physical_device
*physical_device
;
445 /* Backup in-memory cache to be used if the app doesn't provide one */
446 struct tu_pipeline_cache
*mem_cache
;
448 struct list_head shader_slabs
;
449 mtx_t shader_slab_mutex
;
451 struct tu_device_extension_table enabled_extensions
;
463 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
465 tu_bo_init_dmabuf(struct tu_device
*dev
,
470 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
);
472 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
474 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
479 const struct tu_bo
*bo
;
489 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
490 * is full. tu_cs_begin must be called before command packet emission and
491 * tu_cs_end must be called after.
493 * This mode may create multiple entries internally. The entries must be
494 * submitted together.
499 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
500 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
503 * This mode does not create any entry or any BO.
508 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
509 * command packet emission. tu_cs_begin_sub_stream must be called to get a
510 * sub-stream to emit comamnd packets to. When done with the sub-stream,
511 * tu_cs_end_sub_stream must be called.
513 * This mode does not create any entry internally.
515 TU_CS_MODE_SUB_STREAM
,
522 uint32_t *reserved_end
;
525 enum tu_cs_mode mode
;
526 uint32_t next_bo_size
;
528 struct tu_cs_entry
*entries
;
529 uint32_t entry_count
;
530 uint32_t entry_capacity
;
534 uint32_t bo_capacity
;
537 struct tu_device_memory
542 /* for dedicated allocations */
543 struct tu_image
*image
;
544 struct tu_buffer
*buffer
;
551 struct tu_descriptor_range
557 struct tu_descriptor_set
559 const struct tu_descriptor_set_layout
*layout
;
563 uint32_t *mapped_ptr
;
564 struct tu_descriptor_range
*dynamic_descriptors
;
567 struct tu_push_descriptor_set
569 struct tu_descriptor_set set
;
573 struct tu_descriptor_pool_entry
577 struct tu_descriptor_set
*set
;
580 struct tu_descriptor_pool
583 uint64_t current_offset
;
586 uint8_t *host_memory_base
;
587 uint8_t *host_memory_ptr
;
588 uint8_t *host_memory_end
;
590 uint32_t entry_count
;
591 uint32_t max_entry_count
;
592 struct tu_descriptor_pool_entry entries
[0];
595 struct tu_descriptor_update_template_entry
597 VkDescriptorType descriptor_type
;
599 /* The number of descriptors to update */
600 uint32_t descriptor_count
;
602 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
606 /* In dwords. Not valid/used for dynamic descriptors */
609 uint32_t buffer_offset
;
611 /* Only valid for combined image samplers and samplers */
612 uint16_t has_sampler
;
618 /* For push descriptors */
619 const uint32_t *immutable_samplers
;
622 struct tu_descriptor_update_template
624 uint32_t entry_count
;
625 VkPipelineBindPoint bind_point
;
626 struct tu_descriptor_update_template_entry entry
[0];
633 VkBufferUsageFlags usage
;
634 VkBufferCreateFlags flags
;
637 enum tu_dynamic_state_bits
639 TU_DYNAMIC_VIEWPORT
= 1 << 0,
640 TU_DYNAMIC_SCISSOR
= 1 << 1,
641 TU_DYNAMIC_LINE_WIDTH
= 1 << 2,
642 TU_DYNAMIC_DEPTH_BIAS
= 1 << 3,
643 TU_DYNAMIC_BLEND_CONSTANTS
= 1 << 4,
644 TU_DYNAMIC_DEPTH_BOUNDS
= 1 << 5,
645 TU_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6,
646 TU_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7,
647 TU_DYNAMIC_STENCIL_REFERENCE
= 1 << 8,
648 TU_DYNAMIC_DISCARD_RECTANGLE
= 1 << 9,
649 TU_DYNAMIC_ALL
= (1 << 10) - 1,
652 struct tu_vertex_binding
654 struct tu_buffer
*buffer
;
658 struct tu_viewport_state
661 VkViewport viewports
[MAX_VIEWPORTS
];
664 struct tu_scissor_state
667 VkRect2D scissors
[MAX_SCISSORS
];
670 struct tu_discard_rectangle_state
673 VkRect2D rectangles
[MAX_DISCARD_RECTANGLES
];
676 struct tu_dynamic_state
679 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
680 * Defines the set of saved dynamic state.
684 struct tu_viewport_state viewport
;
686 struct tu_scissor_state scissor
;
697 float blend_constants
[4];
709 } stencil_compare_mask
;
715 } stencil_write_mask
;
723 struct tu_discard_rectangle_state discard_rectangle
;
726 extern const struct tu_dynamic_state default_dynamic_state
;
729 tu_get_debug_option_name(int id
);
732 tu_get_perftest_option_name(int id
);
735 * Attachment state when recording a renderpass instance.
737 * The clear value is valid only if there exists a pending clear.
739 struct tu_attachment_state
741 VkImageAspectFlags pending_clear_aspects
;
742 uint32_t cleared_views
;
743 VkClearValue clear_value
;
744 VkImageLayout current_layout
;
747 struct tu_descriptor_state
749 struct tu_descriptor_set
*sets
[MAX_SETS
];
752 struct tu_push_descriptor_set push_set
;
754 uint32_t dynamic_buffers
[4 * MAX_DYNAMIC_BUFFERS
];
765 struct tu_tiling_config
767 VkRect2D render_area
;
768 uint32_t buffer_cpp
[MAX_RTS
+ 2];
769 uint32_t buffer_count
;
771 /* position and size of the first tile */
773 /* number of tiles */
774 VkExtent2D tile_count
;
776 uint32_t gmem_offsets
[MAX_RTS
+ 2];
778 /* size of the first VSC pipe */
780 /* number of VSC pipes */
781 VkExtent2D pipe_count
;
783 /* pipe register values */
784 uint32_t pipe_config
[MAX_VSC_PIPES
];
785 uint32_t pipe_sizes
[MAX_VSC_PIPES
];
790 /* Vertex descriptors */
794 struct tu_dynamic_state dynamic
;
797 struct tu_buffer
*index_buffer
;
798 uint64_t index_offset
;
800 uint32_t max_index_count
;
803 const struct tu_render_pass
*pass
;
804 const struct tu_subpass
*subpass
;
805 const struct tu_framebuffer
*framebuffer
;
806 struct tu_attachment_state
*attachments
;
808 struct tu_tiling_config tiling_config
;
810 struct tu_cs_entry tile_load_ib
;
811 struct tu_cs_entry tile_store_ib
;
816 VkAllocationCallbacks alloc
;
817 struct list_head cmd_buffers
;
818 struct list_head free_cmd_buffers
;
819 uint32_t queue_family_index
;
822 struct tu_cmd_buffer_upload
827 struct list_head list
;
830 enum tu_cmd_buffer_status
832 TU_CMD_BUFFER_STATUS_INVALID
,
833 TU_CMD_BUFFER_STATUS_INITIAL
,
834 TU_CMD_BUFFER_STATUS_RECORDING
,
835 TU_CMD_BUFFER_STATUS_EXECUTABLE
,
836 TU_CMD_BUFFER_STATUS_PENDING
,
843 struct drm_msm_gem_submit_bo
*bo_infos
;
846 #define TU_BO_LIST_FAILED (~0)
849 tu_bo_list_init(struct tu_bo_list
*list
);
851 tu_bo_list_destroy(struct tu_bo_list
*list
);
853 tu_bo_list_reset(struct tu_bo_list
*list
);
855 tu_bo_list_add(struct tu_bo_list
*list
,
856 const struct tu_bo
*bo
,
859 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
);
863 VK_LOADER_DATA _loader_data
;
865 struct tu_device
*device
;
867 struct tu_cmd_pool
*pool
;
868 struct list_head pool_link
;
870 VkCommandBufferUsageFlags usage_flags
;
871 VkCommandBufferLevel level
;
872 enum tu_cmd_buffer_status status
;
874 struct tu_cmd_state state
;
875 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
876 uint32_t queue_family_index
;
878 uint8_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
];
879 VkShaderStageFlags push_constant_stages
;
880 struct tu_descriptor_set meta_push_descriptors
;
882 struct tu_descriptor_state descriptors
[VK_PIPELINE_BIND_POINT_RANGE_SIZE
];
884 struct tu_cmd_buffer_upload upload
;
886 VkResult record_result
;
888 struct tu_bo_list bo_list
;
890 struct tu_cs tile_cs
;
893 uint32_t marker_seqno
;
895 struct tu_bo scratch_bo
;
896 uint32_t scratch_seqno
;
902 tu_get_memory_fd(struct tu_device
*device
,
903 struct tu_device_memory
*memory
,
907 * Takes x,y,z as exact numbers of invocations, instead of blocks.
909 * Limitations: Can't call normal dispatch functions without binding or
911 * the compute pipeline.
914 tu_unaligned_dispatch(struct tu_cmd_buffer
*cmd_buffer
,
924 struct tu_shader_module
;
926 #define TU_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
927 #define TU_HASH_SHADER_SISCHED (1 << 1)
928 #define TU_HASH_SHADER_UNSAFE_MATH (1 << 2)
930 tu_hash_shaders(unsigned char *hash
,
931 const VkPipelineShaderStageCreateInfo
**stages
,
932 const struct tu_pipeline_layout
*layout
,
933 const struct tu_pipeline_key
*key
,
936 static inline gl_shader_stage
937 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
939 assert(__builtin_popcount(vk_stage
) == 1);
940 return ffs(vk_stage
) - 1;
943 static inline VkShaderStageFlagBits
944 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
946 return (1 << mesa_stage
);
949 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
951 #define tu_foreach_stage(stage, stage_bits) \
952 for (gl_shader_stage stage, \
953 __tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
954 stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
956 struct tu_shader_module
958 struct nir_shader
*nir
;
959 unsigned char sha1
[20];
966 struct tu_device
*device
;
967 struct tu_dynamic_state dynamic_state
;
969 struct tu_pipeline_layout
*layout
;
971 bool need_indirect_descriptor_sets
;
972 VkShaderStageFlags active_stages
;
975 struct tu_userdata_info
*
976 tu_lookup_user_sgpr(struct tu_pipeline
*pipeline
,
977 gl_shader_stage stage
,
980 struct tu_shader_variant
*
981 tu_get_shader(struct tu_pipeline
*pipeline
, gl_shader_stage stage
);
983 struct tu_graphics_pipeline_create_info
987 bool db_stencil_clear
;
988 bool db_depth_disable_expclear
;
989 bool db_stencil_disable_expclear
;
990 bool db_flush_depth_inplace
;
991 bool db_flush_stencil_inplace
;
993 uint32_t custom_blend_mode
;
997 tu_graphics_pipeline_create(
999 VkPipelineCache cache
,
1000 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1001 const struct tu_graphics_pipeline_create_info
*extra
,
1002 const VkAllocationCallbacks
*alloc
,
1003 VkPipeline
*pPipeline
);
1005 struct tu_native_format
1007 int vtx
; /* VFMTn_xxx or -1 */
1008 int tex
; /* TFMTn_xxx or -1 */
1009 int rb
; /* RBn_xxx or -1 */
1010 int swap
; /* enum a3xx_color_swap */
1011 bool present
; /* internal only; always true to external users */
1014 const struct tu_native_format
*
1015 tu6_get_native_format(VkFormat format
);
1018 tu_pack_clear_value(const VkClearValue
*val
,
1022 struct tu_image_level
1024 VkDeviceSize offset
;
1032 /* The original VkFormat provided by the client. This may not match any
1033 * of the actual surface formats.
1036 VkImageAspectFlags aspects
;
1037 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1038 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1039 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
1041 uint32_t level_count
;
1042 uint32_t layer_count
;
1048 VkDeviceSize layer_size
;
1049 struct tu_image_level levels
[15];
1052 unsigned queue_family_mask
;
1056 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1057 VkDeviceMemory owned_memory
;
1059 /* Set when bound */
1060 const struct tu_bo
*bo
;
1061 VkDeviceSize bo_offset
;
1065 tu_image_queue_family_mask(const struct tu_image
*image
,
1067 uint32_t queue_family
);
1069 static inline uint32_t
1070 tu_get_layerCount(const struct tu_image
*image
,
1071 const VkImageSubresourceRange
*range
)
1073 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
1074 ? image
->layer_count
- range
->baseArrayLayer
1075 : range
->layerCount
;
1078 static inline uint32_t
1079 tu_get_levelCount(const struct tu_image
*image
,
1080 const VkImageSubresourceRange
*range
)
1082 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
1083 ? image
->level_count
- range
->baseMipLevel
1084 : range
->levelCount
;
1087 struct tu_image_view
1089 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
1091 VkImageViewType type
;
1092 VkImageAspectFlags aspect_mask
;
1094 uint32_t base_layer
;
1095 uint32_t layer_count
;
1097 uint32_t level_count
;
1098 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1100 uint32_t descriptor
[16];
1102 /* Descriptor for use as a storage image as opposed to a sampled image.
1103 * This has a few differences for cube maps (e.g. type).
1105 uint32_t storage_descriptor
[16];
1112 struct tu_image_create_info
1114 const VkImageCreateInfo
*vk_info
;
1116 bool no_metadata_planes
;
1120 tu_image_create(VkDevice _device
,
1121 const struct tu_image_create_info
*info
,
1122 const VkAllocationCallbacks
*alloc
,
1126 tu_image_from_gralloc(VkDevice device_h
,
1127 const VkImageCreateInfo
*base_info
,
1128 const VkNativeBufferANDROID
*gralloc_info
,
1129 const VkAllocationCallbacks
*alloc
,
1130 VkImage
*out_image_h
);
1133 tu_image_view_init(struct tu_image_view
*view
,
1134 struct tu_device
*device
,
1135 const VkImageViewCreateInfo
*pCreateInfo
);
1137 struct tu_buffer_view
1140 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1144 tu_buffer_view_init(struct tu_buffer_view
*view
,
1145 struct tu_device
*device
,
1146 const VkBufferViewCreateInfo
*pCreateInfo
);
1148 static inline struct VkExtent3D
1149 tu_sanitize_image_extent(const VkImageType imageType
,
1150 const struct VkExtent3D imageExtent
)
1152 switch (imageType
) {
1153 case VK_IMAGE_TYPE_1D
:
1154 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1155 case VK_IMAGE_TYPE_2D
:
1156 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1157 case VK_IMAGE_TYPE_3D
:
1160 unreachable("invalid image type");
1164 static inline struct VkOffset3D
1165 tu_sanitize_image_offset(const VkImageType imageType
,
1166 const struct VkOffset3D imageOffset
)
1168 switch (imageType
) {
1169 case VK_IMAGE_TYPE_1D
:
1170 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1171 case VK_IMAGE_TYPE_2D
:
1172 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1173 case VK_IMAGE_TYPE_3D
:
1176 unreachable("invalid image type");
1180 struct tu_attachment_info
1182 struct tu_image_view
*attachment
;
1185 struct tu_framebuffer
1191 uint32_t attachment_count
;
1192 struct tu_attachment_info attachments
[0];
1195 struct tu_subpass_barrier
1197 VkPipelineStageFlags src_stage_mask
;
1198 VkAccessFlags src_access_mask
;
1199 VkAccessFlags dst_access_mask
;
1203 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
1204 const struct tu_subpass_barrier
*barrier
);
1206 struct tu_subpass_attachment
1208 uint32_t attachment
;
1209 VkImageLayout layout
;
1214 uint32_t input_count
;
1215 uint32_t color_count
;
1216 struct tu_subpass_attachment
*input_attachments
;
1217 struct tu_subpass_attachment
*color_attachments
;
1218 struct tu_subpass_attachment
*resolve_attachments
;
1219 struct tu_subpass_attachment depth_stencil_attachment
;
1221 /** Subpass has at least one resolve attachment */
1224 struct tu_subpass_barrier start_barrier
;
1227 VkSampleCountFlagBits max_sample_count
;
1230 struct tu_render_pass_attachment
1234 VkAttachmentLoadOp load_op
;
1235 VkAttachmentLoadOp stencil_load_op
;
1236 VkImageLayout initial_layout
;
1237 VkImageLayout final_layout
;
1241 struct tu_render_pass
1243 uint32_t attachment_count
;
1244 uint32_t subpass_count
;
1245 struct tu_subpass_attachment
*subpass_attachments
;
1246 struct tu_render_pass_attachment
*attachments
;
1247 struct tu_subpass_barrier end_barrier
;
1248 struct tu_subpass subpasses
[0];
1252 tu_device_init_meta(struct tu_device
*device
);
1254 tu_device_finish_meta(struct tu_device
*device
);
1256 struct tu_query_pool
1259 uint32_t availability_offset
;
1263 uint32_t pipeline_stats_mask
;
1269 uint32_t temp_syncobj
;
1273 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1274 VkPipelineBindPoint bind_point
,
1275 struct tu_descriptor_set
*set
,
1279 tu_update_descriptor_sets(struct tu_device
*device
,
1280 struct tu_cmd_buffer
*cmd_buffer
,
1281 VkDescriptorSet overrideSet
,
1282 uint32_t descriptorWriteCount
,
1283 const VkWriteDescriptorSet
*pDescriptorWrites
,
1284 uint32_t descriptorCopyCount
,
1285 const VkCopyDescriptorSet
*pDescriptorCopies
);
1288 tu_update_descriptor_set_with_template(
1289 struct tu_device
*device
,
1290 struct tu_cmd_buffer
*cmd_buffer
,
1291 struct tu_descriptor_set
*set
,
1292 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate
,
1296 tu_meta_push_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1297 VkPipelineBindPoint pipelineBindPoint
,
1298 VkPipelineLayout _layout
,
1300 uint32_t descriptorWriteCount
,
1301 const VkWriteDescriptorSet
*pDescriptorWrites
);
1304 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
);
1307 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
);
1310 tu_drm_submitqueue_new(const struct tu_device
*dev
,
1312 uint32_t *queue_id
);
1315 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
);
1318 tu_gem_new(const struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1320 tu_gem_import_dmabuf(const struct tu_device
*dev
,
1324 tu_gem_export_dmabuf(const struct tu_device
*dev
, uint32_t gem_handle
);
1326 tu_gem_close(const struct tu_device
*dev
, uint32_t gem_handle
);
1328 tu_gem_info_offset(const struct tu_device
*dev
, uint32_t gem_handle
);
1330 tu_gem_info_iova(const struct tu_device
*dev
, uint32_t gem_handle
);
1332 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1334 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1336 return (struct __tu_type *) _handle; \
1339 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1341 return (__VkType) _obj; \
1344 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1346 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1348 return (struct __tu_type *) (uintptr_t) _handle; \
1351 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1353 return (__VkType)(uintptr_t) _obj; \
1356 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1357 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1359 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1360 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1361 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1362 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1363 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1365 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1366 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1367 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1368 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1369 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1370 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1371 VkDescriptorSetLayout
)
1372 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1373 VkDescriptorUpdateTemplateKHR
)
1374 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1375 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1376 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1377 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1378 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1379 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1380 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1381 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1382 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1383 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1384 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1385 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1386 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1387 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1389 #endif /* TU_PRIVATE_H */