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 "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
108 TU_MEM_HEAP_VRAM_CPU_ACCESS
,
116 TU_MEM_TYPE_GTT_WRITE_COMBINE
,
117 TU_MEM_TYPE_VRAM_CPU_ACCESS
,
118 TU_MEM_TYPE_GTT_CACHED
,
122 #define tu_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
124 static inline uint32_t
125 align_u32(uint32_t v
, uint32_t a
)
127 assert(a
!= 0 && a
== (a
& -a
));
128 return (v
+ a
- 1) & ~(a
- 1);
131 static inline uint32_t
132 align_u32_npot(uint32_t v
, uint32_t a
)
134 return (v
+ a
- 1) / a
* a
;
137 static inline uint64_t
138 align_u64(uint64_t v
, uint64_t a
)
140 assert(a
!= 0 && a
== (a
& -a
));
141 return (v
+ a
- 1) & ~(a
- 1);
144 static inline int32_t
145 align_i32(int32_t v
, int32_t a
)
147 assert(a
!= 0 && a
== (a
& -a
));
148 return (v
+ a
- 1) & ~(a
- 1);
151 /** Alignment must be a power of 2. */
153 tu_is_aligned(uintmax_t n
, uintmax_t a
)
155 assert(a
== (a
& -a
));
156 return (n
& (a
- 1)) == 0;
159 static inline uint32_t
160 round_up_u32(uint32_t v
, uint32_t a
)
162 return (v
+ a
- 1) / a
;
165 static inline uint64_t
166 round_up_u64(uint64_t v
, uint64_t a
)
168 return (v
+ a
- 1) / a
;
171 static inline uint32_t
172 tu_minify(uint32_t n
, uint32_t levels
)
174 if (unlikely(n
== 0))
177 return MAX2(n
>> levels
, 1);
180 tu_clamp_f(float f
, float min
, float max
)
193 tu_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
195 if (*inout_mask
& clear_mask
) {
196 *inout_mask
&= ~clear_mask
;
203 #define for_each_bit(b, dword) \
204 for (uint32_t __dword = (dword); \
205 (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b)))
207 #define typed_memcpy(dest, src, count) \
209 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
210 memcpy((dest), (src), (count) * sizeof(*(src))); \
213 /* Whenever we generate an error, pass it through this function. Useful for
214 * debugging, where we can break on it. Only call at error site, not when
215 * propagating errors. Might be useful to plug in a stack trace here.
221 __vk_errorf(struct tu_instance
*instance
,
228 #define vk_error(instance, error) \
229 __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
230 #define vk_errorf(instance, error, format, ...) \
231 __vk_errorf(instance, error, __FILE__, __LINE__, format, ##__VA_ARGS__);
234 __tu_finishme(const char *file
, int line
, const char *format
, ...)
237 tu_loge(const char *format
, ...) tu_printflike(1, 2);
239 tu_loge_v(const char *format
, va_list va
);
241 tu_logi(const char *format
, ...) tu_printflike(1, 2);
243 tu_logi_v(const char *format
, va_list va
);
246 * Print a FINISHME message, including its source location.
248 #define tu_finishme(format, ...) \
250 static bool reported = false; \
252 __tu_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
257 /* A non-fatal assert. Useful for debugging. */
259 #define tu_assert(x) \
261 if (unlikely(!(x))) \
262 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
268 /* Suppress -Wunused in stub functions */
269 #define tu_use_args(...) __tu_use_args(0, ##__VA_ARGS__)
271 __tu_use_args(int ignore
, ...)
277 tu_finishme("stub %s", __func__); \
281 tu_lookup_entrypoint_unchecked(const char *name
);
283 tu_lookup_entrypoint_checked(
285 uint32_t core_version
,
286 const struct tu_instance_extension_table
*instance
,
287 const struct tu_device_extension_table
*device
);
289 struct tu_physical_device
291 VK_LOADER_DATA _loader_data
;
293 struct tu_instance
*instance
;
296 char name
[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
];
297 uint8_t driver_uuid
[VK_UUID_SIZE
];
298 uint8_t device_uuid
[VK_UUID_SIZE
];
299 uint8_t cache_uuid
[VK_UUID_SIZE
];
306 uint32_t tile_align_w
;
307 uint32_t tile_align_h
;
309 /* This is the drivers on-disk cache used as a fallback as opposed to
310 * the pipeline cache defined by apps.
312 struct disk_cache
*disk_cache
;
314 struct tu_device_extension_table supported_extensions
;
319 TU_DEBUG_STARTUP
= 1 << 0,
320 TU_DEBUG_NIR
= 1 << 1,
321 TU_DEBUG_IR3
= 1 << 2,
326 VK_LOADER_DATA _loader_data
;
328 VkAllocationCallbacks alloc
;
330 uint32_t api_version
;
331 int physical_device_count
;
332 struct tu_physical_device physical_devices
[TU_MAX_DRM_DEVICES
];
334 enum tu_debug_flags debug_flags
;
336 struct vk_debug_report_instance debug_report_callbacks
;
338 struct tu_instance_extension_table enabled_extensions
;
342 tu_instance_extension_supported(const char *name
);
344 tu_physical_device_api_version(struct tu_physical_device
*dev
);
346 tu_physical_device_extension_supported(struct tu_physical_device
*dev
,
351 struct tu_pipeline_cache
353 struct tu_device
*device
;
354 pthread_mutex_t mutex
;
358 uint32_t kernel_count
;
359 struct cache_entry
**hash_table
;
362 VkAllocationCallbacks alloc
;
365 struct tu_pipeline_key
370 tu_pipeline_cache_init(struct tu_pipeline_cache
*cache
,
371 struct tu_device
*device
);
373 tu_pipeline_cache_finish(struct tu_pipeline_cache
*cache
);
375 tu_pipeline_cache_load(struct tu_pipeline_cache
*cache
,
379 struct tu_shader_variant
;
382 tu_create_shader_variants_from_pipeline_cache(
383 struct tu_device
*device
,
384 struct tu_pipeline_cache
*cache
,
385 const unsigned char *sha1
,
386 struct tu_shader_variant
**variants
);
389 tu_pipeline_cache_insert_shaders(struct tu_device
*device
,
390 struct tu_pipeline_cache
*cache
,
391 const unsigned char *sha1
,
392 struct tu_shader_variant
**variants
,
393 const void *const *codes
,
394 const unsigned *code_sizes
);
398 VkAllocationCallbacks alloc
;
400 struct tu_pipeline_cache cache
;
404 #define TU_QUEUE_GENERAL 0
406 #define TU_MAX_QUEUE_FAMILIES 1
415 tu_fence_init(struct tu_fence
*fence
, bool signaled
);
417 tu_fence_finish(struct tu_fence
*fence
);
419 tu_fence_update_fd(struct tu_fence
*fence
, int fd
);
421 tu_fence_copy(struct tu_fence
*fence
, const struct tu_fence
*src
);
423 tu_fence_signal(struct tu_fence
*fence
);
425 tu_fence_wait_idle(struct tu_fence
*fence
);
429 VK_LOADER_DATA _loader_data
;
430 struct tu_device
*device
;
431 uint32_t queue_family_index
;
433 VkDeviceQueueCreateFlags flags
;
435 uint32_t msm_queue_id
;
436 struct tu_fence submit_fence
;
441 VK_LOADER_DATA _loader_data
;
443 VkAllocationCallbacks alloc
;
445 struct tu_instance
*instance
;
447 struct tu_meta_state meta_state
;
449 struct tu_queue
*queues
[TU_MAX_QUEUE_FAMILIES
];
450 int queue_count
[TU_MAX_QUEUE_FAMILIES
];
452 struct tu_physical_device
*physical_device
;
454 struct ir3_compiler
*compiler
;
456 /* Backup in-memory cache to be used if the app doesn't provide one */
457 struct tu_pipeline_cache
*mem_cache
;
459 struct list_head shader_slabs
;
460 mtx_t shader_slab_mutex
;
462 struct tu_device_extension_table enabled_extensions
;
474 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
);
476 tu_bo_init_dmabuf(struct tu_device
*dev
,
481 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
);
483 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
);
485 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
);
490 const struct tu_bo
*bo
;
500 * A command stream in TU_CS_MODE_GROW mode grows automatically whenever it
501 * is full. tu_cs_begin must be called before command packet emission and
502 * tu_cs_end must be called after.
504 * This mode may create multiple entries internally. The entries must be
505 * submitted together.
510 * A command stream in TU_CS_MODE_EXTERNAL mode wraps an external,
511 * fixed-size buffer. tu_cs_begin and tu_cs_end are optional and have no
514 * This mode does not create any entry or any BO.
519 * A command stream in TU_CS_MODE_SUB_STREAM mode does not support direct
520 * command packet emission. tu_cs_begin_sub_stream must be called to get a
521 * sub-stream to emit comamnd packets to. When done with the sub-stream,
522 * tu_cs_end_sub_stream must be called.
524 * This mode does not create any entry internally.
526 TU_CS_MODE_SUB_STREAM
,
533 uint32_t *reserved_end
;
536 enum tu_cs_mode mode
;
537 uint32_t next_bo_size
;
539 struct tu_cs_entry
*entries
;
540 uint32_t entry_count
;
541 uint32_t entry_capacity
;
545 uint32_t bo_capacity
;
548 struct tu_device_memory
553 /* for dedicated allocations */
554 struct tu_image
*image
;
555 struct tu_buffer
*buffer
;
562 struct tu_descriptor_range
568 struct tu_descriptor_set
570 const struct tu_descriptor_set_layout
*layout
;
574 uint32_t *mapped_ptr
;
575 struct tu_descriptor_range
*dynamic_descriptors
;
578 struct tu_push_descriptor_set
580 struct tu_descriptor_set set
;
584 struct tu_descriptor_pool_entry
588 struct tu_descriptor_set
*set
;
591 struct tu_descriptor_pool
594 uint64_t current_offset
;
597 uint8_t *host_memory_base
;
598 uint8_t *host_memory_ptr
;
599 uint8_t *host_memory_end
;
601 uint32_t entry_count
;
602 uint32_t max_entry_count
;
603 struct tu_descriptor_pool_entry entries
[0];
606 struct tu_descriptor_update_template_entry
608 VkDescriptorType descriptor_type
;
610 /* The number of descriptors to update */
611 uint32_t descriptor_count
;
613 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array
617 /* In dwords. Not valid/used for dynamic descriptors */
620 uint32_t buffer_offset
;
622 /* Only valid for combined image samplers and samplers */
623 uint16_t has_sampler
;
629 /* For push descriptors */
630 const uint32_t *immutable_samplers
;
633 struct tu_descriptor_update_template
635 uint32_t entry_count
;
636 VkPipelineBindPoint bind_point
;
637 struct tu_descriptor_update_template_entry entry
[0];
644 VkBufferUsageFlags usage
;
645 VkBufferCreateFlags flags
;
648 VkDeviceSize bo_offset
;
651 enum tu_dynamic_state_bits
653 TU_DYNAMIC_VIEWPORT
= 1 << 0,
654 TU_DYNAMIC_SCISSOR
= 1 << 1,
655 TU_DYNAMIC_LINE_WIDTH
= 1 << 2,
656 TU_DYNAMIC_DEPTH_BIAS
= 1 << 3,
657 TU_DYNAMIC_BLEND_CONSTANTS
= 1 << 4,
658 TU_DYNAMIC_DEPTH_BOUNDS
= 1 << 5,
659 TU_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6,
660 TU_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7,
661 TU_DYNAMIC_STENCIL_REFERENCE
= 1 << 8,
662 TU_DYNAMIC_DISCARD_RECTANGLE
= 1 << 9,
663 TU_DYNAMIC_ALL
= (1 << 10) - 1,
666 struct tu_vertex_binding
668 struct tu_buffer
*buffer
;
672 struct tu_viewport_state
675 VkViewport viewports
[MAX_VIEWPORTS
];
678 struct tu_scissor_state
681 VkRect2D scissors
[MAX_SCISSORS
];
684 struct tu_discard_rectangle_state
687 VkRect2D rectangles
[MAX_DISCARD_RECTANGLES
];
690 struct tu_dynamic_state
693 * Bitmask of (1 << VK_DYNAMIC_STATE_*).
694 * Defines the set of saved dynamic state.
698 struct tu_viewport_state viewport
;
700 struct tu_scissor_state scissor
;
711 float blend_constants
[4];
723 } stencil_compare_mask
;
729 } stencil_write_mask
;
737 struct tu_discard_rectangle_state discard_rectangle
;
740 extern const struct tu_dynamic_state default_dynamic_state
;
743 tu_get_debug_option_name(int id
);
746 tu_get_perftest_option_name(int id
);
749 * Attachment state when recording a renderpass instance.
751 * The clear value is valid only if there exists a pending clear.
753 struct tu_attachment_state
755 VkImageAspectFlags pending_clear_aspects
;
756 uint32_t cleared_views
;
757 VkClearValue clear_value
;
758 VkImageLayout current_layout
;
761 struct tu_descriptor_state
763 struct tu_descriptor_set
*sets
[MAX_SETS
];
766 struct tu_push_descriptor_set push_set
;
768 uint32_t dynamic_buffers
[4 * MAX_DYNAMIC_BUFFERS
];
779 struct tu_tiling_config
781 VkRect2D render_area
;
782 uint32_t buffer_cpp
[MAX_RTS
+ 2];
783 uint32_t buffer_count
;
785 /* position and size of the first tile */
787 /* number of tiles */
788 VkExtent2D tile_count
;
790 uint32_t gmem_offsets
[MAX_RTS
+ 2];
792 /* size of the first VSC pipe */
794 /* number of VSC pipes */
795 VkExtent2D pipe_count
;
797 /* pipe register values */
798 uint32_t pipe_config
[MAX_VSC_PIPES
];
799 uint32_t pipe_sizes
[MAX_VSC_PIPES
];
804 /* Vertex descriptors */
808 struct tu_dynamic_state dynamic
;
811 struct tu_buffer
*index_buffer
;
812 uint64_t index_offset
;
814 uint32_t max_index_count
;
817 const struct tu_render_pass
*pass
;
818 const struct tu_subpass
*subpass
;
819 const struct tu_framebuffer
*framebuffer
;
820 struct tu_attachment_state
*attachments
;
822 struct tu_tiling_config tiling_config
;
824 struct tu_cs_entry tile_load_ib
;
825 struct tu_cs_entry tile_store_ib
;
830 VkAllocationCallbacks alloc
;
831 struct list_head cmd_buffers
;
832 struct list_head free_cmd_buffers
;
833 uint32_t queue_family_index
;
836 struct tu_cmd_buffer_upload
841 struct list_head list
;
844 enum tu_cmd_buffer_status
846 TU_CMD_BUFFER_STATUS_INVALID
,
847 TU_CMD_BUFFER_STATUS_INITIAL
,
848 TU_CMD_BUFFER_STATUS_RECORDING
,
849 TU_CMD_BUFFER_STATUS_EXECUTABLE
,
850 TU_CMD_BUFFER_STATUS_PENDING
,
857 struct drm_msm_gem_submit_bo
*bo_infos
;
860 #define TU_BO_LIST_FAILED (~0)
863 tu_bo_list_init(struct tu_bo_list
*list
);
865 tu_bo_list_destroy(struct tu_bo_list
*list
);
867 tu_bo_list_reset(struct tu_bo_list
*list
);
869 tu_bo_list_add(struct tu_bo_list
*list
,
870 const struct tu_bo
*bo
,
873 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
);
877 VK_LOADER_DATA _loader_data
;
879 struct tu_device
*device
;
881 struct tu_cmd_pool
*pool
;
882 struct list_head pool_link
;
884 VkCommandBufferUsageFlags usage_flags
;
885 VkCommandBufferLevel level
;
886 enum tu_cmd_buffer_status status
;
888 struct tu_cmd_state state
;
889 struct tu_vertex_binding vertex_bindings
[MAX_VBS
];
890 uint32_t queue_family_index
;
892 uint8_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
];
893 VkShaderStageFlags push_constant_stages
;
894 struct tu_descriptor_set meta_push_descriptors
;
896 struct tu_descriptor_state descriptors
[VK_PIPELINE_BIND_POINT_RANGE_SIZE
];
898 struct tu_cmd_buffer_upload upload
;
900 VkResult record_result
;
902 struct tu_bo_list bo_list
;
904 struct tu_cs tile_cs
;
907 uint32_t marker_seqno
;
909 struct tu_bo scratch_bo
;
910 uint32_t scratch_seqno
;
916 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
918 enum vgt_event_type event
,
922 tu_get_memory_fd(struct tu_device
*device
,
923 struct tu_device_memory
*memory
,
927 * Takes x,y,z as exact numbers of invocations, instead of blocks.
929 * Limitations: Can't call normal dispatch functions without binding or
931 * the compute pipeline.
934 tu_unaligned_dispatch(struct tu_cmd_buffer
*cmd_buffer
,
944 struct tu_shader_module
;
946 #define TU_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
947 #define TU_HASH_SHADER_SISCHED (1 << 1)
948 #define TU_HASH_SHADER_UNSAFE_MATH (1 << 2)
950 tu_hash_shaders(unsigned char *hash
,
951 const VkPipelineShaderStageCreateInfo
**stages
,
952 const struct tu_pipeline_layout
*layout
,
953 const struct tu_pipeline_key
*key
,
956 static inline gl_shader_stage
957 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
959 assert(__builtin_popcount(vk_stage
) == 1);
960 return ffs(vk_stage
) - 1;
963 static inline VkShaderStageFlagBits
964 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
966 return (1 << mesa_stage
);
969 #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
971 #define tu_foreach_stage(stage, stage_bits) \
972 for (gl_shader_stage stage, \
973 __tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
974 stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
976 struct tu_shader_module
978 unsigned char sha1
[20];
981 const uint32_t *code
[0];
984 struct tu_shader_compile_options
986 struct ir3_shader_key key
;
989 bool include_binning_pass
;
994 struct ir3_shader ir3_shader
;
996 /* This may be true for vertex shaders. When true, variants[1] is the
997 * binning variant and binning_binary is non-NULL.
999 bool has_binning_pass
;
1002 void *binning_binary
;
1004 struct ir3_shader_variant variants
[0];
1008 tu_shader_create(struct tu_device
*dev
,
1009 gl_shader_stage stage
,
1010 const VkPipelineShaderStageCreateInfo
*stage_info
,
1011 const VkAllocationCallbacks
*alloc
);
1014 tu_shader_destroy(struct tu_device
*dev
,
1015 struct tu_shader
*shader
,
1016 const VkAllocationCallbacks
*alloc
);
1019 tu_shader_compile_options_init(
1020 struct tu_shader_compile_options
*options
,
1021 const VkGraphicsPipelineCreateInfo
*pipeline_info
);
1024 tu_shader_compile(struct tu_device
*dev
,
1025 struct tu_shader
*shader
,
1026 const struct tu_shader
*next_stage
,
1027 const struct tu_shader_compile_options
*options
,
1028 const VkAllocationCallbacks
*alloc
);
1034 struct tu_dynamic_state dynamic_state
;
1036 struct tu_pipeline_layout
*layout
;
1038 bool need_indirect_descriptor_sets
;
1039 VkShaderStageFlags active_stages
;
1043 struct tu_bo binary_bo
;
1048 enum pc_di_primtype primtype
;
1049 bool primitive_restart
;
1054 struct tu_cs_entry state_ib
;
1059 uint32_t gras_su_cntl
;
1060 struct tu_cs_entry state_ib
;
1065 struct tu_cs_entry state_ib
;
1070 struct tu_cs_entry state_ib
;
1075 tu6_emit_viewport(struct tu_cs
*cs
, const VkViewport
*viewport
);
1078 tu6_emit_scissor(struct tu_cs
*cs
, const VkRect2D
*scissor
);
1081 tu6_emit_gras_su_cntl(struct tu_cs
*cs
,
1082 uint32_t gras_su_cntl
,
1086 tu6_emit_depth_bias(struct tu_cs
*cs
,
1087 float constant_factor
,
1089 float slope_factor
);
1092 tu6_emit_stencil_compare_mask(struct tu_cs
*cs
,
1097 tu6_emit_stencil_write_mask(struct tu_cs
*cs
, uint32_t front
, uint32_t back
);
1100 tu6_emit_stencil_reference(struct tu_cs
*cs
, uint32_t front
, uint32_t back
);
1103 tu6_emit_blend_constants(struct tu_cs
*cs
, const float constants
[4]);
1105 struct tu_userdata_info
*
1106 tu_lookup_user_sgpr(struct tu_pipeline
*pipeline
,
1107 gl_shader_stage stage
,
1110 struct tu_shader_variant
*
1111 tu_get_shader(struct tu_pipeline
*pipeline
, gl_shader_stage stage
);
1113 struct tu_graphics_pipeline_create_info
1116 bool db_depth_clear
;
1117 bool db_stencil_clear
;
1118 bool db_depth_disable_expclear
;
1119 bool db_stencil_disable_expclear
;
1120 bool db_flush_depth_inplace
;
1121 bool db_flush_stencil_inplace
;
1122 bool db_resummarize
;
1123 uint32_t custom_blend_mode
;
1126 struct tu_native_format
1128 int vtx
; /* VFMTn_xxx or -1 */
1129 int tex
; /* TFMTn_xxx or -1 */
1130 int rb
; /* RBn_xxx or -1 */
1131 int swap
; /* enum a3xx_color_swap */
1132 bool present
; /* internal only; always true to external users */
1135 const struct tu_native_format
*
1136 tu6_get_native_format(VkFormat format
);
1139 tu_pack_clear_value(const VkClearValue
*val
,
1142 enum a6xx_2d_ifmt
tu6_rb_fmt_to_ifmt(enum a6xx_color_fmt fmt
);
1144 struct tu_image_level
1146 VkDeviceSize offset
;
1154 /* The original VkFormat provided by the client. This may not match any
1155 * of the actual surface formats.
1158 VkImageAspectFlags aspects
;
1159 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1160 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1161 VkImageCreateFlags flags
; /** VkImageCreateInfo::flags */
1163 uint32_t level_count
;
1164 uint32_t layer_count
;
1170 VkDeviceSize layer_size
;
1171 struct tu_image_level levels
[15];
1174 unsigned queue_family_mask
;
1178 /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
1179 VkDeviceMemory owned_memory
;
1181 /* Set when bound */
1182 const struct tu_bo
*bo
;
1183 VkDeviceSize bo_offset
;
1187 tu_image_queue_family_mask(const struct tu_image
*image
,
1189 uint32_t queue_family
);
1191 static inline uint32_t
1192 tu_get_layerCount(const struct tu_image
*image
,
1193 const VkImageSubresourceRange
*range
)
1195 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
1196 ? image
->layer_count
- range
->baseArrayLayer
1197 : range
->layerCount
;
1200 static inline uint32_t
1201 tu_get_levelCount(const struct tu_image
*image
,
1202 const VkImageSubresourceRange
*range
)
1204 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
1205 ? image
->level_count
- range
->baseMipLevel
1206 : range
->levelCount
;
1209 struct tu_image_view
1211 struct tu_image
*image
; /**< VkImageViewCreateInfo::image */
1213 VkImageViewType type
;
1214 VkImageAspectFlags aspect_mask
;
1216 uint32_t base_layer
;
1217 uint32_t layer_count
;
1219 uint32_t level_count
;
1220 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1222 uint32_t descriptor
[16];
1224 /* Descriptor for use as a storage image as opposed to a sampled image.
1225 * This has a few differences for cube maps (e.g. type).
1227 uint32_t storage_descriptor
[16];
1234 struct tu_image_create_info
1236 const VkImageCreateInfo
*vk_info
;
1238 bool no_metadata_planes
;
1242 tu_image_create(VkDevice _device
,
1243 const struct tu_image_create_info
*info
,
1244 const VkAllocationCallbacks
*alloc
,
1248 tu_image_from_gralloc(VkDevice device_h
,
1249 const VkImageCreateInfo
*base_info
,
1250 const VkNativeBufferANDROID
*gralloc_info
,
1251 const VkAllocationCallbacks
*alloc
,
1252 VkImage
*out_image_h
);
1255 tu_image_view_init(struct tu_image_view
*view
,
1256 struct tu_device
*device
,
1257 const VkImageViewCreateInfo
*pCreateInfo
);
1259 struct tu_buffer_view
1262 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1266 tu_buffer_view_init(struct tu_buffer_view
*view
,
1267 struct tu_device
*device
,
1268 const VkBufferViewCreateInfo
*pCreateInfo
);
1270 static inline struct VkExtent3D
1271 tu_sanitize_image_extent(const VkImageType imageType
,
1272 const struct VkExtent3D imageExtent
)
1274 switch (imageType
) {
1275 case VK_IMAGE_TYPE_1D
:
1276 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1277 case VK_IMAGE_TYPE_2D
:
1278 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1279 case VK_IMAGE_TYPE_3D
:
1282 unreachable("invalid image type");
1286 static inline struct VkOffset3D
1287 tu_sanitize_image_offset(const VkImageType imageType
,
1288 const struct VkOffset3D imageOffset
)
1290 switch (imageType
) {
1291 case VK_IMAGE_TYPE_1D
:
1292 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1293 case VK_IMAGE_TYPE_2D
:
1294 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1295 case VK_IMAGE_TYPE_3D
:
1298 unreachable("invalid image type");
1302 struct tu_attachment_info
1304 struct tu_image_view
*attachment
;
1307 struct tu_framebuffer
1313 uint32_t attachment_count
;
1314 struct tu_attachment_info attachments
[0];
1317 struct tu_subpass_barrier
1319 VkPipelineStageFlags src_stage_mask
;
1320 VkAccessFlags src_access_mask
;
1321 VkAccessFlags dst_access_mask
;
1325 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
1326 const struct tu_subpass_barrier
*barrier
);
1328 struct tu_subpass_attachment
1330 uint32_t attachment
;
1331 VkImageLayout layout
;
1336 uint32_t input_count
;
1337 uint32_t color_count
;
1338 struct tu_subpass_attachment
*input_attachments
;
1339 struct tu_subpass_attachment
*color_attachments
;
1340 struct tu_subpass_attachment
*resolve_attachments
;
1341 struct tu_subpass_attachment depth_stencil_attachment
;
1343 /** Subpass has at least one resolve attachment */
1346 struct tu_subpass_barrier start_barrier
;
1349 VkSampleCountFlagBits max_sample_count
;
1352 struct tu_render_pass_attachment
1356 VkAttachmentLoadOp load_op
;
1357 VkAttachmentLoadOp stencil_load_op
;
1358 VkImageLayout initial_layout
;
1359 VkImageLayout final_layout
;
1363 struct tu_render_pass
1365 uint32_t attachment_count
;
1366 uint32_t subpass_count
;
1367 struct tu_subpass_attachment
*subpass_attachments
;
1368 struct tu_render_pass_attachment
*attachments
;
1369 struct tu_subpass_barrier end_barrier
;
1370 struct tu_subpass subpasses
[0];
1374 tu_device_init_meta(struct tu_device
*device
);
1376 tu_device_finish_meta(struct tu_device
*device
);
1378 struct tu_query_pool
1381 uint32_t availability_offset
;
1385 uint32_t pipeline_stats_mask
;
1391 uint32_t temp_syncobj
;
1395 tu_set_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1396 VkPipelineBindPoint bind_point
,
1397 struct tu_descriptor_set
*set
,
1401 tu_update_descriptor_sets(struct tu_device
*device
,
1402 struct tu_cmd_buffer
*cmd_buffer
,
1403 VkDescriptorSet overrideSet
,
1404 uint32_t descriptorWriteCount
,
1405 const VkWriteDescriptorSet
*pDescriptorWrites
,
1406 uint32_t descriptorCopyCount
,
1407 const VkCopyDescriptorSet
*pDescriptorCopies
);
1410 tu_update_descriptor_set_with_template(
1411 struct tu_device
*device
,
1412 struct tu_cmd_buffer
*cmd_buffer
,
1413 struct tu_descriptor_set
*set
,
1414 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate
,
1418 tu_meta_push_descriptor_set(struct tu_cmd_buffer
*cmd_buffer
,
1419 VkPipelineBindPoint pipelineBindPoint
,
1420 VkPipelineLayout _layout
,
1422 uint32_t descriptorWriteCount
,
1423 const VkWriteDescriptorSet
*pDescriptorWrites
);
1426 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
);
1429 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
);
1432 tu_drm_submitqueue_new(const struct tu_device
*dev
,
1434 uint32_t *queue_id
);
1437 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
);
1440 tu_gem_new(const struct tu_device
*dev
, uint64_t size
, uint32_t flags
);
1442 tu_gem_import_dmabuf(const struct tu_device
*dev
,
1446 tu_gem_export_dmabuf(const struct tu_device
*dev
, uint32_t gem_handle
);
1448 tu_gem_close(const struct tu_device
*dev
, uint32_t gem_handle
);
1450 tu_gem_info_offset(const struct tu_device
*dev
, uint32_t gem_handle
);
1452 tu_gem_info_iova(const struct tu_device
*dev
, uint32_t gem_handle
);
1454 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
1456 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1458 return (struct __tu_type *) _handle; \
1461 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1463 return (__VkType) _obj; \
1466 #define TU_DEFINE_NONDISP_HANDLE_CASTS(__tu_type, __VkType) \
1468 static inline struct __tu_type *__tu_type##_from_handle(__VkType _handle) \
1470 return (struct __tu_type *) (uintptr_t) _handle; \
1473 static inline __VkType __tu_type##_to_handle(struct __tu_type *_obj) \
1475 return (__VkType)(uintptr_t) _obj; \
1478 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \
1479 struct __tu_type *__name = __tu_type##_from_handle(__handle)
1481 TU_DEFINE_HANDLE_CASTS(tu_cmd_buffer
, VkCommandBuffer
)
1482 TU_DEFINE_HANDLE_CASTS(tu_device
, VkDevice
)
1483 TU_DEFINE_HANDLE_CASTS(tu_instance
, VkInstance
)
1484 TU_DEFINE_HANDLE_CASTS(tu_physical_device
, VkPhysicalDevice
)
1485 TU_DEFINE_HANDLE_CASTS(tu_queue
, VkQueue
)
1487 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_cmd_pool
, VkCommandPool
)
1488 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer
, VkBuffer
)
1489 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view
, VkBufferView
)
1490 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_pool
, VkDescriptorPool
)
1491 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set
, VkDescriptorSet
)
1492 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout
,
1493 VkDescriptorSetLayout
)
1494 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template
,
1495 VkDescriptorUpdateTemplateKHR
)
1496 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory
, VkDeviceMemory
)
1497 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence
, VkFence
)
1498 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event
, VkEvent
)
1499 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer
, VkFramebuffer
)
1500 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image
, VkImage
)
1501 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view
, VkImageView
);
1502 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache
, VkPipelineCache
)
1503 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline
, VkPipeline
)
1504 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_layout
, VkPipelineLayout
)
1505 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool
, VkQueryPool
)
1506 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass
, VkRenderPass
)
1507 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler
, VkSampler
)
1508 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module
, VkShaderModule
)
1509 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_semaphore
, VkSemaphore
)
1511 #endif /* TU_PRIVATE_H */