yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
fb052bf46
master
1// vk-api.h 2#pragma once 3 4#include "core/slang-basic.h" 5#include "vk-module.h" 6 7namespace gfx 8{ 9 10// clang-format off 11#define VK_API_GLOBAL_PROCS (x ) \ 12 x(vkGetInstanceProcAddr) \ 13 x(vkCreateInstance) \ 14 x(vkEnumerateInstanceLayerProperties) \ 15 x(vkEnumerateDeviceExtensionProperties) \ 16 x(vkDestroyInstance) \ 17/* */ 18 19#define VK_API_INSTANCE_PROCS_OPT (x ) \ 20 x(vkGetPhysicalDeviceFeatures2) \ 21 x(vkGetPhysicalDeviceProperties2) \ 22 x(vkCreateDebugReportCallbackEXT) \ 23 x(vkDestroyDebugReportCallbackEXT) \ 24 x(vkDebugReportMessageEXT) \ 25 x(vkGetPhysicalDeviceCooperativeVectorPropertiesNV) \ 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(vkResetDescriptorPool) \ 44 x(vkGetDeviceQueue) \ 45 x(vkQueueSubmit) \ 46 x(vkQueueWaitIdle) \ 47 x(vkCreateBuffer) \ 48 x(vkAllocateMemory) \ 49 x(vkMapMemory) \ 50 x(vkUnmapMemory) \ 51 x(vkCmdCopyBuffer) \ 52 x(vkDestroyBuffer) \ 53 x(vkFreeMemory) \ 54 x(vkCreateDescriptorSetLayout) \ 55 x(vkDestroyDescriptorSetLayout) \ 56 x(vkAllocateDescriptorSets) \ 57 x(vkFreeDescriptorSets) \ 58 x(vkUpdateDescriptorSets) \ 59 x(vkCreatePipelineLayout) \ 60 x(vkDestroyPipelineLayout) \ 61 x(vkCreateComputePipelines) \ 62 x(vkCreateGraphicsPipelines) \ 63 x(vkDestroyPipeline) \ 64 x(vkCreateShaderModule) \ 65 x(vkDestroyShaderModule) \ 66 x(vkCreateFramebuffer) \ 67 x(vkDestroyFramebuffer) \ 68 x(vkCreateImage) \ 69 x(vkDestroyImage) \ 70 x(vkCreateImageView) \ 71 x(vkDestroyImageView) \ 72 x(vkCreateRenderPass) \ 73 x(vkDestroyRenderPass) \ 74 x(vkCreateCommandPool) \ 75 x(vkDestroyCommandPool) \ 76 x(vkCreateSampler) \ 77 x(vkDestroySampler) \ 78 x(vkCreateBufferView) \ 79 x(vkDestroyBufferView) \ 80 \ 81 x(vkGetBufferMemoryRequirements) \ 82 x(vkGetImageMemoryRequirements) \ 83 \ 84 x(vkCmdBindPipeline) \ 85 x(vkCmdClearAttachments) \ 86 x(vkCmdClearColorImage) \ 87 x(vkCmdClearDepthStencilImage) \ 88 x(vkCmdFillBuffer) \ 89 x(vkCmdBindDescriptorSets) \ 90 x(vkCmdDispatch) \ 91 x(vkCmdDispatchIndirect) \ 92 x(vkCmdDraw) \ 93 x(vkCmdDrawIndexed) \ 94 x(vkCmdDrawIndirect) \ 95 x(vkCmdDrawIndirectCount) \ 96 x(vkCmdDrawIndexedIndirect) \ 97 x(vkCmdDrawIndexedIndirectCount) \ 98 x(vkCmdSetScissor) \ 99 x(vkCmdSetViewport) \ 100 x(vkCmdBindVertexBuffers) \ 101 x(vkCmdBindIndexBuffer) \ 102 x(vkCmdBeginRenderPass) \ 103 x(vkCmdEndRenderPass) \ 104 x(vkCmdPipelineBarrier) \ 105 x(vkCmdCopyBufferToImage)\ 106 x(vkCmdCopyImage) \ 107 x(vkCmdCopyImageToBuffer) \ 108 x(vkCmdResolveImage) \ 109 x(vkCmdPushConstants) \ 110 x(vkCmdSetStencilReference) \ 111 x(vkCmdWriteTimestamp) \ 112 x(vkCmdBeginQuery) \ 113 x(vkCmdEndQuery) \ 114 x(vkCmdResetQueryPool) \ 115 x(vkCmdCopyQueryPoolResults) \ 116 \ 117 x(vkCreateFence) \ 118 x(vkDestroyFence) \ 119 x(vkResetFences) \ 120 x(vkGetFenceStatus) \ 121 x(vkWaitForFences) \ 122 \ 123 x(vkCreateSemaphore) \ 124 x(vkDestroySemaphore) \ 125 \ 126 x(vkCreateEvent) \ 127 x(vkDestroyEvent) \ 128 x(vkGetEventStatus) \ 129 x(vkSetEvent) \ 130 x(vkResetEvent) \ 131 \ 132 x(vkFreeCommandBuffers) \ 133 x(vkAllocateCommandBuffers) \ 134 x(vkBeginCommandBuffer) \ 135 x(vkEndCommandBuffer) \ 136 x(vkResetCommandBuffer) \ 137 x(vkResetCommandPool) \ 138 \ 139 x(vkBindImageMemory) \ 140 x(vkBindBufferMemory) \ 141 \ 142 x(vkCreateQueryPool) \ 143 x(vkGetQueryPoolResults) \ 144 x(vkDestroyQueryPool) \ 145/* */ 146 147#if SLANG_WINDOWS_FAMILY 148# define VK_API_INSTANCE_PLATFORM_KHR_PROCS (x ) \ 149 x(vkCreateWin32SurfaceKHR) \ 150/* */ 151#elif SLANG_APPLE_FAMILY 152# define VK_API_INSTANCE_PLATFORM_KHR_PROCS (x ) \ 153 x(vkCreateMetalSurfaceEXT) \ 154/* */ 155#elif SLANG_ENABLE_XLIB 156# define VK_API_INSTANCE_PLATFORM_KHR_PROCS (x ) \ 157 x(vkCreateXlibSurfaceKHR) \ 158/* */ 159#else 160# define VK_API_INSTANCE_PLATFORM_KHR_PROCS (x ) \ 161/* */ 162#endif 163 164#define VK_API_INSTANCE_KHR_PROCS (x ) \ 165 VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ 166 x(vkGetPhysicalDeviceSurfaceSupportKHR) \ 167 x(vkGetPhysicalDeviceSurfaceFormatsKHR) \ 168 x(vkGetPhysicalDeviceSurfacePresentModesKHR) \ 169 x(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ 170 x(vkDestroySurfaceKHR) \ 171 172/* */ 173 174#define VK_API_DEVICE_KHR_PROCS (x ) \ 175 x(vkQueuePresentKHR) \ 176 x(vkCreateSwapchainKHR) \ 177 x(vkGetSwapchainImagesKHR) \ 178 x(vkDestroySwapchainKHR) \ 179 x(vkAcquireNextImageKHR) \ 180 x(vkCreateRayTracingPipelinesKHR) \ 181 x(vkCmdTraceRaysKHR) \ 182 x(vkGetRayTracingShaderGroupHandlesKHR) \ 183/* */ 184 185#if SLANG_WINDOWS_FAMILY 186# define VK_API_DEVICE_PLATFORM_OPT_PROCS (x ) \ 187 x(vkGetMemoryWin32HandleKHR) \ 188 x(vkGetSemaphoreWin32HandleKHR) \ 189/* */ 190#else 191# define VK_API_DEVICE_PLATFORM_OPT_PROCS (x ) \ 192 x(vkGetMemoryFdKHR) \ 193 x(vkGetSemaphoreFdKHR) \ 194/* */ 195#endif 196 197#define VK_API_DEVICE_OPT_PROCS (x ) \ 198 VK_API_DEVICE_PLATFORM_OPT_PROCS(x) \ 199 x(vkCmdSetPrimitiveTopologyEXT) \ 200 x(vkGetBufferDeviceAddress) \ 201 x(vkGetBufferDeviceAddressKHR) \ 202 x(vkGetBufferDeviceAddressEXT) \ 203 x(vkCmdBuildAccelerationStructuresKHR) \ 204 x(vkCmdCopyAccelerationStructureKHR) \ 205 x(vkCmdCopyAccelerationStructureToMemoryKHR) \ 206 x(vkCmdCopyMemoryToAccelerationStructureKHR) \ 207 x(vkCmdWriteAccelerationStructuresPropertiesKHR) \ 208 x(vkCreateAccelerationStructureKHR) \ 209 x(vkDestroyAccelerationStructureKHR) \ 210 x(vkGetAccelerationStructureBuildSizesKHR) \ 211 x(vkGetSemaphoreCounterValue) \ 212 x(vkGetSemaphoreCounterValueKHR) \ 213 x(vkSignalSemaphore) \ 214 x(vkSignalSemaphoreKHR) \ 215 x(vkWaitSemaphores) \ 216 x(vkWaitSemaphoresKHR) \ 217 x(vkCmdSetSampleLocationsEXT) \ 218 x(vkCmdDebugMarkerBeginEXT) \ 219 x(vkCmdDebugMarkerEndEXT) \ 220 x(vkDebugMarkerSetObjectNameEXT) \ 221 x(vkCmdDrawMeshTasksEXT) \ 222/* */ 223 224#define VK_API_ALL_GLOBAL_PROCS (x ) \ 225 VK_API_GLOBAL_PROCS(x) 226 227#define VK_API_ALL_INSTANCE_PROCS (x ) \ 228 VK_API_INSTANCE_PROCS(x) \ 229 VK_API_INSTANCE_KHR_PROCS(x) 230 231#define VK_API_ALL_DEVICE_PROCS (x ) \ 232 VK_API_DEVICE_PROCS(x) \ 233 VK_API_DEVICE_KHR_PROCS(x) \ 234 VK_API_DEVICE_OPT_PROCS(x) 235 236#define VK_API_ALL_PROCS (x ) \ 237 VK_API_ALL_GLOBAL_PROCS(x) \ 238 VK_API_ALL_INSTANCE_PROCS(x) \ 239 VK_API_ALL_DEVICE_PROCS(x) \ 240 \ 241 VK_API_INSTANCE_PROCS_OPT(x) \ 242/* */ 243 244#define VK_API_DECLARE_PROC (NAME ) PFN_##NAME NAME = nullptr; 245// clang-format on 246 247struct VulkanExtendedFeatureProperties 248{ 249// 16 bit storage features 250VkPhysicalDevice16BitStorageFeatures storage16BitFeatures = { 251VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR }; 252// Atomic Float features 253VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomicFloatFeatures = { 254VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT }; 255VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT atomicFloat2Features = { 256VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_2_FEATURES_EXT }; 257// Image int64 atomic features 258VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT imageInt64AtomicFeatures = { 259VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_ATOMIC_INT64_FEATURES_EXT }; 260// Extended dynamic state features 261VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extendedDynamicStateFeatures = { 262VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT }; 263// Acceleration structure features 264VkPhysicalDeviceAccelerationStructureFeaturesKHR accelerationStructureFeatures = { 265VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR }; 266// Ray tracing pipeline features 267VkPhysicalDeviceRayTracingPipelineFeaturesKHR rayTracingPipelineFeatures = { 268VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR }; 269// Ray query (inline ray-tracing) features 270VkPhysicalDeviceRayQueryFeaturesKHR rayQueryFeatures = { 271VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR }; 272// Inline uniform block features 273VkPhysicalDeviceInlineUniformBlockFeaturesEXT inlineUniformBlockFeatures = { 274VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT }; 275// Robustness2 features 276VkPhysicalDeviceRobustness2FeaturesEXT robustness2Features = { 277VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT }; 278 279VkPhysicalDeviceRayTracingInvocationReorderFeaturesNV rayTracingInvocationReorderFeatures = { 280VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV }; 281 282VkPhysicalDeviceVariablePointerFeaturesKHR variablePointersFeatures = { 283VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR }; 284 285VkPhysicalDeviceComputeShaderDerivativesFeaturesNV computeShaderDerivativeFeatures = { 286VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV }; 287 288// Clock features 289VkPhysicalDeviceShaderClockFeaturesKHR clockFeatures = { 290VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR }; 291 292// Mesh shader features 293VkPhysicalDeviceMeshShaderFeaturesEXT meshShaderFeatures = { 294VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT }; 295 296// Multiview features 297VkPhysicalDeviceMultiviewFeaturesKHR multiviewFeatures = { 298VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR }; 299 300// Fragment shading rate features 301VkPhysicalDeviceFragmentShadingRateFeaturesKHR fragmentShadingRateFeatures = { 302VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR }; 303 304// Vulkan 1.2 features. 305VkPhysicalDeviceVulkan12Features vulkan12Features = { 306VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES }; 307 308// Cooperative vector features 309VkPhysicalDeviceCooperativeVectorFeaturesNV cooperativeVectorFeatures = { 310VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_VECTOR_FEATURES_NV }; 311 312// Ray tracing validation features 313VkPhysicalDeviceRayTracingValidationFeaturesNV rayTracingValidationFeatures = { 314VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_VALIDATION_FEATURES_NV }; 315}; 316 317struct VulkanApi 318{ 319VK_API_ALL_PROCS (VK_API_DECLARE_PROC ) 320 321enum class ProcType 322 { 323Global , 324Instance , 325Device , 326 }; 327 328/// Returns true if all the functions in the class are defined 329bool areDefined (ProcType type )const ; 330 331/// Sets up global parameters 332Slang ::Result initGlobalProcs (const VulkanModule & module ); 333/// Initialize the instance functions 334Slang ::Result initInstanceProcs (VkInstance instance ); 335 336/// Called before initDevice 337Slang ::Result initPhysicalDevice (VkPhysicalDevice physicalDevice ); 338 339/// Initialize the device functions 340Slang ::Result initDeviceProcs (VkDevice device ); 341 342/// Type bits control which indices are tested against bit 0 for testing at index 0 343/// properties - a memory type must have all the bits set as passed in 344/// Returns -1 if couldn't find an appropriate memory type index 345int findMemoryTypeIndex (uint32_t typeBits ,VkMemoryPropertyFlags properties )const ; 346 347/// Given queue required flags, finds a queue 348int findQueue (VkQueueFlags reqFlags )const ; 349 350const VulkanModule * m_module = nullptr;///< Module this was all loaded from 351VkInstance m_instance = VK_NULL_HANDLE ; 352VkDevice m_device = VK_NULL_HANDLE ; 353VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE ; 354 355VkPhysicalDeviceProperties m_deviceProperties ; 356VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties ; 357VkPhysicalDeviceFeatures m_deviceFeatures ; 358VkPhysicalDeviceMemoryProperties m_deviceMemoryProperties ; 359VulkanExtendedFeatureProperties m_extendedFeatures ; 360 361Slang ::List < VkCooperativeVectorPropertiesNV > m_cooperativeVectorProperties ; 362}; 363 364}// namespace gfx