Halide 17.0.2
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 VulkanCompilationCacheEntry;
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,
48// --------------------------------------------------------------------------
49// Context
50// --------------------------------------------------------------------------
51
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// --------------------------------------------------------------------------
83bool vk_validate_required_extension_support(void *user_context,
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
100 VkDevice device,
102 VkPipeline compute_pipeline,
104 VkDescriptorSet descriptor_set,
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[],
115
116size_t vk_estimate_scalar_uniform_buffer_size(void *user_context,
117 size_t arg_sizes[],
118 void *args[],
120
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[],
131
132int vk_destroy_scalar_uniform_buffer(void *user_context, VulkanMemoryAllocator *allocator,
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
147 size_t arg_sizes[],
148 void *args[],
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,
160
161// -- Descriptor Set
162int vk_create_descriptor_set(void *user_context,
163 VulkanMemoryAllocator *allocator,
165 VkDescriptorPool descriptor_pool,
166 VkDescriptorSet *descriptor_set);
167
168int vk_update_descriptor_set(void *user_context,
169 VulkanMemoryAllocator *allocator,
171 size_t uniform_buffer_count,
172 size_t storage_buffer_count,
173 size_t arg_sizes[],
174 void *args[],
176 VkDescriptorSet descriptor_set);
177
178// -- Pipeline Layout
179int vk_create_pipeline_layout(void *user_context,
180 VulkanMemoryAllocator *allocator,
184
185int vk_destroy_pipeline_layout(void *user_context,
186 VulkanMemoryAllocator *allocator,
188// -- Compute Pipeline
189int vk_create_compute_pipeline(void *user_context,
190 VulkanMemoryAllocator *allocator,
191 const char *pipeline_name,
195 VkPipeline *compute_pipeline);
196
197int vk_setup_compute_pipeline(void *user_context,
198 VulkanMemoryAllocator *allocator,
199 VulkanShaderBinding *shader_bindings,
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,
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
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
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
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Definition IROperator.h:364
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
The raw representation of an image passed around by generated Halide code.