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 DEALINGS
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"
71 #include "tu_entrypoints.h"
74 #define MAX_VERTEX_ATTRIBS 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); (b) = __builtin_ffs(__dword) - 1, __dword; \
198 __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__)
263 static inline void __tu_use_args(int ignore
, ...) {}
265 #define tu_stub_return(v) \
267 tu_finishme("stub %s", __func__); \
273 tu_finishme("stub %s", __func__); \
278 tu_lookup_entrypoint_unchecked(const char *name
);
280 tu_lookup_entrypoint_checked(
282 uint32_t core_version
,
283 const struct tu_instance_extension_table
*instance
,
284 const struct tu_device_extension_table
*device
);
286 struct tu_physical_device
288 VK_LOADER_DATA _loader_data
;
290 struct tu_instance
*instance
;
293 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
294 uint8_t driver_uuid
[VK_UUID_SIZE
];
295 uint8_t device_uuid
[VK_UUID_SIZE
];
296 uint8_t cache_uuid
[VK_UUID_SIZE
];
301 struct fd_device
*drm_device
;
305 /* This is the drivers on-disk cache used as a fallback as opposed to
306 * the pipeline cache defined by apps.
308 struct disk_cache
*disk_cache
;
310 struct tu_device_extension_table supported_extensions
;
315 TU_DEBUG_STARTUP
= 1 << 0,
320 VK_LOADER_DATA _loader_data
;
322 VkAllocationCallbacks alloc
;
324 uint32_t api_version
;
325 int physical_device_count
;
326 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
328 enum tu_debug_flags debug_flags
;
330 struct vk_debug_report_instance debug_report_callbacks
;
332 struct tu_instance_extension_table enabled_extensions
;
336 tu_instance_extension_supported(const char *name
);
338 tu_physical_device_api_version(struct tu_physical_device
*dev
);
340 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
345 struct tu_pipeline_cache
347 struct tu_device
*device
;
348 pthread_mutex_t mutex
;
352 uint32_t kernel_count
;
353 struct cache_entry
**hash_table
;
356 VkAllocationCallbacks alloc
;
359 struct tu_pipeline_key
364 tu_pipeline_cache_init(struct tu_pipeline_cache
*cache
,
365 struct tu_device
*device
);
367 tu_pipeline_cache_finish(struct tu_pipeline_cache
*cache
);
369 tu_pipeline_cache_load(struct tu_pipeline_cache
*cache
,
373 struct tu_shader_variant
;
376 tu_create_shader_variants_from_pipeline_cache(
377 struct tu_device
*device
,
378 struct tu_pipeline_cache
*cache
,
379 const unsigned char *sha1
,
380 struct tu_shader_variant
**variants
);
383 tu_pipeline_cache_insert_shaders(struct tu_device
*device
,
384 struct tu_pipeline_cache
*cache
,
385 const unsigned char *sha1
,
386 struct tu_shader_variant
**variants
,
387 const void *const *codes
,
388 const unsigned *code_sizes
);
392 VkAllocationCallbacks alloc
;
394 struct tu_pipeline_cache cache
;
398 #define TU_QUEUE_GENERAL 0
400 #define TU_MAX_QUEUE_FAMILIES 1
404 VK_LOADER_DATA _loader_data
;
405 struct tu_device
*device
;
406 uint32_t queue_family_index
;
408 VkDeviceQueueCreateFlags flags
;
414 pthread_mutex_t mutex
;
419 VK_LOADER_DATA _loader_data
;
421 VkAllocationCallbacks alloc
;
423 struct tu_instance
*instance
;
424 struct radeon_winsys
*ws
;
426 struct tu_meta_state meta_state
;
428 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
429 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
431 struct tu_physical_device
*physical_device
;
433 /* Backup in-memory cache to be used if the app doesn't provide one */
434 struct tu_pipeline_cache
*mem_cache
;
436 struct list_head shader_slabs
;
437 mtx_t shader_slab_mutex
;
439 struct tu_device_extension_table enabled_extensions
;
441 /* Whether the driver uses a global BO list. */
442 bool use_global_bo_list
;
444 struct tu_bo_list bo_list
;
457 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
459 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
461 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
463 struct tu_device_memory
468 /* for dedicated allocations */
469 struct tu_image
*image
;
470 struct tu_buffer
*buffer
;
477 struct tu_descriptor_range
483 struct tu_descriptor_set
485 const struct tu_descriptor_set_layout
*layout
;
488 struct radeon_winsys_bo
*bo
;
490 uint32_t *mapped_ptr
;
491 struct tu_descriptor_range
*dynamic_descriptors
;
494 struct tu_push_descriptor_set
496 struct tu_descriptor_set set
;
500 struct tu_descriptor_pool_entry
504 struct tu_descriptor_set
*set
;
507 struct tu_descriptor_pool
509 struct radeon_winsys_bo
*bo
;
511 uint64_t current_offset
;
514 uint8_t *host_memory_base
;
515 uint8_t *host_memory_ptr
;
516 uint8_t *host_memory_end
;
518 uint32_t entry_count
;
519 uint32_t max_entry_count
;
520 struct tu_descriptor_pool_entry entries
[0];
523 struct tu_descriptor_update_template_entry
525 VkDescriptorType descriptor_type
;
527 /* The number of descriptors to update */
528 uint32_t descriptor_count
;
530 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
534 /* In dwords. Not valid/used for dynamic descriptors */
537 uint32_t buffer_offset
;
539 /* Only valid for combined image samplers and samplers */
540 uint16_t has_sampler
;
546 /* For push descriptors */
547 const uint32_t *immutable_samplers
;
550 struct tu_descriptor_update_template
552 uint32_t entry_count
;
553 VkPipelineBindPoint bind_point
;
554 struct tu_descriptor_update_template_entry entry
[0];
561 VkBufferUsageFlags usage
;
562 VkBufferCreateFlags flags
;
565 enum tu_dynamic_state_bits
567 TU_DYNAMIC_VIEWPORT
= 1 << 0,
568 TU_DYNAMIC_SCISSOR
= 1 << 1,
569 TU_DYNAMIC_LINE_WIDTH
= 1 << 2,
570 TU_DYNAMIC_DEPTH_BIAS
= 1 << 3,
571 TU_DYNAMIC_BLEND_CONSTANTS
= 1 << 4,
572 TU_DYNAMIC_DEPTH_BOUNDS
= 1 << 5,
573 TU_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6,
574 TU_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7,
575 TU_DYNAMIC_STENCIL_REFERENCE
= 1 << 8,
576 TU_DYNAMIC_DISCARD_RECTANGLE
= 1 << 9,
577 TU_DYNAMIC_ALL
= (1 << 10) - 1,
580 struct tu_vertex_binding
582 struct tu_buffer
*buffer
;
586 struct tu_viewport_state
589 VkViewport viewports
[MAX_VIEWPORTS
];
592 struct tu_scissor_state
595 VkRect2D scissors
[MAX_SCISSORS
];
598 struct tu_discard_rectangle_state
601 VkRect2D rectangles
[MAX_DISCARD_RECTANGLES
];
604 struct tu_dynamic_state
607 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
608 * Defines the set of saved dynamic state.
612 struct tu_viewport_state viewport
;
614 struct tu_scissor_state scissor
;
625 float blend_constants
[4];
637 } stencil_compare_mask
;
643 } stencil_write_mask
;
651 struct tu_discard_rectangle_state discard_rectangle
;
654 extern const struct tu_dynamic_state default_dynamic_state
;
657 tu_get_debug_option_name(int id
);
660 tu_get_perftest_option_name(int id
);
663 * Attachment state when recording a renderpass instance.
665 * The clear value is valid only if there exists a pending clear.
667 struct tu_attachment_state
669 VkImageAspectFlags pending_clear_aspects
;
670 uint32_t cleared_views
;
671 VkClearValue clear_value
;
672 VkImageLayout current_layout
;
675 struct tu_descriptor_state
677 struct tu_descriptor_set
*sets
[MAX_SETS
];
680 struct tu_push_descriptor_set push_set
;
682 uint32_t dynamic_buffers
[4 * MAX_DYNAMIC_BUFFERS
];
687 /* Vertex descriptors */
691 struct tu_dynamic_state dynamic
;
694 struct tu_buffer
*index_buffer
;
695 uint64_t index_offset
;
697 uint32_t max_index_count
;
703 VkAllocationCallbacks alloc
;
704 struct list_head cmd_buffers
;
705 struct list_head free_cmd_buffers
;
706 uint32_t queue_family_index
;
709 struct tu_cmd_buffer_upload
714 struct radeon_winsys_bo
*upload_bo
;
715 struct list_head list
;
718 enum tu_cmd_buffer_status
720 TU_CMD_BUFFER_STATUS_INVALID
,
721 TU_CMD_BUFFER_STATUS_INITIAL
,
722 TU_CMD_BUFFER_STATUS_RECORDING
,
723 TU_CMD_BUFFER_STATUS_EXECUTABLE
,
724 TU_CMD_BUFFER_STATUS_PENDING
,
729 VK_LOADER_DATA _loader_data
;
731 struct tu_device
*device
;
733 struct tu_cmd_pool
*pool
;
734 struct list_head pool_link
;
736 VkCommandBufferUsageFlags usage_flags
;
737 VkCommandBufferLevel level
;
738 enum tu_cmd_buffer_status status
;
739 struct radeon_cmdbuf
*cs
;
740 struct tu_cmd_state state
;
741 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
742 uint32_t queue_family_index
;
744 uint8_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
];
745 VkShaderStageFlags push_constant_stages
;
746 struct tu_descriptor_set meta_push_descriptors
;
748 struct tu_descriptor_state descriptors
[VK_PIPELINE_BIND_POINT_RANGE_SIZE
];
750 struct tu_cmd_buffer_upload upload
;
752 uint32_t scratch_size_needed
;
753 uint32_t compute_scratch_size_needed
;
754 uint32_t esgs_ring_size_needed
;
755 uint32_t gsvs_ring_size_needed
;
756 bool tess_rings_needed
;
757 bool sample_positions_needed
;
759 VkResult record_result
;
761 uint32_t gfx9_fence_offset
;
762 struct radeon_winsys_bo
*gfx9_fence_bo
;
763 uint32_t gfx9_fence_idx
;
764 uint64_t gfx9_eop_bug_va
;
767 * Whether a query pool has been resetted and we have to flush caches.
769 bool pending_reset_query
;
773 tu_get_memory_fd(struct tu_device
*device
,
774 struct tu_device_memory
*memory
,
778 * Takes x,y,z as exact numbers of invocations, instead of blocks.
780 * Limitations: Can't call normal dispatch functions without binding or
782 * the compute pipeline.
785 tu_unaligned_dispatch(struct tu_cmd_buffer
*cmd_buffer
,
792 struct radeon_winsys_bo
*bo
;
796 struct tu_shader_module
;
798 #define TU_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
799 #define TU_HASH_SHADER_SISCHED (1 << 1)
800 #define TU_HASH_SHADER_UNSAFE_MATH (1 << 2)
802 tu_hash_shaders(unsigned char *hash
,
803 const VkPipelineShaderStageCreateInfo
**stages
,
804 const struct tu_pipeline_layout
*layout
,
805 const struct tu_pipeline_key
*key
,
808 static inline gl_shader_stage
809 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
811 assert(__builtin_popcount(vk_stage
) == 1);
812 return ffs(vk_stage
) - 1;
815 static inline VkShaderStageFlagBits
816 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
818 return (1 << mesa_stage
);
821 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
823 #define tu_foreach_stage(stage, stage_bits) \
824 for (gl_shader_stage stage, \
825 __tmp = (gl_shader_stage)((stage_bits)&TU_STAGE_MASK); \
826 stage = __builtin_ffs(__tmp) - 1, __tmp; \
827 __tmp &= ~(1 << (stage)))
829 struct tu_shader_module
831 struct nir_shader
*nir
;
832 unsigned char sha1
[20];
839 struct tu_device
*device
;
840 struct tu_dynamic_state dynamic_state
;
842 struct tu_pipeline_layout
*layout
;
844 bool need_indirect_descriptor_sets
;
845 VkShaderStageFlags active_stages
;
848 struct tu_userdata_info
*
849 tu_lookup_user_sgpr(struct tu_pipeline
*pipeline
,
850 gl_shader_stage stage
,
853 struct tu_shader_variant
*
854 tu_get_shader(struct tu_pipeline
*pipeline
, gl_shader_stage stage
);
856 struct tu_graphics_pipeline_create_info
860 bool db_stencil_clear
;
861 bool db_depth_disable_expclear
;
862 bool db_stencil_disable_expclear
;
863 bool db_flush_depth_inplace
;
864 bool db_flush_stencil_inplace
;
866 uint32_t custom_blend_mode
;
870 tu_graphics_pipeline_create(
872 VkPipelineCache cache
,
873 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
874 const struct tu_graphics_pipeline_create_info
*extra
,
875 const VkAllocationCallbacks
*alloc
,
876 VkPipeline
*pPipeline
);
878 struct vk_format_description
;
880 tu_translate_buffer_dataformat(const struct vk_format_description
*desc
,
883 tu_translate_buffer_numformat(const struct vk_format_description
*desc
,
886 tu_translate_colorformat(VkFormat format
);
888 tu_translate_color_numformat(VkFormat format
,
889 const struct vk_format_description
*desc
,
892 tu_colorformat_endian_swap(uint32_t colorformat
);
894 tu_translate_colorswap(VkFormat format
, bool do_endian_swap
);
896 tu_translate_dbformat(VkFormat format
);
898 tu_translate_tex_dataformat(VkFormat format
,
899 const struct vk_format_description
*desc
,
902 tu_translate_tex_numformat(VkFormat format
,
903 const struct vk_format_description
*desc
,
906 tu_format_pack_clear_color(VkFormat format
,
907 uint32_t clear_vals
[2],
908 VkClearColorValue
*value
);
910 tu_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
);
912 tu_dcc_formats_compatible(VkFormat format1
, VkFormat format2
);
917 /* The original VkFormat provided by the client. This may not match any
918 * of the actual surface formats.
921 VkImageAspectFlags aspects
;
922 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
923 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
924 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
929 unsigned queue_family_mask
;
933 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
934 VkDeviceMemory owned_memory
;
938 tu_image_queue_family_mask(const struct tu_image
*image
,
940 uint32_t queue_family
);
942 static inline uint32_t
943 tu_get_layerCount(const struct tu_image
*image
,
944 const VkImageSubresourceRange
*range
)
949 static inline uint32_t
950 tu_get_levelCount(const struct tu_image
*image
,
951 const VkImageSubresourceRange
*range
)
958 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
960 VkImageViewType type
;
961 VkImageAspectFlags aspect_mask
;
964 uint32_t layer_count
;
966 uint32_t level_count
;
967 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
969 uint32_t descriptor
[16];
971 /* Descriptor for use as a storage image as opposed to a sampled image.
972 * This has a few differences for cube maps (e.g. type).
974 uint32_t storage_descriptor
[16];
981 struct tu_image_create_info
983 const VkImageCreateInfo
*vk_info
;
985 bool no_metadata_planes
;
989 tu_image_create(VkDevice _device
,
990 const struct tu_image_create_info
*info
,
991 const VkAllocationCallbacks
*alloc
,
995 tu_image_from_gralloc(VkDevice device_h
,
996 const VkImageCreateInfo
*base_info
,
997 const VkNativeBufferANDROID
*gralloc_info
,
998 const VkAllocationCallbacks
*alloc
,
999 VkImage
*out_image_h
);
1002 tu_image_view_init(struct tu_image_view
*view
,
1003 struct tu_device
*device
,
1004 const VkImageViewCreateInfo
*pCreateInfo
);
1006 struct tu_buffer_view
1008 struct radeon_winsys_bo
*bo
;
1010 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1014 tu_buffer_view_init(struct tu_buffer_view
*view
,
1015 struct tu_device
*device
,
1016 const VkBufferViewCreateInfo
*pCreateInfo
);
1018 static inline struct VkExtent3D
1019 tu_sanitize_image_extent(const VkImageType imageType
,
1020 const struct VkExtent3D imageExtent
)
1022 switch (imageType
) {
1023 case VK_IMAGE_TYPE_1D
:
1024 return (VkExtent3D
){ imageExtent
.width
, 1, 1 };
1025 case VK_IMAGE_TYPE_2D
:
1026 return (VkExtent3D
){ imageExtent
.width
, imageExtent
.height
, 1 };
1027 case VK_IMAGE_TYPE_3D
:
1030 unreachable("invalid image type");
1034 static inline struct VkOffset3D
1035 tu_sanitize_image_offset(const VkImageType imageType
,
1036 const struct VkOffset3D imageOffset
)
1038 switch (imageType
) {
1039 case VK_IMAGE_TYPE_1D
:
1040 return (VkOffset3D
){ imageOffset
.x
, 0, 0 };
1041 case VK_IMAGE_TYPE_2D
:
1042 return (VkOffset3D
){ imageOffset
.x
, imageOffset
.y
, 0 };
1043 case VK_IMAGE_TYPE_3D
:
1046 unreachable("invalid image type");
1050 struct tu_attachment_info
1052 struct tu_image_view
*attachment
;
1055 struct tu_framebuffer
1061 uint32_t attachment_count
;
1062 struct tu_attachment_info attachments
[0];
1065 struct tu_subpass_barrier
1067 VkPipelineStageFlags src_stage_mask
;
1068 VkAccessFlags src_access_mask
;
1069 VkAccessFlags dst_access_mask
;
1073 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
1074 const struct tu_subpass_barrier
*barrier
);
1076 struct tu_subpass_attachment
1078 uint32_t attachment
;
1079 VkImageLayout layout
;
1084 uint32_t input_count
;
1085 uint32_t color_count
;
1086 struct tu_subpass_attachment
*input_attachments
;
1087 struct tu_subpass_attachment
*color_attachments
;
1088 struct tu_subpass_attachment
*resolve_attachments
;
1089 struct tu_subpass_attachment depth_stencil_attachment
;
1091 /** Subpass has at least one resolve attachment */
1094 struct tu_subpass_barrier start_barrier
;
1097 VkSampleCountFlagBits max_sample_count
;
1100 struct tu_render_pass_attachment
1104 VkAttachmentLoadOp load_op
;
1105 VkAttachmentLoadOp stencil_load_op
;
1106 VkImageLayout initial_layout
;
1107 VkImageLayout final_layout
;
1111 struct tu_render_pass
1113 uint32_t attachment_count
;
1114 uint32_t subpass_count
;
1115 struct tu_subpass_attachment
*subpass_attachments
;
1116 struct tu_render_pass_attachment
*attachments
;
1117 struct tu_subpass_barrier end_barrier
;
1118 struct tu_subpass subpasses
[0];
1122 tu_device_init_meta(struct tu_device
*device
);
1124 tu_device_finish_meta(struct tu_device
*device
);
1126 struct tu_query_pool
1128 struct radeon_winsys_bo
*bo
;
1130 uint32_t availability_offset
;
1134 uint32_t pipeline_stats_mask
;
1139 /* use a winsys sem for non-exportable */
1140 struct radeon_winsys_sem
*sem
;
1142 uint32_t temp_syncobj
;
1146 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1147 VkPipelineBindPoint bind_point
,
1148 struct tu_descriptor_set
*set
,
1152 tu_update_descriptor_sets(struct tu_device
*device
,
1153 struct tu_cmd_buffer
*cmd_buffer
,
1154 VkDescriptorSet overrideSet
,
1155 uint32_t descriptorWriteCount
,
1156 const VkWriteDescriptorSet
*pDescriptorWrites
,
1157 uint32_t descriptorCopyCount
,
1158 const VkCopyDescriptorSet
*pDescriptorCopies
);
1161 tu_update_descriptor_set_with_template(
1162 struct tu_device
*device
,
1163 struct tu_cmd_buffer
*cmd_buffer
,
1164 struct tu_descriptor_set
*set
,
1165 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate
,
1169 tu_meta_push_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1170 VkPipelineBindPoint pipelineBindPoint
,
1171 VkPipelineLayout _layout
,
1173 uint32_t descriptorWriteCount
,
1174 const VkWriteDescriptorSet
*pDescriptorWrites
);
1178 struct radeon_winsys_fence
*fence
;
1183 uint32_t temp_syncobj
;
1186 /* tu_nir_to_llvm.c */
1187 struct tu_shader_variant_info
;
1188 struct tu_nir_compiler_options
;
1190 struct radeon_winsys_sem
;
1193 tu_gem_new(struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1195 tu_gem_close(struct tu_device
*dev
, uint32_t gem_handle
);
1197 tu_gem_info_offset(struct tu_device
*dev
, uint32_t gem_handle
);
1199 tu_gem_info_iova(struct tu_device
*dev
, uint32_t gem_handle
);
1201 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1203 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1205 return (struct __tu_type *)_handle; \
1208 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1210 return (__VkType)_obj; \
1213 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1215 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1217 return (struct __tu_type *)(uintptr_t)_handle; \
1220 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1222 return (__VkType)(uintptr_t)_obj; \
1225 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1226 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1228 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1229 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1230 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1231 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1232 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1234 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1235 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1236 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1237 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1238 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1239 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1240 VkDescriptorSetLayout
)
1241 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1242 VkDescriptorUpdateTemplateKHR
)
1243 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1244 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1245 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1246 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1247 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1248 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1249 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1250 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1251 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1252 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1253 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1254 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1255 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1256 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1258 #endif /* TU_PRIVATE_H */