blob: 05a84db5db7bb84842a5a19945a718cd872622e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#pragma once
#include "slang-gfx.h"
#define VK_NO_PROTOTYPES
#include "vulkan/vulkan.h"
// This file provides basic loading and helper functions for using
// the Vulkan API.
// The Vulkan function pointers we will use in this example.
// clang-format off
#define VK_API_GLOBAL_PROCS(x) \
x(vkGetInstanceProcAddr) \
x(vkCreateInstance) \
x(vkEnumerateInstanceLayerProperties) \
x(vkDestroyInstance) \
/* */
#define VK_API_INSTANCE_PROCS_OPT(x) \
x(vkGetPhysicalDeviceFeatures2) \
x(vkGetPhysicalDeviceProperties2) \
x(vkCreateDebugReportCallbackEXT) \
x(vkDestroyDebugReportCallbackEXT) \
x(vkDebugReportMessageEXT) \
/* */
#define VK_API_INSTANCE_PROCS(x) \
x(vkCreateDevice) \
x(vkDestroyDevice) \
x(vkEnumeratePhysicalDevices) \
x(vkGetPhysicalDeviceProperties) \
x(vkGetPhysicalDeviceFeatures) \
x(vkGetPhysicalDeviceMemoryProperties) \
x(vkGetPhysicalDeviceQueueFamilyProperties) \
x(vkGetPhysicalDeviceFormatProperties) \
x(vkGetDeviceProcAddr) \
/* */
#define VK_API_DEVICE_PROCS(x) \
x(vkCreateDescriptorPool) \
x(vkDestroyDescriptorPool) \
x(vkGetDeviceQueue) \
x(vkQueueSubmit) \
x(vkQueueWaitIdle) \
x(vkCreateBuffer) \
x(vkAllocateMemory) \
x(vkMapMemory) \
x(vkUnmapMemory) \
x(vkCmdCopyBuffer) \
x(vkDestroyBuffer) \
x(vkFreeMemory) \
x(vkCreateDescriptorSetLayout) \
x(vkDestroyDescriptorSetLayout) \
x(vkAllocateDescriptorSets) \
x(vkUpdateDescriptorSets) \
x(vkCreatePipelineLayout) \
x(vkDestroyPipelineLayout) \
x(vkCreateComputePipelines) \
x(vkDestroyPipeline) \
x(vkCreateShaderModule) \
x(vkDestroyShaderModule) \
x(vkCreateCommandPool) \
x(vkDestroyCommandPool) \
\
x(vkGetBufferMemoryRequirements) \
\
x(vkCmdBindPipeline) \
x(vkCmdBindDescriptorSets) \
x(vkCmdDispatch) \
\
x(vkFreeCommandBuffers) \
x(vkAllocateCommandBuffers) \
x(vkBeginCommandBuffer) \
x(vkEndCommandBuffer) \
x(vkBindBufferMemory) \
/* */
#define VK_API_ALL_GLOBAL_PROCS(x) \
VK_API_GLOBAL_PROCS(x)
#define VK_API_ALL_INSTANCE_PROCS(x) \
VK_API_INSTANCE_PROCS(x) \
#define VK_API_ALL_PROCS(x) \
VK_API_ALL_GLOBAL_PROCS(x) \
VK_API_ALL_INSTANCE_PROCS(x) \
VK_API_DEVICE_PROCS(x) \
VK_API_INSTANCE_PROCS_OPT(x) \
/* */
#define VK_API_DECLARE_PROC(NAME) PFN_##NAME NAME = nullptr;
// clang-format on
struct VulkanAPI
{
gfx::Result initFromGFX(gfx::IDevice* gfxDevice);
VkInstance instance = VK_NULL_HANDLE;
VkDevice device = VK_NULL_HANDLE;
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
VK_API_ALL_PROCS(VK_API_DECLARE_PROC)
gfx::Result initGlobalProcs();
/// Initialize the instance functions
gfx::Result initInstanceProcs();
/// Initialize the device functions
gfx::Result initDeviceProcs();
/// Clean up
~VulkanAPI();
};
#define RETURN_ON_FAIL(x) \
{ \
auto _res = x; \
if (_res != 0) \
{ \
return -1; \
} \
}
// Loads Vulkan library and creates a VkDevice.
// Returns 0 if successful.
int initializeVulkanDevice(VulkanAPI& api);
|