Halide 20.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
25class VulkanMemoryAllocator;
26struct VulkanShaderBinding;
27struct VulkanCompiledShaderModule;
28struct VulkanCompilationCacheEntry;
29
30// --------------------------------------------------------------------------
31
32namespace { // internalize
33
34// --------------------------------------------------------------------------
35// Memory
36// --------------------------------------------------------------------------
37void *vk_host_malloc(void *user_context, size_t size, size_t alignment, VkSystemAllocationScope scope, const VkAllocationCallbacks *callbacks = nullptr);
38void vk_host_free(void *user_context, void *ptr, const VkAllocationCallbacks *callbacks = nullptr);
39int vk_device_crop_from_offset(void *user_context, const struct halide_buffer_t *src, int64_t offset, struct halide_buffer_t *dst);
40VulkanMemoryAllocator *vk_create_memory_allocator(void *user_context, VkDevice device, VkPhysicalDevice physical_device,
41 const VkAllocationCallbacks *alloc_callbacks);
42
43int vk_destroy_memory_allocator(void *user_context, VulkanMemoryAllocator *allocator);
45 VulkanMemoryAllocator *allocator,
49// --------------------------------------------------------------------------
50// Context
51// --------------------------------------------------------------------------
52
54 void *user_context,
55 VulkanMemoryAllocator **allocator,
56 VkInstance *instance,
57 VkDevice *device,
58 VkPhysicalDevice *physical_device,
59 VkQueue *queue, uint32_t *queue_family_index);
60
62 void *user_context,
63 VulkanMemoryAllocator *allocator,
64 VkInstance instance,
65 VkDevice device,
66 VkPhysicalDevice physical_device,
67 VkQueue queue);
68
70
71int vk_create_instance(void *user_context, const StringTable &requested_layers, VkInstance *instance, const VkAllocationCallbacks *alloc_callbacks);
72int vk_destroy_instance(void *user_context, VkInstance instance, const VkAllocationCallbacks *alloc_callbacks);
73
75 VkInstance *instance, VkDevice *device,
76 VkPhysicalDevice *physical_device,
77 uint32_t *queue_family_index);
78
79int vk_create_device(void *user_context, const StringTable &requested_layers, VkInstance *instance, VkDevice *device, VkQueue *queue,
80 VkPhysicalDevice *physical_device, uint32_t *queue_family_index, const VkAllocationCallbacks *alloc_callbacks);
81
82// --------------------------------------------------------------------------
83// Extensions
84// --------------------------------------------------------------------------
94
95// --------------------------------------------------------------------------
96// Resources
97// --------------------------------------------------------------------------
98
99// -- Command Pool
102
103// -- Command Buffer
106
107struct ScopedVulkanCommandBufferAndPool;
108
110 VkDevice device,
112 VkPipeline compute_pipeline,
113 VkPipelineLayout pipeline_layout,
114 VkDescriptorSet descriptor_set,
116 int blocksX, int blocksY, int blocksZ);
117
119
120// -- Scalar Uniform Buffer
122 size_t arg_sizes[],
123 void *args[],
125
127 size_t arg_sizes[],
128 void *args[],
130
132 VulkanMemoryAllocator *allocator,
133 size_t scalar_buffer_size);
134
136 VulkanMemoryAllocator *allocator,
137 MemoryRegion *region,
138 size_t arg_sizes[],
139 void *args[],
141
142int vk_destroy_scalar_uniform_buffer(void *user_context, VulkanMemoryAllocator *allocator,
144// -- Descriptor Pool
146 VulkanMemoryAllocator *allocator,
147 uint32_t uniform_buffer_count,
148 uint32_t storage_buffer_count,
149 VkDescriptorPool *descriptor_pool);
150
152 VulkanMemoryAllocator *allocator,
153 VkDescriptorPool descriptor_pool);
154
155// -- Descriptor Set Layout
157 size_t arg_sizes[],
158 void *args[],
160
162 VulkanMemoryAllocator *allocator,
163 uint32_t uniform_buffer_count,
164 uint32_t storage_buffer_count,
165 VkDescriptorSetLayout *layout);
166
168 VulkanMemoryAllocator *allocator,
170
171// -- Descriptor Set
173 VulkanMemoryAllocator *allocator,
175 VkDescriptorPool descriptor_pool,
176 VkDescriptorSet *descriptor_set);
177
179 VulkanMemoryAllocator *allocator,
181 size_t uniform_buffer_count,
182 size_t storage_buffer_count,
183 size_t arg_sizes[],
184 void *args[],
186 VkDescriptorSet descriptor_set);
187
188// -- Pipeline Layout
190 VulkanMemoryAllocator *allocator,
192 VkDescriptorSetLayout *descriptor_set_layouts,
193 VkPipelineLayout *pipeline_layout);
194
196 VulkanMemoryAllocator *allocator,
197 VkPipelineLayout pipeline_layout);
198// -- Compute Pipeline
200 VulkanMemoryAllocator *allocator,
201 const char *pipeline_name,
202 VkShaderModule shader_module,
203 VkPipelineLayout pipeline_layout,
205 VkPipeline *compute_pipeline);
206
208 VulkanMemoryAllocator *allocator,
209 VulkanShaderBinding *shader_bindings,
210 VkShaderModule shader_module,
211 VkPipelineLayout pipeline_layout,
212 VkPipeline *compute_pipeline);
213
215 VulkanMemoryAllocator *allocator,
216 VkPipeline compute_pipeline);
217
218// -- Kernel Module
219VulkanCompilationCacheEntry *vk_compile_kernel_module(void *user_context, VulkanMemoryAllocator *allocator,
220 const char *ptr, int size);
221
222// -- Shader Module
223VulkanShaderBinding *vk_decode_shader_bindings(void *user_context, VulkanMemoryAllocator *allocator,
225
226VulkanCompiledShaderModule *vk_compile_shader_module(void *user_context, VulkanMemoryAllocator *allocator,
227 const char *src, int size);
228
229int vk_destroy_shader_modules(void *user_context, VulkanMemoryAllocator *allocator);
230
231// -- Copy Buffer
234 int d, bool from_host, bool to_host);
235
236// --------------------------------------------------------------------------
237// Debug & Errors
238// --------------------------------------------------------------------------
239
240VkResult vk_create_debug_utils_messenger(void *user_context, VkInstance instance, VulkanMemoryAllocator *allocator, VkDebugUtilsMessengerEXT *messenger);
241void vk_destroy_debug_utils_messenger(void *user_context, VkInstance instance, VulkanMemoryAllocator *allocator, VkDebugUtilsMessengerEXT messenger);
242
243// Returns the corresponding string for a given vulkan error code
244const char *vk_get_error_name(VkResult error) {
245 switch (error) {
246 case VK_SUCCESS:
247 return "VK_SUCCESS";
248 case VK_NOT_READY:
249 return "VK_NOT_READY";
250 case VK_TIMEOUT:
251 return "VK_TIMEOUT";
252 case VK_EVENT_SET:
253 return "VK_EVENT_SET";
254 case VK_EVENT_RESET:
255 return "VK_EVENT_RESET";
256 case VK_INCOMPLETE:
257 return "VK_INCOMPLETE";
259 return "VK_ERROR_OUT_OF_HOST_MEMORY";
261 return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
263 return "VK_ERROR_INITIALIZATION_FAILED";
265 return "VK_ERROR_DEVICE_LOST";
267 return "VK_ERROR_MEMORY_MAP_FAILED";
269 return "VK_ERROR_LAYER_NOT_PRESENT";
271 return "VK_ERROR_EXTENSION_NOT_PRESENT";
273 return "VK_ERROR_FEATURE_NOT_PRESENT";
275 return "VK_ERROR_INCOMPATIBLE_DRIVER";
277 return "VK_ERROR_TOO_MANY_OBJECTS";
279 return "VK_ERROR_FORMAT_NOT_SUPPORTED";
281 return "VK_ERROR_FRAGMENTED_POOL";
283 return "VK_ERROR_SURFACE_LOST_KHR";
285 return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
287 return "VK_SUBOPTIMAL_KHR";
289 return "VK_ERROR_OUT_OF_DATE_KHR";
291 return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
293 return "VK_ERROR_VALIDATION_FAILED_EXT";
295 return "VK_ERROR_INVALID_SHADER_NV";
297 return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
299 return "VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR";
300 default:
301 return "<Unknown Vulkan Result Code>";
302 }
303}
304
305// --------------------------------------------------------------------------
306
307} // namespace
308} // namespace Vulkan
309} // namespace Internal
310} // namespace Runtime
311} // namespace Halide
312
313#endif // HALIDE_RUNTIME_VULKAN_INTERNAL_H
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
unsigned __INT32_TYPE__ uint32_t
signed __INT8_TYPE__ int8_t
VulkanMemoryAllocator * allocator
The raw representation of an image passed around by generated Halide code.
VkCommandPool command_pool
void * user_context
VkCommandBuffer command_buffer