Halide 16.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_find_compute_capability(void *user_context, int *major, int *minor);
62
63int vk_create_instance(void *user_context, const StringTable &requested_layers, VkInstance *instance, const VkAllocationCallbacks *alloc_callbacks);
64int vk_destroy_instance(void *user_context, VkInstance instance, const VkAllocationCallbacks *alloc_callbacks);
65
66int vk_select_device_for_context(void *user_context,
67 VkInstance *instance, VkDevice *device,
68 VkPhysicalDevice *physical_device,
69 uint32_t *queue_family_index);
70
71int vk_create_device(void *user_context, const StringTable &requested_layers, VkInstance *instance, VkDevice *device, VkQueue *queue,
72 VkPhysicalDevice *physical_device, uint32_t *queue_family_index, const VkAllocationCallbacks *alloc_callbacks);
73
74// --------------------------------------------------------------------------
75// Extensions
76// --------------------------------------------------------------------------
77uint32_t vk_get_requested_layers(void *user_context, StringTable &layer_table);
78uint32_t vk_get_required_instance_extensions(void *user_context, StringTable &ext_table);
79uint32_t vk_get_supported_instance_extensions(void *user_context, StringTable &ext_table);
80uint32_t vk_get_required_device_extensions(void *user_context, StringTable &ext_table);
81uint32_t vk_get_optional_device_extensions(void *user_context, StringTable &ext_table);
82uint32_t vk_get_supported_device_extensions(void *user_context, VkPhysicalDevice physical_device, StringTable &ext_table);
83bool vk_validate_required_extension_support(void *user_context,
84 const StringTable &required_extensions,
85 const StringTable &supported_extensions);
86
87// --------------------------------------------------------------------------
88// Resources
89// --------------------------------------------------------------------------
90
91// -- Command Pool
92int vk_create_command_pool(void *user_context, VulkanMemoryAllocator *allocator, uint32_t queue_index, VkCommandPool *command_pool);
93int vk_destroy_command_pool(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool command_pool);
94
95// -- Command Buffer
96int vk_create_command_buffer(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool pool, VkCommandBuffer *command_buffer);
97int vk_destroy_command_buffer(void *user_context, VulkanMemoryAllocator *allocator, VkCommandPool command_pool, VkCommandBuffer command_buffer);
98
99int vk_fill_command_buffer_with_dispatch_call(void *user_context,
100 VkDevice device,
101 VkCommandBuffer command_buffer,
102 VkPipeline compute_pipeline,
103 VkPipelineLayout pipeline_layout,
104 VkDescriptorSet descriptor_set,
105 uint32_t descriptor_set_index,
106 int blocksX, int blocksY, int blocksZ);
107
108int vk_submit_command_buffer(void *user_context, VkQueue queue, VkCommandBuffer command_buffer);
109
110// -- Scalar Uniform Buffer
111bool vk_needs_scalar_uniform_buffer(void *user_context,
112 size_t arg_sizes[],
113 void *args[],
114 int8_t arg_is_buffer[]);
115
116size_t vk_estimate_scalar_uniform_buffer_size(void *user_context,
117 size_t arg_sizes[],
118 void *args[],
119 int8_t arg_is_buffer[]);
120
121MemoryRegion *vk_create_scalar_uniform_buffer(void *user_context,
122 VulkanMemoryAllocator *allocator,
123 size_t scalar_buffer_size);
124
125int vk_update_scalar_uniform_buffer(void *user_context,
126 VulkanMemoryAllocator *allocator,
127 MemoryRegion *region,
128 size_t arg_sizes[],
129 void *args[],
130 int8_t arg_is_buffer[]);
131
132int vk_destroy_scalar_uniform_buffer(void *user_context, VulkanMemoryAllocator *allocator,
133 MemoryRegion *scalar_args_region);
134// -- Descriptor Pool
135int vk_create_descriptor_pool(void *user_context,
136 VulkanMemoryAllocator *allocator,
137 uint32_t uniform_buffer_count,
138 uint32_t storage_buffer_count,
139 VkDescriptorPool *descriptor_pool);
140
141int vk_destroy_descriptor_pool(void *user_context,
142 VulkanMemoryAllocator *allocator,
143 VkDescriptorPool descriptor_pool);
144
145// -- Descriptor Set Layout
146uint32_t vk_count_bindings_for_descriptor_set(void *user_context,
147 size_t arg_sizes[],
148 void *args[],
149 int8_t arg_is_buffer[]);
150
151int vk_create_descriptor_set_layout(void *user_context,
152 VulkanMemoryAllocator *allocator,
153 uint32_t uniform_buffer_count,
154 uint32_t storage_buffer_count,
155 VkDescriptorSetLayout *layout);
156
157int vk_destroy_descriptor_set_layout(void *user_context,
158 VulkanMemoryAllocator *allocator,
159 VkDescriptorSetLayout descriptor_set_layout);
160
161// -- Descriptor Set
162int vk_create_descriptor_set(void *user_context,
163 VulkanMemoryAllocator *allocator,
164 VkDescriptorSetLayout descriptor_set_layout,
165 VkDescriptorPool descriptor_pool,
166 VkDescriptorSet *descriptor_set);
167
168int vk_update_descriptor_set(void *user_context,
169 VulkanMemoryAllocator *allocator,
170 VkBuffer *scalar_args_buffer,
171 size_t uniform_buffer_count,
172 size_t storage_buffer_count,
173 size_t arg_sizes[],
174 void *args[],
175 int8_t arg_is_buffer[],
176 VkDescriptorSet descriptor_set);
177
178// -- Pipeline Layout
179int vk_create_pipeline_layout(void *user_context,
180 VulkanMemoryAllocator *allocator,
181 uint32_t descriptor_set_count,
182 VkDescriptorSetLayout *descriptor_set_layouts,
183 VkPipelineLayout *pipeline_layout);
184
185int vk_destroy_pipeline_layout(void *user_context,
186 VulkanMemoryAllocator *allocator,
187 VkPipelineLayout pipeline_layout);
188// -- Compute Pipeline
189int vk_create_compute_pipeline(void *user_context,
190 VulkanMemoryAllocator *allocator,
191 const char *pipeline_name,
192 VkShaderModule shader_module,
193 VkPipelineLayout pipeline_layout,
194 VkSpecializationInfo *specialization_info,
195 VkPipeline *compute_pipeline);
196
197int vk_setup_compute_pipeline(void *user_context,
198 VulkanMemoryAllocator *allocator,
199 VulkanShaderBinding *shader_bindings,
200 VkShaderModule shader_module,
201 VkPipelineLayout pipeline_layout,
202 VkPipeline *compute_pipeline);
203
204int vk_destroy_compute_pipeline(void *user_context,
205 VulkanMemoryAllocator *allocator,
206 VkPipeline compute_pipeline);
207
208// -- Shader Module
209VulkanShaderBinding *vk_decode_shader_bindings(void *user_context, VulkanMemoryAllocator *allocator,
210 const uint32_t *module_ptr, uint32_t module_size);
211
212VulkanCompilationCacheEntry *vk_compile_shader_module(void *user_context, VulkanMemoryAllocator *allocator,
213 const char *src, int size);
214
215int vk_destroy_shader_modules(void *user_context, VulkanMemoryAllocator *allocator);
216
217// -- Copy Buffer
218int vk_do_multidimensional_copy(void *user_context, VkCommandBuffer command_buffer,
219 const device_copy &c, uint64_t src_offset, uint64_t dst_offset,
220 int d, bool from_host, bool to_host);
221
222// --------------------------------------------------------------------------
223// Errors
224// --------------------------------------------------------------------------
225
226// Returns the corresponding string for a given vulkan error code
227const char *vk_get_error_name(VkResult error) {
228 switch (error) {
229 case VK_SUCCESS:
230 return "VK_SUCCESS";
231 case VK_NOT_READY:
232 return "VK_NOT_READY";
233 case VK_TIMEOUT:
234 return "VK_TIMEOUT";
235 case VK_EVENT_SET:
236 return "VK_EVENT_SET";
237 case VK_EVENT_RESET:
238 return "VK_EVENT_RESET";
239 case VK_INCOMPLETE:
240 return "VK_INCOMPLETE";
242 return "VK_ERROR_OUT_OF_HOST_MEMORY";
244 return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
246 return "VK_ERROR_INITIALIZATION_FAILED";
248 return "VK_ERROR_DEVICE_LOST";
250 return "VK_ERROR_MEMORY_MAP_FAILED";
252 return "VK_ERROR_LAYER_NOT_PRESENT";
254 return "VK_ERROR_EXTENSION_NOT_PRESENT";
256 return "VK_ERROR_FEATURE_NOT_PRESENT";
258 return "VK_ERROR_INCOMPATIBLE_DRIVER";
260 return "VK_ERROR_TOO_MANY_OBJECTS";
262 return "VK_ERROR_FORMAT_NOT_SUPPORTED";
264 return "VK_ERROR_FRAGMENTED_POOL";
266 return "VK_ERROR_SURFACE_LOST_KHR";
268 return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
270 return "VK_SUBOPTIMAL_KHR";
272 return "VK_ERROR_OUT_OF_DATE_KHR";
274 return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
276 return "VK_ERROR_VALIDATION_FAILED_EXT";
278 return "VK_ERROR_INVALID_SHADER_NV";
280 return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
282 return "VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR";
283 default:
284 return "<Unknown Vulkan Result Code>";
285 }
286}
287
288// --------------------------------------------------------------------------
289
290} // namespace
291} // namespace Vulkan
292} // namespace Internal
293} // namespace Runtime
294} // namespace Halide
295
296#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