// vk-api.h #pragma once #include "vk-module.h" namespace gfx { #define VK_API_GLOBAL_PROCS(x) \ x(vkGetInstanceProcAddr) \ x(vkCreateInstance) \ x(vkEnumerateInstanceLayerProperties) \ x(vkEnumerateDeviceExtensionProperties) \ 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(vkResetDescriptorPool) \ 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(vkFreeDescriptorSets) \ x(vkUpdateDescriptorSets) \ x(vkCreatePipelineLayout) \ x(vkDestroyPipelineLayout) \ x(vkCreateComputePipelines) \ x(vkCreateGraphicsPipelines) \ x(vkDestroyPipeline) \ x(vkCreateShaderModule) \ x(vkDestroyShaderModule) \ x(vkCreateFramebuffer) \ x(vkDestroyFramebuffer) \ x(vkCreateImage) \ x(vkDestroyImage) \ x(vkCreateImageView) \ x(vkDestroyImageView) \ x(vkCreateRenderPass) \ x(vkDestroyRenderPass) \ x(vkCreateCommandPool) \ x(vkDestroyCommandPool) \ x(vkCreateSampler) \ x(vkDestroySampler) \ x(vkCreateBufferView) \ x(vkDestroyBufferView) \ \ x(vkGetBufferMemoryRequirements) \ x(vkGetImageMemoryRequirements) \ \ x(vkCmdBindPipeline) \ x(vkCmdClearAttachments) \ x(vkCmdClearColorImage) \ x(vkCmdClearDepthStencilImage) \ x(vkCmdFillBuffer) \ x(vkCmdBindDescriptorSets) \ x(vkCmdDispatch) \ x(vkCmdDraw) \ x(vkCmdDrawIndexed) \ x(vkCmdDrawIndirect) \ x(vkCmdDrawIndexedIndirect) \ x(vkCmdSetScissor) \ x(vkCmdSetViewport) \ x(vkCmdBindVertexBuffers) \ x(vkCmdBindIndexBuffer) \ x(vkCmdBeginRenderPass) \ x(vkCmdEndRenderPass) \ x(vkCmdPipelineBarrier) \ x(vkCmdCopyBufferToImage)\ x(vkCmdCopyImage) \ x(vkCmdCopyImageToBuffer) \ x(vkCmdPushConstants) \ x(vkCmdSetStencilReference) \ x(vkCmdWriteTimestamp) \ x(vkCmdBeginQuery) \ x(vkCmdEndQuery) \ x(vkCmdResetQueryPool) \ \ x(vkCreateFence) \ x(vkDestroyFence) \ x(vkResetFences) \ x(vkGetFenceStatus) \ x(vkWaitForFences) \ \ x(vkCreateSemaphore) \ x(vkDestroySemaphore) \ \ x(vkCreateEvent) \ x(vkDestroyEvent) \ x(vkGetEventStatus) \ x(vkSetEvent) \ x(vkResetEvent) \ \ x(vkFreeCommandBuffers) \ x(vkAllocateCommandBuffers) \ x(vkBeginCommandBuffer) \ x(vkEndCommandBuffer) \ x(vkResetCommandBuffer) \ x(vkResetCommandPool) \ \ x(vkBindImageMemory) \ x(vkBindBufferMemory) \ \ x(vkCreateQueryPool) \ x(vkGetQueryPoolResults) \ x(vkDestroyQueryPool) \ /* */ #if SLANG_WINDOWS_FAMILY # define VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ x(vkCreateWin32SurfaceKHR) \ /* */ #else # define VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ x(vkCreateXlibSurfaceKHR) \ /* */ #endif #define VK_API_INSTANCE_KHR_PROCS(x) \ VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ x(vkGetPhysicalDeviceSurfaceSupportKHR) \ x(vkGetPhysicalDeviceSurfaceFormatsKHR) \ x(vkGetPhysicalDeviceSurfacePresentModesKHR) \ x(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ x(vkDestroySurfaceKHR) \ /* */ #define VK_API_DEVICE_KHR_PROCS(x) \ x(vkQueuePresentKHR) \ x(vkCreateSwapchainKHR) \ x(vkGetSwapchainImagesKHR) \ x(vkDestroySwapchainKHR) \ x(vkAcquireNextImageKHR) \ /* */ #if SLANG_WINDOWS_FAMILY # define VK_API_DEVICE_PLATFORM_OPT_PROCS(x) \ x(vkGetMemoryWin32HandleKHR) \ /* */ #else # define VK_API_DEVICE_PLATFORM_OPT_PROCS(x) \ x(vkGetMemoryFdKHR) \ /* */ #endif #define VK_API_DEVICE_OPT_PROCS(x) \ VK_API_DEVICE_PLATFORM_OPT_PROCS(x) \ x(vkCmdSetPrimitiveTopologyEXT) \ x(vkGetBufferDeviceAddress) \ x(vkGetBufferDeviceAddressKHR) \ x(vkGetBufferDeviceAddressEXT) \ x(vkCmdBuildAccelerationStructuresKHR) \ x(vkCmdCopyAccelerationStructureKHR) \ x(vkCmdCopyAccelerationStructureToMemoryKHR) \ x(vkCmdCopyMemoryToAccelerationStructureKHR) \ x(vkCmdWriteAccelerationStructuresPropertiesKHR) \ x(vkCreateAccelerationStructureKHR) \ x(vkDestroyAccelerationStructureKHR) \ x(vkGetAccelerationStructureBuildSizesKHR) \ x(vkGetSemaphoreCounterValue) \ x(vkGetSemaphoreCounterValueKHR) \ x(vkSignalSemaphore) \ x(vkSignalSemaphoreKHR) \ x(vkWaitSemaphores) \ x(vkWaitSemaphoresKHR) \ x(vkCmdSetSampleLocationsEXT) \ /* */ #define VK_API_ALL_GLOBAL_PROCS(x) \ VK_API_GLOBAL_PROCS(x) #define VK_API_ALL_INSTANCE_PROCS(x) \ VK_API_INSTANCE_PROCS(x) \ VK_API_INSTANCE_KHR_PROCS(x) #define VK_API_ALL_DEVICE_PROCS(x) \ VK_API_DEVICE_PROCS(x) \ VK_API_DEVICE_KHR_PROCS(x) \ VK_API_DEVICE_OPT_PROCS(x) #define VK_API_ALL_PROCS(x) \ VK_API_ALL_GLOBAL_PROCS(x) \ VK_API_ALL_INSTANCE_PROCS(x) \ VK_API_ALL_DEVICE_PROCS(x) \ \ VK_API_INSTANCE_PROCS_OPT(x) \ /* */ #define VK_API_DECLARE_PROC(NAME) PFN_##NAME NAME = nullptr; struct VulkanExtendedFeatureProperties { // Float16 features VkPhysicalDeviceFloat16Int8FeaturesKHR float16Features = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR}; // 16 bit storage features VkPhysicalDevice16BitStorageFeatures storage16BitFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR}; // AtomicInt64 features VkPhysicalDeviceShaderAtomicInt64FeaturesKHR atomicInt64Features = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR}; // Atomic Float features VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomicFloatFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT}; // Timeline Semaphore features VkPhysicalDeviceTimelineSemaphoreFeatures timelineFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES}; // Extended dynamic state features VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extendedDynamicStateFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT}; // Subgroup extended type features VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures shaderSubgroupExtendedTypeFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES}; // Acceleration structure features VkPhysicalDeviceAccelerationStructureFeaturesKHR accelerationStructureFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR}; // Ray query (inline ray-tracing) features VkPhysicalDeviceRayQueryFeaturesKHR rayQueryFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR}; // Buffer device address features VkPhysicalDeviceBufferDeviceAddressFeatures bufferDeviceAddressFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES}; // Inline uniform block features VkPhysicalDeviceInlineUniformBlockFeaturesEXT inlineUniformBlockFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT}; }; struct VulkanApi { VK_API_ALL_PROCS(VK_API_DECLARE_PROC) enum class ProcType { Global, Instance, Device, }; /// Returns true if all the functions in the class are defined bool areDefined(ProcType type) const; /// Sets up global parameters Slang::Result initGlobalProcs(const VulkanModule& module); /// Initialize the instance functions Slang::Result initInstanceProcs(VkInstance instance); /// Called before initDevice Slang::Result initPhysicalDevice(VkPhysicalDevice physicalDevice); /// Initialize the device functions Slang::Result initDeviceProcs(VkDevice device); /// Type bits control which indices are tested against bit 0 for testing at index 0 /// properties - a memory type must have all the bits set as passed in /// Returns -1 if couldn't find an appropriate memory type index int findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) const; /// Given queue required flags, finds a queue int findQueue(VkQueueFlags reqFlags) const; const VulkanModule* m_module = nullptr; ///< Module this was all loaded from VkInstance m_instance = VK_NULL_HANDLE; VkDevice m_device = VK_NULL_HANDLE; VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE; VkPhysicalDeviceProperties m_deviceProperties; VkPhysicalDeviceFeatures m_deviceFeatures; VkPhysicalDeviceMemoryProperties m_deviceMemoryProperties; VulkanExtendedFeatureProperties m_extendedFeatures; }; } // renderer_test