Halide 18.0.0
Halide compiler and libraries
 
Loading...
Searching...
No Matches
vulkan_internal.h
Go to the documentation of this file.
1#ifndef HALIDE_RUNTIME_VULKAN_INTERNAL_H
2#define HALIDE_RUNTIME_VULKAN_INTERNAL_H
3
5#include "printer.h"
6#include "runtime_internal.h"
7#include "scoped_spin_lock.h"
8
14
15#include "vulkan_interface.h"
16
17// --
18
19namespace Halide {
20namespace Runtime {
21namespace Internal {
22namespace Vulkan {
23
24// Declarations
28
29// --------------------------------------------------------------------------
30
31namespace { // internalize
32
33// --------------------------------------------------------------------------
34// Memory
35// --------------------------------------------------------------------------
36void *vk_host_malloc(void *user_context, size_t size, size_t alignment, VkSystemAllocationScope scope, const VkAllocationCallbacks *callbacks = nullptr);
37void vk_host_free(void *user_context, void *ptr, const VkAllocationCallbacks *callbacks = nullptr);
38int vk_device_crop_from_offset(void *user_context, const struct halide_buffer_t *src, int64_t offset, struct halide_buffer_t *dst);
39VulkanMemoryAllocator *vk_create_memory_allocator(void *user_context, VkDevice device, VkPhysicalDevice physical_device,
40 const VkAllocationCallbacks *alloc_callbacks);
41
42int vk_destroy_memory_allocator(void *user_context, VulkanMemoryAllocator *allocator);
43int vk_clear_device_buffer(void *user_context,
44 VulkanMemoryAllocator *allocator,
45 VkCommandPool command_pool,
46 VkQueue command_queue,
47 VkBuffer device_buffer);
48// --------------------------------------------------------------------------
49// Context
50// --------------------------------------------------------------------------
51
52int vk_create_context(
53 void *user_context,
54 VulkanMemoryAllocator **allocator,
55 VkInstance *instance,
56 VkDevice *device,
57 VkPhysicalDevice *physical_device,
58 VkCommandPool *command_pool,
59 VkQueue *queue, uint32_t *queue_family_index);
60
61int vk_destroy_context(
62 void *user_context,
63 VulkanMemoryAllocator *allocator,
64 VkInstance instance,
65 VkDevice device,
66 VkPhysicalDevice physical_device,
67 VkCommandPool command_pool,
68 VkQueue queue);
69
70int vk_find_compute_capability(void *user_context, int *major, int *minor);
71
72int vk_create_instance(void *user_context, const StringTable &requested_layers, VkInstance *instance, const VkAllocationCallbacks *alloc_callbacks);
73int vk_destroy_instance(void *user_context, VkInstance instance, const VkAllocationCallbacks *alloc_callbacks);
74
75int vk_select_device_for_context(void *user_context,
76 VkInstance *instance, VkDevice *device,
77 VkPhysicalDevice *physical_device,
78 uint32_t *queue_family_index);
79
80int vk_create_device(void *user_context, const StringTable &requested_layers, VkInstance *instance, VkDevice *device, VkQueue *queue,
81 VkPhysicalDevice *physical_device, uint32_t *queue_family_index, const VkAllocationCallbacks *alloc_callbacks);
82
83// --------------------------------------------------------------------------
84// Extensions
85// --------------------------------------------------------------------------
86uint32_t vk_get_requested_layers(void *user_context, StringTable &layer_table);
87uint32_t vk_get_required_instance_extensions(void *user_context, StringTable &ext_table);
88uint32_t vk_get_supported_instance_extensions(void *user_context, StringTable &ext_table);
89uint32_t vk_get_required_device_extensions(void *user_context, StringTable &ext_table);
90uint32_t vk_get_optional_device_extensions(void *user_context, StringTable &ext_table);
91uint32_t vk_get_supported_device_extensions(void *user_context, VkPhysicalDevice physical_device, StringTable &ext_table);
92bool vk_validate_required_extension_support(void *user_context,
93 const StringTable &required_extensions,
94 const StringTable &supported_extensions);
95
96// --------------------------------------------------------------------------
97// Resources
98// --------------------------------------------------------------------------
99
100// -- Command Pool
101int vk_create_command_pool(void *user_context, VulkanMemoryAllocator *allocator, uint32_t queue_index, VkCommandPool *command_pool);
102int vk_destroy_command_pool(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool command_pool);
103
104// Command pools are uint64_t and zero may be valid, so use this as a sentinel for invalid
105const VkCommandPool VkInvalidCommandPool(uint64_t(-1));
106
107// -- Command Buffer
108int vk_create_command_buffer(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool pool, VkCommandBuffer *command_buffer);
109int vk_destroy_command_buffer(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool command_pool, VkCommandBuffer command_buffer);
110
111int vk_fill_command_buffer_with_dispatch_call(void *user_context,
112 VkDevice device,
113 VkCommandBuffer command_buffer,
114 VkPipeline compute_pipeline,
115 VkPipelineLayout pipeline_layout,
116 VkDescriptorSet descriptor_set,
117 uint32_t descriptor_set_index,
118 int blocksX, int blocksY, int blocksZ);
119
120int vk_submit_command_buffer(void *user_context, VkQueue queue, VkCommandBuffer command_buffer);
121
122// -- Scalar Uniform Buffer
123bool vk_needs_scalar_uniform_buffer(void *user_context,
124 size_t arg_sizes[],
125 void *args[],
126 int8_t arg_is_buffer[]);
127
128size_t vk_estimate_scalar_uniform_buffer_size(void *user_context,
129 size_t arg_sizes[],
130 void *args[],
131 int8_t arg_is_buffer[]);
132
133MemoryRegion *vk_create_scalar_uniform_buffer(void *user_context,
134 VulkanMemoryAllocator *allocator,
135 size_t scalar_buffer_size);
136
137int vk_update_scalar_uniform_buffer(void *user_context,
138 VulkanMemoryAllocator *allocator,
139 MemoryRegion *region,
140 size_t arg_sizes[],
141 void *args[],
142 int8_t arg_is_buffer[]);
143
144int vk_destroy_scalar_uniform_buffer(void *user_context, VulkanMemoryAllocator *allocator,
145 MemoryRegion *scalar_args_region);
146// -- Descriptor Pool
147int vk_create_descriptor_pool(void *user_context,
148 VulkanMemoryAllocator *allocator,
149 uint32_t uniform_buffer_count,
150 uint32_t storage_buffer_count,
151 VkDescriptorPool *descriptor_pool);
152
153int vk_destroy_descriptor_pool(void *user_context,
154 VulkanMemoryAllocator *allocator,
155 VkDescriptorPool descriptor_pool);
156
157// -- Descriptor Set Layout
158uint32_t vk_count_bindings_for_descriptor_set(void *user_context,
159 size_t arg_sizes[],
160 void *args[],
161 int8_t arg_is_buffer[]);
162
163int vk_create_descriptor_set_layout(void *user_context,
164 VulkanMemoryAllocator *allocator,
165 uint32_t uniform_buffer_count,
166 uint32_t storage_buffer_count,
167 VkDescriptorSetLayout *layout);
168
169int vk_destroy_descriptor_set_layout(void *user_context,
170 VulkanMemoryAllocator *allocator,
171 VkDescriptorSetLayout descriptor_set_layout);
172
173// -- Descriptor Set
174int vk_create_descriptor_set(void *user_context,
175 VulkanMemoryAllocator *allocator,
176 VkDescriptorSetLayout descriptor_set_layout,
177 VkDescriptorPool descriptor_pool,
178 VkDescriptorSet *descriptor_set);
179
180int vk_update_descriptor_set(void *user_context,
181 VulkanMemoryAllocator *allocator,
182 VkBuffer *scalar_args_buffer,
183 size_t uniform_buffer_count,
184 size_t storage_buffer_count,
185 size_t arg_sizes[],
186 void *args[],
187 int8_t arg_is_buffer[],
188 VkDescriptorSet descriptor_set);
189
190// -- Pipeline Layout
191int vk_create_pipeline_layout(void *user_context,
192 VulkanMemoryAllocator *allocator,
193 uint32_t descriptor_set_count,
194 VkDescriptorSetLayout *descriptor_set_layouts,
195 VkPipelineLayout *pipeline_layout);
196
197int vk_destroy_pipeline_layout(void *user_context,
198 VulkanMemoryAllocator *allocator,
199 VkPipelineLayout pipeline_layout);
200// -- Compute Pipeline
201int vk_create_compute_pipeline(void *user_context,
202 VulkanMemoryAllocator *allocator,
203 const char *pipeline_name,
204 VkShaderModule shader_module,
205 VkPipelineLayout pipeline_layout,
206 VkSpecializationInfo *specialization_info,
207 VkPipeline *compute_pipeline);
208
209int vk_setup_compute_pipeline(void *user_context,
210 VulkanMemoryAllocator *allocator,
211 VulkanShaderBinding *shader_bindings,
212 VkShaderModule shader_module,
213 VkPipelineLayout pipeline_layout,
214 VkPipeline *compute_pipeline);
215
216int vk_destroy_compute_pipeline(void *user_context,
217 VulkanMemoryAllocator *allocator,
218 VkPipeline compute_pipeline);
219
220// -- Shader Module
221VulkanShaderBinding *vk_decode_shader_bindings(void *user_context, VulkanMemoryAllocator *allocator,
222 const uint32_t *module_ptr, uint32_t module_size);
223
224VulkanCompilationCacheEntry *vk_compile_shader_module(void *user_context, VulkanMemoryAllocator *allocator,
225 const char *src, int size);
226
227int vk_destroy_shader_modules(void *user_context, VulkanMemoryAllocator *allocator);
228
229// -- Copy Buffer
230int vk_do_multidimensional_copy(void *user_context, VkCommandBuffer command_buffer,
231 const device_copy &c, uint64_t src_offset, uint64_t dst_offset,
232 int d, bool from_host, bool to_host);
233
234// --------------------------------------------------------------------------
235// Errors
236// --------------------------------------------------------------------------
237
238// Returns the corresponding string for a given vulkan error code
239const char *vk_get_error_name(VkResult error) {
240 switch (error) {
241 case VK_SUCCESS:
242 return "VK_SUCCESS";
243 case VK_NOT_READY:
244 return "VK_NOT_READY";
245 case VK_TIMEOUT:
246 return "VK_TIMEOUT";
247 case VK_EVENT_SET:
248 return "VK_EVENT_SET";
249 case VK_EVENT_RESET:
250 return "VK_EVENT_RESET";
251 case VK_INCOMPLETE:
252 return "VK_INCOMPLETE";
254 return "VK_ERROR_OUT_OF_HOST_MEMORY";
256 return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
258 return "VK_ERROR_INITIALIZATION_FAILED";
260 return "VK_ERROR_DEVICE_LOST";
262 return "VK_ERROR_MEMORY_MAP_FAILED";
264 return "VK_ERROR_LAYER_NOT_PRESENT";
266 return "VK_ERROR_EXTENSION_NOT_PRESENT";
268 return "VK_ERROR_FEATURE_NOT_PRESENT";
270 return "VK_ERROR_INCOMPATIBLE_DRIVER";
272 return "VK_ERROR_TOO_MANY_OBJECTS";
274 return "VK_ERROR_FORMAT_NOT_SUPPORTED";
276 return "VK_ERROR_FRAGMENTED_POOL";
278 return "VK_ERROR_SURFACE_LOST_KHR";
280 return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
282 return "VK_SUBOPTIMAL_KHR";
284 return "VK_ERROR_OUT_OF_DATE_KHR";
286 return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
288 return "VK_ERROR_VALIDATION_FAILED_EXT";
290 return "VK_ERROR_INVALID_SHADER_NV";
292 return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
294 return "VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR";
295 default:
296 return "<Unknown Vulkan Result Code>";
297 }
298}
299
300// --------------------------------------------------------------------------
301
302} // namespace
303} // namespace Vulkan
304} // namespace Internal
305} // namespace Runtime
306} // namespace Halide
307
308#endif // HALIDE_RUNTIME_VULKAN_INTERNAL_H
struct halide_buffer_t halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Vulkan Memory Allocator class interface for managing large memory requests stored as contiguous block...
struct VkSpecializationInfo VkSpecializationInfo
VkSystemAllocationScope
VkResult
@ VK_ERROR_VALIDATION_FAILED_EXT
@ VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
@ VK_ERROR_INVALID_SHADER_NV
@ VK_SUBOPTIMAL_KHR
@ VK_ERROR_EXTENSION_NOT_PRESENT
@ VK_INCOMPLETE
@ VK_ERROR_DEVICE_LOST
@ VK_SUCCESS
@ VK_EVENT_SET
@ VK_EVENT_RESET
@ VK_ERROR_OUT_OF_POOL_MEMORY_KHR
@ VK_ERROR_OUT_OF_HOST_MEMORY
@ VK_ERROR_INITIALIZATION_FAILED
@ VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
@ VK_ERROR_OUT_OF_DEVICE_MEMORY
@ VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
@ VK_ERROR_OUT_OF_DATE_KHR
@ VK_TIMEOUT
@ VK_ERROR_FORMAT_NOT_SUPPORTED
@ VK_ERROR_FRAGMENTED_POOL
@ VK_ERROR_SURFACE_LOST_KHR
@ VK_NOT_READY
@ VK_ERROR_FEATURE_NOT_PRESENT
@ VK_ERROR_TOO_MANY_OBJECTS
@ VK_ERROR_MEMORY_MAP_FAILED
@ VK_ERROR_LAYER_NOT_PRESENT
@ VK_ERROR_INCOMPATIBLE_DRIVER
struct VkAllocationCallbacks VkAllocationCallbacks
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
unsigned __INT32_TYPE__ uint32_t
signed __INT8_TYPE__ int8_t
VkDescriptorSetLayout * descriptor_set_layouts
VulkanShaderBinding * shader_bindings
VkPipelineLayout pipeline_layout
VkShaderModule shader_module