yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Theresa FoleyAdd an example for reflection of parameter blocks (#6161)31bb5eaa0

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