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 "tu_descriptor_set.h"
55 #include "tu_extensions.h"
57 /* Pre-declarations needed for WSI entrypoints */
60 typedef struct xcb_connection_t xcb_connection_t
;
61 typedef uint32_t xcb_visualid_t
;
62 typedef uint32_t xcb_window_t
;
64 #include <vulkan/vk_android_native_buffer.h>
65 #include <vulkan/vk_icd.h>
66 #include <vulkan/vulkan.h>
67 #include <vulkan/vulkan_intel.h>
69 #include "drm/freedreno_ringbuffer.h"
70 #include "tu_entrypoints.h"
73 #define MAX_VERTEX_ATTRIBS 32
75 #define MAX_VIEWPORTS 16
76 #define MAX_SCISSORS 16
77 #define MAX_DISCARD_RECTANGLES 4
78 #define MAX_PUSH_CONSTANTS_SIZE 128
79 #define MAX_PUSH_DESCRIPTORS 32
80 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
81 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
82 #define MAX_DYNAMIC_BUFFERS \
83 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
84 #define MAX_SAMPLES_LOG2 4
85 #define NUM_META_FS_KEYS 13
86 #define TU_MAX_DRM_DEVICES 8
89 #define NUM_DEPTH_CLEAR_PIPELINES 3
92 * This is the point we switch from using CP to compute shader
93 * for certain buffer operations.
95 #define TU_BUFFER_OPS_CS_THRESHOLD 4096
100 TU_MEM_HEAP_VRAM_CPU_ACCESS
,
108 TU_MEM_TYPE_GTT_WRITE_COMBINE
,
109 TU_MEM_TYPE_VRAM_CPU_ACCESS
,
110 TU_MEM_TYPE_GTT_CACHED
,
114 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
116 static inline uint32_t
117 align_u32(uint32_t v
, uint32_t a
)
119 assert(a
!= 0 && a
== (a
& -a
));
120 return (v
+ a
- 1) & ~(a
- 1);
123 static inline uint32_t
124 align_u32_npot(uint32_t v
, uint32_t a
)
126 return (v
+ a
- 1) / a
* a
;
129 static inline uint64_t
130 align_u64(uint64_t v
, uint64_t a
)
132 assert(a
!= 0 && a
== (a
& -a
));
133 return (v
+ a
- 1) & ~(a
- 1);
136 static inline int32_t
137 align_i32(int32_t v
, int32_t a
)
139 assert(a
!= 0 && a
== (a
& -a
));
140 return (v
+ a
- 1) & ~(a
- 1);
143 /** Alignment must be a power of 2. */
145 tu_is_aligned(uintmax_t n
, uintmax_t a
)
147 assert(a
== (a
& -a
));
148 return (n
& (a
- 1)) == 0;
151 static inline uint32_t
152 round_up_u32(uint32_t v
, uint32_t a
)
154 return (v
+ a
- 1) / a
;
157 static inline uint64_t
158 round_up_u64(uint64_t v
, uint64_t a
)
160 return (v
+ a
- 1) / a
;
163 static inline uint32_t
164 tu_minify(uint32_t n
, uint32_t levels
)
166 if (unlikely(n
== 0))
169 return MAX2(n
>> levels
, 1);
172 tu_clamp_f(float f
, float min
, float max
)
185 tu_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
187 if (*inout_mask
& clear_mask
) {
188 *inout_mask
&= ~clear_mask
;
195 #define for_each_bit(b, dword) \
196 for (uint32_t __dword = (dword); \
197 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
199 #define typed_memcpy(dest, src, count) \
201 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
202 memcpy((dest), (src), (count) * sizeof(*(src))); \
205 /* Whenever we generate an error, pass it through this function. Useful for
206 * debugging, where we can break on it. Only call at error site, not when
207 * propagating errors. Might be useful to plug in a stack trace here.
213 __vk_errorf(struct tu_instance
*instance
,
220 #define vk_error(instance, error) \
221 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
222 #define vk_errorf(instance, error, format, ...) \
223 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
226 __tu_finishme(const char *file
, int line
, const char *format
, ...)
229 tu_loge(const char *format
, ...) tu_printflike(1, 2);
231 tu_loge_v(const char *format
, va_list va
);
233 tu_logi(const char *format
, ...) tu_printflike(1, 2);
235 tu_logi_v(const char *format
, va_list va
);
238 * Print a FINISHME message, including its source location.
240 #define tu_finishme(format, ...) \
242 static bool reported = false; \
244 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
249 /* A non-fatal assert. Useful for debugging. */
251 #define tu_assert(x) \
253 if (unlikely(!(x))) \
254 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
260 /* Suppress -Wunused in stub functions */
261 #define tu_use_args(...) __tu_use_args(0, ##__VA_ARGS__)
263 __tu_use_args(int ignore
, ...)
269 tu_finishme("stub %s", __func__); \
273 tu_lookup_entrypoint_unchecked(const char *name
);
275 tu_lookup_entrypoint_checked(
277 uint32_t core_version
,
278 const struct tu_instance_extension_table
*instance
,
279 const struct tu_device_extension_table
*device
);
281 struct tu_physical_device
283 VK_LOADER_DATA _loader_data
;
285 struct tu_instance
*instance
;
288 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
289 uint8_t driver_uuid
[VK_UUID_SIZE
];
290 uint8_t device_uuid
[VK_UUID_SIZE
];
291 uint8_t cache_uuid
[VK_UUID_SIZE
];
296 struct fd_device
*drm_device
;
300 /* This is the drivers on-disk cache used as a fallback as opposed to
301 * the pipeline cache defined by apps.
303 struct disk_cache
*disk_cache
;
305 struct tu_device_extension_table supported_extensions
;
310 TU_DEBUG_STARTUP
= 1 << 0,
315 VK_LOADER_DATA _loader_data
;
317 VkAllocationCallbacks alloc
;
319 uint32_t api_version
;
320 int physical_device_count
;
321 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
323 enum tu_debug_flags debug_flags
;
325 struct vk_debug_report_instance debug_report_callbacks
;
327 struct tu_instance_extension_table enabled_extensions
;
331 tu_instance_extension_supported(const char *name
);
333 tu_physical_device_api_version(struct tu_physical_device
*dev
);
335 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
340 struct tu_pipeline_cache
342 struct tu_device
*device
;
343 pthread_mutex_t mutex
;
347 uint32_t kernel_count
;
348 struct cache_entry
**hash_table
;
351 VkAllocationCallbacks alloc
;
354 struct tu_pipeline_key
359 tu_pipeline_cache_init(struct tu_pipeline_cache
*cache
,
360 struct tu_device
*device
);
362 tu_pipeline_cache_finish(struct tu_pipeline_cache
*cache
);
364 tu_pipeline_cache_load(struct tu_pipeline_cache
*cache
,
368 struct tu_shader_variant
;
371 tu_create_shader_variants_from_pipeline_cache(
372 struct tu_device
*device
,
373 struct tu_pipeline_cache
*cache
,
374 const unsigned char *sha1
,
375 struct tu_shader_variant
**variants
);
378 tu_pipeline_cache_insert_shaders(struct tu_device
*device
,
379 struct tu_pipeline_cache
*cache
,
380 const unsigned char *sha1
,
381 struct tu_shader_variant
**variants
,
382 const void *const *codes
,
383 const unsigned *code_sizes
);
387 VkAllocationCallbacks alloc
;
389 struct tu_pipeline_cache cache
;
393 #define TU_QUEUE_GENERAL 0
395 #define TU_MAX_QUEUE_FAMILIES 1
399 VK_LOADER_DATA _loader_data
;
400 struct tu_device
*device
;
401 uint32_t queue_family_index
;
403 VkDeviceQueueCreateFlags flags
;
408 VK_LOADER_DATA _loader_data
;
410 VkAllocationCallbacks alloc
;
412 struct tu_instance
*instance
;
414 struct tu_meta_state meta_state
;
416 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
417 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
419 struct tu_physical_device
*physical_device
;
421 /* Backup in-memory cache to be used if the app doesn't provide one */
422 struct tu_pipeline_cache
*mem_cache
;
424 struct list_head shader_slabs
;
425 mtx_t shader_slab_mutex
;
427 struct tu_device_extension_table enabled_extensions
;
440 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
442 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
444 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
446 struct tu_device_memory
451 /* for dedicated allocations */
452 struct tu_image
*image
;
453 struct tu_buffer
*buffer
;
460 struct tu_descriptor_range
466 struct tu_descriptor_set
468 const struct tu_descriptor_set_layout
*layout
;
472 uint32_t *mapped_ptr
;
473 struct tu_descriptor_range
*dynamic_descriptors
;
476 struct tu_push_descriptor_set
478 struct tu_descriptor_set set
;
482 struct tu_descriptor_pool_entry
486 struct tu_descriptor_set
*set
;
489 struct tu_descriptor_pool
492 uint64_t current_offset
;
495 uint8_t *host_memory_base
;
496 uint8_t *host_memory_ptr
;
497 uint8_t *host_memory_end
;
499 uint32_t entry_count
;
500 uint32_t max_entry_count
;
501 struct tu_descriptor_pool_entry entries
[0];
504 struct tu_descriptor_update_template_entry
506 VkDescriptorType descriptor_type
;
508 /* The number of descriptors to update */
509 uint32_t descriptor_count
;
511 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
515 /* In dwords. Not valid/used for dynamic descriptors */
518 uint32_t buffer_offset
;
520 /* Only valid for combined image samplers and samplers */
521 uint16_t has_sampler
;
527 /* For push descriptors */
528 const uint32_t *immutable_samplers
;
531 struct tu_descriptor_update_template
533 uint32_t entry_count
;
534 VkPipelineBindPoint bind_point
;
535 struct tu_descriptor_update_template_entry entry
[0];
542 VkBufferUsageFlags usage
;
543 VkBufferCreateFlags flags
;
546 enum tu_dynamic_state_bits
548 TU_DYNAMIC_VIEWPORT
= 1 << 0,
549 TU_DYNAMIC_SCISSOR
= 1 << 1,
550 TU_DYNAMIC_LINE_WIDTH
= 1 << 2,
551 TU_DYNAMIC_DEPTH_BIAS
= 1 << 3,
552 TU_DYNAMIC_BLEND_CONSTANTS
= 1 << 4,
553 TU_DYNAMIC_DEPTH_BOUNDS
= 1 << 5,
554 TU_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6,
555 TU_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7,
556 TU_DYNAMIC_STENCIL_REFERENCE
= 1 << 8,
557 TU_DYNAMIC_DISCARD_RECTANGLE
= 1 << 9,
558 TU_DYNAMIC_ALL
= (1 << 10) - 1,
561 struct tu_vertex_binding
563 struct tu_buffer
*buffer
;
567 struct tu_viewport_state
570 VkViewport viewports
[MAX_VIEWPORTS
];
573 struct tu_scissor_state
576 VkRect2D scissors
[MAX_SCISSORS
];
579 struct tu_discard_rectangle_state
582 VkRect2D rectangles
[MAX_DISCARD_RECTANGLES
];
585 struct tu_dynamic_state
588 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
589 * Defines the set of saved dynamic state.
593 struct tu_viewport_state viewport
;
595 struct tu_scissor_state scissor
;
606 float blend_constants
[4];
618 } stencil_compare_mask
;
624 } stencil_write_mask
;
632 struct tu_discard_rectangle_state discard_rectangle
;
635 extern const struct tu_dynamic_state default_dynamic_state
;
638 tu_get_debug_option_name(int id
);
641 tu_get_perftest_option_name(int id
);
644 * Attachment state when recording a renderpass instance.
646 * The clear value is valid only if there exists a pending clear.
648 struct tu_attachment_state
650 VkImageAspectFlags pending_clear_aspects
;
651 uint32_t cleared_views
;
652 VkClearValue clear_value
;
653 VkImageLayout current_layout
;
656 struct tu_descriptor_state
658 struct tu_descriptor_set
*sets
[MAX_SETS
];
661 struct tu_push_descriptor_set push_set
;
663 uint32_t dynamic_buffers
[4 * MAX_DYNAMIC_BUFFERS
];
668 /* Vertex descriptors */
672 struct tu_dynamic_state dynamic
;
675 struct tu_buffer
*index_buffer
;
676 uint64_t index_offset
;
678 uint32_t max_index_count
;
684 VkAllocationCallbacks alloc
;
685 struct list_head cmd_buffers
;
686 struct list_head free_cmd_buffers
;
687 uint32_t queue_family_index
;
690 struct tu_cmd_buffer_upload
695 struct list_head list
;
698 enum tu_cmd_buffer_status
700 TU_CMD_BUFFER_STATUS_INVALID
,
701 TU_CMD_BUFFER_STATUS_INITIAL
,
702 TU_CMD_BUFFER_STATUS_RECORDING
,
703 TU_CMD_BUFFER_STATUS_EXECUTABLE
,
704 TU_CMD_BUFFER_STATUS_PENDING
,
714 struct tu_cmd_stream_entry
729 struct tu_cmd_stream_entry
*entries
;
730 uint32_t entry_count
;
731 uint32_t entry_capacity
;
735 uint32_t bo_capacity
;
740 VK_LOADER_DATA _loader_data
;
742 struct tu_device
*device
;
744 struct tu_cmd_pool
*pool
;
745 struct list_head pool_link
;
747 VkCommandBufferUsageFlags usage_flags
;
748 VkCommandBufferLevel level
;
749 enum tu_cmd_buffer_status status
;
751 struct tu_cmd_state state
;
752 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
753 uint32_t queue_family_index
;
755 uint8_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
];
756 VkShaderStageFlags push_constant_stages
;
757 struct tu_descriptor_set meta_push_descriptors
;
759 struct tu_descriptor_state descriptors
[VK_PIPELINE_BIND_POINT_RANGE_SIZE
];
761 struct tu_cmd_buffer_upload upload
;
763 struct tu_bo_list bo_list
;
764 struct tu_cmd_stream primary_cmd_stream
;
766 VkResult record_result
;
770 tu_get_memory_fd(struct tu_device
*device
,
771 struct tu_device_memory
*memory
,
775 * Takes x,y,z as exact numbers of invocations, instead of blocks.
777 * Limitations: Can't call normal dispatch functions without binding or
779 * the compute pipeline.
782 tu_unaligned_dispatch(struct tu_cmd_buffer
*cmd_buffer
,
792 struct tu_shader_module
;
794 #define TU_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
795 #define TU_HASH_SHADER_SISCHED (1 << 1)
796 #define TU_HASH_SHADER_UNSAFE_MATH (1 << 2)
798 tu_hash_shaders(unsigned char *hash
,
799 const VkPipelineShaderStageCreateInfo
**stages
,
800 const struct tu_pipeline_layout
*layout
,
801 const struct tu_pipeline_key
*key
,
804 static inline gl_shader_stage
805 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
807 assert(__builtin_popcount(vk_stage
) == 1);
808 return ffs(vk_stage
) - 1;
811 static inline VkShaderStageFlagBits
812 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
814 return (1 << mesa_stage
);
817 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
819 #define tu_foreach_stage(stage, stage_bits) \
820 for (gl_shader_stage stage, \
821 __tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
822 stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
824 struct tu_shader_module
826 struct nir_shader
*nir
;
827 unsigned char sha1
[20];
834 struct tu_device
*device
;
835 struct tu_dynamic_state dynamic_state
;
837 struct tu_pipeline_layout
*layout
;
839 bool need_indirect_descriptor_sets
;
840 VkShaderStageFlags active_stages
;
843 struct tu_userdata_info
*
844 tu_lookup_user_sgpr(struct tu_pipeline
*pipeline
,
845 gl_shader_stage stage
,
848 struct tu_shader_variant
*
849 tu_get_shader(struct tu_pipeline
*pipeline
, gl_shader_stage stage
);
851 struct tu_graphics_pipeline_create_info
855 bool db_stencil_clear
;
856 bool db_depth_disable_expclear
;
857 bool db_stencil_disable_expclear
;
858 bool db_flush_depth_inplace
;
859 bool db_flush_stencil_inplace
;
861 uint32_t custom_blend_mode
;
865 tu_graphics_pipeline_create(
867 VkPipelineCache cache
,
868 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
869 const struct tu_graphics_pipeline_create_info
*extra
,
870 const VkAllocationCallbacks
*alloc
,
871 VkPipeline
*pPipeline
);
873 struct vk_format_description
;
875 tu_translate_buffer_dataformat(const struct vk_format_description
*desc
,
878 tu_translate_buffer_numformat(const struct vk_format_description
*desc
,
881 tu_translate_colorformat(VkFormat format
);
883 tu_translate_color_numformat(VkFormat format
,
884 const struct vk_format_description
*desc
,
887 tu_colorformat_endian_swap(uint32_t colorformat
);
889 tu_translate_colorswap(VkFormat format
, bool do_endian_swap
);
891 tu_translate_dbformat(VkFormat format
);
893 tu_translate_tex_dataformat(VkFormat format
,
894 const struct vk_format_description
*desc
,
897 tu_translate_tex_numformat(VkFormat format
,
898 const struct vk_format_description
*desc
,
901 tu_format_pack_clear_color(VkFormat format
,
902 uint32_t clear_vals
[2],
903 VkClearColorValue
*value
);
905 tu_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
);
907 tu_dcc_formats_compatible(VkFormat format1
, VkFormat format2
);
909 struct tu_image_level
919 /* The original VkFormat provided by the client. This may not match any
920 * of the actual surface formats.
923 VkImageAspectFlags aspects
;
924 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
925 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
926 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
933 VkDeviceSize layer_size
;
934 struct tu_image_level levels
[15];
937 unsigned queue_family_mask
;
941 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
942 VkDeviceMemory owned_memory
;
946 tu_image_queue_family_mask(const struct tu_image
*image
,
948 uint32_t queue_family
);
950 static inline uint32_t
951 tu_get_layerCount(const struct tu_image
*image
,
952 const VkImageSubresourceRange
*range
)
957 static inline uint32_t
958 tu_get_levelCount(const struct tu_image
*image
,
959 const VkImageSubresourceRange
*range
)
966 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
968 VkImageViewType type
;
969 VkImageAspectFlags aspect_mask
;
972 uint32_t layer_count
;
974 uint32_t level_count
;
975 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
977 uint32_t descriptor
[16];
979 /* Descriptor for use as a storage image as opposed to a sampled image.
980 * This has a few differences for cube maps (e.g. type).
982 uint32_t storage_descriptor
[16];
989 struct tu_image_create_info
991 const VkImageCreateInfo
*vk_info
;
993 bool no_metadata_planes
;
997 tu_image_create(VkDevice _device
,
998 const struct tu_image_create_info
*info
,
999 const VkAllocationCallbacks
*alloc
,
1003 tu_image_from_gralloc(VkDevice device_h
,
1004 const VkImageCreateInfo
*base_info
,
1005 const VkNativeBufferANDROID
*gralloc_info
,
1006 const VkAllocationCallbacks
*alloc
,
1007 VkImage
*out_image_h
);
1010 tu_image_view_init(struct tu_image_view
*view
,
1011 struct tu_device
*device
,
1012 const VkImageViewCreateInfo
*pCreateInfo
);
1014 struct tu_buffer_view
1017 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1021 tu_buffer_view_init(struct tu_buffer_view
*view
,
1022 struct tu_device
*device
,
1023 const VkBufferViewCreateInfo
*pCreateInfo
);
1025 static inline struct VkExtent3D
1026 tu_sanitize_image_extent(const VkImageType imageType
,
1027 const struct VkExtent3D imageExtent
)
1029 switch (imageType
) {
1030 case VK_IMAGE_TYPE_1D
:
1031 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1032 case VK_IMAGE_TYPE_2D
:
1033 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1034 case VK_IMAGE_TYPE_3D
:
1037 unreachable("invalid image type");
1041 static inline struct VkOffset3D
1042 tu_sanitize_image_offset(const VkImageType imageType
,
1043 const struct VkOffset3D imageOffset
)
1045 switch (imageType
) {
1046 case VK_IMAGE_TYPE_1D
:
1047 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1048 case VK_IMAGE_TYPE_2D
:
1049 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1050 case VK_IMAGE_TYPE_3D
:
1053 unreachable("invalid image type");
1057 struct tu_attachment_info
1059 struct tu_image_view
*attachment
;
1062 struct tu_framebuffer
1068 uint32_t attachment_count
;
1069 struct tu_attachment_info attachments
[0];
1072 struct tu_subpass_barrier
1074 VkPipelineStageFlags src_stage_mask
;
1075 VkAccessFlags src_access_mask
;
1076 VkAccessFlags dst_access_mask
;
1080 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
1081 const struct tu_subpass_barrier
*barrier
);
1083 struct tu_subpass_attachment
1085 uint32_t attachment
;
1086 VkImageLayout layout
;
1091 uint32_t input_count
;
1092 uint32_t color_count
;
1093 struct tu_subpass_attachment
*input_attachments
;
1094 struct tu_subpass_attachment
*color_attachments
;
1095 struct tu_subpass_attachment
*resolve_attachments
;
1096 struct tu_subpass_attachment depth_stencil_attachment
;
1098 /** Subpass has at least one resolve attachment */
1101 struct tu_subpass_barrier start_barrier
;
1104 VkSampleCountFlagBits max_sample_count
;
1107 struct tu_render_pass_attachment
1111 VkAttachmentLoadOp load_op
;
1112 VkAttachmentLoadOp stencil_load_op
;
1113 VkImageLayout initial_layout
;
1114 VkImageLayout final_layout
;
1118 struct tu_render_pass
1120 uint32_t attachment_count
;
1121 uint32_t subpass_count
;
1122 struct tu_subpass_attachment
*subpass_attachments
;
1123 struct tu_render_pass_attachment
*attachments
;
1124 struct tu_subpass_barrier end_barrier
;
1125 struct tu_subpass subpasses
[0];
1129 tu_device_init_meta(struct tu_device
*device
);
1131 tu_device_finish_meta(struct tu_device
*device
);
1133 struct tu_query_pool
1136 uint32_t availability_offset
;
1140 uint32_t pipeline_stats_mask
;
1146 uint32_t temp_syncobj
;
1150 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1151 VkPipelineBindPoint bind_point
,
1152 struct tu_descriptor_set
*set
,
1156 tu_update_descriptor_sets(struct tu_device
*device
,
1157 struct tu_cmd_buffer
*cmd_buffer
,
1158 VkDescriptorSet overrideSet
,
1159 uint32_t descriptorWriteCount
,
1160 const VkWriteDescriptorSet
*pDescriptorWrites
,
1161 uint32_t descriptorCopyCount
,
1162 const VkCopyDescriptorSet
*pDescriptorCopies
);
1165 tu_update_descriptor_set_with_template(
1166 struct tu_device
*device
,
1167 struct tu_cmd_buffer
*cmd_buffer
,
1168 struct tu_descriptor_set
*set
,
1169 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate
,
1173 tu_meta_push_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1174 VkPipelineBindPoint pipelineBindPoint
,
1175 VkPipelineLayout _layout
,
1177 uint32_t descriptorWriteCount
,
1178 const VkWriteDescriptorSet
*pDescriptorWrites
);
1183 uint32_t temp_syncobj
;
1187 tu_gem_new(struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1189 tu_gem_close(struct tu_device
*dev
, uint32_t gem_handle
);
1191 tu_gem_info_offset(struct tu_device
*dev
, uint32_t gem_handle
);
1193 tu_gem_info_iova(struct tu_device
*dev
, uint32_t gem_handle
);
1195 tu_drm_query_param(struct tu_physical_device
*dev
,
1199 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1201 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1203 return (struct __tu_type *) _handle; \
1206 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1208 return (__VkType) _obj; \
1211 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1213 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1215 return (struct __tu_type *) (uintptr_t) _handle; \
1218 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1220 return (__VkType)(uintptr_t) _obj; \
1223 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1224 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1226 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1227 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1228 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1229 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1230 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1232 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1233 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1234 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1235 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1236 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1237 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1238 VkDescriptorSetLayout
)
1239 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1240 VkDescriptorUpdateTemplateKHR
)
1241 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1242 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1243 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1244 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1245 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1246 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1247 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1248 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1249 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1250 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1251 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1252 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1253 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1254 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1256 #endif /* TU_PRIVATE_H */